[cogl/wip/mir: 2/7] mir: add support for foreign display



commit a3ae538c4593ff7878f99a9169e27f1c5ff9a3ee
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Nov 17 15:59:29 2014 +0100

    mir: add support for foreign display

 cogl/Makefile.am                  |    2 +
 cogl/cogl-mir-renderer.h          |   83 +++++++++++++++++++++++++++++++++++++
 cogl/cogl-renderer-private.h      |    8 ++++
 cogl/winsys/cogl-winsys-egl-mir.c |   56 ++++++++++++++++++++++---
 4 files changed, 142 insertions(+), 7 deletions(-)
---
diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index 3d41843..c36985b 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -504,6 +504,8 @@ cogl_sources_c += \
        $(srcdir)/winsys/cogl-winsys-egl-android-private.h
 endif
 if SUPPORT_EGL_PLATFORM_MIR
+cogl_experimental_h += \
+       $(srcdir)/cogl-mir-renderer.h
 cogl_sources_c += \
        $(srcdir)/winsys/cogl-winsys-egl-mir.c \
        $(srcdir)/winsys/cogl-winsys-egl-mir-private.h
diff --git a/cogl/cogl-mir-renderer.h b/cogl/cogl-mir-renderer.h
new file mode 100644
index 0000000..d03fbea
--- /dev/null
+++ b/cogl/cogl-mir-renderer.h
@@ -0,0 +1,83 @@
+/*
+ * Cogl
+ *
+ * A Low Level GPU Graphics and Utilities API
+ *
+ * Copyright (C) 2014 Canonical Ltd.
+ *
+ * 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.
+ */
+
+#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
+#error "Only <cogl/cogl.h> can be included directly."
+#endif
+
+#ifndef __COGL_MIR_RENDERER_H__
+#define __COGL_MIR_RENDERER_H__
+
+#include <cogl/cogl-types.h>
+#include <cogl/cogl-renderer.h>
+
+#include <mir_toolkit/mir_client_library.h>
+
+COGL_BEGIN_DECLS
+
+/**
+ * cogl_mir_renderer_set_foreign_connection:
+ * @renderer: A #CoglRenderer
+ * @connection: A Mir connection
+ *
+ * Allows you to explicitly control what Mir connection you want Cogl
+ * to work with instead of leaving Cogl to automatically connect to a
+ * mir server.
+ *
+ * Since: 1.8
+ * Stability: unstable
+ */
+void
+cogl_mir_renderer_set_foreign_connection (CoglRenderer *renderer,
+                                          MirConnection *connection);
+
+/**
+ * cogl_mir_renderer_get_connection:
+ * @renderer: A #CoglRenderer
+ *
+ * Retrieves the Mir Connection that Cogl is using. If a foreign
+ * connection has been specified using
+ * cogl_mir_renderer_set_foreign_connection() then that connection will
+ * be returned. If no foreign connection has been specified then the
+ * display that Cogl creates internally will be returned unless the
+ * renderer has not yet been connected (either implicitly or explicitly by
+ * calling cogl_renderer_connect()) in which case %NULL is returned.
+ *
+ * Returns: The mir connection currently associated with @renderer,
+ *          or %NULL if the renderer hasn't yet been connected and no
+ *          foreign connection has been specified.
+ *
+ * Since: 1.8
+ * Stability: unstable
+ */
+MirConnection *
+cogl_mir_renderer_get_connection (CoglRenderer *renderer);
+
+COGL_END_DECLS
+
+#endif /* __COGL_MIR_RENDERER_H__ */
diff --git a/cogl/cogl-renderer-private.h b/cogl/cogl-renderer-private.h
index 3871d91..0f309e6 100644
--- a/cogl/cogl-renderer-private.h
+++ b/cogl/cogl-renderer-private.h
@@ -48,6 +48,10 @@
 #include <wayland-client.h>
 #endif
 
+#if defined (COGL_HAS_EGL_PLATFORM_MIR_SUPPORT)
+#include <mir_toolkit/mir_client_library.h>
+#endif
+
 struct _CoglRenderer
 {
   CoglObject _parent;
@@ -88,6 +92,10 @@ struct _CoglRenderer
   CoglBool wayland_enable_event_dispatch;
 #endif
 
+#if defined (COGL_HAS_EGL_PLATFORM_MIR_SUPPORT)
+  MirConnection *foreign_mir_connection;
+#endif
+
 #if defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT)
   int kms_fd;
 #endif
diff --git a/cogl/winsys/cogl-winsys-egl-mir.c b/cogl/winsys/cogl-winsys-egl-mir.c
index 01f0f71..7ae05d9 100644
--- a/cogl/winsys/cogl-winsys-egl-mir.c
+++ b/cogl/winsys/cogl-winsys-egl-mir.c
@@ -42,6 +42,7 @@
 #include "cogl-winsys-egl-private.h"
 #include "cogl-renderer-private.h"
 #include "cogl-onscreen-private.h"
+#include "cogl-mir-renderer.h"
 #include "cogl-error-private.h"
 
 static const CoglWinsysEGLVtable _cogl_winsys_egl_vtable;
@@ -103,7 +104,10 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
     eglTerminate (egl_renderer->edpy);
 
   if (mir_connection_is_valid (mir_renderer->mir_connection))
-    mir_connection_release (mir_renderer->mir_connection);
+    {
+      if (!mir_connection_is_valid (renderer->foreign_mir_connection))
+        mir_connection_release (mir_renderer->mir_connection);
+    }
 
   g_slice_free (CoglRendererMir, egl_renderer->platform);
   g_slice_free (CoglRendererEGL, egl_renderer);
@@ -124,13 +128,20 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
 
   egl_renderer->platform_vtable = &_cogl_winsys_egl_vtable;
 
-  mir_renderer->mir_connection = mir_connect_sync (NULL, __PRETTY_FUNCTION__);
-  if (!mir_connection_is_valid (mir_renderer->mir_connection))
+  if (mir_connection_is_valid (renderer->foreign_mir_connection))
     {
-      _cogl_set_error (error, COGL_WINSYS_ERROR,
-                       COGL_WINSYS_ERROR_INIT,
-                       "Failed to connect mir display");
-      goto error;
+      mir_renderer->mir_connection = renderer->foreign_mir_connection;
+    }
+  else
+    {
+      mir_renderer->mir_connection = mir_connect_sync (NULL, __PRETTY_FUNCTION__);
+      if (!mir_connection_is_valid (mir_renderer->mir_connection))
+        {
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
+                           COGL_WINSYS_ERROR_INIT,
+                           "Failed to connect mir display");
+          goto error;
+        }
     }
 
   mir_native_dpy =
@@ -391,6 +402,37 @@ _cogl_winsys_onscreen_set_visibility (CoglOnscreen *onscreen,
   mir_surface_set_state (mir_onscreen->mir_surface, new_state);
 }
 
+void
+cogl_mir_renderer_set_foreign_connection (CoglRenderer *renderer,
+                                              MirConnection *connection)
+{
+  _COGL_RETURN_IF_FAIL (cogl_is_renderer (renderer));
+  _COGL_RETURN_IF_FAIL (mir_connection_is_valid (connection));
+
+  /* NB: Renderers are considered immutable once connected */
+  _COGL_RETURN_IF_FAIL (!renderer->connected);
+
+  renderer->foreign_mir_connection = connection;
+}
+
+MirConnection *
+cogl_mir_renderer_get_connection (CoglRenderer *renderer)
+{
+  _COGL_RETURN_VAL_IF_FAIL (cogl_is_renderer (renderer), NULL);
+
+  if (mir_connection_is_valid (renderer->foreign_mir_connection))
+    return renderer->foreign_mir_connection;
+
+  if (renderer->connected)
+    {
+      CoglRendererEGL *egl_renderer = renderer->winsys;
+      CoglRendererMir *mir_renderer = egl_renderer->platform;
+      return mir_renderer->mir_connection;
+    }
+
+  return NULL;
+}
+
 MirSurface *
 cogl_mir_onscreen_get_surface (CoglOnscreen *onscreen)
 {


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