[mutter/gbsneto/red-damage] clutter/stage-cogl: Add option to visualize damaged regions



commit b7d69c4fb2dad192595ce4bf51f56e27bd22332a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Aug 10 01:03:54 2018 -0300

    clutter/stage-cogl: Add option to visualize damaged regions
    
    This is useful to visualize which parts of the screen are being
    damaged.
    
    Add a new 'damage-region' value for CLUTTER_PAINT and paint the
    damaged regions accordingly.

 clutter/clutter/clutter-debug.h           |  3 +-
 clutter/clutter/clutter-main.c            |  4 +++
 clutter/clutter/clutter-stage-window.c    |  5 +++
 clutter/clutter/cogl/clutter-stage-cogl.c | 55 +++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 1 deletion(-)
---
diff --git a/clutter/clutter/clutter-debug.h b/clutter/clutter/clutter-debug.h
index 00302bf5e..69d59502a 100644
--- a/clutter/clutter/clutter-debug.h
+++ b/clutter/clutter/clutter-debug.h
@@ -39,7 +39,8 @@ typedef enum {
   CLUTTER_DEBUG_DISABLE_CULLING         = 1 << 4,
   CLUTTER_DEBUG_DISABLE_OFFSCREEN_REDIRECT = 1 << 5,
   CLUTTER_DEBUG_CONTINUOUS_REDRAW       = 1 << 6,
-  CLUTTER_DEBUG_PAINT_DEFORM_TILES      = 1 << 7
+  CLUTTER_DEBUG_PAINT_DEFORM_TILES      = 1 << 7,
+  CLUTTER_DEBUG_PAINT_DAMAGE_REGION     = 1 << 8,
 } ClutterDrawDebugFlag;
 
 #ifdef CLUTTER_ENABLE_DEBUG
diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c
index 1c1d6f773..f1bc78a6b 100644
--- a/clutter/clutter/clutter-main.c
+++ b/clutter/clutter/clutter-main.c
@@ -149,6 +149,7 @@ static const GDebugKey clutter_paint_debug_keys[] = {
   { "disable-offscreen-redirect", CLUTTER_DEBUG_DISABLE_OFFSCREEN_REDIRECT },
   { "continuous-redraw", CLUTTER_DEBUG_CONTINUOUS_REDRAW },
   { "paint-deform-tiles", CLUTTER_DEBUG_PAINT_DEFORM_TILES },
+  { "damage-region", CLUTTER_DEBUG_PAINT_DAMAGE_REGION },
 };
 
 static void
@@ -1372,6 +1373,9 @@ clutter_init_real (GError **error)
         CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS | CLUTTER_DEBUG_DISABLE_CULLING;
     }
 
+  if (clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_DAMAGE_REGION)
+    g_message ("Enabling damaged region");
+
   /* this will take care of initializing Cogl's state and
    * query the GL machinery for features
    */
diff --git a/clutter/clutter/clutter-stage-window.c b/clutter/clutter/clutter-stage-window.c
index c9a227b8b..cac6962d9 100644
--- a/clutter/clutter/clutter-stage-window.c
+++ b/clutter/clutter/clutter-stage-window.c
@@ -182,6 +182,11 @@ _clutter_stage_window_add_redraw_clip (ClutterStageWindow    *window,
 
   g_return_if_fail (CLUTTER_IS_STAGE_WINDOW (window));
 
+  if (stage_clip)
+    g_message ("Setting redraw clip to %dx%dx%dx%d", stage_clip->x, stage_clip->y, stage_clip->width, 
stage_clip->height);
+  else
+    g_message ("Setting redraw clip to NULL");
+
   iface = CLUTTER_STAGE_WINDOW_GET_IFACE (window);
   if (iface->add_redraw_clip != NULL)
     iface->add_redraw_clip (window, stage_clip);
diff --git a/clutter/clutter/cogl/clutter-stage-cogl.c b/clutter/clutter/cogl/clutter-stage-cogl.c
index 84da1b19f..997d08aab 100644
--- a/clutter/clutter/cogl/clutter-stage-cogl.c
+++ b/clutter/clutter/cogl/clutter-stage-cogl.c
@@ -354,6 +354,58 @@ valid_buffer_age (ClutterStageViewCogl *view_cogl,
   return age < MIN (view_priv->damage_index, DAMAGE_HISTORY_MAX);
 }
 
+static void
+paint_damage_region (ClutterStageWindow    *stage_window,
+                     ClutterStageView      *view,
+                     cairo_rectangle_int_t *swap_region)
+{
+  CoglFramebuffer *framebuffer = clutter_stage_view_get_onscreen (view);
+  CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
+  static CoglPipeline *overlay_blue = NULL;
+  ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window);
+  ClutterActor *actor = CLUTTER_ACTOR (stage_cogl->wrapper);
+  float x_1 = swap_region->x;
+  float x_2 = swap_region->x + swap_region->width;
+  float y_1 = swap_region->y;
+  float y_2 = swap_region->y + swap_region->height;
+  CoglMatrix modelview;
+
+  if (G_UNLIKELY (overlay_blue == NULL))
+    {
+      overlay_blue = cogl_pipeline_new (ctx);
+      cogl_pipeline_set_color4ub (overlay_blue, 0x00, 0x00, 0x33, 0x33);
+    }
+
+  cogl_framebuffer_push_matrix (framebuffer);
+  cogl_matrix_init_identity (&modelview);
+  _clutter_actor_apply_modelview_transform (actor, &modelview);
+  cogl_framebuffer_set_modelview_matrix (framebuffer, &modelview);
+
+  /* Blue for the swap region */
+  cogl_framebuffer_draw_rectangle (framebuffer, overlay_blue, x_1, y_1, x_2, y_2);
+
+  /* Red for the clip */
+  if (stage_cogl->initialized_redraw_clip)
+    {
+      static CoglPipeline *overlay_red = NULL;
+
+      if (G_UNLIKELY (overlay_red == NULL))
+        {
+          overlay_red = cogl_pipeline_new (ctx);
+          cogl_pipeline_set_color4ub (overlay_red, 0x33, 0x00, 0x00, 0x33);
+        }
+
+      x_1 = stage_cogl->bounding_redraw_clip.x;
+      x_2 = stage_cogl->bounding_redraw_clip.x + stage_cogl->bounding_redraw_clip.width;
+      y_1 = stage_cogl->bounding_redraw_clip.y;
+      y_2 = stage_cogl->bounding_redraw_clip.y + stage_cogl->bounding_redraw_clip.height;
+
+      cogl_framebuffer_draw_rectangle (framebuffer, overlay_red, x_1, y_1, x_2, y_2);
+    }
+
+  cogl_framebuffer_pop_matrix (framebuffer);
+}
+
 static gboolean
 swap_framebuffer (ClutterStageWindow    *stage_window,
                   ClutterStageView      *view,
@@ -373,6 +425,9 @@ swap_framebuffer (ClutterStageWindow    *stage_window,
   else
     ndamage = 0;
 
+  if (G_UNLIKELY ((clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_DAMAGE_REGION)))
+    paint_damage_region (stage_window, view, swap_region);
+
   if (cogl_is_onscreen (framebuffer))
     {
       CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);


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