[Glamor] Patch 02/01] Move realloc out of diagonal line drawing loop (2nd post attempt).

Conn Clark conn.o.clark at gmail.com
Tue Mar 25 14:12:48 PDT 2014


From: Conn Clark <conn.o.clark at gmail.com>

Signed-off-by: Conn Clark <conn.o.clark at gmail.com>

---
diff --git a/src/glamor_polylines.c b/src/glamor_polylines.c
index 36636f0..6bbc783 100644
--- a/src/glamor_polylines.c
+++ b/src/glamor_polylines.c
@@ -40,12 +40,10 @@ static void _draw_line(xRectangle *rects, int rect, int
x1, int y1, int x2, int
         rects[rect].height = abs(y1 - y2) + 1;
 }

-static xRectangle *_emit_line(xRectangle *rects, int *rects_cnt, int
*rect, int x1, int y1, int x2, int y2){
-    *rects_cnt += 1;
-    rects = realloc(rects, sizeof(xRectangle) * *rects_cnt);
+static void _emit_line(xRectangle *rects, int *rect, int x1, int y1, int
x2, int y2){
     _draw_line(rects, *rect, x1, y1, x2, y2);
     *rect += 1;
-    return rects;
+    return;
 }

 static void _init_points(int *last_x, int *last_y, int cur_x, int cur_y,
int *last_start_x, int *last_start_y){
@@ -53,16 +51,16 @@ static void _init_points(int *last_x, int *last_y, int
cur_x, int cur_y, int *la
         *last_y = *last_start_y = cur_y;
 }

-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){
+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){
     if ((steep && *last_x != cur_x) || (!steep && *last_y != cur_y)){
         //emit a line from last_start_x,last_start_y to last_x,last_y
-        rects = _emit_line(rects, rects_cnt, rect, *last_start_x,
*last_start_y, *last_x, *last_y);
+        _emit_line(rects, rect, *last_start_x, *last_start_y, *last_x,
*last_y);
         *last_start_x = cur_x;
         *last_start_y = cur_y;
     }
     *last_x = cur_x;
     *last_y = cur_y;
-    return rects;
+    return;
 }

 /**
@@ -127,6 +125,10 @@ static xRectangle *_glamor_diagonal_line(xRectangle
*rects, int *rect_cnt, int *
     cur_x = x1;
     cur_y = y1;

+    // Adjust the rect_cnt and memory alloced for the number of rects added
+        *rect_cnt += abs(y2-y1);
+        rects = realloc(rects, sizeof(xRectangle) * *rect_cnt);
+
     //Now just iterate over the range from x1 to x2 and calculate the y
values
     //When plotting the points, if (vert==true), then just swap the
cur_x/cur_y values
     if (vert)
@@ -138,9 +140,9 @@ static xRectangle *_glamor_diagonal_line(xRectangle
*rects, int *rect_cnt, int *
         cur_x = x1+i;
         cur_y = y1 + round(((float)i)*slope);
         if (vert)
-            rects = _next_point(rects, rect_cnt, rect, cur_y, cur_x,
&last_x, &last_y, &last_start_x, &last_start_y, vert);
+            _next_point(rects, rect, cur_y, cur_x, &last_x, &last_y,
&last_start_x, &last_start_y, vert);
         else
-            rects = _next_point(rects, rect_cnt, rect, cur_x, cur_y,
&last_x, &last_y, &last_start_x, &last_start_y, vert);
+            _next_point(rects, rect, cur_x, cur_y, &last_x, &last_y,
&last_start_x, &last_start_y, vert);
     }

     //And now finalize the last line segment using the space that was
originally


--

Conn O. Clark

Observation: In formal computer science advances are made
by standing on the shoulders of giants. Linux has proved
that if there are enough of you, you can advance just as
far by stepping on each others toes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/glamor/attachments/20140325/ddf1823f/attachment.html>


More information about the Glamor mailing list