[clutter/wip/cogl-winsys-egl: 36/37] wayland stash



commit a88e75db61a5916f8fc6a1929af3f88dd670df6b
Author: Robert Bragg <robert linux intel com>
Date:   Fri Mar 18 11:46:26 2011 +0000

    wayland stash

 clutter/cogl/Makefile.am                   |    2 +-
 clutter/cogl/cogl/winsys/cogl-winsys-egl.c |  157 +++++++++++++++++++++++++---
 2 files changed, 142 insertions(+), 17 deletions(-)
---
diff --git a/clutter/cogl/Makefile.am b/clutter/cogl/Makefile.am
index e695860..837cdbf 100644
--- a/clutter/cogl/Makefile.am
+++ b/clutter/cogl/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = cogl pango
+SUBDIRS = cogl pango examples
 
 if COGL_STANDALONE_BUILD
 SUBDIRS += po
diff --git a/clutter/cogl/cogl/winsys/cogl-winsys-egl.c b/clutter/cogl/cogl/winsys/cogl-winsys-egl.c
index 1d5a24c..2b8ad5d 100644
--- a/clutter/cogl/cogl/winsys/cogl-winsys-egl.c
+++ b/clutter/cogl/cogl/winsys/cogl-winsys-egl.c
@@ -76,6 +76,12 @@ typedef struct _CoglRendererEGL
   CoglRendererXlib _parent;
 #endif
 
+#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
+  struct wl_display *wayland_display;
+  struct wl_compositor *wayland_compositor;
+  struct wl_egl_display *wayland_egl_native_display;
+#endif
+
   EGLDisplay edpy;
 
   EGLint egl_version_major;
@@ -107,7 +113,11 @@ typedef struct _CoglDisplayEGL
 #endif
 
   EGLContext egl_context;
-#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
+#if defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT)
+  EGLSurface dummy_surface;
+#elif define (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
+  struct wl_surface *wayland_surface;
+  struct wl_egl_window *wayland_egl_native_window;
   EGLSurface dummy_surface;
 #elif defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \
       defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT)
@@ -136,7 +146,15 @@ typedef struct _CoglOnscreenXlib
 
 typedef struct _CoglOnscreenEGL
 {
+#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
   CoglOnscreenXlib _parent;
+#endif
+
+#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
+  struct wl_egl_window *native;
+  struct wl_surface *surface;
+#endif
+
   EGLSurface egl_surface;
 } CoglOnscreenEGL;
 
@@ -261,6 +279,19 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
   g_slice_free (CoglRendererEGL, egl_renderer);
 }
 
+static void
+display_handle_global (struct wl_display *display,
+                       uint32_t id,
+		       const char *interface,
+                       uint32_t version,
+                       void *data)
+{
+  struct wl_compositor **compositor = data;
+
+  if (strcmp (interface, "compositor") == 0)
+    *compositor = wl_compositor_create (display, id);
+}
+
 static gboolean
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
                                GError **error)
@@ -290,6 +321,22 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
   status = eglInitialize (egl_renderer->edpy,
                           &egl_renderer->egl_version_major,
                           &egl_renderer->egl_version_minor);
+
+#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
+
+  egl_renderer->wayland_display = wl_display_connect (NULL);
+  wl_display_add_global_listener (egl_renderer->wayland_display ,
+				  display_handle_global,
+                                  &egl_renderer->wayland_compositor);
+
+  /* Wait until we have been notified about the compositor object */
+  while (!egl_renderer->wayland_compositor)
+    wl_display_iterate (egl_renderer->wayland_display);
+
+  renderer->wayland_egl_native_display =
+    wl_egl_display_create (renderer->wayland_display);
+  egl_renderer->edpy = eglGetDisplay (renderer->wayland_egl_native_display);
+
 #else
   egl_renderer->edpy = eglGetDisplay (EGL_DEFAULT_DISPLAY);
 
@@ -361,7 +408,8 @@ update_winsys_features (CoglContext *context)
 
   COGL_NOTE (WINSYS, "  EGL Extensions: %s", egl_extensions);
 
-#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
+#if defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT) || \
+    defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
   context->feature_flags |= COGL_FEATURE_ONSCREEN_MULTIPLE;
   _cogl_bitmask_set (&context->winsys_features,
                      COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN,
@@ -503,6 +551,9 @@ try_create_context (CoglDisplay *display,
   XVisualInfo *xvisinfo;
   XSetWindowAttributes attrs;
 #endif
+#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
+  struct wl_visual *wayland_visual
+#endif
   const char *error_message;
 
   edpy = egl_renderer->edpy;
@@ -580,11 +631,7 @@ try_create_context (CoglDisplay *display,
 
   if (egl_display->dummy_surface == EGL_NO_SURFACE)
     {
-      /* FIXME: we shouldn't be calling g_set_error here we should
-       * just set error_message same goes for below. */
-      g_set_error (error, COGL_WINSYS_ERROR,
-                   COGL_WINSYS_ERROR_CREATE_CONTEXT,
-                   "Unable to create an EGL surface");
+      error_message = "Unable to create an EGL surface";
       goto fail;
     }
 
@@ -593,9 +640,50 @@ try_create_context (CoglDisplay *display,
                        egl_display->dummy_surface,
                        egl_display->egl_context))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
-                   COGL_WINSYS_ERROR_CREATE_CONTEXT,
-                   "Unable to eglMakeCurrent with dummy surface");
+      error_message = "Unable to eglMakeCurrent with dummy surface";
+      goto fail;
+    }
+
+#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
+
+  egl_display->wayland_surface =
+    wl_compositor_create_surface (egl_renderer->wayland_compositor);
+  if (!egl_display->wayland_surface)
+    {
+      error_message= "Failed to create a dummy wayland surface";
+      goto fail;
+    }
+
+  wayland_visual = wl_display_get_premultiplied_argb_visual (display->display);
+  egl_display->wayland_egl_native_window =
+    wl_egl_window_create (egl_renderer->wayland_egl_native_display,
+                          egl_display->wayland_surface,
+                          1,
+                          1,
+                          wayland_visual);
+  if (!egl_display->wayland_egl_native_window)
+    {
+      error_message= "Failed to create a dummy wayland native egl surface";
+      goto fail;
+    }
+
+  egl_display->dummy_surface =
+    eglCreateWindowSurface (edpy,
+                            egl_display->egl_config,
+                            egl_display->wayland_egl_native_window,
+                            NULL);
+  if (egl_display->dummy_surface == EGL_NO_SURFACE)
+    {
+      error_message= "Unable to eglMakeCurrent with dummy surface";
+      goto fail;
+    }
+
+  if (!eglMakeCurrent (edpy,
+                       egl_display->dummy_surface,
+                       egl_display->dummy_surface,
+                       egl_display->egl_context))
+    {
+      error_message = "Unable to eglMakeCurrent with dummy surface";
       goto fail;
     }
 
@@ -608,9 +696,7 @@ try_create_context (CoglDisplay *display,
                             NULL);
   if (egl_display->egl_surface == EGL_NO_SURFACE)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
-                   COGL_WINSYS_ERROR_CREATE_CONTEXT,
-                   "Unable to create EGL window surface");
+      error_message = "Unable to create EGL window surface";
       goto fail;
     }
 
@@ -619,9 +705,7 @@ try_create_context (CoglDisplay *display,
                        egl_display->egl_surface,
                        egl_display->egl_context))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
-                   COGL_WINSYS_ERROR_CREATE_CONTEXT,
-                   "Unable to eglMakeCurrent with egl surface");
+      error_message = "Unable to eglMakeCurrent with egl surface";
       goto fail;
     }
 
@@ -689,6 +773,24 @@ cleanup_context (CoglDisplay *display)
       XDestroyWindow (xlib_renderer->xdpy, xlib_display->dummy_xwin);
       xlib_display->dummy_xwin = None;
     }
+#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
+  if (egl_display->dummy_surface != EGL_NO_SURFACE)
+    {
+      eglDestroySurface (egl_renderer->edpy, egl_display->dummy_surface);
+      egl_display->dummy_surface = EGL_NO_SURFACE;
+    }
+
+  if (egl_display->wayland_egl_native_window)
+    {
+      wl_egl_window_destroy (egl_display->wayland_egl_native_window);
+      egl_display->wayland_egl_native_window = NULL;
+    }
+
+  if (egl_display->wayland_surface)
+    {
+      wl_surface_destroy (egl_display->wayland_surface);
+      egl_display->wayland_surface = NULL;
+    }
 #endif
 }
 
@@ -1008,6 +1110,29 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
                             egl_display->egl_config,
                             (NativeWindowType) xlib_onscreen->xwin,
                             NULL);
+#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
+
+  egl_onscreen->wayland_surface =
+    wl_compositor_create_surface (egl_renderer->wayland_compositor);
+  if (!egl_onscreen->wayland_surface)
+    {
+
+    }
+  wayland_visual =
+    wl_display_get_premultiplied_argb_visual (egl_renderer->wayland_display);
+  egl_onscreen->wayland_egl_native_window =
+    wl_egl_window_create (egl_renderer->wayland_egl_native_display,
+                          egl_onscreen->wayland_surface,
+                          width,
+                          height,
+                          wayland_visual);
+  egl_onscreen->egl_surface =
+    eglCreateWindowSurface (egl_renderer->edpy,
+                            egl_display->egl_config,
+                            egl_onscreen->wayland_egl_native_window,
+                            NULL);
+
+	wl_surface_map_toplevel(window->surface);
 #elif defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT)
   if (egl_display->have_onscreen)
     {



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