[gtk+] inspector: Add frame clock info



commit 85a539ce6d42cea52970c7c22d35538443e54937
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Nov 12 22:50:52 2014 -0500

    inspector: Add frame clock info
    
    Add the frame clocks of toplevel widgets to the object tree,
    and show their frame count and frame rate in the misc tab.

 gtk/inspector/misc-info.c    |   57 +++++++++++++++++++++++++++++++++++
 gtk/inspector/misc-info.ui   |   68 ++++++++++++++++++++++++++++++++++++++++++
 gtk/inspector/misc-info.ui.h |    2 +
 gtk/inspector/object-tree.c  |    9 +++++
 4 files changed, 136 insertions(+), 0 deletions(-)
---
diff --git a/gtk/inspector/misc-info.c b/gtk/inspector/misc-info.c
index 0834311..323f6d5 100644
--- a/gtk/inspector/misc-info.c
+++ b/gtk/inspector/misc-info.c
@@ -56,6 +56,10 @@ struct _GtkInspectorMiscInfoPrivate {
   GtkWidget *clip_area;
   GtkWidget *tick_callback_row;
   GtkWidget *tick_callback;
+  GtkWidget *framerate_row;
+  GtkWidget *framerate;
+  GtkWidget *framecount_row;
+  GtkWidget *framecount;
   GtkWidget *accessible_role_row;
   GtkWidget *accessible_role;
   GtkWidget *mapped_row;
@@ -68,6 +72,7 @@ struct _GtkInspectorMiscInfoPrivate {
   GtkWidget *child_visible;
 
   guint update_source_id;
+  gint64 last_frame;
 };
 
 enum
@@ -324,6 +329,43 @@ update_info (gpointer data)
       update_focus_widget (sl);
     }
 
+  if (GDK_IS_FRAME_CLOCK (sl->priv->object))
+    {
+      GdkFrameClock *clock;
+      gint64 frame;
+      gint64 frame_time;
+      gint64 history_start;
+      gint64 history_len;
+      gint64 previous_frame_time;
+      GdkFrameTimings *previous_timings;
+
+      clock = GDK_FRAME_CLOCK (sl->priv->object);
+      frame = gdk_frame_clock_get_frame_counter (clock);
+      frame_time = gdk_frame_clock_get_frame_time (clock);
+
+      tmp = g_strdup_printf ("%ld", frame);
+      gtk_label_set_label (GTK_LABEL (sl->priv->framecount), tmp);
+      g_free (tmp);
+
+      history_start = gdk_frame_clock_get_history_start (clock);
+      history_len = frame - history_start;
+
+      if (history_len > 0 && sl->priv->last_frame != frame)
+        {
+          previous_timings = gdk_frame_clock_get_timings (clock, history_start);
+          previous_frame_time = gdk_frame_timings_get_frame_time (previous_timings);
+          tmp = g_strdup_printf ("%4.1f ⁄ s", (G_USEC_PER_SEC * history_len) / (double) (frame_time - 
previous_frame_time));
+          gtk_label_set_label (GTK_LABEL (sl->priv->framerate), tmp);
+          g_free (tmp);
+        }
+      else
+        {
+          gtk_label_set_label (GTK_LABEL (sl->priv->framerate), "—");
+        }
+
+      sl->priv->last_frame = frame;
+    }
+
   return G_SOURCE_CONTINUE;
 }
 
@@ -402,6 +444,17 @@ gtk_inspector_misc_info_set_object (GtkInspectorMiscInfo *sl,
       gtk_widget_hide (sl->priv->focus_widget_row);
     }
 
+  if (GDK_IS_FRAME_CLOCK (object))
+    {
+      gtk_widget_show (sl->priv->framecount_row);
+      gtk_widget_show (sl->priv->framerate_row);
+    }
+  else
+    {
+      gtk_widget_hide (sl->priv->framecount_row);
+      gtk_widget_hide (sl->priv->framerate_row);
+    }
+
   update_info (sl);
 }
 
@@ -511,6 +564,10 @@ gtk_inspector_misc_info_class_init (GtkInspectorMiscInfoClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, clip_area);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, tick_callback_row);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, tick_callback);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framecount_row);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framecount);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framerate_row);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framerate);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, accessible_role_row);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, accessible_role);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, mapped_row);
diff --git a/gtk/inspector/misc-info.ui b/gtk/inspector/misc-info.ui
index 4eeba49..d0a7966 100644
--- a/gtk/inspector/misc-info.ui
+++ b/gtk/inspector/misc-info.ui
@@ -343,6 +343,74 @@
                 </child>
 
                 <child>
+                  <object class="GtkListBoxRow" id="framecount_row">
+                    <property name="visible">true</property>
+                    <property name="activatable">false</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="visible">true</property>
+                        <property name="orientation">horizontal</property>
+                        <property name="margin">10</property>
+                        <property name="spacing">40</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">true</property>
+                            <property name="label" translatable="yes">Frame count</property>
+                            <property name="halign">start</property>
+                            <property name="valign">baseline</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="expand">true</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="framecount">
+                            <property name="visible">true</property>
+                            <property name="halign">end</property>
+                            <property name="valign">baseline</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+
+                <child>
+                  <object class="GtkListBoxRow" id="framerate_row">
+                    <property name="visible">true</property>
+                    <property name="activatable">false</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="visible">true</property>
+                        <property name="orientation">horizontal</property>
+                        <property name="margin">10</property>
+                        <property name="spacing">40</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">true</property>
+                            <property name="label" translatable="yes">Frame rate</property>
+                            <property name="halign">start</property>
+                            <property name="valign">baseline</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="expand">true</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="framerate">
+                            <property name="visible">true</property>
+                            <property name="halign">end</property>
+                            <property name="valign">baseline</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+
+                <child>
                   <object class="GtkListBoxRow" id="accessible_role_row">
                     <property name="visible">true</property>
                     <property name="activatable">false</property>
diff --git a/gtk/inspector/misc-info.ui.h b/gtk/inspector/misc-info.ui.h
index 53fba2b..a09a285 100644
--- a/gtk/inspector/misc-info.ui.h
+++ b/gtk/inspector/misc-info.ui.h
@@ -9,6 +9,8 @@ N_("Mnemonic Label");
 N_("Allocated size");
 N_("Clip area");
 N_("Tick callback");
+N_("Frame count");
+N_("Frame rate");
 N_("Accessible role");
 N_("Mapped");
 N_("Realized");
diff --git a/gtk/inspector/object-tree.c b/gtk/inspector/object-tree.c
index 6f7d0bc..000db91 100644
--- a/gtk/inspector/object-tree.c
+++ b/gtk/inspector/object-tree.c
@@ -780,6 +780,15 @@ gtk_inspector_object_tree_append_object (GtkInspectorObjectTree *wt,
             }
           g_list_free (list);
         }
+
+       if (gtk_widget_is_toplevel (GTK_WIDGET (object)))
+         {
+           GObject *clock;
+
+           clock = (GObject *)gtk_widget_get_frame_clock (GTK_WIDGET (object));
+           if (clock)
+             gtk_inspector_object_tree_append_object (wt, clock, &iter, "frame-clock");
+         }
     }
 }
 


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