summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2008-04-12 00:32:30 +0000
committerCarsten Haitzler <raster@rasterman.com>2008-04-12 00:32:30 +0000
commitae1977a214c227695564909094cf8e6184704d0a (patch)
treec9a02bc1a359c504bb6fb54837e5b069e9bf70f4 /legacy
parentc290fa032dd5b431f1c5b816cdf4f35525f21dec (diff)
cedric's cache changes patch
SVN revision: 34253
Diffstat (limited to '')
-rw-r--r--legacy/evas/configure.in41
-rw-r--r--legacy/evas/src/lib/Makefile.am4
-rw-r--r--legacy/evas/src/lib/cache/evas_cache_engine_image.c609
-rw-r--r--legacy/evas/src/lib/cache/evas_cache_image.c721
-rw-r--r--legacy/evas/src/lib/canvas/evas_object_image.c23
-rw-r--r--legacy/evas/src/lib/engines/Makefile.am2
-rw-r--r--legacy/evas/src/lib/engines/common/evas_blit_main.c22
-rw-r--r--legacy/evas/src/lib/engines/common/evas_font_draw.c6
-rw-r--r--legacy/evas/src/lib/engines/common/evas_gradient_main.c18
-rw-r--r--legacy/evas/src/lib/engines/common/evas_image_data.c73
-rw-r--r--legacy/evas/src/lib/engines/common/evas_image_load.c56
-rw-r--r--legacy/evas/src/lib/engines/common/evas_image_main.c342
-rw-r--r--legacy/evas/src/lib/engines/common/evas_line_main.c26
-rw-r--r--legacy/evas/src/lib/engines/common/evas_pipe.c12
-rw-r--r--legacy/evas/src/lib/engines/common/evas_polygon_main.c6
-rw-r--r--legacy/evas/src/lib/engines/common/evas_rectangle_main.c8
-rw-r--r--legacy/evas/src/lib/engines/common/evas_scale_sample.c20
-rw-r--r--legacy/evas/src/lib/engines/common/evas_scale_smooth.c4
-rw-r--r--legacy/evas/src/lib/engines/common/evas_scale_smooth_scaler.c14
-rw-r--r--legacy/evas/src/lib/engines/common/evas_scale_smooth_scaler_down.c2
-rw-r--r--legacy/evas/src/lib/engines/common/evas_scale_smooth_scaler_noscale.c2
-rw-r--r--legacy/evas/src/lib/engines/common/evas_scale_smooth_scaler_up.c10
-rw-r--r--legacy/evas/src/lib/imaging/evas_imaging.c8
-rw-r--r--legacy/evas/src/lib/include/Makefile.am1
-rw-r--r--legacy/evas/src/lib/include/evas_common.h322
-rw-r--r--legacy/evas/src/modules/engines/Makefile.am4
-rw-r--r--legacy/evas/src/modules/engines/buffer/evas_engine.h16
-rw-r--r--legacy/evas/src/modules/engines/buffer/evas_outbuf.c60
-rw-r--r--legacy/evas/src/modules/engines/direct3d/evas_outbuf.c6
-rw-r--r--legacy/evas/src/modules/engines/fb/evas_outbuf.c22
-rw-r--r--legacy/evas/src/modules/engines/gl_common/evas_gl_common.h6
-rw-r--r--legacy/evas/src/modules/engines/gl_common/evas_gl_gradient.c14
-rw-r--r--legacy/evas/src/modules/engines/gl_common/evas_gl_image.c82
-rw-r--r--legacy/evas/src/modules/engines/gl_common/evas_gl_texture.c75
-rw-r--r--legacy/evas/src/modules/engines/gl_glew/evas_engine.c17
-rw-r--r--legacy/evas/src/modules/engines/gl_x11/evas_engine.c55
-rw-r--r--legacy/evas/src/modules/engines/gl_x11/evas_x_main.c4
-rw-r--r--legacy/evas/src/modules/engines/software_16/Makefile.am27
-rw-r--r--legacy/evas/src/modules/engines/software_16/evas_engine.c75
-rw-r--r--legacy/evas/src/modules/engines/software_16_ddraw/evas_engine.c4
-rw-r--r--legacy/evas/src/modules/engines/software_16_ddraw/evas_engine.h2
-rw-r--r--legacy/evas/src/modules/engines/software_16_x11/evas_engine.c46
-rw-r--r--legacy/evas/src/modules/engines/software_16_x11/evas_engine.h4
-rw-r--r--legacy/evas/src/modules/engines/software_16_x11/evas_x_buffer.c19
-rw-r--r--legacy/evas/src/modules/engines/software_ddraw/evas_outbuf.c17
-rw-r--r--legacy/evas/src/modules/engines/software_generic/evas_engine.c73
-rw-r--r--legacy/evas/src/modules/engines/software_sdl/Evas_Engine_SDL.h10
-rw-r--r--legacy/evas/src/modules/engines/software_sdl/evas_engine.c647
-rw-r--r--legacy/evas/src/modules/engines/software_sdl/evas_engine.h51
-rw-r--r--legacy/evas/src/modules/engines/software_x11/evas_outbuf.c96
-rw-r--r--legacy/evas/src/modules/engines/software_xcb/evas_outbuf.c28
-rw-r--r--legacy/evas/src/modules/engines/xrender_x11/evas_engine.c67
-rw-r--r--legacy/evas/src/modules/engines/xrender_x11/evas_engine_font.c4
-rw-r--r--legacy/evas/src/modules/engines/xrender_x11/evas_engine_gradient.c30
-rw-r--r--legacy/evas/src/modules/engines/xrender_x11/evas_engine_image.c30
-rw-r--r--legacy/evas/src/modules/engines/xrender_xcb/evas_engine.c48
-rw-r--r--legacy/evas/src/modules/engines/xrender_xcb/evas_engine_font.c2
-rw-r--r--legacy/evas/src/modules/engines/xrender_xcb/evas_engine_gradient.c9
-rw-r--r--legacy/evas/src/modules/engines/xrender_xcb/evas_engine_image.c43
-rw-r--r--legacy/evas/src/modules/loaders/edb/evas_image_load_edb.c36
-rw-r--r--legacy/evas/src/modules/loaders/eet/evas_image_load_eet.c31
-rw-r--r--legacy/evas/src/modules/loaders/gif/evas_image_load_gif.c28
-rw-r--r--legacy/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c74
-rw-r--r--legacy/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c27
-rw-r--r--legacy/evas/src/modules/loaders/png/evas_image_load_png.c38
-rw-r--r--legacy/evas/src/modules/loaders/svg/evas_image_load_svg.c99
-rw-r--r--legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c42
-rw-r--r--legacy/evas/src/modules/loaders/xpm/evas_image_load_xpm.c30
-rw-r--r--legacy/evas/src/modules/savers/eet/evas_image_save_eet.c6
-rw-r--r--legacy/evas/src/modules/savers/jpeg/evas_image_save_jpeg.c12
-rw-r--r--legacy/evas/src/modules/savers/png/evas_image_save_png.c22
-rw-r--r--legacy/evas/src/modules/savers/tiff/evas_image_save_tiff.c14
72 files changed, 2357 insertions, 2147 deletions
diff --git a/legacy/evas/configure.in b/legacy/evas/configure.in
index 769d7c35f8..93dc58d120 100644
--- a/legacy/evas/configure.in
+++ b/legacy/evas/configure.in
@@ -335,14 +335,6 @@ if test "x$want_evas_software_16_x11" = "xyes"; then
335fi 335fi
336AM_CONDITIONAL(BUILD_ENGINE_SOFTWARE_16_X11, test "x$have_evas_software_16_x11" = "xyes") 336AM_CONDITIONAL(BUILD_ENGINE_SOFTWARE_16_X11, test "x$have_evas_software_16_x11" = "xyes")
337 337
338### if software 16 x11 is enabled - build software_16 (the generic 16bit
339### engine). later enable it fb_16 or other "16" bit engines are enabled.
340have_evas_software_16="no"
341if test "x$have_evas_software_16_x11" = "xyes" -o "x$have_evas_software_16_ddraw" = "xyes"; then
342 have_evas_software_16="yes"
343fi
344AM_CONDITIONAL(BUILD_ENGINE_SOFTWARE_16, test "x$have_evas_software_16" = "xyes")
345
346####################################### 338#######################################
347## Check if we should build the software_xcb engine 339## Check if we should build the software_xcb engine
348want_evas_software_xcb="no"; 340want_evas_software_xcb="no";
@@ -428,6 +420,19 @@ if test "x$want_evas_sdl" = "xyes"; then
428fi 420fi
429AM_CONDITIONAL(BUILD_ENGINE_SDL, test "x$have_evas_sdl" = "xyes") 421AM_CONDITIONAL(BUILD_ENGINE_SDL, test "x$have_evas_sdl" = "xyes")
430 422
423## Check if we want to use some SDL primitive
424sdl_primitive="no";
425
426AC_ARG_ENABLE(sdl-primitive,
427 AC_HELP_STRING([--enable-sdl-primitive], []),
428 [ sdl_primitive=$enableval ]
429)
430AC_MSG_RESULT($sdl_primitive)
431
432if test "x$sdl_primitive" = "xyes"; then
433 AC_DEFINE(ENGINE_SDL_PRIMITIVE, 1, [Use SDL primitive when possible])
434fi
435
431####################################### 436#######################################
432## Check if we should build the fb engine 437## Check if we should build the fb engine
433want_evas_fb="no"; 438want_evas_fb="no";
@@ -1518,6 +1523,20 @@ if test x$want_valgrind = "xyes"; then
1518 ) 1523 )
1519fi 1524fi
1520 1525
1526### if software 16 x11 is enabled - build software_16 (the generic 16bit
1527### engine). later enable it fb_16 or other "16" bit engines are enabled.
1528have_evas_software_16="no"
1529if test "x$have_evas_software_16_x11" = "xyes"; then
1530 have_evas_software_16="yes"
1531fi
1532if test "x$have_evas_sdl" = "xyes"; then
1533 have_evas_software_16="yes"
1534fi
1535if test "x$have_evas_software_16_ddraw" = "xyes"; then
1536 have_evas_software_16="yes"
1537fi
1538AM_CONDITIONAL(BUILD_ENGINE_SOFTWARE_16, test "x$have_evas_software_16" = "xyes")
1539
1521##################################################################### 1540#####################################################################
1522## Fill in flags 1541## Fill in flags
1523 1542
@@ -1591,6 +1610,7 @@ src/lib/engines/common/evas_op_copy/Makefile
1591src/lib/engines/common/evas_op_mask/Makefile 1610src/lib/engines/common/evas_op_mask/Makefile
1592src/lib/engines/common/evas_op_mul/Makefile 1611src/lib/engines/common/evas_op_mul/Makefile
1593src/lib/engines/common/evas_op_sub/Makefile 1612src/lib/engines/common/evas_op_sub/Makefile
1613src/lib/engines/common_16/Makefile
1594src/modules/Makefile 1614src/modules/Makefile
1595src/modules/engines/Makefile 1615src/modules/engines/Makefile
1596src/modules/engines/software_generic/Makefile 1616src/modules/engines/software_generic/Makefile
@@ -1615,6 +1635,7 @@ src/modules/engines/glitz_x11/Makefile
1615src/modules/engines/software_16/Makefile 1635src/modules/engines/software_16/Makefile
1616src/modules/engines/software_16_x11/Makefile 1636src/modules/engines/software_16_x11/Makefile
1617src/modules/engines/software_16_ddraw/Makefile 1637src/modules/engines/software_16_ddraw/Makefile
1638src/modules/engines/software_16_sdl/Makefile
1618src/modules/loaders/Makefile 1639src/modules/loaders/Makefile
1619src/modules/loaders/edb/Makefile 1640src/modules/loaders/edb/Makefile
1620src/modules/loaders/eet/Makefile 1641src/modules/loaders/eet/Makefile
@@ -1657,15 +1678,17 @@ echo " Software Framebuffer.......: $have_evas_fb"
1657echo " Software Qtopia............: $have_evas_qtopia" 1678echo " Software Qtopia............: $have_evas_qtopia"
1658echo " Software Memory Buffer.....: $have_evas_buffer" 1679echo " Software Memory Buffer.....: $have_evas_buffer"
1659echo " DirectFB...................: $have_evas_directfb" 1680echo " DirectFB...................: $have_evas_directfb"
1660echo " Software SDL...............: $have_evas_sdl" 1681echo " Software SDL...............: $have_evas_sdl (primitive: $sdl_primitive)"
1661echo " OpenGL Glew................: $have_evas_gl_glew" 1682echo " OpenGL Glew................: $have_evas_gl_glew"
1662echo " OpenGL X11.................: $have_evas_gl_x11" 1683echo " OpenGL X11.................: $have_evas_gl_x11"
1663echo " Cairo X11..................: $have_evas_cairo_x11" 1684echo " Cairo X11..................: $have_evas_cairo_x11"
1664echo " XRender X11................: $have_evas_xrender_x11" 1685echo " XRender X11................: $have_evas_xrender_x11"
1665echo " XRender XCB................: $have_evas_xrender_xcb" 1686echo " XRender XCB................: $have_evas_xrender_xcb"
1666echo " Glitz X11..................: $have_evas_glitz_x11" 1687echo " Glitz X11..................: $have_evas_glitz_x11"
1688echo " Software 16bit ............: $have_evas_software_16"
1667echo " Software 16bit X11.........: $have_evas_software_16_x11" 1689echo " Software 16bit X11.........: $have_evas_software_16_x11"
1668echo " Software 16bit Directdraw..: $have_evas_software_16_ddraw" 1690echo " Software 16bit Directdraw..: $have_evas_software_16_ddraw"
1691echo " Software 16bit SDL.........: $have_evas_sdl (primitive: $sdl_primitive)"
1669# FIXME: opengl engine needs to be fixed and tested lots for all drivers 1692# FIXME: opengl engine needs to be fixed and tested lots for all drivers
1670# FIXME: xrender engine to be written 1693# FIXME: xrender engine to be written
1671echo 1694echo
diff --git a/legacy/evas/src/lib/Makefile.am b/legacy/evas/src/lib/Makefile.am
index 810da76d9a..ed6dd8cd1e 100644
--- a/legacy/evas/src/lib/Makefile.am
+++ b/legacy/evas/src/lib/Makefile.am
@@ -30,6 +30,7 @@ libevas_la_LIBADD = \
30 cache/libevas_cache.la \ 30 cache/libevas_cache.la \
31 imaging/libevas_imaging.la \ 31 imaging/libevas_imaging.la \
32 engines/common/libevas_engine_common.la \ 32 engines/common/libevas_engine_common.la \
33 engines/common_16/libevas_engine_common_16.la \
33 -lm \ 34 -lm \
34 @fnmatch_libs@ \ 35 @fnmatch_libs@ \
35 @dlopen_libs@ \ 36 @dlopen_libs@ \
@@ -45,7 +46,8 @@ libevas_la_DEPENDENCIES = \
45 file/libevas_file.la \ 46 file/libevas_file.la \
46 cache/libevas_cache.la \ 47 cache/libevas_cache.la \
47 imaging/libevas_imaging.la \ 48 imaging/libevas_imaging.la \
48 engines/common/libevas_engine_common.la 49 engines/common/libevas_engine_common.la \
50 engines/common_16/libevas_engine_common_16.la
49 51
50libevas_la_LDFLAGS = @create_shared_lib@ -version-info @version_info@ 52libevas_la_LDFLAGS = @create_shared_lib@ -version-info @version_info@
51 53
diff --git a/legacy/evas/src/lib/cache/evas_cache_engine_image.c b/legacy/evas/src/lib/cache/evas_cache_engine_image.c
index 1524011077..d5a88973cd 100644
--- a/legacy/evas/src/lib/cache/evas_cache_engine_image.c
+++ b/legacy/evas/src/lib/cache/evas_cache_engine_image.c
@@ -3,6 +3,144 @@
3#include "evas_common.h" 3#include "evas_common.h"
4#include "evas_private.h" 4#include "evas_private.h"
5 5
6static void
7_evas_cache_engine_image_make_dirty(Evas_Cache_Engine_Image *cache,
8 Engine_Image_Entry *eim)
9{
10 eim->flags.cached = 1;
11 eim->flags.dirty = 1;
12 eim->flags.loaded = 1;
13 eim->flags.activ = 0;
14 cache->dirty = evas_object_list_prepend(cache->dirty, eim);
15}
16
17static void
18_evas_cache_engine_image_make_active(Evas_Cache_Engine_Image *cache,
19 Engine_Image_Entry *eim,
20 const char *key)
21{
22 eim->flags.cached = 1;
23 eim->flags.activ = 1;
24 eim->flags.dirty = 0;
25 cache->activ = evas_hash_add(cache->activ, key, eim);
26}
27
28static void
29_evas_cache_engine_image_make_inactive(Evas_Cache_Engine_Image *cache,
30 Engine_Image_Entry *eim,
31 const char *key)
32{
33 eim->flags.cached = 1;
34 eim->flags.dirty = 0;
35 eim->flags.activ = 0;
36 cache->inactiv = evas_hash_add(cache->inactiv, key, eim);
37 cache->lru = evas_object_list_prepend(cache->lru, eim);
38 cache->usage += cache->func.mem_size_get(eim);
39}
40
41static void
42_evas_cache_engine_image_remove_activ(Evas_Cache_Engine_Image *cache,
43 Engine_Image_Entry *eim)
44{
45 if (eim->flags.cached)
46 {
47 if (eim->flags.dirty)
48 {
49 cache->dirty = evas_object_list_remove(cache->dirty, eim);
50 }
51 else
52 if (eim->flags.activ)
53 {
54 cache->activ = evas_hash_del(cache->activ, eim->cache_key, eim);
55 }
56 else
57 {
58 cache->usage -= cache->func.mem_size_get(eim);
59 cache->inactiv = evas_hash_del(cache->inactiv, eim->cache_key, eim);
60 cache->lru = evas_object_list_remove(cache->lru, eim);
61 }
62 eim->flags.cached = 0;
63 eim->flags.dirty = 0;
64 eim->flags.activ = 0;
65 }
66}
67
68static Engine_Image_Entry *
69_evas_cache_engine_image_alloc(Evas_Cache_Engine_Image *cache,
70 Image_Entry *ie,
71 const char *hkey)
72{
73 Engine_Image_Entry *eim;
74
75 assert(cache);
76
77 if (cache->func.alloc)
78 eim = cache->func.alloc();
79 else
80 eim = malloc(sizeof (Engine_Image_Entry));
81
82 if (!eim) goto on_error;
83 memset(eim, 0, sizeof (Engine_Image_Entry));
84
85 eim->cache = cache;
86 if (ie)
87 {
88 eim->w = ie->w;
89 eim->h = ie->h;
90 eim->src = ie;
91 eim->flags.need_parent = 1;
92 }
93 else
94 {
95 eim->w = -1;
96 eim->h = -1;
97 eim->flags.need_parent = 0;
98 eim->src = NULL;
99 }
100
101 eim->flags.cached = 0;
102 eim->references = 0;
103 eim->cache_key = hkey;
104
105 if (hkey)
106 _evas_cache_engine_image_make_active(cache, eim, hkey);
107 else
108 _evas_cache_engine_image_make_dirty(cache, eim);
109
110 return eim;
111
112 on_error:
113 if (eim)
114 evas_cache_engine_image_drop(eim);
115 evas_stringshare_del(hkey);
116 evas_cache_image_drop(ie);
117 return NULL;
118}
119
120static void
121_evas_cache_engine_image_dealloc(Evas_Cache_Engine_Image *cache, Engine_Image_Entry *eim)
122{
123 Image_Entry *im;
124
125 if (cache->func.debug) cache->func.debug("delete", eim);
126
127 _evas_cache_engine_image_remove_activ(cache, eim);
128
129 im = eim->src;
130 cache->func.destructor(eim);
131 if (im) evas_cache_image_drop(im);
132
133 if (cache->func.delete)
134 {
135 cache->func.delete(eim);
136 }
137 else
138 {
139 memset(eim, 0, sizeof (Engine_Image_Entry));
140 free(eim);
141 }
142}
143
6EAPI int 144EAPI int
7evas_cache_engine_image_usage_get(Evas_Cache_Engine_Image *cache) 145evas_cache_engine_image_usage_get(Evas_Cache_Engine_Image *cache)
8{ 146{
@@ -42,11 +180,57 @@ evas_cache_engine_image_init(const Evas_Cache_Engine_Image_Func *cb, Evas_Cache_
42 new->usage = 0; 180 new->usage = 0;
43 181
44 new->dirty = NULL; 182 new->dirty = NULL;
183 new->lru = NULL;
45 new->activ = NULL; 184 new->activ = NULL;
185 new->inactiv = NULL;
46 186
47 new->parent = parent; 187 new->parent = parent;
48 parent->references++; 188 parent->references++;
49 189
190 new->brother = NULL;
191
192 return new;
193}
194
195EAPI Evas_Cache_Engine_Image *
196evas_cache_engine_image_dup(const Evas_Cache_Engine_Image_Func *cb, Evas_Cache_Engine_Image *brother)
197{
198 Evas_Cache_Engine_Image *new;
199
200 new = malloc(sizeof (Evas_Cache_Engine_Image));
201 if (!new)
202 return NULL;
203
204 new->func = brother->func;
205
206#define ORD(Func) if (cb->Func) new->func.Func = cb->Func;
207
208 ORD(key);
209 ORD(constructor);
210 ORD(destructor);
211 ORD(dirty_region);
212 ORD(dirty);
213 ORD(size_set);
214 ORD(update_data);
215 ORD(load);
216 ORD(mem_size_get);
217 ORD(debug);
218
219#undef ORD
220
221 new->limit = -1;
222 new->usage = 0;
223 new->references = 1;
224
225 new->dirty = NULL;
226 new->activ = NULL;
227
228 new->parent = brother->parent;
229 new->parent->references++;
230
231 new->brother = brother;
232 brother->references++;
233
50 return new; 234 return new;
51} 235}
52 236
@@ -54,130 +238,126 @@ static Evas_Bool
54_evas_cache_engine_image_free_cb(const Evas_Hash *hash, const char *key, void *data, void *fdata) 238_evas_cache_engine_image_free_cb(const Evas_Hash *hash, const char *key, void *data, void *fdata)
55{ 239{
56 Evas_Cache_Engine_Image *cache = fdata; 240 Evas_Cache_Engine_Image *cache = fdata;
57 RGBA_Engine_Image *eim = data; 241 Engine_Image_Entry *eim = data;
58 RGBA_Image *im;
59 242
60 if (cache->func.debug) 243 _evas_cache_engine_image_dealloc(cache, eim);
61 cache->func.debug("shutdown-engine-activ", eim);
62 244
63 evas_stringshare_del(eim->cache_key); 245 return 1;
64 eim->cache_key = NULL; 246}
65 247
66 im = eim->src; 248EAPI void
67 cache->func.destructor(eim); 249evas_cache_engine_image_flush(Evas_Cache_Engine_Image *cache)
68 if (im) evas_cache_image_drop(im); 250{
69 free(eim); 251 assert(cache != NULL);
70 252
71 return 1; 253 while ((cache->lru) && (cache->limit < cache->usage))
254 {
255 Engine_Image_Entry *eim;
256
257 eim = (Engine_Image_Entry *) cache->lru->last;
258 _evas_cache_engine_image_dealloc(cache, eim);
259 }
72} 260}
73 261
74EAPI void 262EAPI void
75evas_cache_engine_image_shutdown(Evas_Cache_Engine_Image *cache) 263evas_cache_engine_image_shutdown(Evas_Cache_Engine_Image *cache)
76{ 264{
77 RGBA_Engine_Image *eim; 265 Engine_Image_Entry *eim;
78 RGBA_Image *im;
79 266
80 assert(cache != NULL); 267 assert(cache != NULL);
81 268
269 if (cache->func.debug) cache->func.debug("shutdown-engine", NULL);
270
271 evas_hash_foreach(cache->inactiv, _evas_cache_engine_image_free_cb, cache);
272 evas_hash_free(cache->inactiv);
273
82 /* This is mad, I am about to destroy image still alive, but we need to prevent leak. */ 274 /* This is mad, I am about to destroy image still alive, but we need to prevent leak. */
83 while (cache->dirty) 275 while (cache->dirty)
84 { 276 {
85 eim = (RGBA_Engine_Image *) cache->dirty; 277 eim = (Engine_Image_Entry *) cache->dirty;
86 im = eim->src; 278 _evas_cache_engine_image_dealloc(cache, eim);
87
88 cache->dirty = evas_object_list_remove(cache->dirty, eim);
89
90 if (cache->func.debug)
91 cache->func.debug("shutdown-engine-dirty", eim);
92 cache->func.destructor(eim);
93 if (im) evas_cache_image_drop(im);
94 free(eim);
95 } 279 }
96 280
97 evas_hash_foreach(cache->activ, _evas_cache_engine_image_free_cb, cache); 281 evas_hash_foreach(cache->activ, _evas_cache_engine_image_free_cb, cache);
98 evas_hash_free(cache->activ); 282 evas_hash_free(cache->activ);
283
284 evas_cache_image_shutdown(cache->parent);
285 if (cache->brother)
286 evas_cache_engine_image_shutdown(cache->brother);
287 free(cache);
99} 288}
100 289
101EAPI RGBA_Engine_Image * 290EAPI Engine_Image_Entry *
102evas_cache_engine_image_request(Evas_Cache_Engine_Image *cache, const char *file, const char *key, 291evas_cache_engine_image_request(Evas_Cache_Engine_Image *cache,
292 const char *file, const char *key,
103 RGBA_Image_Loadopts *lo, void *data, int *error) 293 RGBA_Image_Loadopts *lo, void *data, int *error)
104{ 294{
105 RGBA_Engine_Image *eim; 295 Engine_Image_Entry *eim;
106 RGBA_Image *im; 296 Image_Entry *im;
107 const char *ekey; 297 const char *ekey;
108 298
109 assert(cache != NULL); 299 assert(cache != NULL);
110 300
301 *error = -1;
302
303 ekey = NULL;
304 eim = NULL;
305
111 im = evas_cache_image_request(cache->parent, file, key, lo, error); 306 im = evas_cache_image_request(cache->parent, file, key, lo, error);
112 if (!im) 307 if (!im)
113 { 308 goto on_error;
114 *error = -1;
115 return NULL;
116 }
117 309
118 if (cache->func.key) 310 if (cache->func.key)
119 ekey = cache->func.key(im, file, key, lo, data); 311 ekey = cache->func.key(im, file, key, lo, data);
120 else 312 else
121 ekey = evas_stringshare_add(im->cache_key); 313 ekey = evas_stringshare_add(im->cache_key);
122 if (!ekey) 314 if (!ekey)
315 goto on_error;
316
317 eim = evas_hash_find(cache->activ, ekey);
318 if (eim)
123 { 319 {
124 *error = -1;
125 evas_cache_image_drop(im); 320 evas_cache_image_drop(im);
126 return NULL; 321 goto on_ok;
127 } 322 }
128 323
129 eim = evas_hash_find(cache->activ, ekey); 324 eim = evas_hash_find(cache->inactiv, ekey);
130 if (eim) goto on_ok; 325 if (eim)
131 326 {
132 eim = malloc(sizeof(RGBA_Engine_Image)); 327 _evas_cache_engine_image_remove_activ(cache, eim);
133 if (!eim) goto on_error; 328 _evas_cache_engine_image_make_active(cache, eim, ekey);
329 evas_cache_image_drop(im);
330 goto on_ok;
331 }
134 332
135 eim->src = im; 333 eim = _evas_cache_engine_image_alloc(cache, im, ekey);
136 eim->engine_data = NULL; 334 if (!eim) return NULL;
137 eim->flags.dirty = 0;
138 eim->flags.loaded = 0;
139 eim->cache = cache;
140 eim->cache_key = ekey;
141 eim->references = 0;
142 335
143 *error = cache->func.constructor(eim, data); 336 *error = cache->func.constructor(eim, data);
337 if (*error != 0) goto on_error;
144 if (cache->func.debug) 338 if (cache->func.debug)
145 cache->func.debug("constructor-engine", eim); 339 cache->func.debug("constructor-engine", eim);
146 340
147 if (*error != 0) goto on_error;
148
149 cache->activ = evas_hash_add(cache->activ, ekey, eim);
150 cache->usage += strlen(eim->cache_key) + 1 + cache->func.mem_size_get(eim);
151
152 on_ok: 341 on_ok:
153 eim->references++; 342 eim->references++;
154 return eim; 343 return eim;
155 344
156 on_error: 345 on_error:
157 evas_cache_image_drop(im); 346 if (!eim)
158 evas_stringshare_del(ekey); 347 {
159 if (eim) free(eim); 348 if (im) evas_cache_image_drop(im);
160 return NULL; 349 if (ekey) evas_stringshare_del(ekey);
161} 350 }
162 351 else
163static void 352 {
164_evas_cache_engine_image_free(Evas_Cache_Engine_Image *cache, RGBA_Engine_Image *eim) 353 _evas_cache_engine_image_dealloc(cache, eim);
165{ 354 }
166 int size;
167
168 size = cache->func.mem_size_get(eim);
169 cache->usage -= size;
170 355
171 if (cache->func.debug) 356 return NULL;
172 cache->func.debug("drop-engine", eim);
173 cache->func.destructor(eim);
174 if (eim->src) evas_cache_image_drop(eim->src);
175 if (eim->cache_key) evas_stringshare_del(eim->cache_key);
176 free(eim);
177} 357}
178 358
179EAPI void 359EAPI void
180evas_cache_engine_image_drop(RGBA_Engine_Image *eim) 360evas_cache_engine_image_drop(Engine_Image_Entry *eim)
181{ 361{
182 Evas_Cache_Engine_Image *cache; 362 Evas_Cache_Engine_Image *cache;
183 363
@@ -189,28 +369,27 @@ evas_cache_engine_image_drop(RGBA_Engine_Image *eim)
189 369
190 if (eim->flags.dirty) 370 if (eim->flags.dirty)
191 { 371 {
192 cache->dirty = evas_object_list_remove(cache->dirty, eim); 372 _evas_cache_engine_image_dealloc(cache, eim);
193
194 _evas_cache_engine_image_free(cache, eim);
195 return ; 373 return ;
196 } 374 }
197 375
198 if (eim->references == 0) 376 if (eim->references == 0)
199 { 377 {
200 cache->activ = evas_hash_del(cache->activ, eim->cache_key, eim); 378 _evas_cache_engine_image_remove_activ(cache, eim);
201 379 _evas_cache_engine_image_make_inactive(cache, eim, eim->cache_key);
202 _evas_cache_engine_image_free(cache, eim); 380 evas_cache_engine_image_flush(cache);
203 return ; 381 return ;
204 } 382 }
205} 383}
206 384
207EAPI RGBA_Engine_Image * 385EAPI Engine_Image_Entry *
208evas_cache_engine_image_dirty(RGBA_Engine_Image *eim, int x, int y, int w, int h) 386evas_cache_engine_image_dirty(Engine_Image_Entry *eim, int x, int y, int w, int h)
209{ 387{
210 RGBA_Engine_Image *eim_dirty = eim; 388 Engine_Image_Entry *eim_dirty = eim;
211 RGBA_Image *im; 389 Image_Entry *im_dirty = NULL;
212 RGBA_Image *im_dirty; 390 Image_Entry *im;
213 Evas_Cache_Engine_Image *cache; 391 Evas_Cache_Engine_Image *cache;
392 unsigned char alloc_eim;
214 393
215 assert(eim); 394 assert(eim);
216 assert(eim->cache); 395 assert(eim->cache);
@@ -218,56 +397,56 @@ evas_cache_engine_image_dirty(RGBA_Engine_Image *eim, int x, int y, int w, int h
218 cache = eim->cache; 397 cache = eim->cache;
219 if (!(eim->flags.dirty)) 398 if (!(eim->flags.dirty))
220 { 399 {
221 im = eim->src; 400 alloc_eim = 0;
222 im_dirty = evas_cache_image_dirty(im, x, y, w, h);
223 401
224 /* If im == im_dirty, this meens that we have only one reference to the eim. */ 402 if (eim->flags.need_parent == 1)
225 if (im != im_dirty)
226 { 403 {
227 if (eim->references == 1) 404 im = eim->src;
228 { 405 im_dirty = evas_cache_image_dirty(im, x, y, w, h);
229 const char *hkey;
230
231 hkey = eim->cache_key;
232 cache->activ = evas_hash_del(cache->activ, hkey, eim);
233
234 cache->usage -= strlen(hkey) + 1;
235
236 evas_stringshare_del(hkey);
237 406
238 eim_dirty = eim; 407 /* If im == im_dirty, this meens that we have only one reference to the eim. */
239 eim_dirty->src = im_dirty; 408 if (im != im_dirty)
240 }
241 else
242 { 409 {
243 int error; 410 if (eim->references == 1)
244 411 {
245 eim_dirty = malloc(sizeof(RGBA_Engine_Image)); 412 _evas_cache_engine_image_remove_activ(cache, eim);
246 if (!eim_dirty) goto on_error; 413 _evas_cache_engine_image_make_dirty(cache, eim);
247 414
248 eim_dirty->src = im_dirty; 415 eim->src = im_dirty;
249 eim_dirty->engine_data = NULL; 416 }
250 eim_dirty->flags.dirty = 1; 417 else
251 eim_dirty->flags.loaded = 1; 418 alloc_eim = 1;
252 eim_dirty->cache = cache; 419 }
253 eim_dirty->cache_key = NULL; 420 }
254 eim_dirty->references = 1; 421 else
422 if (eim->references > 1)
423 {
424 alloc_eim = 1;
425 }
426 else
427 {
428 _evas_cache_engine_image_remove_activ(cache, eim_dirty);
429 _evas_cache_engine_image_make_dirty(cache, eim_dirty);
430 }
431
432 if (alloc_eim == 1)
433 {
434 int error;
255 435
256 error = cache->func.dirty(eim_dirty, eim); 436 eim_dirty = _evas_cache_engine_image_alloc(cache, im_dirty, NULL);
257 if (cache->func.debug) 437 if (!eim_dirty) goto on_error;
258 cache->func.debug("dirty-engine", eim_dirty);
259 438
260 if (error != 0) goto on_error; 439 eim_dirty->w = eim->w;
440 eim_dirty->h = eim->h;
441 eim_dirty->references = 1;
261 442
262 cache->usage += cache->func.mem_size_get(eim_dirty); 443 error = cache->func.dirty(eim_dirty, eim);
444 if (cache->func.debug)
445 cache->func.debug("dirty-engine", eim_dirty);
263 446
264 evas_cache_engine_image_drop(eim); 447 if (error != 0) goto on_error;
265 }
266 448
267 eim_dirty->cache_key = NULL; 449 evas_cache_engine_image_drop(eim);
268 eim_dirty->flags.dirty = 1;
269
270 cache->dirty = evas_object_list_prepend(cache->dirty, eim_dirty);
271 } 450 }
272 } 451 }
273 452
@@ -280,7 +459,7 @@ evas_cache_engine_image_dirty(RGBA_Engine_Image *eim, int x, int y, int w, int h
280 459
281 on_error: 460 on_error:
282 if (eim) evas_cache_engine_image_drop(eim); 461 if (eim) evas_cache_engine_image_drop(eim);
283 if (eim_dirty) 462 if (eim_dirty && eim_dirty != eim)
284 evas_cache_engine_image_drop(eim_dirty); 463 evas_cache_engine_image_drop(eim_dirty);
285 else 464 else
286 if (im_dirty) evas_cache_image_drop(im_dirty); 465 if (im_dirty) evas_cache_image_drop(im_dirty);
@@ -288,21 +467,43 @@ evas_cache_engine_image_dirty(RGBA_Engine_Image *eim, int x, int y, int w, int h
288 return NULL; 467 return NULL;
289} 468}
290 469
291static RGBA_Engine_Image * 470EAPI Engine_Image_Entry *
292_evas_cache_engine_image_push_dirty(Evas_Cache_Engine_Image *cache, RGBA_Image *im, void *engine_data) 471evas_cache_engine_image_alone(Engine_Image_Entry *eim, void *data)
293{ 472{
294 RGBA_Engine_Image *eim; 473 Evas_Cache_Engine_Image *cache;
474 Image_Entry *im;
475
476
477 assert(eim);
478 assert(eim->cache);
479
480 cache = eim->cache;
481 im = evas_cache_image_alone(eim->src);
482 if (im != eim->src)
483 {
484 eim = _evas_cache_engine_image_alloc(cache, im, NULL);
485 if (!eim) goto on_error;
486
487 eim->references = 1;
488
489 if (cache->func.constructor(eim, data)) goto on_error;
490 }
491 /* FIXME */
492 return eim;
493
494 on_error:
495 evas_cache_image_drop(im);
496 return NULL;
497}
498
499static Engine_Image_Entry *
500_evas_cache_engine_image_push_dirty(Evas_Cache_Engine_Image *cache, Image_Entry *im, void *engine_data)
501{
502 Engine_Image_Entry *eim;
295 int error; 503 int error;
296 504
297 eim = malloc(sizeof(RGBA_Engine_Image)); 505 eim = _evas_cache_engine_image_alloc(cache, im, NULL);
298 if (!eim) goto on_error; 506 if (!eim) goto on_error;
299
300 eim->src = im;
301 eim->engine_data = NULL;
302 eim->flags.dirty = 1;
303 eim->flags.loaded = 1;
304 eim->cache = cache;
305 eim->cache_key = NULL;
306 eim->references = 1; 507 eim->references = 1;
307 508
308 error = cache->func.update_data(eim, engine_data); 509 error = cache->func.update_data(eim, engine_data);
@@ -310,22 +511,18 @@ _evas_cache_engine_image_push_dirty(Evas_Cache_Engine_Image *cache, RGBA_Image *
310 cache->func.debug("dirty-update_data-engine", eim); 511 cache->func.debug("dirty-update_data-engine", eim);
311 if (error != 0) goto on_error; 512 if (error != 0) goto on_error;
312 513
313 cache->dirty = evas_object_list_prepend(cache->dirty, eim);
314
315 return eim; 514 return eim;
316 515
317 on_error: 516 on_error:
318 if (eim) 517 if (eim)
319 evas_cache_engine_image_drop(eim); 518 evas_cache_engine_image_drop(eim);
320 else
321 evas_cache_image_drop(im);
322 return NULL; 519 return NULL;
323} 520}
324 521
325EAPI RGBA_Engine_Image * 522EAPI Engine_Image_Entry *
326evas_cache_engine_image_copied_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data) 523evas_cache_engine_image_copied_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data)
327{ 524{
328 RGBA_Image *im; 525 Image_Entry *im;
329 526
330 assert(cache); 527 assert(cache);
331 528
@@ -334,10 +531,10 @@ evas_cache_engine_image_copied_data(Evas_Cache_Engine_Image *cache, int w, int h
334 return _evas_cache_engine_image_push_dirty(cache, im, engine_data); 531 return _evas_cache_engine_image_push_dirty(cache, im, engine_data);
335} 532}
336 533
337EAPI RGBA_Engine_Image * 534EAPI Engine_Image_Entry *
338evas_cache_engine_image_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data) 535evas_cache_engine_image_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data)
339{ 536{
340 RGBA_Image *im; 537 Image_Entry *im;
341 538
342 assert(cache); 539 assert(cache);
343 540
@@ -346,64 +543,48 @@ evas_cache_engine_image_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA3
346 return _evas_cache_engine_image_push_dirty(cache, im, engine_data); 543 return _evas_cache_engine_image_push_dirty(cache, im, engine_data);
347} 544}
348 545
349EAPI RGBA_Engine_Image * 546EAPI Engine_Image_Entry *
350evas_cache_engine_image_size_set(RGBA_Engine_Image *eim, int w, int h) 547evas_cache_engine_image_size_set(Engine_Image_Entry *eim, int w, int h)
351{ 548{
352 Evas_Cache_Engine_Image *cache; 549 Evas_Cache_Engine_Image *cache;
353 RGBA_Engine_Image *new; 550 Engine_Image_Entry *new;
354 RGBA_Image *im; 551 Image_Entry *im;
355 int error; 552 const char *hkey;
553 int error;
356 554
357 assert(eim); 555 assert(eim);
358 assert(eim->src);
359 assert(eim->cache); 556 assert(eim->cache);
360 assert(eim->references > 0); 557 assert(eim->references > 0);
361 558
362 if (eim->src->image->w == w 559 im = NULL;
363 && eim->src->image->h == h)
364 return eim;
365
366 cache = eim->cache; 560 cache = eim->cache;
367 561
368 im = evas_cache_image_size_set(eim->src, w, h); 562 if (eim->flags.need_parent == 1)
369 /* Good idea to call update_data ? */ 563 {
370 if (im == eim->src) return eim; 564 assert(eim->src);
371 eim->src = NULL; 565
566 if (eim->src->w == w
567 && eim->src->h == h)
568 return eim;
569
570 im = evas_cache_image_size_set(eim->src, w, h);
571 /* FIXME: Good idea to call update_data ? */
572 if (im == eim->src) return eim;
573 eim->src = NULL;
574 }
575
576 hkey = (eim->references > 1 ) ? evas_stringshare_add(eim->cache_key) : NULL;
372 577
373 new = malloc(sizeof(RGBA_Engine_Image)); 578 new = _evas_cache_engine_image_alloc(cache, im, hkey);
374 if (!new) goto on_error; 579 if (!new) goto on_error;
375 580
376 new->src = im; 581 new->w = w;
377 new->engine_data = NULL; 582 new->h = h;
378 new->flags = eim->flags;
379 new->flags.loaded = 1;
380 new->cache = cache;
381 new->cache_key = NULL;
382 new->references = 1; 583 new->references = 1;
383 584
384 error = cache->func.size_set(new, eim); 585 error = cache->func.size_set(new, eim);
385 if (error) goto on_error; 586 if (error) goto on_error;
386 587
387 assert(new->engine_data != eim->engine_data);
388
389 cache->usage += cache->func.mem_size_get(new);
390
391 if (new->flags.dirty || eim->references > 1)
392 {
393 new->flags.dirty = 1;
394 cache->dirty = evas_object_list_prepend(cache->dirty, new);
395 }
396 else
397 {
398 const char *cache_key = NULL;
399
400 cache_key = eim->cache_key ? evas_stringshare_add(eim->cache_key) : NULL;
401 new->cache_key = cache_key;
402
403 cache->activ = evas_hash_add(cache->activ, cache_key, new);
404 cache->usage += strlen(new->cache_key) + 1;
405 }
406
407 evas_cache_engine_image_drop(eim); 588 evas_cache_engine_image_drop(eim);
408 return new; 589 return new;
409 590
@@ -419,10 +600,10 @@ evas_cache_engine_image_size_set(RGBA_Engine_Image *eim, int w, int h)
419} 600}
420 601
421EAPI void 602EAPI void
422evas_cache_engine_image_load_data(RGBA_Engine_Image *eim) 603evas_cache_engine_image_load_data(Engine_Image_Entry *eim)
423{ 604{
424 Evas_Cache_Engine_Image *cache; 605 Evas_Cache_Engine_Image *cache;
425 int size; 606 int size = 0;
426 607
427 assert(eim); 608 assert(eim);
428 assert(eim->src); 609 assert(eim->src);
@@ -430,37 +611,35 @@ evas_cache_engine_image_load_data(RGBA_Engine_Image *eim)
430 611
431 if (eim->flags.loaded) return ; 612 if (eim->flags.loaded) return ;
432 613
433 evas_cache_image_load_data(eim->src); 614 if (eim->src)
615 evas_cache_image_load_data(eim->src);
434 616
435 cache = eim->cache; 617 cache = eim->cache;
436 if (cache->func.debug) 618 if (cache->func.debug)
437 cache->func.debug("load-engine", eim); 619 cache->func.debug("load-engine", eim);
438 620
439 size = cache->func.mem_size_get(eim); 621 if (eim->flags.dirty)
622 size = cache->func.mem_size_get(eim);
440 cache = eim->cache; 623 cache = eim->cache;
441 cache->func.load(eim, eim->src); 624 cache->func.load(eim, eim->src);
442 cache->usage += cache->func.mem_size_get(eim) - size; 625 if (eim->flags.dirty)
626 cache->usage += cache->func.mem_size_get(eim) - size;
443 627
444 eim->flags.loaded = 1; 628 eim->flags.loaded = 1;
445} 629}
446 630
447EAPI RGBA_Engine_Image * 631EAPI Engine_Image_Entry *
448evas_cache_engine_image_engine(Evas_Cache_Engine_Image *cache, void *engine_data) 632evas_cache_engine_image_engine(Evas_Cache_Engine_Image *cache, void *engine_data)
449{ 633{
450 RGBA_Engine_Image *eim; 634 Engine_Image_Entry *eim;
451 int error; 635 Image_Entry *ie;
636 int error;
452 637
453 eim = malloc(sizeof(RGBA_Engine_Image)); 638 ie = evas_cache_image_empty(cache->parent);
454 if (!eim) goto on_error; 639 if (!ie) return NULL;
455
456 eim->src = evas_cache_image_empty(cache->parent);
457 if (!eim->src) goto on_error;
458 640
459 eim->engine_data = NULL; 641 eim = _evas_cache_engine_image_alloc(cache, ie, NULL);
460 eim->flags.dirty = 1; 642 if (!eim) goto on_error;
461 eim->flags.loaded = 1;
462 eim->cache = cache;
463 eim->cache_key = NULL;
464 eim->references = 1; 643 eim->references = 1;
465 644
466 error = cache->func.update_data(eim, engine_data); 645 error = cache->func.update_data(eim, engine_data);
@@ -469,18 +648,23 @@ evas_cache_engine_image_engine(Evas_Cache_Engine_Image *cache, void *engine_data
469 648
470 if (error != 0) goto on_error; 649 if (error != 0) goto on_error;
471 650
472 cache->dirty = evas_object_list_prepend(cache->dirty, eim);
473
474 return eim; 651 return eim;
475 652
476 on_error: 653 on_error:
477 if (eim) 654 if (!eim)
478 evas_cache_engine_image_drop(eim); 655 {
656 if (ie)
657 evas_cache_image_drop(ie);
658 }
659 else
660 {
661 evas_cache_engine_image_drop(eim);
662 }
479 return NULL; 663 return NULL;
480} 664}
481 665
482EAPI void 666EAPI void
483evas_cache_engine_image_colorspace(RGBA_Engine_Image *eim, int cspace, void *engine_data) 667evas_cache_engine_image_colorspace(Engine_Image_Entry *eim, int cspace, void *engine_data)
484{ 668{
485 Evas_Cache_Engine_Image *cache = eim->cache; 669 Evas_Cache_Engine_Image *cache = eim->cache;
486 670
@@ -493,3 +677,12 @@ evas_cache_engine_image_colorspace(RGBA_Engine_Image *eim, int cspace, void *eng
493 cache->func.debug("cosntructor-colorspace-engine", eim); 677 cache->func.debug("cosntructor-colorspace-engine", eim);
494} 678}
495 679
680EAPI void
681evas_cache_engine_parent_not_needed(Engine_Image_Entry *eim)
682{
683 assert(eim);
684 assert(eim->cache);
685
686 eim->flags.need_parent = 0;
687 evas_cache_image_data_not_needed(eim->src);
688}
diff --git a/legacy/evas/src/lib/cache/evas_cache_image.c b/legacy/evas/src/lib/cache/evas_cache_image.c
index 430b579986..47468905d7 100644
--- a/legacy/evas/src/lib/cache/evas_cache_image.c
+++ b/legacy/evas/src/lib/cache/evas_cache_image.c
@@ -4,6 +4,221 @@
4#include "evas_common.h" 4#include "evas_common.h"
5#include "evas_private.h" 5#include "evas_private.h"
6 6
7#define FREESTRC(Var) \
8 if (Var) \
9 { \
10 evas_stringshare_del(Var); \
11 Var = NULL; \
12 }
13
14static void
15_evas_cache_image_make_dirty(Evas_Cache_Image *cache,
16 Image_Entry *im)
17{
18 im->flags.cached = 1;
19 im->flags.dirty = 1;
20 im->flags.activ = 0;
21 im->flags.lru_nodata = 0;
22 cache->dirty = evas_object_list_prepend(cache->dirty, im);
23
24 if (im->cache_key)
25 {
26 evas_stringshare_del(im->cache_key);
27 im->cache_key = NULL;
28 }
29}
30
31static void
32_evas_cache_image_make_activ(Evas_Cache_Image *cache,
33 Image_Entry *im,
34 const char *key)
35{
36 im->cache_key = key;
37 if (key != NULL)
38 {
39 im->flags.cached = 1;
40 im->flags.activ = 1;
41 im->flags.lru_nodata = 0;
42 im->flags.dirty = 0;
43 cache->activ = evas_hash_direct_add(cache->activ, key, im);
44 }
45 else
46 {
47 _evas_cache_image_make_dirty(cache, im);
48 }
49}
50
51static void
52_evas_cache_image_make_inactiv(Evas_Cache_Image *cache,
53 Image_Entry *im,
54 const char *key)
55{
56 im->flags.activ = 0;
57 im->flags.dirty = 0;
58 im->flags.cached = 1;
59 cache->inactiv = evas_hash_direct_add(cache->inactiv, key, im);
60 cache->lru = evas_object_list_prepend(cache->lru, im);
61 cache->usage += cache->func.mem_size_get(im);
62}
63
64static void
65_evas_cache_image_remove_lru_nodata(Evas_Cache_Image *cache,
66 Image_Entry *im)
67{
68 if (im->flags.lru_nodata)
69 {
70 im->flags.lru_nodata = 0;
71 cache->lru_nodata = evas_object_list_remove(cache->lru_nodata, im);
72 cache->usage -= cache->func.mem_size_get(im);
73 }
74}
75
76static void
77_evas_cache_image_activ_lru_nodata(Evas_Cache_Image *cache,
78 Image_Entry *im)
79{
80 im->flags.need_data = 0;
81 im->flags.lru_nodata = 1;
82 cache->lru_nodata = evas_object_list_prepend(cache->lru_nodata, im);
83 cache->usage += cache->func.mem_size_get(im);
84}
85
86static void
87_evas_cache_image_remove_activ(Evas_Cache_Image *cache,
88 Image_Entry *ie)
89{
90 if (ie->flags.cached)
91 {
92 if (ie->flags.activ)
93 {
94 cache->activ = evas_hash_del(cache->activ, ie->cache_key, ie);
95 _evas_cache_image_remove_lru_nodata(cache, ie);
96 }
97 else
98 {
99 if (ie->flags.dirty)
100 {
101 cache->dirty = evas_object_list_remove(cache->dirty, ie);
102 }
103 else
104 {
105 cache->inactiv = evas_hash_del(cache->inactiv, ie->cache_key, ie);
106 cache->lru = evas_object_list_remove(cache->lru, ie);
107 cache->usage -= cache->func.mem_size_get(ie);
108 }
109 }
110 ie->flags.cached = 0;
111 ie->flags.dirty = 0;
112 ie->flags.activ = 0;
113 }
114}
115
116static void
117_evas_cache_image_entry_delete(Evas_Cache_Image *cache, Image_Entry *ie)
118{
119 if (!ie) return ;
120
121 if (cache->func.debug)
122 cache->func.debug("deleting", ie);
123
124 cache->func.destructor(ie);
125
126 _evas_cache_image_remove_activ(cache, ie);
127
128 if (ie->cache_key)
129 {
130 evas_stringshare_del(ie->cache_key);
131 ie->cache_key = NULL;
132 }
133
134 FREESTRC(ie->file);
135 FREESTRC(ie->key);
136
137 cache->func.surface_delete(ie);
138 cache->func.delete(ie);
139}
140
141static Image_Entry *
142_evas_cache_image_entry_new(Evas_Cache_Image *cache,
143 const char *hkey,
144 time_t timestamp,
145 const char *file,
146 const char *key,
147 RGBA_Image_Loadopts *lo,
148 int *error)
149{
150 Image_Entry *ie;
151 const char *cache_key;
152
153 ie = cache->func.alloc();
154 if (!ie)
155 return NULL;
156
157 cache_key = hkey ? evas_stringshare_add(hkey) : NULL;
158
159 ie->flags.loaded = 0;
160 ie->flags.need_data = 1;
161
162 _evas_cache_image_make_activ(cache, ie, cache_key);
163
164 ie->space = EVAS_COLORSPACE_ARGB8888;
165 ie->w = -1;
166 ie->h = -1;
167
168 ie->references = 0;
169 ie->cache = cache;
170
171 ie->file = file ? evas_stringshare_add(file) : NULL;
172 ie->key = key ? evas_stringshare_add(key) : NULL;
173
174 ie->timestamp = timestamp;
175 ie->laststat = time(NULL);
176
177 ie->load_opts.scale_down_by = 0;
178 ie->load_opts.dpi = 0;
179 ie->load_opts.w = 0;
180 ie->load_opts.h = 0;
181 ie->scale = 1;
182
183 if (lo)
184 ie->load_opts = *lo;
185
186 ie->references = 0;
187 if (file)
188 {
189 *error = cache->func.constructor(ie);
190 if (*error != 0)
191 {
192 _evas_cache_image_entry_delete(cache, ie);
193 return NULL;
194 }
195 }
196 if (cache->func.debug)
197 cache->func.debug("build", ie);
198
199 return ie;
200}
201
202static void
203_evas_cache_image_entry_surface_alloc(Evas_Cache_Image *cache,
204 Image_Entry *ie,
205 int w,
206 int h)
207{
208 int wmin;
209 int hmin;
210
211 wmin = w > 0 ? w : 1;
212 hmin = h > 0 ? h : 1;
213 if (cache->func.surface_alloc(ie, wmin, hmin))
214 {
215 wmin = 0;
216 hmin = 0;
217 }
218 ie->w = wmin;
219 ie->h = hmin;
220}
221
7EAPI int 222EAPI int
8evas_cache_image_usage_get(Evas_Cache_Image *cache) 223evas_cache_image_usage_get(Evas_Cache_Image *cache)
9{ 224{
@@ -45,6 +260,7 @@ evas_cache_image_init(const Evas_Cache_Image_Func *cb)
45 260
46 new->dirty = NULL; 261 new->dirty = NULL;
47 new->lru = NULL; 262 new->lru = NULL;
263 new->lru_nodata = NULL;
48 new->inactiv = NULL; 264 new->inactiv = NULL;
49 new->activ = NULL; 265 new->activ = NULL;
50 266
@@ -57,26 +273,17 @@ static Evas_Bool
57_evas_cache_image_free_cb(const Evas_Hash *hash, const char *key, void *data, void *fdata) 273_evas_cache_image_free_cb(const Evas_Hash *hash, const char *key, void *data, void *fdata)
58{ 274{
59 Evas_Cache_Image *cache = fdata; 275 Evas_Cache_Image *cache = fdata;
60 RGBA_Image *im = data; 276 Image_Entry *im = data;
61 277
62 if (cache->func.debug) 278 _evas_cache_image_entry_delete(cache, im);
63 cache->func.debug("shutdown-activ", im);
64 279
65 if (im->cache_key)
66 {
67 evas_stringshare_del(im->cache_key);
68 im->cache_key = NULL;
69 }
70
71 cache->func.destructor(im);
72 evas_common_image_delete(im);
73 return 1; 280 return 1;
74} 281}
75 282
76EAPI void 283EAPI void
77evas_cache_image_shutdown(Evas_Cache_Image *cache) 284evas_cache_image_shutdown(Evas_Cache_Image *cache)
78{ 285{
79 RGBA_Image *im; 286 Image_Entry *im;
80 287
81 assert(cache != NULL); 288 assert(cache != NULL);
82 cache->references--; 289 cache->references--;
@@ -86,31 +293,21 @@ evas_cache_image_shutdown(Evas_Cache_Image *cache)
86 293
87 while (cache->lru) 294 while (cache->lru)
88 { 295 {
89 im = (RGBA_Image *) cache->lru; 296 im = (Image_Entry *) cache->lru;
90 cache->lru = evas_object_list_remove(cache->lru, im); 297 _evas_cache_image_entry_delete(cache, im);
91 298 }
92 if (im->cache_key)
93 {
94 evas_stringshare_del(im->cache_key);
95 im->cache_key = NULL;
96 }
97 299
98 if (cache->func.debug) 300 while (cache->lru_nodata)
99 cache->func.debug("shutdown-lru", im); 301 {
100 cache->func.destructor(im); 302 im = (Image_Entry *) cache->lru_nodata;
101 evas_common_image_delete(im); 303 _evas_cache_image_entry_delete(cache, im);
102 } 304 }
103 305
104 /* This is mad, I am about to destroy image still alive, but we need to prevent leak. */ 306 /* This is mad, I am about to destroy image still alive, but we need to prevent leak. */
105 while (cache->dirty) 307 while (cache->dirty)
106 { 308 {
107 im = (RGBA_Image *) cache->dirty; 309 im = (Image_Entry *) cache->dirty;
108 cache->dirty = evas_object_list_remove(cache->dirty, im); 310 _evas_cache_image_entry_delete(cache, im);
109
110 if (cache->func.debug)
111 cache->func.debug("shutdown-dirty", im);
112 cache->func.destructor(im);
113 evas_common_image_delete(im);
114 } 311 }
115 312
116 evas_hash_foreach(cache->activ, _evas_cache_image_free_cb, cache); 313 evas_hash_foreach(cache->activ, _evas_cache_image_free_cb, cache);
@@ -120,14 +317,17 @@ evas_cache_image_shutdown(Evas_Cache_Image *cache)
120 free(cache); 317 free(cache);
121} 318}
122 319
123EAPI RGBA_Image * 320#define STAT_GAP 2
321
322EAPI Image_Entry *
124evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error) 323evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error)
125{ 324{
126 const char *format; 325 const char *format;
127 char *hkey; 326 char *hkey;
128 RGBA_Image *im; 327 Image_Entry *im;
129 Evas_Image_Load_Opts prevent; 328 Evas_Image_Load_Opts prevent;
130 int size; 329 int size;
330 int stat_done = 0;
131 struct stat st; 331 struct stat st;
132 332
133 assert(cache != NULL); 333 assert(cache != NULL);
@@ -157,106 +357,86 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *
157 hkey = alloca(sizeof (char) * size); 357 hkey = alloca(sizeof (char) * size);
158 snprintf(hkey, size, format, file, key, lo->scale_down_by, lo->dpi, lo->w, lo->h); 358 snprintf(hkey, size, format, file, key, lo->scale_down_by, lo->dpi, lo->w, lo->h);
159 359
160 if (stat(file, &st) < 0)
161 {
162 im = evas_hash_find(cache->inactiv, hkey);
163 if (im)
164 {
165 cache->lru = evas_object_list_remove(cache->lru, im);
166 cache->inactiv = evas_hash_del(cache->inactiv, im->cache_key, im);
167// printf("IMG %p %ix%i %s SUB %i\n",
168// im, im->image->w, im->image->h, im->cache_key,
169// cache->func.mem_size_get(im));
170 cache->usage -= cache->func.mem_size_get(im);
171 if (im->cache_key)
172 {
173 evas_stringshare_del(im->cache_key);
174 im->cache_key = NULL;
175 }
176 cache->func.destructor(im);
177 evas_common_image_delete(im);
178 }
179 return NULL;
180 }
181
182 im = evas_hash_find(cache->activ, hkey); 360 im = evas_hash_find(cache->activ, hkey);
183 if (im) 361 if (im)
184 { 362 {
185 if (st.st_mtime == im->timestamp) 363 time_t t;
186 goto on_ok; 364 int ok;
365
366 ok = 1;
367 t = time(NULL);
368
369 if ((t - im->laststat) > STAT_GAP)
370 {
371 stat_done = 1;
372 if (stat(file, &st) < 0) goto on_error;
373
374 im->laststat = t;
375 if (st.st_mtime != im->timestamp) ok = 0;
376 }
377 if (ok) goto on_ok;
187 } 378 }
188 379
189 im = evas_hash_find(cache->inactiv, hkey); 380 im = evas_hash_find(cache->inactiv, hkey);
190 if (im) 381 if (im)
191 { 382 {
192 if (st.st_mtime == im->timestamp) 383 int ok;
193 {
194 cache->lru = evas_object_list_remove(cache->lru, im);
195 cache->inactiv = evas_hash_del(cache->inactiv, im->cache_key, im);
196 cache->activ = evas_hash_direct_add(cache->activ, im->cache_key, im);
197// printf("IMG %p %ix%i %s SUB %i\n",
198// im, im->image->w, im->image->h, im->cache_key,
199// cache->func.mem_size_get(im));
200 cache->usage -= cache->func.mem_size_get(im);
201 goto on_ok;
202 }
203 else
204 {
205 cache->lru = evas_object_list_remove(cache->lru, im);
206 cache->inactiv = evas_hash_del(cache->inactiv, im->cache_key, im);
207// printf("IMG %p %ix%i %s SUB %i\n",
208// im, im->image->w, im->image->h, im->cache_key,
209// cache->func.mem_size_get(im));
210 cache->usage -= cache->func.mem_size_get(im);
211 if (im->cache_key)
212 {
213 evas_stringshare_del(im->cache_key);
214 im->cache_key = NULL;
215 }
216 cache->func.destructor(im);
217 evas_common_image_delete(im);
218 }
219 }
220 384
221 im = evas_common_image_new(); 385 ok = 1;
222 if (!im) 386 if (!stat_done)
223 { 387 {
224 *error = -1; 388 time_t t;
225 return NULL;
226 }
227 389
228 im->timestamp = st.st_mtime; 390 t = time(NULL);
229 im->laststat = time(NULL); 391 if ((t - im->laststat) > STAT_GAP)
392 {
393 stat_done = 1;
394 if (stat(file, &st) < 0) goto on_error;
230 395
231 if (lo) im->load_opts = *lo; 396 im->laststat = t;
397 if (st.st_mtime != im->timestamp) ok = 0;
398 }
399 }
400 else
401 if (st.st_mtime != im->timestamp) ok = 0;
402
403 if (ok)
404 {
405 _evas_cache_image_remove_activ(cache, im);
406 _evas_cache_image_make_activ(cache, im, im->cache_key);
407 goto on_ok;
408 }
232 409
233 im->info.file = (char *) evas_stringshare_add(file); 410 _evas_cache_image_entry_delete(cache, im);
234 if (key) im->info.key = (char *) evas_stringshare_add(key); 411 }
235 412
236 *error = cache->func.constructor(im); 413 if (!stat_done)
237 if (*error != 0)
238 { 414 {
239 evas_common_image_delete(im); 415 if (stat(file, &st) < 0) return NULL;
240 return NULL;
241 } 416 }
242 417
418 im = _evas_cache_image_entry_new(cache, hkey, st.st_mtime, file, key, lo, error);
419 if (!im)
420 return NULL;
421
243 if (cache->func.debug) 422 if (cache->func.debug)
244 cache->func.debug("request", im); 423 cache->func.debug("request", im);
245 424
246 im->references = 0; 425 on_ok:
247 im->cache_key = evas_stringshare_add(hkey);
248 im->cache = cache;
249
250 cache->activ = evas_hash_direct_add(cache->activ, im->cache_key, im);
251
252 on_ok:
253 *error = 0; 426 *error = 0;
254 im->references++; 427 im->references++;
428 if (im->references > 1 && im->flags.lru_nodata)
429 _evas_cache_image_remove_lru_nodata(cache, im);
430
255 return im; 431 return im;
432
433 on_error:
434 _evas_cache_image_entry_delete(cache, im);
435 return NULL;
256} 436}
257 437
258EAPI void 438EAPI void
259evas_cache_image_drop(RGBA_Image *im) 439evas_cache_image_drop(Image_Entry *im)
260{ 440{
261 Evas_Cache_Image *cache; 441 Evas_Cache_Image *cache;
262 442
@@ -266,72 +446,59 @@ evas_cache_image_drop(RGBA_Image *im)
266 im->references--; 446 im->references--;
267 cache = im->cache; 447 cache = im->cache;
268 448
269// if (im->cache_key) printf("DROP %s -> ref = %i\n", im->cache_key, im->references); 449 if (im->flags.dirty)
270 if ((im->flags & RGBA_IMAGE_IS_DIRTY) == RGBA_IMAGE_IS_DIRTY)
271 { 450 {
272// printf("IMG %p %ix%i %s SUB %i\n", 451 _evas_cache_image_entry_delete(cache, im);
273// im, im->image->w, im->image->h, im->cache_key,
274// cache->func.mem_size_get(im));
275//// don't decrement cache usage - unless we remove from the lru
276// cache->usage -= cache->func.mem_size_get(im);
277// if (im->cache_key) printf("IM-- %s, cache = %i\n", im->cache_key, cache->usage);
278 cache->dirty = evas_object_list_remove(cache->dirty, im);
279 if (cache->func.debug)
280 cache->func.debug("drop", im);
281
282 cache->func.destructor(im);
283 evas_common_image_delete(im);
284
285 return ; 452 return ;
286 } 453 }
287 454
288 if (im->references == 0) 455 if (im->references == 0)
289 { 456 {
290 cache->activ = evas_hash_del(cache->activ, im->cache_key, im); 457 _evas_cache_image_remove_activ(cache, im);
291 cache->inactiv = evas_hash_direct_add(cache->inactiv, im->cache_key, im); 458 _evas_cache_image_make_inactiv(cache, im, im->cache_key);
292 cache->lru = evas_object_list_prepend(cache->lru, im);
293
294// printf("IMG %p %ix%i %s ADD %i\n",
295// im, im->image->w, im->image->h, im->cache_key,
296// cache->func.mem_size_get(im));
297 cache->usage += cache->func.mem_size_get(im);
298// printf("FLUSH!\n");
299 evas_cache_image_flush(cache); 459 evas_cache_image_flush(cache);
300 } 460 }
301} 461}
302 462
303EAPI RGBA_Image * 463EAPI void
304evas_cache_image_dirty(RGBA_Image *im, int x, int y, int w, int h) 464evas_cache_image_data_not_needed(Image_Entry *im)
305{ 465{
306 RGBA_Image *im_dirty = im;
307 Evas_Cache_Image *cache; 466 Evas_Cache_Image *cache;
308 467
309 assert(im); 468 assert(im);
310 assert(im->cache); 469 assert(im->cache);
311 470
312 cache = im->cache; 471 cache = im->cache;
313 if (!(im->flags & RGBA_IMAGE_IS_DIRTY)) 472
473 if (im->references > 1) return ;
474 if (im->flags.dirty || !im->flags.need_data) return ;
475
476 _evas_cache_image_activ_lru_nodata(cache, im);
477}
478
479EAPI Image_Entry *
480evas_cache_image_dirty(Image_Entry *im, int x, int y, int w, int h)
481{
482 Image_Entry *im_dirty = im;
483 Evas_Cache_Image *cache;
484
485 assert(im);
486 assert(im->cache);
487
488 cache = im->cache;
489 if (!(im->flags.dirty))
314 { 490 {
315 if (im->references == 1) 491 if (im->references == 1)
316 { 492 {
317 if (im->cache_key) 493 _evas_cache_image_remove_activ(cache, im);
318 {
319 cache->activ = evas_hash_del(cache->activ, im->cache_key, im);
320 evas_stringshare_del(im->cache_key);
321 im->cache_key = NULL;
322 }
323 im_dirty = im; 494 im_dirty = im;
324 } 495 }
325 else 496 else
326 { 497 {
327 int error; 498 int error;
328 499
329 im_dirty = evas_common_image_new(); 500 im_dirty = _evas_cache_image_entry_new(cache, NULL, im->timestamp, im->file, im->key, &im->load_opts, &error);
330 if (!im_dirty) goto on_error; 501 if (!im_dirty) goto on_error;
331 im_dirty->image = evas_common_image_surface_new(im);
332 if (!im_dirty->image) goto on_error;
333 im_dirty->image->w = w;
334 im_dirty->image->h = h;
335 502
336 if (cache->func.debug) 503 if (cache->func.debug)
337 cache->func.debug("dirty-src", im); 504 cache->func.debug("dirty-src", im);
@@ -341,34 +508,32 @@ evas_cache_image_dirty(RGBA_Image *im, int x, int y, int w, int h)
341 508
342 if (error != 0) goto on_error; 509 if (error != 0) goto on_error;
343 510
344 im_dirty->cache = cache;
345 im_dirty->references = 1; 511 im_dirty->references = 1;
346 512
347 evas_cache_image_drop(im); 513 evas_cache_image_drop(im);
348 } 514 }
349 515
350 im_dirty->flags |= RGBA_IMAGE_IS_DIRTY; 516 _evas_cache_image_make_dirty(cache, im_dirty);
351 cache->dirty = evas_object_list_prepend(cache->dirty, im_dirty);
352 } 517 }
353 518
354 if (cache->func.debug) 519 if (cache->func.debug)
355 cache->func.debug("dirty-region", im_dirty); 520 cache->func.debug("dirty-region", im_dirty);
356 if (cache->func.dirty_region) 521 if (cache->func.dirty_region)
357 cache->func.dirty_region(im_dirty, x, y, w, h); 522 cache->func.dirty_region(im_dirty, x, y, w, h);
358 523
359 return im_dirty; 524 return im_dirty;
360 525
361 on_error: 526 on_error:
362 if (im_dirty) evas_common_image_delete(im_dirty); 527 if (im_dirty) _evas_cache_image_entry_delete(cache, im_dirty);
363 evas_cache_image_drop(im); 528 evas_cache_image_drop(im);
364 return NULL; 529 return NULL;
365} 530}
366 531
367EAPI RGBA_Image * 532EAPI Image_Entry *
368evas_cache_image_alone(RGBA_Image *im) 533evas_cache_image_alone(Image_Entry *im)
369{ 534{
370 RGBA_Image *im_dirty = im; 535 Evas_Cache_Image *cache;
371 Evas_Cache_Image *cache; 536 Image_Entry *im_dirty = im;
372 537
373 assert(im); 538 assert(im);
374 assert(im->cache); 539 assert(im->cache);
@@ -376,28 +541,18 @@ evas_cache_image_alone(RGBA_Image *im)
376 cache = im->cache; 541 cache = im->cache;
377 if (im->references == 1) 542 if (im->references == 1)
378 { 543 {
379 if (!(im->flags & RGBA_IMAGE_IS_DIRTY)) 544 if (!(im->flags.dirty))
380 { 545 {
381 if (im->cache_key) 546 _evas_cache_image_remove_activ(cache, im);
382 { 547 _evas_cache_image_make_dirty(cache, im);
383 cache->activ = evas_hash_del(cache->activ, im->cache_key, im);
384 evas_stringshare_del(im->cache_key);
385 im->cache_key = NULL;
386 }
387 im->flags |= RGBA_IMAGE_IS_DIRTY;
388 cache->dirty = evas_object_list_prepend(cache->dirty, im);
389 } 548 }
390 } 549 }
391 else 550 else
392 { 551 {
393 int error; 552 int error;
394 553
395 im_dirty = evas_common_image_new(); 554 im_dirty = _evas_cache_image_entry_new(cache, NULL, im->timestamp, im->file, im->key, &im->load_opts, &error);
396 if (!im_dirty) goto on_error; 555 if (!im_dirty) goto on_error;
397 im_dirty->image = evas_common_image_surface_new(im);
398 if (!im_dirty->image) goto on_error;
399 im_dirty->image->w = im->image->w;
400 im_dirty->image->h = im->image->h;
401 556
402 if (cache->func.debug) 557 if (cache->func.debug)
403 cache->func.debug("dirty-src", im); 558 cache->func.debug("dirty-src", im);
@@ -407,46 +562,23 @@ evas_cache_image_alone(RGBA_Image *im)
407 562
408 if (error != 0) goto on_error; 563 if (error != 0) goto on_error;
409 564
410 if (im_dirty->cache_key)
411 {
412 evas_stringshare_del(im_dirty->cache_key);
413 im_dirty->cache_key = NULL;
414 }
415 im_dirty->flags |= RGBA_IMAGE_IS_DIRTY;
416 im_dirty->references = 1; 565 im_dirty->references = 1;
417 566
418 cache->dirty = evas_object_list_prepend(cache->dirty, im_dirty);
419
420 evas_cache_image_drop(im); 567 evas_cache_image_drop(im);
421 } 568 }
422 569
423 return im_dirty; 570 return im_dirty;
424 571
425 on_error: 572 on_error:
426 if (im_dirty) evas_common_image_delete(im_dirty); 573 if (im_dirty) _evas_cache_image_entry_delete(cache, im_dirty);
427 evas_cache_image_drop(im); 574 evas_cache_image_drop(im);
428 return NULL; 575 return NULL;
429} 576}
430 577
431static RGBA_Image * 578EAPI Image_Entry *
432_evas_cache_image_push_dirty(Evas_Cache_Image *cache, RGBA_Image *im)
433{
434 cache->dirty = evas_object_list_prepend(cache->dirty, im);
435
436 im->flags |= RGBA_IMAGE_IS_DIRTY;
437 if (im->cache_key)
438 {
439 evas_stringshare_del(im->cache_key);
440 im->cache_key = NULL;
441 }
442 im->cache = cache;
443 return im;
444}
445
446EAPI RGBA_Image *
447evas_cache_image_copied_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace) 579evas_cache_image_copied_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace)
448{ 580{
449 RGBA_Image *im; 581 Image_Entry *im;
450 582
451 assert(cache); 583 assert(cache);
452 584
@@ -454,122 +586,132 @@ evas_cache_image_copied_data(Evas_Cache_Image *cache, int w, int h, DATA32 *imag
454 (cspace == EVAS_COLORSPACE_YCBCR422P709_PL)) 586 (cspace == EVAS_COLORSPACE_YCBCR422P709_PL))
455 w &= ~0x1; 587 w &= ~0x1;
456 588
457 im = evas_common_image_create(w, h); 589 im = _evas_cache_image_entry_new(cache, NULL, 0, NULL, NULL, NULL, NULL);
458 if (!im) return NULL; 590 if (!im) return NULL;
591 im->space = cspace;
592
593 _evas_cache_image_entry_surface_alloc(cache, im, w, h);
459 594
460 if (cache->func.copied_data(im, w, h, image_data, alpha, cspace) != 0) 595 if (cache->func.copied_data(im, w, h, image_data, alpha, cspace) != 0)
461 { 596 {
462 evas_common_image_delete(im); 597 _evas_cache_image_entry_delete(cache, im);
463 return NULL; 598 return NULL;
464 } 599 }
600 im->references = 1;
465 601
466 return _evas_cache_image_push_dirty(cache, im); 602 if (cache->func.debug)
603 cache->func.debug("copied-data", im);
604 return im;
467} 605}
468 606
469EAPI RGBA_Image * 607EAPI Image_Entry *
470evas_cache_image_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace) 608evas_cache_image_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace)
471{ 609{
472 RGBA_Image *im; 610 Image_Entry *im;
473 611
474 assert(cache); 612 assert(cache);
475 613
476 im = evas_common_image_new(); 614 im = _evas_cache_image_entry_new(cache, NULL, 0, NULL, NULL, NULL, NULL);
477 if (!im) return NULL; 615 im->w = w;
478 im->image = evas_common_image_surface_new(im); 616 im->h = h;
479 if (!im->image)
480 {
481 evas_common_image_delete(im);
482 return NULL;
483 }
484 617
485 if (cache->func.data(im, w, h, image_data, alpha, cspace) != 0) 618 if (cache->func.data(im, w, h, image_data, alpha, cspace) != 0)
486 { 619 {
487 evas_common_image_delete(im); 620 _evas_cache_image_entry_delete(cache, im);
488 return NULL; 621 return NULL;
489 } 622 }
623 im->references = 1;
490 624
491 return _evas_cache_image_push_dirty(cache, im); 625 if (cache->func.debug)
626 cache->func.debug("data", im);
627 return im;
492} 628}
493 629
494EAPI RGBA_Image * 630EAPI void
495evas_cache_image_size_set(RGBA_Image *im, int w, int h) 631evas_cache_image_surface_alloc(Image_Entry *im, int w, int h)
632{
633 Evas_Cache_Image *cache;
634
635 assert(im);
636 assert(im->cache);
637
638 cache = im->cache;
639
640 _evas_cache_image_entry_surface_alloc(cache, im, w, h);
641
642 if (cache->func.debug)
643 cache->func.debug("surface-alloc", im);
644}
645
646EAPI Image_Entry *
647evas_cache_image_size_set(Image_Entry *im, int w, int h)
496{ 648{
497 Evas_Cache_Image *cache; 649 Evas_Cache_Image *cache;
498 RGBA_Image *new; 650 Image_Entry *new;
499 int error; 651 int error;
500 652
501 assert(im); 653 assert(im);
502 assert(im->image);
503 assert(im->cache); 654 assert(im->cache);
504 assert(im->references > 0); 655 assert(im->references > 0);
505 656
506 if ((im->image->w == w) && (im->image->h == h)) 657 if ((im->w == w) && (im->h == h))
507 return im; 658 return im;
508 659
509 cache = im->cache; 660 cache = im->cache;
510 661
511 new = evas_common_image_new(); 662 new = _evas_cache_image_entry_new(cache, NULL, 0, NULL, NULL, NULL, &error);
512 if (!new) goto on_error; 663 if (!new) goto on_error;
513 new->image = evas_common_image_surface_new(im);
514 if (!new->image) goto on_error;
515 new->image->w = w;
516 new->image->h = h;
517 664
518 if (cache->func.debug) 665 _evas_cache_image_entry_surface_alloc(cache, new, w, h);
519 cache->func.debug("size_set-in", im);
520 error = cache->func.size_set(new, im, w, h);
521 if (cache->func.debug)
522 cache->func.debug("size_set-out", new);
523 666
524 if (error != 0) goto on_error; 667 new->space = im->space;
668 new->load_opts = im->load_opts;
525 669
526 new->cache = cache; 670 error = cache->func.size_set(new, im, w, h);
527 new->cache_key = NULL; 671 if (error != 0) goto on_error;
528 672
529 new->references = 1; 673 new->references = 1;
530// cache->usage += cache->func.mem_size_get(new);
531
532 if (((im->flags & RGBA_IMAGE_IS_DIRTY) == RGBA_IMAGE_IS_DIRTY)
533 || (im->references > 1))
534 {
535 new->flags |= RGBA_IMAGE_IS_DIRTY;
536 cache->dirty = evas_object_list_prepend(cache->dirty, new);
537 }
538 else
539 {
540 new->cache_key = im->cache_key ? evas_stringshare_add(im->cache_key) : NULL;
541 cache->activ = evas_hash_direct_add(cache->activ, new->cache_key, new);
542 }
543 674
544 evas_cache_image_drop(im); 675 evas_cache_image_drop(im);
545 676
677 if (cache->func.debug)
678 cache->func.debug("size_set", new);
679
546 return new; 680 return new;
547 681
548 on_error: 682 on_error:
549 if (new) evas_common_image_delete(new); 683 if (new) _evas_cache_image_entry_delete(cache, new);
550 evas_cache_image_drop(im); 684 evas_cache_image_drop(im);
551 return NULL; 685 return NULL;
552} 686}
553 687
554EAPI void 688EAPI void
555evas_cache_image_load_data(RGBA_Image *im) 689evas_cache_image_load_data(Image_Entry *im)
556{ 690{
557 Evas_Cache_Image *cache; 691 Evas_Cache_Image *cache;
692 int error;
558 693
559 assert(im); 694 assert(im);
560 assert(im->image);
561 assert(im->cache); 695 assert(im->cache);
562 696
563 if ((im->flags & RGBA_IMAGE_LOADED) == RGBA_IMAGE_LOADED) return ; 697 if (im->flags.loaded) return ;
564 698
565 cache = im->cache; 699 cache = im->cache;
700
701 error = cache->func.load(im);
702
566 if (cache->func.debug) 703 if (cache->func.debug)
567 cache->func.debug("load", im); 704 cache->func.debug("load", im);
568 705
569 cache->func.load(im); 706 if (error)
570 im->flags |= RGBA_IMAGE_LOADED; 707 {
708 _evas_cache_image_entry_surface_alloc(cache, im, im->w, im->h);
709 im->flags.loaded = 0;
710
711 return ;
712 }
571 713
572 assert(im->image->data); 714 im->flags.loaded = 1;
573} 715}
574 716
575EAPI int 717EAPI int
@@ -583,58 +725,53 @@ evas_cache_image_flush(Evas_Cache_Image *cache)
583 725
584 while ((cache->lru) && (cache->limit < cache->usage)) 726 while ((cache->lru) && (cache->limit < cache->usage))
585 { 727 {
586 RGBA_Image *im; 728 Image_Entry *im;
587 729
588 im = (RGBA_Image *) cache->lru->last; 730 im = (Image_Entry *) cache->lru->last;
589 cache->lru = evas_object_list_remove(cache->lru, im); 731 _evas_cache_image_entry_delete(cache, im);
590 cache->inactiv = evas_hash_del(cache->inactiv, im->cache_key, im); 732 }
591// printf("IMG %p %ix%i %s SUB %i\n", 733
592// im, im->image->w, im->image->h, im->cache_key, 734 while ((cache->lru_nodata) && (cache->limit < cache->usage))
593// cache->func.mem_size_get(im)); 735 {
594 cache->usage -= cache->func.mem_size_get(im); 736 Image_Entry *im;
737
738 im = (Image_Entry *) cache->lru_nodata->last;
739 _evas_cache_image_remove_lru_nodata(cache, im);
740
741 cache->func.surface_delete(im);
595 742
596 if (im->cache_key) 743 im->flags.loaded = 0;
597 {
598 evas_stringshare_del(im->cache_key);
599 im->cache_key = NULL;
600 }
601// printf("DEL IMG FROM CACHE\n");
602 cache->func.destructor(im);
603 evas_common_image_delete(im);
604 } 744 }
745
605 return cache->usage; 746 return cache->usage;
606} 747}
607 748
608EAPI RGBA_Image * 749EAPI Image_Entry *
609evas_cache_image_empty(Evas_Cache_Image *cache) 750evas_cache_image_empty(Evas_Cache_Image *cache)
610{ 751{
611 RGBA_Image *new; 752 Image_Entry *new;
612 753
613 new = evas_common_image_new(); 754 new = _evas_cache_image_entry_new(cache, NULL, 0, NULL, NULL, NULL, NULL);
614 if (!new) goto on_error; 755 if (!new) return NULL;
615 new->image = evas_common_image_surface_new(new);
616 if (!new->image) goto on_error;
617 756
618 new->cache = cache;
619 new->references = 1; 757 new->references = 1;
620 758
621 new->cache_key = NULL;
622 new->flags |= RGBA_IMAGE_IS_DIRTY;
623
624 cache->dirty = evas_object_list_prepend(cache->dirty, new);
625
626 return new; 759 return new;
627
628 on_error:
629 if (new) evas_common_image_delete(new);
630 return NULL;
631} 760}
632 761
633EAPI void 762EAPI void
634evas_cache_image_colorspace(RGBA_Image *im, int cspace) 763evas_cache_image_colorspace(Image_Entry *im, int cspace)
635{ 764{
765 Evas_Cache_Image *cache;
766
767 assert(im);
768 assert(im->cache);
769
770 cache = im->cache;
771
636 if (!im) return ; 772 if (!im) return ;
637 if (im->cs.space == cspace) return ; 773 if (im->space == cspace) return ;
638 774
639 evas_common_image_colorspace_set(im, cspace); 775 im->space = cspace;
776 cache->func.color_space(im, cspace);
640} 777}
diff --git a/legacy/evas/src/lib/canvas/evas_object_image.c b/legacy/evas/src/lib/canvas/evas_object_image.c
index bdd3f6b0dd..cd74a93db6 100644
--- a/legacy/evas/src/lib/canvas/evas_object_image.c
+++ b/legacy/evas/src/lib/canvas/evas_object_image.c
@@ -1121,18 +1121,17 @@ evas_object_image_save(const Evas_Object *obj, const char *file, const char *key
1121 else break; 1121 else break;
1122 } 1122 }
1123 } 1123 }
1124 im = evas_cache_image_empty(evas_common_image_cache_get()); 1124 im = (RGBA_Image*) evas_cache_image_data(evas_common_image_cache_get(),
1125 o->cur.image.w,
1126 o->cur.image.h,
1127 data,
1128 o->cur.has_alpha,
1129 EVAS_COLORSPACE_ARGB8888);
1125 if (im) 1130 if (im)
1126 { 1131 {
1127 if (o->cur.has_alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA;
1128
1129 im->image->data = data;
1130 im->image->w = o->cur.image.w;
1131 im->image->h = o->cur.image.h;
1132 im->image->no_free = 1;
1133 ok = evas_common_save_image_to_file(im, file, key, quality, compress); 1132 ok = evas_common_save_image_to_file(im, file, key, quality, compress);
1134 1133
1135 evas_cache_image_drop(im); 1134 evas_cache_image_drop(&im->cache_entry);
1136 } 1135 }
1137 return ok; 1136 return ok;
1138} 1137}
@@ -2332,7 +2331,7 @@ static int
2332evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y) 2331evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2333{ 2332{
2334 Evas_Object_Image *o; 2333 Evas_Object_Image *o;
2335 void *data; 2334 DATA32 *data;
2336 int w, h, stride; 2335 int w, h, stride;
2337 int a; 2336 int a;
2338 2337
@@ -2354,7 +2353,7 @@ evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2354 o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output, 2353 o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
2355 o->engine_data, 2354 o->engine_data,
2356 0, 2355 0,
2357 (DATA32**) &data); 2356 &data);
2358 if (!data) 2357 if (!data)
2359 return 0; 2358 return 0;
2360 2359
@@ -2365,8 +2364,8 @@ evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2365 a = (*((DATA32*)(data)) >> 24) & 0xff; 2364 a = (*((DATA32*)(data)) >> 24) & 0xff;
2366 break; 2365 break;
2367 case EVAS_COLORSPACE_RGB565_A5P: 2366 case EVAS_COLORSPACE_RGB565_A5P:
2368 data = ((DATA16*)(data) + (h * stride)); 2367 data = (void*) ((DATA16*)(data) + (h * stride));
2369 data = ((DATA8*)(data) + ((y * stride) + x)); 2368 data = (void*) ((DATA8*)(data) + ((y * stride) + x));
2370 a = (*((DATA8*)(data))) & 0x1f; 2369 a = (*((DATA8*)(data))) & 0x1f;
2371 break; 2370 break;
2372 default: 2371 default:
diff --git a/legacy/evas/src/lib/engines/Makefile.am b/legacy/evas/src/lib/engines/Makefile.am
index e6a8855883..13f48e3b6a 100644
--- a/legacy/evas/src/lib/engines/Makefile.am
+++ b/legacy/evas/src/lib/engines/Makefile.am
@@ -2,4 +2,4 @@
2MAINTAINERCLEANFILES = Makefile.in 2MAINTAINERCLEANFILES = Makefile.in
3 3
4SUBDIRS = \ 4SUBDIRS = \
5common 5common common_16
diff --git a/legacy/evas/src/lib/engines/common/evas_blit_main.c b/legacy/evas/src/lib/engines/common/evas_blit_main.c
index 637924b11a..208f4351ef 100644
--- a/legacy/evas/src/lib/engines/common/evas_blit_main.c
+++ b/legacy/evas/src/lib/engines/common/evas_blit_main.c
@@ -32,7 +32,7 @@ evas_common_blit_rectangle(const RGBA_Image *src, RGBA_Image *dst, int src_x, in
32 32
33 /* clip clip clip */ 33 /* clip clip clip */
34 if (w <= 0) return; 34 if (w <= 0) return;
35 if (src_x + w > src->image->w) w = src->image->w - src_x; 35 if (src_x + w > src->cache_entry.w) w = src->cache_entry.w - src_x;
36 if (w <= 0) return; 36 if (w <= 0) return;
37 if (src_x < 0) 37 if (src_x < 0)
38 { 38 {
@@ -43,7 +43,7 @@ evas_common_blit_rectangle(const RGBA_Image *src, RGBA_Image *dst, int src_x, in
43 if (w <= 0) return; 43 if (w <= 0) return;
44 44
45 if (h <= 0) return; 45 if (h <= 0) return;
46 if (src_y + h > src->image->h) h = src->image->h - src_y; 46 if (src_y + h > src->cache_entry.h) h = src->cache_entry.h - src_y;
47 if (h <= 0) return; 47 if (h <= 0) return;
48 if (src_y < 0) 48 if (src_y < 0)
49 { 49 {
@@ -54,7 +54,7 @@ evas_common_blit_rectangle(const RGBA_Image *src, RGBA_Image *dst, int src_x, in
54 if (h <= 0) return; 54 if (h <= 0) return;
55 55
56 if (w <= 0) return; 56 if (w <= 0) return;
57 if (dst_x + w > dst->image->w) w = dst->image->w - dst_x; 57 if (dst_x + w > dst->cache_entry.w) w = dst->cache_entry.w - dst_x;
58 if (w <= 0) return; 58 if (w <= 0) return;
59 if (dst_x < 0) 59 if (dst_x < 0)
60 { 60 {
@@ -65,7 +65,7 @@ evas_common_blit_rectangle(const RGBA_Image *src, RGBA_Image *dst, int src_x, in
65 if (w <= 0) return; 65 if (w <= 0) return;
66 66
67 if (h <= 0) return; 67 if (h <= 0) return;
68 if (dst_y + h > dst->image->h) h = dst->image->h - dst_y; 68 if (dst_y + h > dst->cache_entry.h) h = dst->cache_entry.h - dst_y;
69 if (h <= 0) return; 69 if (h <= 0) return;
70 if (dst_y < 0) 70 if (dst_y < 0)
71 { 71 {
@@ -78,13 +78,13 @@ evas_common_blit_rectangle(const RGBA_Image *src, RGBA_Image *dst, int src_x, in
78 if (dst == src) 78 if (dst == src)
79 { 79 {
80 /* src after dst - go forward */ 80 /* src after dst - go forward */
81 if (((src_y * src->image->w) + src_x) > ((dst_y * dst->image->w) + dst_x)) 81 if (((src_y * src->cache_entry.w) + src_x) > ((dst_y * dst->cache_entry.w) + dst_x))
82 { 82 {
83 func = evas_common_draw_func_copy_get(w, 0); 83 func = evas_common_draw_func_copy_get(w, 0);
84 for (y = 0; y < h; y++) 84 for (y = 0; y < h; y++)
85 { 85 {
86 src_ptr = src->image->data + ((y + src_y) * src->image->w) + src_x; 86 src_ptr = src->image.data + ((y + src_y) * src->cache_entry.w) + src_x;
87 dst_ptr = dst->image->data + ((y + dst_y) * dst->image->w) + dst_x; 87 dst_ptr = dst->image.data + ((y + dst_y) * dst->cache_entry.w) + dst_x;
88 func(src_ptr, dst_ptr, w); 88 func(src_ptr, dst_ptr, w);
89 } 89 }
90 } 90 }
@@ -94,8 +94,8 @@ evas_common_blit_rectangle(const RGBA_Image *src, RGBA_Image *dst, int src_x, in
94 func = evas_common_draw_func_copy_get(w, 1); 94 func = evas_common_draw_func_copy_get(w, 1);
95 for (y = h - 1; y >= 0; y--) 95 for (y = h - 1; y >= 0; y--)
96 { 96 {
97 src_ptr = src->image->data + ((y + src_y) * src->image->w) + src_x; 97 src_ptr = src->image.data + ((y + src_y) * src->cache_entry.w) + src_x;
98 dst_ptr = dst->image->data + ((y + dst_y) * dst->image->w) + dst_x; 98 dst_ptr = dst->image.data + ((y + dst_y) * dst->cache_entry.w) + dst_x;
99 func(src_ptr, dst_ptr, w); 99 func(src_ptr, dst_ptr, w);
100 } 100 }
101 } 101 }
@@ -105,8 +105,8 @@ evas_common_blit_rectangle(const RGBA_Image *src, RGBA_Image *dst, int src_x, in
105 func = evas_common_draw_func_copy_get(w, 0); 105 func = evas_common_draw_func_copy_get(w, 0);
106 for (y = 0; y < h; y++) 106 for (y = 0; y < h; y++)
107 { 107 {
108 src_ptr = src->image->data + ((y + src_y) * src->image->w) + src_x; 108 src_ptr = src->image.data + ((y + src_y) * src->cache_entry.w) + src_x;
109 dst_ptr = dst->image->data + ((y + dst_y) * dst->image->w) + dst_x; 109 dst_ptr = dst->image.data + ((y + dst_y) * dst->cache_entry.w) + dst_x;
110 func(src_ptr, dst_ptr, w); 110 func(src_ptr, dst_ptr, w);
111 } 111 }
112 } 112 }
diff --git a/legacy/evas/src/lib/engines/common/evas_font_draw.c b/legacy/evas/src/lib/engines/common/evas_font_draw.c
index 21246e3765..058d430f72 100644
--- a/legacy/evas/src/lib/engines/common/evas_font_draw.c
+++ b/legacy/evas/src/lib/engines/common/evas_font_draw.c
@@ -146,9 +146,9 @@ evas_common_font_draw(RGBA_Image *dst, RGBA_Draw_Context *dc, RGBA_Font *fn, int
146 146
147 fi = fn->fonts->data; 147 fi = fn->fonts->data;
148 148
149 im = dst->image->data; 149 im = dst->image.data;
150 im_w = dst->image->w; 150 im_w = dst->cache_entry.w;
151 im_h = dst->image->h; 151 im_h = dst->cache_entry.h;
152 152
153 ext_x = 0; ext_y = 0; ext_w = im_w; ext_h = im_h; 153 ext_x = 0; ext_y = 0; ext_w = im_w; ext_h = im_h;
154 if (dc->clip.use) 154 if (dc->clip.use)
diff --git a/legacy/evas/src/lib/engines/common/evas_gradient_main.c b/legacy/evas/src/lib/engines/common/evas_gradient_main.c
index 00dbc7e3e6..3df3e2c279 100644
--- a/legacy/evas/src/lib/engines/common/evas_gradient_main.c
+++ b/legacy/evas/src/lib/engines/common/evas_gradient_main.c
@@ -432,7 +432,7 @@ evas_common_gradient_draw(RGBA_Image *dst, RGBA_Draw_Context *dc,
432 float angle; 432 float angle;
433 int direct_copy = 0, buf_step = 0; 433 int direct_copy = 0, buf_step = 0;
434 434
435 if (!dst || !dc || !gr || !dst || !dst->image || !dst->image->data) 435 if (!dst || !dc || !gr || !dst || !dst->image.data)
436 return; 436 return;
437 if (!gr->map.data || !gr->type.geometer) 437 if (!gr->map.data || !gr->type.geometer)
438 return; 438 return;
@@ -440,7 +440,7 @@ evas_common_gradient_draw(RGBA_Image *dst, RGBA_Draw_Context *dc,
440 return; 440 return;
441 if ((w < 1) || (h < 1)) 441 if ((w < 1) || (h < 1))
442 return; 442 return;
443 clx = 0; cly = 0; clw = dst->image->w; clh = dst->image->h; 443 clx = 0; cly = 0; clw = dst->cache_entry.w; clh = dst->cache_entry.h;
444 if ((clw < 1) || (clh < 1)) return; 444 if ((clw < 1) || (clh < 1)) return;
445 445
446 if (dc->clip.use) 446 if (dc->clip.use)
@@ -459,14 +459,14 @@ evas_common_gradient_draw(RGBA_Image *dst, RGBA_Draw_Context *dc,
459 if ((dc->render_op == _EVAS_RENDER_FILL) || 459 if ((dc->render_op == _EVAS_RENDER_FILL) ||
460 (dc->render_op == _EVAS_RENDER_COPY)) 460 (dc->render_op == _EVAS_RENDER_COPY))
461 { 461 {
462 direct_copy = 1; buf_step = dst->image->w; 462 direct_copy = 1; buf_step = dst->cache_entry.w;
463 if (gr->type.geometer->has_alpha(gr, dc->render_op)) 463 if (gr->type.geometer->has_alpha(gr, dc->render_op))
464 dst->flags |= RGBA_IMAGE_HAS_ALPHA; 464 dst->flags |= RGBA_IMAGE_HAS_ALPHA;
465 } 465 }
466 else if ((dc->render_op == _EVAS_RENDER_BLEND) && 466 else if ((dc->render_op == _EVAS_RENDER_BLEND) &&
467 !gr->type.geometer->has_alpha(gr, dc->render_op)) 467 !gr->type.geometer->has_alpha(gr, dc->render_op))
468 { 468 {
469 direct_copy = 1; buf_step = dst->image->w; 469 direct_copy = 1; buf_step = dst->cache_entry.w;
470 } 470 }
471 } 471 }
472 if (!direct_copy) 472 if (!direct_copy)
@@ -514,13 +514,13 @@ evas_common_gradient_draw(RGBA_Image *dst, RGBA_Draw_Context *dc,
514 514
515 map = gr->map.data; 515 map = gr->map.data;
516 len = gr->map.len; 516 len = gr->map.len;
517 pdst = dst->image->data + (y * dst->image->w) + x; 517 pdst = dst->image.data + (y * dst->cache_entry.w) + x;
518 dst_end = pdst + (h * dst->image->w); 518 dst_end = pdst + (h * dst->cache_entry.w);
519 if (!direct_copy) 519 if (!direct_copy)
520 { 520 {
521 buf = argb_buf->image->data; 521 buf = argb_buf->image.data;
522 if (alpha_buf) 522 if (alpha_buf)
523 mask = (DATA8 *)alpha_buf->image->data; 523 mask = (DATA8 *)alpha_buf->image.data;
524 } 524 }
525 else 525 else
526 buf = pdst; 526 buf = pdst;
@@ -536,7 +536,7 @@ evas_common_gradient_draw(RGBA_Image *dst, RGBA_Draw_Context *dc,
536 evas_common_cpu_end_opt(); 536 evas_common_cpu_end_opt();
537 } 537 }
538 buf += buf_step; 538 buf += buf_step;
539 pdst += dst->image->w; 539 pdst += dst->cache_entry.w;
540 yoff++; 540 yoff++;
541 } 541 }
542 542
diff --git a/legacy/evas/src/lib/engines/common/evas_image_data.c b/legacy/evas/src/lib/engines/common/evas_image_data.c
index 3fcab35ad0..27e51b6616 100644
--- a/legacy/evas/src/lib/engines/common/evas_image_data.c
+++ b/legacy/evas/src/lib/engines/common/evas_image_data.c
@@ -3,16 +3,18 @@
3 3
4#include <assert.h> 4#include <assert.h>
5 5
6EAPI int 6int
7evas_common_image_from_data(RGBA_Image* dst, int w, int h, DATA32 *image_data, int alpha, int cspace) 7evas_common_rgba_image_from_data(Image_Entry* ie_dst, int w, int h, DATA32 *image_data, int alpha, int cspace)
8{ 8{
9 RGBA_Image *dst = (RGBA_Image *) ie_dst;
10
9 switch (cspace) 11 switch (cspace)
10 { 12 {
11 case EVAS_COLORSPACE_ARGB8888: 13 case EVAS_COLORSPACE_ARGB8888:
12 dst->image->w = w; 14 dst->cache_entry.w = w;
13 dst->image->h = h; 15 dst->cache_entry.h = h;
14 dst->image->data = image_data; 16 dst->image.data = image_data;
15 dst->image->no_free = 1; 17 dst->image.no_free = 1;
16 if (alpha) 18 if (alpha)
17 dst->flags |= RGBA_IMAGE_HAS_ALPHA; 19 dst->flags |= RGBA_IMAGE_HAS_ALPHA;
18 else 20 else
@@ -21,9 +23,8 @@ evas_common_image_from_data(RGBA_Image* dst, int w, int h, DATA32 *image_data, i
21 case EVAS_COLORSPACE_YCBCR422P601_PL: 23 case EVAS_COLORSPACE_YCBCR422P601_PL:
22 case EVAS_COLORSPACE_YCBCR422P709_PL: 24 case EVAS_COLORSPACE_YCBCR422P709_PL:
23 w &= ~0x1; 25 w &= ~0x1;
24 dst->image->w = w; 26 dst->cache_entry.w = w;
25 dst->image->h = h; 27 dst->cache_entry.h = h;
26 evas_common_image_surface_alloc(dst->image);
27 dst->cs.data = image_data; 28 dst->cs.data = image_data;
28 dst->cs.no_free = 1; 29 dst->cs.no_free = 1;
29 break; 30 break;
@@ -31,14 +32,17 @@ evas_common_image_from_data(RGBA_Image* dst, int w, int h, DATA32 *image_data, i
31 abort(); 32 abort();
32 break; 33 break;
33 } 34 }
34 dst->cs.space = cspace; 35 dst->cache_entry.space = cspace;
35 evas_common_image_colorspace_dirty(dst); 36 evas_common_image_colorspace_dirty(dst);
36 return 0; 37 return 0;
37} 38}
38 39
39EAPI int 40int
40evas_common_image_from_copied_data(RGBA_Image* dst, int w, int h, DATA32 *image_data, int alpha, int cspace) 41evas_common_rgba_image_from_copied_data(Image_Entry* ie_dst, int w, int h, DATA32 *image_data, int alpha, int cspace)
41{ 42{
43 RGBA_Image *dst = (RGBA_Image *) ie_dst;
44
45 /* FIXME: Is dst->image.data valid. */
42 switch (cspace) 46 switch (cspace)
43 { 47 {
44 case EVAS_COLORSPACE_ARGB8888: 48 case EVAS_COLORSPACE_ARGB8888:
@@ -47,46 +51,49 @@ evas_common_image_from_copied_data(RGBA_Image* dst, int w, int h, DATA32 *image_
47 else 51 else
48 dst->flags &= ~RGBA_IMAGE_HAS_ALPHA; 52 dst->flags &= ~RGBA_IMAGE_HAS_ALPHA;
49 if (image_data) 53 if (image_data)
50 memcpy(dst->image->data, image_data, w * h * sizeof(DATA32)); 54 memcpy(dst->image.data, image_data, w * h * sizeof(DATA32));
51 break; 55 break;
52 case EVAS_COLORSPACE_YCBCR422P601_PL: 56 case EVAS_COLORSPACE_YCBCR422P601_PL:
53 case EVAS_COLORSPACE_YCBCR422P709_PL: 57 case EVAS_COLORSPACE_YCBCR422P709_PL:
54 dst->cs.data = calloc(1, dst->image->h * sizeof(unsigned char*) * 2); 58 dst->cs.data = calloc(1, dst->cache_entry.h * sizeof(unsigned char*) * 2);
55 if (image_data && (dst->cs.data)) 59 if (image_data && (dst->cs.data))
56 memcpy(dst->cs.data, image_data, dst->image->h * sizeof(unsigned char*) * 2); 60 memcpy(dst->cs.data, image_data, dst->cache_entry.h * sizeof(unsigned char*) * 2);
57 break; 61 break;
58 default: 62 default:
59 abort(); 63 abort();
60 break; 64 break;
61 } 65 }
62 66
63 dst->cs.space = cspace; 67 dst->cache_entry.space = cspace;
64 evas_common_image_colorspace_dirty(dst); 68 evas_common_image_colorspace_dirty(dst);
65 return 0; 69 return 0;
66} 70}
67 71
68EAPI int 72int
69evas_common_image_size_set(RGBA_Image* dst, const RGBA_Image* im, int w, int h) 73evas_common_rgba_image_size_set(Image_Entry *ie_dst, const Image_Entry *ie_im, int w, int h)
70{ 74{
71 if ((im->cs.space == EVAS_COLORSPACE_YCBCR422P601_PL) || 75 RGBA_Image *dst = (RGBA_Image *) ie_dst;
72 (im->cs.space == EVAS_COLORSPACE_YCBCR422P709_PL)) 76 RGBA_Image *im = (RGBA_Image *) ie_im;
77
78 if ((im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P601_PL) ||
79 (im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P709_PL))
73 w &= ~0x1; 80 w &= ~0x1;
74 81
75 dst->cs.space = im->cs.space;
76 dst->flags = im->flags; 82 dst->flags = im->flags;
77 dst->cs.no_free = 0; 83 dst->cs.no_free = 0;
78 if ((im->cs.space == EVAS_COLORSPACE_YCBCR422P601_PL) || 84 if ((im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P601_PL) ||
79 (im->cs.space == EVAS_COLORSPACE_YCBCR422P709_PL)) 85 (im->cache_entry.space == EVAS_COLORSPACE_YCBCR422P709_PL))
80 dst->cs.data = calloc(1, dst->image->h * sizeof(unsigned char *) * 2); 86 dst->cs.data = calloc(1, dst->cache_entry.h * sizeof(unsigned char *) * 2);
81 evas_common_image_surface_alloc(dst->image);
82 evas_common_image_colorspace_dirty(dst); 87 evas_common_image_colorspace_dirty(dst);
83 88
84 return 0; 89 return 0;
85} 90}
86 91
87EAPI int 92int
88evas_common_image_colorspace_set(RGBA_Image* dst, int cspace) 93evas_common_rgba_image_colorspace_set(Image_Entry* ie_dst, int cspace)
89{ 94{
95 RGBA_Image *dst = (RGBA_Image *) ie_dst;
96
90 switch (cspace) 97 switch (cspace)
91 { 98 {
92 case EVAS_COLORSPACE_ARGB8888: 99 case EVAS_COLORSPACE_ARGB8888:
@@ -99,24 +106,24 @@ evas_common_image_colorspace_set(RGBA_Image* dst, int cspace)
99 break; 106 break;
100 case EVAS_COLORSPACE_YCBCR422P601_PL: 107 case EVAS_COLORSPACE_YCBCR422P601_PL:
101 case EVAS_COLORSPACE_YCBCR422P709_PL: 108 case EVAS_COLORSPACE_YCBCR422P709_PL:
102 if (dst->image->no_free) 109 if (dst->image.no_free)
103 { 110 {
104 dst->image->data = NULL; 111 dst->image.data = NULL;
105 dst->image->no_free = 0; 112 dst->image.no_free = 0;
106 evas_common_image_surface_alloc(dst->image); 113 /* FIXME: Must allocate image.data surface cleanly. */
107 } 114 }
108 if (dst->cs.data) 115 if (dst->cs.data)
109 { 116 {
110 if (!dst->cs.no_free) free(dst->cs.data); 117 if (!dst->cs.no_free) free(dst->cs.data);
111 } 118 }
112 dst->cs.data = calloc(1, dst->image->h * sizeof(unsigned char *) * 2); 119 dst->cs.data = calloc(1, dst->cache_entry.h * sizeof(unsigned char *) * 2);
113 dst->cs.no_free = 0; 120 dst->cs.no_free = 0;
114 break; 121 break;
115 default: 122 default:
116 abort(); 123 abort();
117 break; 124 break;
118 } 125 }
119 dst->cs.space = cspace; 126 dst->cache_entry.space = cspace;
120 evas_common_image_colorspace_dirty(dst); 127 evas_common_image_colorspace_dirty(dst);
121 128
122 return 0; 129 return 0;
diff --git a/legacy/evas/src/lib/engines/common/evas_image_load.c b/legacy/evas/src/lib/engines/common/evas_image_load.c
index 1b41e61db6..7b80ecf74c 100644
--- a/legacy/evas/src/lib/engines/common/evas_image_load.c
+++ b/legacy/evas/src/lib/engines/common/evas_image_load.c
@@ -29,17 +29,18 @@ static struct ext_loader_s loaders[] = {
29 { "pnm", "pmaps" } 29 { "pnm", "pmaps" }
30}; 30};
31 31
32EAPI int 32int
33evas_common_load_image_module_from_file(RGBA_Image *im) 33evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
34{ 34{
35 Evas_Image_Load_Func *evas_image_load_func = NULL; 35 Evas_Image_Load_Func *evas_image_load_func = NULL;
36 RGBA_Image *im = (RGBA_Image *) ie;
36 const char *loader = NULL; 37 const char *loader = NULL;
37 char *dot;
38 Evas_List *l; 38 Evas_List *l;
39 Evas_Module *em; 39 Evas_Module *em;
40 int i; 40 char *dot;
41 int i;
41 42
42 dot = strrchr (im->info.file, '.'); 43 dot = strrchr (ie->file, '.');
43 if (dot) 44 if (dot)
44 { 45 {
45 for (i = 0, ++dot; i < (sizeof (loaders) / sizeof (struct ext_loader_s)); ++i) 46 for (i = 0, ++dot; i < (sizeof (loaders) / sizeof (struct ext_loader_s)); ++i)
@@ -61,7 +62,7 @@ evas_common_load_image_module_from_file(RGBA_Image *im)
61 { 62 {
62 evas_module_use(em); 63 evas_module_use(em);
63 evas_image_load_func = em->functions; 64 evas_image_load_func = em->functions;
64 if (evas_image_load_func->file_head(im, im->info.file, im->info.key)) 65 if (evas_image_load_func->file_head(im, ie->file, ie->key))
65 goto ok; 66 goto ok;
66 } 67 }
67 } 68 }
@@ -74,7 +75,7 @@ evas_common_load_image_module_from_file(RGBA_Image *im)
74 if (!evas_module_load(em)) continue; 75 if (!evas_module_load(em)) continue;
75 evas_image_load_func = em->functions; 76 evas_image_load_func = em->functions;
76 evas_module_use(em); 77 evas_module_use(em);
77 if (evas_image_load_func->file_head(im, im->info.file, im->info.key)) 78 if (evas_image_load_func->file_head(im, ie->file, ie->key))
78 { 79 {
79 if (evas_modules != l) 80 if (evas_modules != l)
80 { 81 {
@@ -87,39 +88,28 @@ evas_common_load_image_module_from_file(RGBA_Image *im)
87 return -1; 88 return -1;
88 89
89 ok: 90 ok:
90 im->info.module = (void *)em; 91 im->info.module = (void*) em;
91 im->info.loader = (void *)evas_image_load_func; 92 im->info.loader = (void*) evas_image_load_func;
92 evas_module_ref((Evas_Module *)im->info.module); 93 evas_module_ref((Evas_Module*) im->info.module);
93 return 0; 94 return 0;
94} 95}
95 96
96EAPI void 97int
97evas_common_load_image_data_from_file(RGBA_Image *im) 98evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
98{ 99{
99 Evas_Image_Load_Func *evas_image_load_func = NULL; 100 Evas_Image_Load_Func *evas_image_load_func = NULL;
101 RGBA_Image *im = (RGBA_Image *) ie;
100 102
101 if ((im->flags & RGBA_IMAGE_LOADED) == RGBA_IMAGE_LOADED) return; 103 if (!im->info.module) return -1;
102 if (!im->info.module) return; 104 if (ie->flags.loaded) return -1;
103 105
104 evas_image_load_func = im->info.loader; 106 evas_image_load_func = im->info.loader;
105 evas_module_use((Evas_Module *)im->info.module); 107 evas_module_use((Evas_Module*) im->info.module);
106 if (!evas_image_load_func->file_data(im, im->info.file, im->info.key)) 108 if (!evas_image_load_func->file_data(im, ie->file, ie->key))
107 { 109 return -1;
108 if (!im->image->data) evas_common_image_surface_alloc(im->image);
109 if (!im->image->data)
110 {
111 const DATA32 pixel = 0xffffffff;
112 110
113 im->image->w = 1; 111 evas_module_unref((Evas_Module*) im->info.module);
114 im->image->h = 1; 112 im->info.module = NULL;
115 im->image->data = (DATA32 *)&pixel; 113
116 im->image->no_free = 1; 114 return 0;
117 }
118 }
119 else
120 {
121 evas_module_unref((Evas_Module *)im->info.module);
122 im->info.module = NULL;
123 }
124 im->flags |= RGBA_IMAGE_LOADED;
125} 115}
diff --git a/legacy/evas/src/lib/engines/common/evas_image_main.c b/legacy/evas/src/lib/engines/common/evas_image_main.c
index a7b3c27462..64695fd553 100644
--- a/legacy/evas/src/lib/engines/common/evas_image_main.c
+++ b/legacy/evas/src/lib/engines/common/evas_image_main.c
@@ -26,28 +26,47 @@ static int reference = 0;
26#define EVAS_ALPHA_LINE_BUFFER_MIN_LEN 256 26#define EVAS_ALPHA_LINE_BUFFER_MIN_LEN 256
27#define EVAS_ALPHA_LINE_BUFFER_MAX_LEN 2048 27#define EVAS_ALPHA_LINE_BUFFER_MAX_LEN 2048
28 28
29/* The cache is doing the allocation and deallocation, you must just do the rest. */
30static void _evas_common_image_unload(RGBA_Image* im);
31 29
32static void _evas_common_image_dirty_region(RGBA_Image* im, int x, int y, int w, int h); 30static Image_Entry *_evas_common_rgba_image_new(void);
31static void _evas_common_rgba_image_delete(Image_Entry *ie);
32
33static int _evas_common_rgba_image_surface_alloc(Image_Entry *ie, int w, int h);
34static void _evas_common_rgba_image_surface_delete(Image_Entry *ie);
35
36static void _evas_common_rgba_image_unload(Image_Entry *im);
37
38static void _evas_common_rgba_image_dirty_region(Image_Entry *im, int x, int y, int w, int h);
39
40static int _evas_common_rgba_image_ram_usage(Image_Entry *ie);
33 41
34/* Only called when references > 0. Need to provide a fresh copie of im. */ 42/* Only called when references > 0. Need to provide a fresh copie of im. */
35/* The destination surface does have a surface, but no allocated pixel data. */ 43/* The destination surface does have a surface, but no allocated pixel data. */
36static int _evas_common_image_dirty(RGBA_Image* dst, const RGBA_Image* src); 44static int _evas_common_rgba_image_dirty(Image_Entry* dst, const Image_Entry* src);
45
46static void
47_evas_common_rgba_image_debug(const char* context, Image_Entry *eim)
48{
49 fprintf(stderr, "%p = [%s] {%s,%s} %i [%i|%i]\n", eim, context, eim->file, eim->key, eim->references, eim->w, eim->h);
50}
37 51
38static const Evas_Cache_Image_Func _evas_common_image_func = 52static const Evas_Cache_Image_Func _evas_common_image_func =
39{ 53{
40 evas_common_load_image_module_from_file, 54 _evas_common_rgba_image_new,
41 _evas_common_image_unload, 55 _evas_common_rgba_image_delete,
42 _evas_common_image_dirty_region, 56 _evas_common_rgba_image_surface_alloc,
43 _evas_common_image_dirty, 57 _evas_common_rgba_image_surface_delete,
44 evas_common_image_size_set, 58 evas_common_load_rgba_image_module_from_file,
45 evas_common_image_from_copied_data, 59 _evas_common_rgba_image_unload,
46 evas_common_image_from_data, 60 _evas_common_rgba_image_dirty_region,
47 evas_common_image_colorspace_set, 61 _evas_common_rgba_image_dirty,
48 evas_common_load_image_data_from_file, 62 evas_common_rgba_image_size_set,
49 evas_common_image_ram_usage, 63 evas_common_rgba_image_from_copied_data,
50 NULL 64 evas_common_rgba_image_from_data,
65 evas_common_rgba_image_colorspace_set,
66 evas_common_load_rgba_image_data_from_file,
67 _evas_common_rgba_image_ram_usage,
68/* _evas_common_rgba_image_debug */
69 NULL
51}; 70};
52 71
53EAPI void 72EAPI void
@@ -91,22 +110,67 @@ evas_common_image_shutdown(void)
91#endif 110#endif
92} 111}
93 112
94static void 113static Image_Entry *
95_evas_common_image_unload(RGBA_Image* im) 114_evas_common_rgba_image_new(void)
96{ 115{
116 RGBA_Image *im;
117
118 im = calloc(1, sizeof(RGBA_Image));
119 if (!im) return NULL;
120 im->flags = RGBA_IMAGE_NOTHING;
121 im->ref = 1;
122 return &im->cache_entry;
97} 123}
98 124
99static void 125static void
100_evas_common_image_dirty_region(RGBA_Image* im, int x, int y, int w, int h) 126_evas_common_rgba_image_delete(Image_Entry *ie)
101{ 127{
128 RGBA_Image *im = (RGBA_Image *) ie;
129
130 evas_common_pipe_free(im);
131 if (im->info.module) evas_module_unref((Evas_Module *)im->info.module);
132 /* memset the image to 0x99 because i recently saw a segv where an
133 * seemed to be used BUT its contents were wrong - it looks like it was
134 * overwritten by something from efreet - as there was an execute command
135 * for a command there and some other signs - but to make sure, I am
136 * going to empty this struct out in case this happens again so i know
137 * that something else is overwritign this struct - or not */
138 memset(im, 0x99, sizeof(im));
139 free(im);
102} 140}
103 141
104void 142static int
105evas_common_image_delete(RGBA_Image* im) 143_evas_common_rgba_image_surface_alloc(Image_Entry *ie, int w, int h)
106{ 144{
107 if ((im->cs.data) && (im->image->data)) 145 RGBA_Image *im = (RGBA_Image *) ie;
146 size_t siz = 0;
147
148/* if (im->image.data) /\* return 0; *\/ */
149/* free(im->image.data); */
150
151 if (im->flags & RGBA_IMAGE_ALPHA_ONLY)
152 siz = w * h * sizeof(DATA8);
153 else
154 siz = w * h * sizeof(DATA32);
155
156 im->image.data = realloc(im->image.data, siz);
157 if (im->image.data == NULL) return -1;
158
159#ifdef HAVE_VALGRIND
160 VALGRIND_MAKE_READABLE(im->image.data, siz);
161#endif
162
163 return 0;
164}
165
166static void
167_evas_common_rgba_image_surface_delete(Image_Entry *ie)
168{
169 RGBA_Image *im = (RGBA_Image *) ie;
170
171 if ((im->cs.data) && (im->image.data))
108 { 172 {
109 if (im->cs.data != im->image->data) 173 if (im->cs.data != im->image.data)
110 { 174 {
111 if (!im->cs.no_free) free(im->cs.data); 175 if (!im->cs.no_free) free(im->cs.data);
112 } 176 }
@@ -115,34 +179,54 @@ evas_common_image_delete(RGBA_Image* im)
115 { 179 {
116 if (!im->cs.no_free) free(im->cs.data); 180 if (!im->cs.no_free) free(im->cs.data);
117 } 181 }
118
119 im->cs.data = NULL; 182 im->cs.data = NULL;
120 evas_common_pipe_free(im); 183
121 if (im->image) evas_common_image_surface_free(im->image); 184 if (im->image.data && !im->image.no_free)
122 if (im->info.file) evas_stringshare_del(im->info.file); 185 free(im->image.data);
123 if (im->info.key) evas_stringshare_del(im->info.key); 186 im->image.data = NULL;
124 if (im->info.module) evas_module_unref((Evas_Module *)im->info.module); 187 im->image.no_free = 1;
125 /* memset the image to 0x99 because i recently saw a segv where an 188}
126 * seemed to be used BUT its contents were wrong - it looks like it was 189
127 * overwritten by something from efreet - as there was an execute command 190static void
128 * for a command there and some other signs - but to make sure, I am 191_evas_common_rgba_image_unload(Image_Entry* im)
129 * going to empty this struct out in case this happens again so i know 192{
130 * that something else is overwritign this struct - or not */ 193}
131 memset(im, 0x99, sizeof(im)); 194
132 free(im); 195static void
196_evas_common_rgba_image_dirty_region(Image_Entry* im, int x, int y, int w, int h)
197{
133} 198}
134 199
135/* Only called when references > 0. Need to provide a fresh copie of im. */ 200/* Only called when references > 0. Need to provide a fresh copie of im. */
136static int 201static int
137_evas_common_image_dirty(RGBA_Image* dst, const RGBA_Image* src) 202_evas_common_rgba_image_dirty(Image_Entry *ie_dst, const Image_Entry *ie_src)
138{ 203{
139 evas_common_load_image_data_from_file(src); 204 RGBA_Image *dst = (RGBA_Image *) ie_dst;
205 RGBA_Image *src = (RGBA_Image *) ie_src;
206
207 evas_cache_image_load_data(&src->cache_entry);
208 if (_evas_common_rgba_image_surface_alloc(&dst->cache_entry,
209 src->cache_entry.w, src->cache_entry.h))
210 return 1;
211
140 evas_common_image_colorspace_normalize(src); 212 evas_common_image_colorspace_normalize(src);
141 evas_common_image_colorspace_normalize(dst); 213 evas_common_image_colorspace_normalize(dst);
142 evas_common_image_surface_alloc(dst->image); 214/* evas_common_blit_rectangle(src, dst, 0, 0, src->cache_entry.w, src->cache_entry.h, 0, 0); */
143 evas_common_blit_rectangle(src, dst, 0, 0, src->image->w, src->image->h, 0, 0); 215/* evas_common_cpu_end_opt(); */
144 evas_common_cpu_end_opt(); 216
217 return 0;
218}
145 219
220static int
221_evas_common_rgba_image_ram_usage(Image_Entry *ie)
222{
223 RGBA_Image *im = (RGBA_Image *) ie;
224
225// ram += sizeof(struct _RGBA_Image);
226// if (im->info.real_file) ram += strlen(im->info.real_file);
227// if (im->info.comment) ram += strlen(im->info.comment);
228 if ((im->image.data) && (!im->image.no_free))
229 return im->cache_entry.w * im->cache_entry.h * sizeof(DATA32);
146 return 0; 230 return 0;
147} 231}
148 232
@@ -212,138 +296,73 @@ evas_common_image_surface_alpha_tiles_calc(RGBA_Surface *is, int tsize)
212} 296}
213#endif 297#endif
214 298
215EAPI RGBA_Surface * 299/* EAPI void */
216evas_common_image_surface_new(RGBA_Image *im) 300/* evas_common_image_surface_dealloc(RGBA_Surface *is) */
217{ 301/* { */
218 RGBA_Surface *is; 302/* if ((is->data) && (!is->no_free)) */
219 303/* { */
220 is = calloc(1, sizeof(RGBA_Surface)); 304/* free(is->data); */
221 is->im = im; 305/* is->data = NULL; */
222 return is; 306/* } */
223} 307/* } */
224 308
225EAPI void 309static RGBA_Image *
226evas_common_image_surface_free(RGBA_Surface *is)
227{
228 evas_common_image_surface_dealloc(is);
229 free(is);
230}
231
232EAPI void
233evas_common_image_surface_alloc(RGBA_Surface *is)
234{
235 size_t siz = 0;
236
237 if (is->data) return ;
238
239 if (is->im->flags & RGBA_IMAGE_ALPHA_ONLY)
240 siz = is->w * is->h * sizeof(DATA8);
241 else
242 siz = is->w * is->h * sizeof(DATA32);
243
244 is->data = malloc(siz);
245
246#ifdef HAVE_VALGRIND
247 VALGRIND_MAKE_READABLE(is->data, siz);
248#endif
249}
250
251EAPI void
252evas_common_image_surface_dealloc(RGBA_Surface *is)
253{
254 if ((is->data) && (!is->no_free))
255 {
256 free(is->data);
257 is->data = NULL;
258 }
259}
260
261EAPI RGBA_Image *
262evas_common_image_create(int w, int h) 310evas_common_image_create(int w, int h)
263{ 311{
264 RGBA_Image *im; 312 RGBA_Image *im;
265 313
266 im = evas_common_image_new(); 314 im = (RGBA_Image *) _evas_common_rgba_image_new();
267 if (!im) return NULL; 315 if (!im) return NULL;
268 im->image = evas_common_image_surface_new(im); 316 im->cache_entry.w = w;
269 if (!im->image) 317 im->cache_entry.h = h;
270 { 318 if (_evas_common_rgba_image_surface_alloc(&im->cache_entry, w, h))
271 evas_common_image_delete(im);
272 return NULL;
273 }
274 im->image->w = w;
275 im->image->h = h;
276 evas_common_image_surface_alloc(im->image);
277 if (!im->image->data)
278 { 319 {
279 evas_common_image_delete(im); 320 _evas_common_rgba_image_delete(&im->cache_entry);
280 return NULL; 321 return NULL;
281 } 322 }
282 im->flags = RGBA_IMAGE_IS_DIRTY; 323 im->cache_entry.flags.cached = 0;
283 im->references = 1;
284 return im; 324 return im;
285} 325}
286 326
287EAPI RGBA_Image * 327EAPI RGBA_Image *
288evas_common_image_alpha_create(int w, int h) 328evas_common_image_alpha_create(int w, int h)
289{ 329{
290 RGBA_Image *im; 330 RGBA_Image *im;
291 331
292 im = evas_common_image_new(); 332 im = (RGBA_Image *) _evas_common_rgba_image_new();
293 if (!im) return NULL; 333 if (!im) return NULL;
294 im->image = evas_common_image_surface_new(im); 334 im->cache_entry.w = w;
295 if (!im->image) 335 im->cache_entry.h = h;
296 {
297 evas_common_image_delete(im);
298 return NULL;
299 }
300 im->image->w = w;
301 im->image->h = h;
302 im->flags |= RGBA_IMAGE_ALPHA_ONLY; 336 im->flags |= RGBA_IMAGE_ALPHA_ONLY;
303 evas_common_image_surface_alloc(im->image); 337 if (_evas_common_rgba_image_surface_alloc(&im->cache_entry, w, h))
304 if (!im->image->data)
305 { 338 {
306 evas_common_image_delete(im); 339 _evas_common_rgba_image_delete(&im->cache_entry);
307 return NULL; 340 return NULL;
308 } 341 }
309 im->flags = RGBA_IMAGE_IS_DIRTY; 342 im->cache_entry.flags.cached = 0;
310 im->references = 1;
311 return im; 343 return im;
312} 344}
313 345
314EAPI RGBA_Image * 346void
315evas_common_image_new(void)
316{
317 RGBA_Image *im;
318
319 im = calloc(1, sizeof(RGBA_Image));
320 if (!im) return NULL;
321 im->flags = RGBA_IMAGE_NOTHING;
322 im->ref = 1;
323 im->cs.space = EVAS_COLORSPACE_ARGB8888;
324 return im;
325}
326
327EAPI void
328evas_common_image_colorspace_normalize(RGBA_Image *im) 347evas_common_image_colorspace_normalize(RGBA_Image *im)
329{ 348{
330 if ((!im->cs.data) || 349 if ((!im->cs.data) ||
331 ((!im->cs.dirty) && (!(im->flags & RGBA_IMAGE_IS_DIRTY)))) return; 350 ((!im->cs.dirty) && (!(im->flags & RGBA_IMAGE_IS_DIRTY)))) return;
332 switch (im->cs.space) 351 switch (im->cache_entry.space)
333 { 352 {
334 case EVAS_COLORSPACE_ARGB8888: 353 case EVAS_COLORSPACE_ARGB8888:
335 if (im->image->data != im->cs.data) 354 if (im->image.data != im->cs.data)
336 { 355 {
337 if (!im->image->no_free) free(im->image->data); 356 if (!im->image.no_free) free(im->image.data);
338 im->image->data = im->cs.data; 357 im->image.data = im->cs.data;
339 im->cs.no_free = im->image->no_free; 358 im->cs.no_free = im->image.no_free;
340 } 359 }
341 break; 360 break;
342 case EVAS_COLORSPACE_YCBCR422P601_PL: 361 case EVAS_COLORSPACE_YCBCR422P601_PL:
343#ifdef BUILD_CONVERT_YUV 362#ifdef BUILD_CONVERT_YUV
344 if ((im->image->data) && (*((unsigned char **)im->cs.data))) 363 if ((im->image.data) && (*((unsigned char **)im->cs.data)))
345 evas_common_convert_yuv_420p_601_rgba(im->cs.data, (DATA8*) im->image->data, 364 evas_common_convert_yuv_420p_601_rgba(im->cs.data, (DATA8*) im->image.data,
346 im->image->w, im->image->h); 365 im->cache_entry.w, im->cache_entry.h);
347#endif 366#endif
348 break; 367 break;
349 default: 368 default:
@@ -374,25 +393,10 @@ evas_common_image_get_cache(void)
374EAPI RGBA_Image * 393EAPI RGBA_Image *
375evas_common_load_image_from_file(const char *file, const char *key, RGBA_Image_Loadopts *lo) 394evas_common_load_image_from_file(const char *file, const char *key, RGBA_Image_Loadopts *lo)
376{ 395{
377 int error; 396 int error;
378 397
379 if (file == NULL) return NULL; 398 if (file == NULL) return NULL;
380 return evas_cache_image_request(eci, file, key, lo, &error); 399 return (RGBA_Image *) evas_cache_image_request(eci, file, key, lo, &error);
381}
382
383EAPI int
384evas_common_image_ram_usage(RGBA_Image *im)
385{
386 int ram = 0;
387
388// ram += sizeof(struct _RGBA_Image);
389// if (im->info.file) ram += strlen(im->info.file);
390// if (im->info.real_file) ram += strlen(im->info.real_file);
391// if (im->info.key) ram += strlen(im->info.key);
392// if (im->info.comment) ram += strlen(im->info.comment);
393 if ((im->image) && (im->image->data) && (!im->image->no_free))
394 ram += im->image->w * im->image->h * sizeof(DATA32);
395 return ram;
396} 400}
397 401
398EAPI void 402EAPI void
@@ -438,7 +442,7 @@ evas_common_image_line_buffer_obtain(int len)
438EAPI void 442EAPI void
439evas_common_image_line_buffer_release(RGBA_Image *im) 443evas_common_image_line_buffer_release(RGBA_Image *im)
440{ 444{
441 evas_common_image_delete(im); 445 _evas_common_rgba_image_delete(&im->cache_entry);;
442/* 446/*
443 if (!evas_rgba_line_buffer) return; 447 if (!evas_rgba_line_buffer) return;
444 if (EVAS_RGBA_LINE_BUFFER_MAX_LEN < evas_rgba_line_buffer->image->w) 448 if (EVAS_RGBA_LINE_BUFFER_MAX_LEN < evas_rgba_line_buffer->image->w)
@@ -458,7 +462,7 @@ evas_common_image_line_buffer_release(RGBA_Image *im)
458EAPI void 462EAPI void
459evas_common_image_line_buffer_free(RGBA_Image *im) 463evas_common_image_line_buffer_free(RGBA_Image *im)
460{ 464{
461 evas_common_image_delete(im); 465 _evas_common_rgba_image_delete(&im->cache_entry);;
462/* 466/*
463 if (!evas_rgba_line_buffer) return; 467 if (!evas_rgba_line_buffer) return;
464 evas_common_image_free(evas_rgba_line_buffer); 468 evas_common_image_free(evas_rgba_line_buffer);
@@ -496,7 +500,7 @@ evas_common_image_alpha_line_buffer_obtain(int len)
496EAPI void 500EAPI void
497evas_common_image_alpha_line_buffer_release(RGBA_Image *im) 501evas_common_image_alpha_line_buffer_release(RGBA_Image *im)
498{ 502{
499 evas_common_image_delete(im); 503 _evas_common_rgba_image_delete(&im->cache_entry);;
500/* 504/*
501 if (!evas_alpha_line_buffer) return; 505 if (!evas_alpha_line_buffer) return;
502 if (EVAS_ALPHA_LINE_BUFFER_MAX_LEN < evas_alpha_line_buffer->image->w) 506 if (EVAS_ALPHA_LINE_BUFFER_MAX_LEN < evas_alpha_line_buffer->image->w)
@@ -519,11 +523,11 @@ evas_common_image_premul(RGBA_Image *im)
519 DATA32 *s, *se; 523 DATA32 *s, *se;
520 DATA32 nas = 0; 524 DATA32 nas = 0;
521 525
522 if (!im || !im->image || !im->image->data) return; 526 if (!im || !im->image.data) return;
523 if (!(im->flags & RGBA_IMAGE_HAS_ALPHA)) return; 527 if (!(im->flags & RGBA_IMAGE_HAS_ALPHA)) return;
524 528
525 s = im->image->data; 529 s = im->image.data;
526 se = s + (im->image->w * im->image->h); 530 se = s + (im->cache_entry.w * im->cache_entry.h);
527 while (s < se) 531 while (s < se)
528 { 532 {
529 DATA32 a = 1 + (*s >> 24); 533 DATA32 a = 1 + (*s >> 24);
@@ -534,7 +538,7 @@ evas_common_image_premul(RGBA_Image *im)
534 if ((a == 1) || (a == 256)) 538 if ((a == 1) || (a == 256))
535 nas++; 539 nas++;
536 } 540 }
537 if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (im->image->w * im->image->h)) 541 if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (im->cache_entry.w * im->cache_entry.h))
538 im->flags |= RGBA_IMAGE_ALPHA_SPARSE; 542 im->flags |= RGBA_IMAGE_ALPHA_SPARSE;
539} 543}
540 544
@@ -544,11 +548,11 @@ evas_common_image_set_alpha_sparse(RGBA_Image *im)
544 DATA32 *s, *se; 548 DATA32 *s, *se;
545 DATA32 nas = 0; 549 DATA32 nas = 0;
546 550
547 if (!im || !im->image || !im->image->data) return; 551 if (!im || !im->image.data) return;
548 if (!(im->flags & RGBA_IMAGE_HAS_ALPHA)) return; 552 if (!(im->flags & RGBA_IMAGE_HAS_ALPHA)) return;
549 553
550 s = im->image->data; 554 s = im->image.data;
551 se = s + (im->image->w * im->image->h); 555 se = s + (im->cache_entry.w * im->cache_entry.h);
552 while (s < se) 556 while (s < se)
553 { 557 {
554 DATA32 p = *s & 0xff000000; 558 DATA32 p = *s & 0xff000000;
@@ -557,6 +561,6 @@ evas_common_image_set_alpha_sparse(RGBA_Image *im)
557 nas++; 561 nas++;
558 s++; 562 s++;
559 } 563 }
560 if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (im->image->w * im->image->h)) 564 if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (im->cache_entry.w * im->cache_entry.h))
561 im->flags |= RGBA_IMAGE_ALPHA_SPARSE; 565 im->flags |= RGBA_IMAGE_ALPHA_SPARSE;
562} 566}
diff --git a/legacy/evas/src/lib/engines/common/evas_line_main.c b/legacy/evas/src/lib/engines/common/evas_line_main.c
index 5026bbd621..189c0c13fc 100644
--- a/legacy/evas/src/lib/engines/common/evas_line_main.c
+++ b/legacy/evas/src/lib/engines/common/evas_line_main.c
@@ -52,8 +52,8 @@ evas_common_line_draw(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, in
52 } 52 }
53 53
54 clx = cly = 0; 54 clx = cly = 0;
55 clw = dst->image->w; 55 clw = dst->cache_entry.w;
56 clh = dst->image->h; 56 clh = dst->cache_entry.h;
57 57
58 /* save out clip info */ 58 /* save out clip info */
59 cuse = dc->clip.use; 59 cuse = dc->clip.use;
@@ -104,13 +104,13 @@ _evas_draw_point(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y)
104{ 104{
105 RGBA_Gfx_Pt_Func pfunc; 105 RGBA_Gfx_Pt_Func pfunc;
106 106
107 if (!IN_RANGE(x, y, dst->image->w, dst->image->h)) 107 if (!IN_RANGE(x, y, dst->cache_entry.w, dst->cache_entry.h))
108 return; 108 return;
109 if ((dc->clip.use) && (!IN_RECT(x, y, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h))) 109 if ((dc->clip.use) && (!IN_RECT(x, y, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h)))
110 return; 110 return;
111 pfunc = evas_common_gfx_func_composite_color_pt_get(dc->col.col, dst, dc->render_op); 111 pfunc = evas_common_gfx_func_composite_color_pt_get(dc->col.col, dst, dc->render_op);
112 if (pfunc) 112 if (pfunc)
113 pfunc(0, 255, dc->col.col, dst->image->data + (dst->image->w * y) + x); 113 pfunc(0, 255, dc->col.col, dst->image.data + (dst->cache_entry.w * y) + x);
114} 114}
115 115
116/* 116/*
@@ -129,7 +129,7 @@ _evas_draw_simple_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, i
129 RGBA_Gfx_Pt_Func pfunc; 129 RGBA_Gfx_Pt_Func pfunc;
130 RGBA_Gfx_Func sfunc; 130 RGBA_Gfx_Func sfunc;
131 131
132 dstw = dst->image->w; 132 dstw = dst->cache_entry.w;
133 color = dc->col.col; 133 color = dc->col.col;
134 134
135 if (y0 > y1) 135 if (y0 > y1)
@@ -170,7 +170,7 @@ _evas_draw_simple_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, i
170 if (x1 > rx) x1 = rx; 170 if (x1 > rx) x1 = rx;
171 171
172 len = x1 - x0 + 1; 172 len = x1 - x0 + 1;
173 p = dst->image->data + (dstw * y0) + x0; 173 p = dst->image.data + (dstw * y0) + x0;
174 sfunc = evas_common_gfx_func_composite_color_span_get(color, dst, len, dc->render_op); 174 sfunc = evas_common_gfx_func_composite_color_span_get(color, dst, len, dc->render_op);
175 if (sfunc) 175 if (sfunc)
176 sfunc(NULL, NULL, color, p, len); 176 sfunc(NULL, NULL, color, p, len);
@@ -190,7 +190,7 @@ _evas_draw_simple_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, i
190 if (y1 > by) y1 = by; 190 if (y1 > by) y1 = by;
191 191
192 len = y1 - y0 + 1; 192 len = y1 - y0 + 1;
193 p = dst->image->data + (dstw * y0) + x0; 193 p = dst->image.data + (dstw * y0) + x0;
194 while (len--) 194 while (len--)
195 { 195 {
196#ifdef EVAS_SLI 196#ifdef EVAS_SLI
@@ -268,7 +268,7 @@ _evas_draw_simple_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, i
268 } 268 }
269 if (y1 > y0) 269 if (y1 > y0)
270 { 270 {
271 p = dst->image->data + (dstw * y0) + x0; 271 p = dst->image.data + (dstw * y0) + x0;
272 len = y1 - y0 + 1; 272 len = y1 - y0 + 1;
273 if (dx > 0) dstw++; 273 if (dx > 0) dstw++;
274 else dstw--; 274 else dstw--;
@@ -276,7 +276,7 @@ _evas_draw_simple_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, i
276 else 276 else
277 { 277 {
278 len = y0 - y1 + 1; 278 len = y0 - y1 + 1;
279 p = dst->image->data + (dstw * y1) + x1; 279 p = dst->image.data + (dstw * y1) + x1;
280 if (dx > 0) dstw--; 280 if (dx > 0) dstw--;
281 else dstw++; 281 else dstw++;
282 } 282 }
@@ -472,8 +472,8 @@ _evas_draw_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1,
472 clw = dc->clip.w; 472 clw = dc->clip.w;
473 clh = dc->clip.h; 473 clh = dc->clip.h;
474 474
475 data = dst->image->data; 475 data = dst->image.data;
476 dstw = dst->image->w; 476 dstw = dst->cache_entry.w;
477 477
478 data += (dstw * cly) + clx; 478 data += (dstw * cly) + clx;
479 x0 -= clx; 479 x0 -= clx;
@@ -579,8 +579,8 @@ _evas_draw_line_aa(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x
579 clw = dc->clip.w; 579 clw = dc->clip.w;
580 clh = dc->clip.h; 580 clh = dc->clip.h;
581 581
582 data = dst->image->data; 582 data = dst->image.data;
583 dstw = dst->image->w; 583 dstw = dst->cache_entry.w;
584 584
585 data += (dstw * cly) + clx; 585 data += (dstw * cly) + clx;
586 x0 -= clx; 586 x0 -= clx;
diff --git a/legacy/evas/src/lib/engines/common/evas_pipe.c b/legacy/evas/src/lib/engines/common/evas_pipe.c
index 56a7866103..f12daab0bf 100644
--- a/legacy/evas/src/lib/engines/common/evas_pipe.c
+++ b/legacy/evas/src/lib/engines/common/evas_pipe.c
@@ -139,26 +139,26 @@ evas_common_pipe_begin(RGBA_Image *im)
139 } 139 }
140 } 140 }
141 y = 0; 141 y = 0;
142 h = im->image->h / thread_num; 142 h = im->cache_entry.h / thread_num;
143 if (h < 1) h = 1; 143 if (h < 1) h = 1;
144 for (i = 0; i < thread_num; i++) 144