2009-03-11 18:26:30 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gmodule.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2009-06-06 14:57:29 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LOAD_SYNC,
|
|
|
|
LOAD_DATA_ASYNC,
|
|
|
|
LOAD_ASYNC
|
|
|
|
};
|
|
|
|
|
2011-09-27 15:40:34 +00:00
|
|
|
static ClutterActor *stage = NULL;
|
|
|
|
|
2009-06-06 14:57:29 +00:00
|
|
|
static void
|
|
|
|
on_load_finished (ClutterTexture *texture,
|
|
|
|
const GError *error,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gint load_type = GPOINTER_TO_INT (user_data);
|
|
|
|
const gchar *load_str = NULL;
|
|
|
|
|
|
|
|
switch (load_type)
|
|
|
|
{
|
|
|
|
case LOAD_SYNC:
|
|
|
|
load_str = "synchronous loading";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOAD_DATA_ASYNC:
|
|
|
|
load_str = "asynchronous data loading";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOAD_ASYNC:
|
|
|
|
load_str = "asynchronous loading";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_print ("%s failed: %s\n", load_str, error->message);
|
|
|
|
else
|
|
|
|
g_print ("%s successful\n", load_str);
|
|
|
|
}
|
2009-03-12 10:14:40 +00:00
|
|
|
|
2009-11-05 17:30:33 +00:00
|
|
|
static void
|
|
|
|
size_change_cb (ClutterTexture *texture,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gpointer user_data)
|
2009-03-12 10:14:40 +00:00
|
|
|
{
|
|
|
|
clutter_actor_set_size (user_data, width, height);
|
|
|
|
}
|
|
|
|
|
2009-11-05 17:30:33 +00:00
|
|
|
static
|
|
|
|
gboolean task (gpointer user_data)
|
2009-03-11 18:26:30 +00:00
|
|
|
{
|
2011-09-27 15:40:34 +00:00
|
|
|
const gchar *path = user_data;
|
|
|
|
ClutterActor *image[3];
|
|
|
|
ClutterActor *clone[3];
|
2009-03-11 18:26:30 +00:00
|
|
|
gint i;
|
|
|
|
|
2009-06-06 14:57:29 +00:00
|
|
|
image[0] = g_object_new (CLUTTER_TYPE_TEXTURE, NULL);
|
|
|
|
g_signal_connect (image[0], "load-finished",
|
|
|
|
G_CALLBACK (on_load_finished),
|
|
|
|
GINT_TO_POINTER (LOAD_SYNC));
|
|
|
|
|
2009-03-11 18:26:30 +00:00
|
|
|
image[1] = g_object_new (CLUTTER_TYPE_TEXTURE,
|
2009-03-12 10:38:39 +00:00
|
|
|
"load-data-async", TRUE,
|
2009-03-11 18:26:30 +00:00
|
|
|
NULL);
|
2009-06-06 14:57:29 +00:00
|
|
|
g_signal_connect (image[1], "load-finished",
|
|
|
|
G_CALLBACK (on_load_finished),
|
|
|
|
GINT_TO_POINTER (LOAD_DATA_ASYNC));
|
2009-03-11 18:26:30 +00:00
|
|
|
image[2] = g_object_new (CLUTTER_TYPE_TEXTURE,
|
2009-03-12 10:38:39 +00:00
|
|
|
"load-async", TRUE,
|
2009-03-11 18:26:30 +00:00
|
|
|
NULL);
|
2009-06-06 14:57:29 +00:00
|
|
|
g_signal_connect (image[2], "load-finished",
|
|
|
|
G_CALLBACK (on_load_finished),
|
|
|
|
GINT_TO_POINTER (LOAD_ASYNC));
|
|
|
|
|
2009-11-05 17:30:33 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2010-06-08 10:19:28 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
clutter_texture_set_from_file (CLUTTER_TEXTURE (image[i]), path, &error);
|
|
|
|
if (error != NULL)
|
|
|
|
g_error ("Unable to load image at '%s': %s",
|
|
|
|
path != NULL ? path : "<unknown>",
|
|
|
|
error->message);
|
|
|
|
}
|
2009-06-06 14:57:29 +00:00
|
|
|
|
2009-11-05 17:30:33 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2011-09-27 15:40:34 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), image[i]);
|
2009-06-06 14:57:29 +00:00
|
|
|
|
2009-11-05 17:30:33 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2009-03-12 10:14:40 +00:00
|
|
|
{
|
2011-09-27 15:40:34 +00:00
|
|
|
clutter_actor_set_position (image[i], 50 + i * 100, 0 + i * 50);
|
2012-03-15 17:42:42 +00:00
|
|
|
clutter_actor_set_depth (image[i], -2500);
|
|
|
|
|
2011-09-27 15:40:34 +00:00
|
|
|
clone[i] = clutter_clone_new (image[i]);
|
2009-03-12 11:48:44 +00:00
|
|
|
g_signal_connect (image[i], "size-change",
|
|
|
|
G_CALLBACK (size_change_cb), clone[i]);
|
2011-09-27 15:40:34 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), clone[i]);
|
|
|
|
clutter_actor_set_position (clone[i], 50 + i * 100, 150 + i * 50 + 100);
|
2009-03-12 10:14:40 +00:00
|
|
|
}
|
2009-03-11 18:26:30 +00:00
|
|
|
|
2009-11-05 17:30:33 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2009-03-11 18:26:30 +00:00
|
|
|
{
|
2012-03-15 17:42:42 +00:00
|
|
|
clutter_actor_save_easing_state (image[i]);
|
|
|
|
clutter_actor_set_easing_duration (image[i], 5000);
|
|
|
|
clutter_actor_set_depth (image[i], 0);
|
|
|
|
clutter_actor_restore_easing_state (image[i]);
|
2009-03-11 18:26:30 +00:00
|
|
|
}
|
2009-11-05 17:30:33 +00:00
|
|
|
|
2009-03-12 10:14:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-27 15:40:34 +00:00
|
|
|
static void
|
|
|
|
cleanup_task (gpointer data)
|
|
|
|
{
|
|
|
|
}
|
2009-03-12 10:14:40 +00:00
|
|
|
|
|
|
|
G_MODULE_EXPORT gint
|
|
|
|
test_texture_async_main (int argc, char *argv[])
|
|
|
|
{
|
2011-09-27 15:40:34 +00:00
|
|
|
gchar *path;
|
|
|
|
|
2011-02-22 00:19:35 +00:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2009-03-12 10:14:40 +00:00
|
|
|
|
2011-09-27 15:40:34 +00:00
|
|
|
stage = clutter_stage_new ();
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Asynchronous Texture Loading");
|
2012-02-13 16:47:17 +00:00
|
|
|
clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue);
|
2011-09-27 15:40:34 +00:00
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
2009-03-12 10:14:40 +00:00
|
|
|
|
2009-03-11 18:26:30 +00:00
|
|
|
clutter_actor_show (stage);
|
2009-03-12 10:14:40 +00:00
|
|
|
|
2010-06-08 10:19:28 +00:00
|
|
|
path = (argc > 1)
|
2009-11-05 17:30:33 +00:00
|
|
|
? g_strdup (argv[1])
|
|
|
|
: g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
|
2009-03-12 10:14:40 +00:00
|
|
|
|
2011-09-27 15:40:34 +00:00
|
|
|
clutter_threads_add_timeout_full (G_PRIORITY_DEFAULT, 500,
|
|
|
|
task, path,
|
|
|
|
cleanup_task);
|
2009-03-11 18:26:30 +00:00
|
|
|
|
2011-10-21 09:44:27 +00:00
|
|
|
clutter_threads_enter ();
|
2009-03-11 18:26:30 +00:00
|
|
|
clutter_main ();
|
2011-10-21 09:44:27 +00:00
|
|
|
clutter_threads_leave ();
|
2009-03-11 18:26:30 +00:00
|
|
|
|
2009-11-05 17:30:33 +00:00
|
|
|
g_free (path);
|
|
|
|
|
2009-03-11 18:26:30 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2011-09-28 12:32:57 +00:00
|
|
|
|
|
|
|
G_MODULE_EXPORT const char *
|
|
|
|
test_texture_async_describe (void)
|
|
|
|
{
|
|
|
|
return "Texture asynchronous loading using threads";
|
|
|
|
}
|