PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/hw/xnest/GCOps.c

https://github.com/dmitriy103/androix-xserver
C | 327 lines | 262 code | 51 blank | 14 comment | 14 complexity | 0b8d2606db196ceb7604cf134e7c539f MD5 | raw file
  1. /*
  2. Copyright 1993 by Davor Matic
  3. Permission to use, copy, modify, distribute, and sell this software
  4. and its documentation for any purpose is hereby granted without fee,
  5. provided that the above copyright notice appear in all copies and that
  6. both that copyright notice and this permission notice appear in
  7. supporting documentation. Davor Matic makes no representations about
  8. the suitability of this software for any purpose. It is provided "as
  9. is" without express or implied warranty.
  10. */
  11. #ifdef HAVE_XNEST_CONFIG_H
  12. #include <xnest-config.h>
  13. #endif
  14. #include <X11/X.h>
  15. #include <X11/Xproto.h>
  16. #include "regionstr.h"
  17. #include <X11/fonts/fontstruct.h>
  18. #include "gcstruct.h"
  19. #include "scrnintstr.h"
  20. #include "windowstr.h"
  21. #include "pixmapstr.h"
  22. #include "region.h"
  23. #include "servermd.h"
  24. #include "Xnest.h"
  25. #include "Display.h"
  26. #include "Screen.h"
  27. #include "XNGC.h"
  28. #include "XNFont.h"
  29. #include "GCOps.h"
  30. #include "Drawable.h"
  31. #include "Visual.h"
  32. void
  33. xnestFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nSpans, xPoint *pPoints,
  34. int *pWidths, int fSorted)
  35. {
  36. ErrorF("xnest warning: function xnestFillSpans not implemented\n");
  37. }
  38. void
  39. xnestSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *pSrc,
  40. xPoint *pPoints, int *pWidths, int nSpans, int fSorted)
  41. {
  42. ErrorF("xnest warning: function xnestSetSpans not implemented\n");
  43. }
  44. void
  45. xnestGetSpans(DrawablePtr pDrawable, int maxWidth, DDXPointPtr pPoints,
  46. int *pWidths, int nSpans, char *pBuffer)
  47. {
  48. ErrorF("xnest warning: function xnestGetSpans not implemented\n");
  49. }
  50. void
  51. xnestQueryBestSize(int class, unsigned short *pWidth, unsigned short *pHeight,
  52. ScreenPtr pScreen)
  53. {
  54. unsigned int width, height;
  55. width = *pWidth;
  56. height = *pHeight;
  57. XQueryBestSize(xnestDisplay, class,
  58. xnestDefaultWindows[pScreen->myNum],
  59. width, height, &width, &height);
  60. *pWidth = width;
  61. *pHeight = height;
  62. }
  63. void
  64. xnestPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
  65. int w, int h, int leftPad, int format, char *pImage)
  66. {
  67. XImage *ximage;
  68. ximage = XCreateImage(xnestDisplay, xnestDefaultVisual(pDrawable->pScreen),
  69. depth, format, leftPad, (char *)pImage,
  70. w, h, BitmapPad(xnestDisplay),
  71. (format == ZPixmap) ?
  72. PixmapBytePad(w, depth) : BitmapBytePad(w+leftPad));
  73. if (ximage) {
  74. XPutImage(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  75. ximage, 0, 0, x, y, w, h);
  76. XFree(ximage);
  77. }
  78. }
  79. void
  80. xnestGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
  81. unsigned int format, unsigned long planeMask,
  82. char *pImage)
  83. {
  84. XImage *ximage;
  85. int length;
  86. ximage = XGetImage(xnestDisplay, xnestDrawable(pDrawable),
  87. x, y, w, h, planeMask, format);
  88. if (ximage) {
  89. length = ximage->bytes_per_line * ximage->height;
  90. memmove(pImage, ximage->data, length);
  91. XDestroyImage(ximage);
  92. }
  93. }
  94. static Bool
  95. xnestBitBlitPredicate(Display *display, XEvent *event, char *args)
  96. {
  97. return event->type == GraphicsExpose || event->type == NoExpose;
  98. }
  99. static RegionPtr
  100. xnestBitBlitHelper(GCPtr pGC)
  101. {
  102. if (!pGC->graphicsExposures)
  103. return NullRegion;
  104. else {
  105. XEvent event;
  106. RegionPtr pReg, pTmpReg;
  107. BoxRec Box;
  108. Bool pending, overlap;
  109. pReg = RegionCreate(NULL, 1);
  110. pTmpReg = RegionCreate(NULL, 1);
  111. if(!pReg || !pTmpReg) return NullRegion;
  112. pending = True;
  113. while (pending) {
  114. XIfEvent(xnestDisplay, &event, xnestBitBlitPredicate, NULL);
  115. switch (event.type) {
  116. case NoExpose:
  117. pending = False;
  118. break;
  119. case GraphicsExpose:
  120. Box.x1 = event.xgraphicsexpose.x;
  121. Box.y1 = event.xgraphicsexpose.y;
  122. Box.x2 = event.xgraphicsexpose.x + event.xgraphicsexpose.width;
  123. Box.y2 = event.xgraphicsexpose.y + event.xgraphicsexpose.height;
  124. RegionReset(pTmpReg, &Box);
  125. RegionAppend(pReg, pTmpReg);
  126. pending = event.xgraphicsexpose.count;
  127. break;
  128. }
  129. }
  130. RegionDestroy(pTmpReg);
  131. RegionValidate(pReg, &overlap);
  132. return pReg;
  133. }
  134. }
  135. RegionPtr
  136. xnestCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
  137. GCPtr pGC, int srcx, int srcy, int width, int height,
  138. int dstx, int dsty)
  139. {
  140. XCopyArea(xnestDisplay,
  141. xnestDrawable(pSrcDrawable), xnestDrawable(pDstDrawable),
  142. xnestGC(pGC), srcx, srcy, width, height, dstx, dsty);
  143. return xnestBitBlitHelper(pGC);
  144. }
  145. RegionPtr
  146. xnestCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
  147. GCPtr pGC, int srcx, int srcy, int width, int height,
  148. int dstx, int dsty, unsigned long plane)
  149. {
  150. XCopyPlane(xnestDisplay,
  151. xnestDrawable(pSrcDrawable), xnestDrawable(pDstDrawable),
  152. xnestGC(pGC), srcx, srcy, width, height, dstx, dsty, plane);
  153. return xnestBitBlitHelper(pGC);
  154. }
  155. void
  156. xnestPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int nPoints,
  157. DDXPointPtr pPoints)
  158. {
  159. XDrawPoints(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  160. (XPoint *)pPoints, nPoints, mode);
  161. }
  162. void
  163. xnestPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode, int nPoints,
  164. DDXPointPtr pPoints)
  165. {
  166. XDrawLines(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  167. (XPoint *)pPoints, nPoints, mode);
  168. }
  169. void
  170. xnestPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nSegments,
  171. xSegment *pSegments)
  172. {
  173. XDrawSegments(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  174. (XSegment *)pSegments, nSegments);
  175. }
  176. void
  177. xnestPolyRectangle(DrawablePtr pDrawable, GCPtr pGC, int nRectangles,
  178. xRectangle *pRectangles)
  179. {
  180. XDrawRectangles(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  181. (XRectangle *)pRectangles, nRectangles);
  182. }
  183. void
  184. xnestPolyArc(DrawablePtr pDrawable, GCPtr pGC, int nArcs, xArc *pArcs)
  185. {
  186. XDrawArcs(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  187. (XArc *)pArcs, nArcs);
  188. }
  189. void
  190. xnestFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape, int mode,
  191. int nPoints, DDXPointPtr pPoints)
  192. {
  193. XFillPolygon(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  194. (XPoint *)pPoints, nPoints, shape, mode);
  195. }
  196. void
  197. xnestPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nRectangles,
  198. xRectangle *pRectangles)
  199. {
  200. XFillRectangles(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  201. (XRectangle *)pRectangles, nRectangles);
  202. }
  203. void
  204. xnestPolyFillArc(DrawablePtr pDrawable, GCPtr pGC, int nArcs, xArc *pArcs)
  205. {
  206. XFillArcs(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  207. (XArc *)pArcs, nArcs);
  208. }
  209. int
  210. xnestPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count,
  211. char *string)
  212. {
  213. int width;
  214. XDrawString(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  215. x, y, string, count);
  216. width = XTextWidth(xnestFontStruct(pGC->font), string, count);
  217. return width + x;
  218. }
  219. int
  220. xnestPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count,
  221. unsigned short *string)
  222. {
  223. int width;
  224. XDrawString16(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  225. x, y, (XChar2b *)string, count);
  226. width = XTextWidth16(xnestFontStruct(pGC->font), (XChar2b *)string, count);
  227. return width + x;
  228. }
  229. void
  230. xnestImageText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count,
  231. char *string)
  232. {
  233. XDrawImageString(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  234. x, y, string, count);
  235. }
  236. void
  237. xnestImageText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count,
  238. unsigned short *string)
  239. {
  240. XDrawImageString16(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
  241. x, y, (XChar2b *)string, count);
  242. }
  243. void
  244. xnestImageGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  245. unsigned int nGlyphs, CharInfoPtr *pCharInfo,
  246. pointer pGlyphBase)
  247. {
  248. ErrorF("xnest warning: function xnestImageGlyphBlt not implemented\n");
  249. }
  250. void
  251. xnestPolyGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
  252. unsigned int nGlyphs, CharInfoPtr *pCharInfo,
  253. pointer pGlyphBase)
  254. {
  255. ErrorF("xnest warning: function xnestPolyGlyphBlt not implemented\n");
  256. }
  257. void
  258. xnestPushPixels(GCPtr pGC, PixmapPtr pBitmap, DrawablePtr pDst,
  259. int width, int height, int x, int y)
  260. {
  261. /* only works for solid bitmaps */
  262. if (pGC->fillStyle == FillSolid)
  263. {
  264. XSetStipple (xnestDisplay, xnestGC(pGC), xnestPixmap(pBitmap));
  265. XSetTSOrigin (xnestDisplay, xnestGC(pGC), x, y);
  266. XSetFillStyle (xnestDisplay, xnestGC(pGC), FillStippled);
  267. XFillRectangle (xnestDisplay, xnestDrawable(pDst),
  268. xnestGC(pGC), x, y, width, height);
  269. XSetFillStyle (xnestDisplay, xnestGC(pGC), FillSolid);
  270. }
  271. else
  272. ErrorF("xnest warning: function xnestPushPixels not implemented\n");
  273. }