jpeg pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=29e7f54ea0458e4634fd0d9d3f1290063a1bdbf3
commit 29e7f54ea0458e4634fd0d9d3f1290063a1bdbf3 Author: Jean-Philippe Andre <[email protected]> Date: Fri Sep 19 15:17:08 2014 +0900 Evas GL: Add evas_gl_surface_query When using EGL, this function should return the properties of a surface. Limited to a subset of known attributes. Right now, this function will only work fine with EGL. GLX support or any other engine is not implemented. @feature --- src/lib/evas/Evas_GL.h | 31 ++++++ src/lib/evas/canvas/evas_gl.c | 26 +++++ src/lib/evas/include/evas_private.h | 1 + src/modules/evas/engines/gl_generic/evas_engine.c | 106 ++++++++++++++++++++- .../evas/engines/software_generic/evas_engine.c | 1 + 5 files changed, 164 insertions(+), 1 deletion(-) diff --git a/src/lib/evas/Evas_GL.h b/src/lib/evas/Evas_GL.h index c5e607a..f6b595a 100644 --- a/src/lib/evas/Evas_GL.h +++ b/src/lib/evas/Evas_GL.h @@ -605,6 +605,26 @@ EAPI Evas_GL_API *evas_gl_api_get (Evas_GL *evas_gl) EINA EAPI int evas_gl_rotation_get (Evas_GL *evas_gl) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; /** + * @brief Query a surface for its properties + * + * @param[in] evas_gl The current Evas_GL object + * @param[in] surface An Evas_GL_Surface surface to query + * @param[in] attribute Specifies the attribute to query. + * @param[out] value Returns the requested value (usually an int) + * + * The currently accepted attributes are the following: + * @li @ref EVAS_GL_WIDTH, + * @li @ref EVAS_GL_HEIGHT, + * @li @ref EVAS_GL_TEXTURE_FORMAT, + * @li @ref EVAS_GL_TEXTURE_TARGET + * + * @return EINA_TRUE in case of success, EINA_FALSE in case of error. + * + * @since_tizen 2.3 + */ +EAPI Eina_Bool evas_gl_surface_query (Evas_GL *evas_gl, Evas_GL_Surface *surface, int attribute, void *value) EINA_ARG_NONNULL(1,2); + +/** * @brief Returns the last error of any evas_gl function called in the current thread. * Initially, the error is set to @ref EVAS_GL_SUCCESS. A call to @ref evas_gl_error_get * resets the error to @ref EVAS_GL_SUCCESS. @@ -1522,6 +1542,17 @@ typedef unsigned long long EvasGLTime; #define EVAS_GL_NO_SYNC ((EvasGLSync) NULL) /**< @brief Empty sync object, see @ref evasglCreateSync */ /** @} */ +/** + * @name Surface attributes + * The attributes can be queried using @ref evas_gl_surface_query + * @{ + */ +#define EVAS_GL_HEIGHT 0x3056 /**< Attribute for @ref evas_gl_surface_query, returns the surface width in pixels (@c value should be an @c int) */ +#define EVAS_GL_WIDTH 0x3057 /**< Attribute for @ref evas_gl_surface_query, returns the surface width in pixels (@c value should be an @c int) */ +#define EVAS_GL_TEXTURE_FORMAT 0x3080 /**< Attribute for @ref evas_gl_surface_query, returns an @ref Evas_GL_Color_Format */ +#define EVAS_GL_TEXTURE_TARGET 0x3081 /**< Attribute for @ref evas_gl_surface_query, returns @ref EVAS_GL_TEXTURE_2D (if format is @c EVAS_GL_RGB_888 or @c EVAS_GL_RGBA_8888) or 0 (meaning @c NO_TEXTURE, from @c EVAS_GL_NO_FBO) (@c value should be an @c int) */ +/** @} */ + #define EVAS_GL_API_VERSION 1 /** diff --git a/src/lib/evas/canvas/evas_gl.c b/src/lib/evas/canvas/evas_gl.c index 5e8fac2..3b7286c 100644 --- a/src/lib/evas/canvas/evas_gl.c +++ b/src/lib/evas/canvas/evas_gl.c @@ -531,3 +531,29 @@ end: _evas_gl_internal_error_set(evas_gl, EVAS_GL_SUCCESS); return err; } + +EAPI Eina_Bool +evas_gl_surface_query(Evas_GL *evas_gl, Evas_GL_Surface *surface, int attribute, void *value) +{ + if (!evas_gl) return EINA_FALSE; + if (!surface) + { + _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_SURFACE); + return EINA_FALSE; + } + + if (!evas_gl->evas->engine.func->gl_surface_query) + { + _evas_gl_internal_error_set(evas_gl, EVAS_GL_NOT_INITIALIZED); + return EINA_FALSE; + } + + if (!value) + { + _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_PARAMETER); + return EINA_FALSE; + } + + return evas_gl->evas->engine.func->gl_surface_query + (evas_gl->evas->engine.data.output, surface->data, attribute, value); +} diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h index c1ebb46..1243033 100644 --- a/src/lib/evas/include/evas_private.h +++ b/src/lib/evas/include/evas_private.h @@ -1248,6 +1248,7 @@ struct _Evas_Func void *(*gl_current_context_get) (void *data); void *(*gl_current_surface_get) (void *data); int (*gl_rotation_angle_get) (void *data); + Eina_Bool (*gl_surface_query) (void *data, void *surface, int attr, void *value); int (*image_load_error_get) (void *data, void *image); int (*font_run_end_get) (void *data, Evas_Font_Set *font, Evas_Font_Instance **script_fi, Evas_Font_Instance **cur_fi, Evas_Script_Type script, const Eina_Unicode *text, int run_len); diff --git a/src/modules/evas/engines/gl_generic/evas_engine.c b/src/modules/evas/engines/gl_generic/evas_engine.c index f678870..b717984 100644 --- a/src/modules/evas/engines/gl_generic/evas_engine.c +++ b/src/modules/evas/engines/gl_generic/evas_engine.c @@ -1327,6 +1327,110 @@ eng_gl_surface_read_pixels(void *data, void *surface, return EINA_TRUE; } + +static Eina_Bool +eng_gl_surface_query(void *data, void *surface, int attr, void *value) +{ + Render_Engine_GL_Generic *re = data; + EVGL_Surface *sfc = surface; + +#ifdef GL_GLES + if (sfc->pbuffer.is_pbuffer) + { + // This is a real EGL surface, let's just call EGL directly + int val; + Eina_Bool ok; + + ok = eglQuerySurface(re->win->egl_disp, sfc->pbuffer.native_surface, attr, &val); + if (!ok) return EINA_FALSE; + switch (attr) + { + case EVAS_GL_TEXTURE_FORMAT: + if (val == EGL_TEXTURE_RGB) + *((int *) value) = EVAS_GL_RGB_888; + else if (val == EGL_TEXTURE_RGBA) + *((int *) value) = EVAS_GL_RGBA_8888; + else // if (val == EGL_NO_TEXTURE) + *((int *) value) = EVAS_GL_NO_FBO; + break; + case EVAS_GL_TEXTURE_TARGET: + if (val == EGL_TEXTURE_2D) + *((int *) value) = val; + else + *((int *) value) = 0; + break; + default: + *((int *) value) = val; + break; + } + return EINA_TRUE; + } + else + { + // Since this is a fake surface (shared with evas), we must filter the + // queries... + switch (attr) + { + // TODO: Add support for whole config get + /* + case EVAS_GL_CONFIG_ID: + *((int *) value) = sfc->cfg_index; + return EINA_TRUE; + */ + case EVAS_GL_WIDTH: + *((int *) value) = sfc->w; + return EINA_TRUE; + case EVAS_GL_HEIGHT: + *((int *) value) = sfc->h; + return EINA_TRUE; + case EVAS_GL_TEXTURE_FORMAT: + // FIXME: Check the possible color formats + if (sfc->color_buf) + { + if ((sfc->color_fmt == GL_RGBA) || (sfc->color_fmt == GL_BGRA)) + { + *((Evas_GL_Color_Format *) value) = EVAS_GL_RGBA_8888; + return EINA_TRUE; + } + else if (sfc->color_fmt == GL_RGB) + { + *((Evas_GL_Color_Format *) value) = EVAS_GL_RGB_888; + return EINA_TRUE; + } + } + *((Evas_GL_Color_Format *) value) = EVAS_GL_NO_FBO; + return EINA_TRUE; + case EVAS_GL_TEXTURE_TARGET: + if (sfc->color_buf) + *((int *) value) = EVAS_GL_TEXTURE_2D; + else + *((int *) value) = 0; + return EINA_TRUE; + // TODO: Add support for this: + /* + case EVAS_GL_MULTISAMPLE_RESOLVE: + *((int *) value) = sfc->msaa_samples; + return EINA_TRUE; + */ + // TODO: Add support for mipmaps + /* + case EVAS_GL_MIPMAP_TEXTURE: + case EVAS_GL_MIPMAP_LEVEL: + return eglQuerySurface(re->win->egl_disp, re->win->egl_surface[0], + attr, (int *) value); + */ + default: break; + } + _evgl_error_set(EVAS_GL_BAD_ATTRIBUTE); + return EINA_FALSE; + } +#else + (void) re; (void) sfc; (void) attr; (void) value; + ERR("GLX support for surface_query is not implemented!"); + return EINA_FALSE; +#endif +} + //--------------------------------// static int @@ -1807,7 +1911,7 @@ module_open(Evas_Module *em) ORD(gl_surface_read_pixels); ORD(gl_surface_unlock); //ORD(gl_error_get); - //ORD(gl_surface_query); + ORD(gl_surface_query); // gl_current_context_get is in engine ORD(gl_current_surface_get); ORD(gl_rotation_angle_get); diff --git a/src/modules/evas/engines/software_generic/evas_engine.c b/src/modules/evas/engines/software_generic/evas_engine.c index dca7868..8ee3d90 100644 --- a/src/modules/evas/engines/software_generic/evas_engine.c +++ b/src/modules/evas/engines/software_generic/evas_engine.c @@ -3079,6 +3079,7 @@ static Evas_Func func = NULL, // need software mesa for gl rendering <- gl_current_context_get NULL, // need software mesa for gl rendering <- gl_current_surface_get NULL, // need software mesa for gl rendering <- gl_rotation_angle_get + NULL, // need software mesa for gl rendering <- gl_surface_query eng_image_load_error_get, eng_font_run_font_end_get, eng_image_animated_get, --
