summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2020-02-14 08:33:07 -0500
committerMike Blumenkrantz <zmike@samsung.com>2020-02-14 08:33:07 -0500
commitc1dd72fc917055eb8742afd4b8f115a52c254971 (patch)
tree1d7fcd6937bda47c69696e9a479feeb9960432b0
parentfff6ce7f2eff52a9d97db2280124278cf08516a8 (diff)
Revert "evas: remove unused function evas_cache_image_request."
Summary: This reverts commit ee3f4e052956ceb49486efae72ece1eccd982b68. Reviewers: raster Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D11334
-rw-r--r--src/lib/evas/cache/evas_cache.h1
-rw-r--r--src/lib/evas/cache/evas_cache_image.c164
2 files changed, 165 insertions, 0 deletions
diff --git a/src/lib/evas/cache/evas_cache.h b/src/lib/evas/cache/evas_cache.h
index b7bcb7d660..cccb986afd 100644
--- a/src/lib/evas/cache/evas_cache.h
+++ b/src/lib/evas/cache/evas_cache.h
@@ -115,6 +115,7 @@ extern "C" {
115 115
116EAPI Evas_Cache_Image* evas_cache_image_init(const Evas_Cache_Image_Func *cb); 116EAPI Evas_Cache_Image* evas_cache_image_init(const Evas_Cache_Image_Func *cb);
117EAPI void evas_cache_image_shutdown(Evas_Cache_Image *cache); 117EAPI void evas_cache_image_shutdown(Evas_Cache_Image *cache);
118EAPI Image_Entry* evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *key, Evas_Image_Load_Opts *lo, int *error);
118EAPI Image_Entry* evas_cache_image_mmap_request(Evas_Cache_Image *cache, Eina_File *f, const char *key, Evas_Image_Load_Opts *lo, int *error); 119EAPI Image_Entry* evas_cache_image_mmap_request(Evas_Cache_Image *cache, Eina_File *f, const char *key, Evas_Image_Load_Opts *lo, int *error);
119EAPI void evas_cache_image_ref(Image_Entry *im); 120EAPI void evas_cache_image_ref(Image_Entry *im);
120EAPI void evas_cache_image_drop(Image_Entry *im); 121EAPI void evas_cache_image_drop(Image_Entry *im);
diff --git a/src/lib/evas/cache/evas_cache_image.c b/src/lib/evas/cache/evas_cache_image.c
index 9608c2188a..b69bc0406b 100644
--- a/src/lib/evas/cache/evas_cache_image.c
+++ b/src/lib/evas/cache/evas_cache_image.c
@@ -848,6 +848,170 @@ evas_cache_image_mmap_request(Evas_Cache_Image *cache,
848 return im; 848 return im;
849} 849}
850 850
851
852EAPI Image_Entry *
853evas_cache_image_request(Evas_Cache_Image *cache, const char *file,
854 const char *key, Evas_Image_Load_Opts *lo, int *error)
855{
856 const char *ckey = "(null)";
857 char *hkey;
858 Image_Entry *im;
859 size_t size;
860 int stat_done = 0, stat_failed = 0;
861 size_t file_length;
862 size_t key_length;
863 struct stat st;
864 Image_Timestamp tstamp;
865 Eina_Bool skip = lo->skip_head;
866 Evas_Image_Load_Opts tlo;
867
868 if (!file)
869 {
870 *error = EVAS_LOAD_ERROR_GENERIC;
871 return NULL;
872 }
873
874 /* generate hkey from file+key+load opts */
875 file_length = strlen(file);
876 key_length = key ? strlen(key) : 6;
877 size = file_length + key_length + 132;
878 hkey = alloca(sizeof (char) * size);
879 memcpy(hkey, file, file_length);
880 size = file_length;
881 memcpy(hkey + size, "//://", 5);
882 size += 5;
883 if (key) ckey = key;
884 memcpy(hkey + size, ckey, key_length);
885 size += key_length;
886 size += _evas_cache_image_loadopts_append(hkey + size, &lo);
887 tlo = *lo;
888 tlo.skip_head = skip;
889
890 /* find image by key in active hash */
891 SLKL(engine_lock);
892 im = eina_hash_find(cache->activ, hkey);
893 if ((im) && (!im->load_failed))
894 {
895 int ok = 1;
896
897 stat_done = 1;
898 if (!skip)
899 {
900 if (stat(file, &st) < 0)
901 {
902 stat_failed = 1;
903 ok = 0;
904 }
905 else if (!_timestamp_compare(&(im->tstamp), &st)) ok = 0;
906 }
907 if (ok) goto on_ok;
908 /* image we found doesn't match what's on disk (stat info wise)
909 * so dirty the active cache entry so we never find it again. this
910 * also implicitly guarantees that we only have 1 active copy
911 * of an image at a given key. we wither find it and keep re-reffing
912 * it or we dirty it and get it out */
913 _evas_cache_image_dirty_add(im);
914 im = NULL;
915 }
916 else if ((im) && (im->load_failed))
917 {
918 _evas_cache_image_dirty_add(im);
919 im = NULL;
920 }
921
922 /* find image by key in inactive/lru hash */
923 im = eina_hash_find(cache->inactiv, hkey);
924 if ((im) && (!im->load_failed))
925 {
926 int ok = 1;
927
928 if (!skip)
929 {
930 if (!stat_done)
931 {
932 stat_done = 1;
933 if (stat(file, &st) < 0)
934 {
935 stat_failed = 1;
936 ok = 0;
937 }
938 else if (!_timestamp_compare(&(im->tstamp), &st)) ok = 0;
939 }
940 else if (!_timestamp_compare(&(im->tstamp), &st)) ok = 0;
941 }
942
943 if (ok)
944 {
945 /* remove from lru and make it active again */
946 _evas_cache_image_lru_del(im);
947 _evas_cache_image_activ_add(im);
948 goto on_ok;
949 }
950 /* as active cache find - if we match in lru and its invalid, dirty */
951 _evas_cache_image_dirty_add(im);
952 /* this image never used, so it have to be deleted */
953 _evas_cache_image_entry_delete(cache, im);
954 im = NULL;
955 }
956 else if ((im) && (im->load_failed))
957 {
958 /* as active cache find - if we match in lru and its invalid, dirty */
959 _evas_cache_image_dirty_add(im);
960 /* this image never used, so it have to be deleted */
961 _evas_cache_image_entry_delete(cache, im);
962 im = NULL;
963 }
964 if (stat_failed) goto on_stat_error;
965
966 if (!skip)
967 {
968 if (!stat_done)
969 {
970 if (stat(file, &st) < 0) goto on_stat_error;
971 }
972 _timestamp_build(&tstamp, &st);
973 im = _evas_cache_image_entry_new(cache, hkey, &tstamp, NULL,
974 file, key, &tlo, error);
975 }
976 else
977 {
978 im = _evas_cache_image_entry_new(cache, hkey, NULL, NULL,
979 file, key, &tlo, error);
980 }
981 if (!im) goto on_stat_error;
982 if (cache->func.debug) cache->func.debug("request", im);
983
984on_ok:
985 *error = EVAS_LOAD_ERROR_NONE;
986//// SLKL(im->lock);
987 im->references++;
988//// SLKU(im->lock);
989 SLKU(engine_lock);
990 return im;
991
992on_stat_error:
993#ifndef _WIN32
994 if ((errno == ENOENT) || (errno == ENOTDIR) ||
995 (errno == ENAMETOOLONG) || (errno == ELOOP))
996#else
997 if (errno == ENOENT)
998#endif
999 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
1000#ifndef _WIN32
1001 else if ((errno == ENOMEM) || (errno == EOVERFLOW))
1002#else
1003 else if (errno == ENOMEM)
1004#endif
1005 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
1006 else if (errno == EACCES)
1007 *error = EVAS_LOAD_ERROR_PERMISSION_DENIED;
1008 else
1009 *error = EVAS_LOAD_ERROR_GENERIC;
1010
1011 SLKU(engine_lock);
1012 return NULL;
1013}
1014
851EAPI void 1015EAPI void
852evas_cache_image_ref(Image_Entry *im) 1016evas_cache_image_ref(Image_Entry *im)
853{ 1017{