From d4411bee6322735b9bcac5e6ef12a9c727ce043f Mon Sep 17 00:00:00 2001 From: cedric Date: Mon, 22 Jun 2009 13:16:51 +0000 Subject: [PATCH] * eina: Fix API naming for eina_rectangle and add a global allocator. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@41155 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/include/eina_rectangle.h | 13 +++++++++++-- src/lib/eina_rectangle.c | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/include/eina_rectangle.h b/src/include/eina_rectangle.h index e2eb58c..e83f901 100644 --- a/src/include/eina_rectangle.h +++ b/src/include/eina_rectangle.h @@ -55,16 +55,25 @@ static inline void eina_rectangle_rescale_out(const Eina_Rectangle *out, const E EAPI int eina_rectangle_init(void); EAPI int eina_rectangle_shutdown(void); -EAPI Eina_Rectangle_Pool *eina_rectangle_pool_add(int w, int h) EINA_MALLOC EINA_WARN_UNUSED_RESULT; +EAPI Eina_Rectangle_Pool *eina_rectangle_pool_new(int w, int h) EINA_MALLOC EINA_WARN_UNUSED_RESULT; EAPI Eina_Rectangle_Pool *eina_rectangle_pool_get(Eina_Rectangle *rect) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); EAPI Eina_Bool eina_rectangle_pool_geometry_get(Eina_Rectangle_Pool *pool, int *w, int *h) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; EAPI void *eina_rectangle_pool_data_get(Eina_Rectangle_Pool *pool) EINA_PURE EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); EAPI void eina_rectangle_pool_data_set(Eina_Rectangle_Pool *pool, const void *data) EINA_ARG_NONNULL(1); -EAPI void eina_rectangle_pool_delete(Eina_Rectangle_Pool *pool) EINA_ARG_NONNULL(1); +EAPI void eina_rectangle_pool_free(Eina_Rectangle_Pool *pool) EINA_ARG_NONNULL(1); EAPI int eina_rectangle_pool_count(Eina_Rectangle_Pool *pool) EINA_PURE EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; EAPI Eina_Rectangle *eina_rectangle_pool_request(Eina_Rectangle_Pool *pool, int w, int h) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); EAPI void eina_rectangle_pool_release(Eina_Rectangle *rect) EINA_ARG_NONNULL(1); +#define EINA_RECTANGLE_SET(Rectangle, X, Y, W, H) \ + Rectangle->x = X; \ + Rectangle->y = Y; \ + Rectangle->w = W; \ + Rectangle->h = H; + +EAPI Eina_Rectangle *eina_rectangle_new(int x, int y, int w, int h); +EAPI void eina_rectangle_free(Eina_Rectangle *rect); + #include "eina_inline_rectangle.x" /** @} */ diff --git a/src/lib/eina_rectangle.c b/src/lib/eina_rectangle.c index d09474a..80d07cf 100644 --- a/src/lib/eina_rectangle.c +++ b/src/lib/eina_rectangle.c @@ -30,6 +30,7 @@ #include "eina_private.h" #include "eina_safety_checks.h" #include "eina_mempool.h" +#include "eina_list.h" /*============================================================================* * Local * @@ -47,6 +48,7 @@ typedef struct _Eina_Rectangle_Alloc Eina_Rectangle_Alloc; struct _Eina_Rectangle_Pool { Eina_Inlist *head; + Eina_List *empty; void *data; unsigned int references; @@ -75,6 +77,7 @@ struct _Eina_Rectangle_Alloc } while (0); static int _eina_rectangle_init_count = 0; +static Eina_Mempool *_eina_rectangle_alloc_mp = NULL; static Eina_Mempool *_eina_rectangle_mp = NULL; static inline Eina_Bool @@ -207,8 +210,28 @@ _eina_rectangle_pool_find(Eina_Rectangle_Alloc *head, int poolw, int poolh, int * API * *============================================================================*/ +EAPI Eina_Rectangle * +eina_rectangle_new(int x, int y, int w, int h) +{ + Eina_Rectangle *rect; + + rect = eina_mempool_alloc(_eina_rectangle_mp, sizeof (Eina_Rectangle)); + if (!rect) return NULL; + + EINA_RECTANGLE_SET(rect, x, y, w, h); + + return rect; +} + +EAPI void +eina_rectangle_free(Eina_Rectangle *rect) +{ + EINA_SAFETY_ON_NULL_RETURN(rect); + eina_mempool_free(_eina_rectangle_mp, rect); +} + EAPI Eina_Rectangle_Pool * -eina_rectangle_pool_add(int w, int h) +eina_rectangle_pool_new(int w, int h) { Eina_Rectangle_Pool *new; @@ -216,6 +239,7 @@ eina_rectangle_pool_add(int w, int h) if (!new) return NULL; new->head = NULL; + new->empty = eina_list_append(NULL, eina_rectangle_add(0, 0, w, h)); new->references = 0; new->w = w; new->h = h; @@ -226,7 +250,7 @@ eina_rectangle_pool_add(int w, int h) } EAPI void -eina_rectangle_pool_delete(Eina_Rectangle_Pool *pool) +eina_rectangle_pool_free(Eina_Rectangle_Pool *pool) { Eina_Rectangle_Alloc *del; @@ -238,7 +262,7 @@ eina_rectangle_pool_delete(Eina_Rectangle_Pool *pool) pool->head = (EINA_INLIST_GET(del))->next; EINA_MAGIC_SET(del, EINA_MAGIC_NONE); - eina_mempool_free(_eina_rectangle_mp, del); + eina_mempool_free(_eina_rectangle_alloc_mp, del); } MAGIC_FREE(pool); @@ -267,7 +291,7 @@ eina_rectangle_pool_request(Eina_Rectangle_Pool *pool, int w, int h) test = _eina_rectangle_pool_find((Eina_Rectangle_Alloc*) pool->head, pool->w, pool->h, w, h, &x, &y); if (!test) return NULL; - new = eina_mempool_alloc(_eina_rectangle_mp, + new = eina_mempool_alloc(_eina_rectangle_alloc_mp, sizeof (Eina_Rectangle_Alloc) + sizeof (Eina_Rectangle)); if (!new) return NULL; @@ -298,7 +322,7 @@ eina_rectangle_pool_release(Eina_Rectangle *rect) era->pool->head = eina_inlist_remove(era->pool->head, EINA_INLIST_GET(era)); EINA_MAGIC_SET(era, EINA_MAGIC_NONE); - eina_mempool_free(_eina_rectangle_mp, era); + eina_mempool_free(_eina_rectangle_alloc_mp, era); } EAPI Eina_Rectangle_Pool * @@ -373,8 +397,15 @@ eina_rectangle_init(void) choice = "chained_mempool"; #endif - _eina_rectangle_mp = eina_mempool_new(choice, "rectangle", NULL, + _eina_rectangle_alloc_mp = eina_mempool_new(choice, "rectangle-alloc", NULL, sizeof (Eina_Rectangle_Alloc) + sizeof (Eina_Rectangle), 42); + if (!_eina_rectangle_alloc_mp) + { + EINA_ERROR_PERR("ERROR: Mempool for rectangle cannot be allocated in list init.\n"); + goto init_error; + } + + _eina_rectangle_mp = eina_mempool_new(choice, "rectangle", NULL, sizeof (Eina_Rectangle), 42); if (!_eina_rectangle_mp) { EINA_ERROR_PERR("ERROR: Mempool for rectangle cannot be allocated in list init.\n"); @@ -398,6 +429,7 @@ eina_rectangle_shutdown(void) if (_eina_rectangle_init_count) return _eina_rectangle_init_count; + eina_mempool_delete(_eina_rectangle_alloc_mp); eina_mempool_delete(_eina_rectangle_mp); eina_mempool_shutdown(); -- 2.7.4