[clutter-gtk/wip/wayland: 2/2] stash: Start playing with using subsurfaces protocol to implement



commit 0a5733f59abeee698ebc3373a73106baeb4685be
Author: Rob Bradford <rob linux intel com>
Date:   Tue Jul 30 18:02:48 2013 +0100

    stash: Start playing with using subsurfaces protocol to implement

 clutter-gtk/Makefile.am         |    6 +-
 clutter-gtk/gtk-clutter-embed.c |   89 ++++++++++++++
 clutter-gtk/gtk-clutter-util.c  |    3 +-
 configure.ac                    |   12 ++
 protocol/subsurface.xml         |  244 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 352 insertions(+), 2 deletions(-)
---
diff --git a/clutter-gtk/Makefile.am b/clutter-gtk/Makefile.am
index 9a35919..ce9329d 100644
--- a/clutter-gtk/Makefile.am
+++ b/clutter-gtk/Makefile.am
@@ -21,7 +21,8 @@ AM_CFLAGS = $(MAINTAINER_CFLAGS) $(CLUTTER_GTK_DEPS_CFLAGS)
 
 lib_LTLIBRARIES = libclutter-gtk- CLUTTER_GTK_API_VERSION@.la
 
-source_c = \
+source_c = $(srcdir)/subsurface-protocol.c $(srcdir)/subsurface-client-protocol.h
+source_c += \
        $(srcdir)/gtk-clutter-actor.c           \
        $(srcdir)/gtk-clutter-embed.c           \
        $(srcdir)/gtk-clutter-offscreen.c       \
@@ -61,6 +62,9 @@ cluttergtkheaders_HEADERS = \
 
 EXTRA_DIST += gtk-clutter-version.h.in
 
+
+ wayland_scanner_rules@
+
 -include $(INTROSPECTION_MAKEFILE)
 
 INTROSPECTION_GIRS =
diff --git a/clutter-gtk/gtk-clutter-embed.c b/clutter-gtk/gtk-clutter-embed.c
index 14d99bf..5c7efae 100644
--- a/clutter-gtk/gtk-clutter-embed.c
+++ b/clutter-gtk/gtk-clutter-embed.c
@@ -66,6 +66,10 @@
 #include <clutter/win32/clutter-win32.h>
 #endif
 
+#if defined(CLUTTER_WINDOWING_WAYLAND)
+#include <clutter/wayland/clutter-wayland.h>
+#endif
+
 #if defined(GDK_WINDOWING_X11)
 #include <gdk/gdkx.h>
 #endif
@@ -74,6 +78,14 @@
 #include <gdk/gdkwin32.h>
 #endif
 
+#if defined(GDK_WINDOWING_WAYLAND)
+#include <gdk/gdkwayland.h>
+#endif
+
+#if defined(GDK_WINDOWING_WAYLAND) && defined(CLUTTER_WINDOWING_WAYLAND)
+#include "subsurface-client-protocol.h"
+#endif
+
 G_DEFINE_TYPE (GtkClutterEmbed, gtk_clutter_embed, GTK_TYPE_CONTAINER);
 
 #define GTK_CLUTTER_EMBED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_CLUTTER_TYPE_EMBED, 
GtkClutterEmbedPrivate))
@@ -92,6 +104,10 @@ struct _GtkClutterEmbedPrivate
 
   guint geometry_changed : 1;
   guint use_layout_size : 1;
+
+#if defined(GDK_WINDOWING_WAYLAND) && defined(CLUTTER_WINDOWING_WAYLAND)
+  struct wl_subcompositor *subcompositor;
+#endif
 };
 
 enum
@@ -363,6 +379,26 @@ gtk_clutter_embed_realize (GtkWidget *widget)
     }
 #endif
 
+#if defined(GDK_WINDOWING_WAYLAND) && defined(CLUTTER_WINDOWING_WAYLAND)
+  if (priv->subcompositor)
+    {
+      GdkDisplay *display;
+      struct wl_subsurface *subsurface;
+      struct wl_surface *clutter_surface, *gtk_surface;
+      struct wl_compositor *compositor;
+
+      display = gdk_display_get_default ();
+      compositor = gdk_wayland_display_get_wl_compositor (display);
+      clutter_surface = wl_compositor_create_surface (compositor);
+      gtk_surface = gdk_wayland_window_get_wl_surface (gdk_window_get_toplevel(window));
+      clutter_wayland_stage_set_wl_surface (CLUTTER_STAGE (priv->stage),
+                                            clutter_surface);
+      subsurface = wl_subcompositor_get_subsurface (priv->subcompositor,
+                                                    clutter_surface,
+                                                    gtk_surface);
+    }
+#endif
+
   clutter_actor_realize (priv->stage);
 
   if (gtk_widget_get_visible (widget))
@@ -938,6 +974,40 @@ gtk_clutter_embed_class_init (GtkClutterEmbedClass *klass)
   g_object_class_install_property (gobject_class, PROP_USE_LAYOUT_SIZE, pspec);
 }
 
+
+
+#if defined(GDK_WINDOWING_WAYLAND) && defined(CLUTTER_WINDOWING_WAYLAND)
+static void
+registry_handle_global (void *data,
+                        struct wl_registry *registry,
+                        uint32_t name,
+                        const char *interface,
+                        uint32_t version)
+{
+  GtkClutterEmbed *embed = data;
+  GtkClutterEmbedPrivate *priv = embed->priv;
+
+  if (strcmp (interface, "wl_subcompositor") == 0) {
+    priv->subcompositor = wl_registry_bind (registry,
+                                            name,
+                                            &wl_subcompositor_interface,
+                                            1);
+  }
+}
+
+static void
+registry_handle_global_remove (void *data,
+                               struct wl_registry *registry,
+                               uint32_t name)
+{
+}
+
+static const struct wl_registry_listener registry_listener = {
+  registry_handle_global,
+  registry_handle_global_remove
+};
+#endif
+
 static void
 gtk_clutter_embed_init (GtkClutterEmbed *embed)
 {
@@ -986,6 +1056,25 @@ gtk_clutter_embed_init (GtkClutterEmbed *embed)
     g_signal_connect (priv->stage,
                       "queue-relayout", G_CALLBACK (on_stage_queue_relayout),
                       embed);
+
+
+#if defined(GDK_WINDOWING_WAYLAND) && defined(CLUTTER_WINDOWING_WAYLAND)
+  {
+    GdkDisplay *gdk_display = gdk_display_get_default ();
+    if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WAYLAND) &&
+        GDK_IS_WAYLAND_DISPLAY (gdk_display))
+    {
+      struct wl_display *display;
+      struct wl_registry *registry;
+
+      display = gdk_wayland_display_get_wl_display (gdk_display);
+      registry = wl_display_get_registry (display);
+      wl_registry_add_listener (registry, &registry_listener, embed);
+
+      wl_display_roundtrip (display);
+    }
+  }
+#endif
 }
 
 /**
diff --git a/clutter-gtk/gtk-clutter-util.c b/clutter-gtk/gtk-clutter-util.c
index 0752d7e..1c989a7 100644
--- a/clutter-gtk/gtk-clutter-util.c
+++ b/clutter-gtk/gtk-clutter-util.c
@@ -105,7 +105,8 @@ post_parse_hook (GOptionContext  *context,
       GDK_IS_WAYLAND_DISPLAY (display))
     {
       /* let GTK+ be in charge of the event handling */
-      /* FIXME: disable event retrieval */
+      clutter_wayland_disable_event_retrieval ();
+      clutter_wayland_set_display (gdk_wayland_display_get_wl_display (display));
     }
   else
 #endif
diff --git a/configure.ac b/configure.ac
index 7d381e2..6c31516 100644
--- a/configure.ac
+++ b/configure.ac
@@ -202,6 +202,18 @@ GTK_DOC_CHECK([1.14], [--flavour=no-tmpl])
 
 GOBJECT_INTROSPECTION_CHECK([0.9.12])
 
+AC_ARG_ENABLE([wayland],
+              [AC_HELP_STRING([--enable-wayland],
+                              [Enable wayland support])],
+              [],
+              [enable_wayland=yes])
+
+AS_IF([test "x$enable_wayland" = "xyes"],
+      [PKG_CHECK_MODULES(WAYLAND, [wayland-client gtk+-wayland-3.0 clutter-wayland-1.0])],
+      [])
+
+WAYLAND_SCANNER_RULES(['$(top_srcdir)/protocol'])
+
 AC_CONFIG_FILES([
         Makefile
         build/Makefile
diff --git a/protocol/subsurface.xml b/protocol/subsurface.xml
new file mode 100644
index 0000000..9e4a658
--- /dev/null
+++ b/protocol/subsurface.xml
@@ -0,0 +1,244 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="subsurface">
+
+  <copyright>
+    Copyright © 2012-2013 Collabora, Ltd.
+
+    Permission to use, copy, modify, distribute, and sell this
+    software and its documentation for any purpose is hereby granted
+    without fee, provided that the above copyright notice appear in
+    all copies and that both that copyright notice and this permission
+    notice appear in supporting documentation, and that the name of
+    the copyright holders not be used in advertising or publicity
+    pertaining to distribution of the software without specific,
+    written prior permission.  The copyright holders make no
+    representations about the suitability of this software for any
+    purpose.  It is provided "as is" without express or implied
+    warranty.
+
+    THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+    SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+    FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+    SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+    AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+    THIS SOFTWARE.
+  </copyright>
+
+  <interface name="wl_subcompositor" version="1">
+    <description summary="sub-surface compositing">
+      The global interface exposing sub-surface compositing capabilities.
+      A wl_surface, that has sub-surfaces associated, is called the
+      parent surface. Sub-surfaces can be arbitrarily nested and create
+      a tree of sub-surfaces.
+
+      The root surface in a tree of sub-surfaces is the main
+      surface. The main surface cannot be a sub-surface, because
+      sub-surfaces must always have a parent.
+
+      A main surface with its sub-surfaces forms a (compound) window.
+      For window management purposes, this set of wl_surface objects is
+      to be considered as a single window, and it should also behave as
+      such.
+
+      The aim of sub-surfaces is to offload some of the compositing work
+      within a window from clients to the compositor. A prime example is
+      a video player with decorations and video in separate wl_surface
+      objects. This should allow the compositor to pass YUV video buffer
+      processing to dedicated overlay hardware when possible.
+    </description>
+
+    <request name="destroy" type="destructor">
+      <description summary="unbind from the subcompositor interface">
+       Informs the server that the client will not be using this
+       protocol object anymore. This does not affect any other
+       objects, wl_subsurface objects included.
+      </description>
+    </request>
+
+    <enum name="error">
+      <entry name="bad_surface" value="0"
+             summary="the to-be sub-surface is invalid"/>
+    </enum>
+
+    <request name="get_subsurface">
+      <description summary="give a surface the role sub-surface">
+       Create a sub-surface interface for the given surface, and
+       associate it with the given parent surface. This turns a
+       plain wl_surface into a sub-surface.
+
+       The to-be sub-surface must not already have a dedicated
+       purpose, like any shell surface type, cursor image, drag icon,
+       or sub-surface. Otherwise a protocol error is raised.
+      </description>
+
+      <arg name="id" type="new_id" interface="wl_subsurface"
+           summary="the new subsurface object id"/>
+      <arg name="surface" type="object" interface="wl_surface"
+           summary="the surface to be turned into a sub-surface"/>
+      <arg name="parent" type="object" interface="wl_surface"
+           summary="the parent surface"/>
+    </request>
+  </interface>
+
+  <interface name="wl_subsurface" version="1">
+    <description summary="sub-surface interface to a wl_surface">
+      An additional interface to a wl_surface object, which has been
+      made a sub-surface. A sub-surface has one parent surface. A
+      sub-surface's size and position are not limited to that of the parent.
+      Particularly, a sub-surface is not automatically clipped to its
+      parent's area.
+
+      A sub-surface becomes mapped, when a non-NULL wl_buffer is applied
+      and the parent surface is mapped. The order of which one happens
+      first is irrelevant. A sub-surface is hidden if the parent becomes
+      hidden, or if a NULL wl_buffer is applied. These rules apply
+      recursively through the tree of surfaces.
+
+      The behaviour of wl_surface.commit request on a sub-surface
+      depends on the sub-surface's mode. The possible modes are
+      synchronized and desynchronized, see methods
+      wl_subsurface.set_sync and wl_subsurface.set_desync. Synchronized
+      mode caches the wl_surface state to be applied when the parent's
+      state gets applied, and desynchronized mode applies the pending
+      wl_surface state directly. A sub-surface is initially in the
+      synchronized mode.
+
+      Sub-surfaces have also other kind of state, which is managed by
+      wl_subsurface requests, as opposed to wl_surface requests. This
+      state includes the sub-surface position relative to the parent
+      surface (wl_subsurface.set_position), and the stacking order of
+      the parent and its sub-surfaces (wl_subsurface.place_above and
+      .place_below). This state is applied when the parent surface's
+      wl_surface state is applied, regardless of the sub-surface's mode.
+      As the exception, set_sync and set_desync are effective immediately.
+
+      The main surface can be thought to be always in desynchronized mode,
+      since it does not have a parent in the sub-surfaces sense.
+
+      Even if a sub-surface is in desynchronized mode, it will behave as
+      in synchronized mode, if its parent surface behaves as in
+      synchronized mode. This rule is applied recursively throughout the
+      tree of surfaces. This means, that one can set a sub-surface into
+      synchronized mode, and then assume that all its child and grand-child
+      sub-surfaces are synchronized, too, without explicitly setting them.
+
+      If the wl_surface associated with the wl_subsurface is destroyed, the
+      wl_subsurface object becomes inert. Note, that destroying either object
+      takes effect immediately. If you need to synchronize the removal
+      of a sub-surface to the parent surface update, unmap the sub-surface
+      first by attaching a NULL wl_buffer, update parent, and then destroy
+      the sub-surface.
+
+      If the parent wl_surface object is destroyed, the sub-surface is
+      unmapped.
+    </description>
+
+    <request name="destroy" type="destructor">
+      <description summary="remove sub-surface interface">
+       The sub-surface interface is removed from the wl_surface object
+       that was turned into a sub-surface with
+       wl_subcompositor.get_subsurface request. The wl_surface's association
+       to the parent is deleted, and the wl_surface loses its role as
+       a sub-surface. The wl_surface is unmapped.
+      </description>
+    </request>
+
+    <enum name="error">
+      <entry name="bad_surface" value="0"
+             summary="wl_surface is not a sibling or the parent"/>
+    </enum>
+
+    <request name="set_position">
+      <description summary="reposition the sub-surface">
+       This schedules a sub-surface position change.
+       The sub-surface will be moved so, that its origin (top-left
+       corner pixel) will be at the location x, y of the parent surface
+       coordinate system. The coordinates are not restricted to the parent
+       surface area. Negative values are allowed.
+
+       The next wl_surface.commit on the parent surface will reset
+       the sub-surface's position to the scheduled coordinates.
+
+       The initial position is 0, 0.
+      </description>
+
+      <arg name="x" type="int" summary="coordinate in the parent surface"/>
+      <arg name="y" type="int" summary="coordinate in the parent surface"/>
+    </request>
+
+    <request name="place_above">
+      <description summary="restack the sub-surface">
+       This sub-surface is taken from the stack, and put back just
+       above the reference surface, changing the z-order of the sub-surfaces.
+       The reference surface must be one of the sibling surfaces, or the
+       parent surface. Using any other surface, including this sub-surface,
+       will cause a protocol error.
+
+       The z-order is double-buffered state, and will be applied on the
+       next commit of the parent surface.
+       See wl_surface.commit and wl_subcompositor.get_subsurface.
+
+       A new sub-surface is initially added as the top-most in the stack
+       of its siblings and parent.
+      </description>
+
+      <arg name="sibling" type="object" interface="wl_surface"
+           summary="the reference surface"/>
+    </request>
+
+    <request name="place_below">
+      <description summary="restack the sub-surface">
+       The sub-surface is placed just below of the reference surface.
+       See wl_subsurface.place_above.
+      </description>
+
+      <arg name="sibling" type="object" interface="wl_surface"
+           summary="the reference surface"/>
+    </request>
+
+    <request name="set_sync">
+      <description summary="set sub-surface to synchronized mode">
+       Change the commit behaviour of the sub-surface to synchronized
+       mode, also described as the parent dependant mode.
+
+       In synchronized mode, wl_surface.commit on a sub-surface will
+       accumulate the committed state in a cache, but the state will
+       not be applied and hence will not change the compositor output.
+       The cached state is applied to the sub-surface immediately after
+       the parent surface's state is applied. This ensures atomic
+       updates of the parent and all its synchronized sub-surfaces.
+       Applying the cached state will invalidate the cache, so further
+       parent surface commits do not (re-)apply old state.
+
+       See wl_subsurface for the recursive effect of this mode.
+      </description>
+    </request>
+
+    <request name="set_desync">
+      <description summary="set sub-surface to desynchronized mode">
+       Change the commit behaviour of the sub-surface to desynchronized
+       mode, also described as independent or freely running mode.
+
+       In desynchronized mode, wl_surface.commit on a sub-surface will
+       apply the pending state directly, without caching, as happens
+       normally with a wl_surface. Calling wl_surface.commit on the
+       parent surface has no effect on the sub-surface's wl_surface
+       state. This mode allows a sub-surface to be updated on its own.
+
+       If cached state exists when wl_surface.commit is called in
+       desynchronized mode, the pending state is added to the cached
+       state, and applied as whole. This invalidates the cache.
+
+       Note: even if a sub-surface is set to desynchronized, a parent
+       sub-surface may override it to behave as synchronized. For details,
+       see wl_subsurface.
+
+       If a surface's parent surface behaves as desynchronized, then
+       the cached state is applied on set_desync.
+      </description>
+    </request>
+
+  </interface>
+</protocol>


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