From: Emmanuele Bassi Date: Fri, 30 Jan 2009 14:59:39 +0000 (+0000) Subject: Load the image asynchronously X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;ds=sidebyside;h=5bff448f092fbf9ab89bd725a642c6e45b594932;p=clutter-gtk 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. --- 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 +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);