[cogl/fosdem-2012: 9/20] renderer: Adds api to add/remove selection criteria



commit 26ac478e0735de2f4b470245e5576694a28e2188
Author: Robert Bragg <robert linux intel com>
Date:   Fri Jan 13 16:48:26 2012 +0000

    renderer: Adds api to add/remove selection criteria
    
    This allows applications to specify certain criteria that feed into the
    process of selecting a CoglRenderer backend on platforms. For example
    applications might depend on x11 for handling input and so they require
    a backend that's also based on x11.

 cogl/cogl-renderer-private.h      |    2 +
 cogl/cogl-renderer.c              |   33 ++++++++++++++++++
 cogl/cogl-renderer.h              |   67 +++++++++++++++++++++++++++++++++++++
 cogl/cogl-texture-2d.c            |    4 +-
 cogl/winsys/cogl-winsys-egl-x11.c |    4 +-
 cogl/winsys/cogl-winsys-egl.c     |    2 +-
 cogl/winsys/cogl-winsys-glx.c     |    4 +-
 cogl/winsys/cogl-winsys-private.h |   15 +--------
 8 files changed, 110 insertions(+), 21 deletions(-)
---
diff --git a/cogl/cogl-renderer-private.h b/cogl/cogl-renderer-private.h
index 47c0667..da8eba7 100644
--- a/cogl/cogl-renderer-private.h
+++ b/cogl/cogl-renderer-private.h
@@ -44,6 +44,8 @@ struct _CoglRenderer
   gboolean connected;
   const CoglWinsysVtable *winsys_vtable;
   CoglWinsysID winsys_id_override;
+  GList *criteria;
+
 #ifdef COGL_HAS_XLIB_SUPPORT
   Display *foreign_xdpy;
   gboolean xlib_enable_event_retrieval;
diff --git a/cogl/cogl-renderer.c b/cogl/cogl-renderer.c
index 1a01b59..2e6dcf1 100644
--- a/cogl/cogl-renderer.c
+++ b/cogl/cogl-renderer.c
@@ -321,6 +321,8 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
     {
       const CoglWinsysVtable *winsys = _cogl_winsys_vtable_getters[i]();
       GError *tmp_error = NULL;
+      GList *l;
+      gboolean criteria_failed = FALSE;
 
       if (renderer->winsys_id_override != COGL_WINSYS_ID_ANY)
         {
@@ -337,6 +339,18 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
             continue;
         }
 
+      for (l = renderer->criteria; l; l = l->next)
+        {
+          CoglRendererCriteria criteria = GPOINTER_TO_UINT (l->data);
+          if (!(winsys->criteria & criteria))
+            {
+              criteria_failed = TRUE;
+              break;
+            }
+        }
+      if (criteria_failed)
+        continue;
+
       /* At least temporarily we will associate this winsys with
        * the renderer in-case ->renderer_connect calls API that
        * wants to query the current winsys... */
@@ -473,3 +487,22 @@ cogl_renderer_get_n_fragment_texture_units (CoglRenderer *renderer)
 
   return n;
 }
+
+void
+cogl_renderer_add_criteria (CoglRenderer *renderer,
+                            CoglRendererCriteria criteria)
+{
+  g_return_if_fail (!renderer->connected);
+  renderer->criteria = g_list_prepend (renderer->criteria,
+                                       GUINT_TO_POINTER (criteria));
+}
+
+void
+cogl_renderer_remove_criteria (CoglRenderer *renderer,
+                               CoglRendererCriteria criteria)
+{
+  g_return_if_fail (!renderer->connected);
+  renderer->criteria = g_list_remove (renderer->criteria,
+                                      GUINT_TO_POINTER (criteria));
+}
+
diff --git a/cogl/cogl-renderer.h b/cogl/cogl-renderer.h
index 94d4de9..fd5d00a 100644
--- a/cogl/cogl-renderer.h
+++ b/cogl/cogl-renderer.h
@@ -155,6 +155,73 @@ cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
 gboolean
 cogl_renderer_connect (CoglRenderer *renderer, GError **error);
 
+/**
+ * CoglRendererCriteria:
+ * @COGL_RENDERER_CRITERIA_USES_X11: Require the renderer to be X11 based
+ * @COGL_RENDERER_CRITERIA_USES_XLIB: Require the renderer to be X11
+ *                                    based and use Xlib
+ * @COGL_RENDERER_CRITERIA_USES_EGL: Require the renderer to be EGL based
+ *
+ * These criteria flags are hard-coded features of the different
+ * renderer backends regardless. Sometimes a platform may support
+ * multiple rendering options which Cogl will usually choose from
+ * automatically. Some of these features are important to higher level
+ * applications and frameworks though, such as whether a renderer is
+ * X11 based because an application might only support X11 based input
+ * handling. An application might also need to ensure EGL is used
+ * internally too if they depend on access to an EGLDisplay for some
+ * purpose.
+ *
+ * Applications should ideally minimize how many of these criteria
+ * they depend on to ensure maximum portability.
+ *
+ * Since: 1.10
+ * Stability: unstable
+ */
+typedef enum
+{
+  COGL_RENDERER_CRITERIA_USES_X11 = (1 << 0),
+  COGL_RENDERER_CRITERIA_USES_XLIB = (1 << 1),
+  COGL_RENDERER_CRITERIA_USES_EGL = (1 << 2)
+} CoglRendererCriteria;
+
+
+/**
+ * cogl_renderer_add_criteria:
+ * @renderer: An unconnected #CoglRenderer
+ * @criteria: A #CoglRendererCriteria constraint to add
+ *
+ * This adds a renderer selection constraint according to the given
+ * @criteria.
+ *
+ * Applications should ideally minimize how many of these criteria
+ * they depend on to ensure maximum portability.
+ *
+ * Since: 1.10
+ * Stability: unstable
+ */
+void
+cogl_renderer_add_criteria (CoglRenderer *renderer,
+                            CoglRendererCriteria criteria);
+
+/**
+ * cogl_renderer_add_criteria:
+ * @renderer: An unconnected #CoglRenderer
+ * @criteria: A #CoglRendererCriteria constraint to remove
+ *
+ * This removes a renderer selection constraint according to the given
+ * @criteria.
+ *
+ * Applications should ideally minimize how many of these criteria
+ * they depend on to ensure maximum portability.
+ *
+ * Since: 1.10
+ * Stability: unstable
+ */
+void
+cogl_renderer_remove_criteria (CoglRenderer *renderer,
+                               CoglRendererCriteria criteria);
+
 G_END_DECLS
 
 #endif /* __COGL_RENDERER_H__ */
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index 4baacb2..a7a6623 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -461,7 +461,7 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
   GLenum gl_error;
 
   _COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->criteria &
-                            COGL_WINSYS_CRITERIA_USES_EGL,
+                            COGL_RENDERER_CRITERIA_USES_EGL,
                             NULL);
 
   _COGL_RETURN_VAL_IF_FAIL (ctx->private_feature_flags &
@@ -543,7 +543,7 @@ cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
       CoglTexture2D *tex;
 
       _COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->criteria &
-                                COGL_WINSYS_CRITERIA_USES_EGL,
+                                COGL_RENDERER_CRITERIA_USES_EGL,
                                 NULL);
       image = _cogl_egl_create_image (ctx,
                                       EGL_WAYLAND_BUFFER_WL,
diff --git a/cogl/winsys/cogl-winsys-egl-x11.c b/cogl/winsys/cogl-winsys-egl-x11.c
index e4fc6de..0e1f5d8 100644
--- a/cogl/winsys/cogl-winsys-egl-x11.c
+++ b/cogl/winsys/cogl-winsys-egl-x11.c
@@ -718,8 +718,8 @@ _cogl_winsys_egl_xlib_get_vtable (void)
 
       vtable.id = COGL_WINSYS_ID_EGL_XLIB;
       vtable.name = "EGL_XLIB";
-      vtable.criteria |= (COGL_WINSYS_CRITERIA_USES_X11 |
-                          COGL_WINSYS_CRITERIA_USES_XLIB);
+      vtable.criteria |= (COGL_RENDERER_CRITERIA_USES_X11 |
+                          COGL_RENDERER_CRITERIA_USES_XLIB);
 
       vtable.renderer_connect = _cogl_winsys_renderer_connect;
       vtable.renderer_disconnect = _cogl_winsys_renderer_disconnect;
diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
index 3f81c2b..023ed7e 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -635,7 +635,7 @@ _cogl_winsys_context_egl_get_egl_display (CoglContext *context)
 
 static CoglWinsysVtable _cogl_winsys_vtable =
   {
-    .criteria = COGL_WINSYS_CRITERIA_USES_EGL,
+    .criteria = COGL_RENDERER_CRITERIA_USES_EGL,
 
     /* This winsys is only used as a base for the EGL-platform
        winsys's so it does not have an ID or a name */
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 362f5ef..75e9f3c 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -1978,8 +1978,8 @@ static CoglWinsysVtable _cogl_winsys_vtable =
   {
     .id = COGL_WINSYS_ID_GLX,
     .name = "GLX",
-    .criteria = (COGL_WINSYS_CRITERIA_USES_X11 |
-                 COGL_WINSYS_CRITERIA_USES_XLIB),
+    .criteria = (COGL_RENDERER_CRITERIA_USES_X11 |
+                 COGL_RENDERER_CRITERIA_USES_XLIB),
 
     .renderer_get_proc_address = _cogl_winsys_renderer_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 871ad0a..8986e25 100644
--- a/cogl/winsys/cogl-winsys-private.h
+++ b/cogl/winsys/cogl-winsys-private.h
@@ -54,23 +54,10 @@ typedef enum
   COGL_WINSYS_RECTANGLE_STATE_ENABLE
 } CoglWinsysRectangleState;
 
-/* These criteria flags are hard-coded features of the winsys
-   regardless of the underlying driver or GPU. We might eventually
-   want to use these in a mechanism for the application to specify
-   criteria for the winsys instead of a specific winsys but for now
-   they are only used internally to assert that an EGL winsys is
-   selected */
-typedef enum
-{
-  COGL_WINSYS_CRITERIA_USES_X11 = (1 << 0),
-  COGL_WINSYS_CRITERIA_USES_XLIB = (1 << 1),
-  COGL_WINSYS_CRITERIA_USES_EGL = (1 << 2)
-} CoglWinsysCriteria;
-
 typedef struct _CoglWinsysVtable
 {
   CoglWinsysID id;
-  CoglWinsysCriteria criteria;
+  CoglRendererCriteria criteria;
 
   const char *name;
 



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