evas_gl: Add feature to set depth/stencil/msaa bit to window surface. 40/47440/4
authorJoogab Yun <joogab.yun@samsung.com>
Wed, 17 Jun 2015 05:34:30 +0000 (14:34 +0900)
committerDaeKwang Ryu <dkdk.ryu@samsung.com>
Wed, 16 Sep 2015 12:05:16 +0000 (21:05 +0900)
    Summary:
    When Evas GL runs with direct rendering, it can not set depth, stencil and msaa to Window surface.
    This patch is possible to use "option" input paramater of ecore_evas_gl_x11_options_new.
    So, new API is not needed.

    The other patch is in elementary. The elementary patch will be used this patch.

    Test Plan: Test elm gl veiw in elementary_test and JP's test app.

    Differential Revision: https://phab.enlightenment.org/D2144

Change-Id: If854ffae327fdd81e52fde44c79aea2e7c98b39e

src/lib/ecore_evas/Ecore_Evas.h
src/modules/ecore_evas/engines/x/ecore_evas_x.c
src/modules/evas/engines/gl_common/evas_gl_core.c
src/modules/evas/engines/gl_common/evas_gl_core_private.h
src/modules/evas/engines/gl_drm/evas_engine.c
src/modules/evas/engines/gl_sdl/evas_engine.c
src/modules/evas/engines/gl_x11/Evas_Engine_GL_X11.h
src/modules/evas/engines/gl_x11/evas_engine.c
src/modules/evas/engines/gl_x11/evas_engine.h
src/modules/evas/engines/gl_x11/evas_x_main.c
src/modules/evas/engines/wayland_egl/evas_engine.c

index 8930dc9d6b462224140bc2496cf20e2ff774f990..37b037b3b6e81fbb6fc4e8125aaf3d73eac4f58b 100644 (file)
@@ -1136,7 +1136,10 @@ EAPI Ecore_X_Pixmap ecore_evas_software_x11_pixmap_get(const Ecore_Evas *ee);
 #define ECORE_EVAS_GL_X11_OPT_INDIRECT     1
 #define ECORE_EVAS_GL_X11_OPT_VSYNC        2
 #define ECORE_EVAS_GL_X11_OPT_SWAP_MODE    3
-#define ECORE_EVAS_GL_X11_OPT_LAST         4
+#define ECORE_EVAS_GL_X11_OPT_GL_DEPTH     4
+#define ECORE_EVAS_GL_X11_OPT_GL_STENCIL   5
+#define ECORE_EVAS_GL_X11_OPT_GL_MSAA      6
+#define ECORE_EVAS_GL_X11_OPT_LAST         7
 
 #define ECORE_EVAS_GL_X11_SWAP_MODE_AUTO   0
 #define ECORE_EVAS_GL_X11_SWAP_MODE_FULL   1
index 31d5108075129f5432ee758ff84c8d77f93f8597..2d9c8f9aca9e87de6421f2b372b8c858b5969d3f 100644 (file)
@@ -432,6 +432,21 @@ _ecore_evas_x_gl_window_new(Ecore_Evas *ee, Ecore_X_Window parent, int x, int y,
                        einfo->swap_mode = opt[op];
                     }
 #endif
+                  else if (opt[op] == ECORE_EVAS_GL_X11_OPT_GL_DEPTH)
+                    {
+                       op++;
+                       einfo->depth_bits = opt[op];
+                    }
+                  else if (opt[op] == ECORE_EVAS_GL_X11_OPT_GL_STENCIL)
+                    {
+                       op++;
+                       einfo->stencil_bits = opt[op];
+                    }
+                  else if (opt[op] == ECORE_EVAS_GL_X11_OPT_GL_MSAA)
+                    {
+                       op++;
+                       einfo->msaa_bits = opt[op];
+                    }
                }
           }
 
index 7c4d13ae19793e59940cc6024deb678b3249e93d..cbb9998658c1b894d46dd6b0daf7dcd23cde3315 100755 (executable)
@@ -348,7 +348,11 @@ _fbo_surface_cap_test(GLint color_ifmt, GLenum color_fmt,
    // Return the result
    if (fb_status != GL_FRAMEBUFFER_COMPLETE)
    {
-       // Put Error Log...
+        int err = glGetError();
+
+        if (err != GL_NO_ERROR)
+           DBG("glGetError() returns %x ", err);
+
       return 0;
    }
    else
@@ -1066,10 +1070,11 @@ _surface_buffers_destroy(EVGL_Surface *sfc)
 }
 
 static int
-_internal_config_set(EVGL_Surface *sfc, Evas_GL_Config *cfg)
+_internal_config_set(void *eng_data, EVGL_Surface *sfc, Evas_GL_Config *cfg)
 {
    int i = 0, cfg_index = -1;
    int color_bit = 0, depth_bit = 0, stencil_bit = 0, msaa_samples = 0;
+   int support_win_cfg = 1;
 
    // Check if engine is valid
    if (!evgl_engine)
@@ -1117,11 +1122,16 @@ _internal_config_set(EVGL_Surface *sfc, Evas_GL_Config *cfg)
              sfc->depth_stencil_fmt = evgl_engine->caps.fbo_fmts[i].depth_stencil_fmt;
              sfc->msaa_samples      = evgl_engine->caps.fbo_fmts[i].samples;
 
-             // TODO: Implement surface reconfigure and add depth+stencil support
-
              // Direct Rendering Option
-             if ((!depth_bit && !stencil_bit && !msaa_samples) || evgl_engine->direct_override)
-               sfc->direct_fb_opt = cfg->options_bits & EVAS_GL_OPTIONS_DIRECT;
+             if (((depth_bit > 0) || (stencil_bit > 0) || (msaa_samples > 0))
+                  && (evgl_engine->funcs->native_win_surface_config_check))
+               {
+                  DBG("request to check win cfg with depth %d,  stencil %d,  msaa %d", depth_bit, stencil_bit, msaa_samples);
+                  support_win_cfg = evgl_engine->funcs->native_win_surface_config_check(eng_data,depth_bit,stencil_bit,msaa_samples);
+               }
+
+             if ((sfc->direct_override) || (support_win_cfg == 1))
+               sfc->direct_fb_opt = !!(cfg->options_bits & EVAS_GL_OPTIONS_DIRECT);
 
              // Extra flags for direct rendering
              sfc->client_side_rotation = !!(cfg->options_bits & EVAS_GL_OPTIONS_CLIENT_SIDE_ROTATION);
@@ -1139,15 +1149,16 @@ _internal_config_set(EVGL_Surface *sfc, Evas_GL_Config *cfg)
      }
    else
      {
-        DBG("-------------Surface Config---------------");
+        DBG("-------------Evas GL Surface Config---------------");
         DBG("Selected Config Index: %d", cfg_index);
         DBG("  Color Format     : %s", _glenum_string_get(sfc->color_fmt));
         DBG("  Depth Format     : %s", _glenum_string_get(sfc->depth_fmt));
         DBG("  Stencil Format   : %s", _glenum_string_get(sfc->stencil_fmt));
         DBG("  D-Stencil Format : %s", _glenum_string_get(sfc->depth_stencil_fmt));
         DBG("  MSAA Samples     : %d", sfc->msaa_samples);
-        DBG("  Direct Option    : %d", sfc->direct_fb_opt);
+        DBG("  Direct Option    : %d%s", sfc->direct_fb_opt, sfc->direct_override ? " (override)" : "");
         DBG("  Client-side Rot. : %d", sfc->client_side_rotation);
+        DBG("--------------------------------------------------");
         sfc->cfg_index = cfg_index;
         return 1;
      }
@@ -1555,7 +1566,7 @@ evgl_surface_create(void *eng_data, Evas_GL_Config *cfg, int w, int h)
 {
    EVGL_Surface *sfc = NULL;
    char *s = NULL;
-   int direct_override = 0, direct_mem_opt = 0, evgl_msaa = 0;
+   int direct_override = 0, direct_mem_opt = 0;
    Eina_Bool need_reconfigure = EINA_FALSE;
    Eina_Bool dbg;
 
@@ -1625,7 +1636,7 @@ evgl_surface_create(void *eng_data, Evas_GL_Config *cfg, int w, int h)
        }
 
    // Set the internal config value
-   if (!_internal_config_set(sfc, cfg))
+   if (!_internal_config_set(eng_data, sfc, cfg))
      {
         ERR("Unsupported Format!");
         evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONFIG);
@@ -1671,8 +1682,7 @@ evgl_surface_create(void *eng_data, Evas_GL_Config *cfg, int w, int h)
           }
 
         INF("Creating special surface for GLES 1.x rendering");
-        evgl_msaa = evgl_engine->caps.msaa_samples[(int) cfg->multisample_bits - 1];
-        evgl_engine->funcs->gles1_surface_create(eng_data, sfc, cfg, w, h, evgl_msaa);
+        evgl_engine->funcs->gles1_surface_create(eng_data, sfc, cfg, w, h);
      }
 
    // Create internal buffers
@@ -1794,7 +1804,7 @@ evgl_pbuffer_surface_create(void *eng_data, Evas_GL_Config *cfg,
    if (sfc->pbuffer.color_fmt != EVAS_GL_NO_FBO)
      {
         // Set the internal config value
-        if (!_internal_config_set(sfc, cfg))
+        if (!_internal_config_set(eng_data, sfc, cfg))
           {
              ERR("Unsupported Format!");
              evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONFIG);
index 87373bf663df58a772b911c196d64af734f4a9a6..10578b25b43746cb735701b75f50b9ba5b5aad76 100755 (executable)
@@ -70,7 +70,7 @@ struct _EVGL_Interface
    int         (*pbuffer_surface_destroy)(void *data, void *surface);
 
    // Create a surface for 1.x rendering (could be pbuffer or xpixmap for instance)
-   void       *(*gles1_surface_create)(void *data, EVGL_Surface *evgl_sfc, Evas_GL_Config *cfg, int w, int h, int evgl_msaa);
+   void       *(*gles1_surface_create)(void *data, EVGL_Surface *evgl_sfc, Evas_GL_Config *cfg, int w, int h);
 
    // Destroy 1.x surface (could be pbuffer or xpixmap for instance)
    int        (*gles1_surface_destroy)(void *data, EVGL_Surface *evgl_sfc);
@@ -78,6 +78,9 @@ struct _EVGL_Interface
    // Create an indirect rendering context for GLES 1.x
    void      *(*gles1_context_create)(void *data, EVGL_Context *share_ctx, EVGL_Surface *evgl_sfc);
 
+   // Check native window surface config for Evas GL Direct Rendering
+   int        (*native_win_surface_config_check)(void *data, int evgl_depth, int evgl_stencil, int evgl_msaa);
+
 };
 
 struct _EVGL_Surface
index b5283eeb20e29a032fcd5cde6d499f03245de2cf..d7d07cafa62ec3bf52a1f08f44d7afcb1bf1e502 100644 (file)
@@ -124,6 +124,7 @@ static const EVGL_Interface evgl_funcs =
    NULL, // PBuffer
    NULL, // OpenGL-ES 1
    NULL, // OpenGL-ES 1
+   NULL, //native_win_surface_config_check
 };
 
 /* local functions */
index 1fa4e49ad39636735626820ecebe81d08e775823..61ab67b9a9151322aedbefe89265e2632776038c 100644 (file)
@@ -259,6 +259,7 @@ static const EVGL_Interface evgl_funcs =
    NULL, // PBuffer
    NULL, // OpenGL-ES 1
    NULL, // OpenGL-ES 1
+   NULL, //native_win_surface_config_check
 };
 
 
index e66539e021429b0a0ceda7b46e02991d1d4a3349..db37cd022b926f307feffbfe655c5600c90b5c56 100644 (file)
@@ -54,5 +54,10 @@ struct _Evas_Engine_Info_GL_X11
    unsigned char vsync : 1; // does nothing right now
    unsigned char indirect : 1; // use indirect rendering
    unsigned char swap_mode : 4; // what swap mode to assume
+
+   /*window surface should be made with these config*/
+    int          depth_bits;
+    int          stencil_bits;
+    int          msaa_bits;
 };
 #endif
index 14b9b40e445d779c3d657e155b2c0e08639d5f85..823cbb416403ba4cb8a772961ea3427c827b99b2 100755 (executable)
@@ -868,7 +868,7 @@ evgl_eng_pbuffer_surface_destroy(void *data, void *surface)
 // FIXME: Avoid passing evgl_engine around like that.
 static void *
 evgl_eng_gles1_surface_create(void *data, EVGL_Surface *evgl_sfc,
-                              Evas_GL_Config *cfg, int w, int h, int evgl_msaa)
+                              Evas_GL_Config *cfg, int w, int h)
 {
    Render_Engine *re = (Render_Engine *)data;
    Eina_Bool alpha = EINA_FALSE;
@@ -1171,6 +1171,25 @@ evgl_eng_gles1_context_create(void *data,
 #endif
 }
 
+static int
+evgl_eng_native_win_surface_config_check(void *data,
+                              int evgl_depth, int evgl_stencil, int evgl_msaa)
+{
+   Render_Engine *re = data;
+   if (!re) return 0;
+
+   if ((eng_get_ob(re)->detected.depth_buffer_size >= evgl_depth)
+       && (eng_get_ob(re)->detected.stencil_buffer_size >= evgl_stencil)
+       && (eng_get_ob(re)->detected.msaa >= evgl_msaa))
+     {
+        DBG("Win cfg can support the Req Evas GL's config successfully");
+        return 1;
+     }
+   DBG("Win cfg can'n  support.win depth %d, stencil %d, msaa %d",
+                   eng_get_ob(re)->detected.depth_buffer_size, eng_get_ob(re)->detected.stencil_buffer_size,eng_get_ob(re)->detected.msaa);
+   return 0;
+}
+
 static const EVGL_Interface evgl_funcs =
 {
    evgl_eng_display_get,
@@ -1190,6 +1209,7 @@ static const EVGL_Interface evgl_funcs =
    evgl_eng_gles1_surface_create,
    evgl_eng_gles1_surface_destroy,
    evgl_eng_gles1_context_create,
+   evgl_eng_native_win_surface_config_check,
 };
 
 //----------------------------------------------------------//
@@ -1587,7 +1607,10 @@ eng_setup(Evas *eo_e, void *in)
                             info->indirect,
                             info->info.destination_alpha,
                             info->info.rotation,
-                            swap_mode);
+                            swap_mode,
+                            info->depth_bits,
+                            info->stencil_bits,
+                            info->msaa_bits);
         if (!ob)
           {
              free(re);
@@ -1652,6 +1675,9 @@ eng_setup(Evas *eo_e, void *in)
                  (info->info.visual != eng_get_ob(re)->visual) ||
                  (info->info.colormap != eng_get_ob(re)->colormap) ||
                  (info->info.depth != eng_get_ob(re)->depth) ||
+                 (info->depth_bits != eng_get_ob(re)->depth_bits) ||
+                 (info->stencil_bits != eng_get_ob(re)->stencil_bits) ||
+                 (info->msaa_bits != eng_get_ob(re)->msaa_bits) ||
                  (info->info.destination_alpha != eng_get_ob(re)->alpha))
                {
                   Outbuf *ob, *ob_old;
@@ -1671,7 +1697,10 @@ eng_setup(Evas *eo_e, void *in)
                                       info->indirect,
                                       info->info.destination_alpha,
                                       info->info.rotation,
-                                      swap_mode);
+                                      swap_mode,
+                                      info->depth_bits,
+                                      info->stencil_bits,
+                                      info->msaa_bits);
                   if (!ob)
                     {
                        if (ob_old) eng_window_free(ob_old);
index 347c41f30e88c3a67ede700aede589020f4a13bd..bc642b480c9d04eca6507db28337d8e48219f8b2 100644 (file)
@@ -68,15 +68,24 @@ struct _Outbuf
 #else
    GLXContext       context;
    GLXWindow        glxwin;
+#endif
    struct {
+      unsigned char depth_buffer_size;
+      unsigned char stencil_buffer_size;
+      unsigned char msaa;
+#ifndef GL_GLES
       Eina_Bool     loose_binding : 1;
-   } detected;
 #endif
+   } detected;
+
 
    Evas            *evas;
    Display         *disp;
    XVisualInfo     *visualinfo;
    Visual          *visual;
+   int              depth_bits;
+   int              stencil_bits;
+   int              msaa_bits;
    Evas_Engine_GL_Context *gl_context;
    Evas_Engine_Info_GL_X11 *info;
 
@@ -158,7 +167,8 @@ Outbuf *eng_window_new(Evas_Engine_Info_GL_X11 *info, Evas *e,
                        Visual *vis, Colormap cmap,
                        int depth, int w, int h, int indirect,
                        int alpha, int rot,
-                       Render_Engine_Swap_Mode swap_mode);
+                       Render_Engine_Swap_Mode swap_mode,
+                       int depth_bits, int stencil_bits, int msaa_bits);
 void      eng_window_free(Outbuf *gw);
 void      eng_window_use(Outbuf *gw);
 void      eng_window_unsurf(Outbuf *gw);
index d0908da7ca6837f28fa9911ada2af359d55486ff..cfb1dc84f7b1e39d7c16aa1b35b5ff7327af84e8 100644 (file)
@@ -117,7 +117,10 @@ eng_window_new(Evas_Engine_Info_GL_X11 *info,
                int      indirect EINA_UNUSED,
                int      alpha,
                int      rot,
-               Render_Engine_Swap_Mode swap_mode)
+               Render_Engine_Swap_Mode swap_mode,
+               int depth_bits,
+               int stencil_bits,
+               int msaa_bits)
 {
    Outbuf *gw;
    GLContext context;
@@ -129,6 +132,7 @@ eng_window_new(Evas_Engine_Info_GL_X11 *info,
 #endif
    const GLubyte *vendor, *renderer, *version, *glslversion;
    int blacklist = 0;
+   int val = 0;
 
    if (!fbconf) eng_best_visual_get(info);
    if (!_evas_gl_x11_vi) return NULL;
@@ -150,6 +154,9 @@ eng_window_new(Evas_Engine_Info_GL_X11 *info,
    gw->swap_mode = swap_mode;
    gw->info = info;
    gw->evas = e;
+   gw->depth_bits = depth_bits;
+   gw->stencil_bits = stencil_bits;
+   gw->msaa_bits = msaa_bits;
 
    if (gw->alpha && _evas_gl_x11_rgba_vi)
      gw->visualinfo = _evas_gl_x11_rgba_vi;
@@ -255,6 +262,17 @@ eng_window_new(Evas_Engine_Info_GL_X11 *info,
         eng_window_free(gw);
         return NULL;
      }
+
+   eglGetConfigAttrib(gw->egl_disp, gw->egl_config, EGL_DEPTH_SIZE, &val);
+   gw->detected.depth_buffer_size = val;
+   DBG("Detected depth size %d", val);
+   eglGetConfigAttrib(gw->egl_disp, gw->egl_config, EGL_STENCIL_SIZE, &val);
+   gw->detected.stencil_buffer_size = val;
+   DBG("Detected stencil size %d", val);
+   eglGetConfigAttrib(gw->egl_disp, gw->egl_config, EGL_SAMPLES, &val);
+   gw->detected.msaa = val;
+   DBG("Detected msaa %d", val);
+
 // GLX
 #else
    context = _tls_context_get();
@@ -427,6 +445,13 @@ eng_window_new(Evas_Engine_Info_GL_X11 *info,
      {
         // noothing yet. add more cases and options over time
      }
+
+   glXGetConfig(gw->disp, gw->visualinfo, GLX_DEPTH_SIZE, &val);
+   gw->detected.depth_buffer_size = val;
+   glXGetConfig(gw->disp, gw->visualinfo, GLX_STENCIL_SIZE, &val);
+   gw->detected.stencil_buffer_size = val;
+   glXGetConfig(gw->disp, gw->visualinfo, GLX_SAMPLES, &val);
+   gw->detected.msaa = val;
 #endif
 
    gw->gl_context = glsym_evas_gl_common_context_new();
@@ -725,10 +750,46 @@ eng_best_visual_get(Evas_Engine_Info_GL_X11 *einfo)
                   config_attrs[n++] = EGL_ALPHA_SIZE;
                   config_attrs[n++] = 0;
                }
-             config_attrs[n++] = EGL_DEPTH_SIZE;
-             config_attrs[n++] = 0;
-             config_attrs[n++] = EGL_STENCIL_SIZE;
-             config_attrs[n++] = 0;
+
+             // Tizen Only :: Direct Rendering Option for widget (e.g. WEBKIT)
+             /*
+               * Sometimes, Tizen Widget uses Evas GL with Direct Rendering.
+               * This widget also runs with depth/stencil.
+               * Unfortunately, Application can not know this widget uses Evas GL that runs with DR, Depth/Stencil buffer.
+               * Although application does not set depth/stencil buffer size,
+               * evas gl render engine should set depth/stencil buffer size with minimum.
+               * This is HACK code for tizen platform.
+               */
+
+             if (einfo->depth_bits)
+               {
+                  config_attrs[n++] = EGL_DEPTH_SIZE;
+                  config_attrs[n++] = einfo->depth_bits;
+               }
+             else
+               {
+                  config_attrs[n++] = EGL_DEPTH_SIZE;
+                  config_attrs[n++] = 1;
+               }
+
+             if (einfo->stencil_bits)
+               {
+                  config_attrs[n++] = EGL_STENCIL_SIZE;
+                  config_attrs[n++] = einfo->stencil_bits;
+               }
+             else
+              {
+                  config_attrs[n++] = EGL_STENCIL_SIZE;
+                  config_attrs[n++] = 1;
+              }
+
+             if (einfo->msaa_bits)
+               {
+                  config_attrs[n++] = EGL_SAMPLE_BUFFERS;
+                  config_attrs[n++] = 1;
+                  config_attrs[n++] = EGL_SAMPLES;
+                  config_attrs[n++] = einfo->msaa_bits;
+               }
              config_attrs[n++] = EGL_NONE;
              num = 0;
              if ((!eglChooseConfig(egl_disp, config_attrs, configs, 200, &num))
index 77e474cbe0e897fe384dcb9da56daf8a729b02cb..aef9a11376b7b6afcb93b82d378b302887e6f587 100644 (file)
@@ -674,6 +674,7 @@ static const EVGL_Interface evgl_funcs =
    evgl_eng_pbuffer_surface_destroy,
    NULL, //gles1_surface_create
    NULL, // gles1_surface_destroy
+   NULL, //native_win_surface_config_check
 };
 
 /* engine functions */