fbwindow.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. *
  3. * Copyright © 1998 Keith Packard
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and its
  6. * documentation for any purpose is hereby granted without fee, provided that
  7. * the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the name of Keith Packard not be used in
  10. * advertising or publicity pertaining to distribution of the software without
  11. * specific, written prior permission. Keith Packard makes no
  12. * representations about the suitability of this software for any purpose. It
  13. * is provided "as is" without express or implied warranty.
  14. *
  15. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  16. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  17. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  18. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  20. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  21. * PERFORMANCE OF THIS SOFTWARE.
  22. */
  23. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include <stdlib.h>
  27. #include "fb.h"
  28. Bool
  29. fbCreateWindow(WindowPtr pWin)
  30. {
  31. pWin->devPrivates[fbWinPrivateIndex].ptr =
  32. (pointer) fbGetScreenPixmap(pWin->drawable.pScreen);
  33. if (pWin->drawable.bitsPerPixel == 32)
  34. pWin->drawable.bitsPerPixel =
  35. fbGetScreenPrivate(pWin->drawable.pScreen)->win32bpp;
  36. return TRUE;
  37. }
  38. Bool
  39. fbDestroyWindow(WindowPtr pWin)
  40. {
  41. return TRUE;
  42. }
  43. Bool
  44. fbMapWindow(WindowPtr pWindow)
  45. {
  46. return TRUE;
  47. }
  48. Bool
  49. fbPositionWindow(WindowPtr pWin, int x, int y)
  50. {
  51. return TRUE;
  52. }
  53. Bool
  54. fbUnmapWindow(WindowPtr pWindow)
  55. {
  56. return TRUE;
  57. }
  58. void
  59. fbCopyWindowProc(DrawablePtr pSrcDrawable,
  60. DrawablePtr pDstDrawable,
  61. GCPtr pGC,
  62. BoxPtr pbox,
  63. int nbox,
  64. int dx,
  65. int dy,
  66. Bool reverse, Bool upsidedown, Pixel bitplane, void *closure)
  67. {
  68. FbBits *src;
  69. FbStride srcStride;
  70. int srcBpp;
  71. int srcXoff, srcYoff;
  72. FbBits *dst;
  73. FbStride dstStride;
  74. int dstBpp;
  75. int dstXoff, dstYoff;
  76. fbGetDrawable(pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
  77. fbGetDrawable(pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  78. while (nbox--) {
  79. fbBlt(src + (pbox->y1 + dy + srcYoff) * srcStride,
  80. srcStride,
  81. (pbox->x1 + dx + srcXoff) * srcBpp,
  82. dst + (pbox->y1 + dstYoff) * dstStride,
  83. dstStride,
  84. (pbox->x1 + dstXoff) * dstBpp,
  85. (pbox->x2 - pbox->x1) * dstBpp,
  86. (pbox->y2 - pbox->y1),
  87. GXcopy, FB_ALLONES, dstBpp, reverse, upsidedown);
  88. pbox++;
  89. }
  90. }
  91. void
  92. fbCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
  93. {
  94. RegionRec rgnDst;
  95. int dx, dy;
  96. PixmapPtr pPixmap = fbGetWindowPixmap(pWin);
  97. DrawablePtr pDrawable = &pPixmap->drawable;
  98. dx = ptOldOrg.x - pWin->drawable.x;
  99. dy = ptOldOrg.y - pWin->drawable.y;
  100. REGION_TRANSLATE(prgnSrc, -dx, -dy);
  101. REGION_NULL(&rgnDst);
  102. REGION_INTERSECT(&rgnDst, &pWin->borderClip,
  103. prgnSrc);
  104. fbCopyRegion(pDrawable, pDrawable,
  105. 0, &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
  106. REGION_UNINIT(&rgnDst);
  107. fbValidateDrawable(&pWin->drawable);
  108. }
  109. Bool
  110. fbChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
  111. {
  112. PixmapPtr pPixmap;
  113. if (mask & CWBackPixmap) {
  114. if (pWin->backgroundState == BackgroundPixmap) {
  115. pPixmap = pWin->background.pixmap;
  116. if (pPixmap->drawable.bitsPerPixel != pWin->drawable.bitsPerPixel) {
  117. pPixmap = fb24_32ReformatTile(pPixmap,
  118. pWin->drawable.bitsPerPixel);
  119. if (pPixmap) {
  120. (*pWin->drawable.pScreen->DestroyPixmap) (pWin->background.
  121. pixmap);
  122. pWin->background.pixmap = pPixmap;
  123. }
  124. }
  125. if (FbEvenTile(pPixmap->drawable.width *
  126. pPixmap->drawable.bitsPerPixel))
  127. fbPadPixmap(pPixmap);
  128. }
  129. }
  130. if (mask & CWBorderPixmap) {
  131. if (pWin->borderIsPixel == FALSE) {
  132. pPixmap = pWin->border.pixmap;
  133. if (pPixmap->drawable.bitsPerPixel != pWin->drawable.bitsPerPixel) {
  134. pPixmap = fb24_32ReformatTile(pPixmap,
  135. pWin->drawable.bitsPerPixel);
  136. if (pPixmap) {
  137. (*pWin->drawable.pScreen->DestroyPixmap) (pWin->border.
  138. pixmap);
  139. pWin->border.pixmap = pPixmap;
  140. }
  141. }
  142. if (FbEvenTile(pPixmap->drawable.width *
  143. pPixmap->drawable.bitsPerPixel))
  144. fbPadPixmap(pPixmap);
  145. }
  146. }
  147. return TRUE;
  148. }
  149. void
  150. fbFillRegionSolid(DrawablePtr pDrawable,
  151. RegionPtr pRegion, FbBits and, FbBits xor)
  152. {
  153. FbBits *dst;
  154. FbStride dstStride;
  155. int dstBpp;
  156. int dstXoff, dstYoff;
  157. int n = REGION_NUM_RECTS(pRegion);
  158. BoxPtr pbox = REGION_RECTS(pRegion);
  159. fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  160. while (n--) {
  161. fbSolid(dst + (pbox->y1 + dstYoff) * dstStride,
  162. dstStride,
  163. (pbox->x1 + dstXoff) * dstBpp,
  164. dstBpp,
  165. (pbox->x2 - pbox->x1) * dstBpp,
  166. pbox->y2 - pbox->y1, and, xor);
  167. fbValidateDrawable(pDrawable);
  168. pbox++;
  169. }
  170. }
  171. void
  172. fbFillRegionTiled(DrawablePtr pDrawable, RegionPtr pRegion, PixmapPtr pTile)
  173. {
  174. FbBits *dst;
  175. FbStride dstStride;
  176. int dstBpp;
  177. int dstXoff, dstYoff;
  178. FbBits *tile;
  179. FbStride tileStride;
  180. int tileBpp;
  181. int tileXoff _X_UNUSED, tileYoff _X_UNUSED; /* XXX assumed to be zero */
  182. int tileWidth, tileHeight;
  183. int n = REGION_NUM_RECTS(pRegion);
  184. BoxPtr pbox = REGION_RECTS(pRegion);
  185. int xRot = pDrawable->x;
  186. int yRot = pDrawable->y;
  187. fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  188. fbGetDrawable(&pTile->drawable, tile, tileStride, tileBpp, tileXoff,
  189. tileYoff);
  190. tileWidth = pTile->drawable.width;
  191. tileHeight = pTile->drawable.height;
  192. xRot += dstXoff;
  193. yRot += dstYoff;
  194. while (n--) {
  195. fbTile(dst + (pbox->y1 + dstYoff) * dstStride,
  196. dstStride,
  197. (pbox->x1 + dstXoff) * dstBpp,
  198. (pbox->x2 - pbox->x1) * dstBpp,
  199. pbox->y2 - pbox->y1,
  200. tile,
  201. tileStride,
  202. tileWidth * dstBpp,
  203. tileHeight,
  204. GXcopy,
  205. FB_ALLONES, dstBpp, xRot * dstBpp, yRot - (pbox->y1 + dstYoff));
  206. pbox++;
  207. }
  208. }
  209. void
  210. fbPaintWindow(WindowPtr pWin, RegionPtr pRegion, int what)
  211. {
  212. WindowPtr pBgWin;
  213. switch (what) {
  214. case PW_BACKGROUND:
  215. switch (pWin->backgroundState) {
  216. case None:
  217. break;
  218. case ParentRelative:
  219. do {
  220. pWin = pWin->parent;
  221. } while (pWin->backgroundState == ParentRelative);
  222. (*pWin->drawable.pScreen->PaintWindowBackground) (pWin, pRegion,
  223. what);
  224. break;
  225. case BackgroundPixmap:
  226. fbFillRegionTiled(&pWin->drawable,
  227. pRegion, pWin->background.pixmap);
  228. break;
  229. case BackgroundPixel:
  230. fbFillRegionSolid(&pWin->drawable,
  231. pRegion,
  232. 0,
  233. fbReplicatePixel(pWin->background.pixel,
  234. pWin->drawable.bitsPerPixel));
  235. break;
  236. }
  237. break;
  238. case PW_BORDER:
  239. if (pWin->borderIsPixel) {
  240. fbFillRegionSolid(&pWin->drawable,
  241. pRegion,
  242. 0,
  243. fbReplicatePixel(pWin->border.pixel,
  244. pWin->drawable.bitsPerPixel));
  245. }
  246. else {
  247. for (pBgWin = pWin;
  248. pBgWin->backgroundState == ParentRelative;
  249. pBgWin = pBgWin->parent);
  250. fbFillRegionTiled(&pBgWin->drawable, pRegion, pWin->border.pixmap);
  251. }
  252. break;
  253. }
  254. fbValidateDrawable(&pWin->drawable);
  255. }