fbimage.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 <string.h>
  27. #include "fb.h"
  28. void
  29. fbPutImage(DrawablePtr pDrawable,
  30. GCPtr pGC,
  31. int depth,
  32. int x, int y, int w, int h, int leftPad, int format, char *pImage)
  33. {
  34. FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
  35. unsigned long i;
  36. FbStride srcStride;
  37. FbStip *src = (FbStip *) pImage;
  38. x += pDrawable->x;
  39. y += pDrawable->y;
  40. switch (format) {
  41. case XYBitmap:
  42. srcStride = BitmapBytePad(w + leftPad) / sizeof(FbStip);
  43. fbPutXYImage(pDrawable,
  44. fbGetCompositeClip(pGC),
  45. pPriv->fg,
  46. pPriv->bg,
  47. pPriv->pm,
  48. pGC->alu, TRUE, x, y, w, h, src, srcStride, leftPad);
  49. break;
  50. case XYPixmap:
  51. srcStride = BitmapBytePad(w + leftPad) / sizeof(FbStip);
  52. for (i = (unsigned long) 1 << (pDrawable->depth - 1); i; i >>= 1) {
  53. if (i & pGC->planemask) {
  54. fbPutXYImage(pDrawable,
  55. fbGetCompositeClip(pGC),
  56. FB_ALLONES,
  57. 0,
  58. fbReplicatePixel(i, pDrawable->bitsPerPixel),
  59. pGC->alu,
  60. TRUE, x, y, w, h, src, srcStride, leftPad);
  61. src += srcStride * h;
  62. }
  63. }
  64. break;
  65. case ZPixmap:
  66. if (pDrawable->bitsPerPixel != BitsPerPixel(pDrawable->depth)) {
  67. srcStride = PixmapBytePad(w, pDrawable->depth);
  68. fb24_32PutZImage(pDrawable,
  69. fbGetCompositeClip(pGC),
  70. pGC->alu,
  71. (FbBits) pGC->planemask,
  72. x, y, w, h, (CARD8 *) pImage, srcStride);
  73. }
  74. else
  75. {
  76. srcStride = PixmapBytePad(w, pDrawable->depth) / sizeof(FbStip);
  77. fbPutZImage(pDrawable,
  78. fbGetCompositeClip(pGC),
  79. pGC->alu, pPriv->pm, x, y, w, h, src, srcStride);
  80. }
  81. }
  82. }
  83. void
  84. fbPutZImage(DrawablePtr pDrawable,
  85. RegionPtr pClip,
  86. int alu,
  87. FbBits pm,
  88. int x,
  89. int y, int width, int height, FbStip * src, FbStride srcStride)
  90. {
  91. FbStip *dst;
  92. FbStride dstStride;
  93. int dstBpp;
  94. int dstXoff, dstYoff;
  95. int nbox;
  96. BoxPtr pbox;
  97. int x1, y1, x2, y2;
  98. fbGetStipDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  99. for (nbox = REGION_NUM_RECTS(pClip),
  100. pbox = REGION_RECTS(pClip); nbox--; pbox++) {
  101. x1 = x;
  102. y1 = y;
  103. x2 = x + width;
  104. y2 = y + height;
  105. if (x1 < pbox->x1)
  106. x1 = pbox->x1;
  107. if (y1 < pbox->y1)
  108. y1 = pbox->y1;
  109. if (x2 > pbox->x2)
  110. x2 = pbox->x2;
  111. if (y2 > pbox->y2)
  112. y2 = pbox->y2;
  113. if (x1 >= x2 || y1 >= y2)
  114. continue;
  115. fbBltStip(src + (y1 - y) * srcStride,
  116. srcStride,
  117. (x1 - x) * dstBpp,
  118. dst + (y1 + dstYoff) * dstStride,
  119. dstStride,
  120. (x1 + dstXoff) * dstBpp,
  121. (x2 - x1) * dstBpp, (y2 - y1), alu, pm, dstBpp);
  122. }
  123. }
  124. void
  125. fbPutXYImage(DrawablePtr pDrawable,
  126. RegionPtr pClip,
  127. FbBits fg,
  128. FbBits bg,
  129. FbBits pm,
  130. int alu,
  131. Bool opaque,
  132. int x,
  133. int y,
  134. int width, int height, FbStip * src, FbStride srcStride, int srcX)
  135. {
  136. FbBits *dst;
  137. FbStride dstStride;
  138. int dstBpp;
  139. int dstXoff, dstYoff;
  140. int nbox;
  141. BoxPtr pbox;
  142. int x1, y1, x2, y2;
  143. FbBits fgand = 0, fgxor = 0, bgand = 0, bgxor = 0;
  144. fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
  145. if (dstBpp == 1) {
  146. if (opaque)
  147. alu = FbOpaqueStipple1Rop(alu, fg, bg);
  148. else
  149. alu = FbStipple1Rop(alu, fg);
  150. }
  151. else {
  152. fgand = fbAnd(alu, fg, pm);
  153. fgxor = fbXor(alu, fg, pm);
  154. if (opaque) {
  155. bgand = fbAnd(alu, bg, pm);
  156. bgxor = fbXor(alu, bg, pm);
  157. }
  158. else {
  159. bgand = fbAnd(GXnoop, (FbBits) 0, FB_ALLONES);
  160. bgxor = fbXor(GXnoop, (FbBits) 0, FB_ALLONES);
  161. }
  162. }
  163. for (nbox = REGION_NUM_RECTS(pClip),
  164. pbox = REGION_RECTS(pClip); nbox--; pbox++) {
  165. x1 = x;
  166. y1 = y;
  167. x2 = x + width;
  168. y2 = y + height;
  169. if (x1 < pbox->x1)
  170. x1 = pbox->x1;
  171. if (y1 < pbox->y1)
  172. y1 = pbox->y1;
  173. if (x2 > pbox->x2)
  174. x2 = pbox->x2;
  175. if (y2 > pbox->y2)
  176. y2 = pbox->y2;
  177. if (x1 >= x2 || y1 >= y2)
  178. continue;
  179. if (dstBpp == 1) {
  180. fbBltStip(src + (y1 - y) * srcStride,
  181. srcStride,
  182. (x1 - x) + srcX,
  183. (FbStip *) (dst + (y1 + dstYoff) * dstStride),
  184. FbBitsStrideToStipStride(dstStride),
  185. (x1 + dstXoff) * dstBpp,
  186. (x2 - x1) * dstBpp, (y2 - y1), alu, pm, dstBpp);
  187. }
  188. else {
  189. fbBltOne(src + (y1 - y) * srcStride,
  190. srcStride,
  191. (x1 - x) + srcX,
  192. dst + (y1 + dstYoff) * dstStride,
  193. dstStride,
  194. (x1 + dstXoff) * dstBpp,
  195. dstBpp,
  196. (x2 - x1) * dstBpp, (y2 - y1), fgand, fgxor, bgand, bgxor);
  197. }
  198. }
  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. }