From: Enlightenment S. <no-...@en...> - 2008-10-27 20:24:21
|
Log: Add Eina_Rectangle_Pool support. Typically help for font handling in OpenGL or any case where you need to split a rectangle in many differents small rectangle. Author: cedric Date: 2008-10-27 13:24:12 -0700 (Mon, 27 Oct 2008) New Revision: 37252 Added: trunk/eina/src/include/eina_inline_rectangle.x trunk/eina/src/lib/eina_rectangle.c trunk/eina/src/tests/eina_test_rectangle.c Modified: trunk/eina/src/include/Makefile.am trunk/eina/src/include/eina_rectangle.h trunk/eina/src/lib/Makefile.am trunk/eina/src/lib/eina_main.c trunk/eina/src/tests/Makefile.am trunk/eina/src/tests/eina_suite.c trunk/eina/src/tests/eina_suite.h trunk/eina/src/tests/eina_test_main.c Modified: trunk/eina/src/include/Makefile.am =================================================================== --- trunk/eina/src/include/Makefile.am 2008-10-27 20:16:52 UTC (rev 37251) +++ trunk/eina/src/include/Makefile.am 2008-10-27 20:24:12 UTC (rev 37252) @@ -25,6 +25,7 @@ eina_benchmark.h \ eina_inline_rbtree.x \ eina_inline_mempool.x \ +eina_inline_rectangle.x \ eina_iterator.h installed_mainheaderdir = $(prefix)/include/eina-@VMAJ@ Added: trunk/eina/src/include/eina_inline_rectangle.x Modified: trunk/eina/src/include/eina_rectangle.h =================================================================== --- trunk/eina/src/include/eina_rectangle.h 2008-10-27 20:16:52 UTC (rev 37251) +++ trunk/eina/src/include/eina_rectangle.h 2008-10-27 20:24:12 UTC (rev 37252) @@ -24,6 +24,8 @@ * @{ */ +#include "eina_types.h" + /** * To be documented * FIXME: To be fixed @@ -36,161 +38,28 @@ int h; } Eina_Rectangle; -/** - * To be documented - * FIXME: To be fixed - * Is it needed?? - */ -static inline int -eina_spans_intersect(int c1, int l1, int c2, int l2) -{ - return (!(((c2 + l2) <= c1) || (c2 >= (c1 + l1)))); -} -/** - * To be documented - * FIXME: To be fixed - */ -static inline Eina_Bool -eina_rectangle_is_empty(Eina_Rectangle *r) -{ - return ((r->w < 1) || (r->h < 1)) ? EINA_TRUE : EINA_FALSE; -} +typedef struct _Eina_Rectangle_Pool Eina_Rectangle_Pool; -/** - * To be documented - * FIXME: To be fixed - */ -static inline void -eina_rectangle_coords_from(Eina_Rectangle *r, int x, int y, int w, int h) -{ - r->x = x; - r->y = y; - r->w = w; - r->h = h; -} +static inline int eina_spans_intersect(int c1, int l1, int c2, int l2); +static inline Eina_Bool eina_rectangle_is_empty(Eina_Rectangle *r); +static inline void eina_rectangle_coords_from(Eina_Rectangle *r, int x, int y, int w, int h); +static inline Eina_Bool eina_rectangles_intersect(Eina_Rectangle *r1, Eina_Rectangle *r2); +static inline Eina_Bool eina_rectangle_xcoord_inside(Eina_Rectangle *r, int x); +static inline Eina_Bool eina_rectangle_ycoord_inside(Eina_Rectangle *r, int y); +static inline Eina_Bool eina_rectangle_coords_inside(Eina_Rectangle *r, int x, int y); +static inline void eina_rectangle_union(Eina_Rectangle *dst, Eina_Rectangle *src); +static inline Eina_Bool eina_rectangle_intersection(Eina_Rectangle *dst, Eina_Rectangle *src); +static inline void eina_rectangle_rescale_in(Eina_Rectangle *out, Eina_Rectangle *in, Eina_Rectangle *res); +static inline void eina_rectangle_rescale_out(Eina_Rectangle *out, Eina_Rectangle *in, Eina_Rectangle *res); -/** - * To be documented - * FIXME: To be fixed - */ -static inline Eina_Bool -eina_rectangles_intersect(Eina_Rectangle *r1, Eina_Rectangle *r2) -{ - return (eina_spans_intersect(r1->x, r1->w, r2->x, r2->w) && eina_spans_intersect(r1->y, r1->h, r2->y, r2->h)) ? EINA_TRUE : EINA_FALSE; -} -/** - * To be documented - * FIXME: To be fixed - */ -static inline Eina_Bool -eina_rectangle_xcoord_inside(Eina_Rectangle *r, int x) -{ - return ((x >= r->x) && (x < (r->x + r->w))) ? EINA_TRUE : EINA_FALSE; -} -/** - * To be documented - * FIXME: To be fixed - */ -static inline Eina_Bool -eina_rectangle_ycoord_inside(Eina_Rectangle *r, int y) -{ - return ((y >= r->y) && (y < (r->y + r->h))) ? EINA_TRUE : EINA_FALSE; -} -/** - * To be documented - * FIXME: To be fixed - */ -static inline Eina_Bool -eina_rectangle_coords_inside(Eina_Rectangle *r, int x, int y) -{ - return (eina_rectangle_xcoord_inside(r, x) && eina_rectangle_ycoord_inside(r, y)) ? EINA_TRUE : EINA_FALSE; -} -/** - * To be documented - * FIXME: To be fixed - */ -static inline void -eina_rectangle_union(Eina_Rectangle *dst, Eina_Rectangle *src) -{ - /* left */ - if (dst->x > src->x) - { - dst->w += dst->x - src->x; - dst->x = src->x; - } - /* right */ - if ((dst->x + dst->w) < (src->x + src->w)) - dst->w = src->x + src->w; - /* top */ - if (dst->y > src->y) - { - dst->h += dst->y - src->y; - dst->y = src->y; - } - /* bottom */ - if ((dst->y + dst->h) < (src->y + src->h)) - dst->h = src->y + src->h; -} -/** - * To be documented - * FIXME: To be fixed - */ -static inline Eina_Bool -eina_rectangle_intersection(Eina_Rectangle *dst, Eina_Rectangle *src) -{ - if (!(eina_rectangles_intersect(dst, src))) - return EINA_FALSE; +EAPI Eina_Rectangle_Pool *eina_rectangle_pool_add(int w, int h); +EAPI void eina_rectangle_pool_delete(Eina_Rectangle_Pool *pool); +EAPI int eina_rectangle_pool_count(Eina_Rectangle_Pool *pool); +EAPI Eina_Rectangle *eina_rectangle_pool_request(Eina_Rectangle_Pool *pool, int w, int h); +EAPI void eina_rectangle_pool_release(Eina_Rectangle *rect); - /* left */ - if (dst->x < src->x) - { - dst->w += dst->x - src->x; - dst->x = src->x; - if (dst->w < 0) - dst->w = 0; - } - /* right */ - if ((dst->x + dst->w) > (src->x + src->w)) - dst->w = src->x + src->w - dst->x; - /* top */ - if (dst->y < src->y) - { - dst->h += dst->y - src->y; - dst->y = src->y; - if (dst->h < 0) - dst->h = 0; - } - /* bottom */ - if ((dst->y + dst->h) > (src->y + src->h)) - dst->h = src->y + src->h - dst->y; +#include "eina_inline_rectangle.x" - return EINA_TRUE; -} - -/** - * Rescale the coordinates from @in as if it where relative to @out - */ -static inline void -eina_rectangle_rescale_in(Eina_Rectangle *out, Eina_Rectangle *in, Eina_Rectangle *res) -{ - res->x = in->x - out->x; - res->y = in->y - out->y; - res->w = in->w; - res->h = in->h; -} -/** - * To be documented - * FIXME: To be fixed - */ -static inline void -eina_rectangle_rescale_out(Eina_Rectangle *out, Eina_Rectangle *in, Eina_Rectangle *res) -{ - res->x = out->x + in->x; - res->y = out->y + in->y; - res->w = out->w; - res->h = out->h; -} - /** @} */ -#endif /*_ENESIM_RECTANGLE_H_*/ +#endif /*_EINA_RECTANGLE_H_*/ Modified: trunk/eina/src/lib/Makefile.am =================================================================== --- trunk/eina/src/lib/Makefile.am 2008-10-27 20:16:52 UTC (rev 37251) +++ trunk/eina/src/lib/Makefile.am 2008-10-27 20:24:12 UTC (rev 37252) @@ -29,6 +29,7 @@ eina_convert.c \ eina_rbtree.c \ eina_benchmark.c \ +eina_rectangle.c \ eina_stringshare.c if EINA_STATIC_BUILD_CHAINED_POOL Modified: trunk/eina/src/lib/eina_main.c =================================================================== --- trunk/eina/src/lib/eina_main.c 2008-10-27 20:16:52 UTC (rev 37251) +++ trunk/eina/src/lib/eina_main.c 2008-10-27 20:24:12 UTC (rev 37252) @@ -30,12 +30,14 @@ * API * *============================================================================*/ +static int _eina_main_count = 0; + EAPI int eina_init(void) { - int r; + if (_eina_main_count) goto finish_init; - r = eina_error_init(); + eina_error_init(); eina_hash_init(); eina_stringshare_init(); eina_list_init(); @@ -44,13 +46,14 @@ eina_benchmark_init(); eina_magic_string_init(); - return r; + finish_init: + return ++_eina_main_count; } EAPI int eina_shutdown(void) { - int r; + if (_eina_main_count != 1) goto finish_shutdown; eina_magic_string_shutdown(); eina_benchmark_shutdown(); @@ -59,8 +62,9 @@ eina_list_shutdown(); eina_stringshare_shutdown(); eina_hash_shutdown(); - r = eina_error_shutdown(); + eina_error_shutdown(); - return r; + finish_shutdown: + return --_eina_main_count; } Added: trunk/eina/src/lib/eina_rectangle.c Modified: trunk/eina/src/tests/Makefile.am =================================================================== --- trunk/eina/src/tests/Makefile.am 2008-10-27 20:16:52 UTC (rev 37251) +++ trunk/eina/src/tests/Makefile.am 2008-10-27 20:24:12 UTC (rev 37252) @@ -63,6 +63,7 @@ eina_test_file.c \ eina_test_benchmark.c \ eina_test_mempool.c \ +eina_test_rectangle.c \ eina_test_list.c eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la Modified: trunk/eina/src/tests/eina_suite.c =================================================================== --- trunk/eina/src/tests/eina_suite.c 2008-10-27 20:16:52 UTC (rev 37251) +++ trunk/eina/src/tests/eina_suite.c 2008-10-27 20:24:12 UTC (rev 37252) @@ -45,6 +45,7 @@ { "File", eina_test_file }, { "Benchmark", eina_test_benchmark }, { "Mempool", eina_test_mempool }, + { "Rectangle", eina_test_rectangle }, { NULL, NULL } }; Modified: trunk/eina/src/tests/eina_suite.h =================================================================== --- trunk/eina/src/tests/eina_suite.h 2008-10-27 20:16:52 UTC (rev 37251) +++ trunk/eina/src/tests/eina_suite.h 2008-10-27 20:24:12 UTC (rev 37252) @@ -43,5 +43,6 @@ void eina_test_file(TCase *tc); void eina_test_benchmark(TCase *tc); void eina_test_mempool(TCase *tc); +void eina_test_rectangle(TCase *tc); #endif /* EINA_SUITE_H_ */ Modified: trunk/eina/src/tests/eina_test_main.c =================================================================== --- trunk/eina/src/tests/eina_test_main.c 2008-10-27 20:16:52 UTC (rev 37251) +++ trunk/eina/src/tests/eina_test_main.c 2008-10-27 20:24:12 UTC (rev 37252) @@ -27,10 +27,8 @@ START_TEST(eina_simple) { - /* Eina_error as already been initialized by eina_hash - that was called by eina_mempool_init that's why we don't have 0 here */ - fail_if(eina_init() != 2); - fail_if(eina_shutdown() != 1); + fail_if(eina_init() != 1); + fail_if(eina_shutdown() != 0); } END_TEST Added: trunk/eina/src/tests/eina_test_rectangle.c |