diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2009-01-30 14:59:39 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2009-01-30 14:59:39 +0000 |
commit | 5bff448f092fbf9ab89bd725a642c6e45b594932 (patch) | |
tree | 1b9de9359eee703f99b0a59e3b181d701ef41147 | |
parent | 78e4d895da3029288ca255a880a225156d6111a4 (diff) | |
download | clutter-gtk-5bff448f092fbf9ab89bd725a642c6e45b594932.tar.gz |
Load the image asynchronously
The ClutterTexture:load-async property allows ClutterTexture to
spawn off a worker thread to load an image from disk -- provided
that we initialize the threading support in GLib, GTK+ and Clutter
first.
-rw-r--r-- | examples/gtk-clutter-viewport.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/examples/gtk-clutter-viewport.c b/examples/gtk-clutter-viewport.c index 33c54ad..70a8df6 100644 --- a/examples/gtk-clutter-viewport.c +++ b/examples/gtk-clutter-viewport.c @@ -3,6 +3,19 @@ #include <clutter-gtk/clutter-gtk.h> +static GTimer *timer = NULL; + +static void +on_load_finished (ClutterTexture *texture, + const GError *error, + gpointer user_data) +{ + if (timer) + g_print ("%s: load time: %.3f secs\n", + G_STRLOC, + g_timer_elapsed (timer, NULL)); +} + int main (int argc, char *argv[]) { @@ -15,6 +28,10 @@ main (int argc, char *argv[]) gint i; ClutterColor col2 = { 0, }; + g_thread_init (NULL); + gdk_threads_init (); + clutter_threads_init (); + if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) g_error ("Unable to initialize GtkClutter"); @@ -50,12 +67,29 @@ main (int argc, char *argv[]) { GError *error = NULL; - tex = clutter_texture_new_from_file (argv[1], &error); + tex = clutter_texture_new (); + g_object_set (G_OBJECT (tex), "load-async", TRUE, NULL); + g_signal_connect (tex, + "load-finished", G_CALLBACK (on_load_finished), + NULL); + + timer = g_timer_new (); + + clutter_texture_set_from_file (CLUTTER_TEXTURE (tex), argv[1], &error); if (error) { g_warning ("Unable to open `%s': %s", argv[1], error->message); g_error_free (error); } + else + g_print ("%s: load time: %.3f secs\n", + G_STRLOC, + g_timer_elapsed (timer, NULL)); + + g_print ("%s: tex.size = %d, %d\n", + G_STRLOC, + clutter_actor_get_width (tex), + clutter_actor_get_height (tex)); } clutter_container_add_actor (CLUTTER_CONTAINER (viewport), tex); |