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
24 #ifdef HAVE_DIX_CONFIG_H
25 #include <dix-config.h>
26 #endif
27
28 #include "scrnintstr.h"
29 #include "gcstruct.h"
30 #include "pixmapstr.h"
31 #include "windowstr.h"
32 #include "mi.h"
33 #include "picturestr.h"
34 #include "mipict.h"
35
36 static void
miColorRects(PicturePtr pDst,PicturePtr pClipPict,xRenderColor * color,int nRect,xRectangle * rects,int xoff,int yoff)37 miColorRects(PicturePtr pDst,
38 PicturePtr pClipPict,
39 xRenderColor * color,
40 int nRect, xRectangle *rects, int xoff, int yoff)
41 {
42 CARD32 pixel;
43 GCPtr pGC;
44 ChangeGCVal tmpval[5];
45 RegionPtr pClip;
46 unsigned long mask;
47
48 miRenderColorToPixel(pDst->pFormat, color, &pixel);
49
50 pGC = GetScratchGC(pDst->pDrawable->depth, pDst->pDrawable->pScreen);
51 if (!pGC)
52 return;
53 tmpval[0].val = GXcopy;
54 tmpval[1].val = pixel;
55 tmpval[2].val = pDst->subWindowMode;
56 mask = GCFunction | GCForeground | GCSubwindowMode;
57 if (pClipPict->clientClip) {
58 tmpval[3].val = pDst->clipOrigin.x - xoff;
59 tmpval[4].val = pDst->clipOrigin.y - yoff;
60 mask |= GCClipXOrigin | GCClipYOrigin;
61
62 pClip = RegionCreate(NULL, 1);
63 RegionCopy(pClip, (RegionPtr) pClipPict->clientClip);
64 (*pGC->funcs->ChangeClip) (pGC, CT_REGION, pClip, 0);
65 }
66
67 ChangeGC(NullClient, pGC, mask, tmpval);
68 ValidateGC(pDst->pDrawable, pGC);
69 if (xoff || yoff) {
70 int i;
71
72 for (i = 0; i < nRect; i++) {
73 rects[i].x -= xoff;
74 rects[i].y -= yoff;
75 }
76 }
77 (*pGC->ops->PolyFillRect) (pDst->pDrawable, pGC, nRect, rects);
78 if (xoff || yoff) {
79 int i;
80
81 for (i = 0; i < nRect; i++) {
82 rects[i].x += xoff;
83 rects[i].y += yoff;
84 }
85 }
86 FreeScratchGC(pGC);
87 }
88
89 void
miCompositeRects(CARD8 op,PicturePtr pDst,xRenderColor * color,int nRect,xRectangle * rects)90 miCompositeRects(CARD8 op,
91 PicturePtr pDst,
92 xRenderColor * color, int nRect, xRectangle *rects)
93 {
94 if (color->alpha == 0xffff) {
95 if (op == PictOpOver)
96 op = PictOpSrc;
97 }
98 if (op == PictOpClear)
99 color->red = color->green = color->blue = color->alpha = 0;
100
101 if (op == PictOpSrc || op == PictOpClear) {
102 miColorRects(pDst, pDst, color, nRect, rects, 0, 0);
103 if (pDst->alphaMap)
104 miColorRects(pDst->alphaMap, pDst,
105 color, nRect, rects,
106 pDst->alphaOrigin.x, pDst->alphaOrigin.y);
107 }
108 else {
109 int error;
110 PicturePtr pSrc = CreateSolidPicture(0, color, &error);
111
112 if (pSrc) {
113 while (nRect--) {
114 CompositePicture(op, pSrc, 0, pDst, 0, 0, 0, 0,
115 rects->x, rects->y,
116 rects->width, rects->height);
117 rects++;
118 }
119
120 FreePicture((void *) pSrc, 0);
121 }
122 }
123 }
124