[cogl] renderer: Adds api to add/remove selection constraints



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

    renderer: Adds api to add/remove selection constraints
    
    This allows applications to specify certain constraints that feed into
    the process of selecting a CoglRenderer backend. 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              |   64 +++++++++++++++++++++++++++++++++++++
 cogl/cogl-texture-2d.c            |    8 ++--
 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, 109 insertions(+), 23 deletions(-)
---
diff --git a/cogl/cogl-renderer-private.h b/cogl/cogl-renderer-private.h
index 47c0667..bdc505d 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 *constraints;
+
 #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..281780d 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 constraints_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->constraints; l; l = l->next)
+        {
+          CoglRendererConstraint constraint = GPOINTER_TO_UINT (l->data);
+          if (!(winsys->constraints & constraint))
+            {
+              constraints_failed = TRUE;
+              break;
+            }
+        }
+      if (constraints_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_contraint (CoglRenderer *renderer,
+                             CoglRendererConstraint constraint)
+{
+  g_return_if_fail (!renderer->connected);
+  renderer->constraints = g_list_prepend (renderer->constraints,
+                                          GUINT_TO_POINTER (constraint));
+}
+
+void
+cogl_renderer_remove_constraint (CoglRenderer *renderer,
+                                 CoglRendererConstraint constraint)
+{
+  g_return_if_fail (!renderer->connected);
+  renderer->constraints = g_list_remove (renderer->constraints,
+                                         GUINT_TO_POINTER (constraint));
+}
+
diff --git a/cogl/cogl-renderer.h b/cogl/cogl-renderer.h
index 94d4de9..e846a2b 100644
--- a/cogl/cogl-renderer.h
+++ b/cogl/cogl-renderer.h
@@ -155,6 +155,70 @@ cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
 gboolean
 cogl_renderer_connect (CoglRenderer *renderer, GError **error);
 
+/**
+ * CoglRendererConstraint:
+ * @COGL_RENDERER_CONSTRAINT_USES_X11: Require the renderer to be X11 based
+ * @COGL_RENDERER_CONSTRAINT_USES_XLIB: Require the renderer to be X11
+ *                                      based and use Xlib
+ * @COGL_RENDERER_CONSTRAINT_USES_EGL: Require the renderer to be EGL based
+ *
+ * These constraint flags are hard-coded features of the different renderer
+ * backends. 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 constraints
+ * they depend on to ensure maximum portability.
+ *
+ * Since: 1.10
+ * Stability: unstable
+ */
+typedef enum
+{
+  COGL_RENDERER_CONSTRAINT_USES_X11 = (1 << 0),
+  COGL_RENDERER_CONSTRAINT_USES_XLIB = (1 << 1),
+  COGL_RENDERER_CONSTRAINT_USES_EGL = (1 << 2)
+} CoglRendererConstraint;
+
+
+/**
+ * cogl_renderer_add_contraint:
+ * @renderer: An unconnected #CoglRenderer
+ * @constraint: A #CoglRendererConstraint to add
+ *
+ * This adds a renderer selection @constraint.
+ *
+ * Applications should ideally minimize how many of these constraints they
+ * depend on to ensure maximum portability.
+ *
+ * Since: 1.10
+ * Stability: unstable
+ */
+void
+cogl_renderer_add_contraint (CoglRenderer *renderer,
+                             CoglRendererConstraint constraint);
+
+/**
+ * cogl_renderer_remove_constraint:
+ * @renderer: An unconnected #CoglRenderer
+ * @constraint: A #CoglRendererConstraint to remove
+ *
+ * This removes a renderer selection @constraint.
+ *
+ * Applications should ideally minimize how many of these constraints they
+ * depend on to ensure maximum portability.
+ *
+ * Since: 1.10
+ * Stability: unstable
+ */
+void
+cogl_renderer_remove_constraint (CoglRenderer *renderer,
+                                 CoglRendererConstraint constraint);
+
 G_END_DECLS
 
 #endif /* __COGL_RENDERER_H__ */
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index 3350dc1..97e449c 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -460,8 +460,8 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
   CoglTexture2D *tex_2d;
   GLenum gl_error;
 
-  _COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->criteria &
-                            COGL_WINSYS_CRITERIA_USES_EGL,
+  _COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->constraints &
+                            COGL_RENDERER_CONSTRAINT_USES_EGL,
                             NULL);
 
   _COGL_RETURN_VAL_IF_FAIL (ctx->private_feature_flags &
@@ -541,8 +541,8 @@ cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
     {
       EGLImageKHR image;
 
-      _COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->criteria &
-                                COGL_WINSYS_CRITERIA_USES_EGL,
+      _COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->constraints &
+                                COGL_RENDERER_CONSTRAINT_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..55cbbc2 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.constraints |= (COGL_RENDERER_CONSTRAINT_USES_X11 |
+                             COGL_RENDERER_CONSTRAINT_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 e5618da..ce06288 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -640,7 +640,7 @@ _cogl_winsys_context_egl_get_egl_display (CoglContext *context)
 
 static CoglWinsysVtable _cogl_winsys_vtable =
   {
-    .criteria = COGL_WINSYS_CRITERIA_USES_EGL,
+    .constraints = COGL_RENDERER_CONSTRAINT_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 ccc746a..4510f33 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -2032,8 +2032,8 @@ static CoglWinsysVtable _cogl_winsys_vtable =
   {
     .id = COGL_WINSYS_ID_GLX,
     .name = "GLX",
-    .criteria = (COGL_WINSYS_CRITERIA_USES_X11 |
-                 COGL_WINSYS_CRITERIA_USES_XLIB),
+    .constraints = (COGL_RENDERER_CONSTRAINT_USES_X11 |
+                    COGL_RENDERER_CONSTRAINT_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 3c235ed..73fcc7b 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;
+  CoglRendererConstraint constraints;
 
   const char *name;
 



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