PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/nx-3.5.0/nx-X11/programs/Xserver/afb/afbwindow.c

#
C | 318 lines | 199 code | 32 blank | 87 comment | 32 complexity | bcc532d61493cf74d9a3792883e89a66 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. /* $XFree86: xc/programs/Xserver/afb/afbwindow.c,v 3.0 1996/08/18 01:45:58 dawes Exp $ */
  2. /* $XConsortium: afbwindow.c,v 5.14 94/04/17 20:28:36 dpw Exp $ */
  3. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  4. /***********************************************************
  5. Copyright (c) 1987 X Consortium
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  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. X CONSORTIUM 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 X Consortium 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 X Consortium.
  23. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  24. All Rights Reserved
  25. Permission to use, copy, modify, and distribute this software and its
  26. documentation for any purpose and without fee is hereby granted,
  27. provided that the above copyright notice appear in all copies and that
  28. both that copyright notice and this permission notice appear in
  29. supporting documentation, and that the name of Digital not be
  30. used in advertising or publicity pertaining to distribution of the
  31. software without specific, written prior permission.
  32. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  33. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  34. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  35. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  36. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  37. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  38. SOFTWARE.
  39. ******************************************************************/
  40. #ifdef HAVE_DIX_CONFIG_H
  41. #include <dix-config.h>
  42. #endif
  43. #include <X11/X.h>
  44. #include "scrnintstr.h"
  45. #include "windowstr.h"
  46. #include "afb.h"
  47. #include "mistruct.h"
  48. #include "regionstr.h"
  49. #include "maskbits.h"
  50. Bool
  51. afbCreateWindow(pWin)
  52. register WindowPtr pWin;
  53. {
  54. register afbPrivWin *pPrivWin;
  55. pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
  56. pPrivWin->pRotatedBorder = NullPixmap;
  57. pPrivWin->pRotatedBackground = NullPixmap;
  58. pPrivWin->fastBackground = FALSE;
  59. pPrivWin->fastBorder = FALSE;
  60. #ifdef PIXMAP_PER_WINDOW
  61. pWin->devPrivates[frameWindowPrivateIndex].ptr =
  62. pWin->pDrawable.pScreen->devPrivates[afbScreenPrivateIndex].ptr;
  63. #endif
  64. return (TRUE);
  65. }
  66. /* This always returns true, because Xfree can't fail. It might be possible
  67. * on some devices for Destroy to fail */
  68. Bool
  69. afbDestroyWindow(pWin)
  70. WindowPtr pWin;
  71. {
  72. register afbPrivWin *pPrivWin;
  73. pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
  74. if (pPrivWin->pRotatedBorder)
  75. (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBorder);
  76. if (pPrivWin->pRotatedBackground)
  77. (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBackground);
  78. return (TRUE);
  79. }
  80. /*ARGSUSED*/
  81. Bool
  82. afbMapWindow(pWindow)
  83. WindowPtr pWindow;
  84. {
  85. return (TRUE);
  86. }
  87. /* (x, y) is the upper left corner of the window on the screen
  88. do we really need to pass this? (is it a;ready in pWin->absCorner?)
  89. we only do the rotation for pixmaps that are 32 bits wide (padded
  90. or otherwise.)
  91. afbChangeWindowAttributes() has already put a copy of the pixmap
  92. in pPrivWin->pRotated*
  93. */
  94. /*ARGSUSED*/
  95. Bool
  96. afbPositionWindow(pWin, x, y)
  97. WindowPtr pWin;
  98. int x, y;
  99. {
  100. register afbPrivWin *pPrivWin;
  101. int reset = 0;
  102. pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
  103. if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground) {
  104. afbXRotatePixmap(pPrivWin->pRotatedBackground,
  105. pWin->drawable.x - pPrivWin->oldRotate.x);
  106. afbYRotatePixmap(pPrivWin->pRotatedBackground,
  107. pWin->drawable.y - pPrivWin->oldRotate.y);
  108. reset = 1;
  109. }
  110. if (!pWin->borderIsPixel && pPrivWin->fastBorder) {
  111. while (pWin->backgroundState == ParentRelative)
  112. pWin = pWin->parent;
  113. afbXRotatePixmap(pPrivWin->pRotatedBorder,
  114. pWin->drawable.x - pPrivWin->oldRotate.x);
  115. afbYRotatePixmap(pPrivWin->pRotatedBorder,
  116. pWin->drawable.y - pPrivWin->oldRotate.y);
  117. reset = 1;
  118. }
  119. if (reset) {
  120. pPrivWin->oldRotate.x = pWin->drawable.x;
  121. pPrivWin->oldRotate.y = pWin->drawable.y;
  122. }
  123. /* This is the "wrong" fix to the right problem, but it doesn't really
  124. * cost very much. When the window is moved, we need to invalidate any
  125. * RotatedPixmap that exists in any GC currently validated against this
  126. * window.
  127. */
  128. pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  129. /* Again, we have no failure modes indicated by any of the routines
  130. * we've called, so we have to assume it worked */
  131. return (TRUE);
  132. }
  133. /*ARGSUSED*/
  134. Bool
  135. afbUnmapWindow(pWindow)
  136. WindowPtr pWindow;
  137. {
  138. return (TRUE);
  139. }
  140. /* UNCLEAN!
  141. this code calls the bitblt helper code directly.
  142. afbCopyWindow copies only the parts of the destination that are
  143. visible in the source.
  144. */
  145. void
  146. afbCopyWindow(pWin, ptOldOrg, prgnSrc)
  147. WindowPtr pWin;
  148. DDXPointRec ptOldOrg;
  149. RegionPtr prgnSrc;
  150. {
  151. DDXPointPtr pptSrc;
  152. register DDXPointPtr ppt;
  153. RegionPtr prgnDst;
  154. register BoxPtr pbox;
  155. register int dx, dy;
  156. register int i, nbox;
  157. WindowPtr pwinRoot;
  158. pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
  159. prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
  160. dx = ptOldOrg.x - pWin->drawable.x;
  161. dy = ptOldOrg.y - pWin->drawable.y;
  162. REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
  163. REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip,
  164. prgnSrc);
  165. pbox = REGION_RECTS(prgnDst);
  166. nbox = REGION_NUM_RECTS(prgnDst);
  167. if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
  168. return;
  169. ppt = pptSrc;
  170. for (i=nbox; --i >= 0; ppt++, pbox++) {
  171. ppt->x = pbox->x1 + dx;
  172. ppt->y = pbox->y1 + dy;
  173. }
  174. afbDoBitblt((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot, GXcopy, prgnDst,
  175. pptSrc, ~0);
  176. DEALLOCATE_LOCAL(pptSrc);
  177. REGION_DESTROY(pWin->drawable.pScreen, prgnDst);
  178. }
  179. /* swap in correct PaintWindow* routine. If we can use a fast output
  180. routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
  181. of it in devPrivate.
  182. */
  183. Bool
  184. afbChangeWindowAttributes(pWin, mask)
  185. register WindowPtr pWin;
  186. register unsigned long mask;
  187. {
  188. register unsigned long index;
  189. register afbPrivWin *pPrivWin;
  190. WindowPtr pBgWin;
  191. pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
  192. /*
  193. * When background state changes from ParentRelative and
  194. * we had previously rotated the fast border pixmap to match
  195. * the parent relative origin, rerotate to match window
  196. */
  197. if (mask & (CWBackPixmap | CWBackPixel) &&
  198. pWin->backgroundState != ParentRelative && pPrivWin->fastBorder &&
  199. (pPrivWin->oldRotate.x != pWin->drawable.x ||
  200. pPrivWin->oldRotate.y != pWin->drawable.y)) {
  201. afbXRotatePixmap(pPrivWin->pRotatedBorder,
  202. pWin->drawable.x - pPrivWin->oldRotate.x);
  203. afbYRotatePixmap(pPrivWin->pRotatedBorder,
  204. pWin->drawable.y - pPrivWin->oldRotate.y);
  205. pPrivWin->oldRotate.x = pWin->drawable.x;
  206. pPrivWin->oldRotate.y = pWin->drawable.y;
  207. }
  208. while(mask) {
  209. index = lowbit (mask);
  210. mask &= ~index;
  211. switch(index) {
  212. case CWBackPixmap:
  213. if (pWin->backgroundState == None)
  214. pPrivWin->fastBackground = FALSE;
  215. else if (pWin->backgroundState == ParentRelative) {
  216. pPrivWin->fastBackground = FALSE;
  217. /* Rotate border to match parent origin */
  218. if (pPrivWin->pRotatedBorder) {
  219. for (pBgWin = pWin->parent;
  220. pBgWin->backgroundState == ParentRelative;
  221. pBgWin = pBgWin->parent);
  222. afbXRotatePixmap(pPrivWin->pRotatedBorder,
  223. pBgWin->drawable.x - pPrivWin->oldRotate.x);
  224. afbYRotatePixmap(pPrivWin->pRotatedBorder,
  225. pBgWin->drawable.y - pPrivWin->oldRotate.y);
  226. pPrivWin->oldRotate.x = pBgWin->drawable.x;
  227. pPrivWin->oldRotate.y = pBgWin->drawable.y;
  228. }
  229. } else if ((pWin->background.pixmap->drawable.width <= PPW) &&
  230. !(pWin->background.pixmap->drawable.width &
  231. (pWin->background.pixmap->drawable.width - 1))) {
  232. afbCopyRotatePixmap(pWin->background.pixmap,
  233. &pPrivWin->pRotatedBackground,
  234. pWin->drawable.x, pWin->drawable.y);
  235. if (pPrivWin->pRotatedBackground) {
  236. pPrivWin->fastBackground = TRUE;
  237. pPrivWin->oldRotate.x = pWin->drawable.x;
  238. pPrivWin->oldRotate.y = pWin->drawable.y;
  239. } else
  240. pPrivWin->fastBackground = FALSE;
  241. } else
  242. pPrivWin->fastBackground = FALSE;
  243. break;
  244. case CWBackPixel:
  245. pPrivWin->fastBackground = FALSE;
  246. break;
  247. case CWBorderPixmap:
  248. if ((pWin->border.pixmap->drawable.width <= PPW) &&
  249. !(pWin->border.pixmap->drawable.width &
  250. (pWin->border.pixmap->drawable.width - 1))) {
  251. for (pBgWin = pWin;
  252. pBgWin->backgroundState == ParentRelative;
  253. pBgWin = pBgWin->parent);
  254. afbCopyRotatePixmap(pWin->border.pixmap,
  255. &pPrivWin->pRotatedBorder,
  256. pBgWin->drawable.x, pBgWin->drawable.y);
  257. if (pPrivWin->pRotatedBorder) {
  258. pPrivWin->fastBorder = TRUE;
  259. pPrivWin->oldRotate.x = pBgWin->drawable.x;
  260. pPrivWin->oldRotate.y = pBgWin->drawable.y;
  261. } else
  262. pPrivWin->fastBorder = FALSE;
  263. } else
  264. pPrivWin->fastBorder = FALSE;
  265. break;
  266. case CWBorderPixel:
  267. pPrivWin->fastBorder = FALSE;
  268. break;
  269. }
  270. }
  271. /* Again, we have no failure modes indicated by any of the routines
  272. * we've called, so we have to assume it worked */
  273. return (TRUE);
  274. }