From 2c022aa30dd2dc44db57d13393f95444bdb8606f Mon Sep 17 00:00:00 2001 From: sung Date: Thu, 12 Jan 2012 13:54:06 +0000 Subject: [PATCH] Added new Evas GL api called evas_gl_config_new/free() to ensure backward compatibility. Previously, the user simply declared a Evas_GL_Config object but this can cause problems if more config options are added. So, we have Evas allocate the config object for the user so it can handle addition in the future. Also, added some safety code around _extensions_init git-svn-id: http://svn.enlightenment.org/svn/e/trunk/evas@67141 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- ChangeLog | 13 +++++++- src/lib/Evas_GL.h | 52 ++++++++++++++++++++++++-------- src/lib/canvas/evas_gl.c | 33 ++++++++++++++++---- src/modules/engines/gl_x11/evas_engine.c | 31 +++++++++++-------- 4 files changed, 96 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14680bb..f95e796 100644 --- a/ChangeLog +++ b/ChangeLog @@ -622,4 +622,15 @@ * Add EvasGL support to software backend using OSMesa. Requires OSMesa library. Due to caveats in OSMesa, surface config stays with a - context + context rather than with a surface. So for now, the config of a + surface remains with the first context that it binds to. May need + to come up with a different solution in the near future. + +2012-01-12 Sung W. Park (sung_) + + * Add new api evas_gl_config_new/free() to ensure backward compatibility. + Previously, the user simply declared a Evas_GL_Config object but this + can cause issues if new configs are added. Now we have evas allocate it + for you. + + diff --git a/src/lib/Evas_GL.h b/src/lib/Evas_GL.h index 04bedea..fdfbaad 100644 --- a/src/lib/Evas_GL.h +++ b/src/lib/Evas_GL.h @@ -28,7 +28,7 @@ typedef enum _Evas_GL_Depth_Bits EVAS_GL_DEPTH_BIT_8 = 1, EVAS_GL_DEPTH_BIT_16 = 2, EVAS_GL_DEPTH_BIT_24 = 3, - EVAS_GL_DEPTH_BIT_32 = 4, + EVAS_GL_DEPTH_BIT_32 = 4 } Evas_GL_Depth_Bits; typedef enum _Evas_GL_Stencil_Bits @@ -38,14 +38,21 @@ typedef enum _Evas_GL_Stencil_Bits EVAS_GL_STENCIL_BIT_2 = 2, EVAS_GL_STENCIL_BIT_4 = 3, EVAS_GL_STENCIL_BIT_8 = 4, - EVAS_GL_STENCIL_BIT_16 = 5, + EVAS_GL_STENCIL_BIT_16 = 5 } Evas_GL_Stencil_Bits; +typedef enum _Evas_GL_Options_Bits +{ + EVAS_GL_OPTIONS_NONE = 0, + EVAS_GL_OPTIONS_DIRECT = (1<<0) +} Evas_GL_Options_Bits; + struct _Evas_GL_Config { - Evas_GL_Color_Format color_format; - Evas_GL_Depth_Bits depth_bits; - Evas_GL_Stencil_Bits stencil_bits; + Evas_GL_Color_Format color_format; + Evas_GL_Depth_Bits depth_bits; + Evas_GL_Stencil_Bits stencil_bits; + Evas_GL_Options_Bits options_bits; }; #define EVAS_GL_EXTENSIONS 1 @@ -73,6 +80,7 @@ typedef struct _GLData { Evas_GL_Context *ctx; Evas_GL_Surface *sfc; + Evas_GL_Config *cfg; Evas_GL *evasgl; Evas_GL_API *glapi; GLuint program; @@ -93,13 +101,6 @@ static GLuint load_shader (GLData *gld, GLenum type, const char *shader_src) int main(int argc, char **argv) { - // config for the surface for evas_gl - Evas_GL_Config config = - { - EVAS_GL_RGBA_8888, - EVAS_GL_DEPTH_NONE, - EVAS_GL_STENCIL_NONE - }; // a size by default int w = 256, h = 256; // some variables we will use @@ -124,8 +125,16 @@ main(int argc, char **argv) // get the evas gl handle for doing gl things gld->evasgl = evas_gl_new(canvas); gld->glapi = evas_gl_api_get(gld->evasgl); + + // Set a surface config + gld->cfg = evas_gl_config_new(); + gld->cfg->color_format = EVAS_GL_RGBA_8888; + //gld->cfg->depth_bits = EVAS_GL_DEPTH_NONE; // Othe config options + //gld->cfg->stencil_bits = EVAS_GL_STENCIL_NONE; + //gld->cfg->options_bits = EVAS_GL_OPTIONS_NONE; + // create a surface and context - gld->sfc = evas_gl_surface_create(gld->evasgl, &config, w, h); + gld->sfc = evas_gl_surface_create(gld->evasgl, gld->cfg, w, h); gld->ctx = evas_gl_context_create(gld->evasgl, NULL); //-// //-//-//-// END GL INIT BLOB @@ -207,6 +216,7 @@ on_del(void *data, Evas *e, Evas_Object *obj, void *event_info) evas_gl_surface_destroy(gld->evasgl, gld->sfc); evas_gl_context_destroy(gld->evasgl, gld->ctx); + evas_gl_config_free(gld->cfg); evas_gl_free(gld->evasgl); free(gld); } @@ -389,6 +399,22 @@ EAPI Evas_GL *evas_gl_new (Evas *e) EINA_WARN_UNU EAPI void evas_gl_free (Evas_GL *evas_gl) EINA_ARG_NONNULL(1); /** + * Allocates a new config object for the user to fill out. + * + * As long as the Evas creates a config object for the user, it takes care + * of the backward compatibility issue. + */ +EAPI Evas_GL_Config *evas_gl_config_new (); + +/** + * Frees a config object created from evas_gl_config_new. + * + * As long as the Evas creates a config object for the user, it takes care + * of the backward compatibility issue. + */ +EAPI void evas_gl_config_free (Evas_GL_Config *cfg) EINA_ARG_NONNULL(1); + +/** * Creates and returns new Evas_GL_Surface object for GL Rendering. * * @param evas_gl The given Evas_GL object. diff --git a/src/lib/canvas/evas_gl.c b/src/lib/canvas/evas_gl.c index 08edbc4..85ed851 100644 --- a/src/lib/canvas/evas_gl.c +++ b/src/lib/canvas/evas_gl.c @@ -37,6 +37,13 @@ evas_gl_new(Evas *e) evas_gl->magic = MAGIC_EVAS_GL; evas_gl->evas = e; + if (!evas_gl->evas->engine.func->gl_context_create) + { + ERR("GL engine not available\n"); + free(evas_gl); + return NULL; + } + return evas_gl; } @@ -60,6 +67,24 @@ evas_gl_free(Evas_GL *evas_gl) free(evas_gl); } +EAPI Evas_GL_Config * +evas_gl_config_new() +{ + Evas_GL_Config *cfg; + + cfg = calloc(1, sizeof(Evas_GL_Config)); + + if (!cfg) return NULL; + + return cfg; +} + +EAPI void +evas_gl_config_free(Evas_GL_Config *cfg) +{ + if (cfg) free(cfg); +} + EAPI Evas_GL_Surface * evas_gl_surface_create(Evas_GL *evas_gl, Evas_GL_Config *config, int width, int height) { @@ -77,6 +102,8 @@ evas_gl_surface_create(Evas_GL *evas_gl, Evas_GL_Config *config, int width, int surf = calloc(1, sizeof(Evas_GL_Surface)); + if (!surf) return NULL; + surf->data = evas_gl->evas->engine.func->gl_surface_create(evas_gl->evas->engine.data.output, config, width, height); if (!surf->data) @@ -135,12 +162,6 @@ evas_gl_context_create(Evas_GL *evas_gl, Evas_GL_Context *share_ctx) return NULL; } - if (!evas_gl->evas->engine.func->gl_context_create) - { - ERR("GL engine not available\n"); - return NULL; - } - // Call engine->gl_create_context if (share_ctx) { diff --git a/src/modules/engines/gl_x11/evas_engine.c b/src/modules/engines/gl_x11/evas_engine.c index 9ad6eb5..fbbd1a2 100644 --- a/src/modules/engines/gl_x11/evas_engine.c +++ b/src/modules/engines/gl_x11/evas_engine.c @@ -584,25 +584,30 @@ _extensions_init(Render_Engine *re) #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) // EGL Extensions - evasglexts = glsym_eglQueryString(re->win->egl_disp, EGL_EXTENSIONS); + if (glsym_eglQueryString) + { + evasglexts = glsym_eglQueryString(re->win->egl_disp, EGL_EXTENSIONS); #else - evasglexts = glXQueryExtensionsString(re->info->info.display, - re->info->info.screen); + if (glsym_glXQueryExtensionsString) + { + evasglexts = glXQueryExtensionsString(re->info->info.display, + re->info->info.screen); #endif - DBG("--------EvasGL Extensions----------"); - for (i = 0; _evasgl_ext_entries[i].name != NULL; i++) - { - if ( (strstr(evasglexts, _evasgl_ext_entries[i].name) != NULL) || - (strstr(evasglexts, _evasgl_ext_entries[i].real_name) != NULL) ) + DBG("--------EvasGL Extensions----------"); + for (i = 0; _evasgl_ext_entries[i].name != NULL; i++) { - _evasgl_ext_entries[i].supported = 1; - strcat(_evasgl_ext_string, _evasgl_ext_entries[i].name); - strcat(_evasgl_ext_string, " "); - DBG("\t%s", _evasgl_ext_entries[i].name); + if ( (strstr(evasglexts, _evasgl_ext_entries[i].name) != NULL) || + (strstr(evasglexts, _evasgl_ext_entries[i].real_name) != NULL) ) + { + _evasgl_ext_entries[i].supported = 1; + strcat(_evasgl_ext_string, _evasgl_ext_entries[i].name); + strcat(_evasgl_ext_string, " "); + DBG("\t%s", _evasgl_ext_entries[i].name); + } } + DBG(" "); } - DBG(" "); } int _evas_engine_GL_X11_log_dom = -1; -- 2.7.4