spacegrapher pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=7db0e2066108c2ee78afd317727b581d1d7e8342

commit 7db0e2066108c2ee78afd317727b581d1d7e8342
Author: Dongyeon Kim <dy5....@samsung.com>
Date:   Thu Nov 12 13:56:17 2015 +0900

    evas/gl: Bind texture with external target for tbm surface
    
    egl images created using tbm surface for native surface set use
    GL_TEXTURE_EXTERNAL_OES as texture target, so we should bind to
    this target when rendering.
    Dynamic hint set using tbm surface also creates egl images, but
    as we only use RGB* colorspace for this we can use GL_TEXTURE_2D.
    So, keep track of texture target in shader array, and bind to the
    appropriate one.
    This also fixes the bug that image_data_get only worked when BOTH
    sec_image_map and sec_tbm_surface extensions are supported.
---
 .../evas/engines/gl_common/evas_gl_common.h        |  3 ++
 .../evas/engines/gl_common/evas_gl_context.c       | 21 +++++++---
 .../evas/engines/gl_common/evas_gl_texture.c       | 45 ++++++++++------------
 src/modules/evas/engines/gl_generic/evas_engine.c  |  8 ++--
 src/modules/evas/engines/gl_x11/evas_engine.c      | 10 ++---
 5 files changed, 48 insertions(+), 39 deletions(-)

diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h 
b/src/modules/evas/engines/gl_common/evas_gl_common.h
index 5fd8775..202e81b 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -253,6 +253,7 @@ struct _Evas_Engine_GL_Context
       struct {
          Evas_GL_Program *prog;
          GLuint          cur_tex, cur_texu, cur_texv, cur_texa, cur_texm;
+         int             tex_target;
          int             render_op;
          int             cx, cy, cw, ch;
          int             smooth;
@@ -282,6 +283,7 @@ struct _Evas_Engine_GL_Context
          Evas_GL_Image  *surface;
          GLuint          cur_tex, cur_texu, cur_texv, cur_texa, cur_texm;
          void           *cur_tex_dyn, *cur_texu_dyn, *cur_texv_dyn;
+         int             tex_target;
          int             render_op;
          int             cx, cy, cw, ch;
          int             smooth;
@@ -355,6 +357,7 @@ struct _Evas_GL_Texture_Pool
       int           w, h;
       int           stride;
       int           checked_out;
+      int           target;
    } dyn;
    Eina_List       *allocations;
    Eina_Rectangle_Pool *eina_pool;
diff --git a/src/modules/evas/engines/gl_common/evas_gl_context.c 
b/src/modules/evas/engines/gl_common/evas_gl_context.c
index d39be5a..dc33384 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_context.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_context.c
@@ -1071,6 +1071,7 @@ evas_gl_common_context_newframe(Evas_Engine_GL_Context 
*gc)
    gc->state.current.cur_texv = 0;
    gc->state.current.cur_texa = 0;
    gc->state.current.cur_texm = 0;
+   gc->state.current.tex_target = GL_TEXTURE_2D;
    gc->state.current.render_op = 0;
    gc->state.current.smooth = 0;
    gc->state.current.blend = 0;
@@ -1099,6 +1100,7 @@ evas_gl_common_context_newframe(Evas_Engine_GL_Context 
*gc)
         gc->pipe[i].shader.cur_texv = 0;
         gc->pipe[i].shader.cur_texa = 0;
         gc->pipe[i].shader.cur_texm = 0;
+        gc->pipe[i].shader.tex_target = GL_TEXTURE_2D;
         gc->pipe[i].shader.render_op = EVAS_RENDER_BLEND;
         gc->pipe[i].shader.smooth = 0;
         gc->pipe[i].shader.blend = 0;
@@ -1137,7 +1139,7 @@ evas_gl_common_context_newframe(Evas_Engine_GL_Context 
*gc)
      glUseProgram(gc->state.current.prog->prog);
 
    glActiveTexture(GL_TEXTURE0);
-   glBindTexture(GL_TEXTURE_2D, gc->pipe[0].shader.cur_tex);
+   glBindTexture(gc->pipe[0].shader.tex_target, gc->pipe[0].shader.cur_tex);
 
    _evas_gl_common_viewport_set(gc);
 }
@@ -1222,6 +1224,7 @@ 
evas_gl_common_context_target_surface_set(Evas_Engine_GL_Context *gc,
    gc->state.current.cur_texv = 0;
    gc->state.current.cur_texa = 0;
    gc->state.current.cur_texm = 0;
+   gc->state.current.tex_target = GL_TEXTURE_2D;
    gc->state.current.render_op = -1;
    gc->state.current.smooth = -1;
    gc->state.current.blend = -1;
@@ -1917,9 +1920,15 @@ evas_gl_common_context_image_push(Evas_Engine_GL_Context 
*gc,
    Shader_Sampling sam = 0, masksam = 0;
    int yinvert = 0;
    Shader_Type shd_in = SHD_IMAGE;
+   int tex_target = GL_TEXTURE_2D;
 
-   if ((tex->im) && (tex->im->native.data))
-     shd_in = SHD_IMAGENATIVE;
+   if (tex->im)
+     {
+        if (tex->im->native.data)
+          shd_in = SHD_IMAGENATIVE;
+        if (tex->im->native.target == GL_TEXTURE_EXTERNAL_OES)
+          tex_target = GL_TEXTURE_EXTERNAL_OES;
+     }
 
    if (!!mtex)
      {
@@ -1968,6 +1977,7 @@ evas_gl_common_context_image_push(Evas_Engine_GL_Context 
*gc,
    gc->pipe[pn].shader.prog = prog;
    gc->pipe[pn].shader.cur_tex = pt->texture;
    gc->pipe[pn].shader.cur_texm = mtex ? mtex->pt->texture : 0;
+   gc->pipe[pn].shader.tex_target = tex_target;
    gc->pipe[pn].shader.smooth = smooth;
    gc->pipe[pn].shader.mask_smooth = mask_smooth;
    gc->pipe[pn].shader.blend = blend;
@@ -2951,7 +2961,7 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
                }
 #endif
              glActiveTexture(GL_TEXTURE0);
-             glBindTexture(GL_TEXTURE_2D, gc->pipe[i].shader.cur_tex);
+             glBindTexture(gc->pipe[i].shader.tex_target, 
gc->pipe[i].shader.cur_tex);
           }
         if (gc->pipe[i].array.im)
           {
@@ -2959,7 +2969,7 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
              if (gc->pipe[i].array.im->tex->pt->dyn.img)
                {
                   secsym_glEGLImageTargetTexture2DOES
-                        (GL_TEXTURE_2D, 
gc->pipe[i].array.im->tex->pt->dyn.img);
+                        (gc->pipe[i].array.im->tex->pt->dyn.target, 
gc->pipe[i].array.im->tex->pt->dyn.img);
                }
              else
 #endif
@@ -3524,6 +3534,7 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
         gc->state.current.cur_texa  = gc->pipe[i].shader.cur_texa;
         gc->state.current.cur_texu  = gc->pipe[i].shader.cur_texu;
         gc->state.current.cur_texv  = gc->pipe[i].shader.cur_texv;
+        gc->state.current.tex_target = gc->pipe[i].shader.tex_target;
         gc->state.current.render_op = gc->pipe[i].shader.render_op;
 //        gc->state.current.cx        = gc->pipe[i].shader.cx;
 //        gc->state.current.cy        = gc->pipe[i].shader.cy;
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 b848c68..3107507 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_texture.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_texture.c
@@ -400,7 +400,7 @@ _pool_tex_new(Evas_Engine_GL_Context *gc, int w, int h, 
GLenum intformat, GLenum
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    ok = _tex_2d(gc, pt->intformat, w, h, pt->format, pt->dataformat);
-   glBindTexture(GL_TEXTURE_2D, gc->state.current.cur_tex);
+   glBindTexture(gc->state.current.tex_target, gc->state.current.cur_tex);
    if (!ok)
      {
         glDeleteTextures(1, &(pt->texture));
@@ -632,7 +632,7 @@ _pool_tex_render_new(Evas_Engine_GL_Context *gc, int w, int 
h, int intformat, in
      }
 
    glsym_glBindFramebuffer(GL_FRAMEBUFFER, fnum);
-   glBindTexture(GL_TEXTURE_2D, gc->state.current.cur_tex);
+   glBindTexture(gc->state.current.tex_target, gc->state.current.cur_tex);
 
    if (!ok)
      {
@@ -700,7 +700,7 @@ _pool_tex_native_new(Evas_Engine_GL_Context *gc, int w, int 
h, int intformat, in
    glTexParameteri(im->native.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(im->native.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glBindTexture(im->native.target, 0);
-   glBindTexture(im->native.target, gc->state.current.cur_tex);
+   glBindTexture(gc->state.current.tex_target, gc->state.current.cur_tex);
 
    texinfo.n.num++;
    texinfo.n.pix += pt->w * pt->h;
@@ -735,12 +735,14 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, i
 
    _print_tex_count();
 
+   pt->dyn.target = GL_TEXTURE_2D;
+
    glGenTextures(1, &(pt->texture));
-   glBindTexture(GL_TEXTURE_2D, pt->texture);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+   glBindTexture(pt->dyn.target, pt->texture);
+   glTexParameteri(pt->dyn.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+   glTexParameteri(pt->dyn.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+   glTexParameteri(pt->dyn.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+   glTexParameteri(pt->dyn.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
    egldisplay = pt->gc->egldisp;
 
@@ -748,11 +750,6 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, i
      {
         tbm_format buffer_format = TBM_FORMAT_RGBA8888;
         tbm_surface_info_s info;
-        int attr[] =
-          {
-             EGL_IMAGE_PRESERVED_KHR,    EGL_TRUE,
-             EGL_NONE,
-          };
 
         switch (intformat)
           {
@@ -771,7 +768,7 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, i
         pt->dyn.img = secsym_eglCreateImage(egldisplay,
                                             EGL_NO_CONTEXT,
                                             EGL_NATIVE_SURFACE_TIZEN,
-                                            pt->dyn.buffer, attr);
+                                            pt->dyn.buffer, NULL);
         if (!pt->dyn.img)
           {
              secsym_tbm_surface_destroy(pt->dyn.buffer);
@@ -848,7 +845,7 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, 
int h, int intformat, i
         goto error;
      }
 
-   glBindTexture(GL_TEXTURE_2D, gc->state.current.cur_tex);
+   glBindTexture(gc->state.current.tex_target, gc->state.current.cur_tex);
 #else
    if (gc + w + h + intformat + format) return pt;
 #endif
@@ -862,7 +859,7 @@ error:
        secsym_eglDestroyImage(egldisplay, pt->dyn.img);
        pt->dyn.img = NULL;
     }
-  glBindTexture(GL_TEXTURE_2D, 0);
+  glBindTexture(pt->dyn.target, 0);
   glDeleteTextures(1, &(pt->texture));
   if (pt->eina_pool)
     eina_rectangle_pool_free(pt->eina_pool);
@@ -1171,7 +1168,7 @@ evas_gl_common_texture_upload(Evas_GL_Texture *tex, 
RGBA_Image *im, unsigned int
      }
    //glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    if (tex->pt->texture != tex->gc->state.current.cur_tex)
-     glBindTexture(GL_TEXTURE_2D, tex->gc->state.current.cur_tex);
+     glBindTexture(tex->gc->state.current.tex_target, 
tex->gc->state.current.cur_tex);
 }
 
 void
@@ -1271,7 +1268,7 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, 
RGBA_Image *im)
 
            if (tex->pt->texture != tex->gc->state.current.cur_tex)
              {
-                glBindTexture(GL_TEXTURE_2D, tex->gc->state.current.cur_tex);
+                glBindTexture(tex->gc->state.current.tex_target, 
tex->gc->state.current.cur_tex);
              }
            return;
         }
@@ -1391,7 +1388,7 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, 
RGBA_Image *im)
 
         // Switch back to current texture
         if (tex->ptt->texture != tex->gc->state.current.cur_tex)
-          glBindTexture(GL_TEXTURE_2D, tex->gc->state.current.cur_tex);
+          glBindTexture(tex->gc->state.current.tex_target, 
tex->gc->state.current.cur_tex);
 
         // Now prepare uploading the main texture before returning;
         async = malloc(sizeof (Evas_GL_Texture_Async_Preload));
@@ -1529,7 +1526,7 @@ evas_gl_common_texture_alpha_update(Evas_GL_Texture *tex, 
DATA8 *pixels,
    _tex_sub_2d(tex->gc, tex->x, tex->y, w, h, tex->pt->format,
                tex->pt->dataformat, pixels);
    if (tex->pt->texture != tex->gc->state.current.cur_tex)
-     glBindTexture(GL_TEXTURE_2D, tex->gc->state.current.cur_tex);
+     glBindTexture(tex->gc->state.current.tex_target, 
tex->gc->state.current.cur_tex);
 }
 
 Evas_GL_Texture *
@@ -1703,7 +1700,7 @@ evas_gl_common_texture_rgb_a_pair_update(Evas_GL_Texture 
*tex,
           }
      }
 on_error:
-   glBindTexture(GL_TEXTURE_2D, tex->gc->state.current.cur_tex);
+   glBindTexture(tex->gc->state.current.tex_target, 
tex->gc->state.current.cur_tex);
 }
 
 Evas_GL_Texture *
@@ -1886,7 +1883,7 @@ evas_gl_common_texture_yuv_update(Evas_GL_Texture *tex, 
DATA8 **rows, unsigned i
           }
      }
    if (tex->pt->texture != tex->gc->state.current.cur_tex)
-     glBindTexture(GL_TEXTURE_2D, tex->gc->state.current.cur_tex);
+     glBindTexture(tex->gc->state.current.tex_target, 
tex->gc->state.current.cur_tex);
 }
 
 static Evas_GL_Texture *
@@ -2055,7 +2052,7 @@ evas_gl_common_texture_yuy2_update(Evas_GL_Texture *tex, 
DATA8 **rows, unsigned
      }
 
    if (tex->pt->texture != tex->gc->state.current.cur_tex)
-     glBindTexture(GL_TEXTURE_2D, tex->gc->state.current.cur_tex);
+     glBindTexture(tex->gc->state.current.tex_target, 
tex->gc->state.current.cur_tex);
 }
 
 void
@@ -2110,7 +2107,7 @@ evas_gl_common_texture_nv12_update(Evas_GL_Texture *tex, 
DATA8 **rows, unsigned
           }
      }
    if (tex->pt->texture != tex->gc->state.current.cur_tex)
-     glBindTexture(GL_TEXTURE_2D, tex->gc->state.current.cur_tex);
+     glBindTexture(tex->gc->state.current.tex_target, 
tex->gc->state.current.cur_tex);
 }
 
 void
diff --git a/src/modules/evas/engines/gl_generic/evas_engine.c 
b/src/modules/evas/engines/gl_generic/evas_engine.c
index 8895f9b..6adea19 100644
--- a/src/modules/evas/engines/gl_generic/evas_engine.c
+++ b/src/modules/evas/engines/gl_generic/evas_engine.c
@@ -746,9 +746,7 @@ eng_image_data_get(void *data, void *image, int to_write, 
DATA32 **image_data, i
    re->window_use(re->software.ob);
 
    if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.img) && 
-       (im->cs.space == EVAS_COLORSPACE_ARGB8888) &&
-       secsym_tbm_surface_map &&
-       secsym_eglMapImageSEC)
+       (im->cs.space == EVAS_COLORSPACE_ARGB8888))
      {
         if (im->tex->pt->dyn.checked_out > 0)
           {
@@ -756,7 +754,7 @@ eng_image_data_get(void *data, void *image, int to_write, 
DATA32 **image_data, i
              *image_data = im->tex->pt->dyn.data;
              return im;
           }
-        if (im->gc->shared->info.sec_tbm_surface)
+        if ((im->gc->shared->info.sec_tbm_surface) && (secsym_tbm_surface_map))
           {
              tbm_surface_info_s info;
              secsym_tbm_surface_map(im->tex->pt->dyn.buffer,
@@ -764,7 +762,7 @@ eng_image_data_get(void *data, void *image, int to_write, 
DATA32 **image_data, i
                                     &info);
              *image_data = im->tex->pt->dyn.data = (DATA32 *) 
info.planes[0].ptr;
           }
-        else if (im->gc->shared->info.sec_image_map)
+        else if ((im->gc->shared->info.sec_image_map) && 
(secsym_eglMapImageSEC))
           {
              void *disp = re->window_egl_display_get(re->software.ob);
              *image_data = im->tex->pt->dyn.data = secsym_eglMapImageSEC(disp,
diff --git a/src/modules/evas/engines/gl_x11/evas_engine.c 
b/src/modules/evas/engines/gl_x11/evas_engine.c
index ffb5a32..ab45b76 100644
--- a/src/modules/evas/engines/gl_x11/evas_engine.c
+++ b/src/modules/evas/engines/gl_x11/evas_engine.c
@@ -2037,7 +2037,7 @@ _native_bind_cb(void *data EINA_UNUSED, void *image)
          {
             if (glsym_glEGLImageTargetTexture2DOES)
               {
-                 glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, n->surface);
+                 glsym_glEGLImageTargetTexture2DOES(im->native.target, 
n->surface);
                  GLERRV("glsym_glEGLImageTargetTexture2DOES");
               }
             else
@@ -2060,7 +2060,7 @@ _native_bind_cb(void *data EINA_UNUSED, void *image)
     }
   else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
     {
-       glBindTexture(GL_TEXTURE_2D, n->ns.data.opengl.texture_id);
+       glBindTexture(im->native.target, n->ns.data.opengl.texture_id);
     }
   else if (n->ns.type == EVAS_NATIVE_SURFACE_TBM)
     {
@@ -2069,7 +2069,7 @@ _native_bind_cb(void *data EINA_UNUSED, void *image)
          {
             if (glsym_glEGLImageTargetTexture2DOES)
               {
-                 glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, 
n->surface);
+                 glsym_glEGLImageTargetTexture2DOES(im->native.target, 
n->surface);
                  GLERRV("glsym_glEGLImageTargetTexture2DOES");
               }
              else
@@ -2088,7 +2088,7 @@ _native_bind_cb(void *data EINA_UNUSED, void *image)
 #ifdef GL_GLES
                  if (glsym_glEGLImageTargetTexture2DOES)
                    {
-                      glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, 
buffer);
+                      glsym_glEGLImageTargetTexture2DOES(im->native.target, 
buffer);
                       GLERRV("glsym_glEGLImageTargetTexture2DOES");
                    }
                  else
@@ -2146,7 +2146,7 @@ _native_unbind_cb(void *data EINA_UNUSED, void *image)
      }
    else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
      {
-        glBindTexture(GL_TEXTURE_2D, 0);
+        glBindTexture(im->native.target, 0);
      }
    else if (n->ns.type == EVAS_NATIVE_SURFACE_TBM)
      {

-- 


Reply via email to