mivaltree.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /*
  2. * mivaltree.c --
  3. * Functions for recalculating window clip lists. Main function
  4. * is miValidateTree.
  5. *
  6. Copyright 1987, 1988, 1989, 1998 The Open Group
  7. Permission to use, copy, modify, distribute, and sell this software and its
  8. documentation for any purpose is hereby granted without fee, provided that
  9. the above copyright notice appear in all copies and that both that
  10. copyright notice and this permission notice appear in supporting
  11. documentation.
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  18. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. Except as contained in this notice, the name of The Open Group shall not be
  21. used in advertising or otherwise to promote the sale, use or other dealings
  22. in this Software without prior written authorization from The Open Group.
  23. *
  24. * Copyright 1987, 1988, 1989 by
  25. * Digital Equipment Corporation, Maynard, Massachusetts,
  26. *
  27. * All Rights Reserved
  28. *
  29. * Permission to use, copy, modify, and distribute this software and its
  30. * documentation for any purpose and without fee is hereby granted,
  31. * provided that the above copyright notice appear in all copies and that
  32. * both that copyright notice and this permission notice appear in
  33. * supporting documentation, and that the name of Digital not be
  34. * used in advertising or publicity pertaining to distribution of the
  35. * software without specific, written prior permission.
  36. *
  37. * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  38. * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  39. * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  40. * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  41. * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  42. * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  43. * SOFTWARE.
  44. *
  45. ******************************************************************/
  46. /* The panoramix components contained the following notice */
  47. /*****************************************************************
  48. Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
  49. Permission is hereby granted, free of charge, to any person obtaining a copy
  50. of this software and associated documentation files (the "Software"), to deal
  51. in the Software without restriction, including without limitation the rights
  52. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  53. copies of the Software.
  54. The above copyright notice and this permission notice shall be included in
  55. all copies or substantial portions of the Software.
  56. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  57. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  58. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  59. DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
  60. BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
  61. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  62. IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  63. Except as contained in this notice, the name of Digital Equipment Corporation
  64. shall not be used in advertising or otherwise to promote the sale, use or other
  65. dealings in this Software without prior written authorization from Digital
  66. Equipment Corporation.
  67. ******************************************************************/
  68. /*
  69. * Aug '86: Susan Angebranndt -- original code
  70. * July '87: Adam de Boor -- substantially modified and commented
  71. * Summer '89: Joel McCormack -- so fast you wouldn't believe it possible.
  72. * In particular, much improved code for window mapping and
  73. * circulating.
  74. * Bob Scheifler -- avoid miComputeClips for unmapped windows,
  75. * valdata changes
  76. */
  77. #ifdef HAVE_DIX_CONFIG_H
  78. #include <dix-config.h>
  79. #endif
  80. #include <X11/X.h>
  81. #include "scrnintstr.h"
  82. #include "validate.h"
  83. #include "windowstr.h"
  84. #include "mi.h"
  85. #include "regionstr.h"
  86. #include "mivalidate.h"
  87. #include "globals.h"
  88. /*
  89. * Compute the visibility of a shaped window
  90. */
  91. _X_EXPORT int
  92. miShapedWindowIn (pScreen, universe, bounding, rect, x, y)
  93. ScreenPtr pScreen;
  94. RegionPtr universe, bounding;
  95. BoxPtr rect;
  96. int x, y;
  97. {
  98. BoxRec box;
  99. BoxPtr boundBox;
  100. int nbox;
  101. Bool someIn, someOut;
  102. int t, x1, y1, x2, y2;
  103. nbox = REGION_NUM_RECTS (bounding);
  104. boundBox = REGION_RECTS (bounding);
  105. someIn = someOut = FALSE;
  106. x1 = rect->x1;
  107. y1 = rect->y1;
  108. x2 = rect->x2;
  109. y2 = rect->y2;
  110. while (nbox--)
  111. {
  112. if ((t = boundBox->x1 + x) < x1)
  113. t = x1;
  114. box.x1 = t;
  115. if ((t = boundBox->y1 + y) < y1)
  116. t = y1;
  117. box.y1 = t;
  118. if ((t = boundBox->x2 + x) > x2)
  119. t = x2;
  120. box.x2 = t;
  121. if ((t = boundBox->y2 + y) > y2)
  122. t = y2;
  123. box.y2 = t;
  124. if (box.x1 > box.x2)
  125. box.x2 = box.x1;
  126. if (box.y1 > box.y2)
  127. box.y2 = box.y1;
  128. switch (RECT_IN_REGION(universe, &box))
  129. {
  130. case rgnIN:
  131. if (someOut)
  132. return rgnPART;
  133. someIn = TRUE;
  134. break;
  135. case rgnOUT:
  136. if (someIn)
  137. return rgnPART;
  138. someOut = TRUE;
  139. break;
  140. default:
  141. return rgnPART;
  142. }
  143. boundBox++;
  144. }
  145. if (someIn)
  146. return rgnIN;
  147. return rgnOUT;
  148. }
  149. #define HasParentRelativeBorder(w) (!(w)->borderIsPixel && \
  150. HasBorder(w) && \
  151. (w)->backgroundState == ParentRelative)
  152. /*
  153. *-----------------------------------------------------------------------
  154. * miComputeClips --
  155. * Recompute the clipList, borderClip, exposed and borderExposed
  156. * regions for pParent and its children. Only viewable windows are
  157. * taken into account.
  158. *
  159. * Results:
  160. * None.
  161. *
  162. * Side Effects:
  163. * clipList, borderClip, exposed and borderExposed are altered.
  164. * A VisibilityNotify event may be generated on the parent window.
  165. *
  166. *-----------------------------------------------------------------------
  167. */
  168. static void
  169. miComputeClips (
  170. register WindowPtr pParent,
  171. register ScreenPtr pScreen,
  172. register RegionPtr universe,
  173. VTKind kind,
  174. RegionPtr exposed ) /* for intermediate calculations */
  175. {
  176. int dx,
  177. dy;
  178. RegionRec childUniverse;
  179. WindowPtr pChild;
  180. int oldVis, newVis;
  181. BoxRec borderSize;
  182. RegionRec childUnion;
  183. Bool overlap;
  184. RegionPtr borderVisible;
  185. /*
  186. * Figure out the new visibility of this window.
  187. * The extent of the universe should be the same as the extent of
  188. * the borderSize region. If the window is unobscured, this rectangle
  189. * will be completely inside the universe (the universe will cover it
  190. * completely). If the window is completely obscured, none of the
  191. * universe will cover the rectangle.
  192. */
  193. borderSize.x1 = pParent->drawable.x - wBorderWidth(pParent);
  194. borderSize.y1 = pParent->drawable.y - wBorderWidth(pParent);
  195. dx = (int) pParent->drawable.x + (int) pParent->drawable.width + wBorderWidth(pParent);
  196. if (dx > 32767)
  197. dx = 32767;
  198. borderSize.x2 = dx;
  199. dy = (int) pParent->drawable.y + (int) pParent->drawable.height + wBorderWidth(pParent);
  200. if (dy > 32767)
  201. dy = 32767;
  202. borderSize.y2 = dy;
  203. oldVis = pParent->visibility;
  204. switch (RECT_IN_REGION(universe, &borderSize))
  205. {
  206. case rgnIN:
  207. newVis = VisibilityUnobscured;
  208. break;
  209. case rgnPART:
  210. newVis = VisibilityPartiallyObscured;
  211. {
  212. RegionPtr pBounding;
  213. if ((pBounding = wBoundingShape (pParent)))
  214. {
  215. switch (miShapedWindowIn (pScreen, universe, pBounding,
  216. &borderSize,
  217. pParent->drawable.x,
  218. pParent->drawable.y))
  219. {
  220. case rgnIN:
  221. newVis = VisibilityUnobscured;
  222. break;
  223. case rgnOUT:
  224. newVis = VisibilityFullyObscured;
  225. break;
  226. }
  227. }
  228. }
  229. break;
  230. default:
  231. newVis = VisibilityFullyObscured;
  232. break;
  233. }
  234. pParent->visibility = newVis;
  235. if (oldVis != newVis &&
  236. ((pParent->eventMask | wOtherEventMasks(pParent)) & VisibilityChangeMask))
  237. SendVisibilityNotify(pParent);
  238. dx = pParent->drawable.x - pParent->valdata->before.oldAbsCorner.x;
  239. dy = pParent->drawable.y - pParent->valdata->before.oldAbsCorner.y;
  240. /*
  241. * avoid computations when dealing with simple operations
  242. */
  243. switch (kind) {
  244. case VTMap:
  245. case VTStack:
  246. case VTUnmap:
  247. break;
  248. case VTMove:
  249. if ((oldVis == newVis) &&
  250. ((oldVis == VisibilityFullyObscured) ||
  251. (oldVis == VisibilityUnobscured)))
  252. {
  253. pChild = pParent;
  254. while (1)
  255. {
  256. if (pChild->viewable)
  257. {
  258. if (pChild->visibility != VisibilityFullyObscured)
  259. {
  260. REGION_TRANSLATE(&pChild->borderClip,
  261. dx, dy);
  262. REGION_TRANSLATE(&pChild->clipList,
  263. dx, dy);
  264. pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  265. if (pScreen->ClipNotify)
  266. (* pScreen->ClipNotify) (pChild, dx, dy);
  267. }
  268. if (pChild->valdata)
  269. {
  270. REGION_NULL(
  271. &pChild->valdata->after.borderExposed);
  272. if (HasParentRelativeBorder(pChild))
  273. {
  274. REGION_SUBTRACT(
  275. &pChild->valdata->after.borderExposed,
  276. &pChild->borderClip,
  277. &pChild->winSize);
  278. }
  279. REGION_NULL(&pChild->valdata->after.exposed);
  280. }
  281. if (pChild->firstChild)
  282. {
  283. pChild = pChild->firstChild;
  284. continue;
  285. }
  286. }
  287. while (!pChild->nextSib && (pChild != pParent))
  288. pChild = pChild->parent;
  289. if (pChild == pParent)
  290. break;
  291. pChild = pChild->nextSib;
  292. }
  293. return;
  294. }
  295. /* fall through */
  296. default:
  297. /*
  298. * To calculate exposures correctly, we have to translate the old
  299. * borderClip and clipList regions to the window's new location so there
  300. * is a correspondence between pieces of the new and old clipping regions.
  301. */
  302. if (dx || dy)
  303. {
  304. /*
  305. * We translate the old clipList because that will be exposed or copied
  306. * if gravity is right.
  307. */
  308. REGION_TRANSLATE(&pParent->borderClip, dx, dy);
  309. REGION_TRANSLATE(&pParent->clipList, dx, dy);
  310. }
  311. break;
  312. case VTBroken:
  313. REGION_EMPTY(&pParent->borderClip);
  314. REGION_EMPTY(&pParent->clipList);
  315. break;
  316. }
  317. borderVisible = pParent->valdata->before.borderVisible;
  318. REGION_NULL(&pParent->valdata->after.borderExposed);
  319. REGION_NULL(&pParent->valdata->after.exposed);
  320. /*
  321. * Since the borderClip must not be clipped by the children, we do
  322. * the border exposure first...
  323. *
  324. * 'universe' is the window's borderClip. To figure the exposures, remove
  325. * the area that used to be exposed from the new.
  326. * This leaves a region of pieces that weren't exposed before.
  327. */
  328. if (HasBorder (pParent))
  329. {
  330. if (borderVisible)
  331. {
  332. /*
  333. * when the border changes shape, the old visible portions
  334. * of the border will be saved by DIX in borderVisible --
  335. * use that region and destroy it
  336. */
  337. REGION_SUBTRACT(exposed, universe, borderVisible);
  338. REGION_DESTROY(borderVisible);
  339. }
  340. else
  341. {
  342. REGION_SUBTRACT(exposed, universe, &pParent->borderClip);
  343. }
  344. if (HasParentRelativeBorder(pParent) && (dx || dy))
  345. REGION_SUBTRACT(&pParent->valdata->after.borderExposed,
  346. universe,
  347. &pParent->winSize);
  348. else
  349. REGION_SUBTRACT(&pParent->valdata->after.borderExposed,
  350. exposed, &pParent->winSize);
  351. REGION_COPY(&pParent->borderClip, universe);
  352. /*
  353. * To get the right clipList for the parent, and to make doubly sure
  354. * that no child overlaps the parent's border, we remove the parent's
  355. * border from the universe before proceeding.
  356. */
  357. REGION_INTERSECT(universe, universe, &pParent->winSize);
  358. }
  359. else
  360. REGION_COPY(&pParent->borderClip, universe);
  361. if ((pChild = pParent->firstChild) && pParent->mapped)
  362. {
  363. REGION_NULL(&childUniverse);
  364. REGION_NULL(&childUnion);
  365. if ((pChild->drawable.y < pParent->lastChild->drawable.y) ||
  366. ((pChild->drawable.y == pParent->lastChild->drawable.y) &&
  367. (pChild->drawable.x < pParent->lastChild->drawable.x)))
  368. {
  369. for (; pChild; pChild = pChild->nextSib)
  370. {
  371. if (pChild->viewable)
  372. REGION_APPEND(&childUnion, &pChild->borderSize);
  373. }
  374. }
  375. else
  376. {
  377. for (pChild = pParent->lastChild; pChild; pChild = pChild->prevSib)
  378. {
  379. if (pChild->viewable)
  380. REGION_APPEND(&childUnion, &pChild->borderSize);
  381. }
  382. }
  383. REGION_VALIDATE(&childUnion, &overlap);
  384. for (pChild = pParent->firstChild;
  385. pChild;
  386. pChild = pChild->nextSib)
  387. {
  388. if (pChild->viewable) {
  389. /*
  390. * If the child is viewable, we want to remove its extents
  391. * from the current universe, but we only re-clip it if
  392. * it's been marked.
  393. */
  394. if (pChild->valdata) {
  395. /*
  396. * Figure out the new universe from the child's
  397. * perspective and recurse.
  398. */
  399. REGION_INTERSECT(&childUniverse,
  400. universe,
  401. &pChild->borderSize);
  402. miComputeClips (pChild, pScreen, &childUniverse, kind,
  403. exposed);
  404. }
  405. /*
  406. * Once the child has been processed, we remove its extents
  407. * from the current universe, thus denying its space to any
  408. * other sibling.
  409. */
  410. if (overlap)
  411. REGION_SUBTRACT(universe, universe,
  412. &pChild->borderSize);
  413. }
  414. }
  415. if (!overlap)
  416. REGION_SUBTRACT(universe, universe, &childUnion);
  417. REGION_UNINIT(&childUnion);
  418. REGION_UNINIT(&childUniverse);
  419. } /* if any children */
  420. /*
  421. * 'universe' now contains the new clipList for the parent window.
  422. *
  423. * To figure the exposure of the window we subtract the old clip from the
  424. * new, just as for the border.
  425. */
  426. if (oldVis == VisibilityFullyObscured ||
  427. oldVis == VisibilityNotViewable)
  428. {
  429. REGION_COPY(&pParent->valdata->after.exposed, universe);
  430. }
  431. else if (newVis != VisibilityFullyObscured &&
  432. newVis != VisibilityNotViewable)
  433. {
  434. REGION_SUBTRACT(&pParent->valdata->after.exposed,
  435. universe, &pParent->clipList);
  436. }
  437. /* HACK ALERT - copying contents of regions, instead of regions */
  438. {
  439. RegionRec tmp;
  440. tmp = pParent->clipList;
  441. pParent->clipList = *universe;
  442. *universe = tmp;
  443. }
  444. #ifdef NOTDEF
  445. REGION_COPY(&pParent->clipList, universe);
  446. #endif
  447. pParent->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  448. if (pScreen->ClipNotify)
  449. (* pScreen->ClipNotify) (pParent, dx, dy);
  450. }
  451. static void
  452. miTreeObscured(
  453. register WindowPtr pParent )
  454. {
  455. WindowPtr pChild;
  456. int oldVis;
  457. pChild = pParent;
  458. while (1)
  459. {
  460. if (pChild->viewable)
  461. {
  462. oldVis = pChild->visibility;
  463. if (oldVis != (pChild->visibility = VisibilityFullyObscured) &&
  464. ((pChild->eventMask | wOtherEventMasks(pChild)) & VisibilityChangeMask))
  465. SendVisibilityNotify(pChild);
  466. if (pChild->firstChild)
  467. {
  468. pChild = pChild->firstChild;
  469. continue;
  470. }
  471. }
  472. while (!pChild->nextSib && (pChild != pParent))
  473. pChild = pChild->parent;
  474. if (pChild == pParent)
  475. break;
  476. pChild = pChild->nextSib;
  477. }
  478. }
  479. /*
  480. *-----------------------------------------------------------------------
  481. * miValidateTree --
  482. * Recomputes the clip list for pParent and all its inferiors.
  483. *
  484. * Results:
  485. * Always returns 1.
  486. *
  487. * Side Effects:
  488. * The clipList, borderClip, exposed, and borderExposed regions for
  489. * each marked window are altered.
  490. *
  491. * Notes:
  492. * This routine assumes that all affected windows have been marked
  493. * (valdata created) and their winSize and borderSize regions
  494. * adjusted to correspond to their new positions. The borderClip and
  495. * clipList regions should not have been touched.
  496. *
  497. * The top-most level is treated differently from all lower levels
  498. * because pParent is unchanged. For the top level, we merge the
  499. * regions taken up by the marked children back into the clipList
  500. * for pParent, thus forming a region from which the marked children
  501. * can claim their areas. For lower levels, where the old clipList
  502. * and borderClip are invalid, we can't do this and have to do the
  503. * extra operations done in miComputeClips, but this is much faster
  504. * e.g. when only one child has moved...
  505. *
  506. *-----------------------------------------------------------------------
  507. */
  508. /*ARGSUSED*/
  509. int
  510. miValidateTree (pParent, pChild, kind)
  511. WindowPtr pParent; /* Parent to validate */
  512. WindowPtr pChild; /* First child of pParent that was
  513. * affected */
  514. VTKind kind; /* What kind of configuration caused call */
  515. {
  516. RegionRec totalClip; /* Total clipping region available to
  517. * the marked children. pParent's clipList
  518. * merged with the borderClips of all
  519. * the marked children. */
  520. RegionRec childClip; /* The new borderClip for the current
  521. * child */
  522. RegionRec childUnion; /* the space covered by borderSize for
  523. * all marked children */
  524. RegionRec exposed; /* For intermediate calculations */
  525. ScreenPtr pScreen;
  526. WindowPtr pWin;
  527. Bool overlap;
  528. int viewvals;
  529. Bool forward;
  530. pScreen = pParent->drawable.pScreen;
  531. if (pChild == NullWindow)
  532. pChild = pParent->firstChild;
  533. REGION_NULL(&childClip);
  534. REGION_NULL(&exposed);
  535. /*
  536. * compute the area of the parent window occupied
  537. * by the marked children + the parent itself. This
  538. * is the area which can be divied up among the marked
  539. * children in their new configuration.
  540. */
  541. REGION_NULL(&totalClip);
  542. viewvals = 0;
  543. if (REGION_BROKEN(&pParent->clipList) &&
  544. !REGION_BROKEN(&pParent->borderClip))
  545. {
  546. kind = VTBroken;
  547. /*
  548. * When rebuilding clip lists after out of memory,
  549. * assume everything is busted.
  550. */
  551. forward = TRUE;
  552. REGION_COPY(&totalClip, &pParent->borderClip);
  553. REGION_INTERSECT(&totalClip, &totalClip, &pParent->winSize);
  554. for (pWin = pParent->firstChild; pWin != pChild; pWin = pWin->nextSib)
  555. {
  556. if (pWin->viewable)
  557. REGION_SUBTRACT(&totalClip, &totalClip, &pWin->borderSize);
  558. }
  559. for (pWin = pChild; pWin; pWin = pWin->nextSib)
  560. if (pWin->valdata && pWin->viewable)
  561. viewvals++;
  562. REGION_EMPTY(&pParent->clipList);
  563. }
  564. else
  565. {
  566. if ((pChild->drawable.y < pParent->lastChild->drawable.y) ||
  567. ((pChild->drawable.y == pParent->lastChild->drawable.y) &&
  568. (pChild->drawable.x < pParent->lastChild->drawable.x)))
  569. {
  570. forward = TRUE;
  571. for (pWin = pChild; pWin; pWin = pWin->nextSib)
  572. {
  573. if (pWin->valdata)
  574. {
  575. RegionPtr pBorderClip = &pWin->borderClip;
  576. REGION_APPEND(&totalClip, pBorderClip );
  577. if (pWin->viewable)
  578. viewvals++;
  579. }
  580. }
  581. }
  582. else
  583. {
  584. forward = FALSE;
  585. pWin = pParent->lastChild;
  586. while (1)
  587. {
  588. if (pWin->valdata)
  589. {
  590. RegionPtr pBorderClip = &pWin->borderClip;
  591. REGION_APPEND(&totalClip, pBorderClip );
  592. if (pWin->viewable)
  593. viewvals++;
  594. }
  595. if (pWin == pChild)
  596. break;
  597. pWin = pWin->prevSib;
  598. }
  599. }
  600. REGION_VALIDATE(&totalClip, &overlap);
  601. }
  602. /*
  603. * Now go through the children of the root and figure their new
  604. * borderClips from the totalClip, passing that off to miComputeClips
  605. * to handle recursively. Once that's done, we remove the child
  606. * from the totalClip to clip any siblings below it.
  607. */
  608. overlap = TRUE;
  609. if (kind != VTStack)
  610. {
  611. REGION_UNION(&totalClip, &totalClip, &pParent->clipList);
  612. if (viewvals > 1)
  613. {
  614. /*
  615. * precompute childUnion to discover whether any of them
  616. * overlap. This seems redundant, but performance studies
  617. * have demonstrated that the cost of this loop is
  618. * lower than the cost of multiple Subtracts in the
  619. * loop below.
  620. */
  621. REGION_NULL(&childUnion);
  622. if (forward)
  623. {
  624. for (pWin = pChild; pWin; pWin = pWin->nextSib)
  625. if (pWin->valdata && pWin->viewable)
  626. REGION_APPEND(&childUnion,
  627. &pWin->borderSize);
  628. }
  629. else
  630. {
  631. pWin = pParent->lastChild;
  632. while (1)
  633. {
  634. if (pWin->valdata && pWin->viewable)
  635. REGION_APPEND(&childUnion,
  636. &pWin->borderSize);
  637. if (pWin == pChild)
  638. break;
  639. pWin = pWin->prevSib;
  640. }
  641. }
  642. REGION_VALIDATE(&childUnion, &overlap);
  643. if (overlap)
  644. REGION_UNINIT(&childUnion);
  645. }
  646. }
  647. for (pWin = pChild;
  648. pWin != NullWindow;
  649. pWin = pWin->nextSib)
  650. {
  651. if (pWin->viewable) {
  652. if (pWin->valdata) {
  653. REGION_INTERSECT(&childClip,
  654. &totalClip,
  655. &pWin->borderSize);
  656. miComputeClips (pWin, pScreen, &childClip, kind, &exposed);
  657. if (overlap)
  658. {
  659. REGION_SUBTRACT(&totalClip,
  660. &totalClip,
  661. &pWin->borderSize);
  662. }
  663. } else if (pWin->visibility == VisibilityNotViewable) {
  664. miTreeObscured(pWin);
  665. }
  666. } else {
  667. if (pWin->valdata) {
  668. REGION_EMPTY(&pWin->clipList);
  669. if (pScreen->ClipNotify)
  670. (* pScreen->ClipNotify) (pWin, 0, 0);
  671. REGION_EMPTY(&pWin->borderClip);
  672. pWin->valdata = (ValidatePtr)NULL;
  673. }
  674. }
  675. }
  676. REGION_UNINIT(&childClip);
  677. if (!overlap)
  678. {
  679. REGION_SUBTRACT(&totalClip, &totalClip, &childUnion);
  680. REGION_UNINIT(&childUnion);
  681. }
  682. REGION_NULL(&pParent->valdata->after.exposed);
  683. REGION_NULL(&pParent->valdata->after.borderExposed);
  684. /*
  685. * each case below is responsible for updating the
  686. * clipList and serial number for the parent window
  687. */
  688. switch (kind) {
  689. case VTStack:
  690. break;
  691. default:
  692. /*
  693. * totalClip contains the new clipList for the parent. Figure out
  694. * exposures and obscures as per miComputeClips and reset the parent's
  695. * clipList.
  696. */
  697. REGION_SUBTRACT(&pParent->valdata->after.exposed,
  698. &totalClip, &pParent->clipList);
  699. /* fall through */
  700. case VTMap:
  701. REGION_COPY(&pParent->clipList, &totalClip);
  702. pParent->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  703. break;
  704. }
  705. REGION_UNINIT(&totalClip);
  706. REGION_UNINIT(&exposed);
  707. if (pScreen->ClipNotify)
  708. (*pScreen->ClipNotify) (pParent, 0, 0);
  709. return (1);
  710. }