[Cogl] [PATCH] egl: remove special re-try without stencil code

Robert Bragg robert at sixbynine.org
Fri Sep 28 07:57:37 PDT 2012


From: Robert Bragg <robert at linux.intel.com>

The EGL winsys had a special case code path when trying to create a
context where if it failed it would try again except without requesting
a stencil buffer. Historically this code path was to allow Clutter to
run on PowerVR MBX hardware which doesn't support a stencil buffer. It
doesn't really make sense to keep this workaround in Cogl as it would
leave Cogl in a state where the clip stack doesn't work without
providing any feedback to the developer. If we need to support running
on MBX like hardware - probably not very likely these days - then we
should provide developer control over the stencil buffer so the
equivalent workaround could be implemented on top of Cogl.
---
 cogl/winsys/cogl-winsys-egl-private.h |    1 -
 cogl/winsys/cogl-winsys-egl.c         |  135 +++++++++++++-------------------
 2 files changed, 55 insertions(+), 81 deletions(-)

diff --git a/cogl/winsys/cogl-winsys-egl-private.h b/cogl/winsys/cogl-winsys-egl-private.h
index 3f092ae..f1e5361 100644
--- a/cogl/winsys/cogl-winsys-egl-private.h
+++ b/cogl/winsys/cogl-winsys-egl-private.h
@@ -108,7 +108,6 @@ typedef struct _CoglDisplayEGL
 
   EGLConfig egl_config;
   CoglBool found_egl_config;
-  CoglBool stencil_disabled;
 
   EGLSurface current_read_surface;
   EGLSurface current_draw_surface;
diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
index dcd17ed..6974663 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -199,7 +199,6 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
 static void
 egl_attributes_from_framebuffer_config (CoglDisplay *display,
                                         CoglFramebufferConfig *config,
-                                        CoglBool needs_stencil_override,
                                         EGLint *attributes)
 {
   CoglRenderer *renderer = display->renderer;
@@ -212,8 +211,11 @@ egl_attributes_from_framebuffer_config (CoglDisplay *display,
                                                               config,
                                                               attributes);
 
-  attributes[i++] = EGL_STENCIL_SIZE;
-  attributes[i++] = needs_stencil_override ? 2 : 0;
+  if (config->need_stencil)
+    {
+      attributes[i++] = EGL_STENCIL_SIZE;
+      attributes[i++] = 2;
+    }
 
   attributes[i++] = EGL_RED_SIZE;
   attributes[i++] = 1;
@@ -254,9 +256,55 @@ egl_attributes_from_framebuffer_config (CoglDisplay *display,
   g_assert (i < MAX_EGL_CONFIG_ATTRIBS);
 }
 
+EGLBoolean
+_cogl_winsys_egl_make_current (CoglDisplay *display,
+                               EGLSurface draw,
+                               EGLSurface read,
+                               EGLContext context)
+{
+  CoglDisplayEGL *egl_display = display->winsys;
+  CoglRendererEGL *egl_renderer = display->renderer->winsys;
+  EGLBoolean ret;
+
+  if (egl_display->current_draw_surface == draw &&
+      egl_display->current_read_surface == read &&
+      egl_display->current_context == context)
+  return EGL_TRUE;
+
+  ret = eglMakeCurrent (egl_renderer->edpy,
+                        draw,
+                        read,
+                        context);
+
+  egl_display->current_draw_surface = draw;
+  egl_display->current_read_surface = read;
+  egl_display->current_context = context;
+
+  return ret;
+}
+
+static void
+cleanup_context (CoglDisplay *display)
+{
+  CoglRenderer *renderer = display->renderer;
+  CoglDisplayEGL *egl_display = display->winsys;
+  CoglRendererEGL *egl_renderer = renderer->winsys;
+
+  if (egl_display->egl_context != EGL_NO_CONTEXT)
+    {
+      _cogl_winsys_egl_make_current (display,
+                                     EGL_NO_SURFACE, EGL_NO_SURFACE,
+                                     EGL_NO_CONTEXT);
+      eglDestroyContext (egl_renderer->edpy, egl_display->egl_context);
+      egl_display->egl_context = EGL_NO_CONTEXT;
+    }
+
+  if (egl_renderer->platform_vtable->cleanup_context)
+    egl_renderer->platform_vtable->cleanup_context (display);
+}
+
 static CoglBool
 try_create_context (CoglDisplay *display,
-                    CoglBool with_stencil_buffer,
                     CoglError **error)
 {
   CoglRenderer *renderer = display->renderer;
@@ -286,7 +334,6 @@ try_create_context (CoglDisplay *display,
 
   egl_attributes_from_framebuffer_config (display,
                                           &display->onscreen_template->config,
-                                          with_stencil_buffer,
                                           cfg_attribs);
 
   edpy = egl_renderer->edpy;
@@ -323,79 +370,10 @@ fail:
   _cogl_set_error (error, COGL_WINSYS_ERROR,
                COGL_WINSYS_ERROR_CREATE_CONTEXT,
                "%s", error_message);
-  return FALSE;
-}
-
-EGLBoolean
-_cogl_winsys_egl_make_current (CoglDisplay *display,
-                               EGLSurface draw,
-                               EGLSurface read,
-                               EGLContext context)
-{
-  CoglDisplayEGL *egl_display = display->winsys;
-  CoglRendererEGL *egl_renderer = display->renderer->winsys;
-  EGLBoolean ret;
-
-  if (egl_display->current_draw_surface == draw &&
-      egl_display->current_read_surface == read &&
-      egl_display->current_context == context)
-  return EGL_TRUE;
-
-  ret = eglMakeCurrent (egl_renderer->edpy,
-                        draw,
-                        read,
-                        context);
-
-  egl_display->current_draw_surface = draw;
-  egl_display->current_read_surface = read;
-  egl_display->current_context = context;
-
-  return ret;
-}
-
-static void
-cleanup_context (CoglDisplay *display)
-{
-  CoglRenderer *renderer = display->renderer;
-  CoglDisplayEGL *egl_display = display->winsys;
-  CoglRendererEGL *egl_renderer = renderer->winsys;
-
-  if (egl_display->egl_context != EGL_NO_CONTEXT)
-    {
-      _cogl_winsys_egl_make_current (display,
-                                     EGL_NO_SURFACE, EGL_NO_SURFACE,
-                                     EGL_NO_CONTEXT);
-      eglDestroyContext (egl_renderer->edpy, egl_display->egl_context);
-      egl_display->egl_context = EGL_NO_CONTEXT;
-    }
 
-  if (egl_renderer->platform_vtable->cleanup_context)
-    egl_renderer->platform_vtable->cleanup_context (display);
-}
-
-static CoglBool
-create_context (CoglDisplay *display, CoglError **error)
-{
-  CoglDisplayEGL *egl_display = display->winsys;
+  cleanup_context (display);
 
-  /* Note: we don't just rely on eglChooseConfig to correctly
-   * report that the driver doesn't support a stencil buffer
-   * because we've seen PVR drivers that claim stencil buffer
-   * support according to the EGLConfig but then later fail
-   * when trying to create a context with such a config.
-   */
-  if (try_create_context (display, TRUE, error))
-    {
-      egl_display->stencil_disabled = FALSE;
-      return TRUE;
-    }
-  else
-    {
-      _cogl_clear_error (error);
-      cleanup_context (display);
-      egl_display->stencil_disabled = TRUE;
-      return try_create_context (display, FALSE, error);
-    }
+  return FALSE;
 }
 
 static void
@@ -443,7 +421,7 @@ _cogl_winsys_display_setup (CoglDisplay *display,
       !egl_renderer->platform_vtable->display_setup (display, error))
     goto error;
 
-  if (!create_context (display, error))
+  if (!try_create_context (display, error))
     goto error;
 
   egl_display->found_egl_config = TRUE;
@@ -569,14 +547,11 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
   EGLConfig egl_config;
   EGLint config_count = 0;
   EGLBoolean status;
-  CoglBool need_stencil =
-    egl_display->stencil_disabled ? FALSE : framebuffer->config.need_stencil;
 
   _COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context, FALSE);
 
   egl_attributes_from_framebuffer_config (display,
                                           &framebuffer->config,
-                                          need_stencil,
                                           attributes);
 
   status = eglChooseConfig (egl_renderer->edpy,
-- 
1.7.7.6



More information about the Cogl mailing list