From 3b5b553e7beda756d6f61e36a88e4af9370235f0 Mon Sep 17 00:00:00 2001 From: Joogab Yun Date: Fri, 20 Nov 2015 14:55:43 +0900 Subject: [PATCH] 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. From 7db0e2066108c2ee78afd317727b581d1d7e8342 Mon Sep 17 00:00:00 2001 From: Dongyeon Kim Change-Id: Iab9437f0119025d7b97223f8b12e723a2e336771 --- .../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(-) mode change 100644 => 100755 src/modules/evas/engines/gl_common/evas_gl_context.c 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 eb5e44c..dc1c352 100755 --- a/src/modules/evas/engines/gl_common/evas_gl_common.h +++ b/src/modules/evas/engines/gl_common/evas_gl_common.h @@ -251,6 +251,7 @@ struct _Evas_Engine_GL_Context Evas_GL_Shader id; GLuint cur_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; @@ -281,6 +282,7 @@ struct _Evas_Engine_GL_Context GLuint cur_prog; 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; @@ -354,6 +356,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 old mode 100644 new mode 100755 index a1b8abd..cfb2d76 --- a/src/modules/evas/engines/gl_common/evas_gl_context.c +++ b/src/modules/evas/engines/gl_common/evas_gl_context.c @@ -1081,6 +1081,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; @@ -1110,6 +1111,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; @@ -1149,7 +1151,7 @@ evas_gl_common_context_newframe(Evas_Engine_GL_Context *gc) else glUseProgram(gc->state.current.cur_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,1); } @@ -1238,6 +1240,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; @@ -2094,9 +2097,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) { @@ -2147,6 +2156,7 @@ evas_gl_common_context_image_push(Evas_Engine_GL_Context *gc, gc->pipe[pn].shader.cur_tex = pt->texture; gc->pipe[pn].shader.cur_texm = mtex ? mtex->pt->texture : 0; gc->pipe[pn].shader.cur_prog = prog; + 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; @@ -3149,7 +3159,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) { @@ -3157,7 +3167,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 @@ -3723,6 +3733,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 1a954f0..3e491dd 100644 --- a/src/modules/evas/engines/gl_generic/evas_engine.c +++ b/src/modules/evas/engines/gl_generic/evas_engine.c @@ -727,9 +727,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) { @@ -737,7 +735,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, @@ -745,7 +743,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 fcc8f67..df3983e 100644 --- a/src/modules/evas/engines/gl_x11/evas_engine.c +++ b/src/modules/evas/engines/gl_x11/evas_engine.c @@ -1976,7 +1976,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 @@ -1999,7 +1999,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) { @@ -2008,7 +2008,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 @@ -2027,7 +2027,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 @@ -2085,7 +2085,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) { -- 2.7.4