<div dir="ltr">From: Conn Clark <<a href="mailto:conn.o.clark@gmail.com">conn.o.clark@gmail.com</a>><br><br>Signed-off-by: Conn Clark <<a href="mailto:conn.o.clark@gmail.com">conn.o.clark@gmail.com</a>><br><br>
---<br>diff --git a/src/glamor_polylines.c b/src/glamor_polylines.c<br>index 36636f0..6bbc783 100644<br>--- a/src/glamor_polylines.c<br>+++ b/src/glamor_polylines.c<br>@@ -40,12 +40,10 @@ static void _draw_line(xRectangle *rects, int rect, int x1, int y1, int x2, int<br>
rects[rect].height = abs(y1 - y2) + 1;<br> }<br> <br>-static xRectangle *_emit_line(xRectangle *rects, int *rects_cnt, int *rect, int x1, int y1, int x2, int y2){<br>- *rects_cnt += 1;<br>- rects = realloc(rects, sizeof(xRectangle) * *rects_cnt);<br>
+static void _emit_line(xRectangle *rects, int *rect, int x1, int y1, int x2, int y2){<br> _draw_line(rects, *rect, x1, y1, x2, y2);<br> *rect += 1;<br>- return rects;<br>+ return;<br> }<br> <br> static void _init_points(int *last_x, int *last_y, int cur_x, int cur_y, int *last_start_x, int *last_start_y){<br>
@@ -53,16 +51,16 @@ static void _init_points(int *last_x, int *last_y, int cur_x, int cur_y, int *la<br> *last_y = *last_start_y = cur_y;<br> }<br> <br>-static xRectangle *_next_point(xRectangle *rects, int *rects_cnt, int *rect, int cur_x, int cur_y, int *last_x, int *last_y, int *last_start_x, int *last_start_y, int steep){<br>
+static void _next_point(xRectangle *rects, int *rect, int cur_x, int cur_y, int *last_x, int *last_y, int *last_start_x, int *last_start_y, int steep){<br> if ((steep && *last_x != cur_x) || (!steep && *last_y != cur_y)){<br>
//emit a line from last_start_x,last_start_y to last_x,last_y<br>- rects = _emit_line(rects, rects_cnt, rect, *last_start_x, *last_start_y, *last_x, *last_y);<br>+ _emit_line(rects, rect, *last_start_x, *last_start_y, *last_x, *last_y);<br>
*last_start_x = cur_x;<br> *last_start_y = cur_y;<br> }<br> *last_x = cur_x;<br> *last_y = cur_y;<br>- return rects;<br>+ return;<br> }<br> <br> /**<br>@@ -127,6 +125,10 @@ static xRectangle *_glamor_diagonal_line(xRectangle *rects, int *rect_cnt, int *<br>
cur_x = x1;<br> cur_y = y1;<br> <br>+ // Adjust the rect_cnt and memory alloced for the number of rects added<br>+ *rect_cnt += abs(y2-y1);<br>+ rects = realloc(rects, sizeof(xRectangle) * *rect_cnt);<br>
+<br> //Now just iterate over the range from x1 to x2 and calculate the y values<br> //When plotting the points, if (vert==true), then just swap the cur_x/cur_y values<br> if (vert)<br>@@ -138,9 +140,9 @@ static xRectangle *_glamor_diagonal_line(xRectangle *rects, int *rect_cnt, int *<br>
cur_x = x1+i;<br> cur_y = y1 + round(((float)i)*slope);<br> if (vert)<br>- rects = _next_point(rects, rect_cnt, rect, cur_y, cur_x, &last_x, &last_y, &last_start_x, &last_start_y, vert);<br>
+ _next_point(rects, rect, cur_y, cur_x, &last_x, &last_y, &last_start_x, &last_start_y, vert);<br> else<br>- rects = _next_point(rects, rect_cnt, rect, cur_x, cur_y, &last_x, &last_y, &last_start_x, &last_start_y, vert);<br>
+ _next_point(rects, rect, cur_x, cur_y, &last_x, &last_y, &last_start_x, &last_start_y, vert);<br> }<br> <br> //And now finalize the last line segment using the space that was originally<br>
<br><br>--<br><br>Conn O. Clark<br><br>Observation: In formal computer science advances are made<br>by standing on the shoulders of giants. Linux has proved<br>that if there are enough of you, you can advance just as<br>far by stepping on each others toes.</div>