evas-wayland-egl: Fix missing support for EVAS_NATIVE_SURFACE_WL

Summary: Support for using EVAS_NATIVE_SURFACE_WL was missing/incomplete in the
wayland_egl engine. This commit addresses that issue so that now the
wayland_egl engine can support both EVAS_NATIVE_SURFACE_OPENGL and
EVAS_NATIVE_SURFACE_WL.

@fix

Signed-off-by: Chris Michael <cp.michael@samsung.com>
This commit is contained in:
Chris Michael 2015-11-02 16:08:27 -05:00
parent c3f40bd0f9
commit 1dbecbb676
1 changed files with 160 additions and 14 deletions

View File

@ -33,6 +33,7 @@ typedef struct _Native Native;
struct _Native
{
Evas_Native_Surface ns;
struct wl_buffer *wl_buf;
void *egl_surface;
};
@ -75,6 +76,7 @@ void (*glsym_eglDestroyImage) (EGLDisplay a, void *b) = NULL;
void (*glsym_glEGLImageTargetTexture2DOES) (int a, void *b) = NULL;
unsigned int (*glsym_eglSwapBuffersWithDamage) (EGLDisplay a, void *b, const EGLint *d, EGLint c) = NULL;
unsigned int (*glsym_eglSetDamageRegionKHR) (EGLDisplay a, EGLSurface b, EGLint *c, EGLint d) = NULL;
unsigned int (*glsym_eglQueryWaylandBufferWL)(EGLDisplay a, struct wl_resource *b, EGLint c, EGLint *d) = NULL;
/* local variables */
static Eina_Bool initted = EINA_FALSE;
@ -171,6 +173,9 @@ gl_symbols(void)
FINDSYM(glsym_eglSetDamageRegionKHR, "eglSetDamageRegionKHR",
glsym_func_uint);
FINDSYM(glsym_eglQueryWaylandBufferWL, "eglQueryWaylandBufferWL",
glsym_func_uint);
done = EINA_TRUE;
}
@ -797,7 +802,21 @@ _native_cb_bind(void *data EINA_UNUSED, void *image)
if (!(img = image)) return;
if (!(n = img->native.data)) return;
if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
{
if (n->egl_surface)
{
if (glsym_glEGLImageTargetTexture2DOES)
{
glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, n->egl_surface);
if (eglGetError() != EGL_SUCCESS)
ERR("glEGLImageTargetTexture2DOES() failed.");
}
else
ERR("Try glEGLImageTargetTexture2DOES on EGL with no support");
}
}
else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
{
glBindTexture(GL_TEXTURE_2D, n->ns.data.opengl.texture_id);
}
@ -812,7 +831,11 @@ _native_cb_unbind(void *data EINA_UNUSED, void *image)
if (!(img = image)) return;
if (!(n = img->native.data)) return;
if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
{
//glBindTexture(GL_TEXTURE_2D, 0); //really need?
}
else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
{
glBindTexture(GL_TEXTURE_2D, 0);
}
@ -826,13 +849,30 @@ _native_cb_free(void *data, void *image)
Evas_GL_Image *img;
Native *n;
uint32_t texid;
void *wlid;
if (!(re = (Render_Engine *)data)) return;
if (!(img = image)) return;
if (!(n = img->native.data)) return;
if (!(ob = eng_get_ob(re))) return;
if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
{
wlid = (void*)n->wl_buf;
eina_hash_del(ob->gl_context->shared->native_wl_hash, &wlid, img);
if (n->egl_surface)
{
if (glsym_eglDestroyImage)
{
glsym_eglDestroyImage(ob->egl_disp, n->egl_surface);
if (eglGetError() != EGL_SUCCESS)
ERR("eglDestroyImage() failed.");
}
else
ERR("Try eglDestroyImage on EGL with no support");
}
}
else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
{
texid = n->ns.data.opengl.texture_id;
eina_hash_del(ob->gl_context->shared->native_tex_hash, &texid, img);
@ -857,6 +897,7 @@ eng_image_native_set(void *data, void *image, void *native)
Evas_GL_Image *img, *img2;
unsigned int tex = 0, fbo = 0;
uint32_t texid;
void *wlid, *wl_buf = NULL;
if (!(re = (Render_Engine *)data)) return NULL;
if (!(ob = eng_get_ob(re))) return NULL;
@ -878,18 +919,33 @@ eng_image_native_set(void *data, void *image, void *native)
return NULL;
}
if ((ns) && (ns->type == EVAS_NATIVE_SURFACE_OPENGL))
if (ns)
{
tex = ns->data.opengl.texture_id;
fbo = ns->data.opengl.framebuffer_id;
if (img->native.data)
if (ns->type == EVAS_NATIVE_SURFACE_WL)
{
Evas_Native_Surface *ens;
wl_buf = ns->data.wl.legacy_buffer;
if (img->native.data)
{
Evas_Native_Surface *ens;
ens = img->native.data;
if ((ens->data.opengl.texture_id == tex) &&
(ens->data.opengl.framebuffer_id == fbo))
return img;
ens = img->native.data;
if (ens->data.wl.legacy_buffer == wl_buf)
return img;
}
}
else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
{
tex = ns->data.opengl.texture_id;
fbo = ns->data.opengl.framebuffer_id;
if (img->native.data)
{
Evas_Native_Surface *ens;
ens = img->native.data;
if ((ens->data.opengl.texture_id == tex) &&
(ens->data.opengl.framebuffer_id == fbo))
return img;
}
}
}
@ -906,7 +962,22 @@ eng_image_native_set(void *data, void *image, void *native)
if (!ns) return img;
if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
if (ns->type == EVAS_NATIVE_SURFACE_WL)
{
wlid = wl_buf;
img2 = eina_hash_find(ob->gl_context->shared->native_wl_hash, &wlid);
if (img2 == img) return img;
if (img2)
{
if((n = img2->native.data))
{
glsym_evas_gl_common_image_ref(img2);
glsym_evas_gl_common_image_free(img);
return img2;
}
}
}
else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
{
texid = tex;
img2 = eina_hash_find(ob->gl_context->shared->native_tex_hash, &texid);
@ -929,7 +1000,82 @@ eng_image_native_set(void *data, void *image, void *native)
if (!(img = img2)) return NULL;
if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
if (ns->type == EVAS_NATIVE_SURFACE_WL)
{
if (native)
{
if ((n = calloc(1, sizeof(Native))))
{
EGLint attribs[3];
int format, yinvert = 1;
glsym_eglQueryWaylandBufferWL(ob->egl_disp, wl_buf,
EGL_TEXTURE_FORMAT, &format);
if ((format != EGL_TEXTURE_RGB) &&
(format != EGL_TEXTURE_RGBA))
{
ERR("eglQueryWaylandBufferWL() %d format is not supported ", format);
glsym_evas_gl_common_image_free(img);
free(n);
return NULL;
}
attribs[0] = EGL_WAYLAND_PLANE_WL;
attribs[1] = 0; //if plane is 1 then 0, if plane is 2 then 1
attribs[2] = EGL_NONE;
memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
if (glsym_eglQueryWaylandBufferWL(ob->egl_disp, wl_buf,
EGL_WAYLAND_Y_INVERTED_WL,
&yinvert) == EGL_FALSE)
yinvert = 1;
eina_hash_add(ob->gl_context->shared->native_wl_hash,
&wlid, img);
n->wl_buf = wl_buf;
if (glsym_eglCreateImage)
n->egl_surface = glsym_eglCreateImage(ob->egl_disp,
NULL,
EGL_WAYLAND_BUFFER_WL,
wl_buf, attribs);
else
{
ERR("Try eglCreateImage on EGL with no support");
eina_hash_del(ob->gl_context->shared->native_wl_hash,
&wlid, img);
glsym_evas_gl_common_image_free(img);
free(n);
return NULL;
}
if (!n->egl_surface)
{
ERR("eglCreatePixmapSurface() for %p failed", wl_buf);
eina_hash_del(ob->gl_context->shared->native_wl_hash,
&wlid, img);
glsym_evas_gl_common_image_free(img);
free(n);
return NULL;
}
//XXX: workaround for mesa-10.2.8
// mesa's eglQueryWaylandBufferWL() with EGL_WAYLAND_Y_INVERTED_WL works incorrect.
//img->native.yinvert = yinvert;
img->native.yinvert = 1;
img->native.loose = 0;
img->native.data = n;
img->native.func.data = re;
img->native.func.bind = _native_cb_bind;
img->native.func.unbind = _native_cb_unbind;
img->native.func.free = _native_cb_free;
img->native.target = GL_TEXTURE_2D;
img->native.mipmap = 0;
glsym_evas_gl_common_image_native_enable(img);
}
}
}
else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
{
if (native)
{