migc.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. Copyright 1993, 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
  9. in all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  14. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  15. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  16. OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall
  18. not be used in advertising or otherwise to promote the sale, use or
  19. other dealings in this Software without prior written authorization
  20. from The Open Group.
  21. */
  22. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include "scrnintstr.h"
  26. #include "gcstruct.h"
  27. #include "pixmapstr.h"
  28. #include "windowstr.h"
  29. #include "migc.h"
  30. /* ARGSUSED */
  31. _X_EXPORT void
  32. miChangeGC(pGC, mask)
  33. GCPtr pGC;
  34. unsigned long mask;
  35. {
  36. return;
  37. }
  38. _X_EXPORT void
  39. miDestroyGC(pGC)
  40. GCPtr pGC;
  41. {
  42. if (pGC->pRotatedPixmap)
  43. (*pGC->pScreen->DestroyPixmap) (pGC->pRotatedPixmap);
  44. if (pGC->freeCompClip)
  45. REGION_DESTROY(pGC->pCompositeClip);
  46. miDestroyGCOps(pGC->ops);
  47. }
  48. /*
  49. * create a private op array for a gc
  50. */
  51. _X_EXPORT GCOpsPtr
  52. miCreateGCOps(prototype)
  53. GCOpsPtr prototype;
  54. {
  55. GCOpsPtr ret;
  56. /* XXX */ Must_have_memory = TRUE;
  57. ret = malloc(sizeof(GCOps));
  58. /* XXX */ Must_have_memory = FALSE;
  59. if (!ret)
  60. return 0;
  61. *ret = *prototype;
  62. ret->devPrivate.val = 1;
  63. return ret;
  64. }
  65. _X_EXPORT void
  66. miDestroyGCOps(ops)
  67. GCOpsPtr ops;
  68. {
  69. if (ops->devPrivate.val)
  70. free(ops);
  71. }
  72. _X_EXPORT void
  73. miDestroyClip(pGC)
  74. GCPtr pGC;
  75. {
  76. if (pGC->clientClipType == CT_NONE)
  77. return;
  78. else if (pGC->clientClipType == CT_PIXMAP)
  79. {
  80. (*pGC->pScreen->DestroyPixmap) ((PixmapPtr) (pGC->clientClip));
  81. }
  82. else
  83. {
  84. /*
  85. * we know we'll never have a list of rectangles, since ChangeClip
  86. * immediately turns them into a region
  87. */
  88. REGION_DESTROY(pGC->clientClip);
  89. }
  90. pGC->clientClip = NULL;
  91. pGC->clientClipType = CT_NONE;
  92. }
  93. _X_EXPORT void
  94. miChangeClip(pGC, type, pvalue, nrects)
  95. GCPtr pGC;
  96. int type;
  97. pointer pvalue;
  98. int nrects;
  99. {
  100. (*pGC->funcs->DestroyClip) (pGC);
  101. if (type == CT_PIXMAP)
  102. {
  103. /* convert the pixmap to a region */
  104. pGC->clientClip = (pointer) BITMAP_TO_REGION(pGC->pScreen,
  105. (PixmapPtr) pvalue);
  106. (*pGC->pScreen->DestroyPixmap) (pvalue);
  107. }
  108. else if (type == CT_REGION)
  109. {
  110. /* stuff the region in the GC */
  111. pGC->clientClip = pvalue;
  112. }
  113. else if (type != CT_NONE)
  114. {
  115. pGC->clientClip = (pointer) RECTS_TO_REGION(nrects,
  116. (xRectangle *) pvalue,
  117. type);
  118. free(pvalue);
  119. }
  120. pGC->clientClipType = (type != CT_NONE && pGC->clientClip) ? CT_REGION : CT_NONE;
  121. pGC->stateChanges |= GCClipMask;
  122. }
  123. _X_EXPORT void
  124. miCopyClip(pgcDst, pgcSrc)
  125. GCPtr pgcDst, pgcSrc;
  126. {
  127. RegionPtr prgnNew;
  128. switch (pgcSrc->clientClipType)
  129. {
  130. case CT_PIXMAP:
  131. ((PixmapPtr) pgcSrc->clientClip)->refcnt++;
  132. /* Fall through !! */
  133. case CT_NONE:
  134. (*pgcDst->funcs->ChangeClip) (pgcDst, (int) pgcSrc->clientClipType,
  135. pgcSrc->clientClip, 0);
  136. break;
  137. case CT_REGION:
  138. prgnNew = REGION_CREATE(NULL, 1);
  139. REGION_COPY(prgnNew,
  140. (RegionPtr) (pgcSrc->clientClip));
  141. (*pgcDst->funcs->ChangeClip) (pgcDst, CT_REGION, (pointer) prgnNew, 0);
  142. break;
  143. }
  144. }
  145. /* ARGSUSED */
  146. _X_EXPORT void
  147. miCopyGC(pGCSrc, changes, pGCDst)
  148. GCPtr pGCSrc;
  149. unsigned long changes;
  150. GCPtr pGCDst;
  151. {
  152. return;
  153. }
  154. _X_EXPORT void
  155. miComputeCompositeClip(pGC, pDrawable)
  156. GCPtr pGC;
  157. DrawablePtr pDrawable;
  158. {
  159. ScreenPtr pScreen;
  160. /* This prevents warnings about pScreen not being used. */
  161. pGC->pScreen = pScreen = pGC->pScreen;
  162. if (pDrawable->type == DRAWABLE_WINDOW)
  163. {
  164. WindowPtr pWin = (WindowPtr) pDrawable;
  165. RegionPtr pregWin;
  166. Bool freeTmpClip, freeCompClip;
  167. if (pGC->subWindowMode == IncludeInferiors)
  168. {
  169. pregWin = NotClippedByChildren(pWin);
  170. freeTmpClip = TRUE;
  171. }
  172. else
  173. {
  174. pregWin = &pWin->clipList;
  175. freeTmpClip = FALSE;
  176. }
  177. freeCompClip = pGC->freeCompClip;
  178. /*
  179. * if there is no client clip, we can get by with just keeping the
  180. * pointer we got, and remembering whether or not should destroy (or
  181. * maybe re-use) it later. this way, we avoid unnecessary copying of
  182. * regions. (this wins especially if many clients clip by children
  183. * and have no client clip.)
  184. */
  185. if (pGC->clientClipType == CT_NONE)
  186. {
  187. if (freeCompClip)
  188. REGION_DESTROY(pGC->pCompositeClip);
  189. pGC->pCompositeClip = pregWin;
  190. pGC->freeCompClip = freeTmpClip;
  191. }
  192. else
  193. {
  194. /*
  195. * we need one 'real' region to put into the composite clip. if
  196. * pregWin the current composite clip are real, we can get rid of
  197. * one. if pregWin is real and the current composite clip isn't,
  198. * use pregWin for the composite clip. if the current composite
  199. * clip is real and pregWin isn't, use the current composite
  200. * clip. if neither is real, create a new region.
  201. */
  202. REGION_TRANSLATE(pGC->clientClip,
  203. pDrawable->x + pGC->clipOrg.x,
  204. pDrawable->y + pGC->clipOrg.y);
  205. if (freeCompClip)
  206. {
  207. REGION_INTERSECT(pGC->pCompositeClip,
  208. pregWin, pGC->clientClip);
  209. if (freeTmpClip)
  210. REGION_DESTROY(pregWin);
  211. }
  212. else if (freeTmpClip)
  213. {
  214. REGION_INTERSECT(pregWin, pregWin, pGC->clientClip);
  215. pGC->pCompositeClip = pregWin;
  216. }
  217. else
  218. {
  219. pGC->pCompositeClip = REGION_CREATE(NullBox, 0);
  220. REGION_INTERSECT(pGC->pCompositeClip,
  221. pregWin, pGC->clientClip);
  222. }
  223. pGC->freeCompClip = TRUE;
  224. REGION_TRANSLATE(pGC->clientClip,
  225. -(pDrawable->x + pGC->clipOrg.x),
  226. -(pDrawable->y + pGC->clipOrg.y));
  227. }
  228. } /* end of composite clip for a window */
  229. else
  230. {
  231. BoxRec pixbounds;
  232. /* XXX should we translate by drawable.x/y here ? */
  233. /* If you want pixmaps in offscreen memory, yes */
  234. pixbounds.x1 = pDrawable->x;
  235. pixbounds.y1 = pDrawable->y;
  236. pixbounds.x2 = pDrawable->x + pDrawable->width;
  237. pixbounds.y2 = pDrawable->y + pDrawable->height;
  238. if (pGC->freeCompClip)
  239. {
  240. REGION_RESET(pGC->pCompositeClip, &pixbounds);
  241. }
  242. else
  243. {
  244. pGC->freeCompClip = TRUE;
  245. pGC->pCompositeClip = REGION_CREATE(&pixbounds, 1);
  246. }
  247. if (pGC->clientClipType == CT_REGION)
  248. {
  249. if(pDrawable->x || pDrawable->y) {
  250. REGION_TRANSLATE(pGC->clientClip,
  251. pDrawable->x + pGC->clipOrg.x,
  252. pDrawable->y + pGC->clipOrg.y);
  253. REGION_INTERSECT(pGC->pCompositeClip,
  254. pGC->pCompositeClip, pGC->clientClip);
  255. REGION_TRANSLATE(pGC->clientClip,
  256. -(pDrawable->x + pGC->clipOrg.x),
  257. -(pDrawable->y + pGC->clipOrg.y));
  258. } else {
  259. REGION_TRANSLATE(pGC->pCompositeClip,
  260. -pGC->clipOrg.x, -pGC->clipOrg.y);
  261. REGION_INTERSECT(pGC->pCompositeClip,
  262. pGC->pCompositeClip, pGC->clientClip);
  263. REGION_TRANSLATE(pGC->pCompositeClip,
  264. pGC->clipOrg.x, pGC->clipOrg.y);
  265. }
  266. }
  267. } /* end of composite clip for pixmap */
  268. } /* end miComputeCompositeClip */