static inline void eina_rectangle_rescale_in(const Eina_Rectangle *out, const Eina_Rectangle *in, Eina_Rectangle *res) EINA_ARG_NONNULL(1, 2, 3);
static inline void eina_rectangle_rescale_out(const Eina_Rectangle *out, const Eina_Rectangle *in, Eina_Rectangle *res) EINA_ARG_NONNULL(1, 2, 3);
+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_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;
#include "eina_counter.h"
#include "eina_benchmark.h"
#include "eina_magic.h"
+#include "eina_rectangle.h"
/*============================================================================*
* Global *
eina_counter_init();
eina_benchmark_init();
eina_magic_string_init();
+ eina_rectangle_init();
finish_init:
return ++_eina_main_count;
{
if (_eina_main_count != 1) goto finish_shutdown;
+ eina_rectangle_shutdown();
eina_magic_string_shutdown();
eina_benchmark_shutdown();
eina_counter_shutdown();
#include "eina_inlist.h"
#include "eina_private.h"
#include "eina_safety_checks.h"
+#include "eina_mempool.h"
/*============================================================================*
* Local *
EINA_MAGIC_FAIL((d), EINA_RECTANGLE_ALLOC_MAGIC); \
} while (0);
+static int _eina_rectangle_init_count = 0;
+static Eina_Mempool *_eina_rectangle_mp = NULL;
+
static inline Eina_Bool
_eina_rectangle_pool_collide(Eina_Rectangle_Alloc *head, Eina_Rectangle_Alloc *current, Eina_Rectangle *test)
{
pool->head = (EINA_INLIST_GET(del))->next;
- MAGIC_FREE(del);
+ EINA_MAGIC_SET(del, EINA_MAGIC_NONE);
+ eina_mempool_free(_eina_rectangle_mp, del);
}
MAGIC_FREE(pool);
test = _eina_rectangle_pool_find((Eina_Rectangle_Alloc*) pool->head, pool->w, pool->h, w, h, &x, &y);
if (!test) return NULL;
- new = malloc(sizeof (Eina_Rectangle_Alloc) + sizeof (Eina_Rectangle));
+ new = eina_mempool_alloc(_eina_rectangle_mp,
+ sizeof (Eina_Rectangle_Alloc) + sizeof (Eina_Rectangle));
if (!new) return NULL;
rect = (Eina_Rectangle*) (new + 1);
era->pool->references--;
era->pool->head = eina_inlist_remove(era->pool->head, EINA_INLIST_GET(era));
- MAGIC_FREE(era);
+ EINA_MAGIC_SET(era, EINA_MAGIC_NONE);
+ eina_mempool_free(_eina_rectangle_mp, era);
}
EAPI Eina_Rectangle_Pool *
return EINA_TRUE;
}
+EAPI int
+eina_rectangle_init(void)
+{
+ const char *choice;
+
+ _eina_rectangle_init_count++;
+
+ if (_eina_rectangle_init_count > 1) return _eina_rectangle_init_count;
+
+ eina_error_init();
+ eina_mempool_init();
+
+#ifdef EINA_DEFAULT_MEMPOOL
+ choice = "pass_through";
+#else
+ if (!(choice = getenv("EINA_MEMPOOL")))
+ choice = "chained_mempool";
+#endif
+
+ _eina_rectangle_mp = eina_mempool_new(choice, "rectangle", NULL,
+ sizeof (Eina_Rectangle_Alloc) + sizeof (Eina_Rectangle), 42);
+ if (!_eina_rectangle_mp)
+ {
+ EINA_ERROR_PERR("ERROR: Mempool for rectangle cannot be allocated in list init.\n");
+ abort();
+ }
+
+ return _eina_rectangle_init_count;
+}
+
+EAPI int
+eina_rectangle_shutdown(void)
+{
+ --_eina_rectangle_init_count;
+
+ if (_eina_rectangle_init_count) return _eina_rectangle_init_count;
+
+ eina_mempool_delete(_eina_rectangle_mp);
+
+ eina_mempool_shutdown();
+ eina_error_shutdown();
+
+ return 0;
+}