Initial commit
[xorg_rtime.git] / xorg-server-1.4 / render / mirect.c
blob87767a76cd388eb493e7915f7ff285e4f305c564
1 /*
3 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
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.
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.
24 #ifdef HAVE_DIX_CONFIG_H
25 #include <dix-config.h>
26 #endif
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"
36 static void
37 miColorRects (PicturePtr pDst,
38 PicturePtr pClipPict,
39 xRenderColor *color,
40 int nRect,
41 xRectangle *rects,
42 int xoff,
43 int yoff)
45 ScreenPtr pScreen = pDst->pDrawable->pScreen;
46 CARD32 pixel;
47 GCPtr pGC;
48 CARD32 tmpval[5];
49 RegionPtr pClip;
50 unsigned long mask;
52 miRenderColorToPixel (pDst->pFormat, color, &pixel);
54 pGC = GetScratchGC (pDst->pDrawable->depth, pScreen);
55 if (!pGC)
56 return;
57 tmpval[0] = GXcopy;
58 tmpval[1] = pixel;
59 tmpval[2] = pDst->subWindowMode;
60 mask = GCFunction | GCForeground | GCSubwindowMode;
61 if (pClipPict->clientClipType == CT_REGION)
63 tmpval[3] = pDst->clipOrigin.x - xoff;
64 tmpval[4] = pDst->clipOrigin.y - yoff;
65 mask |= GCClipXOrigin|GCClipYOrigin;
67 pClip = REGION_CREATE (pScreen, NULL, 1);
68 REGION_COPY (pScreen, pClip,
69 (RegionPtr) pClipPict->clientClip);
70 (*pGC->funcs->ChangeClip) (pGC, CT_REGION, pClip, 0);
73 ChangeGC (pGC, mask, tmpval);
74 ValidateGC (pDst->pDrawable, pGC);
75 if (xoff || yoff)
77 int i;
78 for (i = 0; i < nRect; i++)
80 rects[i].x -= xoff;
81 rects[i].y -= yoff;
84 (*pGC->ops->PolyFillRect) (pDst->pDrawable, pGC, nRect, rects);
85 if (xoff || yoff)
87 int i;
88 for (i = 0; i < nRect; i++)
90 rects[i].x += xoff;
91 rects[i].y += yoff;
94 FreeScratchGC (pGC);
97 _X_EXPORT void
98 miCompositeRects (CARD8 op,
99 PicturePtr pDst,
100 xRenderColor *color,
101 int nRect,
102 xRectangle *rects)
104 ScreenPtr pScreen = pDst->pDrawable->pScreen;
106 if (color->alpha == 0xffff)
108 if (op == PictOpOver)
109 op = PictOpSrc;
111 if (op == PictOpClear)
112 color->red = color->green = color->blue = color->alpha = 0;
114 if (op == PictOpSrc || op == PictOpClear)
116 miColorRects (pDst, pDst, color, nRect, rects, 0, 0);
117 if (pDst->alphaMap)
118 miColorRects (pDst->alphaMap, pDst,
119 color, nRect, rects,
120 pDst->alphaOrigin.x,
121 pDst->alphaOrigin.y);
123 else
125 PictFormatPtr rgbaFormat;
126 PixmapPtr pPixmap;
127 PicturePtr pSrc;
128 xRectangle one;
129 int error;
130 Pixel pixel;
131 GCPtr pGC;
132 CARD32 tmpval[2];
134 rgbaFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8);
135 if (!rgbaFormat)
136 goto bail1;
138 pPixmap = (*pScreen->CreatePixmap) (pScreen, 1, 1,
139 rgbaFormat->depth);
140 if (!pPixmap)
141 goto bail2;
143 miRenderColorToPixel (rgbaFormat, color, &pixel);
145 pGC = GetScratchGC (rgbaFormat->depth, pScreen);
146 if (!pGC)
147 goto bail3;
148 tmpval[0] = GXcopy;
149 tmpval[1] = pixel;
151 ChangeGC (pGC, GCFunction | GCForeground, tmpval);
152 ValidateGC (&pPixmap->drawable, pGC);
153 one.x = 0;
154 one.y = 0;
155 one.width = 1;
156 one.height = 1;
157 (*pGC->ops->PolyFillRect) (&pPixmap->drawable, pGC, 1, &one);
159 tmpval[0] = xTrue;
160 pSrc = CreatePicture (0, &pPixmap->drawable, rgbaFormat,
161 CPRepeat, tmpval, 0, &error);
163 if (!pSrc)
164 goto bail4;
166 while (nRect--)
168 CompositePicture (op, pSrc, 0, pDst, 0, 0, 0, 0,
169 rects->x,
170 rects->y,
171 rects->width,
172 rects->height);
173 rects++;
176 FreePicture ((pointer) pSrc, 0);
177 bail4:
178 FreeScratchGC (pGC);
179 bail3:
180 (*pScreen->DestroyPixmap) (pPixmap);
181 bail2:
182 bail1: