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
29 #ifdef HAVE_DIX_CONFIG_H
30 #include <dix-config.h>
33 #include "scrnintstr.h"
35 #include "pixmapstr.h"
36 #include "windowstr.h"
41 miChangeGC(GCPtr pGC
, unsigned long mask
)
47 miDestroyGC(GCPtr pGC
)
49 if (pGC
->pRotatedPixmap
)
50 (*pGC
->pScreen
->DestroyPixmap
) (pGC
->pRotatedPixmap
);
51 if (pGC
->freeCompClip
)
52 RegionDestroy(pGC
->pCompositeClip
);
56 miDestroyClip(GCPtr pGC
)
58 if (pGC
->clientClipType
== CT_NONE
)
60 else if (pGC
->clientClipType
== CT_PIXMAP
) {
61 (*pGC
->pScreen
->DestroyPixmap
) ((PixmapPtr
) (pGC
->clientClip
));
65 * we know we'll never have a list of rectangles, since ChangeClip
66 * immediately turns them into a region
68 RegionDestroy(pGC
->clientClip
);
70 pGC
->clientClip
= NULL
;
71 pGC
->clientClipType
= CT_NONE
;
75 miChangeClip(GCPtr pGC
, int type
, pointer pvalue
, int nrects
)
77 (*pGC
->funcs
->DestroyClip
) (pGC
);
78 if (type
== CT_PIXMAP
) {
79 /* convert the pixmap to a region */
80 pGC
->clientClip
= (pointer
) BitmapToRegion(pGC
->pScreen
,
82 (*pGC
->pScreen
->DestroyPixmap
) (pvalue
);
84 else if (type
== CT_REGION
) {
85 /* stuff the region in the GC */
86 pGC
->clientClip
= pvalue
;
88 else if (type
!= CT_NONE
) {
89 pGC
->clientClip
= (pointer
) RegionFromRects(nrects
,
90 (xRectangle
*) pvalue
,
94 pGC
->clientClipType
= (type
!= CT_NONE
&&
95 pGC
->clientClip
) ? CT_REGION
: CT_NONE
;
96 pGC
->stateChanges
|= GCClipMask
;
100 miCopyClip(GCPtr pgcDst
, GCPtr pgcSrc
)
104 switch (pgcSrc
->clientClipType
) {
106 ((PixmapPtr
) pgcSrc
->clientClip
)->refcnt
++;
107 /* Fall through !! */
109 (*pgcDst
->funcs
->ChangeClip
) (pgcDst
, (int) pgcSrc
->clientClipType
,
110 pgcSrc
->clientClip
, 0);
113 prgnNew
= RegionCreate(NULL
, 1);
114 RegionCopy(prgnNew
, (RegionPtr
) (pgcSrc
->clientClip
));
115 (*pgcDst
->funcs
->ChangeClip
) (pgcDst
, CT_REGION
, (pointer
) prgnNew
, 0);
122 miCopyGC(GCPtr pGCSrc
, unsigned long changes
, GCPtr pGCDst
)
128 miComputeCompositeClip(GCPtr pGC
, DrawablePtr pDrawable
)
130 if (pDrawable
->type
== DRAWABLE_WINDOW
) {
131 WindowPtr pWin
= (WindowPtr
) pDrawable
;
133 Bool freeTmpClip
, freeCompClip
;
135 if (pGC
->subWindowMode
== IncludeInferiors
) {
136 pregWin
= NotClippedByChildren(pWin
);
140 pregWin
= &pWin
->clipList
;
143 freeCompClip
= pGC
->freeCompClip
;
146 * if there is no client clip, we can get by with just keeping the
147 * pointer we got, and remembering whether or not should destroy (or
148 * maybe re-use) it later. this way, we avoid unnecessary copying of
149 * regions. (this wins especially if many clients clip by children
150 * and have no client clip.)
152 if (pGC
->clientClipType
== CT_NONE
) {
154 RegionDestroy(pGC
->pCompositeClip
);
155 pGC
->pCompositeClip
= pregWin
;
156 pGC
->freeCompClip
= freeTmpClip
;
160 * we need one 'real' region to put into the composite clip. if
161 * pregWin the current composite clip are real, we can get rid of
162 * one. if pregWin is real and the current composite clip isn't,
163 * use pregWin for the composite clip. if the current composite
164 * clip is real and pregWin isn't, use the current composite
165 * clip. if neither is real, create a new region.
168 RegionTranslate(pGC
->clientClip
,
169 pDrawable
->x
+ pGC
->clipOrg
.x
,
170 pDrawable
->y
+ pGC
->clipOrg
.y
);
173 RegionIntersect(pGC
->pCompositeClip
, pregWin
, pGC
->clientClip
);
175 RegionDestroy(pregWin
);
177 else if (freeTmpClip
) {
178 RegionIntersect(pregWin
, pregWin
, pGC
->clientClip
);
179 pGC
->pCompositeClip
= pregWin
;
182 pGC
->pCompositeClip
= RegionCreate(NullBox
, 0);
183 RegionIntersect(pGC
->pCompositeClip
, pregWin
, pGC
->clientClip
);
185 pGC
->freeCompClip
= TRUE
;
186 RegionTranslate(pGC
->clientClip
,
187 -(pDrawable
->x
+ pGC
->clipOrg
.x
),
188 -(pDrawable
->y
+ pGC
->clipOrg
.y
));
190 } /* end of composite clip for a window */
194 /* XXX should we translate by drawable.x/y here ? */
195 /* If you want pixmaps in offscreen memory, yes */
196 pixbounds
.x1
= pDrawable
->x
;
197 pixbounds
.y1
= pDrawable
->y
;
198 pixbounds
.x2
= pDrawable
->x
+ pDrawable
->width
;
199 pixbounds
.y2
= pDrawable
->y
+ pDrawable
->height
;
201 if (pGC
->freeCompClip
) {
202 RegionReset(pGC
->pCompositeClip
, &pixbounds
);
205 pGC
->freeCompClip
= TRUE
;
206 pGC
->pCompositeClip
= RegionCreate(&pixbounds
, 1);
209 if (pGC
->clientClipType
== CT_REGION
) {
210 if (pDrawable
->x
|| pDrawable
->y
) {
211 RegionTranslate(pGC
->clientClip
,
212 pDrawable
->x
+ pGC
->clipOrg
.x
,
213 pDrawable
->y
+ pGC
->clipOrg
.y
);
214 RegionIntersect(pGC
->pCompositeClip
,
215 pGC
->pCompositeClip
, pGC
->clientClip
);
216 RegionTranslate(pGC
->clientClip
,
217 -(pDrawable
->x
+ pGC
->clipOrg
.x
),
218 -(pDrawable
->y
+ pGC
->clipOrg
.y
));
221 RegionTranslate(pGC
->pCompositeClip
,
222 -pGC
->clipOrg
.x
, -pGC
->clipOrg
.y
);
223 RegionIntersect(pGC
->pCompositeClip
,
224 pGC
->pCompositeClip
, pGC
->clientClip
);
225 RegionTranslate(pGC
->pCompositeClip
,
226 pGC
->clipOrg
.x
, pGC
->clipOrg
.y
);
229 } /* end of composite clip for pixmap */
230 } /* end miComputeCompositeClip */