Mercurial > MadButterfly
changeset 867:4f8d53be9488
Allocate linear, radial, image paints from elmpools
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Thu, 23 Sep 2010 10:43:56 +0800 |
parents | 9a7ac4487849 |
children | f41ac71266bc |
files | include/mb_redraw_man.h src/paint.c src/redraw_man.c |
diffstat | 3 files changed, 41 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_redraw_man.h Thu Sep 23 10:14:05 2010 +0800 +++ b/include/mb_redraw_man.h Thu Sep 23 10:43:56 2010 +0800 @@ -55,6 +55,9 @@ elmpool_t *observer_pool; elmpool_t *subject_pool; elmpool_t *paint_color_pool; + elmpool_t *paint_linear_pool; + elmpool_t *paint_radial_pool; + elmpool_t *paint_image_pool; elmpool_t *pent_pool; elmpool_t *coord_canvas_pool;
--- a/src/paint.c Thu Sep 23 10:14:05 2010 +0800 +++ b/src/paint.c Thu Sep 23 10:43:56 2010 +0800 @@ -78,10 +78,14 @@ grad_stop_t *stops; int flags; mbe_pattern_t *ptn; + + redraw_man_t *rdman; /*!< \brief Used by paint_linear_free(). */ } paint_linear_t; #define LIF_DIRTY 0x1 +int _paint_linear_size = sizeof(paint_linear_t); + static void paint_linear_prepare(paint_t *paint, mbe_t *cr) { paint_linear_t *linear = (paint_linear_t *)paint; mbe_pattern_t *ptn; @@ -107,7 +111,7 @@ if(linear->ptn) mbe_pattern_destroy(linear->ptn); paint_destroy(paint); - free(paint); + elmpool_elm_free(linear->rdman->paint_linear_pool, linear); } paint_t *rdman_paint_linear_new(redraw_man_t *rdman, @@ -115,7 +119,7 @@ co_aix x2, co_aix y2) { paint_linear_t *linear; - linear = (paint_linear_t *)malloc(sizeof(paint_linear_t)); + linear = (paint_linear_t *)elmpool_elm_alloc(rdman->paint_linear_pool); if(linear == NULL) return NULL; @@ -130,6 +134,7 @@ linear->stops = NULL; linear->flags = LIF_DIRTY; linear->ptn = NULL; + linear->rdman = rdman; return (paint_t *)linear; } @@ -166,10 +171,14 @@ grad_stop_t *stops; int flags; mbe_pattern_t *ptn; + + redraw_man_t *rdman; /*!< \brief Used by paint_radial_free() */ } paint_radial_t; #define RDF_DIRTY 0x1 +int _paint_radial_size = sizeof(paint_radial_t); + static void paint_radial_prepare(paint_t *paint, mbe_t *cr) { paint_radial_t *radial = (paint_radial_t *)paint; mbe_pattern_t *ptn; @@ -193,14 +202,14 @@ if(radial->ptn) mbe_pattern_destroy(radial->ptn); paint_destroy(paint); - free(paint); + elmpool_elm_free(radial->rdman->paint_radial_pool, radial); } paint_t *rdman_paint_radial_new(redraw_man_t *rdman, co_aix cx, co_aix cy, co_aix r) { paint_radial_t *radial; - radial = O_ALLOC(paint_radial_t); + radial = elmpool_elm_alloc(rdman->paint_radial_pool); if(radial == NULL) return NULL; @@ -213,6 +222,7 @@ radial->stops = NULL; radial->flags = RDF_DIRTY; radial->ptn = NULL; + radial->rdman = rdman; return (paint_t *)radial; } @@ -247,8 +257,12 @@ mb_img_data_t *img; mbe_surface_t *surf; mbe_pattern_t *ptn; + + redraw_man_t *rdman; /*!< \brief Used by paint_image_free() */ } paint_image_t; +int _paint_image_size = sizeof(paint_image_t); + static void paint_image_prepare(paint_t *paint, mbe_t *cr) { paint_image_t *paint_img = (paint_image_t *)paint; @@ -267,7 +281,7 @@ img_data = paint_img->img; MB_IMG_DATA_FREE(img_data); paint_destroy(&paint_img->paint); - free(paint); + elmpool_elm_free(paint_img->rdman->paint_image_pool, paint_img); } /*! \brief Create an image painter. @@ -281,13 +295,14 @@ mb_img_data_t *img) { paint_image_t *paint; - paint = O_ALLOC(paint_image_t); + paint = elmpool_elm_alloc(rdman->paint_image_pool); if(paint == NULL) return NULL; paint_init(&paint->paint, MBP_IMAGE, paint_image_prepare, paint_image_free); paint->img = img; + paint->rdman = rdman; paint->surf = mbe_image_surface_create_for_data(img->content, img->fmt, img->w, @@ -295,7 +310,7 @@ img->stride); if(paint->surf == NULL) { paint_destroy(&paint->paint); - free(paint); + elmpool_elm_free(rdman->paint_image_pool, paint); return NULL; } @@ -303,7 +318,7 @@ if(paint->ptn == NULL) { paint_destroy(&paint->paint); mbe_surface_destroy(paint->surf); - free(paint); + elmpool_elm_free(rdman->paint_image_pool, paint); return NULL; }
--- a/src/redraw_man.c Thu Sep 23 10:14:05 2010 +0800 +++ b/src/redraw_man.c Thu Sep 23 10:43:56 2010 +0800 @@ -642,6 +642,9 @@ extern int _sh_path_size; extern int _sh_rect_size; extern int _paint_color_size; + extern int _paint_linear_size; + extern int _paint_radial_size; + extern int _paint_image_size; observer_t *addrm_ob; extern void addrm_monitor_hdlr(event_t *evt, void *arg); @@ -660,6 +663,9 @@ rdman->observer_pool = elmpool_new(sizeof(observer_t), 32); rdman->subject_pool = elmpool_new(sizeof(subject_t), 32); rdman->paint_color_pool = elmpool_new(_paint_color_size, 64); + rdman->paint_linear_pool = elmpool_new(_paint_linear_size, 64); + rdman->paint_radial_pool = elmpool_new(_paint_radial_size, 64); + rdman->paint_image_pool = elmpool_new(_paint_image_size, 64); rdman->pent_pool = elmpool_new(sizeof(mb_prop_entry_t), 128); rdman->coord_canvas_pool = elmpool_new(sizeof(coord_canvas_info_t), 16); if(!(rdman->geo_pool && rdman->coord_pool && rdman->shnode_pool && @@ -734,6 +740,12 @@ elmpool_free(rdman->subject_pool); if(rdman->paint_color_pool) elmpool_free(rdman->paint_color_pool); + if(rdman->paint_linear_pool) + elmpool_free(rdman->paint_linear_pool); + if(rdman->paint_radial_pool) + elmpool_free(rdman->paint_radial_pool); + if(rdman->paint_image_pool) + elmpool_free(rdman->paint_image_pool); if(rdman->pent_pool) elmpool_free(rdman->pent_pool); if(rdman->coord_canvas_pool) @@ -792,6 +804,9 @@ elmpool_free(rdman->observer_pool); elmpool_free(rdman->subject_pool); elmpool_free(rdman->paint_color_pool); + elmpool_free(rdman->paint_linear_pool); + elmpool_free(rdman->paint_radial_pool); + elmpool_free(rdman->paint_image_pool); elmpool_free(rdman->pent_pool); elmpool_free(rdman->coord_canvas_pool);