3 Copyright 1993, 1998 The Open Group
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
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
30 #ifdef HAVE_DIX_CONFIG_H
31 #include <dix-config.h>
34 #include "scrnintstr.h"
36 #include "pixmapstr.h"
37 #include "windowstr.h"
42 miChangeGC(GCPtr pGC, unsigned long mask)
48 miDestroyGC(GCPtr pGC)
50 if (pGC->pRotatedPixmap)
51 (*pGC->pScreen->DestroyPixmap) (pGC->pRotatedPixmap);
52 if (pGC->freeCompClip)
53 RegionDestroy(pGC->pCompositeClip);
57 miDestroyClip(GCPtr pGC)
59 if (pGC->clientClipType == CT_NONE)
61 else if (pGC->clientClipType == CT_PIXMAP)
63 (*pGC->pScreen->DestroyPixmap) ((PixmapPtr) (pGC->clientClip));
68 * we know we'll never have a list of rectangles, since ChangeClip
69 * immediately turns them into a region
71 RegionDestroy(pGC->clientClip);
73 pGC->clientClip = NULL;
74 pGC->clientClipType = CT_NONE;
78 miChangeClip( GCPtr pGC, int type, pointer pvalue, int nrects)
80 (*pGC->funcs->DestroyClip) (pGC);
81 if (type == CT_PIXMAP)
83 /* convert the pixmap to a region */
84 pGC->clientClip = (pointer) BitmapToRegion(pGC->pScreen,
86 (*pGC->pScreen->DestroyPixmap) (pvalue);
88 else if (type == CT_REGION)
90 /* stuff the region in the GC */
91 pGC->clientClip = pvalue;
93 else if (type != CT_NONE)
95 pGC->clientClip = (pointer) RegionFromRects(nrects,
96 (xRectangle *) pvalue,
100 pGC->clientClipType = (type != CT_NONE && pGC->clientClip) ? CT_REGION : CT_NONE;
101 pGC->stateChanges |= GCClipMask;
105 miCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
109 switch (pgcSrc->clientClipType)
112 ((PixmapPtr) pgcSrc->clientClip)->refcnt++;
113 /* Fall through !! */
115 (*pgcDst->funcs->ChangeClip) (pgcDst, (int) pgcSrc->clientClipType,
116 pgcSrc->clientClip, 0);
119 prgnNew = RegionCreate(NULL, 1);
120 RegionCopy(prgnNew, (RegionPtr) (pgcSrc->clientClip));
121 (*pgcDst->funcs->ChangeClip) (pgcDst, CT_REGION, (pointer) prgnNew, 0);
128 miCopyGC(GCPtr pGCSrc, unsigned long changes, GCPtr pGCDst)
134 miComputeCompositeClip( GCPtr pGC, DrawablePtr pDrawable)
136 if (pDrawable->type == DRAWABLE_WINDOW)
138 WindowPtr pWin = (WindowPtr) pDrawable;
140 Bool freeTmpClip, freeCompClip;
142 if (pGC->subWindowMode == IncludeInferiors)
144 pregWin = NotClippedByChildren(pWin);
149 pregWin = &pWin->clipList;
152 freeCompClip = pGC->freeCompClip;
155 * if there is no client clip, we can get by with just keeping the
156 * pointer we got, and remembering whether or not should destroy (or
157 * maybe re-use) it later. this way, we avoid unnecessary copying of
158 * regions. (this wins especially if many clients clip by children
159 * and have no client clip.)
161 if (pGC->clientClipType == CT_NONE)
164 RegionDestroy(pGC->pCompositeClip);
165 pGC->pCompositeClip = pregWin;
166 pGC->freeCompClip = freeTmpClip;
171 * we need one 'real' region to put into the composite clip. if
172 * pregWin the current composite clip are real, we can get rid of
173 * one. if pregWin is real and the current composite clip isn't,
174 * use pregWin for the composite clip. if the current composite
175 * clip is real and pregWin isn't, use the current composite
176 * clip. if neither is real, create a new region.
179 RegionTranslate(pGC->clientClip,
180 pDrawable->x + pGC->clipOrg.x,
181 pDrawable->y + pGC->clipOrg.y);
185 RegionIntersect(pGC->pCompositeClip,
186 pregWin, pGC->clientClip);
188 RegionDestroy(pregWin);
190 else if (freeTmpClip)
192 RegionIntersect(pregWin, pregWin, pGC->clientClip);
193 pGC->pCompositeClip = pregWin;
197 pGC->pCompositeClip = RegionCreate(NullBox, 0);
198 RegionIntersect(pGC->pCompositeClip,
199 pregWin, pGC->clientClip);
201 pGC->freeCompClip = TRUE;
202 RegionTranslate(pGC->clientClip,
203 -(pDrawable->x + pGC->clipOrg.x),
204 -(pDrawable->y + pGC->clipOrg.y));
206 } /* end of composite clip for a window */
211 /* XXX should we translate by drawable.x/y here ? */
212 /* If you want pixmaps in offscreen memory, yes */
213 pixbounds.x1 = pDrawable->x;
214 pixbounds.y1 = pDrawable->y;
215 pixbounds.x2 = pDrawable->x + pDrawable->width;
216 pixbounds.y2 = pDrawable->y + pDrawable->height;
218 if (pGC->freeCompClip)
220 RegionReset(pGC->pCompositeClip, &pixbounds);
224 pGC->freeCompClip = TRUE;
225 pGC->pCompositeClip = RegionCreate(&pixbounds, 1);
228 if (pGC->clientClipType == CT_REGION)
230 if(pDrawable->x || pDrawable->y) {
231 RegionTranslate(pGC->clientClip,
232 pDrawable->x + pGC->clipOrg.x,
233 pDrawable->y + pGC->clipOrg.y);
234 RegionIntersect(pGC->pCompositeClip,
235 pGC->pCompositeClip, pGC->clientClip);
236 RegionTranslate(pGC->clientClip,
237 -(pDrawable->x + pGC->clipOrg.x),
238 -(pDrawable->y + pGC->clipOrg.y));
240 RegionTranslate(pGC->pCompositeClip,
241 -pGC->clipOrg.x, -pGC->clipOrg.y);
242 RegionIntersect(pGC->pCompositeClip,
243 pGC->pCompositeClip, pGC->clientClip);
244 RegionTranslate(pGC->pCompositeClip,
245 pGC->clipOrg.x, pGC->clipOrg.y);
248 } /* end of composite clip for pixmap */
249 } /* end miComputeCompositeClip */