[mutter] cogl: Add API for setting custom winsys



commit d6cde4b04398952f418e402b2c8a2d9c3b826f5d
Author: Jonas Ådahl <jadahl gmail com>
Date:   Thu May 5 15:20:07 2016 +0800

    cogl: Add API for setting custom winsys
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768976

 cogl/cogl/cogl-mutter.h           |   42 +++++++++++++++++++++++++++++++++
 cogl/cogl/cogl-renderer-private.h |    2 +
 cogl/cogl/cogl-renderer.c         |   46 +++++++++++++++++++++++++++++++++++-
 cogl/cogl/cogl.h                  |    4 +++
 4 files changed, 92 insertions(+), 2 deletions(-)
---
diff --git a/cogl/cogl/cogl-mutter.h b/cogl/cogl/cogl-mutter.h
new file mode 100644
index 0000000..21ef074
--- /dev/null
+++ b/cogl/cogl/cogl-mutter.h
@@ -0,0 +1,42 @@
+/*
+ * Cogl
+ *
+ * A Low Level GPU Graphics and Utilities API
+ *
+ * Copyright (C) 2016 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ *
+ */
+
+#ifndef __COGL_MUTTER_H___
+#define __COGL_MUTTER_H___
+
+#include <cogl/winsys/cogl-winsys-egl-kms-private.h>
+#include <cogl/winsys/cogl-winsys-private.h>
+
+typedef const CoglWinsysVtable *(*CoglWinsysVtableGetter) (void);
+
+void cogl_renderer_set_custom_winsys (CoglRenderer          *renderer,
+                                      CoglWinsysVtableGetter winsys_vtable_getter);
+
+#endif /* __COGL_MUTTER_H___ */
diff --git a/cogl/cogl/cogl-renderer-private.h b/cogl/cogl/cogl-renderer-private.h
index 06aa213..81d956f 100644
--- a/cogl/cogl/cogl-renderer-private.h
+++ b/cogl/cogl/cogl-renderer-private.h
@@ -39,6 +39,7 @@
 #include "cogl-texture-driver.h"
 #include "cogl-context.h"
 #include "cogl-closure-list-private.h"
+#include "cogl-mutter.h"
 
 #ifdef COGL_HAS_XLIB_SUPPORT
 #include <X11/Xlib.h>
@@ -52,6 +53,7 @@ struct _CoglRenderer
   const CoglDriverVtable *driver_vtable;
   const CoglTextureDriver *texture_driver;
   const CoglWinsysVtable *winsys_vtable;
+  CoglWinsysVtableGetter custom_winsys_vtable_getter;
   CoglWinsysID winsys_id_override;
   GList *constraints;
 
diff --git a/cogl/cogl/cogl-renderer.c b/cogl/cogl/cogl-renderer.c
index 498a00f..da2f411 100644
--- a/cogl/cogl/cogl-renderer.c
+++ b/cogl/cogl/cogl-renderer.c
@@ -41,6 +41,7 @@
 #include "cogl-object.h"
 #include "cogl-context-private.h"
 #include "cogl-util-gl-private.h"
+#include "cogl-mutter.h"
 
 #include "cogl-renderer.h"
 #include "cogl-renderer-private.h"
@@ -65,8 +66,6 @@
 #include "cogl-xlib-renderer.h"
 #endif
 
-typedef const CoglWinsysVtable *(*CoglWinsysVtableGetter) (void);
-
 #ifdef HAVE_COGL_GL
 extern const CoglTextureDriver _cogl_texture_driver_gl;
 extern const CoglDriverVtable _cogl_driver_gl;
@@ -564,6 +563,46 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer,
 
 /* Final connection API */
 
+void
+cogl_renderer_set_custom_winsys (CoglRenderer          *renderer,
+                                 CoglWinsysVtableGetter winsys_vtable_getter)
+{
+  renderer->custom_winsys_vtable_getter = winsys_vtable_getter;
+}
+
+static CoglBool
+connect_custom_winsys (CoglRenderer *renderer,
+                       CoglError   **error)
+{
+  const CoglWinsysVtable *winsys = renderer->custom_winsys_vtable_getter();
+  CoglError *tmp_error = NULL;
+  GString *error_message;
+
+  renderer->winsys_vtable = winsys;
+
+  error_message = g_string_new ("");
+  if (!winsys->renderer_connect (renderer, &tmp_error))
+    {
+      g_string_append_c (error_message, '\n');
+      g_string_append (error_message, tmp_error->message);
+      cogl_error_free (tmp_error);
+    }
+  else
+    {
+      renderer->connected = TRUE;
+      g_string_free (error_message, TRUE);
+      return TRUE;
+    }
+
+  renderer->winsys_vtable = NULL;
+  _cogl_set_error (error, COGL_WINSYS_ERROR,
+                   COGL_WINSYS_ERROR_INIT,
+                   "Failed to connected to any renderer: %s",
+                   error_message->str);
+  g_string_free (error_message, TRUE);
+  return FALSE;
+}
+
 CoglBool
 cogl_renderer_connect (CoglRenderer *renderer, CoglError **error)
 {
@@ -580,6 +619,9 @@ cogl_renderer_connect (CoglRenderer *renderer, CoglError **error)
   if (!_cogl_renderer_choose_driver (renderer, error))
     return FALSE;
 
+  if (renderer->custom_winsys_vtable_getter)
+    return connect_custom_winsys (renderer, error);
+
   error_message = g_string_new ("");
   for (i = 0; i < G_N_ELEMENTS (_cogl_winsys_vtable_getters); i++)
     {
diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h
index 7fa3921..778fdda 100644
--- a/cogl/cogl/cogl.h
+++ b/cogl/cogl/cogl.h
@@ -96,6 +96,10 @@
 #include <cogl/deprecated/cogl-framebuffer-deprecated.h>
 #include <cogl/deprecated/cogl-auto-texture.h>
 
+#ifdef COGL_ENABLE_MUTTER_API
+#include <cogl/cogl-mutter.h>
+#endif
+
 /*
  * 2.0 api that's compatible with the 1.x api...
  */


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