diff src/redraw_man.c @ 152:2b316b5d65f9

Refactory code snippets for making coords dirty. add_dirty_coord() is the function to making coords dirty.
author Thinker K.F. Li <thinker@branda.to>
date Fri, 26 Sep 2008 17:56:08 +0800
parents d11aa8fc06c7
children 6ce68c1f7405
line wrap: on
line diff
--- a/src/redraw_man.c	Fri Sep 26 17:42:16 2008 +0800
+++ b/src/redraw_man.c	Fri Sep 26 17:56:08 2008 +0800
@@ -90,6 +90,27 @@
     return OK;
 }
 
+static int add_dirty_coord(redraw_man_t *rdman, coord_t *coord) {
+    int max_dirty_coords;
+    int r;
+    
+    if(rdman->n_dirty_coords >= rdman->max_dirty_coords) {
+	/* Max of dirty_coords is not big enough. */
+	max_dirty_coords = rdman->max_dirty_coords + 16;
+	
+	r = extend_memblk((void **)&rdman->dirty_coords,
+			  sizeof(coord_t *) * rdman->n_dirty_coords,
+			  sizeof(coord_t *) * max_dirty_coords);
+	if(r != OK)
+	    return ERR;
+	rdman->max_dirty_coords = max_dirty_coords;
+    }
+
+    rdman->dirty_coords[rdman->n_dirty_coords++] = coord;
+    coord->flags |= COF_DIRTY;
+    return OK;
+}
+
 static int add_dirty_geo(redraw_man_t *rdman, geo_t *geo) {
     int max_dirty_geos;
     int r;
@@ -393,7 +414,7 @@
 
     /* If parent is dirty, children should be dirty. */
     if(parent && (parent->flags & COF_DIRTY))
-	rdman_coord_changed(rdman, coord);
+	add_dirty_coord(rdman, coord);
 
     return coord;
 }
@@ -428,21 +449,6 @@
     return OK;
 }
 
-static void make_sure_dirty_coords(redraw_man_t *rdman) {
-    int max_dirty_coords;
-    int r;
-    
-    if(rdman->n_dirty_coords >= rdman->max_dirty_coords) {
-	/* Max of dirty_coords is not big enough. */
-	max_dirty_coords = rdman->max_dirty_coords + 16;
-	
-	r = extend_memblk((void **)&rdman->dirty_coords,
-			  sizeof(coord_t *) * rdman->n_dirty_coords,
-			  sizeof(coord_t *) * max_dirty_coords);
-	rdman->max_dirty_coords = max_dirty_coords;
-    }
-}
-
 /*! \brief Mark a coord is changed.
  *
  * A changed coord_t object is marked as dirty and put
@@ -454,9 +460,7 @@
     if(coord->flags & COF_DIRTY)
 	return OK;
 
-    make_sure_dirty_coords(rdman);
-    rdman->dirty_coords[rdman->n_dirty_coords++] = coord;
-    coord->flags |= COF_DIRTY;
+    add_dirty_coord(rdman, coord);
 
     /* Make child coords dirty. */
     for(child = preorder_coord_subtree(coord, coord);
@@ -467,9 +471,7 @@
 	    continue;
 	}
 
-	make_sure_dirty_coords(rdman);
-	rdman->dirty_coords[rdman->n_dirty_coords++] = child;
-	child->flags |= COF_DIRTY;
+	add_dirty_coord(rdman, child);
     }
 
     return OK;