From a7f82745c628f6085d24cde69f0d5cb48bee7220 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 19 May 2014 21:11:01 -0400 Subject: [PATCH] shell-perf-helper: Add an option for continual redraws Add an option for windows created with Scripting.createTestWindow() to continually redraw themselves; this is for testing performance of application updates. https://bugzilla.gnome.org/show_bug.cgi?id=732350 --- js/ui/scripting.js | 7 +++-- src/Makefile.am | 2 +- src/shell-perf-helper.c | 67 +++++++++++++++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/js/ui/scripting.js b/js/ui/scripting.js index 4cea3a15f..fe13ce29c 100644 --- a/js/ui/scripting.js +++ b/js/ui/scripting.js @@ -79,6 +79,7 @@ const PerfHelperIface = ' \ \ \ \ + \ \ \ \ @@ -127,6 +128,7 @@ function _callRemote(obj, method, ...args) { * height - height of window, in pixels (default 480) * alpha - whether the window should have an alpha channel (default false) * maximized - whether the window should be created maximized (default false) + * redraws - whether the window should continually redraw itself (default false) * @maximized: whethe the window should be created maximized * * Creates a window using gnome-shell-perf-helper for testing purposes. @@ -139,12 +141,13 @@ function createTestWindow(width, height, params) { params = Params.parse(params, { width: 640, height: 480, alpha: false, - maximized: false }); + maximized: false, + redraws: false }); let perfHelper = _getPerfHelper(); return _callRemote(perfHelper, perfHelper.CreateWindowRemote, params.width, params.height, - params.alpha, params.maximized); + params.alpha, params.maximized, params.redraws); } /** diff --git a/src/Makefile.am b/src/Makefile.am index 52ddbfd54..da61ad5f3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -257,7 +257,7 @@ libexec_PROGRAMS += gnome-shell-perf-helper gnome_shell_perf_helper_SOURCES = shell-perf-helper.c gnome_shell_perf_helper_CPPFLAGS = $(SHELL_PERF_HELPER_CFLAGS) -gnome_shell_perf_helper_LDADD = $(SHELL_PERF_HELPER_LIBS) +gnome_shell_perf_helper_LDADD = $(SHELL_PERF_HELPER_LIBS) -lm ######################################## diff --git a/src/shell-perf-helper.c b/src/shell-perf-helper.c index dabaa5499..eea5d47be 100644 --- a/src/shell-perf-helper.c +++ b/src/shell-perf-helper.c @@ -9,6 +9,8 @@ #include "config.h" +#include + #include #include @@ -27,6 +29,7 @@ static const gchar introspection_xml[] = " " " " " " + " " " " " " " " @@ -40,9 +43,13 @@ typedef struct { guint alpha : 1; guint maximized : 1; + guint redraws : 1; guint mapped : 1; guint exposed : 1; guint pending : 1; + + gint64 start_time; + gint64 time; } WindowInfo; static int opt_idle_timeout = 30; @@ -119,6 +126,7 @@ on_window_draw (GtkWidget *window, { cairo_rectangle_int_t allocation; gtk_widget_get_allocation (window, &allocation); + double x_offset, y_offset; /* We draw an arbitrary pattern of red lines near the border of the * window to make it more clear than empty windows if something @@ -136,16 +144,27 @@ on_window_draw (GtkWidget *window, cairo_paint (cr); cairo_restore (cr); + if (info->redraws) + { + double position = (info->time - info->start_time) / 1000000.; + x_offset = 20 * cos (2 * M_PI * position); + y_offset = 20 * sin (2 * M_PI * position); + } + else + { + x_offset = y_offset = 0; + } + cairo_set_source_rgb (cr, 1, 0, 0); cairo_set_line_width (cr, 10); - cairo_move_to (cr, 0, 40); - cairo_line_to (cr, allocation.width, 40); - cairo_move_to (cr, 0, allocation.height - 40); - cairo_line_to (cr, allocation.width, allocation.height - 40); - cairo_move_to (cr, 40, 0); - cairo_line_to (cr, 40, allocation.height); - cairo_move_to (cr, allocation.width - 40, 0); - cairo_line_to (cr, allocation.width - 40, allocation.height); + cairo_move_to (cr, 0, 40 + y_offset); + cairo_line_to (cr, allocation.width, 40 + y_offset); + cairo_move_to (cr, 0, allocation.height - 40 + y_offset); + cairo_line_to (cr, allocation.width, allocation.height - 40 + y_offset); + cairo_move_to (cr, 40 + x_offset, 0); + cairo_line_to (cr, 40 + x_offset, allocation.height); + cairo_move_to (cr, allocation.width - 40 + x_offset, 0); + cairo_line_to (cr, allocation.width - 40 + x_offset, allocation.height); cairo_stroke (cr); info->exposed = TRUE; @@ -159,11 +178,29 @@ on_window_draw (GtkWidget *window, return FALSE; } +static gboolean +tick_callback (GtkWidget *widget, + GdkFrameClock *frame_clock, + gpointer user_data) +{ + WindowInfo *info = user_data; + + if (info->start_time < 0) + info->start_time = info->time = gdk_frame_clock_get_frame_time (frame_clock); + else + info->time = gdk_frame_clock_get_frame_time (frame_clock); + + gtk_widget_queue_draw (widget); + + return TRUE; +} + static void create_window (int width, int height, gboolean alpha, - gboolean maximized) + gboolean maximized, + gboolean redraws) { WindowInfo *info; @@ -172,12 +209,14 @@ create_window (int width, info->height = height; info->alpha = alpha; info->maximized = maximized; + info->redraws = redraws; info->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); if (alpha) gtk_widget_set_visual (info->window, gdk_screen_get_rgba_visual (gdk_screen_get_default ())); if (maximized) gtk_window_maximize (GTK_WINDOW (info->window)); info->pending = TRUE; + info->start_time = -1; gtk_widget_set_size_request (info->window, width, height); gtk_widget_set_app_paintable (info->window, TRUE); @@ -185,6 +224,10 @@ create_window (int width, g_signal_connect (info->window, "draw", G_CALLBACK (on_window_draw), info); gtk_widget_show (info->window); + if (info->redraws) + gtk_widget_add_tick_callback (info->window, tick_callback, + info, NULL); + our_windows = g_list_prepend (our_windows, info); } @@ -242,11 +285,11 @@ handle_method_call (GDBusConnection *connection, else if (g_strcmp0 (method_name, "CreateWindow") == 0) { int width, height; - gboolean alpha, maximized; + gboolean alpha, maximized, redraws; - g_variant_get (parameters, "(iibb)", &width, &height, &alpha, &maximized); + g_variant_get (parameters, "(iibbb)", &width, &height, &alpha, &maximized, &redraws); - create_window (width, height, alpha, maximized); + create_window (width, height, alpha, maximized, redraws); g_dbus_method_invocation_return_value (invocation, NULL); } else if (g_strcmp0 (method_name, "WaitWindows") == 0)