evas cache: refactor internal logic.

Summary:
Adding cache targets in other modules are inproper.
This can't be managed by cache module inside.

One representive scenario is,
when preload cancel is triggered, preload canceling sequence
can't be performed properly because cache targets implicitly were
increased by backend modules.

And then, Cache itself couldn't get notified it.
see this condition.

if ((!ie->targets) && (ie->preload) && (!ie->flags.pending))
in _evas_cache_image_entry_preload_remove()

Consequently, I move preloaded callbacks to sync with adding cache targets,
not to add by backed engines themselves.

This will bring Cache to manage cache targets properly.

Reviewers: #committers, raster

Subscribers: cedric, #reviewers, #committers, zmike

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D6912
This commit is contained in:
Hermet Park 2018-08-30 13:26:06 +09:00
parent ad9e13ea56
commit 54f2a554da
8 changed files with 28 additions and 58 deletions

View File

@ -161,7 +161,7 @@ EAPI Engine_Image_Entry* evas_cache_engine_image_size_set(Engine_Image_Entr
EAPI void evas_cache_engine_image_load_data(Engine_Image_Entry *eim); EAPI void evas_cache_engine_image_load_data(Engine_Image_Entry *eim);
EAPI void evas_cache_image_preload_data(Image_Entry *im, const Eo *target); EAPI void evas_cache_image_preload_data(Image_Entry *im, const Eo *target, void (*preloaded_cb)(void *data), void *preloaded_data);
EAPI void evas_cache_image_preload_cancel(Image_Entry *im, const Eo *target); EAPI void evas_cache_image_preload_cancel(Image_Entry *im, const Eo *target);
EAPI int evas_cache_async_frozen_get(void); EAPI int evas_cache_async_frozen_get(void);

View File

@ -391,17 +391,9 @@ _evas_cache_image_preloaded_notify(Image_Entry *ie)
ie->targets = (Evas_Cache_Target *) ie->targets = (Evas_Cache_Target *)
eina_inlist_remove(EINA_INLIST_GET(ie->targets), eina_inlist_remove(EINA_INLIST_GET(ie->targets),
EINA_INLIST_GET(ie->targets)); EINA_INLIST_GET(ie->targets));
if (tmp->preloaded_cb) if (!tmp->delete_me && tmp->preloaded_cb)
{ tmp->preloaded_cb(tmp->preloaded_data);
if (!tmp->delete_me) evas_object_inform_call_image_preloaded((Evas_Object*) tmp->target);
{
tmp->preloaded_cb(tmp->preloaded_data);
}
}
else
{
evas_object_inform_call_image_preloaded((Evas_Object*) tmp->target);
}
free(tmp); free(tmp);
} }
} }
@ -471,7 +463,7 @@ _evas_cache_image_async_cancel(void *data)
// note - preload_add assumes a target is ONLY added ONCE to the image // note - preload_add assumes a target is ONLY added ONCE to the image
// entry. make sure you only add once, or remove first, then add // entry. make sure you only add once, or remove first, then add
static int static int
_evas_cache_image_entry_preload_add(Image_Entry *ie, const Eo *target) _evas_cache_image_entry_preload_add(Image_Entry *ie, const Eo *target, void (*preloaded_cb)(void *), void *preloaded_data)
{ {
Evas_Cache_Target *tg; Evas_Cache_Target *tg;
@ -486,6 +478,8 @@ _evas_cache_image_entry_preload_add(Image_Entry *ie, const Eo *target)
tg = calloc(1, sizeof(Evas_Cache_Target)); tg = calloc(1, sizeof(Evas_Cache_Target));
if (!tg) return 0; if (!tg) return 0;
tg->target = target; tg->target = target;
tg->preloaded_cb = preloaded_cb;
tg->preloaded_data = preloaded_data;
ie->targets = (Evas_Cache_Target *) ie->targets = (Evas_Cache_Target *)
eina_inlist_append(EINA_INLIST_GET(ie->targets), EINA_INLIST_GET(tg)); eina_inlist_append(EINA_INLIST_GET(ie->targets), EINA_INLIST_GET(tg));
@ -1254,7 +1248,7 @@ evas_cache_image_is_loaded(Image_Entry *im)
} }
EAPI void EAPI void
evas_cache_image_preload_data(Image_Entry *im, const Eo *target) evas_cache_image_preload_data(Image_Entry *im, const Eo *target, void (*preloaded_cb)(void *), void *preloaded_data)
{ {
RGBA_Image *img = (RGBA_Image *)im; RGBA_Image *img = (RGBA_Image *)im;
@ -1270,7 +1264,7 @@ evas_cache_image_preload_data(Image_Entry *im, const Eo *target)
return; return;
} }
im->flags.loaded = 0; im->flags.loaded = 0;
if (!_evas_cache_image_entry_preload_add(im, target)) if (!_evas_cache_image_entry_preload_add(im, target, preloaded_cb, preloaded_data))
evas_object_inform_call_image_preloaded((Evas_Object*) target); evas_object_inform_call_image_preloaded((Evas_Object*) target);
evas_cache_image_drop(im); evas_cache_image_drop(im);
} }

View File

@ -314,18 +314,9 @@ _evas_cache2_image_preloaded_cb(void *data, Eina_Bool success)
EINA_INLIST_GET(ie->targets)); EINA_INLIST_GET(ie->targets));
if (!ie->flags.delete_me) if (!ie->flags.delete_me)
{ {
if (tmp->preloaded_cb) if (!tmp->delete_me && tmp->preloaded_cb)
{ tmp->preloaded_cb(tmp->preloaded_data);
if (!tmp->delete_me) evas_object_inform_call_image_preloaded((Evas_Object *)tmp->target);
{
tmp->preloaded_cb(tmp->preloaded_data);
}
}
else
{
evas_object_inform_call_image_preloaded
((Evas_Object *)tmp->target);
}
} }
free(tmp); free(tmp);
} }
@ -335,7 +326,7 @@ _evas_cache2_image_preloaded_cb(void *data, Eina_Bool success)
} }
static Eina_Bool static Eina_Bool
_evas_cache2_image_entry_preload_add(Image_Entry *ie, const void *target) _evas_cache2_image_entry_preload_add(Image_Entry *ie, const void *target, void (*preloaded_cb)(void *), void *preloaded_data)
{ {
Evas_Cache_Target *tg; Evas_Cache_Target *tg;
@ -347,6 +338,9 @@ _evas_cache2_image_entry_preload_add(Image_Entry *ie, const void *target)
return EINA_TRUE; return EINA_TRUE;
tg->target = target; tg->target = target;
tg->preloaded_cb = preloaded_cb;
tg->preloaded_data = preloaded_data;
ie->targets = (Evas_Cache_Target *) ie->targets = (Evas_Cache_Target *)
eina_inlist_append(EINA_INLIST_GET(ie->targets), EINA_INLIST_GET(tg)); eina_inlist_append(EINA_INLIST_GET(ie->targets), EINA_INLIST_GET(tg));
@ -1063,7 +1057,7 @@ evas_cache2_image_unload_data(Image_Entry *im)
} }
EAPI void EAPI void
evas_cache2_image_preload_data(Image_Entry *im, const void *target) evas_cache2_image_preload_data(Image_Entry *im, const void *target, void (*preloaded_cb)(void *), void *preloaded_data)
{ {
RGBA_Image *img = (RGBA_Image *)im; RGBA_Image *img = (RGBA_Image *)im;
@ -1073,7 +1067,7 @@ evas_cache2_image_preload_data(Image_Entry *im, const void *target)
return; return;
} }
if (!_evas_cache2_image_entry_preload_add(im, target)) if (!_evas_cache2_image_entry_preload_add(im, target, preloaded_cb, preloaded_data))
evas_object_inform_call_image_preloaded((Evas_Object *)target); evas_object_inform_call_image_preloaded((Evas_Object *)target);
} }

View File

@ -65,7 +65,7 @@ EAPI void evas_cache2_image_ref(Image_Entry *im);
EAPI void evas_cache2_image_close(Image_Entry *im); EAPI void evas_cache2_image_close(Image_Entry *im);
EAPI int evas_cache2_image_load_data(Image_Entry *ie); EAPI int evas_cache2_image_load_data(Image_Entry *ie);
EAPI void evas_cache2_image_unload_data(Image_Entry *im); EAPI void evas_cache2_image_unload_data(Image_Entry *im);
EAPI void evas_cache2_image_preload_data(Image_Entry *im, const void *target); EAPI void evas_cache2_image_preload_data(Image_Entry *im, const void *target, void (*preloaded_cb)(void *data), void *data);
EAPI void evas_cache2_image_preload_cancel(Image_Entry *im, const void *target); EAPI void evas_cache2_image_preload_cancel(Image_Entry *im, const void *target);
EAPI void evas_cache2_image_cache_key_create(char *hkey, const char *path, size_t pathlen, const char *key, size_t keylen, const Evas_Image_Load_Opts *lo); EAPI void evas_cache2_image_cache_key_create(char *hkey, const char *path, size_t pathlen, const char *key, size_t keylen, const Evas_Image_Load_Opts *lo);

View File

@ -735,7 +735,7 @@ Evas_GL_Image *evas_gl_common_image_mmap(Evas_Engine_GL_Context *gc, Eina_Fil
Evas_GL_Image *evas_gl_common_image_new_from_copied_data(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, DATA32 *data, int alpha, Evas_Colorspace cspace); Evas_GL_Image *evas_gl_common_image_new_from_copied_data(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, DATA32 *data, int alpha, Evas_Colorspace cspace);
Evas_GL_Image *evas_gl_common_image_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha, Evas_Colorspace cspace); Evas_GL_Image *evas_gl_common_image_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha, Evas_Colorspace cspace);
Evas_GL_Image *evas_gl_common_image_new_from_rgbaimage(Evas_Engine_GL_Context *gc, RGBA_Image *im, Evas_Image_Load_Opts *lo, int *error); Evas_GL_Image *evas_gl_common_image_new_from_rgbaimage(Evas_Engine_GL_Context *gc, RGBA_Image *im, Evas_Image_Load_Opts *lo, int *error);
void evas_gl_common_image_preload_watch(Evas_GL_Image *im); void evas_gl_common_image_preload_done(void *data /*Evas_GL_Image *im*/);
void evas_gl_common_image_preload_unwatch(Evas_GL_Image *im); void evas_gl_common_image_preload_unwatch(Evas_GL_Image *im);
Evas_GL_Image *evas_gl_common_image_alpha_set(Evas_GL_Image *im, int alpha); Evas_GL_Image *evas_gl_common_image_alpha_set(Evas_GL_Image *im, int alpha);
void evas_gl_common_image_scale_hint_set(Evas_GL_Image *im, int hint); void evas_gl_common_image_scale_hint_set(Evas_GL_Image *im, int hint);

View File

@ -150,8 +150,8 @@ _evas_gl_cspace_list_fill(Evas_Engine_GL_Context *gc)
CS_APPEND(EVAS_COLORSPACE_ARGB8888); CS_APPEND(EVAS_COLORSPACE_ARGB8888);
} }
static void void
preload_done(void *data) evas_gl_common_image_preload_done(void *data)
{ {
Evas_GL_Image *im = data; Evas_GL_Image *im = data;
@ -192,26 +192,9 @@ found_cspace:
im->w = im->im->cache_entry.w; im->w = im->im->cache_entry.w;
im->h = im->im->cache_entry.h; im->h = im->im->cache_entry.h;
} }
evas_gl_common_image_preload_unwatch(im);
}
void
evas_gl_common_image_preload_watch(Evas_GL_Image *im)
{
Evas_Cache_Target *tg;
if (!im->im) return;
tg = calloc(1, sizeof(Evas_Cache_Target));
if (tg)
{
tg->preloaded_cb = preload_done;
tg->preloaded_data = im;
im->im->cache_entry.targets = (Evas_Cache_Target *)
eina_inlist_append(EINA_INLIST_GET(im->im->cache_entry.targets),
EINA_INLIST_GET(tg));
}
} }
//FIXME: This is a hacky way. Need an proper interface...
void void
evas_gl_common_image_preload_unwatch(Evas_GL_Image *im) evas_gl_common_image_preload_unwatch(Evas_GL_Image *im)
{ {
@ -221,7 +204,7 @@ evas_gl_common_image_preload_unwatch(Evas_GL_Image *im)
if (!im->im) return; if (!im->im) return;
EINA_INLIST_FOREACH_SAFE(im->im->cache_entry.targets, l2, tg) EINA_INLIST_FOREACH_SAFE(im->im->cache_entry.targets, l2, tg)
{ {
if ((tg->preloaded_cb != preload_done) || (tg->preloaded_data != im)) if ((tg->preloaded_cb != evas_gl_common_image_preload_done) || (tg->preloaded_data != im))
continue; continue;
tg->delete_me = EINA_TRUE; tg->delete_me = EINA_TRUE;
break; break;

View File

@ -1132,13 +1132,12 @@ eng_image_data_preload_request(void *engine EINA_UNUSED, void *image, const Eo *
im = (RGBA_Image *)gim->im; im = (RGBA_Image *)gim->im;
if (!im) return; if (!im) return;
evas_gl_common_image_preload_watch(gim);
#ifdef EVAS_CSERVE2 #ifdef EVAS_CSERVE2
if (evas_cserve2_use_get() && evas_cache2_image_cached(&im->cache_entry)) if (evas_cserve2_use_get() && evas_cache2_image_cached(&im->cache_entry))
evas_cache2_image_preload_data(&im->cache_entry, target); evas_cache2_image_preload_data(&im->cache_entry, target, evas_gl_common_image_preload_done, gim);
else else
#endif #endif
evas_cache_image_preload_data(&im->cache_entry, target); evas_cache_image_preload_data(&im->cache_entry, target, evas_gl_common_image_preload_done, gim);
} }
static void static void

View File

@ -2339,11 +2339,11 @@ eng_image_data_preload_request(void *data EINA_UNUSED, void *image, const Eo *ta
#ifdef EVAS_CSERVE2 #ifdef EVAS_CSERVE2
if (evas_cserve2_use_get() && evas_cache2_image_cached(&im->cache_entry)) if (evas_cserve2_use_get() && evas_cache2_image_cached(&im->cache_entry))
{ {
evas_cache2_image_preload_data(&im->cache_entry, target); evas_cache2_image_preload_data(&im->cache_entry, target, NULL, NULL);
return; return;
} }
#endif #endif
evas_cache_image_preload_data(&im->cache_entry, target); evas_cache_image_preload_data(&im->cache_entry, target, NULL, NULL);
} }
static void static void