fbimage.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Copyright © 1998 Keith Packard
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that
  7. * copyright notice and this permission notice appear in supporting
  8. * documentation, and that the name of Keith Packard not be used in
  9. * advertising or publicity pertaining to distribution of the software without
  10. * specific, written prior permission. Keith Packard makes no
  11. * representations about the suitability of this software for any purpose. It
  12. * is provided "as is" without express or implied warranty.
  13. *
  14. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20. * PERFORMANCE OF THIS SOFTWARE.
  21. */
  22. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include <string.h>
  26. #include "fb.h"
  27. void
  28. fbPutImage(DrawablePtr pDrawable,
  29. GCPtr pGC,
  30. int depth,
  31. int x, int y, int w, int h, int leftPad, int format, char *pImage)
  32. {
  33. FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
  34. unsigned long i;
  35. FbStride srcStride;
  36. FbStip *src = (FbStip *) pImage;
  37. x += pDrawable->x;
  38. y += pDrawable->y;
  39. switch (format) {
  40. case XYBitmap:
  41. srcStride = BitmapBytePad(w + leftPad) / sizeof(FbStip);
  42. fbPutXYImage(pDrawable,
  43. fbGetCompositeClip(pGC),
  44. pPriv->fg,
  45. pPriv->bg,
  46. pPriv->pm,
  47. pGC->alu, TRUE, x, y, w, h, src, srcStride, leftPad);
  48. break;
  49. case XYPixmap:
  50. srcStride = BitmapBytePad(w + leftPad) / sizeof(FbStip);
  51. for (i = (unsigned long) 1 << (pDrawable->depth - 1); i; i >>= 1) {
  52. if (i & pGC->planemask) {
  53. fbPutXYImage(pDrawable,
  54. fbGetCompositeClip(pGC),
  55. FB_ALLONES,
  56. 0,
  57. fbReplicatePixel(i, pDrawable->bitsPerPixel),
  58. pGC->alu,
  59. TRUE, x, y, w, h, src, srcStride, leftPad);
  60. src += srcStride * h;
  61. }
  62. }
  63. break;
  64. case ZPixmap:
  65. if (pDrawable->bitsPerPixel != BitsPerPixel(pDrawable->depth)) {
  66. srcStride = PixmapBytePad(w, pDrawable->depth);
  67. fb24_32PutZImage(pDrawable,
  68. fbGetCompositeClip(pGC),
  69. pGC->alu,
  70. (FbBits) pGC->planemask,
  71. x, y, w, h, (CARD8 *) pImage, srcStride);
  72. }
  73. else {
  74. srcStride = PixmapBytePad(w, pDrawable->depth) / sizeof(FbStip);
  75. fbPutZImage(pDrawable,
  76. fbGetCompositeClip(pGC),
  77. pGC->alu, pPriv->pm, x, y, w, h, src, srcStride);
  78. }
  79. }
  80. }
  81. void
  82. fbPutZImage(DrawablePtr pDrawable,
  83. RegionPtr pClip,
  84. int alu,
  85. FbBits pm,
  86. int x,
  87. int y, int width, int height, FbStip * src, FbStride srcStride)
  88. {
  89. FbStip *dst;
  90. FbStride dstStride;
  91. int dstBpp;
  92. int dstXoff, dstYoff;
  93. int nbox;
  94. BoxPtr pbox;
  95. int x1, y1, x2, y2;
  96. fbGetStipDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  97. for (nbox = RegionNumRects(pClip),
  98. pbox = RegionRects(pClip); nbox--; pbox++) {
  99. x1 = x;
  100. y1 = y;
  101. x2 = x + width;
  102. y2 = y + height;
  103. if (x1 < pbox->x1)
  104. x1 = pbox->x1;
  105. if (y1 < pbox->y1)
  106. y1 = pbox->y1;
  107. if (x2 > pbox->x2)
  108. x2 = pbox->x2;
  109. if (y2 > pbox->y2)
  110. y2 = pbox->y2;
  111. if (x1 >= x2 || y1 >= y2)
  112. continue;
  113. fbBltStip(src + (y1 - y) * srcStride,
  114. srcStride,
  115. (x1 - x) * dstBpp,
  116. dst + (y1 + dstYoff) * dstStride,
  117. dstStride,
  118. (x1 + dstXoff) * dstBpp,
  119. (x2 - x1) * dstBpp, (y2 - y1), alu, pm, dstBpp);
  120. }
  121. fbFinishAccess(pDrawable);
  122. }
  123. void
  124. fbPutXYImage(DrawablePtr pDrawable,
  125. RegionPtr pClip,
  126. FbBits fg,
  127. FbBits bg,
  128. FbBits pm,
  129. int alu,
  130. Bool opaque,
  131. int x,
  132. int y,
  133. int width, int height, FbStip * src, FbStride srcStride, int srcX)
  134. {
  135. FbBits *dst;
  136. FbStride dstStride;
  137. int dstBpp;
  138. int dstXoff, dstYoff;
  139. int nbox;
  140. BoxPtr pbox;
  141. int x1, y1, x2, y2;
  142. FbBits fgand = 0, fgxor = 0, bgand = 0, bgxor = 0;
  143. fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  144. if (dstBpp == 1) {
  145. if (opaque)
  146. alu = FbOpaqueStipple1Rop(alu, fg, bg);
  147. else
  148. alu = FbStipple1Rop(alu, fg);
  149. }
  150. else {
  151. fgand = fbAnd(alu, fg, pm);
  152. fgxor = fbXor(alu, fg, pm);
  153. if (opaque) {
  154. bgand = fbAnd(alu, bg, pm);
  155. bgxor = fbXor(alu, bg, pm);
  156. }
  157. else {
  158. bgand = fbAnd(GXnoop, (FbBits) 0, FB_ALLONES);
  159. bgxor = fbXor(GXnoop, (FbBits) 0, FB_ALLONES);
  160. }
  161. }
  162. for (nbox = RegionNumRects(pClip),
  163. pbox = RegionRects(pClip); nbox--; pbox++) {
  164. x1 = x;
  165. y1 = y;
  166. x2 = x + width;
  167. y2 = y + height;
  168. if (x1 < pbox->x1)
  169. x1 = pbox->x1;
  170. if (y1 < pbox->y1)
  171. y1 = pbox->y1;
  172. if (x2 > pbox->x2)
  173. x2 = pbox->x2;
  174. if (y2 > pbox->y2)
  175. y2 = pbox->y2;
  176. if (x1 >= x2 || y1 >= y2)
  177. continue;
  178. if (dstBpp == 1) {
  179. fbBltStip(src + (y1 - y) * srcStride,
  180. srcStride,
  181. (x1 - x) + srcX,
  182. (FbStip *) (dst + (y1 + dstYoff) * dstStride),
  183. FbBitsStrideToStipStride(dstStride),
  184. (x1 + dstXoff) * dstBpp,
  185. (x2 - x1) * dstBpp, (y2 - y1), alu, pm, dstBpp);
  186. }
  187. else {
  188. fbBltOne(src + (y1 - y) * srcStride,
  189. srcStride,
  190. (x1 - x) + srcX,
  191. dst + (y1 + dstYoff) * dstStride,
  192. dstStride,
  193. (x1 + dstXoff) * dstBpp,
  194. dstBpp,
  195. (x2 - x1) * dstBpp, (y2 - y1), fgand, fgxor, bgand, bgxor);
  196. }
  197. }
  198. fbFinishAccess(pDrawable);
  199. }
  200. void
  201. fbGetImage(DrawablePtr pDrawable,
  202. int x,
  203. int y,
  204. int w, int h, unsigned int format, unsigned long planeMask, char *d)
  205. {
  206. FbBits *src;
  207. FbStride srcStride;
  208. int srcBpp;
  209. int srcXoff, srcYoff;
  210. FbStip *dst;
  211. FbStride dstStride;
  212. /*
  213. * XFree86 DDX empties the root borderClip when the VT is
  214. * switched away; this checks for that case
  215. */
  216. if (!fbDrawableEnabled(pDrawable))
  217. return;
  218. if (format == ZPixmap &&
  219. pDrawable->bitsPerPixel != BitsPerPixel(pDrawable->depth)) {
  220. fb24_32GetImage(pDrawable, x, y, w, h, format, planeMask, d);
  221. return;
  222. }
  223. fbGetDrawable(pDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
  224. x += pDrawable->x;
  225. y += pDrawable->y;
  226. dst = (FbStip *) d;
  227. if (format == ZPixmap || srcBpp == 1) {
  228. FbBits pm;
  229. pm = fbReplicatePixel(planeMask, srcBpp);
  230. dstStride = PixmapBytePad(w, pDrawable->depth);
  231. if (pm != FB_ALLONES)
  232. memset(d, 0, dstStride * h);
  233. dstStride /= sizeof(FbStip);
  234. fbBltStip((FbStip *) (src + (y + srcYoff) * srcStride),
  235. FbBitsStrideToStipStride(srcStride),
  236. (x + srcXoff) * srcBpp,
  237. dst, dstStride, 0, w * srcBpp, h, GXcopy, pm, srcBpp);
  238. }
  239. else {
  240. dstStride = BitmapBytePad(w) / sizeof(FbStip);
  241. fbBltPlane(src + (y + srcYoff) * srcStride,
  242. srcStride,
  243. (x + srcXoff) * srcBpp,
  244. srcBpp,
  245. dst,
  246. dstStride,
  247. 0,
  248. w * srcBpp, h,
  249. fbAndStip(GXcopy, FB_STIP_ALLONES, FB_STIP_ALLONES),
  250. fbXorStip(GXcopy, FB_STIP_ALLONES, FB_STIP_ALLONES),
  251. fbAndStip(GXcopy, 0, FB_STIP_ALLONES),
  252. fbXorStip(GXcopy, 0, FB_STIP_ALLONES), planeMask);
  253. }
  254. fbFinishAccess(pDrawable);
  255. }