evas_gl: Add feature to set depth/stencil/msaa bit to window surface.
authorWonsik Jung <sidein@samsung.com>
Mon, 16 Mar 2015 04:57:09 +0000 (13:57 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Mon, 16 Mar 2015 05:50:56 +0000 (14:50 +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.

Reviewers: spacegrapher, cedric, raster, jpeg

Reviewed By: jpeg

Subscribers: cedric, mer.kim

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

Signed-off-by: Jean-Philippe Andre <jp.andre@samsung.com>
Note: jpeg changed the original patch a bit (fix style and depth value)

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 118bce1..d65e11b 100644 (file)
@@ -1113,7 +1113,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 31d5108..2d9c8f9 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 afa2a6f..8d86d99 100644 (file)
@@ -1067,10 +1067,12 @@ _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 depth_size = 0;
+   Eina_Bool support_win_cfg = 1;
 
    // Check if engine is valid
    if (!evgl_engine)
@@ -1081,7 +1083,11 @@ _internal_config_set(EVGL_Surface *sfc, Evas_GL_Config *cfg)
 
    // Convert Config Format to bitmask friendly format
    color_bit = (1 << cfg->color_format);
-   if (cfg->depth_bits) depth_bit = (1 << (cfg->depth_bits-1));
+   if (cfg->depth_bits)
+     {
+        depth_bit = (1 << (cfg->depth_bits-1));
+        depth_size = 8 * cfg->depth_bits;
+     }
    if (cfg->stencil_bits) stencil_bit = (1 << (cfg->stencil_bits-1));
    if (cfg->multisample_bits)
       msaa_samples = evgl_engine->caps.msaa_samples[cfg->multisample_bits-1];
@@ -1118,18 +1124,15 @@ _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:
-             if (((depth_bit > 0)  ||(stencil_bit > 0) ||(msaa_samples > 0))
+             // Direct Rendering Option
+             if (((depth_bit > 0) || (stencil_bit > 0) || (msaa_samples > 0))
                   && (evgl_engine->funcs->native_win_surface_config_check))
                {
-                  DBG("request to check wid 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);
+                  DBG("request to check win cfg with depth %d, stencil %d, msaa %d", depth_size, stencil_bit, msaa_samples);
+                  support_win_cfg = evgl_engine->funcs->native_win_surface_config_check(eng_data, depth_size, stencil_bit, msaa_samples);
                }
-             */
 
-             // Direct Rendering Option
-             if ((!depth_bit && !stencil_bit && !msaa_samples) || sfc->direct_override)
+             if ((sfc->direct_override) || support_win_cfg)
                sfc->direct_fb_opt = !!(cfg->options_bits & EVAS_GL_OPTIONS_DIRECT);
 
              // Extra flags for direct rendering
@@ -1148,7 +1151,7 @@ _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));
@@ -1157,6 +1160,7 @@ _internal_config_set(EVGL_Surface *sfc, Evas_GL_Config *cfg)
         DBG("  MSAA Samples     : %d", sfc->msaa_samples);
         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;
      }
@@ -1606,7 +1610,7 @@ evgl_surface_create(void *eng_data, Evas_GL_Config *cfg, int w, int h)
      sfc->direct_override = EINA_TRUE;
 
    // 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);
@@ -1762,7 +1766,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 454534a..075d4a1 100644 (file)
@@ -77,6 +77,10 @@ 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
+   Eina_Bool  (*native_win_surface_config_check)(void *data, int evgl_depth, int evgl_stencil, int evgl_msaa);
+
 };
 
 struct _EVGL_Surface
index 2152e88..11a20b6 100644 (file)
@@ -132,6 +132,8 @@ static const EVGL_Interface evgl_funcs =
    NULL, // PBuffer
    NULL, // OpenGL-ES 1
    NULL, // OpenGL-ES 1
+   NULL, // OpenGL-ES 1
+   NULL, // native_win_surface_config_check
 };
 
 /* local functions */
index 20d2c45..5691684 100644 (file)
@@ -259,6 +259,8 @@ static const EVGL_Interface evgl_funcs =
    NULL, // PBuffer
    NULL, // OpenGL-ES 1
    NULL, // OpenGL-ES 1
+   NULL, // OpenGL-ES 1
+   NULL, // native_win_surface_config_check
 };
 
 
index e66539e..ded7ca4 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 0f5ae53..fa6ad34 100644 (file)
@@ -1179,6 +1179,26 @@ evgl_eng_gles1_context_create(void *data,
 #endif
 }
 
+static Eina_Bool
+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 EINA_FALSE;
+
+   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 EINA_TRUE;
+     }
+   DBG("Win cfg can't support Evas GL DR 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 EINA_FALSE;
+}
 
 static const EVGL_Interface evgl_funcs =
 {
@@ -1199,6 +1219,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,
 };
 
 //----------------------------------------------------------//
@@ -1579,7 +1600,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);
@@ -1644,6 +1668,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;
@@ -1663,7 +1690,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 114ea6e..a090393 100644 (file)
@@ -69,15 +69,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;
 
@@ -159,7 +168,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 767f580..29b3910 100644 (file)
@@ -118,7 +118,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;
@@ -130,6 +133,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;
@@ -151,6 +155,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;
@@ -264,6 +271,17 @@ try_gles2:
         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();
@@ -436,6 +454,13 @@ try_gles2:
      {
         // 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();
@@ -772,10 +797,26 @@ 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;
+
+             if (einfo->depth_bits)
+               {
+                  config_attrs[n++] = EGL_DEPTH_SIZE;
+                  config_attrs[n++] = einfo->depth_bits;
+               }
+
+             if (einfo->stencil_bits)
+               {
+                  config_attrs[n++] = EGL_STENCIL_SIZE;
+                  config_attrs[n++] = einfo->stencil_bits;
+               }
+
+             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 3841211..0b33672 100644 (file)
@@ -476,6 +476,8 @@ static const EVGL_Interface evgl_funcs =
    NULL, // PBuffer
    NULL, // OpenGL-ES 1
    NULL, // OpenGL-ES 1
+   NULL, // OpenGL-ES 1
+   NULL, // native_win_surface_config_check
 };
 
 /* engine functions */