3 #include <clutter/clutter.h>
12 static ClutterActor *stage = NULL;
15 on_load_finished (ClutterTexture *texture,
19 gint load_type = GPOINTER_TO_INT (user_data);
20 const gchar *load_str = NULL;
25 load_str = "synchronous loading";
29 load_str = "asynchronous data loading";
33 load_str = "asynchronous loading";
38 g_print ("%s failed: %s\n", load_str, error->message);
40 g_print ("%s successful\n", load_str);
44 size_change_cb (ClutterTexture *texture,
49 clutter_actor_set_size (user_data, width, height);
53 gboolean task (gpointer user_data)
55 const gchar *path = user_data;
56 ClutterActor *image[3];
57 ClutterActor *clone[3];
60 image[0] = g_object_new (CLUTTER_TYPE_TEXTURE, NULL);
61 g_signal_connect (image[0], "load-finished",
62 G_CALLBACK (on_load_finished),
63 GINT_TO_POINTER (LOAD_SYNC));
65 image[1] = g_object_new (CLUTTER_TYPE_TEXTURE,
66 "load-data-async", TRUE,
68 g_signal_connect (image[1], "load-finished",
69 G_CALLBACK (on_load_finished),
70 GINT_TO_POINTER (LOAD_DATA_ASYNC));
71 image[2] = g_object_new (CLUTTER_TYPE_TEXTURE,
74 g_signal_connect (image[2], "load-finished",
75 G_CALLBACK (on_load_finished),
76 GINT_TO_POINTER (LOAD_ASYNC));
78 for (i = 0; i < 3; i++)
82 clutter_texture_set_from_file (CLUTTER_TEXTURE (image[i]), path, &error);
84 g_error ("Unable to load image at '%s': %s",
85 path != NULL ? path : "<unknown>",
89 for (i = 0; i < 3; i++)
90 clutter_container_add_actor (CLUTTER_CONTAINER (stage), image[i]);
92 for (i = 0; i < 3; i++)
94 clutter_actor_set_position (image[i], 50 + i * 100, 0 + i * 50);
95 clone[i] = clutter_clone_new (image[i]);
96 g_signal_connect (image[i], "size-change",
97 G_CALLBACK (size_change_cb), clone[i]);
98 clutter_container_add_actor (CLUTTER_CONTAINER (stage), clone[i]);
99 clutter_actor_set_position (clone[i], 50 + i * 100, 150 + i * 50 + 100);
102 for (i = 0; i < 3; i++)
104 clutter_actor_set_depth (image[i], -2500);
105 clutter_actor_animate (image[i], CLUTTER_LINEAR, 5000,
114 cleanup_task (gpointer data)
119 test_texture_async_main (int argc, char *argv[])
123 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
126 stage = clutter_stage_new ();
127 clutter_stage_set_title (CLUTTER_STAGE (stage), "Asynchronous Texture Loading");
128 clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_LightSkyBlue);
129 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
131 clutter_actor_show (stage);
135 : g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
137 clutter_threads_add_timeout_full (G_PRIORITY_DEFAULT, 500,
141 clutter_threads_enter ();
143 clutter_threads_leave ();
150 G_MODULE_EXPORT const char *
151 test_texture_async_describe (void)
153 return "Texture asynchronous loading using threads";