region.c 24 KB

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