mitri.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. *
  3. * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and its
  6. * documentation for any purpose is hereby granted without fee, provided that
  7. * the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the name of Keith Packard not be used in
  10. * advertising or publicity pertaining to distribution of the software without
  11. * specific, written prior permission. Keith Packard makes no
  12. * representations about the suitability of this software for any purpose. It
  13. * is provided "as is" without express or implied warranty.
  14. *
  15. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  16. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  17. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  18. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  20. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  21. * PERFORMANCE OF THIS SOFTWARE.
  22. */
  23. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include "scrnintstr.h"
  27. #include "gcstruct.h"
  28. #include "pixmapstr.h"
  29. #include "windowstr.h"
  30. #include "mi.h"
  31. #include "picturestr.h"
  32. #include "mipict.h"
  33. void
  34. miPointFixedBounds(int npoint, xPointFixed * points, BoxPtr bounds)
  35. {
  36. bounds->x1 = xFixedToInt(points->x);
  37. bounds->x2 = xFixedToInt(xFixedCeil(points->x));
  38. bounds->y1 = xFixedToInt(points->y);
  39. bounds->y2 = xFixedToInt(xFixedCeil(points->y));
  40. points++;
  41. npoint--;
  42. while (npoint-- > 0) {
  43. INT16 x1 = xFixedToInt(points->x);
  44. INT16 x2 = xFixedToInt(xFixedCeil(points->x));
  45. INT16 y1 = xFixedToInt(points->y);
  46. INT16 y2 = xFixedToInt(xFixedCeil(points->y));
  47. if (x1 < bounds->x1)
  48. bounds->x1 = x1;
  49. else if (x2 > bounds->x2)
  50. bounds->x2 = x2;
  51. if (y1 < bounds->y1)
  52. bounds->y1 = y1;
  53. else if (y2 > bounds->y2)
  54. bounds->y2 = y2;
  55. points++;
  56. }
  57. }
  58. void
  59. miTriangleBounds(int ntri, xTriangle * tris, BoxPtr bounds)
  60. {
  61. miPointFixedBounds(ntri * 3, (xPointFixed *) tris, bounds);
  62. }
  63. void
  64. miTriangles(CARD8 op,
  65. PicturePtr pSrc,
  66. PicturePtr pDst,
  67. PictFormatPtr maskFormat,
  68. INT16 xSrc, INT16 ySrc, int ntri, xTriangle * tris)
  69. {
  70. ScreenPtr pScreen = pDst->pDrawable->pScreen;
  71. PictureScreenPtr ps = GetPictureScreen(pScreen);
  72. /*
  73. * Check for solid alpha add
  74. */
  75. if (op == PictOpAdd && miIsSolidAlpha(pSrc)) {
  76. (*ps->AddTriangles) (pDst, 0, 0, ntri, tris);
  77. }
  78. else if (maskFormat) {
  79. BoxRec bounds;
  80. PicturePtr pPicture;
  81. INT16 xDst, yDst;
  82. INT16 xRel, yRel;
  83. xDst = tris[0].p1.x >> 16;
  84. yDst = tris[0].p1.y >> 16;
  85. miTriangleBounds(ntri, tris, &bounds);
  86. if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
  87. return;
  88. pPicture = miCreateAlphaPicture(pScreen, pDst, maskFormat,
  89. bounds.x2 - bounds.x1,
  90. bounds.y2 - bounds.y1);
  91. if (!pPicture)
  92. return;
  93. (*ps->AddTriangles) (pPicture, -bounds.x1, -bounds.y1, ntri, tris);
  94. xRel = bounds.x1 + xSrc - xDst;
  95. yRel = bounds.y1 + ySrc - yDst;
  96. CompositePicture(op, pSrc, pPicture, pDst,
  97. xRel, yRel, 0, 0, bounds.x1, bounds.y1,
  98. bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
  99. FreePicture(pPicture, 0);
  100. }
  101. else {
  102. if (pDst->polyEdge == PolyEdgeSharp)
  103. maskFormat = PictureMatchFormat(pScreen, 1, PICT_a1);
  104. else
  105. maskFormat = PictureMatchFormat(pScreen, 8, PICT_a8);
  106. for (; ntri; ntri--, tris++)
  107. miTriangles(op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, tris);
  108. }
  109. }
  110. void
  111. miTriStrip(CARD8 op,
  112. PicturePtr pSrc,
  113. PicturePtr pDst,
  114. PictFormatPtr maskFormat,
  115. INT16 xSrc, INT16 ySrc, int npoint, xPointFixed * points)
  116. {
  117. ScreenPtr pScreen = pDst->pDrawable->pScreen;
  118. PictureScreenPtr ps = GetPictureScreen(pScreen);
  119. xTriangle *tris, *tri;
  120. int ntri;
  121. if (npoint < 3)
  122. return;
  123. ntri = npoint - 2;
  124. tris = ALLOCATE_LOCAL(ntri * sizeof(xTriangle));
  125. if (!tris)
  126. return;
  127. for (tri = tris; npoint >= 3; npoint--, points++, tri++) {
  128. tri->p1 = points[0];
  129. tri->p2 = points[1];
  130. tri->p3 = points[2];
  131. }
  132. (*ps->Triangles) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntri, tris);
  133. DEALLOCATE_LOCAL(tris);
  134. }
  135. void
  136. miTriFan(CARD8 op,
  137. PicturePtr pSrc,
  138. PicturePtr pDst,
  139. PictFormatPtr maskFormat,
  140. INT16 xSrc, INT16 ySrc, int npoint, xPointFixed * points)
  141. {
  142. ScreenPtr pScreen = pDst->pDrawable->pScreen;
  143. PictureScreenPtr ps = GetPictureScreen(pScreen);
  144. xTriangle *tris, *tri;
  145. xPointFixed *first;
  146. int ntri;
  147. if (npoint < 3)
  148. return;
  149. ntri = npoint - 2;
  150. tris = ALLOCATE_LOCAL(ntri * sizeof(xTriangle));
  151. if (!tris)
  152. return;
  153. first = points++;
  154. for (tri = tris; npoint >= 3; npoint--, points++, tri++) {
  155. tri->p1 = *first;
  156. tri->p2 = points[0];
  157. tri->p3 = points[1];
  158. }
  159. (*ps->Triangles) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntri, tris);
  160. DEALLOCATE_LOCAL(tris);
  161. }