Region.c revision 4456fccd
1/*
2 * $Id: Region.c,v 1.1.1.1 2008/07/30 02:48:24 mrg Exp $
3 *
4 * Copyright © 2003 Keith Packard
5 *
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission.  Keith Packard makes no
13 * representations about the suitability of this software for any purpose.  It
14 * is provided "as is" without express or implied warranty.
15 *
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
23 */
24
25#ifdef HAVE_CONFIG_H
26#include <config.h>
27#endif
28#include "Xfixesint.h"
29
30XserverRegion
31XFixesCreateRegion (Display *dpy, XRectangle *rectangles, int nrectangles)
32{
33    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
34    xXFixesCreateRegionReq	*req;
35    long    			len;
36    XserverRegion		region;
37
38    XFixesCheckExtension (dpy, info, 0);
39    LockDisplay (dpy);
40    GetReq (XFixesCreateRegion, req);
41    req->reqType = info->codes->major_opcode;
42    req->xfixesReqType = X_XFixesCreateRegion;
43    region = req->region = XAllocID (dpy);
44    len = ((long) nrectangles) << 1;
45    SetReqLen (req, len, len);
46    len <<= 2;
47    Data16 (dpy, (short *) rectangles, len);
48    UnlockDisplay (dpy);
49    SyncHandle();
50    return region;
51}
52
53XserverRegion
54XFixesCreateRegionFromBitmap (Display *dpy, Pixmap bitmap)
55{
56    XFixesExtDisplayInfo		*info = XFixesFindDisplay (dpy);
57    xXFixesCreateRegionFromBitmapReq	*req;
58    XserverRegion			region;
59
60    XFixesCheckExtension (dpy, info, 0);
61    LockDisplay (dpy);
62    GetReq (XFixesCreateRegionFromBitmap, req);
63    req->reqType = info->codes->major_opcode;
64    req->xfixesReqType = X_XFixesCreateRegionFromBitmap;
65    region = req->region = XAllocID (dpy);
66    req->bitmap = bitmap;
67    UnlockDisplay (dpy);
68    SyncHandle();
69    return region;
70}
71
72XserverRegion
73XFixesCreateRegionFromWindow (Display *dpy, Window window, int kind)
74{
75    XFixesExtDisplayInfo		*info = XFixesFindDisplay (dpy);
76    xXFixesCreateRegionFromWindowReq	*req;
77    XserverRegion			region;
78
79    XFixesCheckExtension (dpy, info, 0);
80    LockDisplay (dpy);
81    GetReq (XFixesCreateRegionFromWindow, req);
82    req->reqType = info->codes->major_opcode;
83    req->xfixesReqType = X_XFixesCreateRegionFromWindow;
84    region = req->region = XAllocID (dpy);
85    req->window = window;
86    req->kind = kind;
87    UnlockDisplay (dpy);
88    SyncHandle();
89    return region;
90}
91
92XserverRegion
93XFixesCreateRegionFromGC (Display *dpy, GC gc)
94{
95    XFixesExtDisplayInfo		*info = XFixesFindDisplay (dpy);
96    xXFixesCreateRegionFromGCReq	*req;
97    XserverRegion			region;
98
99    XFixesCheckExtension (dpy, info, 0);
100    LockDisplay (dpy);
101    GetReq (XFixesCreateRegionFromGC, req);
102    req->reqType = info->codes->major_opcode;
103    req->xfixesReqType = X_XFixesCreateRegionFromGC;
104    region = req->region = XAllocID (dpy);
105    req->gc = gc->gid;
106    UnlockDisplay (dpy);
107    SyncHandle();
108    return region;
109}
110
111XserverRegion
112XFixesCreateRegionFromPicture (Display *dpy, XID picture)
113{
114    XFixesExtDisplayInfo		*info = XFixesFindDisplay (dpy);
115    xXFixesCreateRegionFromPictureReq	*req;
116    XserverRegion			region;
117
118    XFixesCheckExtension (dpy, info, 0);
119    LockDisplay (dpy);
120    GetReq (XFixesCreateRegionFromPicture, req);
121    req->reqType = info->codes->major_opcode;
122    req->xfixesReqType = X_XFixesCreateRegionFromPicture;
123    region = req->region = XAllocID (dpy);
124    req->picture = picture;
125    UnlockDisplay (dpy);
126    SyncHandle();
127    return region;
128}
129
130void
131XFixesDestroyRegion (Display *dpy, XserverRegion region)
132{
133    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
134    xXFixesDestroyRegionReq	*req;
135
136    XFixesSimpleCheckExtension (dpy, info);
137    LockDisplay (dpy);
138    GetReq (XFixesDestroyRegion, req);
139    req->reqType = info->codes->major_opcode;
140    req->xfixesReqType = X_XFixesDestroyRegion;
141    req->region = region;
142    UnlockDisplay (dpy);
143    SyncHandle();
144}
145
146void
147XFixesSetRegion (Display *dpy, XserverRegion region,
148		 XRectangle *rectangles, int nrectangles)
149{
150    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
151    xXFixesSetRegionReq		*req;
152    long    			len;
153
154    XFixesSimpleCheckExtension (dpy, info);
155    LockDisplay (dpy);
156    GetReq (XFixesSetRegion, req);
157    req->reqType = info->codes->major_opcode;
158    req->xfixesReqType = X_XFixesSetRegion;
159    req->region = region;
160    len = ((long) nrectangles) << 1;
161    SetReqLen (req, len, len);
162    len <<= 2;
163    Data16 (dpy, (short *) rectangles, len);
164    UnlockDisplay (dpy);
165    SyncHandle();
166}
167
168void
169XFixesCopyRegion (Display *dpy, XserverRegion dst, XserverRegion src)
170{
171    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
172    xXFixesCopyRegionReq	*req;
173
174    XFixesSimpleCheckExtension (dpy, info);
175    LockDisplay (dpy);
176    GetReq (XFixesCopyRegion, req);
177    req->reqType = info->codes->major_opcode;
178    req->xfixesReqType = X_XFixesCopyRegion;
179    req->source = src;
180    req->destination = dst;
181    UnlockDisplay (dpy);
182    SyncHandle();
183}
184
185void
186XFixesUnionRegion (Display *dpy, XserverRegion dst,
187		   XserverRegion src1, XserverRegion src2)
188{
189    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
190    xXFixesUnionRegionReq	*req;
191
192    XFixesSimpleCheckExtension (dpy, info);
193    LockDisplay (dpy);
194    GetReq (XFixesUnionRegion, req);
195    req->reqType = info->codes->major_opcode;
196    req->xfixesReqType = X_XFixesUnionRegion;
197    req->source1 = src1;
198    req->source2 = src2;
199    req->destination = dst;
200    UnlockDisplay (dpy);
201    SyncHandle();
202}
203
204void
205XFixesIntersectRegion (Display *dpy, XserverRegion dst,
206		       XserverRegion src1, XserverRegion src2)
207{
208    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
209    xXFixesIntersectRegionReq	*req;
210
211    XFixesSimpleCheckExtension (dpy, info);
212    LockDisplay (dpy);
213    GetReq (XFixesIntersectRegion, req);
214    req->reqType = info->codes->major_opcode;
215    req->xfixesReqType = X_XFixesIntersectRegion;
216    req->source1 = src1;
217    req->source2 = src2;
218    req->destination = dst;
219    UnlockDisplay (dpy);
220    SyncHandle();
221}
222
223void
224XFixesSubtractRegion (Display *dpy, XserverRegion dst,
225		      XserverRegion src1, XserverRegion src2)
226{
227    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
228    xXFixesSubtractRegionReq	*req;
229
230    XFixesSimpleCheckExtension (dpy, info);
231    LockDisplay (dpy);
232    GetReq (XFixesSubtractRegion, req);
233    req->reqType = info->codes->major_opcode;
234    req->xfixesReqType = X_XFixesSubtractRegion;
235    req->source1 = src1;
236    req->source2 = src2;
237    req->destination = dst;
238    UnlockDisplay (dpy);
239    SyncHandle();
240}
241
242void
243XFixesInvertRegion (Display *dpy, XserverRegion dst,
244		    XRectangle *rect, XserverRegion src)
245{
246    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
247    xXFixesInvertRegionReq	*req;
248
249    XFixesSimpleCheckExtension (dpy, info);
250    LockDisplay (dpy);
251    GetReq (XFixesInvertRegion, req);
252    req->reqType = info->codes->major_opcode;
253    req->xfixesReqType = X_XFixesInvertRegion;
254    req->x = rect->x;
255    req->y = rect->y;
256    req->width = rect->width;
257    req->height = rect->height;
258    req->source = src;
259    req->destination = dst;
260    UnlockDisplay (dpy);
261    SyncHandle();
262}
263
264void
265XFixesTranslateRegion (Display *dpy, XserverRegion region, int dx, int dy)
266{
267    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
268    xXFixesTranslateRegionReq	*req;
269
270    XFixesSimpleCheckExtension (dpy, info);
271    LockDisplay (dpy);
272    GetReq (XFixesTranslateRegion, req);
273    req->reqType = info->codes->major_opcode;
274    req->xfixesReqType = X_XFixesTranslateRegion;
275    req->region = region;
276    req->dx = dx;
277    req->dy = dy;
278    UnlockDisplay (dpy);
279    SyncHandle();
280}
281
282void
283XFixesRegionExtents (Display *dpy, XserverRegion dst, XserverRegion src)
284{
285    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
286    xXFixesRegionExtentsReq	*req;
287
288    XFixesSimpleCheckExtension (dpy, info);
289    LockDisplay (dpy);
290    GetReq (XFixesRegionExtents, req);
291    req->reqType = info->codes->major_opcode;
292    req->xfixesReqType = X_XFixesRegionExtents;
293    req->source = src;
294    req->destination = dst;
295    UnlockDisplay (dpy);
296    SyncHandle();
297}
298
299XRectangle *
300XFixesFetchRegion (Display *dpy, XserverRegion region, int *nrectanglesRet)
301{
302    XRectangle	bounds;
303
304    return XFixesFetchRegionAndBounds (dpy, region, nrectanglesRet, &bounds);
305}
306
307XRectangle *
308XFixesFetchRegionAndBounds (Display	    *dpy,
309			    XserverRegion   region,
310			    int		    *nrectanglesRet,
311			    XRectangle	    *bounds)
312{
313    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
314    xXFixesFetchRegionReq	*req;
315    xXFixesFetchRegionReply	rep;
316    XRectangle			*rects;
317    int    			nrects;
318    long    			nbytes;
319    long			nread;
320
321    XFixesCheckExtension (dpy, info, 0);
322    LockDisplay (dpy);
323    GetReq (XFixesFetchRegion, req);
324    req->reqType = info->codes->major_opcode;
325    req->xfixesReqType = X_XFixesFetchRegion;
326    req->region = region;
327    *nrectanglesRet = 0;
328    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
329    {
330	UnlockDisplay (dpy);
331	SyncHandle ();
332	return 0;
333    }
334    bounds->x = rep.x;
335    bounds->y = rep.y;
336    bounds->width = rep.width;
337    bounds->height = rep.height;
338    nbytes = (long) rep.length << 2;
339    nrects = rep.length >> 1;
340    nread = nrects << 3;
341    rects = Xmalloc (nrects * sizeof (XRectangle));
342    if (!rects)
343    {
344	_XEatData (dpy, nbytes);
345	UnlockDisplay (dpy);
346	SyncHandle ();
347	return 0;
348    }
349    _XRead16 (dpy, (short *) rects, nrects << 3);
350    /* skip any padding */
351    if(nbytes > nread)
352    {
353	_XEatData (dpy, (unsigned long) (nbytes - nread));
354    }
355    UnlockDisplay (dpy);
356    SyncHandle();
357    *nrectanglesRet = nrects;
358    return rects;
359}
360
361void
362XFixesSetGCClipRegion (Display *dpy, GC gc,
363		       int clip_x_origin, int clip_y_origin,
364		       XserverRegion region)
365{
366    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
367    xXFixesSetGCClipRegionReq	    *req;
368
369    XFixesSimpleCheckExtension (dpy, info);
370    LockDisplay (dpy);
371    GetReq (XFixesSetGCClipRegion, req);
372    req->reqType = info->codes->major_opcode;
373    req->xfixesReqType = X_XFixesSetGCClipRegion;
374    req->gc = gc->gid;
375    req->region = region;
376    req->xOrigin = clip_x_origin;
377    req->yOrigin = clip_y_origin;
378    UnlockDisplay (dpy);
379    SyncHandle();
380}
381
382void
383XFixesSetWindowShapeRegion (Display *dpy, Window win, int shape_kind,
384			    int x_off, int y_off, XserverRegion region)
385{
386    XFixesExtDisplayInfo	    *info = XFixesFindDisplay (dpy);
387    xXFixesSetWindowShapeRegionReq  *req;
388
389    XFixesSimpleCheckExtension (dpy, info);
390    LockDisplay (dpy);
391    GetReq (XFixesSetWindowShapeRegion, req);
392    req->reqType = info->codes->major_opcode;
393    req->xfixesReqType = X_XFixesSetWindowShapeRegion;
394    req->dest = win;
395    req->destKind = shape_kind;
396    req->xOff = x_off;
397    req->yOff = y_off;
398    req->region = region;
399    UnlockDisplay (dpy);
400    SyncHandle();
401}
402
403void
404XFixesSetPictureClipRegion (Display *dpy, XID picture,
405			    int clip_x_origin, int clip_y_origin,
406			    XserverRegion region)
407{
408    XFixesExtDisplayInfo	    *info = XFixesFindDisplay (dpy);
409    xXFixesSetPictureClipRegionReq  *req;
410
411    XFixesSimpleCheckExtension (dpy, info);
412    LockDisplay (dpy);
413    GetReq (XFixesSetPictureClipRegion, req);
414    req->reqType = info->codes->major_opcode;
415    req->xfixesReqType = X_XFixesSetPictureClipRegion;
416    req->picture = picture;
417    req->region = region;
418    req->xOrigin = clip_x_origin;
419    req->yOrigin = clip_y_origin;
420    UnlockDisplay (dpy);
421    SyncHandle();
422}
423
424void
425XFixesExpandRegion (Display *dpy, XserverRegion dst, XserverRegion src,
426		    unsigned left, unsigned right,
427		    unsigned top, unsigned bottom)
428{
429    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
430    xXFixesExpandRegionReq	*req;
431
432    XFixesSimpleCheckExtension (dpy, info);
433    LockDisplay (dpy);
434    GetReq (XFixesExpandRegion, req);
435    req->reqType = info->codes->major_opcode;
436    req->xfixesReqType = X_XFixesExpandRegion;
437    req->source = src;
438    req->destination = dst;
439    req->left = left;
440    req->right = right;
441    req->top = top;
442    req->bottom = bottom;
443    UnlockDisplay (dpy);
444    SyncHandle();
445}
446
447