summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/gl_common/evas_gl_texture.c
diff options
context:
space:
mode:
authorDongyeon Kim <dy5.kim@samsung.com>2015-03-02 14:40:12 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-03-02 15:55:47 +0900
commita32edfaf1999f232d923f6bff615c582415d5fbd (patch)
tree4a79081dac233060b52e929e4c3f33b32089d091 /src/modules/evas/engines/gl_common/evas_gl_texture.c
parent433d24cfa0ec815de82c8a3b35e57213dcb7b945 (diff)
evas/gl: implement dynamic hint set using tbm surface
Summary: Currently dynamic hint set is implemented using eglMapImageSEC extension, which is no longer supported by any drivers (should be deprecated) This patch implements dynamic hint set using Khronos extension EGL_TIZEN_image_native_surface. Since tbm surface library is required for this, libtbm.so is queried at context new. Test Plan: Local tests Reviewers: raster, Hermet, cedric, jpeg Subscribers: mer.kim, wonsik, cedric Differential Revision: https://phab.enlightenment.org/D2027 Signed-off-by: Jean-Philippe Andre <jp.andre@samsung.com> jpeg: I also fixed a few minor style issues and two warnings (bad function names, glsym instead of secsym).
Diffstat (limited to '')
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_texture.c182
1 files changed, 116 insertions, 66 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_texture.c b/src/modules/evas/engines/gl_common/evas_gl_texture.c
index c2af7f349b..2f3852f7cd 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_texture.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_texture.c
@@ -692,33 +692,10 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, i
692 Evas_GL_Texture_Pool *pt = NULL; 692 Evas_GL_Texture_Pool *pt = NULL;
693 693
694#ifdef GL_GLES 694#ifdef GL_GLES
695 int fmt; // EGL_MAP_GL_TEXTURE_RGBA_SEC or EGL_MAP_GL_TEXTURE_RGB_SEC or bust
696 int pixtype; // EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC or bust
697 int attr[] =
698 {
699 EGL_MAP_GL_TEXTURE_WIDTH_SEC, 32,
700 EGL_MAP_GL_TEXTURE_HEIGHT_SEC, 32,
701 EGL_MAP_GL_TEXTURE_FORMAT_SEC, EGL_MAP_GL_TEXTURE_RGBA_SEC,
702 EGL_MAP_GL_TEXTURE_PIXEL_TYPE_SEC, EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC,
703 EGL_NONE
704 };
705 void *egldisplay; 695 void *egldisplay;
706 696
707 if (intformat != format) return NULL; 697 if (intformat != format) return NULL;
708 698
709 switch (intformat)
710 {
711#ifdef EGL_MAP_GL_TEXTURE_LUMINANCE_SEC
712 case GL_LUMINANCE: attr[5] = EGL_MAP_GL_TEXTURE_LUMINANCE_SEC; break;
713#endif
714#ifdef EGL_MAP_GL_TEXTURE_LUMINANCE_ALPHA_SEC
715 case GL_LUMINANCE_ALPHA: attr[5] = EGL_MAP_GL_TEXTURE_LUMINANCE_ALPHA_SEC; break;
716#endif
717 case GL_RGBA: attr[5] = EGL_MAP_GL_TEXTURE_RGBA_SEC; break;
718 case GL_BGRA: attr[5] = EGL_MAP_GL_TEXTURE_BGRA_SEC; break;
719 default: fprintf(stderr, "unknown format\n"); return NULL;
720 }
721
722 pt = calloc(1, sizeof(Evas_GL_Texture_Pool)); 699 pt = calloc(1, sizeof(Evas_GL_Texture_Pool));
723 if (!pt) return NULL; 700 if (!pt) return NULL;
724 _tex_adjust(gc, &w, &h); 701 _tex_adjust(gc, &w, &h);
@@ -745,48 +722,110 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, i
745 722
746 egldisplay = pt->gc->egldisp; 723 egldisplay = pt->gc->egldisp;
747 724
748 attr[1] = pt->w; 725 if (gc->shared->info.sec_tbm_surface)
749 attr[3] = pt->h; 726 {
727 tbm_format buffer_format = TBM_FORMAT_RGBA8888;
728 tbm_surface_info_s info;
729 int attr[] =
730 {
731 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
732 EGL_NONE,
733 };
750 734
751 // FIXME: seems a bit slower than i'd like - maybe too many flushes? 735 switch (intformat)
752 // FIXME: YCbCr no support as yet 736 {
753 pt->dyn.img = secsym_eglCreateImage(egldisplay, 737 case GL_LUMINANCE: buffer_format = TBM_FORMAT_C8; break;
754 EGL_NO_CONTEXT, 738 case GL_LUMINANCE_ALPHA: buffer_format = TBM_FORMAT_C8; break;
755 EGL_MAP_GL_TEXTURE_2D_SEC, 739 case GL_RGBA: buffer_format = TBM_FORMAT_RGBA8888; break;
756 0, attr); 740 case GL_BGRA: buffer_format = TBM_FORMAT_BGRA8888; break;
757 GLERRV("secsym_eglCreateImage"); 741 case GL_RGB: buffer_format = TBM_FORMAT_RGB888; break;
758 if (!pt->dyn.img) 742 default: ERR("TBM: unknown format"); return NULL;
743 }
744
745 pt->dyn.buffer = (void *)secsym_tbm_surface_create(pt->w, pt->h,
746 buffer_format);
747 if (!pt->dyn.buffer) goto error;
748
749 pt->dyn.img = secsym_eglCreateImage(egldisplay,
750 EGL_NO_CONTEXT,
751 EGL_NATIVE_SURFACE_TIZEN,
752 pt->dyn.buffer, attr);
753 if (!pt->dyn.img)
754 {
755 secsym_tbm_surface_destroy(pt->dyn.buffer);
756 goto error;
757 }
758 secsym_tbm_surface_get_info(pt->dyn.buffer, &info);
759 pt->dyn.w = info.width;
760 pt->dyn.h = info.height;
761 pt->dyn.stride = info.planes[0].stride;
762 }
763 else if (gc->shared->info.sec_image_map)
759 { 764 {
760 glBindTexture(GL_TEXTURE_2D, 0); 765 int fmt; // EGL_MAP_GL_TEXTURE_RGBA_SEC or EGL_MAP_GL_TEXTURE_RGB_SEC or bust
761 glDeleteTextures(1, &(pt->texture)); 766 int pixtype; // EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC or bust
762 if (pt->eina_pool) 767 int attr[] =
763 eina_rectangle_pool_free(pt->eina_pool); 768 {
764 free(pt); 769 EGL_MAP_GL_TEXTURE_WIDTH_SEC, 32,
765 return NULL; 770 EGL_MAP_GL_TEXTURE_HEIGHT_SEC, 32,
771 EGL_MAP_GL_TEXTURE_FORMAT_SEC, EGL_MAP_GL_TEXTURE_RGBA_SEC,
772 EGL_MAP_GL_TEXTURE_PIXEL_TYPE_SEC, EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC,
773 EGL_NONE
774 };
775
776 switch (intformat)
777 {
778#ifdef EGL_MAP_GL_TEXTURE_LUMINANCE_SEC
779 case GL_LUMINANCE: attr[5] = EGL_MAP_GL_TEXTURE_LUMINANCE_SEC; break;
780#endif
781#ifdef EGL_MAP_GL_TEXTURE_LUMINANCE_ALPHA_SEC
782 case GL_LUMINANCE_ALPHA: attr[5] = EGL_MAP_GL_TEXTURE_LUMINANCE_ALPHA_SEC; break;
783#endif
784 case GL_RGBA: attr[5] = EGL_MAP_GL_TEXTURE_RGBA_SEC; break;
785 case GL_BGRA: attr[5] = EGL_MAP_GL_TEXTURE_BGRA_SEC; break;
786 default: ERR("SEC map: unknown format"); return NULL;
787 }
788
789 attr[1] = pt->w;
790 attr[3] = pt->h;
791
792 // FIXME: seems a bit slower than i'd like - maybe too many flushes?
793 // FIXME: YCbCr no support as yet
794 pt->dyn.img = secsym_eglCreateImage(egldisplay,
795 EGL_NO_CONTEXT,
796 EGL_MAP_GL_TEXTURE_2D_SEC,
797 0, attr);
798 GLERRV("secsym_eglCreateImage");
799 if (!pt->dyn.img) goto error;
800
801 if (secsym_eglGetImageAttribSEC(egldisplay,
802 pt->dyn.img,
803 EGL_MAP_GL_TEXTURE_WIDTH_SEC,
804 &(pt->dyn.w)) != EGL_TRUE) goto error;
805 if (secsym_eglGetImageAttribSEC(egldisplay,
806 pt->dyn.img,
807 EGL_MAP_GL_TEXTURE_HEIGHT_SEC,
808 &(pt->dyn.h)) != EGL_TRUE) goto error;
809 if (secsym_eglGetImageAttribSEC(egldisplay,
810 pt->dyn.img,
811 EGL_MAP_GL_TEXTURE_STRIDE_IN_BYTES_SEC,
812 &(pt->dyn.stride)) != EGL_TRUE) goto error;
813 if (secsym_eglGetImageAttribSEC(egldisplay,
814 pt->dyn.img,
815 EGL_MAP_GL_TEXTURE_FORMAT_SEC,
816 &(fmt)) != EGL_TRUE) goto error;
817 if (secsym_eglGetImageAttribSEC(egldisplay,
818 pt->dyn.img,
819 EGL_MAP_GL_TEXTURE_PIXEL_TYPE_SEC,
820 &(pixtype)) != EGL_TRUE) goto error;
821
822 if (pixtype != EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC) goto error;
823 }
824 else
825 {
826 ERR("TBM surface or SEC image map should be enabled!");
827 goto error;
766 } 828 }
767 if (secsym_eglGetImageAttribSEC(egldisplay,
768 pt->dyn.img,
769 EGL_MAP_GL_TEXTURE_WIDTH_SEC,
770 &(pt->dyn.w)) != EGL_TRUE) goto error;
771 if (secsym_eglGetImageAttribSEC(egldisplay,
772 pt->dyn.img,
773 EGL_MAP_GL_TEXTURE_HEIGHT_SEC,
774 &(pt->dyn.h)) != EGL_TRUE) goto error;
775 if (secsym_eglGetImageAttribSEC(egldisplay,
776 pt->dyn.img,
777 EGL_MAP_GL_TEXTURE_STRIDE_IN_BYTES_SEC,
778 &(pt->dyn.stride)) != EGL_TRUE) goto error;
779 if (secsym_eglGetImageAttribSEC(egldisplay,
780 pt->dyn.img,
781 EGL_MAP_GL_TEXTURE_FORMAT_SEC,
782 &(fmt)) != EGL_TRUE) goto error;
783
784 if (secsym_eglGetImageAttribSEC(egldisplay,
785 pt->dyn.img,
786 EGL_MAP_GL_TEXTURE_PIXEL_TYPE_SEC,
787 &(pixtype)) != EGL_TRUE) goto error;
788
789 if (pixtype != EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC) goto error;
790 829
791 glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex); 830 glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex);
792#else 831#else
@@ -797,9 +836,12 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, i
797/* ERROR HANDLING */ 836/* ERROR HANDLING */
798#ifdef GL_GLES 837#ifdef GL_GLES
799error: 838error:
800 secsym_eglDestroyImage(egldisplay, pt->dyn.img); 839 if (pt->dyn.img)
801 GLERRV("secsym_eglDestroyImage"); 840 {
802 pt->dyn.img = NULL; 841 secsym_eglDestroyImage(egldisplay, pt->dyn.img);
842 GLERRV("secsym_eglDestroyImage");
843 pt->dyn.img = NULL;
844 }
803 glBindTexture(GL_TEXTURE_2D, 0); 845 glBindTexture(GL_TEXTURE_2D, 0);
804 glDeleteTextures(1, &(pt->texture)); 846 glDeleteTextures(1, &(pt->texture));
805 if (pt->eina_pool) 847 if (pt->eina_pool)
@@ -853,9 +895,17 @@ evas_gl_texture_pool_empty(Evas_GL_Texture_Pool *pt)
853 if (pt->dyn.img) 895 if (pt->dyn.img)
854 { 896 {
855 if (pt->dyn.checked_out > 0) 897 if (pt->dyn.checked_out > 0)
856 secsym_eglUnmapImageSEC(pt->gc->egldisp, pt->dyn.img, EGL_MAP_GL_TEXTURE_DEVICE_CPU_SEC); 898 {
899 if (pt->gc->shared->info.sec_tbm_surface)
900 secsym_tbm_surface_unmap(pt->dyn.buffer);
901 else if (pt->gc->shared->info.sec_image_map)
902 secsym_eglUnmapImageSEC(pt->gc->egldisp, pt->dyn.img, EGL_MAP_GL_TEXTURE_DEVICE_CPU_SEC);
903 }
904 if (pt->dyn.buffer)
905 secsym_tbm_surface_destroy(pt->dyn.buffer);
857 secsym_eglDestroyImage(pt->gc->egldisp, pt->dyn.img); 906 secsym_eglDestroyImage(pt->gc->egldisp, pt->dyn.img);
858 pt->dyn.img = NULL; 907 pt->dyn.img = NULL;
908 pt->dyn.buffer = NULL;
859 pt->dyn.data = NULL; 909 pt->dyn.data = NULL;
860 pt->dyn.w = 0; 910 pt->dyn.w = 0;
861 pt->dyn.h = 0; 911 pt->dyn.h = 0;