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



commit 7629db5a20cc7b527d777ab0dbfe82818e2dd0e8
Author: Robert Bragg <robert linux intel com>
Date:   Mon Mar 21 23:16:05 2011 +0000

    stash

 clutter/cogl/cogl/winsys/cogl-winsys-egl.c |  136 ++++++++++++++++++++++++----
 clutter/cogl/configure.ac                  |   19 +---
 2 files changed, 125 insertions(+), 30 deletions(-)
---
diff --git a/clutter/cogl/cogl/winsys/cogl-winsys-egl.c b/clutter/cogl/cogl/winsys/cogl-winsys-egl.c
index 2b8ad5d..f7d4a6b 100644
--- a/clutter/cogl/cogl/winsys/cogl-winsys-egl.c
+++ b/clutter/cogl/cogl/winsys/cogl-winsys-egl.c
@@ -43,6 +43,9 @@
 #endif
 #include "cogl-private.h"
 
+#include <wayland-client.h>
+#include <wayland-egl.h>
+
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -115,7 +118,7 @@ typedef struct _CoglDisplayEGL
   EGLContext egl_context;
 #if defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT)
   EGLSurface dummy_surface;
-#elif define (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
+#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
   struct wl_surface *wayland_surface;
   struct wl_egl_window *wayland_egl_native_window;
   EGLSurface dummy_surface;
@@ -138,11 +141,13 @@ typedef struct _CoglContextEGL
   EGLSurface current_surface;
 } CoglContextEGL;
 
+#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
 typedef struct _CoglOnscreenXlib
 {
   Window xwin;
   gboolean is_foreign_xwin;
 } CoglOnscreenXlib;
+#endif
 
 typedef struct _CoglOnscreenEGL
 {
@@ -151,8 +156,8 @@ typedef struct _CoglOnscreenEGL
 #endif
 
 #ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
-  struct wl_egl_window *native;
-  struct wl_surface *surface;
+  struct wl_egl_window *wayland_egl_native_window;
+  struct wl_surface *wayland_surface;
 #endif
 
   EGLSurface egl_surface;
@@ -292,6 +297,35 @@ display_handle_global (struct wl_display *display,
     *compositor = wl_compositor_create (display, id);
 }
 
+static int
+event_mask_update (uint32_t mask, void *data)
+{
+  uint32_t *mask_out = data;
+  *mask_out = mask;
+  return 0;
+}
+
+#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
+static void
+sync_callback(void *data)
+{
+   int *done = data;
+
+   *done = 1;
+}
+
+static void
+force_roundtrip(struct wl_display *display)
+{
+   int done = 0;
+
+   wl_display_sync_callback(display, sync_callback, &done);
+   wl_display_iterate(display, WL_DISPLAY_WRITABLE);
+   while (!done)
+      wl_display_iterate(display, WL_DISPLAY_READABLE);
+}
+#endif
+
 static gboolean
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
                                GError **error)
@@ -305,6 +339,9 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
   gdl_ret_t rc = GDL_SUCCESS;
   gdl_display_info_t gdl_display_info;
 #endif
+#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
+  uint32_t mask;
+#endif
 
   renderer->winsys = g_slice_new0 (CoglRendererEGL);
 
@@ -325,17 +362,42 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
 #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 ,
+  if (!egl_renderer->wayland_display)
+    {
+      g_set_error (error, COGL_WINSYS_ERROR,
+                   COGL_WINSYS_ERROR_INIT,
+                   "Failed to connect wayland display");
+      goto error;
+    }
+
+  egl_renderer->wayland_egl_native_display =
+    wl_egl_display_create (egl_renderer->wayland_display);
+  egl_renderer->edpy =
+    eglGetDisplay ((EGLNativeDisplayType)
+                   egl_renderer->wayland_egl_native_display);
+
+  status = eglInitialize (egl_renderer->edpy,
+			  &egl_renderer->egl_version_major,
+			  &egl_renderer->egl_version_minor);
+
+  /*
+   * XXX: For some reason, this can only be done after calling eglInitialize
+   * otherwise eglInitialize fails in dri2_initialize_wayland because
+   * dri2_dpy->wl_dpy->fd doesn't get updated.
+   */
+  wl_display_add_global_listener (egl_renderer->wayland_display,
 				  display_handle_global,
                                   &egl_renderer->wayland_compositor);
 
+  force_roundtrip (egl_renderer->wayland_display);
+  g_assert (egl_renderer->wayland_compositor);
+
+#if 0
   /* Wait until we have been notified about the compositor object */
+  wl_display_get_fd (egl_renderer->wayland_display, event_mask_update, &mask);
   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);
+    wl_display_iterate (egl_renderer->wayland_display, mask);
+#endif
 
 #else
   egl_renderer->edpy = eglGetDisplay (EGL_DEFAULT_DISPLAY);
@@ -552,7 +614,7 @@ try_create_context (CoglDisplay *display,
   XSetWindowAttributes attrs;
 #endif
 #ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
-  struct wl_visual *wayland_visual
+  struct wl_visual *wayland_visual;
 #endif
   const char *error_message;
 
@@ -654,7 +716,8 @@ try_create_context (CoglDisplay *display,
       goto fail;
     }
 
-  wayland_visual = wl_display_get_premultiplied_argb_visual (display->display);
+  wayland_visual =
+    wl_display_get_premultiplied_argb_visual (egl_renderer->wayland_display);
   egl_display->wayland_egl_native_window =
     wl_egl_window_create (egl_renderer->wayland_egl_native_display,
                           egl_display->wayland_surface,
@@ -670,6 +733,7 @@ try_create_context (CoglDisplay *display,
   egl_display->dummy_surface =
     eglCreateWindowSurface (edpy,
                             egl_display->egl_config,
+                            (EGLNativeWindowType)
                             egl_display->wayland_egl_native_window,
                             NULL);
   if (egl_display->dummy_surface == EGL_NO_SURFACE)
@@ -934,8 +998,10 @@ _cogl_winsys_display_setup (CoglDisplay *display,
   egl_display = g_slice_new0 (CoglDisplayEGL);
   display->winsys = egl_display;
 
+#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
   if (!gdl_plane_init (display, error))
     goto error;
+#endif
 
   if (!create_context (display, error))
     goto error;
@@ -989,7 +1055,11 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
   CoglOnscreenXlib *xlib_onscreen;
   Window xwin;
 #endif
+#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
+  CoglRendererEGL *egl_renderer = display->renderer->winsys;
+#endif
   CoglOnscreenEGL *egl_onscreen;
+  struct wl_visual *wayland_visual;
 
   g_return_val_if_fail (egl_display->egl_context, FALSE);
 
@@ -1116,23 +1186,38 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
     wl_compositor_create_surface (egl_renderer->wayland_compositor);
   if (!egl_onscreen->wayland_surface)
     {
-
+      g_set_error (error, COGL_WINSYS_ERROR,
+                   COGL_WINSYS_ERROR_CREATE_ONSCREEN,
+                   "Error while creating wayland surface for CoglOnscreen");
+      return FALSE;
     }
+
   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,
+                          cogl_framebuffer_get_width (framebuffer),
+                          cogl_framebuffer_get_height (framebuffer),
                           wayland_visual);
+  if (!egl_onscreen->wayland_egl_native_window)
+    {
+      g_set_error (error, COGL_WINSYS_ERROR,
+                   COGL_WINSYS_ERROR_CREATE_ONSCREEN,
+                   "Error while creating wayland egl native window "
+                   "for CoglOnscreen");
+      return FALSE;
+    }
+
   egl_onscreen->egl_surface =
     eglCreateWindowSurface (egl_renderer->edpy,
                             egl_display->egl_config,
+                            (EGLNativeWindowType)
                             egl_onscreen->wayland_egl_native_window,
                             NULL);
 
-	wl_surface_map_toplevel(window->surface);
+  wl_surface_map_toplevel (egl_onscreen->wayland_surface);
+
 #elif defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT)
   if (egl_display->have_onscreen)
     {
@@ -1198,6 +1283,20 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
   if (_cogl_xlib_untrap_errors (&old_state) != Success)
     g_warning ("X Error while destroying X window");
 #endif
+
+#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
+  if (egl_onscreen->wayland_egl_native_window)
+    {
+      wl_egl_window_destroy (egl_onscreen->wayland_egl_native_window);
+      egl_onscreen->wayland_egl_native_window = NULL;
+    }
+
+  if (egl_onscreen->wayland_surface)
+    {
+      wl_surface_destroy (egl_onscreen->wayland_surface);
+      egl_onscreen->wayland_surface = NULL;
+    }
+#endif
 }
 
 static void
@@ -1220,7 +1319,8 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
 
   if (G_UNLIKELY (!onscreen))
     {
-#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
+#if defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT) || \
+    defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
       eglMakeCurrent (egl_renderer->edpy,
                       egl_display->dummy_surface,
                       egl_display->dummy_surface,
@@ -1286,12 +1386,14 @@ _cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
   eglSwapBuffers (egl_renderer->edpy, egl_onscreen->egl_surface);
 }
 
+#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
 static guint32
 _cogl_winsys_onscreen_x11_get_window_xid (CoglOnscreen *onscreen)
 {
   CoglOnscreenXlib *xlib_onscreen = onscreen->winsys;
   return xlib_onscreen->xwin;
 }
+#endif
 
 static unsigned int
 _cogl_winsys_onscreen_add_swap_buffers_callback (CoglOnscreen *onscreen,
@@ -1382,8 +1484,10 @@ static CoglWinsysVtable _cogl_winsys_vtable =
     .onscreen_swap_region = _cogl_winsys_onscreen_swap_region,
     .onscreen_update_swap_throttled =
       _cogl_winsys_onscreen_update_swap_throttled,
+#ifdef COGL_HAS_XLIB_SUPPORT
     .onscreen_x11_get_window_xid =
       _cogl_winsys_onscreen_x11_get_window_xid,
+#endif
     .onscreen_add_swap_buffers_callback =
       _cogl_winsys_onscreen_add_swap_buffers_callback,
     .onscreen_remove_swap_buffers_callback =
diff --git a/clutter/cogl/configure.ac b/clutter/cogl/configure.ac
index bb26be2..c5493cc 100644
--- a/clutter/cogl/configure.ac
+++ b/clutter/cogl/configure.ac
@@ -426,8 +426,7 @@ AS_IF([test "x$enable_null_egl_platform" = "xyes"],
         NEED_EGL=yes
         EGL_PLATFORMS="$EGL_PLATFORMS null"
 
-        AC_DEFINE([COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT], [1],
-                  [Cogl supports NULL EGL platform typedefs])
+        COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT"
       ])
 AM_CONDITIONAL(SUPPORT_EGL_PLATFORM_POWERVR_NULL,
                [test "x$enable_null_egl_platform" = "xyes"])
@@ -454,8 +453,7 @@ AS_IF([test "x$enable_gdl_egl_platform" == "xyes"],
               [AC_MSG_ERROR([libgdl.h not found])])
           ])
 
-        AC_DEFINE([COGL_HAS_EGL_PLATFORM_GDL_SUPPORT], [1],
-                  [Cogl supports GDL based EGL platform typedefs])
+        COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_EGL_PLATFORM_GDL_SUPPORT"
       ])
 AM_CONDITIONAL(SUPPORT_EGL_PLATFORM_GDL,
                [test "x$enable_gdl_egl_platform" = "xyes"])
@@ -479,9 +477,7 @@ AS_IF([test "x$enable_wayland_egl_platform" == "xyes"],
                          ],
                          [AC_MSG_ERROR([Unable to locate required wayland libraries])])
 
-        AC_DEFINE([COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT], [1],
-                  [Cogl supports Wayland based EGL platform typedefs])
-
+        COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT"
       ])
 AM_CONDITIONAL(SUPPORT_EGL_PLATFORM_WAYLAND,
                [test "x$enable_wayland_egl_platform" = "xyes"])
@@ -503,8 +499,7 @@ AS_IF([test "x$enable_xlib_egl_platform" = "xyes"],
         NEED_XLIB=yes
         EGL_PLATFORMS="$EGL_PLATFORMS xlib"
 
-        AC_DEFINE([COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT], [1],
-                  [Cogl supports Xlib based EGL platform typedefs])
+        COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT"
       ])
 AM_CONDITIONAL(SUPPORT_EGL_PLATFORM_POWERVR_X11,
                [test "x$enable_xlib_egl_platform" = "xyes"])
@@ -533,6 +528,7 @@ AS_IF([test "x$NEED_EGL" = "xyes" && test "x$EGL_CHECKED" != "xyes"],
           )
         SUPPORT_EGL=yes
         GL_WINSYS_APIS="$GL_WINSYS_APIS egl"
+        COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_EGL_SUPPORT"
       ])
 AM_CONDITIONAL(SUPPORT_EGL, [test "x$SUPPORT_EGL" = "xyes"])
 
@@ -548,11 +544,6 @@ AS_IF([test "x$NEED_XLIB" = "xyes"],
         SUPPORT_X11=yes
         SUPPORT_XLIB=yes
 
-        AC_DEFINE([COGL_HAS_X11_SUPPORT], [1],
-                  [Cogl supports the X11 window system])
-        AC_DEFINE([COGL_HAS_XLIB_SUPPORT], [1],
-                  [Cogl supports X11 using the Xlib API])
-
         COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_X11"
         COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_X11_SUPPORT"
         COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_XLIB"



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