mirect.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. *
  3. * Copyright © 2000 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. static void
  34. miColorRects(PicturePtr pDst,
  35. PicturePtr pClipPict,
  36. xRenderColor * color,
  37. int nRect, xRectangle *rects, int xoff, int yoff)
  38. {
  39. ScreenPtr pScreen = pDst->pDrawable->pScreen;
  40. CARD32 pixel;
  41. GCPtr pGC;
  42. CARD32 tmpval[5];
  43. RegionPtr pClip;
  44. unsigned long mask;
  45. miRenderColorToPixel(pDst->pFormat, color, &pixel);
  46. pGC = GetScratchGC(pDst->pDrawable->depth, pScreen);
  47. if (!pGC)
  48. return;
  49. tmpval[0] = GXcopy;
  50. tmpval[1] = pixel;
  51. tmpval[2] = pDst->subWindowMode;
  52. mask = GCFunction | GCForeground | GCSubwindowMode;
  53. if (pClipPict->clientClipType == CT_REGION) {
  54. tmpval[3] = pDst->clipOrigin.x - xoff;
  55. tmpval[4] = pDst->clipOrigin.y - yoff;
  56. mask |= GCClipXOrigin | GCClipYOrigin;
  57. pClip = REGION_CREATE(NULL, 1);
  58. REGION_COPY(pClip, (RegionPtr) pClipPict->clientClip);
  59. (*pGC->funcs->ChangeClip) (pGC, CT_REGION, pClip, 0);
  60. }
  61. ChangeGC(pGC, mask, tmpval);
  62. ValidateGC(pDst->pDrawable, pGC);
  63. if (xoff || yoff) {
  64. int i;
  65. for (i = 0; i < nRect; i++) {
  66. rects[i].x -= xoff;
  67. rects[i].y -= yoff;
  68. }
  69. }
  70. (*pGC->ops->PolyFillRect) (pDst->pDrawable, pGC, nRect, rects);
  71. if (xoff || yoff) {
  72. int i;
  73. for (i = 0; i < nRect; i++) {
  74. rects[i].x += xoff;
  75. rects[i].y += yoff;
  76. }
  77. }
  78. FreeScratchGC(pGC);
  79. }
  80. _X_EXPORT void
  81. miCompositeRects(CARD8 op,
  82. PicturePtr pDst,
  83. xRenderColor * color, int nRect, xRectangle *rects)
  84. {
  85. ScreenPtr pScreen = pDst->pDrawable->pScreen;
  86. if (color->alpha == 0xffff) {
  87. if (op == PictOpOver)
  88. op = PictOpSrc;
  89. }
  90. if (op == PictOpClear)
  91. color->red = color->green = color->blue = color->alpha = 0;
  92. if (op == PictOpSrc || op == PictOpClear) {
  93. miColorRects(pDst, pDst, color, nRect, rects, 0, 0);
  94. if (pDst->alphaMap)
  95. miColorRects(pDst->alphaMap, pDst,
  96. color, nRect, rects,
  97. pDst->alphaOrigin.x, pDst->alphaOrigin.y);
  98. }
  99. else {
  100. PictFormatPtr rgbaFormat;
  101. PixmapPtr pPixmap;
  102. PicturePtr pSrc;
  103. xRectangle one;
  104. int error;
  105. Pixel pixel;
  106. GCPtr pGC;
  107. CARD32 tmpval[2];
  108. rgbaFormat = PictureMatchFormat(pScreen, 32, PICT_a8r8g8b8);
  109. if (!rgbaFormat)
  110. goto bail1;
  111. pPixmap = (*pScreen->CreatePixmap) (pScreen, 1, 1, rgbaFormat->depth);
  112. if (!pPixmap)
  113. goto bail2;
  114. miRenderColorToPixel(rgbaFormat, color, &pixel);
  115. pGC = GetScratchGC(rgbaFormat->depth, pScreen);
  116. if (!pGC)
  117. goto bail3;
  118. tmpval[0] = GXcopy;
  119. tmpval[1] = pixel;
  120. ChangeGC(pGC, GCFunction | GCForeground, tmpval);
  121. ValidateGC(&pPixmap->drawable, pGC);
  122. one.x = 0;
  123. one.y = 0;
  124. one.width = 1;
  125. one.height = 1;
  126. (*pGC->ops->PolyFillRect) (&pPixmap->drawable, pGC, 1, &one);
  127. tmpval[0] = xTrue;
  128. pSrc = CreatePicture(0, &pPixmap->drawable, rgbaFormat,
  129. CPRepeat, tmpval, 0, &error);
  130. if (!pSrc)
  131. goto bail4;
  132. while (nRect--) {
  133. CompositePicture(op, pSrc, 0, pDst, 0, 0, 0, 0,
  134. rects->x, rects->y, rects->width, rects->height);
  135. rects++;
  136. }
  137. FreePicture((pointer) pSrc, 0);
  138. bail4:
  139. FreeScratchGC(pGC);
  140. bail3:
  141. (*pScreen->DestroyPixmap) (pPixmap);
  142. bail2:
  143. bail1:
  144. ;
  145. }
  146. }