update warning flags for gcc 4.4
[swfdec.git] / test / swfdec_test_plugin.c
blob679aac6d673757c03c7d09fedaa8fe400077287d
1 /* Swfdec
2 * Copyright (C) 2008 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "swfdec_test_plugin.h"
25 #include <swfdec/swfdec.h>
26 #include "swfdec_test_test.h"
27 #include "swfdec_test_swfdec_socket.h"
29 static void
30 swfdec_test_plugin_swfdec_advance (SwfdecTestPlugin *plugin, unsigned int msecs)
32 while (plugin->data && msecs > 0) {
33 long next_event = swfdec_player_get_next_event (plugin->data);
34 if (next_event < 0)
35 break;
36 next_event = MIN (next_event, (long) msecs);
37 msecs -= swfdec_player_advance (plugin->data, next_event);
39 while (plugin->data && swfdec_player_get_next_event (plugin->data) == 0) {
40 swfdec_player_advance (plugin->data, 0);
44 static void
45 swfdec_test_plugin_swfdec_screenshot (SwfdecTestPlugin *plugin, unsigned char *data,
46 guint x, guint y, guint width, guint height)
48 cairo_surface_t *surface;
49 cairo_t *cr;
50 guint background;
52 surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32,
53 width, height, width * 4);
54 cairo_surface_set_device_offset (surface, -(double) x, -(double) y);
55 cr = cairo_create (surface);
56 background = swfdec_player_get_background_color (plugin->data);
57 cairo_set_source_rgb (cr,
58 ((background >> 16) & 0xFF) / 255.0,
59 ((background >> 8) & 0xFF) / 255.0,
60 (background & 0xFF) / 255.0);
61 cairo_paint (cr);
63 swfdec_player_render (plugin->data, cr);
64 cairo_destroy (cr);
65 cairo_surface_destroy (surface);
68 static void
69 swfdec_test_plugin_swfdec_mouse_move (SwfdecTestPlugin *plugin, double x, double y)
71 swfdec_player_mouse_move (plugin->data, x, y);
74 static void
75 swfdec_test_plugin_swfdec_mouse_press (SwfdecTestPlugin *plugin, double x, double y, guint button)
77 swfdec_player_mouse_press (plugin->data, x, y, button);
80 static void
81 swfdec_test_plugin_swfdec_mouse_release (SwfdecTestPlugin *plugin, double x, double y, guint button)
83 swfdec_player_mouse_release (plugin->data, x, y, button);
86 static void
87 swfdec_test_plugin_swfdec_finish (SwfdecTestPlugin *plugin)
89 if (plugin->data) {
90 g_object_unref (plugin->data);
91 plugin->data = NULL;
95 static void
96 swfdec_test_plugin_swfdec_trace (SwfdecPlayer *player, const char *message,
97 SwfdecTestPlugin *plugin)
99 plugin->trace (plugin, message);
102 static void
103 swfdec_test_plugin_swfdec_launch (SwfdecPlayer *player, const char *url,
104 const char *target, SwfdecBuffer *data, guint header_count,
105 const char **header_names, const char **header_values,
106 SwfdecTestPlugin *plugin)
108 plugin->launch (plugin, url);
111 static void
112 swfdec_test_plugin_swfdec_fscommand (SwfdecPlayer *player, const char *command,
113 const char *para, SwfdecTestPlugin *plugin)
115 if (g_ascii_strcasecmp (command, "quit") == 0) {
116 plugin->quit (plugin);
117 swfdec_test_plugin_swfdec_finish (plugin);
121 static void
122 swfdec_test_plugin_swfdec_notify (SwfdecPlayer *player, GParamSpec *pspec, SwfdecTestPlugin *plugin)
124 if (g_str_equal (pspec->name, "default-width") ||
125 g_str_equal (pspec->name, "default-height")) {
126 swfdec_player_get_default_size (player, &plugin->width, &plugin->height);
127 } else if (g_str_equal (pspec->name, "rate")) {
128 plugin->rate = swfdec_player_get_rate (player) * 256;
132 void
133 swfdec_test_plugin_swfdec_new (SwfdecTestPlugin *plugin)
135 static const GTimeVal the_beginning = { 1035840244, 123 };
136 SwfdecPlayer *player;
137 SwfdecURL *url;
139 plugin->advance = swfdec_test_plugin_swfdec_advance;
140 plugin->screenshot = swfdec_test_plugin_swfdec_screenshot;
141 plugin->mouse_move = swfdec_test_plugin_swfdec_mouse_move;
142 plugin->mouse_press = swfdec_test_plugin_swfdec_mouse_press;
143 plugin->mouse_release = swfdec_test_plugin_swfdec_mouse_release;
144 plugin->finish = swfdec_test_plugin_swfdec_finish;
145 plugin->data = player = g_object_new (SWFDEC_TYPE_PLAYER, "random-seed", 0,
146 "loader-type", SWFDEC_TYPE_FILE_LOADER, "socket-type", SWFDEC_TYPE_TEST_SWFDEC_SOCKET,
147 "max-runtime", 0, "start-time", &the_beginning, "allow-fullscreen", TRUE,
148 "memory-until-gc", 0, NULL);
150 g_object_set_data (G_OBJECT (player), "plugin", plugin);
151 g_signal_connect (player, "fscommand", G_CALLBACK (swfdec_test_plugin_swfdec_fscommand), plugin);
152 g_signal_connect (player, "trace", G_CALLBACK (swfdec_test_plugin_swfdec_trace), plugin);
153 g_signal_connect (player, "launch", G_CALLBACK (swfdec_test_plugin_swfdec_launch), plugin);
154 g_signal_connect (player, "notify", G_CALLBACK (swfdec_test_plugin_swfdec_notify), plugin);
155 url = swfdec_url_new_from_input (plugin->filename);
156 swfdec_player_set_url (player, url);
157 swfdec_url_free (url);
158 while (swfdec_player_get_next_event (player) == 0)
159 swfdec_player_advance (player, 0);