From 4263c087604264f282e846f91fb8e8c484762ac5 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Fri, 16 Apr 2021 03:15:31 +0000 Subject: [PATCH] evas gl - drm - native bind - handle null eglimage create on bind this can happen if dmabuf is invalid (already destroyed) so handle this so evas knows and falls back to rendering a rect and complains to stderr so we know @fix --- .../evas/engines/gl_common/evas_gl_common.h | 2 ++ .../evas/engines/gl_common/evas_gl_context.c | 24 ++++++++++++++++++- src/modules/evas/engines/gl_drm/evas_engine.c | 20 +++++++++------- 3 files changed, 37 insertions(+), 9 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 2d9d825a75..baa1660d66 100644 --- a/src/modules/evas/engines/gl_common/evas_gl_common.h +++ b/src/modules/evas/engines/gl_common/evas_gl_common.h @@ -367,6 +367,7 @@ struct _Evas_Engine_GL_Context Eina_List *font_glyph_textures; Eina_List *font_glyph_images; Evas_GL_Image *def_surface; + Evas_GL_Image *err_img; RGBA_Image *font_surface; int font_glyph_textures_size; int font_glyph_atlas_size; @@ -479,6 +480,7 @@ struct _Evas_GL_Image Eina_Bool yinvert : 1; Eina_Bool mipmap : 1; Eina_Bool loose : 1; + Eina_Bool invalid : 1; } native; struct { 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 26ff021cd4..af51f9626e 100644 --- a/src/modules/evas/engines/gl_common/evas_gl_context.c +++ b/src/modules/evas/engines/gl_common/evas_gl_context.c @@ -1180,6 +1180,7 @@ evas_gl_common_context_new(void) _evas_gl_common_viewport_set(gc); gc->def_surface = evas_gl_common_image_surface_new(gc, 1, 1, 1, EINA_FALSE); + gc->err_img = evas_gl_common_image_surface_new(gc, 1, 1, 0, EINA_FALSE); return gc; @@ -1428,6 +1429,7 @@ evas_gl_common_context_free(Evas_Engine_GL_Context *gc) if (gc->references > 0) return; if (gc->shared) gc->shared->references--; + if (gc->err_img) evas_gl_common_image_free(gc->err_img); if (gc->def_surface) evas_gl_common_image_free(gc->def_surface); if (gc->font_surface) @@ -4035,7 +4037,27 @@ shader_array_flush(Evas_Engine_GL_Context *gc) if (!gc->pipe[i].array.im->native.loose) { if (gc->pipe[i].array.im->native.func.bind) - gc->pipe[i].array.im->native.func.bind(gc->pipe[i].array.im); + { + gc->pipe[i].array.im->native.func.bind(gc->pipe[i].array.im); + if (gc->pipe[i].array.im->native.invalid) + { + fprintf(stderr, + "Evas GL: native bind failed for %ix%i image\n", + gc->pipe[i].array.im->w, + gc->pipe[i].array.im->h); + if ((gc->err_img) && + (gc->err_img->tex) && + (gc->err_img->tex->pt)) + { + glActiveTexture(GL_TEXTURE0); + glBindTexture + (GL_TEXTURE_2D, + gc->err_img->tex->pt->texture); + gc->pipe[i].shader.cur_tex = + gc->err_img->tex->pt->texture; + } + } + } } } } diff --git a/src/modules/evas/engines/gl_drm/evas_engine.c b/src/modules/evas/engines/gl_drm/evas_engine.c index 3ecea196c5..d59f762160 100644 --- a/src/modules/evas/engines/gl_drm/evas_engine.c +++ b/src/modules/evas/engines/gl_drm/evas_engine.c @@ -798,15 +798,17 @@ _native_cb_bind(void *image) if (n->ns.type == EVAS_NATIVE_SURFACE_WL_DMABUF) { - void *v; - /* Must re-import every time for coherency. */ if (n->ns_data.wl_surface_dmabuf.image) glsym_evas_gl_common_eglDestroyImage(img->native.disp, n->ns_data.wl_surface_dmabuf.image); - v = gl_import_simple_dmabuf(img->native.disp, &n->ns_data.wl_surface_dmabuf.attr); - if (!v) return; - glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, v); - n->ns_data.wl_surface_dmabuf.image = v; + n->ns_data.wl_surface_dmabuf.image = gl_import_simple_dmabuf(img->native.disp, &n->ns_data.wl_surface_dmabuf.attr); + if (!n->ns_data.wl_surface_dmabuf.image) + { + img->native.invalid = EINA_TRUE; + return; + } + img->native.invalid = EINA_FALSE; + glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, n->ns_data.wl_surface_dmabuf.image); } else if (n->ns.type == EVAS_NATIVE_SURFACE_WL) { @@ -839,8 +841,10 @@ _native_cb_unbind(void *image) if (n->ns.type == EVAS_NATIVE_SURFACE_WL_DMABUF) { if (n->ns_data.wl_surface_dmabuf.image) - glsym_evas_gl_common_eglDestroyImage(img->native.disp, n->ns_data.wl_surface_dmabuf.image); - n->ns_data.wl_surface_dmabuf.image = NULL; + { + glsym_evas_gl_common_eglDestroyImage(img->native.disp, n->ns_data.wl_surface_dmabuf.image); + n->ns_data.wl_surface_dmabuf.image = NULL; + } } else if (n->ns.type == EVAS_NATIVE_SURFACE_WL) {