summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2007-12-14 21:56:54 +0100
committerBenjamin Otte <otte@gnome.org>2007-12-14 21:56:54 +0100
commit58b1173072e7f2ee904bf9262c27d88a8a53dd14 (patch)
tree2a1e4226e0d2e2440a65a7a3a6fe825b0e88ec23
parenta5c5ba8ba912940f9339d6806ad483ce32eb0ed3 (diff)
add a benchmarking program that tests rendering speed
-rw-r--r--Makefile.am3
-rw-r--r--configure.ac1
-rw-r--r--test/.gitignore6
-rw-r--r--test/Makefile.am8
-rw-r--r--test/bench.c109
5 files changed, 126 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index a97a578..d5c576a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,8 @@
SUBDIRS= \
data \
swfdec-directfb \
- player
+ player \
+ test
ACLOCAL_FLAGS = -I m4
diff --git a/configure.ac b/configure.ac
index 238802d..9b47da2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,6 +84,7 @@ AC_CONFIG_FILES(
data/Makefile
swfdec-directfb/Makefile
player/Makefile
+ test/Makefile
)
AC_OUTPUT
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..e2d7a89
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1,6 @@
+.deps
+.libs
+
+*.o
+*.lo
+swfdec-directfb-bench
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..89fc21a
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,8 @@
+bin_PROGRAMS = swfdec-directfb-bench
+
+swfdec_directfb_bench_SOURCES = \
+ bench.c
+
+swfdec_directfb_bench_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_DFB_CFLAGS)
+swfdec_directfb_bench_LDFLAGS = $(SWFDEC_DFB_LIBS)
+
diff --git a/test/bench.c b/test/bench.c
new file mode 100644
index 0000000..82bb7cc
--- /dev/null
+++ b/test/bench.c
@@ -0,0 +1,109 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <swfdec-directfb/swfdec-directfb.h>
+#include <directfb.h>
+#include <stdio.h>
+
+#define ERROR_CHECK(x) G_STMT_START{ \
+ DFBResult err = (x); \
+ if (err != DFB_OK) { \
+ DirectFBErrorFatal ("fatal error", err); \
+ } \
+}G_STMT_END
+
+int
+main (int argc, char *argv[])
+{
+ GError *error = NULL;
+ GOptionContext *ctx;
+ DFBSurfaceDescription dsc;
+ SwfdecPlayer *player;
+ SwfdecDfbRenderer *renderer;
+ guint w, h;
+ IDirectFB *dfb;
+ IDirectFBSurface *surface;
+ long next_event;
+ GTimer *timer;
+ /* config variables */
+ int total = 0;
+ int seconds = 10000;
+
+ GOptionEntry options[] = {
+ { "time", 't', 0, G_OPTION_ARG_INT, &seconds, "number of milliseconds to advance (default: 10.000)", "mSECS" },
+ { NULL }
+ };
+
+ ERROR_CHECK (DirectFBInit (&argc, &argv));
+ swfdec_init ();
+
+ ctx = g_option_context_new ("");
+ g_option_context_add_main_entries (ctx, options, "options");
+ g_option_context_parse (ctx, &argc, &argv, &error);
+ g_option_context_free (ctx);
+
+ if (error) {
+ g_printerr ("Error parsing command line arguments: %s\n", error->message);
+ g_error_free (error);
+ return 1;
+ }
+
+ if (argc < 2) {
+ g_printerr ("Usage: %s [OPTIONS] filename\n", argv[0]);
+ return 1;
+ }
+
+ ERROR_CHECK (DirectFBCreate (&dfb));
+ player = swfdec_player_new_from_file (argv[1]);
+ next_event = swfdec_player_get_next_event (player);
+ while (next_event >= 0 && !swfdec_player_is_initialized (player)) {
+ swfdec_player_advance (player, next_event);
+ next_event = swfdec_player_get_next_event (player);
+ }
+
+ swfdec_player_get_default_size (player, &w, &h);
+ dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT;
+ dsc.width = w;
+ dsc.height = h;
+
+ ERROR_CHECK (dfb->CreateSurface (dfb, &dsc, &surface));
+ renderer = swfdec_dfb_renderer_new (dfb, surface, player);
+
+ timer = g_timer_new ();
+ while (g_main_context_iteration (NULL, FALSE));
+ while (next_event >= 0 && total + next_event < seconds) {
+ swfdec_player_advance (player, next_event);
+ total += next_event;
+ while (g_main_context_iteration (NULL, FALSE));
+
+ next_event = swfdec_player_get_next_event (player);
+ }
+ g_timer_stop (timer);
+ g_print ("advanced %u.%03us in %.3gs\n", seconds / 1000, seconds % 1000, g_timer_elapsed (timer, NULL));
+
+ g_object_unref (renderer);
+ g_object_unref (player);
+ surface->Release (surface);
+ dfb->Release (dfb);
+ return 0;
+}
+