[gtk/frame-pixel-counter] profiling: Add a counter for pixels drawn per frame



commit 6c9d50a01352efb0f81af2490a633f59b2b9af5f
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 18 17:12:32 2019 +0000

    profiling: Add a counter for pixels drawn per frame
    
    This number clearly shows the recently discovered
    "full redraws" problem.

 gdk/gdkdrawcontext.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
---
diff --git a/gdk/gdkdrawcontext.c b/gdk/gdkdrawcontext.c
index 169bdb82cc..6f19c5fde6 100644
--- a/gdk/gdkdrawcontext.c
+++ b/gdk/gdkdrawcontext.c
@@ -24,6 +24,7 @@
 
 #include "gdkinternals.h"
 #include "gdkintl.h"
+#include "gdkprofilerprivate.h"
 
 /**
  * SECTION:gdkdrawcontext
@@ -174,9 +175,15 @@ gdk_draw_context_class_init (GdkDrawContextClass *klass)
   g_object_class_install_properties (gobject_class, LAST_PROP, pspecs);
 }
 
+static guint pixels_counter;
+
 static void
 gdk_draw_context_init (GdkDrawContext *self)
 {
+#ifdef G_ENABLE_DEBUG
+  if (pixels_counter == 0)
+    pixels_counter = gdk_profiler_define_int_counter ("frame pixels", "Pixels drawn per frame");
+#endif
 }
 
 /**
@@ -315,6 +322,25 @@ gdk_draw_context_begin_frame (GdkDrawContext       *context,
   GDK_DRAW_CONTEXT_GET_CLASS (context)->begin_frame (context, priv->frame_region);
 }
 
+#ifdef G_ENABLE_DEBUG
+static gint64
+region_get_pixels (cairo_region_t *region)
+{
+  int i, n;
+  cairo_rectangle_int_t rect;
+  gint64 pixels = 0;
+
+  n = cairo_region_num_rectangles (region);
+  for (i = 0; i < n; i++)
+    {
+      cairo_region_get_rectangle (region, i, &rect);
+      pixels += rect.width * rect.height;
+    }
+
+  return pixels;
+}
+#endif
+
 /**
  * gdk_draw_context_end_frame:
  * @context: a #GdkDrawContext
@@ -354,6 +380,13 @@ gdk_draw_context_end_frame (GdkDrawContext *context)
 
   GDK_DRAW_CONTEXT_GET_CLASS (context)->end_frame (context, priv->frame_region);
 
+#ifdef G_ENABLE_DEBUG
+  if (gdk_profiler_is_running ())
+    gdk_profiler_set_int_counter (pixels_counter,
+                                  g_get_monotonic_time () * 1000,
+                                  region_get_pixels (priv->frame_region));
+#endif
+
   g_clear_pointer (&priv->frame_region, cairo_region_destroy);
   g_clear_object (&priv->surface->paint_context);
 }


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