Evas engines: Add internal functions for native images

- image_native_init
- image_native_shutdown

init() will be used to test whether the engine supports a
certain type of native image.

Note: Native image support is very much dependent on the engine,
and some stuff like opengl should work everywhere (even in sw
with osmesa) but that's not the case.
This commit is contained in:
Jean-Philippe Andre 2016-03-09 16:18:34 +09:00
parent a58a3532e3
commit 20b4d9dd6a
10 changed files with 251 additions and 11 deletions

View File

@ -1348,6 +1348,9 @@ struct _Evas_Func
Evas_Colorspace (*image_colorspace_get) (void *data, void *image);
Evas_Colorspace (*image_file_colorspace_get)(void *data, void *image);
Eina_Bool (*image_can_region_get) (void *data, void *image);
int (*image_native_init) (void *data, Evas_Native_Surface_Type type);
void (*image_native_shutdown) (void *data, Evas_Native_Surface_Type type);
void *(*image_native_set) (void *data, void *image, void *native);
void *(*image_native_get) (void *data, void *image);

View File

@ -1012,6 +1012,34 @@ eng_output_dump(void *data)
_re_winfree(re);
}
static int
eng_image_native_init(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
case EVAS_NATIVE_SURFACE_OPENGL:
case EVAS_NATIVE_SURFACE_WL:
return 1;
default:
ERR("Native surface type %d not supported!", type);
return 0;
}
}
static void
eng_image_native_shutdown(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
case EVAS_NATIVE_SURFACE_OPENGL:
case EVAS_NATIVE_SURFACE_WL:
return;
default:
ERR("Native surface type %d not supported!", type);
return;
}
}
static void *
eng_image_native_set(void *data, void *image, void *native)
{
@ -1270,6 +1298,8 @@ module_open(Evas_Module *em)
EVAS_API_OVERRIDE(output_free, &func, eng_);
EVAS_API_OVERRIDE(output_dump, &func, eng_);
EVAS_API_OVERRIDE(image_native_set, &func, eng_);
EVAS_API_OVERRIDE(image_native_init, &func, eng_);
EVAS_API_OVERRIDE(image_native_shutdown, &func, eng_);
/* Mesa's EGL driver loads wayland egl by default. (called by eglGetProcaddr() )
* implicit env set (EGL_PLATFORM=drm) prevent that. */

View File

@ -373,6 +373,32 @@ _native_free_cb(void *data, void *image)
free(n);
}
static int
eng_image_native_init(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
case EVAS_NATIVE_SURFACE_OPENGL:
return 1;
default:
ERR("Native surface type %d not supported!", type);
return 0;
}
}
static void
eng_image_native_shutdown(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
case EVAS_NATIVE_SURFACE_OPENGL:
return;
default:
ERR("Native surface type %d not supported!", type);
return;
}
}
static void *
eng_image_native_set(void *data, void *image, void *native)
{
@ -2816,6 +2842,8 @@ module_open(Evas_Module *em)
ORD(image_colorspace_get);
ORD(image_file_colorspace_get);
ORD(image_can_region_get);
ORD(image_native_init);
ORD(image_native_shutdown);
ORD(image_native_set);
ORD(image_native_get);

View File

@ -2309,6 +2309,52 @@ _native_yinvert_cb(void *data, void *image)
return yinvert;
}
static int
eng_image_native_init(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
#ifdef GL_GLES
case EVAS_NATIVE_SURFACE_TBM:
return _evas_native_tbm_init();
#endif
case EVAS_NATIVE_SURFACE_X11:
case EVAS_NATIVE_SURFACE_OPENGL:
case EVAS_NATIVE_SURFACE_EVASGL:
return 1;
#if defined(GL_GLES) && defined(HAVE_WAYLAND)
case EVAS_NATIVE_SURFACE_WL:
return (glsym_eglQueryWaylandBufferWL != NULL) ? 1 : 0;
#endif
default:
ERR("Native surface type %d not supported!", type);
return 0;
}
}
static void
eng_image_native_shutdown(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
#ifdef GL_GLES
case EVAS_NATIVE_SURFACE_TBM:
_evas_native_tbm_shutdown();
return;
#endif
case EVAS_NATIVE_SURFACE_X11:
case EVAS_NATIVE_SURFACE_OPENGL:
case EVAS_NATIVE_SURFACE_EVASGL:
#if defined(GL_GLES) && defined(HAVE_WAYLAND)
case EVAS_NATIVE_SURFACE_WL:
#endif
return;
default:
ERR("Native surface type %d not supported!", type);
return;
}
}
static void *
eng_image_native_set(void *data, void *image, void *native)
{
@ -3015,6 +3061,8 @@ module_open(Evas_Module *em)
ORD(output_free);
ORD(output_dump);
ORD(image_native_init);
ORD(image_native_shutdown);
ORD(image_native_set);
ORD(gl_error_get);

View File

@ -26,6 +26,7 @@
#endif
#include "Evas_Engine_Software_Generic.h"
#include "evas_native_common.h"
#ifdef EVAS_GL
//----------------------------------//
@ -1113,6 +1114,25 @@ eng_image_colorspace_set(void *data EINA_UNUSED, void *image, Evas_Colorspace cs
evas_cache_image_colorspace(im, cspace);
}
static int
eng_image_native_init(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
if (type == EVAS_NATIVE_SURFACE_TBM)
return _evas_native_tbm_init();
ERR("Native surface type %d not supported!", type);
return 0;
}
static void
eng_image_native_shutdown(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
if (type == EVAS_NATIVE_SURFACE_TBM)
_evas_native_tbm_shutdown();
else
ERR("Native surface type %d not supported!", type);
}
static void *
eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
{
@ -4124,6 +4144,8 @@ static Evas_Func func =
eng_image_colorspace_get,
eng_image_file_colorspace_get,
eng_image_can_region_get,
eng_image_native_init,
eng_image_native_shutdown,
eng_image_native_set,
eng_image_native_get,
/* image cache funcs */

View File

@ -75,7 +75,9 @@ struct _Native
} ns_data; /**< Choose one union data according to your surface in Evas Engine. */
};
EAPI void * evas_native_tbm_surface_image_set(void *data, void *image, void *native);
EAPI void *_evas_native_tbm_surface_image_set(void *data, void *image, void *native);
EAPI int _evas_native_tbm_init(void);
EAPI void _evas_native_tbm_shutdown(void);
typedef void *(*Evas_Native_Tbm_Surface_Image_Set_Call)(void *data, void *image, void *native);

View File

@ -67,13 +67,13 @@ typedef struct _tbm_surface_info
static int (*sym_tbm_surface_map) (tbm_surface_h surface, int opt, tbm_surface_info_s *info) = NULL;
static int (*sym_tbm_surface_unmap) (tbm_surface_h surface) = NULL;
static Eina_Bool
tbm_init(void)
EAPI int
_evas_native_tbm_init(void)
{
if (tbm_lib)
{
tbm_ref++;
return EINA_TRUE;
return tbm_ref;
}
const char *tbm_libs[] =
@ -108,14 +108,14 @@ tbm_init(void)
else break;
}
}
if (!tbm_lib) return EINA_FALSE;
if (!tbm_lib) return 0;
tbm_ref++;
return EINA_TRUE;
return tbm_ref;
}
static void
tbm_shutdown(void)
EAPI void
_evas_native_tbm_shutdown(void)
{
if (tbm_ref > 0)
{
@ -254,11 +254,11 @@ _native_free_cb(void *data EINA_UNUSED, void *image)
free(n);
tbm_shutdown();
_evas_native_tbm_shutdown();
}
EAPI void *
evas_native_tbm_surface_image_set(void *data EINA_UNUSED, void *image, void *native)
_evas_native_tbm_surface_image_set(void *data EINA_UNUSED, void *image, void *native)
{
Evas_Native_Surface *ns = native;
RGBA_Image *im = image;
@ -279,7 +279,7 @@ evas_native_tbm_surface_image_set(void *data EINA_UNUSED, void *image, void *nat
tbm_surf = ns->data.tbm.buffer;
if (!tbm_init())
if (!_evas_native_tbm_init())
{
ERR("Could not initialize TBM!");
return NULL;

View File

@ -671,6 +671,43 @@ _native_evasgl_free(void *data EINA_UNUSED, void *image)
free(n);
}
static int
eng_image_native_init(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
#ifdef GL_GLES
case EVAS_NATIVE_SURFACE_TBM:
return _evas_native_tbm_init();
#endif
case EVAS_NATIVE_SURFACE_X11:
case EVAS_NATIVE_SURFACE_EVASGL:
return 1;
default:
ERR("Native surface type %d not supported!", type);
return 0;
}
}
static void
eng_image_native_shutdown(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
#ifdef GL_GLES
case EVAS_NATIVE_SURFACE_TBM:
_evas_native_tbm_shutdown();
return;
#endif
case EVAS_NATIVE_SURFACE_X11:
case EVAS_NATIVE_SURFACE_OPENGL:
return;
default:
ERR("Native surface type %d not supported!", type);
return;
}
}
static void *
eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
{
@ -817,6 +854,8 @@ module_open(Evas_Module *em)
ORD(setup);
ORD(canvas_alpha_get);
ORD(output_free);
ORD(image_native_init);
ORD(image_native_shutdown);
ORD(image_native_set);
ORD(image_native_get);

View File

@ -992,6 +992,45 @@ _native_cb_yinvert(void *data EINA_UNUSED, void *image)
return yinvert;
}
static int
eng_image_native_init(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
#ifdef GL_GLES
case EVAS_NATIVE_SURFACE_TBM:
return _evas_native_tbm_init();
#endif
case EVAS_NATIVE_SURFACE_EVASGL:
case EVAS_NATIVE_SURFACE_OPENGL:
case EVAS_NATIVE_SURFACE_WL:
return 1;
default:
ERR("Native surface type %d not supported!", type);
return 0;
}
}
static void
eng_image_native_shutdown(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
#ifdef GL_GLES
case EVAS_NATIVE_SURFACE_TBM:
_evas_native_tbm_shutdown();
return;
#endif
case EVAS_NATIVE_SURFACE_EVASGL:
case EVAS_NATIVE_SURFACE_OPENGL:
case EVAS_NATIVE_SURFACE_WL:
return;
default:
ERR("Native surface type %d not supported!", type);
return;
}
}
static void *
eng_image_native_set(void *data, void *image, void *native)
{

View File

@ -265,6 +265,33 @@ eng_output_resize(void *data, int w, int h)
re->generic.h = h;
}
static int
eng_image_native_init(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
case EVAS_NATIVE_SURFACE_TBM:
return _evas_native_tbm_init();
default:
ERR("Native surface type %d not supported!", type);
return 0;
}
}
static void
eng_image_native_shutdown(void *data EINA_UNUSED, Evas_Native_Surface_Type type)
{
switch (type)
{
case EVAS_NATIVE_SURFACE_TBM:
_evas_native_tbm_shutdown();
return;
default:
ERR("Native surface type %d not supported!", type);
return;
}
}
static void *
eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
{
@ -287,6 +314,8 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
}
}
/* FIXME: WTF is this? OPENGL supported here? uh? and x11.visual used???
* It looks like this code needs to fail and return NULL. */
if ((ns->type == EVAS_NATIVE_SURFACE_OPENGL) &&
(ns->version == EVAS_NATIVE_SURFACE_VERSION))
im2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),