ecore-wayland: Simplify opaque and input region handling.
authorChris Michael <cp.michael@samsung.com>
Wed, 7 Jan 2015 19:46:14 +0000 (14:46 -0500)
committerChris Michael <cp.michael@samsung.com>
Wed, 7 Jan 2015 19:50:00 +0000 (14:50 -0500)
Summary: We can make opaque and input region handling simplier if we
just use one opaque & input region per window. Previous code would
always create a new region, set it to the surface, then destroy it.
This code works much nicer in that it hammers the protocol with less
region create/destroy calls.

@fix

Signed-off-by: Chris Michael <cp.michael@samsung.com>
src/lib/ecore_wayland/ecore_wl_private.h
src/lib/ecore_wayland/ecore_wl_window.c

index eacc22ff9881586167d9afdebf3f0f63efa50c5d..52b7a9b5091c8735d8fddd6ec99da45c95c0ce18 100644 (file)
@@ -117,6 +117,9 @@ struct _Ecore_Wl_Window
    int ivi_surface_id;
 # endif
 
+   struct wl_region *opaque_region;
+   struct wl_region *input_region;
+
    struct xdg_surface *xdg_surface;
    struct xdg_popup *xdg_popup;
    Eina_Bool focused : 1;
index ecf3ac95f23c3cf255e6ae8944778c44771a4f85..55c7097f6b46d57ce7484174378d8f03a73d6052 100644 (file)
@@ -101,6 +101,12 @@ ecore_wl_window_new(Ecore_Wl_Window *parent, int x, int y, int w, int h, int buf
    win->opaque.w = w;
    win->opaque.h = h;
 
+   win->opaque_region = 
+     wl_compositor_create_region(_ecore_wl_compositor_get());
+
+   win->input_region = 
+     wl_compositor_create_region(_ecore_wl_compositor_get());
+
    win->title = NULL;
    win->class_name = NULL;
 
@@ -132,6 +138,9 @@ ecore_wl_window_free(Ecore_Wl_Window *win)
 
    if (win->subsurfs) _ecore_wl_subsurfs_del_all(win);
 
+   if (win->input_region) wl_region_destroy(win->input_region);
+   if (win->opaque_region) wl_region_destroy(win->opaque_region);
+
 #ifdef USE_IVI_SHELL
    if (win->ivi_surface) ivi_surface_destroy(win->ivi_surface);
    win->ivi_surface = NULL;
@@ -228,6 +237,19 @@ ecore_wl_window_commit(Ecore_Wl_Window *win)
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
    if (!win) return;
+
+   if (win->opaque_region)
+     {
+        if (win->surface)
+          wl_surface_set_opaque_region(win->surface, win->opaque_region);
+     }
+
+   if (win->input_region)
+     {
+        if (win->surface)
+          wl_surface_set_input_region(win->surface, win->input_region);
+     }
+
    if ((win->surface) && (win->has_buffer)) 
      wl_surface_commit(win->surface);
 }
@@ -253,7 +275,7 @@ ecore_wl_window_buffer_attach(Ecore_Wl_Window *win, struct wl_buffer *buffer, in
              wl_surface_attach(win->surface, buffer, x, y);
              wl_surface_damage(win->surface, 0, 0, 
                                win->allocation.w, win->allocation.h);
-             wl_surface_commit(win->surface);
+             ecore_wl_window_commit(win);
           }
         break;
       default:
@@ -796,39 +818,27 @@ ecore_wl_window_input_region_set(Ecore_Wl_Window *win, int x, int y, int w, int
 
    win->input.x = x;
    win->input.y = y;
-   if ((w > 0) && (h > 0))
-     {
-        if ((win->input.w == w) && (win->input.h == h))
-          return;
-
-        win->input.w = w;
-        win->input.h = h;
-     }
+   win->input.w = w;
+   win->input.h = h;
 
-   if ((win->type != ECORE_WL_WINDOW_TYPE_FULLSCREEN) || 
-       (win->type != ECORE_WL_WINDOW_TYPE_DND))
+   if (win->type != ECORE_WL_WINDOW_TYPE_DND)
      {
-        if ((w > 0) && (h > 0))
+        switch (win->rotation)
           {
-             struct wl_region *region = NULL;
-
-             region = 
-               wl_compositor_create_region(_ecore_wl_compositor_get());
-             if (!region)
-               {
-                  wl_surface_set_input_region(win->surface, NULL);
-                  return;
-               }
-
-             wl_region_add(region, x, y, w, h);
-             wl_surface_set_input_region(win->surface, region);
-             wl_region_destroy(region);
+           case 0:
+             wl_region_add(win->input_region, x, y, w, h);
+             break;
+           case 180:
+             wl_region_add(win->input_region, x, x + y, w, h);
+             break;
+           case 90:
+             wl_region_add(win->input_region, y, x, h, w);
+             break;
+           case 270:
+             wl_region_add(win->input_region, x + y, x, h, w);
+             break;
           }
-        else
-          wl_surface_set_input_region(win->surface, NULL);
      }
-
-   /* ecore_wl_window_commit(win); */
 }
 
 /* @since 1.8 */
@@ -841,50 +851,35 @@ ecore_wl_window_opaque_region_set(Ecore_Wl_Window *win, int x, int y, int w, int
 
    win->opaque.x = x;
    win->opaque.y = y;
-   if ((w > 0) && (h > 0))
-     {
-        if ((win->opaque.w == w) && (win->opaque.h == h))
-          return;
+   win->opaque.w = w;
+   win->opaque.h = h;
 
-        win->opaque.w = w;
-        win->opaque.h = h;
-     }
+   if ((win->transparent) || (win->alpha)) return;
 
-   if (((w > 0) && (h > 0)) && ((!win->transparent) && (!win->alpha)))
+   switch (win->rotation)
      {
-        struct wl_region *region = NULL;
-
-        region = 
-          wl_compositor_create_region(_ecore_wl_compositor_get());
-        if (!region)
-          {
-             wl_surface_set_opaque_region(win->surface, NULL);
-             return;
-          }
-
-        switch (win->rotation)
-          {
-           case 0:
-             wl_region_add(region, x, y, w, h);
-             break;
-           case 180:
-             wl_region_add(region, x, x + y, w, h);
-             break;
-           case 90:
-             wl_region_add(region, y, x, h, w);
-             break;
-           case 270:
-             wl_region_add(region, x + y, x, h, w);
-             break;
-          }
-
-        wl_surface_set_opaque_region(win->surface, region);
-        wl_region_destroy(region);
+      case 0:
+        wl_region_add(win->opaque_region, x, y, w, h);
+        break;
+      case 180:
+        wl_region_add(win->opaque_region, x, x + y, w, h);
+        break;
+      case 90:
+        wl_region_add(win->opaque_region, y, x, h, w);
+        break;
+      case 270:
+        wl_region_add(win->opaque_region, x + y, x, h, w);
+        break;
      }
-   else
-     wl_surface_set_opaque_region(win->surface, NULL);
 
-   /* ecore_wl_window_commit(win); */
+   /* if ((w > 0) && (h > 0)) */
+   /*   { */
+   /*      if ((win->opaque.w == w) && (win->opaque.h == h)) */
+   /*        return; */
+
+   /*      win->opaque.w = w; */
+   /*      win->opaque.h = h; */
+   /*   } */
 }
 
 /* @since 1.8 */