summaryrefslogtreecommitdiff
path: root/src/theme-viewer.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@pobox.com>2002-02-07 04:22:57 +0000
committerHavoc Pennington <hp@src.gnome.org>2002-02-07 04:22:57 +0000
commit8f1cfefbb223af8755b1013573d4088d476eae7c (patch)
tree86100aa8a9b37373387e593163e490fea2b10653 /src/theme-viewer.c
parentf33a46072b2bcfed59e26f42356175d0f3a62c9a (diff)
downloadmetacity-8f1cfefbb223af8755b1013573d4088d476eae7c.tar.gz
benchmark theme on startup
2002-02-06 Havoc Pennington <hp@pobox.com> * src/theme-viewer.c: benchmark theme on startup * src/theme-parser.c (parse_draw_op_element): fix "colorize != NULL" to "colorize_spec != NULL" and free pixbuf on color spec failure * src/theme.c (colorize_pixbuf): minor reformatting, raise function calls out of inner loop, clamp r/g/b values to uchar range before assigning to uchar (draw_op_as_pixbuf): cache the colorized pixbuf (meta_draw_op_free): free the cache pixbuf
Diffstat (limited to 'src/theme-viewer.c')
-rw-r--r--src/theme-viewer.c88
1 files changed, 82 insertions, 6 deletions
diff --git a/src/theme-viewer.c b/src/theme-viewer.c
index dd2ecdf9..0f8a24ad 100644
--- a/src/theme-viewer.c
+++ b/src/theme-viewer.c
@@ -28,13 +28,15 @@
#include <time.h>
#include <stdlib.h>
-static int client_width = 200;
-static int client_height = 200;
+#define CLIENT_WIDTH 200
+#define CLIENT_HEIGHT 200
static MetaTheme *global_theme = NULL;
static void run_position_expression_tests (void);
static void run_position_expression_timings (void);
+static void run_theme_benchmark (int client_width,
+ int client_height);
static MetaFrameFlags
get_flags (GtkWidget *widget)
@@ -139,8 +141,8 @@ set_widget_to_frame_size (GtkWidget *widget)
&right_width);
gtk_widget_set_size_request (widget,
- client_width + left_width + right_width,
- client_height + top_height + bottom_height);
+ CLIENT_WIDTH + left_width + right_width,
+ CLIENT_HEIGHT + top_height + bottom_height);
}
static gboolean
@@ -176,7 +178,7 @@ expose_handler (GtkWidget *widget,
0, 0,
META_FRAME_TYPE_NORMAL,
get_flags (widget),
- client_width, client_height,
+ CLIENT_WIDTH, CLIENT_HEIGHT,
layout,
get_text_height (widget),
button_states,
@@ -189,7 +191,7 @@ expose_handler (GtkWidget *widget,
widget->style->white_gc,
TRUE,
left_width, top_height,
- client_width, client_height);
+ CLIENT_WIDTH, CLIENT_HEIGHT);
g_object_unref (G_OBJECT (layout));
@@ -241,6 +243,8 @@ main (int argc, char **argv)
global_theme->name,
(end - start) / (double) CLOCKS_PER_SEC);
+ run_theme_benchmark (CLIENT_WIDTH, CLIENT_HEIGHT);
+
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 270, 270);
@@ -285,6 +289,78 @@ main (int argc, char **argv)
return 0;
}
+static void
+run_theme_benchmark (int client_width,
+ int client_height)
+{
+ GtkWidget* widget;
+ GdkPixmap *pixmap;
+ int top_height, bottom_height, left_width, right_width;
+ MetaButtonState button_states[META_BUTTON_TYPE_LAST] =
+ {
+ META_BUTTON_STATE_NORMAL,
+ META_BUTTON_STATE_NORMAL,
+ META_BUTTON_STATE_NORMAL,
+ META_BUTTON_STATE_NORMAL
+ };
+ PangoLayout *layout;
+ clock_t start;
+ clock_t end;
+ int i;
+#define ITERATIONS 100
+
+ widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_widget_realize (widget);
+
+ meta_theme_get_frame_borders (global_theme,
+ META_FRAME_TYPE_NORMAL,
+ get_text_height (widget),
+ get_flags (widget),
+ &top_height,
+ &bottom_height,
+ &left_width,
+ &right_width);
+
+ pixmap = gdk_pixmap_new (widget->window,
+ client_width + left_width + right_width,
+ client_height + top_height + bottom_height,
+ -1);
+
+ layout = create_title_layout (widget);
+
+ start = clock ();
+
+ i = 0;
+ while (i < ITERATIONS)
+ {
+ meta_theme_draw_frame (global_theme,
+ widget,
+ pixmap,
+ NULL,
+ 0, 0,
+ META_FRAME_TYPE_NORMAL,
+ get_flags (widget),
+ client_width, client_height,
+ layout,
+ get_text_height (widget),
+ button_states,
+ get_mini_icon (),
+ get_icon ());
+ ++i;
+ }
+
+ end = clock ();
+
+ g_print ("Drew %d frames for %dx%d clients in %g seconds (%g seconds per frame)\n",
+ ITERATIONS, client_width, client_height,
+ ((double)end - (double)start) / CLOCKS_PER_SEC,
+ ((double)end - (double)start) / CLOCKS_PER_SEC / (double) ITERATIONS);
+
+ g_object_unref (G_OBJECT (layout));
+ g_object_unref (G_OBJECT (pixmap));
+ gtk_widget_destroy (widget);
+}
+
typedef struct
{
GdkRectangle rect;