[cogl] renderer: Expose winsys ID setter/getters



commit b3a105c576a00fdecd27982811ef6b085009291a
Author: Robert Bragg <robert linux intel com>
Date:   Mon Jun 20 13:29:12 2011 +0100

    renderer: Expose winsys ID setter/getters
    
    This adds API to let you override the choice of Cogl's winsys backend.
    Previously it was only possible to override the winsys using the
    COGL_RENDERER environment variable, but it's useful for something like
    Clutter to be able to control the winsys via API without needing
    environment variable tricks. This also adds API to query back the
    winsys chosen by Cogl, in case you don't set an explicit override.
    
    Signed-off-by: Neil Roberts <neil linux intel com>

 cogl/cogl-renderer-private.h      |    1 +
 cogl/cogl-renderer.c              |   31 +++++++++++++++++++--
 cogl/cogl-renderer.h              |   55 +++++++++++++++++++++++++++++++++++++
 cogl/winsys/cogl-winsys-egl.c     |    1 +
 cogl/winsys/cogl-winsys-glx.c     |    1 +
 cogl/winsys/cogl-winsys-private.h |    4 +++
 cogl/winsys/cogl-winsys-stub.c    |    1 +
 cogl/winsys/cogl-winsys-wgl.c     |    1 +
 8 files changed, 92 insertions(+), 3 deletions(-)
---
diff --git a/cogl/cogl-renderer-private.h b/cogl/cogl-renderer-private.h
index 9300f9f..fa07b32 100644
--- a/cogl/cogl-renderer-private.h
+++ b/cogl/cogl-renderer-private.h
@@ -40,6 +40,7 @@ struct _CoglRenderer
   CoglObject _parent;
   gboolean connected;
   const CoglWinsysVtable *winsys_vtable;
+  CoglWinsysID winsys_id_override;
 #ifdef COGL_HAS_XLIB_SUPPORT
   Display *foreign_xdpy;
 #endif
diff --git a/cogl/cogl-renderer.c b/cogl/cogl-renderer.c
index 06679d4..d89065d 100644
--- a/cogl/cogl-renderer.c
+++ b/cogl/cogl-renderer.c
@@ -172,7 +172,6 @@ gboolean
 cogl_renderer_connect (CoglRenderer *renderer, GError **error)
 {
   int i;
-  char *renderer_name = getenv ("COGL_RENDERER");
   GString *error_message;
 
   if (renderer->connected)
@@ -184,8 +183,17 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
       const CoglWinsysVtable *winsys = _cogl_winsys_vtable_getters[i]();
       GError *tmp_error = NULL;
 
-      if (renderer_name && strcmp (winsys->name, renderer_name) != 0)
-        continue;
+      if (renderer->winsys_id_override != COGL_WINSYS_ID_ANY)
+        {
+          if (renderer->winsys_id_override != winsys->id)
+            continue;
+        }
+      else
+        {
+          char *user_choice = getenv ("COGL_RENDERER");
+          if (user_choice && strcmp (winsys->name, user_choice) != 0)
+            continue;
+        }
 
       /* At least temporarily we will associate this winsys with
        * the renderer in-case ->renderer_connect calls API that
@@ -282,3 +290,20 @@ cogl_renderer_remove_native_filter (CoglRenderer *renderer,
         }
     }
 }
+
+void
+cogl_renderer_set_winsys_id (CoglRenderer *renderer,
+                             CoglWinsysID winsys_id)
+{
+  g_return_if_fail (!renderer->connected);
+
+  renderer->winsys_id_override = winsys_id;
+}
+
+CoglWinsysID
+cogl_renderer_get_winsys_id (CoglRenderer *renderer)
+{
+  g_return_val_if_fail (renderer->connected, 0);
+
+  return renderer->winsys_vtable->id;
+}
diff --git a/cogl/cogl-renderer.h b/cogl/cogl-renderer.h
index 38b7fe9..2c6d9d0 100644
--- a/cogl/cogl-renderer.h
+++ b/cogl/cogl-renderer.h
@@ -67,6 +67,61 @@ cogl_renderer_new (void);
 
 /* optional configuration APIs */
 
+/**
+ * CoglWinsysID:
+ * @COGL_WINSYS_ID_ANY: Implies no preference for which backend is used
+ * @COGL_WINSYS_ID_STUB: Use the no-op stub backend
+ * @COGL_WINSYS_ID_GLX: Use the GLX window system binding API
+ * @COGL_WINSYS_ID_EGL: Use the Khronos EGL window system binding API
+ * @COGL_WINSYS_ID_WGL: Use the Microsoft Windows WGL binding API
+ *
+ * Identifies specific window system backends that Cogl supports.
+ *
+ * These can be used to query what backend Cogl is using or to try and
+ * explicitly select a backend to use.
+ */
+typedef enum
+{
+  COGL_WINSYS_ID_ANY,
+  COGL_WINSYS_ID_STUB,
+  COGL_WINSYS_ID_GLX,
+  COGL_WINSYS_ID_EGL,
+  COGL_WINSYS_ID_WGL
+} CoglWinsysID;
+
+/**
+ * cogl_renderer_set_winsys_id:
+ * @renderer: A #CoglRenderer
+ * @winsys_id: An ID of the winsys you explicitly want to use.
+ *
+ * This allows you to explicitly select a winsys backend to use instead
+ * of letting Cogl automatically select a backend.
+ *
+ * if you select an unsupported backend then cogl_renderer_connect()
+ * will fail and report an error.
+ *
+ * This may only be called on an un-connected #CoglRenderer.
+ */
+#define cogl_renderer_set_winsys_id cogl_renderer_set_winsys_id_EXP
+void
+cogl_renderer_set_winsys_id (CoglRenderer *renderer,
+                             CoglWinsysID winsys_id);
+
+/**
+ * cogl_renderer_get_winsys_id:
+ * @renderer: A #CoglRenderer
+ *
+ * Queries which window system backend Cogl has chosen to use.
+ *
+ * This may only be called on a connected #CoglRenderer.
+ *
+ * Returns: The #CoglWinsysID corresponding to the chosen window
+ *          system backend.
+ */
+#define cogl_renderer_get_winsys_id cogl_renderer_get_winsys_id_EXP
+CoglWinsysID
+cogl_renderer_get_winsys_id (CoglRenderer *renderer);
+
 #define cogl_renderer_handle_native_event cogl_renderer_handle_native_event_EXP
 /*
  * cogl_renderer_handle_native_event:
diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
index 1ae78e3..69da529 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -1646,6 +1646,7 @@ _cogl_winsys_texture_pixmap_x11_get_texture (CoglTexturePixmapX11 *tex_pixmap)
 
 static CoglWinsysVtable _cogl_winsys_vtable =
   {
+    .id = COGL_WINSYS_ID_EGL,
     .name = "EGL",
     .get_proc_address = _cogl_winsys_get_proc_address,
     .renderer_connect = _cogl_winsys_renderer_connect,
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index f5baa79..77e7ebe 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -1895,6 +1895,7 @@ _cogl_winsys_texture_pixmap_x11_get_texture (CoglTexturePixmapX11 *tex_pixmap)
 
 static CoglWinsysVtable _cogl_winsys_vtable =
   {
+    .id = COGL_WINSYS_ID_GLX,
     .name = "GLX",
     .get_proc_address = _cogl_winsys_get_proc_address,
     .renderer_connect = _cogl_winsys_renderer_connect,
diff --git a/cogl/winsys/cogl-winsys-private.h b/cogl/winsys/cogl-winsys-private.h
index a8aaf90..5822479 100644
--- a/cogl/winsys/cogl-winsys-private.h
+++ b/cogl/winsys/cogl-winsys-private.h
@@ -24,6 +24,8 @@
 #ifndef __COGL_WINSYS_PRIVATE_H
 #define __COGL_WINSYS_PRIVATE_H
 
+#include "cogl-renderer.h"
+
 #include "cogl-framebuffer-private.h"
 #ifdef COGL_HAS_XLIB_SUPPORT
 #include "cogl-texture-pixmap-x11-private.h"
@@ -54,6 +56,8 @@ typedef enum
 
 typedef struct _CoglWinsysVtable
 {
+  CoglWinsysID id;
+
   const char *name;
 
   /* Required functions */
diff --git a/cogl/winsys/cogl-winsys-stub.c b/cogl/winsys/cogl-winsys-stub.c
index ef22e13..5db9918 100644
--- a/cogl/winsys/cogl-winsys-stub.c
+++ b/cogl/winsys/cogl-winsys-stub.c
@@ -134,6 +134,7 @@ _cogl_winsys_onscreen_set_visibility (CoglOnscreen *onscreen,
 
 static CoglWinsysVtable _cogl_winsys_vtable =
   {
+    .id = COGL_WINSYS_ID_STUB,
     .name = "STUB",
     .get_proc_address = _cogl_winsys_get_proc_address,
     .renderer_connect = _cogl_winsys_renderer_connect,
diff --git a/cogl/winsys/cogl-winsys-wgl.c b/cogl/winsys/cogl-winsys-wgl.c
index 9eb9e87..a20cd02 100644
--- a/cogl/winsys/cogl-winsys-wgl.c
+++ b/cogl/winsys/cogl-winsys-wgl.c
@@ -827,6 +827,7 @@ _cogl_winsys_wgl_get_vtable (void)
     {
       memset (&vtable, 0, sizeof (vtable));
 
+      vtable.id = COGL_WINSYS_ID_EGL;
       vtable.name = "WGL";
       vtable.get_proc_address = _cogl_winsys_get_proc_address;
       vtable.renderer_connect = _cogl_winsys_renderer_connect;



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