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