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
This commit is contained in:
Owen W. Taylor 2014-05-19 21:11:01 -04:00
parent a6fa6519d5
commit a7f82745c6
3 changed files with 61 additions and 15 deletions

View File

@ -79,6 +79,7 @@ const PerfHelperIface = '<node> \
<arg type="i" direction="in" /> \
<arg type="b" direction="in" /> \
<arg type="b" direction="in" /> \
<arg type="b" direction="in" /> \
</method> \
<method name="WaitWindows" /> \
<method name="DestroyWindows" /> \
@ -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);
}
/**

View File

@ -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
########################################

View File

@ -9,6 +9,8 @@
#include "config.h"
#include <math.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
@ -27,6 +29,7 @@ static const gchar introspection_xml[] =
" <arg type='i' name='height' direction='in'/>"
" <arg type='b' name='alpha' direction='in'/>"
" <arg type='b' name='maximized' direction='in'/>"
" <arg type='b' name='redraws' direction='in'/>"
" </method>"
" <method name='WaitWindows'/>"
" <method name='DestroyWindows'/>"
@ -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)