1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Permission to use, copy, modify, distribute, and sell this software and its
6*4882a593Smuzhiyun * documentation for any purpose is hereby granted without fee, provided that
7*4882a593Smuzhiyun * the above copyright notice appear in all copies and that both that
8*4882a593Smuzhiyun * copyright notice and this permission notice appear in supporting
9*4882a593Smuzhiyun * documentation, and that the name of Keith Packard not be used in
10*4882a593Smuzhiyun * advertising or publicity pertaining to distribution of the software without
11*4882a593Smuzhiyun * specific, written prior permission. Keith Packard makes no
12*4882a593Smuzhiyun * representations about the suitability of this software for any purpose. It
13*4882a593Smuzhiyun * is provided "as is" without express or implied warranty.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16*4882a593Smuzhiyun * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17*4882a593Smuzhiyun * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18*4882a593Smuzhiyun * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19*4882a593Smuzhiyun * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20*4882a593Smuzhiyun * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21*4882a593Smuzhiyun * PERFORMANCE OF THIS SOFTWARE.
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
25*4882a593Smuzhiyun #include <dix-config.h>
26*4882a593Smuzhiyun #endif
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun #include "scrnintstr.h"
29*4882a593Smuzhiyun #include "gcstruct.h"
30*4882a593Smuzhiyun #include "pixmapstr.h"
31*4882a593Smuzhiyun #include "windowstr.h"
32*4882a593Smuzhiyun #include "mi.h"
33*4882a593Smuzhiyun #include "picturestr.h"
34*4882a593Smuzhiyun #include "mipict.h"
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun static void
miColorRects(PicturePtr pDst,PicturePtr pClipPict,xRenderColor * color,int nRect,xRectangle * rects,int xoff,int yoff)37*4882a593Smuzhiyun miColorRects(PicturePtr pDst,
38*4882a593Smuzhiyun PicturePtr pClipPict,
39*4882a593Smuzhiyun xRenderColor * color,
40*4882a593Smuzhiyun int nRect, xRectangle *rects, int xoff, int yoff)
41*4882a593Smuzhiyun {
42*4882a593Smuzhiyun CARD32 pixel;
43*4882a593Smuzhiyun GCPtr pGC;
44*4882a593Smuzhiyun ChangeGCVal tmpval[5];
45*4882a593Smuzhiyun RegionPtr pClip;
46*4882a593Smuzhiyun unsigned long mask;
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun miRenderColorToPixel(pDst->pFormat, color, &pixel);
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun pGC = GetScratchGC(pDst->pDrawable->depth, pDst->pDrawable->pScreen);
51*4882a593Smuzhiyun if (!pGC)
52*4882a593Smuzhiyun return;
53*4882a593Smuzhiyun tmpval[0].val = GXcopy;
54*4882a593Smuzhiyun tmpval[1].val = pixel;
55*4882a593Smuzhiyun tmpval[2].val = pDst->subWindowMode;
56*4882a593Smuzhiyun mask = GCFunction | GCForeground | GCSubwindowMode;
57*4882a593Smuzhiyun if (pClipPict->clientClip) {
58*4882a593Smuzhiyun tmpval[3].val = pDst->clipOrigin.x - xoff;
59*4882a593Smuzhiyun tmpval[4].val = pDst->clipOrigin.y - yoff;
60*4882a593Smuzhiyun mask |= GCClipXOrigin | GCClipYOrigin;
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun pClip = RegionCreate(NULL, 1);
63*4882a593Smuzhiyun RegionCopy(pClip, (RegionPtr) pClipPict->clientClip);
64*4882a593Smuzhiyun (*pGC->funcs->ChangeClip) (pGC, CT_REGION, pClip, 0);
65*4882a593Smuzhiyun }
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun ChangeGC(NullClient, pGC, mask, tmpval);
68*4882a593Smuzhiyun ValidateGC(pDst->pDrawable, pGC);
69*4882a593Smuzhiyun if (xoff || yoff) {
70*4882a593Smuzhiyun int i;
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun for (i = 0; i < nRect; i++) {
73*4882a593Smuzhiyun rects[i].x -= xoff;
74*4882a593Smuzhiyun rects[i].y -= yoff;
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun (*pGC->ops->PolyFillRect) (pDst->pDrawable, pGC, nRect, rects);
78*4882a593Smuzhiyun if (xoff || yoff) {
79*4882a593Smuzhiyun int i;
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun for (i = 0; i < nRect; i++) {
82*4882a593Smuzhiyun rects[i].x += xoff;
83*4882a593Smuzhiyun rects[i].y += yoff;
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun FreeScratchGC(pGC);
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun void
miCompositeRects(CARD8 op,PicturePtr pDst,xRenderColor * color,int nRect,xRectangle * rects)90*4882a593Smuzhiyun miCompositeRects(CARD8 op,
91*4882a593Smuzhiyun PicturePtr pDst,
92*4882a593Smuzhiyun xRenderColor * color, int nRect, xRectangle *rects)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun if (color->alpha == 0xffff) {
95*4882a593Smuzhiyun if (op == PictOpOver)
96*4882a593Smuzhiyun op = PictOpSrc;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun if (op == PictOpClear)
99*4882a593Smuzhiyun color->red = color->green = color->blue = color->alpha = 0;
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun if (op == PictOpSrc || op == PictOpClear) {
102*4882a593Smuzhiyun miColorRects(pDst, pDst, color, nRect, rects, 0, 0);
103*4882a593Smuzhiyun if (pDst->alphaMap)
104*4882a593Smuzhiyun miColorRects(pDst->alphaMap, pDst,
105*4882a593Smuzhiyun color, nRect, rects,
106*4882a593Smuzhiyun pDst->alphaOrigin.x, pDst->alphaOrigin.y);
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun else {
109*4882a593Smuzhiyun int error;
110*4882a593Smuzhiyun PicturePtr pSrc = CreateSolidPicture(0, color, &error);
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun if (pSrc) {
113*4882a593Smuzhiyun while (nRect--) {
114*4882a593Smuzhiyun CompositePicture(op, pSrc, 0, pDst, 0, 0, 0, 0,
115*4882a593Smuzhiyun rects->x, rects->y,
116*4882a593Smuzhiyun rects->width, rects->height);
117*4882a593Smuzhiyun rects++;
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun FreePicture((void *) pSrc, 0);
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun }
124