summaryrefslogtreecommitdiff
path: root/src/lib/evas/cache2
diff options
context:
space:
mode:
authorPaulo Alcantara <pcacjr@profusion.mobi>2012-11-27 18:23:25 +0000
committerIván Briano <sachieru@gmail.com>2012-11-27 18:23:25 +0000
commitf8f79f8599da9166e29a31abaf9c5169bf3f6691 (patch)
tree683ad886b1a8141f367cea231de35f79fe95e249 /src/lib/evas/cache2
parent8ac3152e898668a8354d9fd3afada89484ac575b (diff)
evas/cserve2: Add scalecache support
Signed-off-by: Paulo Alcantara <pcacjr@profusion.mobi> Patch by: Paulo Alcantara <pcacjr@profusion.mobi> SVN revision: 79754
Diffstat (limited to 'src/lib/evas/cache2')
-rw-r--r--src/lib/evas/cache2/evas_cache2.c165
-rw-r--r--src/lib/evas/cache2/evas_cache2.h1
2 files changed, 164 insertions, 2 deletions
diff --git a/src/lib/evas/cache2/evas_cache2.c b/src/lib/evas/cache2/evas_cache2.c
index 1b9d05cbd8..6397f10981 100644
--- a/src/lib/evas/cache2/evas_cache2.c
+++ b/src/lib/evas/cache2/evas_cache2.c
@@ -25,6 +25,11 @@
25 Var = NULL; \ 25 Var = NULL; \
26} 26}
27 27
28/* Size of characters used to determine a string that'll be used for load
29 * options in hash keys.
30 */
31#define HKEY_LOAD_OPTS_STR_LEN 215
32
28static void _evas_cache_image_dirty_add(Image_Entry *im); 33static void _evas_cache_image_dirty_add(Image_Entry *im);
29static void _evas_cache_image_dirty_del(Image_Entry *im); 34static void _evas_cache_image_dirty_del(Image_Entry *im);
30static void _evas_cache_image_activ_add(Image_Entry *im); 35static void _evas_cache_image_activ_add(Image_Entry *im);
@@ -567,7 +572,39 @@ _create_hash_key(char *hkey, const char *path, size_t pathlen, const char *key,
567 size += eina_convert_xtoa(lo->region.w, hkey + size); 572 size += eina_convert_xtoa(lo->region.w, hkey + size);
568 hkey[size] = 'x'; 573 hkey[size] = 'x';
569 size += 1; 574 size += 1;
575
570 size += eina_convert_xtoa(lo->region.h, hkey + size); 576 size += eina_convert_xtoa(lo->region.h, hkey + size);
577 hkey[size++] = '!';
578 hkey[size++] = '(';
579
580 hkey[size] = '[';
581 size += 1;
582 size += eina_convert_xtoa(lo->scale_load.src_x, hkey + size);
583 hkey[size] = ',';
584 size += 1;
585 size += eina_convert_xtoa(lo->scale_load.src_y, hkey + size);
586 hkey[size] = ':';
587 size += 1;
588 size += eina_convert_xtoa(lo->scale_load.src_w, hkey + size);
589 hkey[size] = 'x';
590 size += 1;
591 size += eina_convert_xtoa(lo->scale_load.src_h, hkey + size);
592 hkey[size++] = ']';
593
594 hkey[size++] = '-';
595
596 hkey[size] = '[';
597 size += 1;
598 size += eina_convert_xtoa(lo->scale_load.dst_w, hkey + size);
599 hkey[size] = 'x';
600 size += 1;
601 size += eina_convert_xtoa(lo->scale_load.dst_h, hkey + size);
602 hkey[size] = ':';
603 size += 1;
604 size += eina_convert_xtoa(lo->scale_load.smooth, hkey + size);
605 hkey[size++] = ']';
606
607 hkey[size++] = ')';
571 608
572 if (lo->orientation) 609 if (lo->orientation)
573 { 610 {
@@ -591,7 +628,8 @@ evas_cache2_image_open(Evas_Cache2 *cache, const char *path, const char *key, RG
591 int stat_done = 0, stat_failed = 0; 628 int stat_done = 0, stat_failed = 0;
592 struct stat st; 629 struct stat st;
593 Image_Timestamp tstamp; 630 Image_Timestamp tstamp;
594 Evas_Image_Load_Opts prevent = { 0, 0.0, 0, 0, 0, { 0, 0, 0, 0 }, EINA_FALSE }; 631 Evas_Image_Load_Opts prevent = { 0, 0.0, 0, 0, 0, { 0, 0, 0, 0 },
632 { 0, 0, 0, 0, 0, 0, 0, 0 }, EINA_FALSE };
595 633
596 if ((!path) || ((!path) && (!key))) 634 if ((!path) || ((!path) && (!key)))
597 { 635 {
@@ -601,7 +639,7 @@ evas_cache2_image_open(Evas_Cache2 *cache, const char *path, const char *key, RG
601 639
602 pathlen = strlen(path); 640 pathlen = strlen(path);
603 keylen = key ? strlen(key) : 6; 641 keylen = key ? strlen(key) : 6;
604 size = pathlen + keylen + 132; 642 size = pathlen + keylen + HKEY_LOAD_OPTS_STR_LEN;
605 hkey = alloca(sizeof(char) * size); 643 hkey = alloca(sizeof(char) * size);
606 644
607 _create_hash_key(hkey, path, pathlen, key, keylen, lo); 645 _create_hash_key(hkey, path, pathlen, key, keylen, lo);
@@ -614,6 +652,7 @@ evas_cache2_image_open(Evas_Cache2 *cache, const char *path, const char *key, RG
614 (lo->dpi == 0.0) && 652 (lo->dpi == 0.0) &&
615 ((lo->w == 0) || (lo->h == 0)) && 653 ((lo->w == 0) || (lo->h == 0)) &&
616 ((lo->region.w == 0) || (lo->region.h == 0)) && 654 ((lo->region.w == 0) || (lo->region.h == 0)) &&
655 ((lo->scale_load.dst_w == 0) || (lo->scale_load.dst_h == 0)) &&
617 (lo->orientation == 0) 656 (lo->orientation == 0)
618 )) 657 ))
619 { 658 {
@@ -731,6 +770,128 @@ evas_cache2_image_open_wait(Image_Entry *im)
731 return EVAS_LOAD_ERROR_NONE; 770 return EVAS_LOAD_ERROR_NONE;
732} 771}
733 772
773static Image_Entry *
774_scaled_image_find(Image_Entry *im, int src_x, int src_y, int src_w, int src_h, int dst_w, int dst_h, int smooth)
775{
776 size_t pathlen, keylen, size;
777 char *hkey;
778 RGBA_Image_Loadopts lo;
779 Image_Entry *ret;
780
781 if (((!im->file) || ((!im->file) && (!im->key))) || (!im->data1) ||
782 ((src_w == dst_w) && (src_h == dst_h)) ||
783 ((!im->flags.alpha) && (!smooth))) return NULL;
784
785 pathlen = strlen(im->file);
786 keylen = im->key ? strlen(im->key) : 6;
787 size = pathlen + keylen + HKEY_LOAD_OPTS_STR_LEN;
788 hkey = alloca(sizeof(char) * size);
789
790 memcpy(&lo, &im->load_opts, sizeof lo);
791 lo.scale_load.src_x = src_x;
792 lo.scale_load.src_y = src_y;
793 lo.scale_load.src_w = src_w;
794 lo.scale_load.src_h = src_h;
795 lo.scale_load.dst_w = dst_w;
796 lo.scale_load.dst_h = dst_h;
797 lo.scale_load.smooth = smooth;
798
799 if (!smooth)
800 {
801 lo.scale_load.smooth = 1;
802 _create_hash_key(hkey, im->file, pathlen, im->key, keylen, &lo);
803
804 ret = eina_hash_find(im->cache2->activ, hkey);
805 if (ret) goto found;
806
807 ret = eina_hash_find(im->cache2->inactiv, hkey);
808 if (ret) goto handle_inactiv;
809
810 lo.scale_load.smooth = smooth;
811 }
812
813 _create_hash_key(hkey, im->file, pathlen, im->key, keylen, &lo);
814
815 ret = eina_hash_find(im->cache2->activ, hkey);
816 if (ret) goto found;
817
818 ret = eina_hash_find(im->cache2->inactiv, hkey);
819
820 handle_inactiv:
821 if (!ret) return NULL;
822
823 /* Remove from lru and make it active again */
824 _evas_cache_image_lru_del(ret);
825 _evas_cache_image_activ_add(ret);
826
827 found:
828 evas_cache2_image_load_data(ret);
829
830 return ret;
831}
832
833EAPI Image_Entry *
834evas_cache2_image_scale_load(Image_Entry *im, int src_x, int src_y, int src_w, int src_h, int dst_w, int dst_h, int smooth)
835{
836 size_t pathlen, keylen, size;
837 char *hkey;
838 RGBA_Image_Loadopts lo;
839 int error = EVAS_LOAD_ERROR_NONE;
840 Image_Entry *ret;
841
842 if (((!im->file) || ((!im->file) && (!im->key))) ||
843 ((src_w == 0) || (src_h == 0) || (dst_w == 0) || (dst_h == 0)) ||
844 (im->scale_hint == EVAS_IMAGE_SCALE_HINT_DYNAMIC)) goto parent_out;
845
846 if (((src_w == dst_w) && (src_h == dst_h)) ||
847 ((!im->flags.alpha) && (!smooth))) goto parent_out;
848
849 ret = _scaled_image_find(im, src_x, src_y, src_w, src_h,
850 dst_w, dst_h, smooth);
851 if (ret) return ret;
852
853 pathlen = strlen(im->file);
854 keylen = im->key ? strlen(im->key) : 6;
855 size = pathlen + keylen + HKEY_LOAD_OPTS_STR_LEN;
856 hkey = alloca(sizeof(char) * size);
857
858 memcpy(&lo, &im->load_opts, sizeof lo);
859 lo.scale_load.src_x = src_x;
860 lo.scale_load.src_y = src_y;
861 lo.scale_load.src_w = src_w;
862 lo.scale_load.src_h = src_h;
863 lo.scale_load.dst_w = dst_w;
864 lo.scale_load.dst_h = dst_h;
865 lo.scale_load.smooth = smooth;
866 lo.scale_load.scale_hint = im->scale_hint;
867
868 _create_hash_key(hkey, im->file, pathlen, im->key, keylen, &lo);
869
870 ret = _evas_cache_image_entry_new(im->cache2, hkey, NULL, im->file, im->key,
871 &lo, &error);
872 if (error != EVAS_LOAD_ERROR_NONE)
873 {
874 ERR("Failed to create scale image entry with error code %d.", error);
875
876 if (ret) _evas_cache_image_entry_delete(im->cache2, ret);
877 goto parent_out;
878 }
879
880 evas_cserve2_image_load_wait(ret);
881 evas_cache2_image_load_data(ret);
882
883 ret->references++;
884 ret->w = dst_w;
885 ret->h = dst_h;
886
887 return ret;
888
889 parent_out:
890 evas_cache2_image_load_data(im);
891
892 return im;
893}
894
734EAPI void 895EAPI void
735evas_cache2_image_close(Image_Entry *im) 896evas_cache2_image_close(Image_Entry *im)
736{ 897{
diff --git a/src/lib/evas/cache2/evas_cache2.h b/src/lib/evas/cache2/evas_cache2.h
index 7028338e7b..8fc300aca7 100644
--- a/src/lib/evas/cache2/evas_cache2.h
+++ b/src/lib/evas/cache2/evas_cache2.h
@@ -59,6 +59,7 @@ extern "C" {
59EAPI Evas_Cache2* evas_cache2_init(const Evas_Cache2_Image_Func *cb); 59EAPI Evas_Cache2* evas_cache2_init(const Evas_Cache2_Image_Func *cb);
60EAPI void evas_cache2_shutdown(Evas_Cache2 *cache); 60EAPI void evas_cache2_shutdown(Evas_Cache2 *cache);
61EAPI Image_Entry * evas_cache2_image_open(Evas_Cache2 *cache, const char *path, const char *key, RGBA_Image_Loadopts *lo, int *error); 61EAPI Image_Entry * evas_cache2_image_open(Evas_Cache2 *cache, const char *path, const char *key, RGBA_Image_Loadopts *lo, int *error);
62EAPI Image_Entry *evas_cache2_image_scale_load(Image_Entry *im, int src_x, int src_y, int src_w, int src_h, int dst_w, int dst_h, int smooth);
62EAPI int evas_cache2_image_open_wait(Image_Entry *im); 63EAPI int evas_cache2_image_open_wait(Image_Entry *im);
63EAPI void evas_cache2_image_close(Image_Entry *im); 64EAPI void evas_cache2_image_close(Image_Entry *im);
64EAPI int evas_cache2_image_load_data(Image_Entry *ie); 65EAPI int evas_cache2_image_load_data(Image_Entry *ie);