[cogl] Make stub winsys into a proper winsys backend



commit b380fed23d61688d1ea199ac28ff4bfba0a32985
Author: Robert Bragg <robert linux intel com>
Date:   Tue May 17 15:00:38 2011 +0100

    Make stub winsys into a proper winsys backend
    
    Instead of the stub winsys being a special case set of #ifdef'd code
    used when COGL_HAS_FULL_WINSYS wasn't defined, the stub winsys now
    implements a CoglWinsysVtable like all other winsys backends (it's just
    that everything is a NOP). This way we can get rid of the
    COGL_HAS_FULL_WINSYS define and also the stub winsys can be runtime
    selected whereas before it was incompatible with all other winsys
    backends.

 cogl/Makefile.am                       |    5 +-
 cogl/cogl-clutter.c                    |    3 +-
 cogl/cogl-context-private.h            |    1 -
 cogl/cogl-context.c                    |   19 +----
 cogl/cogl-display.c                    |    4 -
 cogl/cogl-framebuffer.c                |    2 -
 cogl/cogl-renderer.c                   |   18 +----
 cogl/cogl.c                            |    4 -
 cogl/winsys/cogl-winsys-stub-private.h |   30 +++++++
 cogl/winsys/cogl-winsys-stub.c         |  137 +++++++++++++++++++++-----------
 configure.ac                           |   40 ---------
 11 files changed, 130 insertions(+), 133 deletions(-)
---
diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index 91451bb..be2759d 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -303,6 +303,7 @@ cogl_sources_c = \
 	$(srcdir)/cogl-point-in-poly-private.h       	\
 	$(srcdir)/cogl-point-in-poly.c       		\
 	$(srcdir)/cogl-clutter.c       			\
+	$(srcdir)/winsys/cogl-winsys-stub.c		\
 	$(NULL)
 
 if SUPPORT_XLIB
@@ -352,10 +353,6 @@ if SUPPORT_EGL_PLATFORM_ANDROID
 cogl_sources_c += \
        $(srcdir)/winsys/cogl-winsys-egl.c
 endif
-if SUPPORT_STUB
-cogl_sources_c += \
-       $(srcdir)/winsys/cogl-winsys-stub.c
-endif
 
 EXTRA_DIST += stb_image.c
 
diff --git a/cogl/cogl-clutter.c b/cogl/cogl-clutter.c
index f85f32e..aaf0281 100644
--- a/cogl/cogl-clutter.c
+++ b/cogl/cogl-clutter.c
@@ -35,6 +35,7 @@
 #include "cogl-private.h"
 #include "cogl-context-private.h"
 #include "cogl-winsys-private.h"
+#include "cogl-winsys-stub-private.h"
 #include "cogl-framebuffer-private.h"
 
 gboolean
@@ -56,7 +57,7 @@ cogl_onscreen_clutter_backend_set_size (int width, int height)
 
   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
 
-  if (!ctx->stub_winsys)
+  if (_cogl_context_get_winsys (ctx) != _cogl_winsys_stub_get_vtable ())
     return;
 
   framebuffer = COGL_FRAMEBUFFER (ctx->window_buffer);
diff --git a/cogl/cogl-context-private.h b/cogl/cogl-context-private.h
index c9b7c64..2cf1be5 100644
--- a/cogl/cogl-context-private.h
+++ b/cogl/cogl-context-private.h
@@ -263,7 +263,6 @@ struct _CoglContext
   unsigned int winsys_features
     [COGL_FLAGS_N_INTS_FOR_SIZE (COGL_WINSYS_FEATURE_N_FEATURES)];
   void *winsys;
-  gboolean stub_winsys;
 };
 
 CoglContext *
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index 90f8af4..7a0063d 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -30,6 +30,7 @@
 #include "cogl-internal.h"
 #include "cogl-private.h"
 #include "cogl-winsys-private.h"
+#include "cogl-winsys-stub-private.h"
 #include "cogl-profile.h"
 #include "cogl-util.h"
 #include "cogl-context-private.h"
@@ -162,8 +163,6 @@ cogl_context_new (CoglDisplay *display,
 
   context->display = display;
 
-#ifdef COGL_HAS_FULL_WINSYS
-  context->stub_winsys = FALSE;
   winsys = _cogl_context_get_winsys (context);
   if (!winsys->context_init (context, error))
     {
@@ -171,20 +170,6 @@ cogl_context_new (CoglDisplay *display,
       g_free (context);
       return NULL;
     }
-#else
-  /* In this case Clutter is still responsible for creating a GL
-   * context. */
-  context->stub_winsys = TRUE;
-  if (!_cogl_gl_check_version (error))
-    {
-      g_free (context);
-      return NULL;
-    }
-  _cogl_gl_update_features (context);
-#ifdef COGL_HAS_XLIB_SUPPORT
-  _cogl_xlib_query_damage_extension ();
-#endif
-#endif
 
   /* Initialise the driver specific state */
   _cogl_init_feature_overrides (context);
@@ -284,7 +269,7 @@ cogl_context_new (CoglDisplay *display,
    * the OpenGL binding API and for creating onscreen framebuffers and
    * so we have to add a dummy framebuffer to represent the backend
    * owned window... */
-  if (context->stub_winsys)
+  if (_cogl_context_get_winsys (context) == _cogl_winsys_stub_get_vtable ())
     {
       CoglOnscreen *window = _cogl_onscreen_new ();
       cogl_set_framebuffer (COGL_FRAMEBUFFER (window));
diff --git a/cogl/cogl-display.c b/cogl/cogl-display.c
index 0953f1f..967c070 100644
--- a/cogl/cogl-display.c
+++ b/cogl/cogl-display.c
@@ -104,18 +104,14 @@ gboolean
 cogl_display_setup (CoglDisplay *display,
                     GError **error)
 {
-#ifdef COGL_HAS_FULL_WINSYS
   const CoglWinsysVtable *winsys;
-#endif
 
   if (display->setup)
     return TRUE;
 
-#ifdef COGL_HAS_FULL_WINSYS
   winsys = _cogl_display_get_winsys (display);
   if (!winsys->display_setup (display, error))
     return FALSE;
-#endif
 
   display->setup = TRUE;
 
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index ac2244d..82d3f76 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -1372,11 +1372,9 @@ bind_gl_framebuffer (CoglContext *ctx,
                            COGL_OFFSCREEN (framebuffer)->fbo_handle));
   else
     {
-#ifdef COGL_HAS_FULL_WINSYS
       const CoglWinsysVtable *winsys =
         _cogl_framebuffer_get_winsys (framebuffer);
       winsys->onscreen_bind (COGL_ONSCREEN (framebuffer));
-#endif
       /* glBindFramebuffer is an an extension with OpenGL ES 1.1 */
       if (cogl_features_available (COGL_FEATURE_OFFSCREEN))
         GE (glBindFramebuffer (target, 0));
diff --git a/cogl/cogl-renderer.c b/cogl/cogl-renderer.c
index df05247..d2badc8 100644
--- a/cogl/cogl-renderer.c
+++ b/cogl/cogl-renderer.c
@@ -39,8 +39,7 @@
 #include "cogl-renderer-private.h"
 #include "cogl-display-private.h"
 #include "cogl-winsys-private.h"
-
-#ifdef COGL_HAS_FULL_WINSYS
+#include "cogl-winsys-stub-private.h"
 
 #ifdef COGL_HAS_GLX_SUPPORT
 extern const CoglWinsysVtable *_cogl_winsys_glx_get_vtable (void);
@@ -65,10 +64,9 @@ static CoglWinsysVtableGetter _cogl_winsys_vtable_getters[] =
 #ifdef COGL_HAS_WGL_SUPPORT
   _cogl_winsys_wgl_get_vtable,
 #endif
+  _cogl_winsys_stub_get_vtable,
 };
 
-#endif /* COGL_HAS_FULL_WINSYS */
-
 static void _cogl_renderer_free (CoglRenderer *renderer);
 
 COGL_OBJECT_DEFINE (Renderer, renderer);
@@ -100,10 +98,8 @@ native_filter_closure_free (CoglNativeFilterClosure *closure)
 static void
 _cogl_renderer_free (CoglRenderer *renderer)
 {
-#ifdef COGL_HAS_FULL_WINSYS
   const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer);
   winsys->renderer_disconnect (renderer);
-#endif
 
   g_slist_foreach (renderer->event_filters,
                    (GFunc) native_filter_closure_free,
@@ -151,7 +147,6 @@ cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
                                        CoglOnscreenTemplate *onscreen_template,
                                        GError **error)
 {
-#ifdef COGL_HAS_FULL_WINSYS
   CoglDisplay *display;
   const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer);
 
@@ -166,7 +161,7 @@ cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
     }
 
   cogl_object_unref (display);
-#endif
+
   return TRUE;
 }
 
@@ -175,16 +170,13 @@ cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
 gboolean
 cogl_renderer_connect (CoglRenderer *renderer, GError **error)
 {
-#ifdef COGL_HAS_FULL_WINSYS
   int i;
   char *renderer_name = getenv ("COGL_RENDERER");
-#endif
   GString *error_message;
 
   if (renderer->connected)
     return TRUE;
 
-#ifdef COGL_HAS_FULL_WINSYS
   error_message = g_string_new ("");
   for (i = 0; i < G_N_ELEMENTS (_cogl_winsys_vtable_getters); i++)
     {
@@ -221,10 +213,6 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
     }
 
   return TRUE;
-#else
-  renderer->connected = TRUE;
-  return TRUE;
-#endif
 }
 
 CoglFilterReturn
diff --git a/cogl/cogl.c b/cogl/cogl.c
index 6592221..896b2e6 100644
--- a/cogl/cogl.c
+++ b/cogl/cogl.c
@@ -95,7 +95,6 @@ cogl_get_proc_address (const char* name)
 {
   void *address;
   static GModule *module = NULL;
-#ifdef COGL_HAS_FULL_WINSYS
   const CoglWinsysVtable *winsys;
 
   _COGL_GET_CONTEXT (ctx, NULL);
@@ -103,9 +102,6 @@ cogl_get_proc_address (const char* name)
   winsys = _cogl_context_get_winsys (ctx);
 
   address = winsys->get_proc_address (name);
-#else
-  address = _cogl_winsys_get_proc_address (name);
-#endif
   if (address)
     return address;
 
diff --git a/cogl/winsys/cogl-winsys-stub-private.h b/cogl/winsys/cogl-winsys-stub-private.h
new file mode 100644
index 0000000..3e837b2
--- /dev/null
+++ b/cogl/winsys/cogl-winsys-stub-private.h
@@ -0,0 +1,30 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2011 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ */
+
+#ifndef __COGL_WINSYS_STUB_PRIVATE_H
+#define __COGL_WINSYS_STUB_PRIVATE_H
+
+const CoglWinsysVtable *
+_cogl_winsys_stub_get_vtable (void);
+
+#endif /* __COGL_WINSYS_STUB_PRIVATE_H */
diff --git a/cogl/winsys/cogl-winsys-stub.c b/cogl/winsys/cogl-winsys-stub.c
index a45cbdf..ef22e13 100644
--- a/cogl/winsys/cogl-winsys-stub.c
+++ b/cogl/winsys/cogl-winsys-stub.c
@@ -3,7 +3,7 @@
  *
  * An object oriented GL/GLES Abstraction/Utility Layer
  *
- * Copyright (C) 2010 Intel Corporation.
+ * Copyright (C) 2011 Intel Corporation.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -16,97 +16,144 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
  *
  *
+ * Authors:
+ *  Robert Bragg <robert linux intel com>
+ *
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include "cogl-renderer-private.h"
+#include "cogl-display-private.h"
+#include "cogl-context-private.h"
 #include "cogl-framebuffer-private.h"
+#include "cogl-private.h"
+
+#include <string.h>
+
+static int _cogl_winsys_stub_dummy_ptr;
 
-/* This provides a stub winsys implementation for when Clutter still handles
- * creating an OpenGL context. This is useful so we don't have to guard all
- * calls into the winsys layer with #ifdef COGL_HAS_FULL_WINSYS
+/* This provides a NOP winsys. This can be useful for debugging or for
+ * integrating with toolkits that already have window system
+ * integration code.
  */
 
-CoglFuncPtr
+static CoglFuncPtr
 _cogl_winsys_get_proc_address (const char *name)
 {
   return NULL;
 }
 
-void
-_cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
+static void
+_cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 {
-
+  renderer->winsys = NULL;
 }
 
-void
-_cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
-                                   int *rectangles,
-                                   int n_rectangles)
+static gboolean
+_cogl_winsys_renderer_connect (CoglRenderer *renderer,
+                               GError **error)
 {
-
+  renderer->winsys = &_cogl_winsys_stub_dummy_ptr;
+  return TRUE;
 }
 
-void
-_cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen)
+static void
+_cogl_winsys_display_destroy (CoglDisplay *display)
 {
-
+  display->winsys = NULL;
 }
 
-unsigned int
-_cogl_winsys_onscreen_add_swap_buffers_callback (CoglOnscreen *onscreen,
-                                                 CoglSwapBuffersNotify callback,
-                                                 void *user_data)
+static gboolean
+_cogl_winsys_display_setup (CoglDisplay *display,
+                            GError **error)
 {
-  g_assert (0);
-  return 0;
+  display->winsys = &_cogl_winsys_stub_dummy_ptr;
+  return TRUE;
 }
 
-void
-_cogl_winsys_onscreen_remove_swap_buffers_callback (CoglOnscreen *onscreen,
-                                                    unsigned int id)
+static gboolean
+_cogl_winsys_context_init (CoglContext *context, GError **error)
 {
-  g_assert (0);
-}
+  context->winsys = &_cogl_winsys_stub_dummy_ptr;
 
-#ifdef COGL_HAS_XLIB_SUPPORT
-XVisualInfo *
-_cogl_winsys_xlib_get_visual_info (void)
-{
-  g_assert (0);
-  return NULL;
+  if (!_cogl_gl_check_version (error))
+    return FALSE;
+
+  _cogl_gl_update_features (context);
+
+  memset (context->winsys_features, 0, sizeof (context->winsys_features));
+
+  return TRUE;
 }
-#endif
 
-#ifdef COGL_HAS_X11_SUPPORT
-guint32
-_cogl_winsys_onscreen_x11_get_window_xid (CoglOnscreen *onscreen)
+static void
+_cogl_winsys_context_deinit (CoglContext *context)
 {
-  g_assert (0);
-  return 0;
+  context->winsys = NULL;
 }
-#endif
 
-gboolean
+static gboolean
 _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
                             GError **error)
 {
   return TRUE;
 }
 
-void
+static void
 _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
 {
+}
 
+static void
+_cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
+{
 }
 
-void
-_cogl_winsys_context_deinit (CoglContext *context)
+static void
+_cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
 {
+}
 
+static void
+_cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen)
+{
+}
+
+static void
+_cogl_winsys_onscreen_set_visibility (CoglOnscreen *onscreen,
+                                      gboolean visibility)
+{
+}
+
+static CoglWinsysVtable _cogl_winsys_vtable =
+  {
+    .name = "STUB",
+    .get_proc_address = _cogl_winsys_get_proc_address,
+    .renderer_connect = _cogl_winsys_renderer_connect,
+    .renderer_disconnect = _cogl_winsys_renderer_disconnect,
+    .display_setup = _cogl_winsys_display_setup,
+    .display_destroy = _cogl_winsys_display_destroy,
+    .context_init = _cogl_winsys_context_init,
+    .context_deinit = _cogl_winsys_context_deinit,
+
+    .onscreen_init = _cogl_winsys_onscreen_init,
+    .onscreen_deinit = _cogl_winsys_onscreen_deinit,
+    .onscreen_bind = _cogl_winsys_onscreen_bind,
+    .onscreen_swap_buffers = _cogl_winsys_onscreen_swap_buffers,
+    .onscreen_update_swap_throttled =
+      _cogl_winsys_onscreen_update_swap_throttled,
+    .onscreen_set_visibility = _cogl_winsys_onscreen_set_visibility,
+  };
+
+const CoglWinsysVtable *
+_cogl_winsys_stub_get_vtable (void)
+{
+  return &_cogl_winsys_vtable;
 }
diff --git a/configure.ac b/configure.ac
index 6173033..b0ce0d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -486,24 +486,6 @@ dnl         ========================================================
 dnl         Check window system integration libraries...
 dnl         ========================================================
 
-dnl The "stub" winsys is a fallback option we use when Cogl doesn't
-dnl yet have support for a window system. It enables a toolkit like
-dnl Clutter to provide external support instead. Currently this is
-dnl not compatible with other window system backends.
-AC_ARG_ENABLE(
-  [stub-winsys],
-  [AC_HELP_STRING([--enable-stub-winsys=@<:@no/yes@:>@], [Enable support stub winsys @<:@default=no@:>@])],
-  [],
-  enable_stub_winsys=no
-)
-AS_IF([test "x$enable_stub_winsys" = "xyes"],
-      [
-        GL_WINSYS_APIS="$GL_WINSYS_APIS stub"
-        ALLOW_GLX=no
-        ALLOW_WGL=no
-      ])
-AM_CONDITIONAL(SUPPORT_STUB, [test "x$enable_stub_winsys" = "xyes"])
-
 AC_ARG_ENABLE(
   [glx],
   [AC_HELP_STRING([--enable-glx=@<:@no/yes@:>@], [Enable support GLX @<:@default=auto@:>@])],
@@ -512,9 +494,6 @@ AC_ARG_ENABLE(
 )
 AS_IF([test "x$enable_glx" = "xyes"],
       [
-        AS_IF([test "x$enable_stub_winsys" = "xyes"],
-              [AC_MSG_ERROR([Stub winsys not currently compatible with others])])
-
         AS_IF([test "x$ALLOW_GLX" != "xyes"],
               [AC_MSG_ERROR([GLX not supported with $COGL_DRIVER driver])])
 
@@ -523,8 +502,6 @@ AS_IF([test "x$enable_glx" = "xyes"],
         GL_WINSYS_APIS="$GL_WINSYS_APIS glx"
 
         AC_DEFINE([COGL_HAS_GLX_SUPPORT], [1], [Cogl supports OpenGL using the GLX API])
-        AC_DEFINE([COGL_HAS_FULL_WINSYS], [1],
-                  [Cogl can create its own OpenGL context])
 
         # We might fall back to DRM for sync-to-vblank on GLX
         PKG_CHECK_EXISTS([libdrm],
@@ -544,9 +521,6 @@ AC_ARG_ENABLE(
 )
 AS_IF([test "x$enable_wgl" = "xyes"],
       [
-        AS_IF([test "x$enable_stub_winsys" = "xyes"],
-              [AC_MSG_ERROR([Stub winsys not currently compatible with others])])
-
         AS_IF([test "x$ALLOW_WGL" != "xyes"],
               [AC_MSG_ERROR([WGL not supported with $COGL_DRIVER driver])])
 
@@ -555,9 +529,6 @@ AS_IF([test "x$enable_wgl" = "xyes"],
 
         AC_DEFINE([COGL_HAS_WGL_SUPPORT], [1], [Cogl supports OpenGL using the WGL API])
         COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_WIN32_SUPPORT"
-
-        AC_DEFINE([COGL_HAS_FULL_WINSYS], [1],
-                  [Cogl can create its own OpenGL context])
       ])
 AM_CONDITIONAL(SUPPORT_WGL, [test "x$SUPPORT_WGL" = "xyes"])
 
@@ -571,9 +542,6 @@ AC_ARG_ENABLE(
 )
 AS_IF([test "x$enable_null_egl_platform" = "xyes"],
       [
-        AS_IF([test "x$enable_stub_winsys" = "xyes"],
-              [AC_MSG_ERROR([Stub winsys not currently compatible with others])])
-
         EGL_PLATFORM_COUNT=$((EGL_PLATFORM_COUNT+1))
         NEED_EGL=yes
         EGL_PLATFORMS="$EGL_PLATFORMS null"
@@ -591,9 +559,6 @@ AC_ARG_ENABLE(
 )
 AS_IF([test "x$enable_gdl_egl_platform" == "xyes"],
       [
-        AS_IF([test "x$enable_stub_winsys" = "xyes"],
-              [AC_MSG_ERROR([Stub winsys not currently compatible with others])])
-
         EGL_PLATFORM_COUNT=$((EGL_PLATFORM_COUNT+1))
         NEED_EGL=yes
         EGL_PLATFORMS="$EGL_PLATFORMS gdl"
@@ -670,9 +635,6 @@ AC_ARG_ENABLE(
 )
 AS_IF([test "x$enable_xlib_egl_platform" = "xyes"],
       [
-        AS_IF([test "x$enable_stub_winsys" = "xyes"],
-              [AC_MSG_ERROR([Stub winsys not currently compatible with others])])
-
         EGL_PLATFORM_COUNT=$((EGL_PLATFORM_COUNT+1))
         NEED_EGL=yes
         NEED_XLIB=yes
@@ -712,8 +674,6 @@ AS_IF([test "x$NEED_EGL" = "xyes"],
         SUPPORT_EGL=yes
         GL_WINSYS_APIS="$GL_WINSYS_APIS egl"
         COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_EGL_SUPPORT"
-        AC_DEFINE([COGL_HAS_FULL_WINSYS], [1],
-                  [Cogl can create its own OpenGL context])
       ])
 
 AM_CONDITIONAL(SUPPORT_EGL, [test "x$SUPPORT_EGL" = "xyes"])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]