[cogl/wip/mir: 3/7] mir: add support for foreign surfaces



commit 1b9380ef3c89623907c1d6a4437957c5f4df4179
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Nov 17 16:08:59 2014 +0100

    mir: add support for foreign surfaces

 cogl/cogl-onscreen-private.h      |    4 +++
 cogl/cogl-onscreen.h              |   18 +++++++++++++++++
 cogl/winsys/cogl-winsys-egl-mir.c |   39 +++++++++++++++++++++++++++---------
 3 files changed, 51 insertions(+), 10 deletions(-)
---
diff --git a/cogl/cogl-onscreen-private.h b/cogl/cogl-onscreen-private.h
index b30aeb9..b2d7dcb 100644
--- a/cogl/cogl-onscreen-private.h
+++ b/cogl/cogl-onscreen-private.h
@@ -77,6 +77,10 @@ struct _CoglOnscreen
   struct wl_surface *foreign_surface;
 #endif
 
+#ifdef COGL_HAS_EGL_PLATFORM_MIR_SUPPORT
+  struct MirSurface *foreign_surface;
+#endif
+
   CoglBool swap_throttled;
 
   CoglList frame_closures;
diff --git a/cogl/cogl-onscreen.h b/cogl/cogl-onscreen.h
index d9f36f7..990a716 100644
--- a/cogl/cogl-onscreen.h
+++ b/cogl/cogl-onscreen.h
@@ -270,6 +270,24 @@ cogl_wayland_onscreen_resize (CoglOnscreen *onscreen,
 #if defined (COGL_HAS_EGL_PLATFORM_MIR_SUPPORT)
 struct MirSurface *
 cogl_mir_onscreen_get_surface (CoglOnscreen *onscreen);
+
+/**
+ * cogl_mir_onscreen_set_foreign_surface:
+ * @onscreen: An unallocated framebuffer.
+ * @surface A Mir surface to associate with the @onscreen.
+ *
+ * Allows you to explicitly notify Cogl of an existing Mir surface to use,
+ * which prevents Cogl from allocating a surface for the @onscreen.
+ * An allocated surface will not be destroyed when the @onscreen is freed.
+ *
+ * This function must be called before @onscreen is allocated.
+ *
+ * Since: 1.18
+ * Stability: unstable
+ */
+void
+cogl_mir_onscreen_set_foreign_surface (CoglOnscreen *onscreen,
+                                       struct MirSurface *surface);
 #endif /* COGL_HAS_EGL_PLATFORM_MIR_SUPPORT */
 
 /**
diff --git a/cogl/winsys/cogl-winsys-egl-mir.c b/cogl/winsys/cogl-winsys-egl-mir.c
index 7ae05d9..c48e102 100644
--- a/cogl/winsys/cogl-winsys-egl-mir.c
+++ b/cogl/winsys/cogl-winsys-egl-mir.c
@@ -317,15 +317,21 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
   mir_onscreen = g_slice_new0 (CoglOnscreenMir);
   egl_onscreen->platform = mir_onscreen;
 
-  surfaceparm.name = "CoglSurface";
-  surfaceparm.width = cogl_framebuffer_get_width (framebuffer);
-  surfaceparm.height = cogl_framebuffer_get_height (framebuffer);
-  surfaceparm.pixel_format = _mir_connection_get_valid_format (mir_renderer->mir_connection);
-  surfaceparm.buffer_usage = mir_buffer_usage_hardware;
-  surfaceparm.output_id = mir_display_output_id_invalid;
-
-  mir_onscreen->mir_surface =
-    mir_connection_create_surface_sync (mir_renderer->mir_connection, &surfaceparm);
+  if (mir_surface_is_valid (onscreen->foreign_surface))
+    {
+      mir_onscreen->mir_surface = onscreen->foreign_surface;
+    }
+  else
+    {
+      surfaceparm.name = "CoglSurface";
+      surfaceparm.width = cogl_framebuffer_get_width (framebuffer);
+      surfaceparm.height = cogl_framebuffer_get_height (framebuffer);
+      surfaceparm.pixel_format = _mir_connection_get_valid_format (mir_renderer->mir_connection);
+      surfaceparm.buffer_usage = mir_buffer_usage_hardware;
+      surfaceparm.output_id = mir_display_output_id_invalid;
+      mir_onscreen->mir_surface =
+        mir_connection_create_surface_sync (mir_renderer->mir_connection, &surfaceparm);
+    }
 
   mir_onscreen->last_state = mir_surface_get_state (mir_onscreen->mir_surface);
 
@@ -362,7 +368,7 @@ _cogl_winsys_egl_onscreen_deinit (CoglOnscreen *onscreen)
   CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
   CoglOnscreenMir *mir_onscreen = egl_onscreen->platform;
 
-  if (mir_onscreen->mir_surface)
+  if (mir_onscreen->mir_surface && !onscreen->foreign_surface)
     {
       mir_surface_release (mir_onscreen->mir_surface, NULL, NULL);
       mir_onscreen->mir_surface = NULL;
@@ -433,6 +439,19 @@ cogl_mir_renderer_get_connection (CoglRenderer *renderer)
   return NULL;
 }
 
+void
+cogl_mir_onscreen_set_foreign_surface (CoglOnscreen *onscreen,
+                                       MirSurface *surface)
+{
+  CoglFramebuffer *fb;
+  _COGL_RETURN_IF_FAIL (mir_surface_is_valid (surface));
+
+  fb = COGL_FRAMEBUFFER (onscreen);
+  _COGL_RETURN_IF_FAIL (!fb->allocated);
+
+  onscreen->foreign_surface = surface;
+}
+
 MirSurface *
 cogl_mir_onscreen_get_surface (CoglOnscreen *onscreen)
 {


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