Imported Upstream version 1.15.1
[deb_xorg-server.git] / mi / migc.c
1 /*
2
3 Copyright 1993, 1998 The Open Group
4
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.
10
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13
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.
21
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.
26
27 */
28
29 #ifdef HAVE_DIX_CONFIG_H
30 #include <dix-config.h>
31 #endif
32
33 #include "scrnintstr.h"
34 #include "gcstruct.h"
35 #include "pixmapstr.h"
36 #include "windowstr.h"
37 #include "migc.h"
38
39 /* ARGSUSED */
40 void
41 miChangeGC(GCPtr pGC, unsigned long mask)
42 {
43 return;
44 }
45
46 void
47 miDestroyGC(GCPtr pGC)
48 {
49 if (pGC->pRotatedPixmap)
50 (*pGC->pScreen->DestroyPixmap) (pGC->pRotatedPixmap);
51 if (pGC->freeCompClip)
52 RegionDestroy(pGC->pCompositeClip);
53 }
54
55 void
56 miDestroyClip(GCPtr pGC)
57 {
58 if (pGC->clientClipType == CT_NONE)
59 return;
60 else if (pGC->clientClipType == CT_PIXMAP) {
61 (*pGC->pScreen->DestroyPixmap) ((PixmapPtr) (pGC->clientClip));
62 }
63 else {
64 /*
65 * we know we'll never have a list of rectangles, since ChangeClip
66 * immediately turns them into a region
67 */
68 RegionDestroy(pGC->clientClip);
69 }
70 pGC->clientClip = NULL;
71 pGC->clientClipType = CT_NONE;
72 }
73
74 void
75 miChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects)
76 {
77 (*pGC->funcs->DestroyClip) (pGC);
78 if (type == CT_PIXMAP) {
79 /* convert the pixmap to a region */
80 pGC->clientClip = (pointer) BitmapToRegion(pGC->pScreen,
81 (PixmapPtr) pvalue);
82 (*pGC->pScreen->DestroyPixmap) (pvalue);
83 }
84 else if (type == CT_REGION) {
85 /* stuff the region in the GC */
86 pGC->clientClip = pvalue;
87 }
88 else if (type != CT_NONE) {
89 pGC->clientClip = (pointer) RegionFromRects(nrects,
90 (xRectangle *) pvalue,
91 type);
92 free(pvalue);
93 }
94 pGC->clientClipType = (type != CT_NONE &&
95 pGC->clientClip) ? CT_REGION : CT_NONE;
96 pGC->stateChanges |= GCClipMask;
97 }
98
99 void
100 miCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
101 {
102 RegionPtr prgnNew;
103
104 switch (pgcSrc->clientClipType) {
105 case CT_PIXMAP:
106 ((PixmapPtr) pgcSrc->clientClip)->refcnt++;
107 /* Fall through !! */
108 case CT_NONE:
109 (*pgcDst->funcs->ChangeClip) (pgcDst, (int) pgcSrc->clientClipType,
110 pgcSrc->clientClip, 0);
111 break;
112 case CT_REGION:
113 prgnNew = RegionCreate(NULL, 1);
114 RegionCopy(prgnNew, (RegionPtr) (pgcSrc->clientClip));
115 (*pgcDst->funcs->ChangeClip) (pgcDst, CT_REGION, (pointer) prgnNew, 0);
116 break;
117 }
118 }
119
120 /* ARGSUSED */
121 void
122 miCopyGC(GCPtr pGCSrc, unsigned long changes, GCPtr pGCDst)
123 {
124 return;
125 }
126
127 void
128 miComputeCompositeClip(GCPtr pGC, DrawablePtr pDrawable)
129 {
130 if (pDrawable->type == DRAWABLE_WINDOW) {
131 WindowPtr pWin = (WindowPtr) pDrawable;
132 RegionPtr pregWin;
133 Bool freeTmpClip, freeCompClip;
134
135 if (pGC->subWindowMode == IncludeInferiors) {
136 pregWin = NotClippedByChildren(pWin);
137 freeTmpClip = TRUE;
138 }
139 else {
140 pregWin = &pWin->clipList;
141 freeTmpClip = FALSE;
142 }
143 freeCompClip = pGC->freeCompClip;
144
145 /*
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.)
151 */
152 if (pGC->clientClipType == CT_NONE) {
153 if (freeCompClip)
154 RegionDestroy(pGC->pCompositeClip);
155 pGC->pCompositeClip = pregWin;
156 pGC->freeCompClip = freeTmpClip;
157 }
158 else {
159 /*
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.
166 */
167
168 RegionTranslate(pGC->clientClip,
169 pDrawable->x + pGC->clipOrg.x,
170 pDrawable->y + pGC->clipOrg.y);
171
172 if (freeCompClip) {
173 RegionIntersect(pGC->pCompositeClip, pregWin, pGC->clientClip);
174 if (freeTmpClip)
175 RegionDestroy(pregWin);
176 }
177 else if (freeTmpClip) {
178 RegionIntersect(pregWin, pregWin, pGC->clientClip);
179 pGC->pCompositeClip = pregWin;
180 }
181 else {
182 pGC->pCompositeClip = RegionCreate(NullBox, 0);
183 RegionIntersect(pGC->pCompositeClip, pregWin, pGC->clientClip);
184 }
185 pGC->freeCompClip = TRUE;
186 RegionTranslate(pGC->clientClip,
187 -(pDrawable->x + pGC->clipOrg.x),
188 -(pDrawable->y + pGC->clipOrg.y));
189 }
190 } /* end of composite clip for a window */
191 else {
192 BoxRec pixbounds;
193
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;
200
201 if (pGC->freeCompClip) {
202 RegionReset(pGC->pCompositeClip, &pixbounds);
203 }
204 else {
205 pGC->freeCompClip = TRUE;
206 pGC->pCompositeClip = RegionCreate(&pixbounds, 1);
207 }
208
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));
219 }
220 else {
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);
227 }
228 }
229 } /* end of composite clip for pixmap */
230 } /* end miComputeCompositeClip */