fbtrap.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright © 2004 Keith Packard
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that
  7. * copyright notice and this permission notice appear in supporting
  8. * documentation, and that the name of Keith Packard not be used in
  9. * advertising or publicity pertaining to distribution of the software without
  10. * specific, written prior permission. Keith Packard makes no
  11. * representations about the suitability of this software for any purpose. It
  12. * is provided "as is" without express or implied warranty.
  13. *
  14. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20. * PERFORMANCE OF THIS SOFTWARE.
  21. */
  22. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include "fb.h"
  26. #include "picturestr.h"
  27. #include "mipict.h"
  28. #include "fbpict.h"
  29. #include "damage.h"
  30. void
  31. fbAddTraps(PicturePtr pPicture,
  32. INT16 x_off, INT16 y_off, int ntrap, xTrap * traps)
  33. {
  34. pixman_image_t *image;
  35. int dst_xoff, dst_yoff;
  36. if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
  37. return;
  38. pixman_add_traps(image, x_off + dst_xoff, y_off + dst_yoff,
  39. ntrap, (pixman_trap_t *) traps);
  40. free_pixman_pict(pPicture, image);
  41. }
  42. void
  43. fbRasterizeTrapezoid(PicturePtr pPicture,
  44. xTrapezoid * trap, int x_off, int y_off)
  45. {
  46. pixman_image_t *image;
  47. int dst_xoff, dst_yoff;
  48. if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
  49. return;
  50. pixman_rasterize_trapezoid(image, (pixman_trapezoid_t *) trap,
  51. x_off + dst_xoff, y_off + dst_yoff);
  52. free_pixman_pict(pPicture, image);
  53. }
  54. void
  55. fbAddTriangles(PicturePtr pPicture,
  56. INT16 x_off, INT16 y_off, int ntri, xTriangle * tris)
  57. {
  58. pixman_image_t *image;
  59. int dst_xoff, dst_yoff;
  60. if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
  61. return;
  62. pixman_add_triangles(image,
  63. dst_xoff + x_off, dst_yoff + y_off,
  64. ntri, (pixman_triangle_t *) tris);
  65. free_pixman_pict(pPicture, image);
  66. }
  67. typedef void (*CompositeShapesFunc) (pixman_op_t op,
  68. pixman_image_t * src,
  69. pixman_image_t * dst,
  70. pixman_format_code_t mask_format,
  71. int x_src, int y_src,
  72. int x_dst, int y_dst,
  73. int n_shapes, const uint8_t * shapes);
  74. static void
  75. fbShapes(CompositeShapesFunc composite,
  76. pixman_op_t op,
  77. PicturePtr pSrc,
  78. PicturePtr pDst,
  79. PictFormatPtr maskFormat,
  80. int16_t xSrc,
  81. int16_t ySrc, int nshapes, int shape_size, const uint8_t * shapes)
  82. {
  83. pixman_image_t *src, *dst;
  84. int src_xoff, src_yoff;
  85. int dst_xoff, dst_yoff;
  86. miCompositeSourceValidate(pSrc);
  87. src = image_from_pict(pSrc, FALSE, &src_xoff, &src_yoff);
  88. dst = image_from_pict(pDst, TRUE, &dst_xoff, &dst_yoff);
  89. if (src && dst) {
  90. pixman_format_code_t format;
  91. DamageRegionAppend(pDst->pDrawable, pDst->pCompositeClip);
  92. if (!maskFormat) {
  93. int i;
  94. if (pDst->polyEdge == PolyEdgeSharp)
  95. format = PIXMAN_a1;
  96. else
  97. format = PIXMAN_a8;
  98. for (i = 0; i < nshapes; ++i) {
  99. composite(op, src, dst, format,
  100. xSrc + src_xoff,
  101. ySrc + src_yoff,
  102. dst_xoff, dst_yoff, 1, shapes + i * shape_size);
  103. }
  104. }
  105. else {
  106. switch (PICT_FORMAT_A(maskFormat->format)) {
  107. case 1:
  108. format = PIXMAN_a1;
  109. break;
  110. case 4:
  111. format = PIXMAN_a4;
  112. break;
  113. default:
  114. case 8:
  115. format = PIXMAN_a8;
  116. break;
  117. }
  118. composite(op, src, dst, format,
  119. xSrc + src_xoff,
  120. ySrc + src_yoff, dst_xoff, dst_yoff, nshapes, shapes);
  121. }
  122. DamageRegionProcessPending(pDst->pDrawable);
  123. }
  124. free_pixman_pict(pSrc, src);
  125. free_pixman_pict(pDst, dst);
  126. }
  127. void
  128. fbTrapezoids(CARD8 op,
  129. PicturePtr pSrc,
  130. PicturePtr pDst,
  131. PictFormatPtr maskFormat,
  132. INT16 xSrc, INT16 ySrc, int ntrap, xTrapezoid * traps)
  133. {
  134. xSrc -= (traps[0].left.p1.x >> 16);
  135. ySrc -= (traps[0].left.p1.y >> 16);
  136. fbShapes((CompositeShapesFunc) pixman_composite_trapezoids,
  137. op, pSrc, pDst, maskFormat,
  138. xSrc, ySrc, ntrap, sizeof(xTrapezoid), (const uint8_t *) traps);
  139. }
  140. void
  141. fbTriangles(CARD8 op,
  142. PicturePtr pSrc,
  143. PicturePtr pDst,
  144. PictFormatPtr maskFormat,
  145. INT16 xSrc, INT16 ySrc, int ntris, xTriangle * tris)
  146. {
  147. xSrc -= (tris[0].p1.x >> 16);
  148. ySrc -= (tris[0].p1.y >> 16);
  149. fbShapes((CompositeShapesFunc) pixman_composite_triangles,
  150. op, pSrc, pDst, maskFormat,
  151. xSrc, ySrc, ntris, sizeof(xTriangle), (const uint8_t *) tris);
  152. }