ecore/wayland: Add subsurface handling APIs. 88/11088/1 accepted/tizen/20131018.135106 accepted/tizen/20131018.135929 accepted/tizen/20131112.015522 submit/tizen/20131017.152941
authorRafael Antognolli <rafael.antognolli@intel.com>
Fri, 11 Oct 2013 17:50:41 +0000 (14:50 -0300)
committerRafael Antognolli <rafael.antognolli@intel.com>
Thu, 17 Oct 2013 14:42:50 +0000 (11:42 -0300)
Change-Id: I1bbcb416d11f9b6ae93ca962f1765125cd3fb25b

src/lib/ecore_evas/ecore_evas_wayland_egl.c
src/lib/ecore_evas/ecore_evas_wayland_shm.c
src/lib/ecore_wayland/Ecore_Wayland.h
src/lib/ecore_wayland/Makefile.am
src/lib/ecore_wayland/ecore_wl.c
src/lib/ecore_wayland/ecore_wl_private.h
src/lib/ecore_wayland/ecore_wl_subsurf.c [new file with mode: 0644]
src/lib/ecore_wayland/ecore_wl_window.c

index 0e7312d..a438e1c 100644 (file)
@@ -905,7 +905,7 @@ _ecore_evas_wl_render(Ecore_Evas *ee)
                                            &frame_listener, ee);
                }
 
-             if ((updates = evas_render_updates(ee->evas)))
+             if ((updates = evas_render_updates(ee->evas)) || ee->engine.wl.win->needs_commit)
                {
                   Eina_List *l = NULL;
                   Eina_Rectangle *r;
@@ -916,6 +916,7 @@ _ecore_evas_wl_render(Ecore_Evas *ee)
                      ecore_wl_window_damage(win,
                                             r->x, r->y, r->w, r->h);
 
+                  ecore_wl_window_commit(ee->engine.wl.win);
                   ecore_wl_flush();
 
                   evas_render_updates_free(updates);
index d8e0ae9..987c413 100644 (file)
@@ -1018,7 +1018,7 @@ _ecore_evas_wl_render(Ecore_Evas *ee)
                                            &frame_listener, ee);
                }
 
-             if ((updates = evas_render_updates(ee->evas)))
+             if ((updates = evas_render_updates(ee->evas)) || ee->engine.wl.win->needs_commit)
                {
                   Eina_List *l = NULL;
                   Eina_Rectangle *r;
index f47950d..4738086 100644 (file)
@@ -34,6 +34,7 @@ typedef struct _Ecore_Wl_Display Ecore_Wl_Display;
 typedef struct _Ecore_Wl_Output Ecore_Wl_Output;
 typedef struct _Ecore_Wl_Input Ecore_Wl_Input;
 typedef struct _Ecore_Wl_Global Ecore_Wl_Global; /** @since 1.7.6 */
+typedef struct _Ecore_Wl_Subsurf Ecore_Wl_Subsurf; /** @since 1.8 */
 
 # ifndef _ECORE_WAYLAND_WINDOW_PREDEF
 typedef struct _Ecore_Wl_Window Ecore_Wl_Window;
@@ -225,7 +226,10 @@ struct _Ecore_Wl_Window
    /* FIXME: Ideally we should record the cursor name for this window 
     * so we can compare and avoid unnecessary cursor set calls to wayland */
 
+   Ecore_Wl_Subsurf *subsurfs;
+
    void *data;
+   Eina_Bool needs_commit : 1;
 };
 
 struct _Ecore_Wl_Event_Mouse_In
@@ -343,6 +347,7 @@ struct _Ecore_Wl_Event_Interfaces_Bound
  * @li @ref Ecore_Wl_Display_Group
  * @li @ref Ecore_Wl_Flush_Group
  * @li @ref Ecore_Wl_Window_Group
+ * @li @ref Ecore_Wl_Subsurf
  */
 
 EAPI extern int ECORE_WL_EVENT_MOUSE_IN;
@@ -438,10 +443,102 @@ EAPI Eina_Bool ecore_wl_dnd_selection_has_owner(Ecore_Wl_Dnd *dnd);
  * @param win The window which will use this newly created surface.
  *
  * @ingroup Ecore_Wl_Window_Group
- * @since 1.8
  */
 EAPI struct wl_surface *ecore_wl_window_surface_create(Ecore_Wl_Window *win);
 
+/**
+ * @defgroup Ecore_Wl_Subsurf Functions to manipulate subsurfaces.
+ * @ingroup Ecore_Wl_Group
+ *
+ * Functions to manipulate wayland subsurfaces, using Ecore_Wl_Subsurf.
+ *
+ * This API is intended to expose Wayland subsurface functionality, although it
+ * should not be necessary for most applications to use it, as soon as we have
+ * means to make Evas automatically switch Evas images to use subsurfaces.
+ *
+ * It can/should be used, for instance, when subsurfaces are needed to be not
+ * in sync with the main window surface.
+ */
+
+/**
+ * Create and return a new subsurface.
+ *
+ * Create a new surface (and subsurface interface), with the parent surface
+ * being the one associated with the given @param win.
+ *
+ * The @param win must be visible, otherwise there will be no surface created
+ * for it yet.
+ *
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI Ecore_Wl_Subsurf *ecore_wl_subsurf_create(Ecore_Wl_Window *win);
+
+/**
+ * Destroy the given subsurface, as well as the surface associated with it.
+ *
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI void ecore_wl_subsurf_del(Ecore_Wl_Subsurf *ess);
+
+/**
+ * Return the wl_surface associated with this subsurface.
+ *
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI struct wl_surface *ecore_wl_subsurf_surface_get(Ecore_Wl_Subsurf *ess);
+
+/**
+ * Set the position of this subsurface, relative to its parent surface.
+ *
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI void ecore_wl_subsurf_position_set(Ecore_Wl_Subsurf *ess, int x, int y);
+
+/**
+ * Get the position of this subsurface, relative to its parent surface.
+ *
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI void ecore_wl_subsurf_position_get(Ecore_Wl_Subsurf *ess, int *x, int *y);
+
+/**
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI void ecore_wl_subsurf_place_above(Ecore_Wl_Subsurf *ess, struct wl_surface *surface);
+
+/**
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI void ecore_wl_subsurf_place_below(Ecore_Wl_Subsurf *ess, struct wl_surface *surface);
+
+/**
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI void ecore_wl_subsurf_sync_set(Ecore_Wl_Subsurf *ess, Eina_Bool val);
+
+/**
+ * Set an opaque region for the given subsurface.
+ *
+ * Use a 0x0 region size to unset the opaque region.
+ *
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI void ecore_wl_subsurf_opaque_region_set(Ecore_Wl_Subsurf *ess, int x, int y, int w, int h);
+
+/**
+ * Commit the subsurface.
+ *
+ * Use this function instead of wl_surface_commit(), if you want to force the
+ * parent surface to commit too. That's because if the subsurface is in sync
+ * mode, its commit will only take effect when the parent surface is committed
+ * too.
+ *
+ * This function will set a flag on the parent window that will force it to be
+ * committed whenever there's a commit on the subsurface.
+ *
+ * @ingroup Ecore_Wl_Subsurf
+ */
+EAPI void ecore_wl_subsurf_commit(Ecore_Wl_Subsurf *ess);
 #ifdef __cplusplus
 }
 #endif
index 027f771..81bd45b 100644 (file)
@@ -19,6 +19,7 @@ ecore_wl_output.c \
 ecore_wl_input.c \
 ecore_wl_window.c \
 ecore_wl_dnd.c \
+ecore_wl_subsurf.c \
 subsurface-protocol.c \
 subsurface-client-protocol.h
 
index 4dd2654..64f7553 100644 (file)
@@ -456,7 +456,7 @@ _ecore_wl_shutdown(Eina_Bool close)
         if (_ecore_wl_disp->wl.compositor)
           wl_compositor_destroy(_ecore_wl_disp->wl.compositor);
         if (_ecore_wl_disp->wl.subcompositor)
-          wl_compositor_destroy(_ecore_wl_disp->wl.subcompositor);
+          wl_subcompositor_destroy(_ecore_wl_disp->wl.subcompositor);
         if (_ecore_wl_disp->wl.display)
           {
              wl_registry_destroy(_ecore_wl_disp->wl.registry);
index 7f59ae9..40beee1 100644 (file)
@@ -99,5 +99,7 @@ void _ecore_wl_dnd_drop(void *data, struct wl_data_device *data_device __UNUSED_
 void _ecore_wl_dnd_selection(void *data, struct wl_data_device *data_device __UNUSED__, struct wl_data_offer *offer);
 void _ecore_wl_dnd_del(Ecore_Wl_Dnd_Source *source);
 
+void _ecore_wl_subsurfs_del_all(Ecore_Wl_Window *win);
+
 struct wl_data_source *_ecore_wl_create_data_source(Ecore_Wl_Display *ewd);
 #endif
diff --git a/src/lib/ecore_wayland/ecore_wl_subsurf.c b/src/lib/ecore_wayland/ecore_wl_subsurf.c
new file mode 100644 (file)
index 0000000..8c1b059
--- /dev/null
@@ -0,0 +1,206 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "ecore_wl_private.h"
+#include <subsurface-client-protocol.h>
+
+struct _Ecore_Wl_Subsurf
+{
+   EINA_INLIST;
+   Ecore_Wl_Window *parent_win;
+   struct wl_surface *surface;
+   struct wl_subsurface *subsurface;
+
+   int x, y;
+
+   Eina_Bool sync : 1;
+};
+
+EAPI Ecore_Wl_Subsurf *
+ecore_wl_subsurf_create(Ecore_Wl_Window *win)
+{
+   struct wl_subsurface *subsurface;
+   struct wl_surface *surface;
+   Ecore_Wl_Subsurf *ess;
+
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!win) return NULL;
+   if (!win->surface) return NULL;
+   if (!_ecore_wl_disp->wl.subcompositor) return NULL;
+
+   surface = wl_compositor_create_surface(_ecore_wl_disp->wl.compositor);
+   if (!surface)
+     return NULL;
+
+   subsurface = wl_subcompositor_get_subsurface
+      (_ecore_wl_disp->wl.subcompositor, surface, win->surface);
+   if (!subsurface)
+     {
+        wl_surface_destroy(surface);
+        return NULL;
+     }
+
+   ess = calloc(1, sizeof(*ess));
+   ess->surface = surface;
+   ess->subsurface = subsurface;
+   ess->parent_win = win;
+
+   win->subsurfs = (Ecore_Wl_Subsurf *)eina_inlist_append
+      (EINA_INLIST_GET(win->subsurfs), EINA_INLIST_GET(ess));
+
+   return ess;
+}
+
+static void
+_ecore_wl_subsurf_destroy(Ecore_Wl_Subsurf *ess)
+{
+   Ecore_Wl_Window *parent;
+
+   wl_subsurface_destroy(ess->subsurface);
+   wl_surface_destroy(ess->surface);
+
+   parent = ess->parent_win;
+   parent->subsurfs = (Ecore_Wl_Subsurf *)eina_inlist_remove
+      (EINA_INLIST_GET(parent->subsurfs), EINA_INLIST_GET(ess));
+
+   free(ess);
+}
+
+EAPI void
+ecore_wl_subsurf_del(Ecore_Wl_Subsurf *ess)
+{
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!ess) return;
+
+   _ecore_wl_subsurf_destroy(ess);
+}
+
+void
+_ecore_wl_subsurfs_del_all(Ecore_Wl_Window *win)
+{
+   Eina_Inlist *it;
+   Ecore_Wl_Subsurf *ess;
+
+   if (!win) return;
+
+   EINA_INLIST_FOREACH_SAFE(win->subsurfs, it, ess)
+     {
+        _ecore_wl_subsurf_destroy(ess);
+     }
+}
+
+EAPI struct wl_surface *
+ecore_wl_subsurf_surface_get(Ecore_Wl_Subsurf *ess)
+{
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!ess) return NULL;
+
+   return ess->surface;
+}
+
+EAPI void
+ecore_wl_subsurf_position_set(Ecore_Wl_Subsurf *ess, int x, int y)
+{
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!ess) return;
+
+   if ((x == ess->x) && (y == ess->y))
+     return;
+
+   ess->x = x;
+   ess->y = y;
+
+   wl_subsurface_set_position(ess->subsurface, x, y);
+}
+
+EAPI void
+ecore_wl_subsurf_position_get(Ecore_Wl_Subsurf *ess, int *x, int *y)
+{
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!ess) return;
+
+   if (x) *x = ess->x;
+   if (y) *y = ess->y;
+}
+
+EAPI void
+ecore_wl_subsurf_place_above(Ecore_Wl_Subsurf *ess, struct wl_surface *surface)
+{
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!ess) return;
+   if (!surface) return;
+
+   wl_subsurface_place_above(ess->subsurface, surface);
+}
+
+EAPI void
+ecore_wl_subsurf_place_below(Ecore_Wl_Subsurf *ess, struct wl_surface *surface)
+{
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!ess) return;
+   if (!surface) return;
+
+   wl_subsurface_place_below(ess->subsurface, surface);
+}
+
+EAPI void
+ecore_wl_subsurf_sync_set(Ecore_Wl_Subsurf *ess, Eina_Bool val)
+{
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!ess) return;
+
+   val = !!val;
+   if (val == ess->sync) return;
+
+   ess->sync = val;
+
+   if (ess->sync)
+     wl_subsurface_set_sync(ess->subsurface);
+   else
+     wl_subsurface_set_desync(ess->subsurface);
+}
+
+EAPI void
+ecore_wl_subsurf_opaque_region_set(Ecore_Wl_Subsurf *ess, int x, int y, int w, int h)
+{
+   Ecore_Wl_Window *parent;
+   struct wl_region *region = NULL;
+
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!ess) return;
+
+   if ((w > 0) && (h > 0))
+     {
+        parent = ess->parent_win;
+        region = wl_compositor_create_region(parent->display->wl.compositor);
+        wl_region_add(region, x, y, w, h);
+        wl_surface_set_opaque_region(ess->surface, region);
+        wl_region_destroy(region);
+     }
+   else
+     wl_surface_set_opaque_region(ess->surface, NULL);
+}
+
+EAPI void
+ecore_wl_subsurf_commit(Ecore_Wl_Subsurf *ess)
+{
+   Ecore_Wl_Window *parent;
+
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!ess) return;
+   if (!ess->parent_win) return;
+
+   wl_surface_commit(ess->surface);
+   ess->parent_win->needs_commit = EINA_TRUE;
+}
index 9bc29a6..c908e49 100644 (file)
@@ -152,6 +152,8 @@ ecore_wl_window_free(Ecore_Wl_Window *win)
           input->keyboard_focus = NULL;
      }
 
+   if (win->subsurfs) _ecore_wl_subsurfs_del_all(win);
+
    if (win->region.input) wl_region_destroy(win->region.input);
    win->region.input = NULL;
    if (win->region.opaque) wl_region_destroy(win->region.opaque);
@@ -287,6 +289,7 @@ ecore_wl_window_commit(Ecore_Wl_Window *win)
    if (!win) return;
    if (win->surface)
      wl_surface_commit(win->surface);
+   win->needs_commit = EINA_FALSE;
 }
 
 EAPI struct wl_surface*