[PATCH weston 1/3] ivi-shell: clear order.surface_list before reordering it

Ucan, Emre (ADITG/SW1) eucan at de.adit-jv.com
Thu Aug 20 07:13:29 PDT 2015


It is only possible to remove a surface from the order.surface_list of a layer,
when ivi_layout_layer_set_render_order is called with an empty array.
Therefore, list of surfaces are cumulated if the API is called many times with different list of surfaces.

Change how the flags are set:
- Introduce the dirty parameter for triggering the render order change.
- IVI_NOTIFICATION_REMOVE/ADD flags are set only at commit_layer_list.

Checking wl_list_empty() on a link offers no information: if it returns true, wl_list_remove() is safe to do. If it returns false, you still do not know if wl_list_remove() is safe;
the link could be part of a list, or the link could be "uninitialized" (e.g. just wl_list_remove()'d). (From Pekka Paalanen's comment at http://lists.freedesktop.org/archives/wayland-devel/2015-August/023987.html).

Calling wl_list_init just before wl_list_insert is redundant.
Because the links of the list are not read before it is overwritten by wl_list_insert.

Use assert to control if the ivilayer->order.surface_list is empty.

Signed-off-by: Emre Ucan <eucan at de.adit-jv.com>
---
 ivi-shell/ivi-layout-private.h |    1 +
 ivi-shell/ivi-layout.c         |   66 ++++++++++++----------------------------
 2 files changed, 21 insertions(+), 46 deletions(-)

diff --git a/ivi-shell/ivi-layout-private.h b/ivi-shell/ivi-layout-private.h
index 9c04c30..074d598 100644
--- a/ivi-shell/ivi-layout-private.h
+++ b/ivi-shell/ivi-layout-private.h
@@ -81,6 +81,7 @@ struct ivi_layout_layer {
 	} pending;
 
 	struct {
+		int dirty;
 		struct wl_list surface_list;
 		struct wl_list link;
 	} order;
diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index d412069..34bb221 100644
--- a/ivi-shell/ivi-layout.c
+++ b/ivi-shell/ivi-layout.c
@@ -58,6 +58,7 @@
 #include "config.h"
 
 #include <string.h>
+#include <assert.h>
 
 #include "compositor.h"
 #include "ivi-layout-export.h"
@@ -809,53 +810,30 @@ commit_layer_list(struct ivi_layout *layout)
 
 		ivilayer->prop = ivilayer->pending.prop;
 
-		if (!(ivilayer->event_mask &
-		      (IVI_NOTIFICATION_ADD | IVI_NOTIFICATION_REMOVE)) ) {
+		if (!ivilayer->order.dirty) {
 			continue;
 		}
 
-		if (ivilayer->event_mask & IVI_NOTIFICATION_REMOVE) {
-			wl_list_for_each_safe(ivisurf, next,
-				&ivilayer->order.surface_list, order.link) {
-				remove_ordersurface_from_layer(ivisurf);
-
-				if (!wl_list_empty(&ivisurf->order.link)) {
-					wl_list_remove(&ivisurf->order.link);
-				}
-
-				wl_list_init(&ivisurf->order.link);
-				ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
-			}
-
-			wl_list_init(&ivilayer->order.surface_list);
+		wl_list_for_each_safe(ivisurf, next, &ivilayer->order.surface_list,
+					 order.link) {
+			remove_ordersurface_from_layer(ivisurf);
+			wl_list_remove(&ivisurf->order.link);
+			wl_list_init(&ivisurf->order.link);
+			ivisurf->event_mask |= IVI_NOTIFICATION_REMOVE;
 		}
 
-		if (ivilayer->event_mask & IVI_NOTIFICATION_ADD) {
-			wl_list_for_each_safe(ivisurf, next,
-					      &ivilayer->order.surface_list, order.link) {
-				remove_ordersurface_from_layer(ivisurf);
-
-				if (!wl_list_empty(&ivisurf->order.link)) {
-					wl_list_remove(&ivisurf->order.link);
-				}
+		assert(wl_list_empty(&ivilayer->order.surface_list));
 
-				wl_list_init(&ivisurf->order.link);
-			}
-
-			wl_list_init(&ivilayer->order.surface_list);
-			wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
+		wl_list_for_each(ivisurf, &ivilayer->pending.surface_list,
 					 pending.link) {
-				if (!wl_list_empty(&ivisurf->order.link)) {
-					wl_list_remove(&ivisurf->order.link);
-					wl_list_init(&ivisurf->order.link);
-				}
-
-				wl_list_insert(&ivilayer->order.surface_list,
-					       &ivisurf->order.link);
-				add_ordersurface_to_layer(ivisurf, ivilayer);
-				ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
-			}
+			wl_list_remove(&ivisurf->order.link);
+			wl_list_insert(&ivilayer->order.surface_list,
+				       &ivisurf->order.link);
+			add_ordersurface_to_layer(ivisurf, ivilayer);
+			ivisurf->event_mask |= IVI_NOTIFICATION_ADD;
 		}
+
+		ivilayer->order.dirty = 0;
 	}
 }
 
@@ -997,8 +975,6 @@ clear_surface_pending_list(struct ivi_layout_layer *ivilayer)
 
 		wl_list_init(&surface_link->pending.link);
 	}
-
-	ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
 }
 
 static void
@@ -1015,8 +991,6 @@ clear_surface_order_list(struct ivi_layout_layer *ivilayer)
 
 		wl_list_init(&surface_link->order.link);
 	}
-
-	ivilayer->event_mask |= IVI_NOTIFICATION_REMOVE;
 }
 
 static void
@@ -2102,7 +2076,7 @@ ivi_layout_layer_set_render_order(struct ivi_layout_layer *ivilayer,
 		}
 	}
 
-	ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
+	ivilayer->order.dirty = 1;
 
 	return IVI_SUCCEEDED;
 }
@@ -2526,7 +2500,7 @@ ivi_layout_layer_add_surface(struct ivi_layout_layer *ivilayer,
 		}
 	}
 
-	ivilayer->event_mask |= IVI_NOTIFICATION_ADD;
+	ivilayer->order.dirty = 1;
 
 	return IVI_SUCCEEDED;
 }
@@ -2554,7 +2528,7 @@ ivi_layout_layer_remove_surface(struct ivi_layout_layer *ivilayer,
 		}
 	}
 
-	remsurf->event_mask |= IVI_NOTIFICATION_REMOVE;
+	ivilayer->order.dirty = 1;
 }
 
 static int32_t
-- 
1.7.9.5



More information about the wayland-devel mailing list