region.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include "xfixesint.h"
  26. #include "scrnintstr.h"
  27. #include <picturestr.h>
  28. extern int RenderErrBase;
  29. #include <regionstr.h>
  30. #include <gcstruct.h>
  31. #include <window.h>
  32. RESTYPE RegionResType;
  33. static int
  34. RegionResFree(pointer data, XID id)
  35. {
  36. RegionPtr pRegion = (RegionPtr) data;
  37. REGION_DESTROY(pRegion);
  38. return Success;
  39. }
  40. RegionPtr
  41. XFixesRegionCopy(RegionPtr pRegion)
  42. {
  43. RegionPtr pNew = REGION_CREATE(REGION_EXTENTS(pRegion),
  44. REGION_NUM_RECTS(pRegion));
  45. if (!pNew)
  46. return 0;
  47. if (!REGION_COPY(pNew, pRegion)) {
  48. REGION_DESTROY(pNew);
  49. return 0;
  50. }
  51. return pNew;
  52. }
  53. Bool
  54. XFixesRegionInit(void)
  55. {
  56. RegionResType = CreateNewResourceType(RegionResFree);
  57. return TRUE;
  58. }
  59. int
  60. ProcXFixesCreateRegion(ClientPtr client)
  61. {
  62. int things;
  63. RegionPtr pRegion;
  64. REQUEST(xXFixesCreateRegionReq);
  65. REQUEST_AT_LEAST_SIZE(xXFixesCreateRegionReq);
  66. LEGAL_NEW_RESOURCE(stuff->region, client);
  67. things = (client->req_len << 2) - sizeof(xXFixesCreateRegionReq);
  68. if (things & 4)
  69. return BadLength;
  70. things >>= 3;
  71. pRegion =
  72. RECTS_TO_REGION(things, (xRectangle *) (stuff + 1), CT_UNSORTED);
  73. if (!pRegion)
  74. return BadAlloc;
  75. if (!AddResource(stuff->region, RegionResType, (pointer) pRegion))
  76. return BadAlloc;
  77. return (client->noClientException);
  78. }
  79. int
  80. SProcXFixesCreateRegion(ClientPtr client)
  81. {
  82. REQUEST(xXFixesCreateRegionReq);
  83. swaps(&stuff->length);
  84. REQUEST_AT_LEAST_SIZE(xXFixesCreateRegionReq);
  85. swapl(&stuff->region);
  86. SwapRestS(stuff);
  87. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  88. }
  89. int
  90. ProcXFixesCreateRegionFromBitmap(ClientPtr client)
  91. {
  92. RegionPtr pRegion;
  93. PixmapPtr pPixmap;
  94. REQUEST(xXFixesCreateRegionFromBitmapReq);
  95. REQUEST_SIZE_MATCH(xXFixesCreateRegionFromBitmapReq);
  96. LEGAL_NEW_RESOURCE(stuff->region, client);
  97. pPixmap = (PixmapPtr) SecurityLookupIDByType(client, stuff->bitmap,
  98. RT_PIXMAP, SecurityReadAccess);
  99. if (!pPixmap) {
  100. client->errorValue = stuff->bitmap;
  101. return BadPixmap;
  102. }
  103. if (pPixmap->drawable.depth != 1)
  104. return BadMatch;
  105. pRegion = BITMAP_TO_REGION(pPixmap->drawable.pScreen, pPixmap);
  106. if (!pRegion)
  107. return BadAlloc;
  108. if (!AddResource(stuff->region, RegionResType, (pointer) pRegion))
  109. return BadAlloc;
  110. return (client->noClientException);
  111. }
  112. int
  113. SProcXFixesCreateRegionFromBitmap(ClientPtr client)
  114. {
  115. REQUEST(xXFixesCreateRegionFromBitmapReq);
  116. swaps(&stuff->length);
  117. REQUEST_SIZE_MATCH(xXFixesCreateRegionFromBitmapReq);
  118. swapl(&stuff->region);
  119. swapl(&stuff->bitmap);
  120. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  121. }
  122. int
  123. ProcXFixesCreateRegionFromWindow(ClientPtr client)
  124. {
  125. RegionPtr pRegion;
  126. Bool copy = TRUE;
  127. WindowPtr pWin;
  128. REQUEST(xXFixesCreateRegionFromWindowReq);
  129. REQUEST_SIZE_MATCH(xXFixesCreateRegionFromWindowReq);
  130. LEGAL_NEW_RESOURCE(stuff->region, client);
  131. pWin = (WindowPtr) LookupIDByType(stuff->window, RT_WINDOW);
  132. if (!pWin) {
  133. client->errorValue = stuff->window;
  134. return BadWindow;
  135. }
  136. switch (stuff->kind) {
  137. case WindowRegionBounding:
  138. pRegion = wBoundingShape(pWin);
  139. if (!pRegion)
  140. {
  141. pRegion = CreateBoundingShape(pWin);
  142. copy = FALSE;
  143. }
  144. break;
  145. case WindowRegionClip:
  146. pRegion = wClipShape(pWin);
  147. if (!pRegion)
  148. {
  149. pRegion = CreateClipShape(pWin);
  150. copy = FALSE;
  151. }
  152. break;
  153. default:
  154. client->errorValue = stuff->kind;
  155. return BadValue;
  156. }
  157. if (copy && pRegion)
  158. pRegion = XFixesRegionCopy(pRegion);
  159. if (!pRegion)
  160. return BadAlloc;
  161. if (!AddResource(stuff->region, RegionResType, (pointer) pRegion))
  162. return BadAlloc;
  163. return (client->noClientException);
  164. }
  165. int
  166. SProcXFixesCreateRegionFromWindow(ClientPtr client)
  167. {
  168. REQUEST(xXFixesCreateRegionFromWindowReq);
  169. swaps(&stuff->length);
  170. REQUEST_SIZE_MATCH(xXFixesCreateRegionFromWindowReq);
  171. swapl(&stuff->region);
  172. swapl(&stuff->window);
  173. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  174. }
  175. int
  176. ProcXFixesCreateRegionFromGC(ClientPtr client)
  177. {
  178. RegionPtr pRegion, pClip;
  179. GCPtr pGC;
  180. REQUEST(xXFixesCreateRegionFromGCReq);
  181. REQUEST_SIZE_MATCH(xXFixesCreateRegionFromGCReq);
  182. LEGAL_NEW_RESOURCE(stuff->region, client);
  183. SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityReadAccess);
  184. switch (pGC->clientClipType) {
  185. case CT_PIXMAP:
  186. pRegion = BITMAP_TO_REGION(pGC->pScreen, (PixmapPtr) pGC->clientClip);
  187. if (!pRegion)
  188. return BadAlloc;
  189. break;
  190. case CT_REGION:
  191. pClip = (RegionPtr) pGC->clientClip;
  192. pRegion = XFixesRegionCopy(pClip);
  193. if (!pRegion)
  194. return BadAlloc;
  195. break;
  196. default:
  197. return BadImplementation; /* assume sane server bits */
  198. }
  199. if (!AddResource(stuff->region, RegionResType, (pointer) pRegion))
  200. return BadAlloc;
  201. return (client->noClientException);
  202. }
  203. int
  204. SProcXFixesCreateRegionFromGC(ClientPtr client)
  205. {
  206. REQUEST(xXFixesCreateRegionFromGCReq);
  207. swaps(&stuff->length);
  208. REQUEST_SIZE_MATCH(xXFixesCreateRegionFromGCReq);
  209. swapl(&stuff->region);
  210. swapl(&stuff->gc);
  211. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  212. }
  213. int
  214. ProcXFixesCreateRegionFromPicture(ClientPtr client)
  215. {
  216. RegionPtr pRegion;
  217. PicturePtr pPicture;
  218. REQUEST(xXFixesCreateRegionFromPictureReq);
  219. REQUEST_SIZE_MATCH(xXFixesCreateRegionFromPictureReq);
  220. LEGAL_NEW_RESOURCE(stuff->region, client);
  221. VERIFY_PICTURE(pPicture, stuff->picture, client, SecurityReadAccess,
  222. RenderErrBase + BadPicture);
  223. switch (pPicture->clientClipType) {
  224. case CT_PIXMAP:
  225. pRegion = BITMAP_TO_REGION(pPicture->pDrawable->pScreen,
  226. (PixmapPtr) pPicture->clientClip);
  227. if (!pRegion)
  228. return BadAlloc;
  229. break;
  230. case CT_REGION:
  231. pRegion = XFixesRegionCopy((RegionPtr) pPicture->clientClip);
  232. if (!pRegion)
  233. return BadAlloc;
  234. break;
  235. default:
  236. return BadImplementation; /* assume sane server bits */
  237. }
  238. if (!AddResource(stuff->region, RegionResType, (pointer) pRegion))
  239. return BadAlloc;
  240. return (client->noClientException);
  241. }
  242. int
  243. SProcXFixesCreateRegionFromPicture(ClientPtr client)
  244. {
  245. REQUEST(xXFixesCreateRegionFromPictureReq);
  246. swaps(&stuff->length);
  247. REQUEST_SIZE_MATCH(xXFixesCreateRegionFromPictureReq);
  248. swapl(&stuff->region);
  249. swapl(&stuff->picture);
  250. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  251. }
  252. int
  253. ProcXFixesDestroyRegion(ClientPtr client)
  254. {
  255. REQUEST(xXFixesDestroyRegionReq);
  256. RegionPtr pRegion;
  257. REQUEST_SIZE_MATCH(xXFixesDestroyRegionReq);
  258. VERIFY_REGION(pRegion, stuff->region, client, SecurityWriteAccess);
  259. FreeResource(stuff->region, RT_NONE);
  260. return (client->noClientException);
  261. }
  262. int
  263. SProcXFixesDestroyRegion(ClientPtr client)
  264. {
  265. REQUEST(xXFixesDestroyRegionReq);
  266. swaps(&stuff->length);
  267. REQUEST_SIZE_MATCH(xXFixesDestroyRegionReq);
  268. swapl(&stuff->region);
  269. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  270. }
  271. int
  272. ProcXFixesSetRegion(ClientPtr client)
  273. {
  274. int things;
  275. RegionPtr pRegion, pNew;
  276. REQUEST(xXFixesSetRegionReq);
  277. REQUEST_AT_LEAST_SIZE(xXFixesSetRegionReq);
  278. VERIFY_REGION(pRegion, stuff->region, client, SecurityWriteAccess);
  279. things = (client->req_len << 2) - sizeof(xXFixesCreateRegionReq);
  280. if (things & 4)
  281. return BadLength;
  282. things >>= 3;
  283. pNew = RECTS_TO_REGION(things, (xRectangle *) (stuff + 1), CT_UNSORTED);
  284. if (!pNew)
  285. return BadAlloc;
  286. if (!REGION_COPY(pRegion, pNew)) {
  287. REGION_DESTROY(pNew);
  288. return BadAlloc;
  289. }
  290. REGION_DESTROY(pNew);
  291. return (client->noClientException);
  292. }
  293. int
  294. SProcXFixesSetRegion(ClientPtr client)
  295. {
  296. REQUEST(xXFixesSetRegionReq);
  297. swaps(&stuff->length);
  298. REQUEST_AT_LEAST_SIZE(xXFixesSetRegionReq);
  299. swapl(&stuff->region);
  300. SwapRestS(stuff);
  301. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  302. }
  303. int
  304. ProcXFixesCopyRegion(ClientPtr client)
  305. {
  306. RegionPtr pSource, pDestination;
  307. REQUEST(xXFixesCopyRegionReq);
  308. VERIFY_REGION(pSource, stuff->source, client, SecurityReadAccess);
  309. VERIFY_REGION(pDestination, stuff->destination, client,
  310. SecurityWriteAccess);
  311. if (!REGION_COPY(pDestination, pSource))
  312. return BadAlloc;
  313. return (client->noClientException);
  314. }
  315. int
  316. SProcXFixesCopyRegion(ClientPtr client)
  317. {
  318. REQUEST(xXFixesCopyRegionReq);
  319. swaps(&stuff->length);
  320. REQUEST_AT_LEAST_SIZE(xXFixesCopyRegionReq);
  321. swapl(&stuff->source);
  322. swapl(&stuff->destination);
  323. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  324. }
  325. int
  326. ProcXFixesCombineRegion(ClientPtr client)
  327. {
  328. RegionPtr pSource1, pSource2, pDestination;
  329. int ret = Success;
  330. REQUEST(xXFixesCombineRegionReq);
  331. REQUEST_SIZE_MATCH(xXFixesCombineRegionReq);
  332. VERIFY_REGION(pSource1, stuff->source1, client, SecurityReadAccess);
  333. VERIFY_REGION(pSource2, stuff->source2, client, SecurityReadAccess);
  334. VERIFY_REGION(pDestination, stuff->destination, client,
  335. SecurityWriteAccess);
  336. switch (stuff->xfixesReqType) {
  337. case X_XFixesUnionRegion:
  338. if (!REGION_UNION(pDestination, pSource1, pSource2))
  339. ret = BadAlloc;
  340. break;
  341. case X_XFixesIntersectRegion:
  342. if (!REGION_INTERSECT(pDestination, pSource1, pSource2))
  343. ret = BadAlloc;
  344. break;
  345. case X_XFixesSubtractRegion:
  346. if (!REGION_SUBTRACT(pDestination, pSource1, pSource2))
  347. ret = BadAlloc;
  348. break;
  349. }
  350. if (ret == Success)
  351. ret = client->noClientException;
  352. return ret;
  353. }
  354. int
  355. SProcXFixesCombineRegion(ClientPtr client)
  356. {
  357. REQUEST(xXFixesCombineRegionReq);
  358. swaps(&stuff->length);
  359. REQUEST_SIZE_MATCH(xXFixesCombineRegionReq);
  360. swapl(&stuff->source1);
  361. swapl(&stuff->source2);
  362. swapl(&stuff->destination);
  363. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  364. }
  365. int
  366. ProcXFixesInvertRegion(ClientPtr client)
  367. {
  368. RegionPtr pSource, pDestination;
  369. BoxRec bounds;
  370. int ret = Success;
  371. REQUEST(xXFixesInvertRegionReq);
  372. REQUEST_SIZE_MATCH(xXFixesInvertRegionReq);
  373. VERIFY_REGION(pSource, stuff->source, client, SecurityReadAccess);
  374. VERIFY_REGION(pDestination, stuff->destination, client,
  375. SecurityWriteAccess);
  376. /* Compute bounds, limit to 16 bits */
  377. bounds.x1 = stuff->x;
  378. bounds.y1 = stuff->y;
  379. if ((int) stuff->x + (int) stuff->width > MAXSHORT)
  380. bounds.x2 = MAXSHORT;
  381. else
  382. bounds.x2 = stuff->x + stuff->width;
  383. if ((int) stuff->y + (int) stuff->height > MAXSHORT)
  384. bounds.y2 = MAXSHORT;
  385. else
  386. bounds.y2 = stuff->y + stuff->height;
  387. if (!REGION_INVERSE(pDestination, pSource, &bounds))
  388. ret = BadAlloc;
  389. if (ret == Success)
  390. ret = client->noClientException;
  391. return ret;
  392. }
  393. int
  394. SProcXFixesInvertRegion(ClientPtr client)
  395. {
  396. REQUEST(xXFixesInvertRegionReq);
  397. swaps(&stuff->length);
  398. REQUEST_SIZE_MATCH(xXFixesInvertRegionReq);
  399. swapl(&stuff->source);
  400. swaps(&stuff->x);
  401. swaps(&stuff->y);
  402. swaps(&stuff->width);
  403. swaps(&stuff->height);
  404. swapl(&stuff->destination);
  405. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  406. }
  407. int
  408. ProcXFixesTranslateRegion(ClientPtr client)
  409. {
  410. RegionPtr pRegion;
  411. REQUEST(xXFixesTranslateRegionReq);
  412. REQUEST_SIZE_MATCH(xXFixesTranslateRegionReq);
  413. VERIFY_REGION(pRegion, stuff->region, client, SecurityWriteAccess);
  414. REGION_TRANSLATE(pRegion, stuff->dx, stuff->dy);
  415. return (client->noClientException);
  416. }
  417. int
  418. SProcXFixesTranslateRegion(ClientPtr client)
  419. {
  420. REQUEST(xXFixesTranslateRegionReq);
  421. swaps(&stuff->length);
  422. REQUEST_SIZE_MATCH(xXFixesTranslateRegionReq);
  423. swapl(&stuff->region);
  424. swaps(&stuff->dx);
  425. swaps(&stuff->dy);
  426. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  427. }
  428. int
  429. ProcXFixesRegionExtents(ClientPtr client)
  430. {
  431. RegionPtr pSource, pDestination;
  432. REQUEST(xXFixesRegionExtentsReq);
  433. REQUEST_SIZE_MATCH(xXFixesRegionExtentsReq);
  434. VERIFY_REGION(pSource, stuff->source, client, SecurityReadAccess);
  435. VERIFY_REGION(pDestination, stuff->destination, client,
  436. SecurityWriteAccess);
  437. REGION_RESET(pDestination, REGION_EXTENTS(pSource));
  438. return (client->noClientException);
  439. }
  440. int
  441. SProcXFixesRegionExtents(ClientPtr client)
  442. {
  443. REQUEST(xXFixesRegionExtentsReq);
  444. swaps(&stuff->length);
  445. REQUEST_SIZE_MATCH(xXFixesRegionExtentsReq);
  446. swapl(&stuff->source);
  447. swapl(&stuff->destination);
  448. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  449. }
  450. int
  451. ProcXFixesFetchRegion(ClientPtr client)
  452. {
  453. RegionPtr pRegion;
  454. xXFixesFetchRegionReply *reply;
  455. xRectangle *pRect;
  456. BoxPtr pExtent;
  457. BoxPtr pBox;
  458. int i, nBox;
  459. REQUEST(xXFixesFetchRegionReq);
  460. REQUEST_SIZE_MATCH(xXFixesFetchRegionReq);
  461. VERIFY_REGION(pRegion, stuff->region, client, SecurityReadAccess);
  462. pExtent = REGION_EXTENTS(pRegion);
  463. pBox = REGION_RECTS(pRegion);
  464. nBox = REGION_NUM_RECTS(pRegion);
  465. reply = malloc(sizeof(xXFixesFetchRegionReply) + nBox * sizeof(xRectangle));
  466. if (!reply)
  467. return BadAlloc;
  468. reply->type = X_Reply;
  469. reply->sequenceNumber = client->sequence;
  470. reply->length = nBox << 1;
  471. reply->x = pExtent->x1;
  472. reply->y = pExtent->y1;
  473. reply->width = pExtent->x2 - pExtent->x1;
  474. reply->height = pExtent->y2 - pExtent->y1;
  475. pRect = (xRectangle *) (reply + 1);
  476. for (i = 0; i < nBox; i++) {
  477. pRect[i].x = pBox[i].x1;
  478. pRect[i].y = pBox[i].y1;
  479. pRect[i].width = pBox[i].x2 - pBox[i].x1;
  480. pRect[i].height = pBox[i].y2 - pBox[i].y1;
  481. }
  482. if (client->swapped) {
  483. swaps(&reply->sequenceNumber);
  484. swapl(&reply->length);
  485. swaps(&reply->x);
  486. swaps(&reply->y);
  487. swaps(&reply->width);
  488. swaps(&reply->height);
  489. SwapShorts((INT16 *) pRect, nBox * 4);
  490. }
  491. (void) WriteToClient(client, sizeof(xXFixesFetchRegionReply) +
  492. nBox * sizeof(xRectangle), (char *) reply);
  493. free(reply);
  494. return (client->noClientException);
  495. }
  496. int
  497. SProcXFixesFetchRegion(ClientPtr client)
  498. {
  499. REQUEST(xXFixesFetchRegionReq);
  500. swaps(&stuff->length);
  501. REQUEST_SIZE_MATCH(xXFixesFetchRegionReq);
  502. swapl(&stuff->region);
  503. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  504. }
  505. int
  506. ProcXFixesSetGCClipRegion(ClientPtr client)
  507. {
  508. GCPtr pGC;
  509. RegionPtr pRegion;
  510. XID vals[2];
  511. REQUEST(xXFixesSetGCClipRegionReq);
  512. REQUEST_SIZE_MATCH(xXFixesSetGCClipRegionReq);
  513. SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess);
  514. VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, SecurityReadAccess);
  515. if (pRegion) {
  516. pRegion = XFixesRegionCopy(pRegion);
  517. if (!pRegion)
  518. return BadAlloc;
  519. }
  520. vals[0] = stuff->xOrigin;
  521. vals[1] = stuff->yOrigin;
  522. DoChangeGC(pGC, GCClipXOrigin | GCClipYOrigin, vals, 0);
  523. (*pGC->funcs->ChangeClip) (pGC, pRegion ? CT_REGION : CT_NONE,
  524. (pointer) pRegion, 0);
  525. return (client->noClientException);
  526. }
  527. int
  528. SProcXFixesSetGCClipRegion(ClientPtr client)
  529. {
  530. REQUEST(xXFixesSetGCClipRegionReq);
  531. swaps(&stuff->length);
  532. REQUEST_SIZE_MATCH(xXFixesSetGCClipRegionReq);
  533. swapl(&stuff->gc);
  534. swapl(&stuff->region);
  535. swaps(&stuff->xOrigin);
  536. swaps(&stuff->yOrigin);
  537. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  538. }
  539. typedef RegionPtr (*CreateDftPtr) (WindowPtr pWin);
  540. int
  541. ProcXFixesSetWindowShapeRegion(ClientPtr client)
  542. {
  543. WindowPtr pWin;
  544. ScreenPtr pScreen;
  545. RegionPtr pRegion;
  546. RegionPtr *pDestRegion;
  547. REQUEST(xXFixesSetWindowShapeRegionReq);
  548. REQUEST_SIZE_MATCH(xXFixesSetWindowShapeRegionReq);
  549. pWin = (WindowPtr) LookupIDByType(stuff->dest, RT_WINDOW);
  550. if (!pWin) {
  551. client->errorValue = stuff->dest;
  552. return BadWindow;
  553. }
  554. VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, SecurityWriteAccess);
  555. pScreen = pWin->drawable.pScreen;
  556. switch (stuff->destKind) {
  557. case ShapeBounding:
  558. case ShapeClip:
  559. case ShapeInput:
  560. break;
  561. default:
  562. client->errorValue = stuff->destKind;
  563. return BadValue;
  564. }
  565. if (pRegion) {
  566. pRegion = XFixesRegionCopy(pRegion);
  567. if (!pRegion)
  568. return BadAlloc;
  569. if (!pWin->optional)
  570. MakeWindowOptional(pWin);
  571. switch (stuff->destKind) {
  572. default:
  573. case ShapeBounding:
  574. pDestRegion = &pWin->optional->boundingShape;
  575. break;
  576. case ShapeClip:
  577. pDestRegion = &pWin->optional->clipShape;
  578. break;
  579. case ShapeInput:
  580. pDestRegion = &pWin->optional->inputShape;
  581. break;
  582. }
  583. if (stuff->xOff || stuff->yOff)
  584. REGION_TRANSLATE(pRegion, stuff->xOff, stuff->yOff);
  585. }
  586. else {
  587. if (pWin->optional) {
  588. switch (stuff->destKind) {
  589. default:
  590. case ShapeBounding:
  591. pDestRegion = &pWin->optional->boundingShape;
  592. break;
  593. case ShapeClip:
  594. pDestRegion = &pWin->optional->clipShape;
  595. break;
  596. case ShapeInput:
  597. pDestRegion = &pWin->optional->inputShape;
  598. break;
  599. }
  600. }
  601. else
  602. pDestRegion = &pRegion; /* a NULL region pointer */
  603. }
  604. if (*pDestRegion)
  605. REGION_DESTROY(*pDestRegion);
  606. *pDestRegion = pRegion;
  607. (*pScreen->SetShape) (pWin);
  608. SendShapeNotify(pWin, stuff->destKind);
  609. return (client->noClientException);
  610. }
  611. int
  612. SProcXFixesSetWindowShapeRegion(ClientPtr client)
  613. {
  614. REQUEST(xXFixesSetWindowShapeRegionReq);
  615. swaps(&stuff->length);
  616. REQUEST_SIZE_MATCH(xXFixesSetWindowShapeRegionReq);
  617. swapl(&stuff->dest);
  618. swaps(&stuff->xOff);
  619. swaps(&stuff->yOff);
  620. swapl(&stuff->region);
  621. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  622. }
  623. int
  624. ProcXFixesSetPictureClipRegion(ClientPtr client)
  625. {
  626. PicturePtr pPicture;
  627. RegionPtr pRegion;
  628. REQUEST(xXFixesSetPictureClipRegionReq);
  629. REQUEST_SIZE_MATCH(xXFixesSetPictureClipRegionReq);
  630. VERIFY_PICTURE(pPicture, stuff->picture, client, SecurityWriteAccess,
  631. RenderErrBase + BadPicture);
  632. VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, SecurityReadAccess);
  633. return SetPictureClipRegion(pPicture, stuff->xOrigin, stuff->yOrigin,
  634. pRegion);
  635. }
  636. int
  637. SProcXFixesSetPictureClipRegion(ClientPtr client)
  638. {
  639. REQUEST(xXFixesSetPictureClipRegionReq);
  640. swaps(&stuff->length);
  641. REQUEST_SIZE_MATCH(xXFixesSetPictureClipRegionReq);
  642. swapl(&stuff->picture);
  643. swapl(&stuff->region);
  644. swaps(&stuff->xOrigin);
  645. swaps(&stuff->yOrigin);
  646. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  647. }
  648. int
  649. ProcXFixesExpandRegion(ClientPtr client)
  650. {
  651. RegionPtr pSource, pDestination;
  652. int ret = Success;
  653. REQUEST(xXFixesExpandRegionReq);
  654. BoxPtr pTmp;
  655. BoxPtr pSrc;
  656. int nBoxes;
  657. int i;
  658. REQUEST_SIZE_MATCH(xXFixesExpandRegionReq);
  659. VERIFY_REGION(pSource, stuff->source, client, SecurityReadAccess);
  660. VERIFY_REGION(pDestination, stuff->destination, client,
  661. SecurityWriteAccess);
  662. nBoxes = REGION_NUM_RECTS(pSource);
  663. pSrc = REGION_RECTS(pSource);
  664. if (nBoxes) {
  665. pTmp = malloc(nBoxes * sizeof(BoxRec));
  666. if (!pTmp)
  667. return BadAlloc;
  668. for (i = 0; i < nBoxes; i++) {
  669. pTmp[i].x1 = pSrc[i].x1 - stuff->left;
  670. pTmp[i].x2 = pSrc[i].x2 + stuff->right;
  671. pTmp[i].y1 = pSrc[i].y1 - stuff->top;
  672. pTmp[i].y2 = pSrc[i].y2 + stuff->bottom;
  673. }
  674. REGION_EMPTY(pDestination);
  675. for (i = 0; i < nBoxes; i++) {
  676. RegionRec r;
  677. REGION_INIT(&r, &pTmp[i], 0);
  678. REGION_UNION(pDestination, pDestination, &r);
  679. }
  680. free(pTmp);
  681. }
  682. if (ret == Success)
  683. ret = client->noClientException;
  684. return ret;
  685. }
  686. int
  687. SProcXFixesExpandRegion(ClientPtr client)
  688. {
  689. REQUEST(xXFixesExpandRegionReq);
  690. swaps(&stuff->length);
  691. REQUEST_SIZE_MATCH(xXFixesExpandRegionReq);
  692. swapl(&stuff->source);
  693. swapl(&stuff->destination);
  694. swaps(&stuff->left);
  695. swaps(&stuff->right);
  696. swaps(&stuff->top);
  697. swaps(&stuff->bottom);
  698. return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
  699. }