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"
53 if (pGC
->pRotatedPixmap
)
54 (*pGC
->pScreen
->DestroyPixmap
) (pGC
->pRotatedPixmap
);
55 if (pGC
->freeCompClip
)
56 REGION_DESTROY(pGC
->pScreen
, pGC
->pCompositeClip
);
57 miDestroyGCOps(pGC
->ops
);
61 * create a private op array for a gc
65 miCreateGCOps(prototype
)
70 /* XXX */ Must_have_memory
= TRUE
;
71 ret
= (GCOpsPtr
) xalloc(sizeof(GCOps
));
72 /* XXX */ Must_have_memory
= FALSE
;
76 ret
->devPrivate
.val
= 1;
84 if (ops
->devPrivate
.val
)
93 if (pGC
->clientClipType
== CT_NONE
)
95 else if (pGC
->clientClipType
== CT_PIXMAP
)
97 (*pGC
->pScreen
->DestroyPixmap
) ((PixmapPtr
) (pGC
->clientClip
));
102 * we know we'll never have a list of rectangles, since ChangeClip
103 * immediately turns them into a region
105 REGION_DESTROY(pGC
->pScreen
, pGC
->clientClip
);
107 pGC
->clientClip
= NULL
;
108 pGC
->clientClipType
= CT_NONE
;
112 miChangeClip(pGC
, type
, pvalue
, nrects
)
118 (*pGC
->funcs
->DestroyClip
) (pGC
);
119 if (type
== CT_PIXMAP
)
121 /* convert the pixmap to a region */
122 pGC
->clientClip
= (pointer
) BITMAP_TO_REGION(pGC
->pScreen
,
124 (*pGC
->pScreen
->DestroyPixmap
) (pvalue
);
126 else if (type
== CT_REGION
)
128 /* stuff the region in the GC */
129 pGC
->clientClip
= pvalue
;
131 else if (type
!= CT_NONE
)
133 pGC
->clientClip
= (pointer
) RECTS_TO_REGION(pGC
->pScreen
, nrects
,
134 (xRectangle
*) pvalue
,
138 pGC
->clientClipType
= (type
!= CT_NONE
&& pGC
->clientClip
) ? CT_REGION
: CT_NONE
;
139 pGC
->stateChanges
|= GCClipMask
;
143 miCopyClip(pgcDst
, pgcSrc
)
144 GCPtr pgcDst
, pgcSrc
;
148 switch (pgcSrc
->clientClipType
)
151 ((PixmapPtr
) pgcSrc
->clientClip
)->refcnt
++;
152 /* Fall through !! */
154 (*pgcDst
->funcs
->ChangeClip
) (pgcDst
, (int) pgcSrc
->clientClipType
,
155 pgcSrc
->clientClip
, 0);
158 prgnNew
= REGION_CREATE(pgcSrc
->pScreen
, NULL
, 1);
159 REGION_COPY(pgcDst
->pScreen
, prgnNew
,
160 (RegionPtr
) (pgcSrc
->clientClip
));
161 (*pgcDst
->funcs
->ChangeClip
) (pgcDst
, CT_REGION
, (pointer
) prgnNew
, 0);
168 miCopyGC(pGCSrc
, changes
, pGCDst
)
170 unsigned long changes
;
177 miComputeCompositeClip(pGC
, pDrawable
)
179 DrawablePtr pDrawable
;
183 /* This prevents warnings about pScreen not being used. */
184 pGC
->pScreen
= pScreen
= pGC
->pScreen
;
186 if (pDrawable
->type
== DRAWABLE_WINDOW
)
188 WindowPtr pWin
= (WindowPtr
) pDrawable
;
190 Bool freeTmpClip
, freeCompClip
;
192 if (pGC
->subWindowMode
== IncludeInferiors
)
194 pregWin
= NotClippedByChildren(pWin
);
199 pregWin
= &pWin
->clipList
;
202 freeCompClip
= pGC
->freeCompClip
;
205 * if there is no client clip, we can get by with just keeping the
206 * pointer we got, and remembering whether or not should destroy (or
207 * maybe re-use) it later. this way, we avoid unnecessary copying of
208 * regions. (this wins especially if many clients clip by children
209 * and have no client clip.)
211 if (pGC
->clientClipType
== CT_NONE
)
214 REGION_DESTROY(pScreen
, pGC
->pCompositeClip
);
215 pGC
->pCompositeClip
= pregWin
;
216 pGC
->freeCompClip
= freeTmpClip
;
221 * we need one 'real' region to put into the composite clip. if
222 * pregWin the current composite clip are real, we can get rid of
223 * one. if pregWin is real and the current composite clip isn't,
224 * use pregWin for the composite clip. if the current composite
225 * clip is real and pregWin isn't, use the current composite
226 * clip. if neither is real, create a new region.
229 REGION_TRANSLATE(pScreen
, pGC
->clientClip
,
230 pDrawable
->x
+ pGC
->clipOrg
.x
,
231 pDrawable
->y
+ pGC
->clipOrg
.y
);
235 REGION_INTERSECT(pGC
->pScreen
, pGC
->pCompositeClip
,
236 pregWin
, pGC
->clientClip
);
238 REGION_DESTROY(pScreen
, pregWin
);
240 else if (freeTmpClip
)
242 REGION_INTERSECT(pScreen
, pregWin
, pregWin
, pGC
->clientClip
);
243 pGC
->pCompositeClip
= pregWin
;
247 pGC
->pCompositeClip
= REGION_CREATE(pScreen
, NullBox
, 0);
248 REGION_INTERSECT(pScreen
, pGC
->pCompositeClip
,
249 pregWin
, pGC
->clientClip
);
251 pGC
->freeCompClip
= TRUE
;
252 REGION_TRANSLATE(pScreen
, pGC
->clientClip
,
253 -(pDrawable
->x
+ pGC
->clipOrg
.x
),
254 -(pDrawable
->y
+ pGC
->clipOrg
.y
));
256 } /* end of composite clip for a window */
261 /* XXX should we translate by drawable.x/y here ? */
262 /* If you want pixmaps in offscreen memory, yes */
263 pixbounds
.x1
= pDrawable
->x
;
264 pixbounds
.y1
= pDrawable
->y
;
265 pixbounds
.x2
= pDrawable
->x
+ pDrawable
->width
;
266 pixbounds
.y2
= pDrawable
->y
+ pDrawable
->height
;
268 if (pGC
->freeCompClip
)
270 REGION_RESET(pScreen
, pGC
->pCompositeClip
, &pixbounds
);
274 pGC
->freeCompClip
= TRUE
;
275 pGC
->pCompositeClip
= REGION_CREATE(pScreen
, &pixbounds
, 1);
278 if (pGC
->clientClipType
== CT_REGION
)
280 if(pDrawable
->x
|| pDrawable
->y
) {
281 REGION_TRANSLATE(pScreen
, pGC
->clientClip
,
282 pDrawable
->x
+ pGC
->clipOrg
.x
,
283 pDrawable
->y
+ pGC
->clipOrg
.y
);
284 REGION_INTERSECT(pScreen
, pGC
->pCompositeClip
,
285 pGC
->pCompositeClip
, pGC
->clientClip
);
286 REGION_TRANSLATE(pScreen
, pGC
->clientClip
,
287 -(pDrawable
->x
+ pGC
->clipOrg
.x
),
288 -(pDrawable
->y
+ pGC
->clipOrg
.y
));
290 REGION_TRANSLATE(pScreen
, pGC
->pCompositeClip
,
291 -pGC
->clipOrg
.x
, -pGC
->clipOrg
.y
);
292 REGION_INTERSECT(pScreen
, pGC
->pCompositeClip
,
293 pGC
->pCompositeClip
, pGC
->clientClip
);
294 REGION_TRANSLATE(pScreen
, pGC
->pCompositeClip
,
295 pGC
->clipOrg
.x
, pGC
->clipOrg
.y
);
298 } /* end of composite clip for pixmap */
299 } /* end miComputeCompositeClip */