annotate src/redraw_man.c @ 12:79e9edf4c00a

Add redraw manager
author Thinker K.F. Li <thinker@branda.to>
date Mon, 28 Jul 2008 17:45:36 +0800
parents
children ed55009d96d3
rev   line source
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <stdlib.h>
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <string.h>
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "mb_types.h"
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include "shapes.h"
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #include "tools.h"
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include "redraw_man.h"
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 #define OK 0
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 #define ERR -1
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 int redraw_man_init(redraw_man_t *rdman) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 extern void redraw_man_destroy(redraw_man_t *rdman);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 memset(rdman, 0, sizeof(redraw_man_t));
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 rdman->geo_pool = elmpool_new(sizeof(geo_t), 128);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 if(rdman->geo_pool == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 rdman->coord_pool = elmpool_new(sizeof(coord_t), 16);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 if(rdman->coord_pool == NULL) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 elmpool_free(rdman->geo_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 rdman->root_coord = elmpool_elm_alloc(rdman->coord_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 if(rdman->root_coord == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 redraw_man_destroy(rdman);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 coord_init(rdman->root_coord, NULL);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 return OK;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 void redraw_man_destroy(redraw_man_t *rdman) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 elmpool_free(rdman->coord_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 elmpool_free(rdman->geo_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 #define ASSERT(x)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 /*
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 * Change transformation matrix
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 * - update aggregated transformation matrix
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 * - of coord_t object been changed.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 * - of children coord_t objects.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 * - redraw members of coord_t objects.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 * - redraw shape objects they are overlaid with members.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 * - find out overlaid shape objects.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 * - geo_t of a coord_t object
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 * - can make finding more efficiency.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 * - fill overlay geo_t objects of members.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 * Change a shape object
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 * - redraw changed object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 * - redraw shape objects they are overlaid with changed object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 * - find out overlaid shape objects.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 * That coord and geo of shape objects are setted by user code
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 * give user code a chance to collect coord and geo objects together
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 * and gain interest of higher cache hit rate.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 */
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 /*! \brief Find out all affected shape objects.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 * Find out all shape objects that are overalid with geo_t of
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 * a geometry changed object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 * Linear scan geo_t objects of all shape objects in all_shapes
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 * list of a redraw_man_t object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 */
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 int rdman_find_overlaid_shapes(redraw_man_t *rdman, geo_t *geo,
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 geo_t ***overlays) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 int n_geos;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 geo_t **geos;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 geo_t *geo_cur;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 int n_overlays;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 geo_t **_overlays;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 int i;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 n_geos = rdman->n_geos;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 geos = (geo_t **)malloc(sizeof(geo_t *) * n_geos);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 if(geos == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 return -1;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 _overlays = (geo_t **)malloc(sizeof(geo_t *) * n_geos);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 if(geos == NULL) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 free(geos);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 return -1;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 geo_cur = STAILQ_HEAD(rdman->all_geos);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 for(i = 0; i < n_geos; i++) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 geos[i] = geo_cur;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 geo_cur = STAILQ_NEXT(geo_t, next, geo_cur);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 geo_mark_overlay(geo, n_geos, geos, &n_overlays, _overlays);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 free(geos);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 *overlays = _overlays;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 return n_overlays;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 int rdman_add_shape(redraw_man_t *rdman, shape_t *shape, coord_t *coord) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 geo_t *geo;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 geo = elmpool_elm_alloc(rdman->geo_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 if(geo == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113 sh_attach_geo(shape, geo);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 STAILQ_INS_TAIL(rdman->all_geos, geo_t, next, geo);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 rdman->n_geos++;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116 sh_attach_coord(shape, coord);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 return OK;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 int rdman_remove_shape(redraw_man_t *rdman, shape_t *shape) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 STAILQ_REMOVE(rdman->all_geos, geo_t, next, shape->geo);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 elmpool_elm_free(rdman->geo_pool, shape->geo);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 sh_detach_geo(shape);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125 rdman->n_geos--;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 sh_detach_coord(shape);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 return OK;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 coord_t *coord;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 coord = elmpool_elm_alloc(rdman->coord_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134 if(coord == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 return NULL;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 coord_init(coord, parent);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 return coord;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 /*! \brief Free a coord of a redraw_man_t object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144 * \param coord is a coord_t without children and members.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 * \return 0 for successful, -1 for error.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 */
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 int rdman_coord_free(redraw_man_t *rdman, coord_t *coord) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148 coord_t *parent;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 parent = coord->parent;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 if(parent == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154 if(STAILQ_HEAD(coord->members) != NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157 if(STAILQ_HEAD(coord->children) != NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
158 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
159
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
160 STAILQ_REMOVE(parent->children, coord_t, sibling, coord);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 elmpool_elm_free(rdman->coord_pool, coord);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
163 return OK;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
164 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
165
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 void rdman_coord_changed(redraw_man_t *rdman, coord_t *coord) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
168
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
169 /*
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 * When redraw an area, the affected elements may also extend to
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171 * outside of the area. Since the order of drawing will change
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 * the result, it will infect more and more elements to keep
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173 * drawing order althrough they are overlaid directly with
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 * specified area.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 * To fix the problem, we don't extend the set of redrawing to
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
177 * elements they are not overliad directly. The redrawing is
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
178 * performed on a temporary surface, clipped to fit the area, and
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179 * update only specified area on the destinate surface.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
180 */
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
182 /*
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183 * To accelerate speed of transformation, when a matrix changed,
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184 * transformation should be aggregated and computed in a loop.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
185 * It can get intereset of higher hit rate of cache.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
186 * - shapes prvoide list of positions needed to be transformed.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
187 * - redraw_man transforms positions from shapes.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
188 * - shapes drawing with result of transforms.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
189 * - shapes should be called to give them a chance to update geometries.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
190 */
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
191
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
192 #ifdef UNITTEST
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
193
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 #include <CUnit/Basic.h>
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196 struct _sh_dummy {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
197 shape_t shape;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
198 co_aix x, y;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
199 co_aix w, h;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
200 };
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
201 typedef struct _sh_dummy sh_dummy_t;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
202
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 shape_t *sh_dummy_new(co_aix x, co_aix y, co_aix w, co_aix h) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
204 sh_dummy_t *dummy;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
205
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
206 dummy = (sh_dummy_t *)malloc(sizeof(sh_dummy_t));
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
207 if(dummy == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
208 return NULL;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
209
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
210 dummy->x = x;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
211 dummy->y = y;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
212 dummy->w = w;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
213 dummy->h = h;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
214
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
215 return (shape_t *)dummy;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
216 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
217
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
218 void sh_dummy_free(shape_t *sh) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
219 free(sh);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
220 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
221
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
222 void sh_dummy_transform(shape_t *shape) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
223 sh_dummy_t *dummy = (sh_dummy_t *)shape;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
224 co_aix poses[2][2];
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
225 co_aix x1, y1, x2, y2;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
226
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
227 if(shape->geo && shape->coord) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
228 x1 = dummy->x;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
229 y1 = dummy->y;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
230 x2 = x1 + dummy->w;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
231 y2 = y1 + dummy->h;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
232
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
233 coord_trans_pos(shape->coord, &x1, &y1);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234 coord_trans_pos(shape->coord, &x2, &y2);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
235 poses[0][0] = x1;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
236 poses[0][1] = y1;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
237 poses[1][0] = x2;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
238 poses[1][1] = y2;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
239
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
240 geo_init(shape->geo, 2, poses);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
241 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
242 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
243
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
244 void test_rdman_find_overlaid_shapes(void) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
245 redraw_man_t rdman;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
246 geo_t geo;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
247 coord_t *coords[3];
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
248 shape_t *shapes[5];
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
249 geo_t **overlays;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
250 int n;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
251 int i;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
252
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
253 redraw_man_init(&rdman);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
254 coords[0] = rdman.root_coord;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
255 for(i = 1; i < 3; i++) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
256 coords[i] = rdman_coord_new(&rdman, rdman.root_coord);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
257 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
258 for(i = 0; i < 5; i++) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
259 shapes[i] = sh_dummy_new(10 + i * 30, 10 + i * 20, 25, 15);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
260 CU_ASSERT(shapes[i] != NULL);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
261 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
262 for(i = 0; i < 3; i++)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
263 rdman_add_shape(&rdman, shapes[i], coords[1]);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
264 for(i = 3; i < 5; i++)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
265 rdman_add_shape(&rdman, shapes[i], coords[2]);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
266
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
267 coords[1]->matrix[0] = 2;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
268 coords[0]->matrix[4] = 2;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
269
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
270 update_aggr_matrix(coords[0]);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
271 for(i = 0; i < 5; i++)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
272 sh_dummy_transform(shapes[i]);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
273
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
274 geo.x = 100;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
275 geo.y = 120;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
276 geo.w = 140;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
277 geo.h = 40;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
278
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
279 n = rdman_find_overlaid_shapes(&rdman, &geo, &overlays);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
280 CU_ASSERT(n == 2);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
281 CU_ASSERT(overlays != NULL);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
282 CU_ASSERT(overlays[0] == shapes[2]->geo);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
283 CU_ASSERT(overlays[1] == shapes[3]->geo);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
284
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
285 free(overlays);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
286 for(i = 0; i < 5; i++)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
287 sh_dummy_free(shapes[i]);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
288
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
289 redraw_man_destroy(&rdman);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
290 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
291
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
292 CU_pSuite get_redraw_man_suite(void) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
293 CU_pSuite suite;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
294
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
295 suite = CU_add_suite("Suite_redraw_man", NULL, NULL);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
296 CU_ADD_TEST(suite, test_rdman_find_overlaid_shapes);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
297
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
298 return suite;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
299 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
300
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
301 #endif /* UNITTEST */