First import
[xorg_rtime.git] / xorg-server-1.4 / mi / migc.c
blob46643ab2664db3e93e728548e032ca751e75166a
1 /*
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
9 documentation.
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
25 from The Open Group.
30 #ifdef HAVE_DIX_CONFIG_H
31 #include <dix-config.h>
32 #endif
34 #include "scrnintstr.h"
35 #include "gcstruct.h"
36 #include "pixmapstr.h"
37 #include "windowstr.h"
38 #include "migc.h"
40 /* ARGSUSED */
41 _X_EXPORT void
42 miChangeGC(pGC, mask)
43 GCPtr pGC;
44 unsigned long mask;
46 return;
49 _X_EXPORT void
50 miDestroyGC(pGC)
51 GCPtr pGC;
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
64 _X_EXPORT GCOpsPtr
65 miCreateGCOps(prototype)
66 GCOpsPtr prototype;
68 GCOpsPtr ret;
70 /* XXX */ Must_have_memory = TRUE;
71 ret = (GCOpsPtr) xalloc(sizeof(GCOps));
72 /* XXX */ Must_have_memory = FALSE;
73 if (!ret)
74 return 0;
75 *ret = *prototype;
76 ret->devPrivate.val = 1;
77 return ret;
80 _X_EXPORT void
81 miDestroyGCOps(ops)
82 GCOpsPtr ops;
84 if (ops->devPrivate.val)
85 xfree(ops);
89 _X_EXPORT void
90 miDestroyClip(pGC)
91 GCPtr pGC;
93 if (pGC->clientClipType == CT_NONE)
94 return;
95 else if (pGC->clientClipType == CT_PIXMAP)
97 (*pGC->pScreen->DestroyPixmap) ((PixmapPtr) (pGC->clientClip));
99 else
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;
111 _X_EXPORT void
112 miChangeClip(pGC, type, pvalue, nrects)
113 GCPtr pGC;
114 int type;
115 pointer pvalue;
116 int 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,
123 (PixmapPtr) pvalue);
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,
135 type);
136 xfree(pvalue);
138 pGC->clientClipType = (type != CT_NONE && pGC->clientClip) ? CT_REGION : CT_NONE;
139 pGC->stateChanges |= GCClipMask;
142 _X_EXPORT void
143 miCopyClip(pgcDst, pgcSrc)
144 GCPtr pgcDst, pgcSrc;
146 RegionPtr prgnNew;
148 switch (pgcSrc->clientClipType)
150 case CT_PIXMAP:
151 ((PixmapPtr) pgcSrc->clientClip)->refcnt++;
152 /* Fall through !! */
153 case CT_NONE:
154 (*pgcDst->funcs->ChangeClip) (pgcDst, (int) pgcSrc->clientClipType,
155 pgcSrc->clientClip, 0);
156 break;
157 case CT_REGION:
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);
162 break;
166 /* ARGSUSED */
167 _X_EXPORT void
168 miCopyGC(pGCSrc, changes, pGCDst)
169 GCPtr pGCSrc;
170 unsigned long changes;
171 GCPtr pGCDst;
173 return;
176 _X_EXPORT void
177 miComputeCompositeClip(pGC, pDrawable)
178 GCPtr pGC;
179 DrawablePtr pDrawable;
181 ScreenPtr pScreen;
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;
189 RegionPtr pregWin;
190 Bool freeTmpClip, freeCompClip;
192 if (pGC->subWindowMode == IncludeInferiors)
194 pregWin = NotClippedByChildren(pWin);
195 freeTmpClip = TRUE;
197 else
199 pregWin = &pWin->clipList;
200 freeTmpClip = FALSE;
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)
213 if (freeCompClip)
214 REGION_DESTROY(pScreen, pGC->pCompositeClip);
215 pGC->pCompositeClip = pregWin;
216 pGC->freeCompClip = freeTmpClip;
218 else
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);
233 if (freeCompClip)
235 REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
236 pregWin, pGC->clientClip);
237 if (freeTmpClip)
238 REGION_DESTROY(pScreen, pregWin);
240 else if (freeTmpClip)
242 REGION_INTERSECT(pScreen, pregWin, pregWin, pGC->clientClip);
243 pGC->pCompositeClip = pregWin;
245 else
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 */
257 else
259 BoxRec pixbounds;
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);
272 else
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));
289 } else {
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 */