PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/mi/mizerline.c

https://gitlab.com/buktemirlnk/xorg-xserver
C | 358 lines | 228 code | 42 blank | 88 comment | 45 complexity | 30ce81a18458eda7106d85c6afca8f6f MD5 | raw file
  1. /***********************************************************
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ******************************************************************/
  36. #ifdef HAVE_DIX_CONFIG_H
  37. #include <dix-config.h>
  38. #endif
  39. #include <X11/X.h>
  40. #include "misc.h"
  41. #include "scrnintstr.h"
  42. #include "gcstruct.h"
  43. #include "windowstr.h"
  44. #include "pixmap.h"
  45. #include "mi.h"
  46. #include "miline.h"
  47. /* Draw lineSolid, fillStyle-independent zero width lines.
  48. *
  49. * Must keep X and Y coordinates in "ints" at least until after they're
  50. * translated and clipped to accomodate CoordModePrevious lines with very
  51. * large coordinates.
  52. *
  53. * Draws the same pixels regardless of sign(dx) or sign(dy).
  54. *
  55. * Ken Whaley
  56. *
  57. */
  58. /* largest positive value that can fit into a component of a point.
  59. * Assumes that the point structure is {type x, y;} where type is
  60. * a signed type.
  61. */
  62. #define MAX_COORDINATE ((1 << (((sizeof(DDXPointRec) >> 1) << 3) - 1)) - 1)
  63. #define MI_OUTPUT_POINT(xx, yy)\
  64. {\
  65. if ( !new_span && yy == current_y)\
  66. {\
  67. if (xx < spans->x)\
  68. spans->x = xx;\
  69. ++*widths;\
  70. }\
  71. else\
  72. {\
  73. ++Nspans;\
  74. ++spans;\
  75. ++widths;\
  76. spans->x = xx;\
  77. spans->y = yy;\
  78. *widths = 1;\
  79. current_y = yy;\
  80. new_span = FALSE;\
  81. }\
  82. }
  83. void
  84. miZeroLine(DrawablePtr pDraw, GCPtr pGC, int mode, /* Origin or Previous */
  85. int npt, /* number of points */
  86. DDXPointPtr pptInit)
  87. {
  88. int Nspans, current_y = 0;
  89. DDXPointPtr ppt;
  90. DDXPointPtr pspanInit, spans;
  91. int *pwidthInit, *widths, list_len;
  92. int xleft, ytop, xright, ybottom;
  93. int new_x1, new_y1, new_x2, new_y2;
  94. int x = 0, y = 0, x1, y1, x2, y2, xstart, ystart;
  95. int oc1, oc2;
  96. int result;
  97. int pt1_clipped, pt2_clipped = 0;
  98. Bool new_span;
  99. int signdx, signdy;
  100. int clipdx, clipdy;
  101. int width, height;
  102. int adx, ady;
  103. int octant;
  104. unsigned int bias = miGetZeroLineBias(pDraw->pScreen);
  105. int e, e1, e2, e3; /* Bresenham error terms */
  106. int length; /* length of lines == # of pixels on major axis */
  107. xleft = pDraw->x;
  108. ytop = pDraw->y;
  109. xright = pDraw->x + pDraw->width - 1;
  110. ybottom = pDraw->y + pDraw->height - 1;
  111. if (!pGC->miTranslate) {
  112. /* do everything in drawable-relative coordinates */
  113. xleft = 0;
  114. ytop = 0;
  115. xright -= pDraw->x;
  116. ybottom -= pDraw->y;
  117. }
  118. /* it doesn't matter whether we're in drawable or screen coordinates,
  119. * FillSpans simply cannot take starting coordinates outside of the
  120. * range of a DDXPointRec component.
  121. */
  122. if (xright > MAX_COORDINATE)
  123. xright = MAX_COORDINATE;
  124. if (ybottom > MAX_COORDINATE)
  125. ybottom = MAX_COORDINATE;
  126. /* since we're clipping to the drawable's boundaries & coordinate
  127. * space boundaries, we're guaranteed that the larger of width/height
  128. * is the longest span we'll need to output
  129. */
  130. width = xright - xleft + 1;
  131. height = ybottom - ytop + 1;
  132. list_len = (height >= width) ? height : width;
  133. pspanInit = xallocarray(list_len, sizeof(DDXPointRec));
  134. pwidthInit = xallocarray(list_len, sizeof(int));
  135. if (!pspanInit || !pwidthInit) {
  136. free(pspanInit);
  137. free(pwidthInit);
  138. return;
  139. }
  140. Nspans = 0;
  141. new_span = TRUE;
  142. spans = pspanInit - 1;
  143. widths = pwidthInit - 1;
  144. ppt = pptInit;
  145. xstart = ppt->x;
  146. ystart = ppt->y;
  147. if (pGC->miTranslate) {
  148. xstart += pDraw->x;
  149. ystart += pDraw->y;
  150. }
  151. /* x2, y2, oc2 copied to x1, y1, oc1 at top of loop to simplify
  152. * iteration logic
  153. */
  154. x2 = xstart;
  155. y2 = ystart;
  156. oc2 = 0;
  157. MIOUTCODES(oc2, x2, y2, xleft, ytop, xright, ybottom);
  158. while (--npt > 0) {
  159. x1 = x2;
  160. y1 = y2;
  161. oc1 = oc2;
  162. ++ppt;
  163. x2 = ppt->x;
  164. y2 = ppt->y;
  165. if (pGC->miTranslate && (mode != CoordModePrevious)) {
  166. x2 += pDraw->x;
  167. y2 += pDraw->y;
  168. }
  169. else if (mode == CoordModePrevious) {
  170. x2 += x1;
  171. y2 += y1;
  172. }
  173. oc2 = 0;
  174. MIOUTCODES(oc2, x2, y2, xleft, ytop, xright, ybottom);
  175. CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy, 1, 1, octant);
  176. if (ady + 1 > (list_len - Nspans)) {
  177. (*pGC->ops->FillSpans) (pDraw, pGC, Nspans, pspanInit,
  178. pwidthInit, FALSE);
  179. Nspans = 0;
  180. spans = pspanInit - 1;
  181. widths = pwidthInit - 1;
  182. }
  183. new_span = TRUE;
  184. if (adx > ady) {
  185. e1 = ady << 1;
  186. e2 = e1 - (adx << 1);
  187. e = e1 - adx;
  188. length = adx; /* don't draw endpoint in main loop */
  189. FIXUP_ERROR(e, octant, bias);
  190. new_x1 = x1;
  191. new_y1 = y1;
  192. new_x2 = x2;
  193. new_y2 = y2;
  194. pt1_clipped = 0;
  195. pt2_clipped = 0;
  196. if ((oc1 | oc2) != 0) {
  197. result = miZeroClipLine(xleft, ytop, xright, ybottom,
  198. &new_x1, &new_y1, &new_x2, &new_y2,
  199. adx, ady,
  200. &pt1_clipped, &pt2_clipped,
  201. octant, bias, oc1, oc2);
  202. if (result == -1)
  203. continue;
  204. length = abs(new_x2 - new_x1);
  205. /* if we've clipped the endpoint, always draw the full length
  206. * of the segment, because then the capstyle doesn't matter
  207. */
  208. if (pt2_clipped)
  209. length++;
  210. if (pt1_clipped) {
  211. /* must calculate new error terms */
  212. clipdx = abs(new_x1 - x1);
  213. clipdy = abs(new_y1 - y1);
  214. e += (clipdy * e2) + ((clipdx - clipdy) * e1);
  215. }
  216. }
  217. /* draw the segment */
  218. x = new_x1;
  219. y = new_y1;
  220. e3 = e2 - e1;
  221. e = e - e1;
  222. while (length--) {
  223. MI_OUTPUT_POINT(x, y);
  224. e += e1;
  225. if (e >= 0) {
  226. y += signdy;
  227. e += e3;
  228. }
  229. x += signdx;
  230. }
  231. }
  232. else { /* Y major line */
  233. e1 = adx << 1;
  234. e2 = e1 - (ady << 1);
  235. e = e1 - ady;
  236. length = ady; /* don't draw endpoint in main loop */
  237. SetYMajorOctant(octant);
  238. FIXUP_ERROR(e, octant, bias);
  239. new_x1 = x1;
  240. new_y1 = y1;
  241. new_x2 = x2;
  242. new_y2 = y2;
  243. pt1_clipped = 0;
  244. pt2_clipped = 0;
  245. if ((oc1 | oc2) != 0) {
  246. result = miZeroClipLine(xleft, ytop, xright, ybottom,
  247. &new_x1, &new_y1, &new_x2, &new_y2,
  248. adx, ady,
  249. &pt1_clipped, &pt2_clipped,
  250. octant, bias, oc1, oc2);
  251. if (result == -1)
  252. continue;
  253. length = abs(new_y2 - new_y1);
  254. /* if we've clipped the endpoint, always draw the full length
  255. * of the segment, because then the capstyle doesn't matter
  256. */
  257. if (pt2_clipped)
  258. length++;
  259. if (pt1_clipped) {
  260. /* must calculate new error terms */
  261. clipdx = abs(new_x1 - x1);
  262. clipdy = abs(new_y1 - y1);
  263. e += (clipdx * e2) + ((clipdy - clipdx) * e1);
  264. }
  265. }
  266. /* draw the segment */
  267. x = new_x1;
  268. y = new_y1;
  269. e3 = e2 - e1;
  270. e = e - e1;
  271. while (length--) {
  272. MI_OUTPUT_POINT(x, y);
  273. e += e1;
  274. if (e >= 0) {
  275. x += signdx;
  276. e += e3;
  277. }
  278. y += signdy;
  279. }
  280. }
  281. }
  282. /* only do the capnotlast check on the last segment
  283. * and only if the endpoint wasn't clipped. And then, if the last
  284. * point is the same as the first point, do not draw it, unless the
  285. * line is degenerate
  286. */
  287. if ((!pt2_clipped) && (pGC->capStyle != CapNotLast) &&
  288. (((xstart != x2) || (ystart != y2)) || (ppt == pptInit + 1))) {
  289. MI_OUTPUT_POINT(x, y);
  290. }
  291. if (Nspans > 0)
  292. (*pGC->ops->FillSpans) (pDraw, pGC, Nspans, pspanInit,
  293. pwidthInit, FALSE);
  294. free(pwidthInit);
  295. free(pspanInit);
  296. }
  297. void
  298. miZeroDashLine(DrawablePtr dst, GCPtr pgc, int mode, int nptInit, /* number of points in polyline */
  299. DDXPointRec * pptInit /* points in the polyline */
  300. )
  301. {
  302. /* XXX kludge until real zero-width dash code is written */
  303. pgc->lineWidth = 1;
  304. miWideDash(dst, pgc, mode, nptInit, pptInit);
  305. pgc->lineWidth = 0;
  306. }