comparison 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
comparison
equal deleted inserted replaced
151:d11aa8fc06c7 152:2b316b5d65f9
88 *buf = new_buf; 88 *buf = new_buf;
89 89
90 return OK; 90 return OK;
91 } 91 }
92 92
93 static int add_dirty_coord(redraw_man_t *rdman, coord_t *coord) {
94 int max_dirty_coords;
95 int r;
96
97 if(rdman->n_dirty_coords >= rdman->max_dirty_coords) {
98 /* Max of dirty_coords is not big enough. */
99 max_dirty_coords = rdman->max_dirty_coords + 16;
100
101 r = extend_memblk((void **)&rdman->dirty_coords,
102 sizeof(coord_t *) * rdman->n_dirty_coords,
103 sizeof(coord_t *) * max_dirty_coords);
104 if(r != OK)
105 return ERR;
106 rdman->max_dirty_coords = max_dirty_coords;
107 }
108
109 rdman->dirty_coords[rdman->n_dirty_coords++] = coord;
110 coord->flags |= COF_DIRTY;
111 return OK;
112 }
113
93 static int add_dirty_geo(redraw_man_t *rdman, geo_t *geo) { 114 static int add_dirty_geo(redraw_man_t *rdman, geo_t *geo) {
94 int max_dirty_geos; 115 int max_dirty_geos;
95 int r; 116 int r;
96 117
97 if(rdman->n_dirty_geos >= rdman->max_dirty_geos) { 118 if(rdman->n_dirty_geos >= rdman->max_dirty_geos) {
391 412
392 coord->before_pmem = parent->num_members; 413 coord->before_pmem = parent->num_members;
393 414
394 /* If parent is dirty, children should be dirty. */ 415 /* If parent is dirty, children should be dirty. */
395 if(parent && (parent->flags & COF_DIRTY)) 416 if(parent && (parent->flags & COF_DIRTY))
396 rdman_coord_changed(rdman, coord); 417 add_dirty_coord(rdman, coord);
397 418
398 return coord; 419 return coord;
399 } 420 }
400 421
401 /*! \brief Free a coord of a redraw_man_t object. 422 /*! \brief Free a coord of a redraw_man_t object.
426 rdman->n_coords--; 447 rdman->n_coords--;
427 448
428 return OK; 449 return OK;
429 } 450 }
430 451
431 static void make_sure_dirty_coords(redraw_man_t *rdman) {
432 int max_dirty_coords;
433 int r;
434
435 if(rdman->n_dirty_coords >= rdman->max_dirty_coords) {
436 /* Max of dirty_coords is not big enough. */
437 max_dirty_coords = rdman->max_dirty_coords + 16;
438
439 r = extend_memblk((void **)&rdman->dirty_coords,
440 sizeof(coord_t *) * rdman->n_dirty_coords,
441 sizeof(coord_t *) * max_dirty_coords);
442 rdman->max_dirty_coords = max_dirty_coords;
443 }
444 }
445
446 /*! \brief Mark a coord is changed. 452 /*! \brief Mark a coord is changed.
447 * 453 *
448 * A changed coord_t object is marked as dirty and put 454 * A changed coord_t object is marked as dirty and put
449 * into dirty_coords list. 455 * into dirty_coords list.
450 */ 456 */
452 coord_t *child; 458 coord_t *child;
453 459
454 if(coord->flags & COF_DIRTY) 460 if(coord->flags & COF_DIRTY)
455 return OK; 461 return OK;
456 462
457 make_sure_dirty_coords(rdman); 463 add_dirty_coord(rdman, coord);
458 rdman->dirty_coords[rdman->n_dirty_coords++] = coord;
459 coord->flags |= COF_DIRTY;
460 464
461 /* Make child coords dirty. */ 465 /* Make child coords dirty. */
462 for(child = preorder_coord_subtree(coord, coord); 466 for(child = preorder_coord_subtree(coord, coord);
463 child != NULL; 467 child != NULL;
464 child = preorder_coord_subtree(coord, child)) { 468 child = preorder_coord_subtree(coord, child)) {
465 if(child->flags & (COF_DIRTY | COF_HIDDEN)) { 469 if(child->flags & (COF_DIRTY | COF_HIDDEN)) {
466 preorder_coord_skip_subtree(child); 470 preorder_coord_skip_subtree(child);
467 continue; 471 continue;
468 } 472 }
469 473
470 make_sure_dirty_coords(rdman); 474 add_dirty_coord(rdman, child);
471 rdman->dirty_coords[rdman->n_dirty_coords++] = child;
472 child->flags |= COF_DIRTY;
473 } 475 }
474 476
475 return OK; 477 return OK;
476 } 478 }
477 479