comparison src/redraw_man.c @ 832:8ae1fb7b3104

Check transform from parent cached coord to descendant cached coord
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 17 Sep 2010 12:21:35 +0800
parents 94041f085797
children 419c7de41bfa
comparison
equal deleted inserted replaced
831:904b6928f727 832:8ae1fb7b3104
515 static void free_objs_destroy(redraw_man_t *rdman) { 515 static void free_objs_destroy(redraw_man_t *rdman) {
516 if(rdman->free_objs.objs != NULL) 516 if(rdman->free_objs.objs != NULL)
517 free(rdman->free_objs.objs); 517 free(rdman->free_objs.objs);
518 } 518 }
519 519
520 520 #ifdef UNITTEST
521 /*! \brief This is only used for unittest.
522 */
523 typedef struct {
524 co_aix parent_2_cache[6];
525 } mock_mbe_t;
526 #endif
521 527
522 static mbe_t *canvas_new(int w, int h) { 528 static mbe_t *canvas_new(int w, int h) {
523 #ifndef UNITTEST 529 #ifndef UNITTEST
524 mbe_surface_t *surface; 530 mbe_surface_t *surface;
525 mbe_t *cr; 531 mbe_t *cr;
528 w, h); 534 w, h);
529 cr = mbe_create(surface); 535 cr = mbe_create(surface);
530 536
531 return cr; 537 return cr;
532 #else 538 #else
533 return (mbe_t *)malloc(16); 539 return (mbe_t *)malloc(sizeof(mock_mbe_t));
534 #endif 540 #endif
535 } 541 }
536 542
537 static void canvas_free(mbe_t *canvas) { 543 static void canvas_free(mbe_t *canvas) {
538 #ifndef UNITTEST 544 #ifndef UNITTEST
2189 static void copy_cr_2_backend(redraw_man_t *rdman, int n_dirty_areas, 2195 static void copy_cr_2_backend(redraw_man_t *rdman, int n_dirty_areas,
2190 area_t **dirty_areas) { 2196 area_t **dirty_areas) {
2191 } 2197 }
2192 #endif /* UNITTEST */ 2198 #endif /* UNITTEST */
2193 2199
2194 static void update_cached_canvas_2_parent(redraw_man_t *rdman, 2200 static void
2195 coord_t *coord) { 2201 _update_cached_canvas_2_parent(redraw_man_t *rdman, co_aix reverse[6],
2196 #ifndef UNITTEST 2202 mbe_t *canvas, mbe_t *pcanvas,
2197 mbe_t *pcanvas, *canvas; 2203 co_aix opacity) {
2198 mbe_surface_t *surface; 2204 mbe_surface_t *surface;
2199 mbe_pattern_t *pattern; 2205 mbe_pattern_t *pattern;
2200 co_aix reverse[6]; 2206
2201 co_aix canvas2pdev_matrix[6];
2202
2203 if(coord_is_root(coord))
2204 return;
2205
2206 compute_cached_2_pdev_matrix(coord, canvas2pdev_matrix);
2207 compute_reverse(canvas2pdev_matrix, reverse);
2208
2209 canvas = _coord_get_canvas(coord);
2210 pcanvas = _coord_get_canvas(coord->parent);
2211 surface = mbe_get_target(canvas); 2207 surface = mbe_get_target(canvas);
2212 pattern = mbe_pattern_create_for_surface(surface); 2208 pattern = mbe_pattern_create_for_surface(surface);
2213 mbe_pattern_set_matrix(pattern, reverse); 2209 mbe_pattern_set_matrix(pattern, reverse);
2214 mbe_set_source(pcanvas, pattern); 2210 mbe_set_source(pcanvas, pattern);
2215 mbe_paint_with_alpha(pcanvas, coord->opacity); 2211 mbe_paint_with_alpha(pcanvas, opacity);
2212 }
2213
2214 static void update_cached_canvas_2_parent(redraw_man_t *rdman,
2215 coord_t *coord) {
2216 mbe_t *pcanvas, *canvas;
2217 co_aix reverse[6];
2218 co_aix canvas2pdev_matrix[6];
2219
2220 if(coord_is_root(coord))
2221 return;
2222
2223 compute_cached_2_pdev_matrix(coord, canvas2pdev_matrix);
2224 compute_reverse(canvas2pdev_matrix, reverse);
2225
2226 canvas = _coord_get_canvas(coord);
2227 pcanvas = _coord_get_canvas(coord->parent);
2228 #ifndef UNITTEST
2229 _update_cached_canvas_2_parent(rdman, reverse, canvas, pcanvas,
2230 coord->opacity);
2231 #else
2232 memcpy(((mock_mbe_t *)canvas)->parent_2_cache, reverse,
2233 sizeof(co_aix) * 6);
2216 #endif 2234 #endif
2217 } 2235 }
2218 2236
2219 static int draw_coord_shapes_in_dirty_areas(redraw_man_t *rdman, 2237 static int draw_coord_shapes_in_dirty_areas(redraw_man_t *rdman,
2220 coord_t *coord) { 2238 coord_t *coord) {
2615 shape_t shape; 2633 shape_t shape;
2616 co_aix x, y; 2634 co_aix x, y;
2617 co_aix w, h; 2635 co_aix w, h;
2618 int trans_cnt; 2636 int trans_cnt;
2619 int draw_cnt; 2637 int draw_cnt;
2620 redraw_man_t *last_draw; 2638 mbe_t *last_draw;
2621 }; 2639 };
2622 2640
2623 void sh_dummy_free(shape_t *sh) { 2641 void sh_dummy_free(shape_t *sh) {
2624 free(sh); 2642 free(sh);
2625 } 2643 }
2807 CU_ASSERT(coord2->parent == coord1); 2825 CU_ASSERT(coord2->parent == coord1);
2808 2826
2809 coord_set_opacity(coord2, 0.9); 2827 coord_set_opacity(coord2, 0.9);
2810 rdman_coord_changed(rdman, coord2); 2828 rdman_coord_changed(rdman, coord2);
2811 2829
2812 sh = (shape_t *)sh_dummy_new(rdman, 100, 100, 20, 20); 2830 sh = (sh_dummy_t *)sh_dummy_new(rdman, 100, 100, 20, 20);
2813 rdman_add_shape(rdman, (shape_t *)sh, coord2); 2831 rdman_add_shape(rdman, (shape_t *)sh, coord2);
2814 rdman_shape_changed(rdman, (shape_t *)sh); 2832 rdman_shape_changed(rdman, (shape_t *)sh);
2815 2833
2816 clean_coord(rdman, coord2); 2834 clean_coord(rdman, coord2);
2817 2835
2841 CU_ASSERT(coord2->parent == coord1); 2859 CU_ASSERT(coord2->parent == coord1);
2842 2860
2843 coord_set_opacity(coord2, 0.9); 2861 coord_set_opacity(coord2, 0.9);
2844 rdman_coord_changed(rdman, coord2); 2862 rdman_coord_changed(rdman, coord2);
2845 2863
2846 sh = (shape_t *)sh_dummy_new(rdman, 100, 100, 20, 20); 2864 sh = (sh_dummy_t *)sh_dummy_new(rdman, 100, 100, 20, 20);
2847 rdman_add_shape(rdman, (shape_t *)sh, coord2); 2865 rdman_add_shape(rdman, (shape_t *)sh, coord2);
2848 rdman_shape_changed(rdman, (shape_t *)sh); 2866 rdman_shape_changed(rdman, (shape_t *)sh);
2849 2867
2850 rdman_clean_dirties(rdman); 2868 rdman_clean_dirties(rdman);
2851 2869
2865 redraw_man_t *rdman; 2883 redraw_man_t *rdman;
2866 redraw_man_t _rdman; 2884 redraw_man_t _rdman;
2867 coord_t *coord1, *coord2; 2885 coord_t *coord1, *coord2;
2868 sh_dummy_t *sh; 2886 sh_dummy_t *sh;
2869 paint_t *paint; 2887 paint_t *paint;
2888 co_aix *parent_2_cache;
2870 2889
2871 redraw_man_init(&_rdman, NULL, NULL); 2890 redraw_man_init(&_rdman, NULL, NULL);
2872 rdman = &_rdman; 2891 rdman = &_rdman;
2873 2892
2874 coord1 = rdman_coord_new(rdman, rdman->root_coord); 2893 coord1 = rdman_coord_new(rdman, rdman->root_coord);
2878 CU_ASSERT(coord2->parent == coord1); 2897 CU_ASSERT(coord2->parent == coord1);
2879 2898
2880 coord_set_opacity(coord2, 0.9); 2899 coord_set_opacity(coord2, 0.9);
2881 rdman_coord_changed(rdman, coord2); 2900 rdman_coord_changed(rdman, coord2);
2882 2901
2883 sh = (shape_t *)sh_dummy_new(rdman, 100, 100, 20, 20); 2902 sh = (sh_dummy_t *)sh_dummy_new(rdman, 100, 100, 20, 20);
2884 rdman_add_shape(rdman, (shape_t *)sh, coord2); 2903 rdman_add_shape(rdman, (shape_t *)sh, coord2);
2885 rdman_shape_changed(rdman, (shape_t *)sh); 2904 rdman_shape_changed(rdman, (shape_t *)sh);
2886 2905
2887 paint = dummy_paint_new(rdman); 2906 paint = dummy_paint_new(rdman);
2888 rdman_paint_fill(rdman, paint, (shape_t *)sh); 2907 rdman_paint_fill(rdman, paint, (shape_t *)sh);
2890 rdman_redraw_all(rdman); 2909 rdman_redraw_all(rdman);
2891 2910
2892 CU_ASSERT(sh->draw_cnt == 1); 2911 CU_ASSERT(sh->draw_cnt == 1);
2893 CU_ASSERT(sh->last_draw == _coord_get_canvas(coord2)); 2912 CU_ASSERT(sh->last_draw == _coord_get_canvas(coord2));
2894 2913
2914 parent_2_cache = ((mock_mbe_t *)_coord_get_canvas(coord2))->parent_2_cache;
2915 CU_ASSERT(parent_2_cache[0] == 1);
2916 CU_ASSERT(parent_2_cache[1] == 0);
2917 CU_ASSERT(parent_2_cache[2] == -100);
2918 CU_ASSERT(parent_2_cache[3] == 0);
2919 CU_ASSERT(parent_2_cache[4] == 1);
2920 CU_ASSERT(parent_2_cache[5] == -100);
2921
2895 rdman_paint_free(rdman, paint); 2922 rdman_paint_free(rdman, paint);
2896 redraw_man_destroy(rdman); 2923 redraw_man_destroy(rdman);
2897 } 2924 }
2898 2925
2899 CU_pSuite get_redraw_man_suite(void) { 2926 CU_pSuite get_redraw_man_suite(void) {