diff src/redraw_man.c @ 816:0e56a1ca19b2

Testcases for caching coords
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 13 Sep 2010 13:25:34 +0800
parents 4badbfa8f386
children 387d1c597632
line wrap: on
line diff
--- a/src/redraw_man.c	Sun Sep 12 12:20:09 2010 +0800
+++ b/src/redraw_man.c	Mon Sep 13 13:25:34 2010 +0800
@@ -584,9 +584,11 @@
     coord->num_members--;
 }
 
-static coord_canvas_info_t *coord_canvas_info_new(redraw_man_t *rdman,
-						  coord_t *coord,
-						  mbe_t *canvas) {
+/*! \brief Create a new canvas and respective info struct for a coord.
+ */
+static coord_canvas_info_t *
+coord_canvas_info_new(redraw_man_t *rdman, coord_t *coord,
+		      mbe_t *canvas) {
     coord_canvas_info_t *info;
 
     info = (coord_canvas_info_t *)elmpool_elm_alloc(rdman->coord_canvas_pool);
@@ -1243,7 +1245,7 @@
     if(coord->parent == NULL)
 	return;
 
-    if(coord->opacity != 1 || coord_is_cached(coord)) {
+    if(coord->opacity != 1 || coord_is_always_cached(coord)) {
 	if(!coord_is_cached(coord)) {
 	    /* canvas is assigned latter, in zeroing_coord() */
 	    coord->canvas_info = coord_canvas_info_new(rdman, coord, NULL);
@@ -1981,6 +1983,8 @@
 	}
     }
     
+    /* XXX: some geo may swap two times.  Should avoid it.
+     */
     geos = rdman->dirty_geos.ds;
     for(i = 0; i < rdman->dirty_geos.num; i++) {
 	geo = geos[i];
@@ -2754,12 +2758,66 @@
     CU_ASSERT(test_free_pass == 4);
 }
 
+static void
+test_setup_canvas_info(void) {
+    redraw_man_t *rdman;
+    redraw_man_t _rdman;
+    coord_t *coord;
+
+    redraw_man_init(&_rdman, NULL, NULL);
+    rdman = &_rdman;
+    
+    coord = rdman_coord_new(rdman, rdman->root_coord);
+    CU_ASSERT(coord->parent == rdman->root_coord);
+
+    coord_set_opacity(coord, 0.9);
+    setup_canvas_info(rdman, coord);
+
+    CU_ASSERT(coord->canvas_info != rdman->root_coord->canvas_info);
+
+    coord_set_opacity(coord, 1);
+    setup_canvas_info(rdman, coord);
+
+    CU_ASSERT(coord->canvas_info == rdman->root_coord->canvas_info);
+}
+
+static void
+test_own_canvas(void) {
+    redraw_man_t *rdman;
+    redraw_man_t _rdman;
+    coord_t *coord1, *coord2;
+    sh_dummy_t *sh;
+
+    redraw_man_init(&_rdman, NULL, NULL);
+    rdman = &_rdman;
+    
+    coord1 = rdman_coord_new(rdman, rdman->root_coord);
+    CU_ASSERT(coord1->parent == rdman->root_coord);
+
+    coord2 = rdman_coord_new(rdman, coord1);
+    CU_ASSERT(coord2->parent == coord1);
+
+    coord_set_opacity(coord2, 0.9);
+    rdman_coord_changed(rdman, coord2);
+
+    sh = (shape_t *)sh_dummy_new(rdman, 100, 100, 20, 20);
+    rdman_add_shape(rdman, (shape_t *)sh, coord2);
+    rdman_shape_changed(rdman, (shape_t *)sh);
+
+    clean_rdman_coords(rdman);
+
+    /* Parent cached coord must be updated */
+    CU_ASSERT(_coord_get_dirty_areas(rdman->root_coord)->num >= 1);
+}
+
 CU_pSuite get_redraw_man_suite(void) {
     CU_pSuite suite;
 
     suite = CU_add_suite("Suite_redraw_man", NULL, NULL);
     CU_ADD_TEST(suite, test_rdman_redraw_changed);
     CU_ADD_TEST(suite, test_rdman_free_objs);
+    CU_ADD_TEST(suite, test_setup_canvas_info);
+    CU_ADD_TEST(suite, test_own_canvas);
 
     return suite;
 }