Damage debug wasn't very useful since it only used a single static color.
This patch makes it so a random color is assigned for each damage event,
making debug damage much more helpful as a debugging tool.
---
 src/compositor.c | 33 +++++++++++++++++++++++++++++++++
 src/compositor.h |  1 +
 src/shell.c      | 25 ++++---------------------
 3 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 7c161d0..8b88124 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1127,6 +1127,34 @@ surface_accumulate_damage(struct weston_surface *surface,
 }
 
 static void
+show_repaint(struct weston_compositor *ec)
+{
+       struct weston_surface *surface;
+       struct weston_plane plane;
+       float r, g, b;
+
+       surface = ec->debug_repaint_surface;
+       r = random() % 25 / 100.0;
+       g = random() % 25 / 100.0;
+       b = random() % 25 / 100.0;
+       weston_surface_set_color(surface, r, g, b, 0.3);
+
+       /* Here's the dirty little trick that makes the
+        * repaint debugging work: we move the surface to a
+        * different plane and force an update_transform to
+        * update dependent state and clear the
+        * geometry.dirty bit.  This way the call to
+        * damage_below() in update_transform() does not
+        * add damage to the primary plane.  */
+
+       weston_plane_init(&plane, 0, 0);
+       surface->plane = &plane;
+       weston_surface_update_transform(surface);
+       surface->plane = &ec->primary_plane;
+       weston_plane_release(&plane);
+}
+
+static void
 weston_output_repaint(struct weston_output *output, uint32_t msecs)
 {
        struct weston_compositor *ec = output->compositor;
@@ -1146,6 +1174,9 @@ weston_output_repaint(struct weston_output *output, 
uint32_t msecs)
                output->border.top + output->border.bottom;
        glViewport(0, 0, width, height);
 
+       if (ec->debug_repaint_surface)
+               show_repaint(ec);
+
        /* Rebuild the surface list and update surface transforms up front. */
        wl_list_init(&ec->surface_list);
        wl_list_init(&frame_callback_list);
@@ -3175,6 +3206,8 @@ weston_compositor_init(struct weston_compositor *ec,
 
        ec->ping_handler = NULL;
 
+       ec->debug_repaint_surface = NULL;
+
        screenshooter_create(ec);
        text_cursor_position_notifier_create(ec);
 
diff --git a/src/compositor.h b/src/compositor.h
index 7a8058e..1dd78e8 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -335,6 +335,7 @@ struct weston_compositor {
        PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
        PFNEGLQUERYWAYLANDBUFFERWL query_buffer;
        int has_bind_display;
+       struct weston_surface *debug_repaint_surface;
 
        void (*destroy)(struct weston_compositor *ec);
        void (*restore)(struct weston_compositor *ec);
diff --git a/src/shell.c b/src/shell.c
index 13a7fd0..44bafa7 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -131,7 +131,6 @@ struct desktop_shell {
 
        uint32_t binding_modifier;
        enum animation_type win_animation_type;
-       struct weston_surface *debug_repaint_surface;
 };
 
 enum shell_surface_type {
@@ -3189,34 +3188,18 @@ debug_repaint_binding(struct wl_seat *seat, uint32_t 
time, uint32_t key,
        struct desktop_shell *shell = data;
        struct weston_compositor *compositor = shell->compositor;
        struct weston_surface *surface;
-       struct weston_plane plane;
 
-       if (shell->debug_repaint_surface) {
-               weston_surface_destroy(shell->debug_repaint_surface);
-               shell->debug_repaint_surface = NULL;
+       if (compositor->debug_repaint_surface) {
+               weston_surface_destroy(compositor->debug_repaint_surface);
+               compositor->debug_repaint_surface = NULL;
        } else {
                surface = weston_surface_create(compositor);
-               weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
+               compositor->debug_repaint_surface = surface;
                weston_surface_configure(surface, 0, 0, 8192, 8192);
                wl_list_insert(&compositor->fade_layer.surface_list,
                               &surface->layer_link);
                weston_surface_assign_output(surface);
                pixman_region32_init(&surface->input);
-
-               /* Here's the dirty little trick that makes the
-                * repaint debugging work: we move the surface to a
-                * different plane and force an update_transform to
-                * update dependent state and clear the
-                * geometry.dirty bit.  This way the call to
-                * damage_below() in update_transform() does not
-                * add damage to the primary plane.  */
-
-               weston_plane_init(&plane, 0, 0);
-               surface->plane = &plane;
-               weston_surface_update_transform(surface);
-               shell->debug_repaint_surface = surface;
-               surface->plane = &compositor->primary_plane;
-               weston_plane_release(&plane);
        }
 }
 
-- 
1.7.11.2

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to