evas image skip header - more fixes for when images fail to load

this fixes some more issues i have found in using skip header like if
the file doesn't exist etc. recent feature add so not a fix.
This commit is contained in:
Carsten Haitzler 2017-01-06 09:37:40 +09:00
parent 273238d725
commit 3842e87d3a
3 changed files with 63 additions and 18 deletions

View File

@ -307,7 +307,7 @@ _evas_cache_image_entry_surface_alloc__locked(Evas_Cache_Image *cache,
unsigned int hmin) unsigned int hmin)
{ {
if ((ie->allocated.w == wmin) && (ie->allocated.h == hmin)) return; if ((ie->allocated.w == wmin) && (ie->allocated.h == hmin)) return;
if (cache->func.surface_alloc(ie, wmin, hmin)) if ((cache->func.surface_alloc(ie, wmin, hmin)) || (ie->load_failed))
{ {
wmin = 0; wmin = 0;
hmin = 0; hmin = 0;
@ -418,6 +418,7 @@ _evas_cache_image_async_end(void *data)
ie->flags.preload_pending = 0; ie->flags.preload_pending = 0;
LKU(wakeup); LKU(wakeup);
evas_cache_image_ref(ie);
while ((tmp = ie->targets)) while ((tmp = ie->targets))
{ {
ie->targets = (Evas_Cache_Target *) ie->targets = (Evas_Cache_Target *)
@ -439,6 +440,7 @@ _evas_cache_image_async_end(void *data)
EINA_LIST_FREE(ie->tasks, task) EINA_LIST_FREE(ie->tasks, task)
if (task != &dummy_task) free(task); if (task != &dummy_task) free(task);
evas_cache_image_drop(ie);
} }
static void static void
@ -821,16 +823,29 @@ evas_cache_image_mmap_request(Evas_Cache_Image *cache,
/* find image by key in active mmap hash */ /* find image by key in active mmap hash */
im = eina_hash_find(cache->mmap_activ, hkey); im = eina_hash_find(cache->mmap_activ, hkey);
if (im) goto on_ok; if ((im) && (!im->load_failed)) goto on_ok;
else if ((im) && (im->load_failed))
{
_evas_cache_image_dirty_add(im);
im = NULL;
}
/* find image by key in inactive/lru hash */ /* find image by key in inactive/lru hash */
im = eina_hash_find(cache->mmap_inactiv, hkey); im = eina_hash_find(cache->mmap_inactiv, hkey);
if (im) if ((im) && (!im->load_failed))
{ {
_evas_cache_image_lru_del(im); _evas_cache_image_lru_del(im);
_evas_cache_image_activ_add(im); _evas_cache_image_activ_add(im);
goto on_ok; goto on_ok;
} }
else if ((im) && (im->load_failed))
{
/* as active cache find - if we match in lru and its invalid, dirty */
_evas_cache_image_dirty_add(im);
/* this image never used, so it have to be deleted */
_evas_cache_image_entry_delete(cache, im);
im = NULL;
}
im = _evas_cache_image_entry_new(cache, hkey, NULL, f, NULL, key, lo, error); im = _evas_cache_image_entry_new(cache, hkey, NULL, f, NULL, key, lo, error);
if (!im) return NULL; if (!im) return NULL;
@ -882,7 +897,7 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file,
/* find image by key in active hash */ /* find image by key in active hash */
im = eina_hash_find(cache->activ, hkey); im = eina_hash_find(cache->activ, hkey);
if (im) if ((im) && (!im->load_failed))
{ {
int ok = 1; int ok = 1;
@ -905,10 +920,15 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file,
_evas_cache_image_dirty_add(im); _evas_cache_image_dirty_add(im);
im = NULL; im = NULL;
} }
else if ((im) && (im->load_failed))
{
_evas_cache_image_dirty_add(im);
im = NULL;
}
/* find image by key in inactive/lru hash */ /* find image by key in inactive/lru hash */
im = eina_hash_find(cache->inactiv, hkey); im = eina_hash_find(cache->inactiv, hkey);
if (im) if ((im) && (!im->load_failed))
{ {
int ok = 1; int ok = 1;
@ -940,6 +960,14 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file,
_evas_cache_image_entry_delete(cache, im); _evas_cache_image_entry_delete(cache, im);
im = NULL; im = NULL;
} }
else if ((im) && (im->load_failed))
{
/* as active cache find - if we match in lru and its invalid, dirty */
_evas_cache_image_dirty_add(im);
/* this image never used, so it have to be deleted */
_evas_cache_image_entry_delete(cache, im);
im = NULL;
}
if (stat_failed) goto on_stat_error; if (stat_failed) goto on_stat_error;
if (!skip) if (!skip)
@ -1012,7 +1040,7 @@ evas_cache_image_drop(Image_Entry *im)
_evas_cache_image_entry_preload_remove(im, NULL); _evas_cache_image_entry_preload_remove(im, NULL);
return; return;
} }
if (im->flags.dirty) if ((im->flags.dirty) || (im->load_failed))
{ {
_evas_cache_image_entry_delete(cache, im); _evas_cache_image_entry_delete(cache, im);
return; return;
@ -1420,6 +1448,7 @@ evas_cache_image_flush(Evas_Cache_Image *cache)
Image_Entry *im; Image_Entry *im;
im = (Image_Entry *)cache->lru->last; im = (Image_Entry *)cache->lru->last;
if (!im) im = (Image_Entry *)cache->lru;
_evas_cache_image_entry_delete(cache, im); _evas_cache_image_entry_delete(cache, im);
} }
@ -1427,7 +1456,8 @@ evas_cache_image_flush(Evas_Cache_Image *cache)
{ {
Image_Entry *im; Image_Entry *im;
im = (Image_Entry *) cache->lru_nodata->last; im = (Image_Entry *)cache->lru_nodata->last;
if (!im) im = (Image_Entry *)cache->lru_nodata;
_evas_cache_image_lru_nodata_del(im); _evas_cache_image_lru_nodata_del(im);
cache->func.surface_delete(im); cache->func.surface_delete(im);
im->flags.loaded = 0; im->flags.loaded = 0;

View File

@ -383,7 +383,7 @@ end:
ie->info.module = em; ie->info.module = em;
ie->info.loader = em->functions; ie->info.loader = em->functions;
evas_module_ref(ie->info.module); if (em) evas_module_ref(em);
return ret; return ret;
} }
@ -419,7 +419,11 @@ evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
CRI("This function shouldn't be called anymore!"); CRI("This function shouldn't be called anymore!");
#endif #endif
if (!ie->info.module) return EVAS_LOAD_ERROR_GENERIC; if (!ie->info.module)
{
ie->load_failed = 1;
return EVAS_LOAD_ERROR_GENERIC;
}
evas_image_load_func = ie->info.loader; evas_image_load_func = ie->info.loader;
evas_module_use(ie->info.module); evas_module_use(ie->info.module);
@ -431,20 +435,20 @@ evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
if (_evas_image_file_header(em, ie, &ret)) if (_evas_image_file_header(em, ie, &ret))
{ {
em = NULL; em = NULL;
for (i = 0; i < sizeof(loaders_name) / sizeof (char *); i++) if (!ie->load_opts.skip_head)
{ {
em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, for (i = 0; i < sizeof(loaders_name) / sizeof (char *); i++)
loaders_name[i]);
if (em)
{ {
if (!ie->load_opts.skip_head) em = evas_module_find_type
(EVAS_MODULE_TYPE_IMAGE_LOADER, loaders_name[i]);
if (em)
{ {
if (!_evas_image_file_header(em, ie, &ret)) if (!_evas_image_file_header(em, ie, &ret))
goto end; goto end;
} }
else DBG("could not find module '%s'", loaders_name[i]);
em = NULL;
} }
else DBG("could not find module '%s'", loaders_name[i]);
em = NULL;
} }
} }
end: end:
@ -455,7 +459,11 @@ end:
ie->info.module = em; ie->info.module = em;
} }
} }
if ((!ie->f) || (!ie->info.module)) return EVAS_LOAD_ERROR_DOES_NOT_EXIST; if ((!ie->f) || (!ie->info.module))
{
ie->load_failed = 1;
return EVAS_LOAD_ERROR_DOES_NOT_EXIST;
}
if ((ie->file) && (stat(ie->file, &st) == 0)) if ((ie->file) && (stat(ie->file, &st) == 0))
_timestamp_build(&(ie->tstamp), &st); _timestamp_build(&(ie->tstamp), &st);
@ -477,7 +485,11 @@ end:
property.borders.b = ie->borders.b; property.borders.b = ie->borders.b;
pixels = evas_cache_image_pixels(ie); pixels = evas_cache_image_pixels(ie);
if (!pixels) return EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; if (!pixels)
{
ie->load_failed = 1;
return EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
}
evas_image_load_func->file_data(ie->loader_data, &property, pixels, &ret); evas_image_load_func->file_data(ie->loader_data, &property, pixels, &ret);

View File

@ -617,6 +617,8 @@ struct _Image_Entry
{ {
EINA_INLIST; EINA_INLIST;
int magic;
Evas_Cache_Image *cache; Evas_Cache_Image *cache;
#ifdef EVAS_CSERVE2 #ifdef EVAS_CSERVE2
Evas_Cache2 *cache2; Evas_Cache2 *cache2;
@ -650,6 +652,7 @@ struct _Image_Entry
unsigned char scale; unsigned char scale;
unsigned char need_unload : 1; unsigned char need_unload : 1;
unsigned char load_failed : 1;
struct struct
{ {