miexpose.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /***********************************************************
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ******************************************************************/
  36. /*****************************************************************
  37. Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
  38. Permission is hereby granted, free of charge, to any person obtaining a copy
  39. of this software and associated documentation files (the "Software"), to deal
  40. in the Software without restriction, including without limitation the rights
  41. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  42. copies of the Software.
  43. The above copyright notice and this permission notice shall be included in
  44. all copies or substantial portions of the Software.
  45. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  46. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  47. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  48. DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
  49. BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
  50. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  51. IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  52. Except as contained in this notice, the name of Digital Equipment Corporation
  53. shall not be used in advertising or otherwise to promote the sale, use or other
  54. dealings in this Software without prior written authorization from Digital
  55. Equipment Corporation.
  56. ******************************************************************/
  57. #ifdef HAVE_DIX_CONFIG_H
  58. #include <dix-config.h>
  59. #endif
  60. #include <X11/X.h>
  61. #include <X11/Xproto.h>
  62. #include <X11/Xprotostr.h>
  63. #include "misc.h"
  64. #include "regionstr.h"
  65. #include "scrnintstr.h"
  66. #include "gcstruct.h"
  67. #include "windowstr.h"
  68. #include "pixmap.h"
  69. #include "input.h"
  70. #include "dixstruct.h"
  71. #include "mi.h"
  72. #include <X11/Xmd.h>
  73. #include "globals.h"
  74. /*
  75. machine-independent graphics exposure code. any device that uses
  76. the region package can call this.
  77. */
  78. #ifndef RECTLIMIT
  79. #define RECTLIMIT 25 /* pick a number, any number > 8 */
  80. #endif
  81. /* miHandleExposures
  82. generate a region for exposures for areas that were copied from obscured or
  83. non-existent areas to non-obscured areas of the destination. Paint the
  84. background for the region, if the destination is a window.
  85. NOTE:
  86. this should generally be called, even if graphicsExposures is false,
  87. because this is where bits get recovered from backing store.
  88. NOTE:
  89. added argument 'plane' is used to indicate how exposures from backing
  90. store should be accomplished. If plane is 0 (i.e. no bit plane), CopyArea
  91. should be used, else a CopyPlane of the indicated plane will be used. The
  92. exposing is done by the backing store's GraphicsExpose function, of course.
  93. */
  94. _X_EXPORT RegionPtr
  95. miHandleExposures(pSrcDrawable, pDstDrawable,
  96. pGC, srcx, srcy, width, height, dstx, dsty, plane)
  97. DrawablePtr pSrcDrawable;
  98. DrawablePtr pDstDrawable;
  99. GCPtr pGC;
  100. int srcx, srcy;
  101. int width, height;
  102. int dstx, dsty;
  103. unsigned long plane;
  104. {
  105. ScreenPtr pscr;
  106. RegionPtr prgnSrcClip; /* drawable-relative source clip */
  107. RegionRec rgnSrcRec;
  108. RegionPtr prgnDstClip; /* drawable-relative dest clip */
  109. RegionRec rgnDstRec;
  110. BoxRec srcBox; /* unclipped source */
  111. RegionRec rgnExposed; /* exposed region, calculated source-
  112. relative, made dst relative to
  113. intersect with visible parts of
  114. dest and send events to client,
  115. and then screen relative to paint
  116. the window background
  117. */
  118. WindowPtr pSrcWin;
  119. BoxRec expBox;
  120. Bool extents;
  121. /* This prevents warning about pscr not being used. */
  122. pGC->pScreen = pscr = pGC->pScreen;
  123. /* avoid work if we can */
  124. if (!pGC->graphicsExposures &&
  125. (pDstDrawable->type == DRAWABLE_PIXMAP) &&
  126. ((pSrcDrawable->type == DRAWABLE_PIXMAP)))
  127. return NULL;
  128. srcBox.x1 = srcx;
  129. srcBox.y1 = srcy;
  130. srcBox.x2 = srcx+width;
  131. srcBox.y2 = srcy+height;
  132. if (pSrcDrawable->type != DRAWABLE_PIXMAP)
  133. {
  134. BoxRec TsrcBox;
  135. TsrcBox.x1 = srcx + pSrcDrawable->x;
  136. TsrcBox.y1 = srcy + pSrcDrawable->y;
  137. TsrcBox.x2 = TsrcBox.x1 + width;
  138. TsrcBox.y2 = TsrcBox.y1 + height;
  139. pSrcWin = (WindowPtr) pSrcDrawable;
  140. if (pGC->subWindowMode == IncludeInferiors)
  141. {
  142. prgnSrcClip = NotClippedByChildren (pSrcWin);
  143. if ((RECT_IN_REGION(prgnSrcClip, &TsrcBox)) == rgnIN)
  144. {
  145. REGION_DESTROY(prgnSrcClip);
  146. return NULL;
  147. }
  148. }
  149. else
  150. {
  151. if ((RECT_IN_REGION(&pSrcWin->clipList, &TsrcBox)) == rgnIN)
  152. return NULL;
  153. prgnSrcClip = &rgnSrcRec;
  154. REGION_NULL(prgnSrcClip);
  155. REGION_COPY(prgnSrcClip, &pSrcWin->clipList);
  156. }
  157. REGION_TRANSLATE(prgnSrcClip,
  158. -pSrcDrawable->x, -pSrcDrawable->y);
  159. }
  160. else
  161. {
  162. BoxRec box;
  163. if ((srcBox.x1 >= 0) && (srcBox.y1 >= 0) &&
  164. (srcBox.x2 <= pSrcDrawable->width) &&
  165. (srcBox.y2 <= pSrcDrawable->height))
  166. return NULL;
  167. box.x1 = 0;
  168. box.y1 = 0;
  169. box.x2 = pSrcDrawable->width;
  170. box.y2 = pSrcDrawable->height;
  171. prgnSrcClip = &rgnSrcRec;
  172. REGION_INIT(prgnSrcClip, &box, 1);
  173. pSrcWin = (WindowPtr)NULL;
  174. }
  175. if (pDstDrawable == pSrcDrawable)
  176. {
  177. prgnDstClip = prgnSrcClip;
  178. }
  179. else if (pDstDrawable->type != DRAWABLE_PIXMAP)
  180. {
  181. if (pGC->subWindowMode == IncludeInferiors)
  182. {
  183. prgnDstClip = NotClippedByChildren((WindowPtr)pDstDrawable);
  184. }
  185. else
  186. {
  187. prgnDstClip = &rgnDstRec;
  188. REGION_NULL(prgnDstClip);
  189. REGION_COPY(prgnDstClip,
  190. &((WindowPtr)pDstDrawable)->clipList);
  191. }
  192. REGION_TRANSLATE(prgnDstClip,
  193. -pDstDrawable->x, -pDstDrawable->y);
  194. }
  195. else
  196. {
  197. BoxRec box;
  198. box.x1 = 0;
  199. box.y1 = 0;
  200. box.x2 = pDstDrawable->width;
  201. box.y2 = pDstDrawable->height;
  202. prgnDstClip = &rgnDstRec;
  203. REGION_INIT(prgnDstClip, &box, 1);
  204. }
  205. /* drawable-relative source region */
  206. REGION_INIT(&rgnExposed, &srcBox, 1);
  207. /* now get the hidden parts of the source box*/
  208. REGION_SUBTRACT(&rgnExposed, &rgnExposed, prgnSrcClip);
  209. /* move them over the destination */
  210. REGION_TRANSLATE(&rgnExposed, dstx-srcx, dsty-srcy);
  211. /* intersect with visible areas of dest */
  212. REGION_INTERSECT(&rgnExposed, &rgnExposed, prgnDstClip);
  213. /*
  214. * If we have LOTS of rectangles, we decide to take the extents
  215. * and force an exposure on that. This should require much less
  216. * work overall, on both client and server. This is cheating, but
  217. * isn't prohibited by the protocol ("spontaneous combustion" :-)
  218. * for windows.
  219. */
  220. extents = pGC->graphicsExposures &&
  221. (REGION_NUM_RECTS(&rgnExposed) > RECTLIMIT) &&
  222. (pDstDrawable->type != DRAWABLE_PIXMAP);
  223. if (pSrcWin)
  224. {
  225. RegionPtr region;
  226. if (!(region = wClipShape (pSrcWin)))
  227. region = wBoundingShape (pSrcWin);
  228. /*
  229. * If you try to CopyArea the extents of a shaped window, compacting the
  230. * exposed region will undo all our work!
  231. */
  232. if (extents && pSrcWin && region &&
  233. (RECT_IN_REGION(region, &srcBox) != rgnIN))
  234. extents = FALSE;
  235. }
  236. if (extents)
  237. {
  238. expBox = *REGION_EXTENTS(&rgnExposed);
  239. REGION_RESET(&rgnExposed, &expBox);
  240. }
  241. if ((pDstDrawable->type != DRAWABLE_PIXMAP) &&
  242. (((WindowPtr)pDstDrawable)->backgroundState != None))
  243. {
  244. WindowPtr pWin = (WindowPtr)pDstDrawable;
  245. /* make the exposed area screen-relative */
  246. REGION_TRANSLATE(&rgnExposed,
  247. pDstDrawable->x, pDstDrawable->y);
  248. if (extents)
  249. {
  250. /* PaintWindowBackground doesn't clip, so we have to */
  251. REGION_INTERSECT(&rgnExposed, &rgnExposed, &pWin->clipList);
  252. }
  253. (*pWin->drawable.pScreen->PaintWindowBackground)(
  254. (WindowPtr)pDstDrawable, &rgnExposed, PW_BACKGROUND);
  255. if (extents)
  256. {
  257. REGION_RESET(&rgnExposed, &expBox);
  258. }
  259. else
  260. REGION_TRANSLATE(&rgnExposed,
  261. -pDstDrawable->x, -pDstDrawable->y);
  262. }
  263. if (prgnDstClip == &rgnDstRec)
  264. {
  265. REGION_UNINIT(prgnDstClip);
  266. }
  267. else if (prgnDstClip != prgnSrcClip)
  268. {
  269. REGION_DESTROY(prgnDstClip);
  270. }
  271. if (prgnSrcClip == &rgnSrcRec)
  272. {
  273. REGION_UNINIT(prgnSrcClip);
  274. }
  275. else
  276. {
  277. REGION_DESTROY(prgnSrcClip);
  278. }
  279. if (pGC->graphicsExposures)
  280. {
  281. /* don't look */
  282. RegionPtr exposed = REGION_CREATE(NullBox, 0);
  283. *exposed = rgnExposed;
  284. return exposed;
  285. }
  286. else
  287. {
  288. REGION_UNINIT(&rgnExposed);
  289. return NULL;
  290. }
  291. }
  292. /* send GraphicsExpose events, or a NoExpose event, based on the region */
  293. _X_EXPORT void
  294. miSendGraphicsExpose (client, pRgn, drawable, major, minor)
  295. ClientPtr client;
  296. RegionPtr pRgn;
  297. XID drawable;
  298. int major;
  299. int minor;
  300. {
  301. if (pRgn && !REGION_NIL(pRgn))
  302. {
  303. xEvent *pEvent;
  304. xEvent *pe;
  305. BoxPtr pBox;
  306. int i;
  307. int numRects;
  308. numRects = REGION_NUM_RECTS(pRgn);
  309. pBox = REGION_RECTS(pRgn);
  310. if(!(pEvent = (xEvent *)ALLOCATE_LOCAL(numRects * sizeof(xEvent))))
  311. return;
  312. pe = pEvent;
  313. for (i=1; i<=numRects; i++, pe++, pBox++)
  314. {
  315. pe->u.u.type = GraphicsExpose;
  316. pe->u.graphicsExposure.drawable = drawable;
  317. pe->u.graphicsExposure.x = pBox->x1;
  318. pe->u.graphicsExposure.y = pBox->y1;
  319. pe->u.graphicsExposure.width = pBox->x2 - pBox->x1;
  320. pe->u.graphicsExposure.height = pBox->y2 - pBox->y1;
  321. pe->u.graphicsExposure.count = numRects - i;
  322. pe->u.graphicsExposure.majorEvent = major;
  323. pe->u.graphicsExposure.minorEvent = minor;
  324. }
  325. TryClientEvents(client, pEvent, numRects,
  326. (Mask)0, NoEventMask, NullGrab);
  327. DEALLOCATE_LOCAL(pEvent);
  328. }
  329. else
  330. {
  331. xEvent event;
  332. event.u.u.type = NoExpose;
  333. event.u.noExposure.drawable = drawable;
  334. event.u.noExposure.majorEvent = major;
  335. event.u.noExposure.minorEvent = minor;
  336. TryClientEvents(client, &event, 1,
  337. (Mask)0, NoEventMask, NullGrab);
  338. }
  339. }
  340. void
  341. miSendExposures(pWin, pRgn, dx, dy)
  342. WindowPtr pWin;
  343. RegionPtr pRgn;
  344. int dx, dy;
  345. {
  346. BoxPtr pBox;
  347. int numRects;
  348. xEvent *pEvent, *pe;
  349. int i;
  350. pBox = REGION_RECTS(pRgn);
  351. numRects = REGION_NUM_RECTS(pRgn);
  352. if(!(pEvent = (xEvent *) ALLOCATE_LOCAL(numRects * sizeof(xEvent))))
  353. return;
  354. for (i=numRects, pe = pEvent; --i >= 0; pe++, pBox++)
  355. {
  356. pe->u.u.type = Expose;
  357. pe->u.expose.window = pWin->drawable.id;
  358. pe->u.expose.x = pBox->x1 - dx;
  359. pe->u.expose.y = pBox->y1 - dy;
  360. pe->u.expose.width = pBox->x2 - pBox->x1;
  361. pe->u.expose.height = pBox->y2 - pBox->y1;
  362. pe->u.expose.count = i;
  363. }
  364. DeliverEvents(pWin, pEvent, numRects, NullWindow);
  365. DEALLOCATE_LOCAL(pEvent);
  366. }
  367. _X_EXPORT void
  368. miWindowExposures(pWin, prgn, other_exposed)
  369. WindowPtr pWin;
  370. RegionPtr prgn, other_exposed;
  371. {
  372. RegionPtr exposures = prgn;
  373. if ((prgn && !REGION_NIL(prgn)) ||
  374. (exposures && !REGION_NIL(exposures)) || other_exposed)
  375. {
  376. RegionRec expRec;
  377. int clientInterested;
  378. /*
  379. * Restore from backing-store FIRST.
  380. */
  381. clientInterested = (pWin->eventMask|wOtherEventMasks(pWin)) & ExposureMask;
  382. if (other_exposed)
  383. {
  384. if (exposures)
  385. {
  386. REGION_UNION(other_exposed,
  387. exposures,
  388. other_exposed);
  389. if (exposures != prgn)
  390. REGION_DESTROY(exposures);
  391. }
  392. exposures = other_exposed;
  393. }
  394. if (clientInterested && exposures && (REGION_NUM_RECTS(exposures) > RECTLIMIT))
  395. {
  396. /*
  397. * If we have LOTS of rectangles, we decide to take the extents
  398. * and force an exposure on that. This should require much less
  399. * work overall, on both client and server. This is cheating, but
  400. * isn't prohibited by the protocol ("spontaneous combustion" :-).
  401. */
  402. BoxRec box;
  403. box = *REGION_EXTENTS(exposures);
  404. if (exposures == prgn) {
  405. exposures = &expRec;
  406. REGION_INIT(exposures, &box, 1);
  407. REGION_RESET(prgn, &box);
  408. } else {
  409. REGION_RESET(exposures, &box);
  410. REGION_UNION(prgn, prgn, exposures);
  411. }
  412. /* PaintWindowBackground doesn't clip, so we have to */
  413. REGION_INTERSECT(prgn, prgn, &pWin->clipList);
  414. }
  415. if (prgn && !REGION_NIL(prgn))
  416. (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, prgn, PW_BACKGROUND);
  417. if (clientInterested && exposures && !REGION_NIL(exposures))
  418. miSendExposures(pWin, exposures,
  419. pWin->drawable.x, pWin->drawable.y);
  420. if (exposures == &expRec)
  421. {
  422. REGION_UNINIT(exposures);
  423. }
  424. else if (exposures && exposures != prgn && exposures != other_exposed)
  425. REGION_DESTROY(exposures);
  426. if (prgn)
  427. REGION_EMPTY(prgn);
  428. }
  429. else if (exposures && exposures != prgn)
  430. REGION_DESTROY(exposures);
  431. }
  432. /*
  433. this code is highly unlikely. it is not haile selassie.
  434. there is some hair here. we can't just use the window's
  435. clip region as it is, because if we are painting the border,
  436. the border is not in the client area and so we will be excluded
  437. when we validate the GC, and if we are painting a parent-relative
  438. background, the area we want to paint is in some other window.
  439. since we trust the code calling us to tell us to paint only areas
  440. that are really ours, we will temporarily give the window a
  441. clipList the size of the whole screen and an origin at (0,0).
  442. this more or less assumes that ddX code will do translation
  443. based on the window's absolute position, and that ValidateGC will
  444. look at clipList, and that no other fields from the
  445. window will be used. it's not possible to just draw
  446. in the root because it may be a different depth.
  447. to get the tile to align correctly we set the GC's tile origin to
  448. be the (x,y) of the window's upper left corner, after which we
  449. get the right bits when drawing into the root.
  450. because the clip_mask is being set to None, we may call DoChangeGC with
  451. fPointer set true, thus we no longer need to install the background or
  452. border tile in the resource table.
  453. */
  454. /* MICLEARDRAWABLE -- sets the entire drawable to the background color of
  455. * the GC. Useful when we have a scratch drawable and need to initialize
  456. * it. */
  457. _X_EXPORT void
  458. miClearDrawable(pDraw, pGC)
  459. DrawablePtr pDraw;
  460. GCPtr pGC;
  461. {
  462. XID fg = pGC->fgPixel;
  463. XID bg = pGC->bgPixel;
  464. xRectangle rect;
  465. rect.x = 0;
  466. rect.y = 0;
  467. rect.width = pDraw->width;
  468. rect.height = pDraw->height;
  469. DoChangeGC(pGC, GCForeground, &bg, 0);
  470. ValidateGC(pDraw, pGC);
  471. (*pGC->ops->PolyFillRect)(pDraw, pGC, 1, &rect);
  472. DoChangeGC(pGC, GCForeground, &fg, 0);
  473. ValidateGC(pDraw, pGC);
  474. }