mirror of
https://github.com/brl/mutter.git
synced 2025-02-22 16:04:09 +00:00
tests/clutter: Remove tests testing or relying on ClutterTexture
ClutterTexture is going to be removed, so remove interactive tests that stand in the way for that. Some test texture features, while some makes heavy use of ClutterTexture to implement their testing. Remove these tests to prepare for the removal of ClutterTexture. https://gitlab.gnome.org/GNOME/mutter/merge_requests/932
This commit is contained in:
parent
f7ad7e6c0f
commit
244f55df28
@ -16,7 +16,6 @@ struct _TestDestroy
|
|||||||
|
|
||||||
ClutterActor *bg;
|
ClutterActor *bg;
|
||||||
ClutterActor *label;
|
ClutterActor *label;
|
||||||
ClutterActor *tex;
|
|
||||||
|
|
||||||
GList *children;
|
GList *children;
|
||||||
};
|
};
|
||||||
@ -78,7 +77,7 @@ test_destroy_destroy (ClutterActor *self)
|
|||||||
{
|
{
|
||||||
TestDestroy *test = TEST_DESTROY (self);
|
TestDestroy *test = TEST_DESTROY (self);
|
||||||
|
|
||||||
g_assert_cmpuint (g_list_length (test->children), ==, 4);
|
g_assert_cmpuint (g_list_length (test->children), ==, 3);
|
||||||
|
|
||||||
if (test->bg != NULL)
|
if (test->bg != NULL)
|
||||||
{
|
{
|
||||||
@ -102,17 +101,6 @@ test_destroy_destroy (ClutterActor *self)
|
|||||||
test->label = NULL;
|
test->label = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test->tex != NULL)
|
|
||||||
{
|
|
||||||
if (g_test_verbose ())
|
|
||||||
g_print ("Destroying '%s' (type:%s)\n",
|
|
||||||
clutter_actor_get_name (test->tex),
|
|
||||||
G_OBJECT_TYPE_NAME (test->tex));
|
|
||||||
|
|
||||||
clutter_actor_destroy (test->tex);
|
|
||||||
test->tex = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert_cmpuint (g_list_length (test->children), ==, 1);
|
g_assert_cmpuint (g_list_length (test->children), ==, 1);
|
||||||
|
|
||||||
if (CLUTTER_ACTOR_CLASS (test_destroy_parent_class)->destroy)
|
if (CLUTTER_ACTOR_CLASS (test_destroy_parent_class)->destroy)
|
||||||
@ -139,10 +127,6 @@ test_destroy_init (TestDestroy *self)
|
|||||||
self->label = clutter_text_new ();
|
self->label = clutter_text_new ();
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (self), self->label);
|
clutter_container_add_actor (CLUTTER_CONTAINER (self), self->label);
|
||||||
clutter_actor_set_name (self->label, "Label");
|
clutter_actor_set_name (self->label, "Label");
|
||||||
|
|
||||||
self->tex = clutter_texture_new ();
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (self), self->tex);
|
|
||||||
clutter_actor_set_name (self->tex, "Texture");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1,198 +0,0 @@
|
|||||||
#include <clutter/clutter.h>
|
|
||||||
#include <cogl/cogl.h>
|
|
||||||
|
|
||||||
#include "test-conform-common.h"
|
|
||||||
|
|
||||||
#define BLOCK_SIZE 16
|
|
||||||
|
|
||||||
/* Number of pixels at the border of a block to skip when verifying */
|
|
||||||
#define TEST_INSET 1
|
|
||||||
|
|
||||||
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
/* The first frame is drawn using clutter_cairo_texture_create. The
|
|
||||||
second frame is an update of the first frame using
|
|
||||||
clutter_cairo_texture_create_region. The states are stored like
|
|
||||||
this because the cairo drawing is done on idle and the validation
|
|
||||||
is done during paint and we need to synchronize the two */
|
|
||||||
TEST_BEFORE_DRAW_FIRST_FRAME,
|
|
||||||
TEST_BEFORE_VALIDATE_FIRST_FRAME,
|
|
||||||
TEST_BEFORE_DRAW_SECOND_FRAME,
|
|
||||||
TEST_BEFORE_VALIDATE_SECOND_FRAME,
|
|
||||||
TEST_DONE
|
|
||||||
} TestProgress;
|
|
||||||
|
|
||||||
typedef struct _TestState
|
|
||||||
{
|
|
||||||
ClutterActor *stage;
|
|
||||||
ClutterActor *ct;
|
|
||||||
guint frame;
|
|
||||||
TestProgress progress;
|
|
||||||
} TestState;
|
|
||||||
|
|
||||||
static void
|
|
||||||
validate_part (int block_x, int block_y, const ClutterColor *color)
|
|
||||||
{
|
|
||||||
guint8 data[BLOCK_SIZE * BLOCK_SIZE * 4];
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
cogl_read_pixels (block_x * BLOCK_SIZE,
|
|
||||||
block_y * BLOCK_SIZE,
|
|
||||||
BLOCK_SIZE, BLOCK_SIZE,
|
|
||||||
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
||||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
||||||
data);
|
|
||||||
|
|
||||||
for (x = 0; x < BLOCK_SIZE - TEST_INSET * 2; x++)
|
|
||||||
for (y = 0; y < BLOCK_SIZE - TEST_INSET * 2; y++)
|
|
||||||
{
|
|
||||||
const guint8 *p = data + ((x + TEST_INSET) * 4 +
|
|
||||||
(y + TEST_INSET) * BLOCK_SIZE * 4);
|
|
||||||
|
|
||||||
g_assert_cmpint (p[0], ==, color->red);
|
|
||||||
g_assert_cmpint (p[1], ==, color->green);
|
|
||||||
g_assert_cmpint (p[2], ==, color->blue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
paint_cb (ClutterActor *actor, TestState *state)
|
|
||||||
{
|
|
||||||
static const ClutterColor red = { 0xff, 0x00, 0x00, 0xff };
|
|
||||||
static const ClutterColor green = { 0x00, 0xff, 0x00, 0xff };
|
|
||||||
static const ClutterColor blue = { 0x00, 0x00, 0xff, 0xff };
|
|
||||||
|
|
||||||
if (state->frame++ < 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (state->progress)
|
|
||||||
{
|
|
||||||
case TEST_BEFORE_DRAW_FIRST_FRAME:
|
|
||||||
case TEST_BEFORE_DRAW_SECOND_FRAME:
|
|
||||||
case TEST_DONE:
|
|
||||||
/* Handled by the idle callback */
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TEST_BEFORE_VALIDATE_FIRST_FRAME:
|
|
||||||
/* In the first frame there is a red rectangle next to a green
|
|
||||||
rectangle */
|
|
||||||
validate_part (0, 0, &red);
|
|
||||||
validate_part (1, 0, &green);
|
|
||||||
|
|
||||||
state->progress = TEST_BEFORE_DRAW_SECOND_FRAME;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TEST_BEFORE_VALIDATE_SECOND_FRAME:
|
|
||||||
/* The second frame is the same except the green rectangle is
|
|
||||||
replaced with a blue one */
|
|
||||||
validate_part (0, 0, &red);
|
|
||||||
validate_part (1, 0, &blue);
|
|
||||||
|
|
||||||
state->progress = TEST_DONE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
idle_cb (gpointer data)
|
|
||||||
{
|
|
||||||
TestState *state = data;
|
|
||||||
cairo_t *cr;
|
|
||||||
|
|
||||||
if (state->frame < 2)
|
|
||||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (state->stage));
|
|
||||||
else
|
|
||||||
switch (state->progress)
|
|
||||||
{
|
|
||||||
case TEST_BEFORE_DRAW_FIRST_FRAME:
|
|
||||||
/* Draw two different colour rectangles */
|
|
||||||
cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (state->ct));
|
|
||||||
|
|
||||||
cairo_save (cr);
|
|
||||||
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
|
||||||
|
|
||||||
cairo_save (cr);
|
|
||||||
cairo_rectangle (cr, 0, 0, BLOCK_SIZE, BLOCK_SIZE);
|
|
||||||
cairo_clip (cr);
|
|
||||||
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
|
|
||||||
cairo_paint (cr);
|
|
||||||
cairo_restore (cr);
|
|
||||||
|
|
||||||
cairo_rectangle (cr, BLOCK_SIZE, 0, BLOCK_SIZE, BLOCK_SIZE);
|
|
||||||
cairo_clip (cr);
|
|
||||||
cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
|
|
||||||
cairo_paint (cr);
|
|
||||||
|
|
||||||
cairo_restore (cr);
|
|
||||||
|
|
||||||
cairo_destroy (cr);
|
|
||||||
|
|
||||||
state->progress = TEST_BEFORE_VALIDATE_FIRST_FRAME;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TEST_BEFORE_DRAW_SECOND_FRAME:
|
|
||||||
/* Replace the second rectangle with a blue one */
|
|
||||||
cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (state->ct));
|
|
||||||
|
|
||||||
cairo_rectangle (cr, BLOCK_SIZE, 0, BLOCK_SIZE, BLOCK_SIZE);
|
|
||||||
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
|
|
||||||
cairo_fill (cr);
|
|
||||||
|
|
||||||
cairo_destroy (cr);
|
|
||||||
|
|
||||||
state->progress = TEST_BEFORE_VALIDATE_SECOND_FRAME;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TEST_BEFORE_VALIDATE_FIRST_FRAME:
|
|
||||||
case TEST_BEFORE_VALIDATE_SECOND_FRAME:
|
|
||||||
/* Handled by the paint callback */
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TEST_DONE:
|
|
||||||
clutter_main_quit ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return G_SOURCE_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
texture_cairo (TestConformSimpleFixture *fixture,
|
|
||||||
gconstpointer data)
|
|
||||||
{
|
|
||||||
TestState state;
|
|
||||||
unsigned int idle_source;
|
|
||||||
unsigned int paint_handler;
|
|
||||||
|
|
||||||
state.frame = 0;
|
|
||||||
state.stage = clutter_stage_new ();
|
|
||||||
state.progress = TEST_BEFORE_DRAW_FIRST_FRAME;
|
|
||||||
|
|
||||||
state.ct = clutter_cairo_texture_new (BLOCK_SIZE * 2, BLOCK_SIZE);
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (state.stage), state.ct);
|
|
||||||
|
|
||||||
clutter_stage_set_color (CLUTTER_STAGE (state.stage), &stage_color);
|
|
||||||
|
|
||||||
/* We force continuous redrawing of the stage, since we need to skip
|
|
||||||
* the first few frames, and we wont be doing anything else that
|
|
||||||
* will trigger redrawing. */
|
|
||||||
idle_source = clutter_threads_add_idle (idle_cb, &state);
|
|
||||||
paint_handler = g_signal_connect_after (state.stage, "paint",
|
|
||||||
G_CALLBACK (paint_cb), &state);
|
|
||||||
|
|
||||||
clutter_actor_show (state.stage);
|
|
||||||
clutter_main ();
|
|
||||||
|
|
||||||
g_signal_handler_disconnect (state.stage, paint_handler);
|
|
||||||
g_source_remove (idle_source);
|
|
||||||
|
|
||||||
if (g_test_verbose ())
|
|
||||||
g_print ("OK\n");
|
|
||||||
|
|
||||||
clutter_actor_destroy (state.stage);
|
|
||||||
}
|
|
||||||
|
|
1
src/tests/clutter/interactive/.gitignore
vendored
1
src/tests/clutter/interactive/.gitignore
vendored
@ -47,7 +47,6 @@
|
|||||||
/test-table-layout
|
/test-table-layout
|
||||||
/test-text
|
/test-text
|
||||||
/test-text-field
|
/test-text-field
|
||||||
/test-texture-async
|
|
||||||
/test-texture-material
|
/test-texture-material
|
||||||
/test-texture-quality
|
/test-texture-quality
|
||||||
/test-texture-slicing
|
/test-texture-slicing
|
||||||
|
@ -15,9 +15,6 @@ clutter_tests_interactive_link_args = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
clutter_tests_interactive_test_sources = [
|
clutter_tests_interactive_test_sources = [
|
||||||
'test-texture-slicing.c',
|
|
||||||
'test-texture-async.c',
|
|
||||||
'test-texture-material.c',
|
|
||||||
'test-events.c',
|
'test-events.c',
|
||||||
'test-actors.c',
|
'test-actors.c',
|
||||||
'test-shader-effects.c',
|
'test-shader-effects.c',
|
||||||
@ -25,13 +22,11 @@ clutter_tests_interactive_test_sources = [
|
|||||||
'test-grab.c',
|
'test-grab.c',
|
||||||
'test-cogl-shader-glsl.c',
|
'test-cogl-shader-glsl.c',
|
||||||
'test-state.c',
|
'test-state.c',
|
||||||
'test-fbo.c',
|
|
||||||
'test-cogl-tex-tile.c',
|
'test-cogl-tex-tile.c',
|
||||||
'test-cogl-tex-convert.c',
|
'test-cogl-tex-convert.c',
|
||||||
'test-cogl-offscreen.c',
|
'test-cogl-offscreen.c',
|
||||||
'test-cogl-tex-polygon.c',
|
'test-cogl-tex-polygon.c',
|
||||||
'test-cogl-multitexture.c',
|
'test-cogl-multitexture.c',
|
||||||
'test-stage-read-pixels.c',
|
|
||||||
'test-paint-wrapper.c',
|
'test-paint-wrapper.c',
|
||||||
'test-layout.c',
|
'test-layout.c',
|
||||||
'test-animation.c',
|
'test-animation.c',
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
#include <clutter/clutter.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include <gmodule.h>
|
|
||||||
|
|
||||||
#define STAGE_WIDTH 800
|
|
||||||
#define STAGE_HEIGHT 600
|
|
||||||
|
|
||||||
int
|
|
||||||
test_fbo_main (int argc, char *argv[]);
|
|
||||||
|
|
||||||
const char *
|
|
||||||
test_fbo_describe (void);
|
|
||||||
|
|
||||||
static ClutterActor *
|
|
||||||
make_source (void)
|
|
||||||
{
|
|
||||||
ClutterActor *source, *actor;
|
|
||||||
GError *error = NULL;
|
|
||||||
gchar *file;
|
|
||||||
|
|
||||||
ClutterColor yellow = {0xff, 0xff, 0x00, 0xff};
|
|
||||||
|
|
||||||
source = clutter_group_new ();
|
|
||||||
|
|
||||||
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
|
|
||||||
actor = clutter_texture_new_from_file (file, &error);
|
|
||||||
if (!actor)
|
|
||||||
g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
|
|
||||||
|
|
||||||
g_free (file);
|
|
||||||
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (source), actor);
|
|
||||||
|
|
||||||
actor = clutter_text_new_with_text ("Sans Bold 50px", "Clutter");
|
|
||||||
|
|
||||||
clutter_text_set_color (CLUTTER_TEXT (actor), &yellow);
|
|
||||||
clutter_actor_set_y (actor, clutter_actor_get_height(source) + 5);
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (source), actor);
|
|
||||||
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_MODULE_EXPORT int
|
|
||||||
test_fbo_main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
ClutterActor *fbo;
|
|
||||||
ClutterActor *onscreen_source;
|
|
||||||
ClutterActor *stage;
|
|
||||||
ClutterAnimation *animation;
|
|
||||||
int x_pos = 200;
|
|
||||||
int y_pos = 100;
|
|
||||||
|
|
||||||
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (clutter_feature_available (CLUTTER_FEATURE_OFFSCREEN) == FALSE)
|
|
||||||
g_error("This test requires CLUTTER_FEATURE_OFFSCREEN");
|
|
||||||
|
|
||||||
stage = clutter_stage_new ();
|
|
||||||
clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
|
|
||||||
clutter_actor_set_background_color (stage, CLUTTER_COLOR_SkyBlue);
|
|
||||||
clutter_stage_set_title (CLUTTER_STAGE (stage), "Texture from Actor");
|
|
||||||
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
|
||||||
|
|
||||||
/* Create the first source */
|
|
||||||
onscreen_source = make_source();
|
|
||||||
clutter_actor_show_all (onscreen_source);
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), onscreen_source);
|
|
||||||
|
|
||||||
y_pos = (STAGE_HEIGHT/2.0) -
|
|
||||||
(clutter_actor_get_height (onscreen_source)/2.0);
|
|
||||||
clutter_actor_set_position (onscreen_source, x_pos, y_pos);
|
|
||||||
x_pos += clutter_actor_get_width (onscreen_source);
|
|
||||||
|
|
||||||
animation = clutter_actor_animate (onscreen_source,
|
|
||||||
CLUTTER_LINEAR,
|
|
||||||
5000, /* 1 second duration */
|
|
||||||
"rotation-angle-y", 360.0f,
|
|
||||||
NULL);
|
|
||||||
clutter_animation_set_loop (animation, TRUE);
|
|
||||||
|
|
||||||
/* Second hand = actor from onscreen_source */
|
|
||||||
if ((fbo = clutter_texture_new_from_actor (onscreen_source)) == NULL)
|
|
||||||
g_error("onscreen fbo creation failed");
|
|
||||||
|
|
||||||
clutter_actor_set_position (fbo, x_pos, y_pos);
|
|
||||||
x_pos += clutter_actor_get_width (fbo);
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), fbo);
|
|
||||||
|
|
||||||
/* Third hand = actor from Second hand */
|
|
||||||
if ((fbo = clutter_texture_new_from_actor (fbo)) == NULL)
|
|
||||||
g_error("fbo from fbo creation failed");
|
|
||||||
|
|
||||||
clutter_actor_set_position (fbo, x_pos, y_pos);
|
|
||||||
x_pos += clutter_actor_get_width (fbo);
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), fbo);
|
|
||||||
|
|
||||||
clutter_actor_show_all (stage);
|
|
||||||
clutter_main ();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_MODULE_EXPORT const char *
|
|
||||||
test_fbo_describe (void)
|
|
||||||
{
|
|
||||||
return "Create a texture from an actor.";
|
|
||||||
}
|
|
@ -33,24 +33,6 @@
|
|||||||
{ "name" : "button-press-event", "handler" : "clutter_main_quit" }
|
{ "name" : "button-press-event", "handler" : "clutter_main_quit" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id" : "red-hand",
|
|
||||||
"type" : "ClutterTexture",
|
|
||||||
"filename" : "redhand.png",
|
|
||||||
"position" : { "x" : 100.0, "y" : 100.0 },
|
|
||||||
"width" : "20 mm",
|
|
||||||
"keep-aspect-ratio" : true,
|
|
||||||
"anchor-x" : "5 em",
|
|
||||||
"anchor-y" : "5 pt",
|
|
||||||
"opacity" : 100
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id" : "red-hand-clone",
|
|
||||||
"type" : "ClutterClone",
|
|
||||||
"source" : "red-hand",
|
|
||||||
"position" : [ 250.0, 150.0 ],
|
|
||||||
"opacity" : 100
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id" : "label",
|
"id" : "label",
|
||||||
"type" : "ClutterText",
|
"type" : "ClutterText",
|
||||||
|
@ -1,174 +0,0 @@
|
|||||||
#include <gmodule.h>
|
|
||||||
#include <clutter/clutter.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define DOT_SIZE 2
|
|
||||||
#define TEX_SIZE 64
|
|
||||||
|
|
||||||
typedef struct _CallbackData CallbackData;
|
|
||||||
|
|
||||||
struct _CallbackData
|
|
||||||
{
|
|
||||||
ClutterActor *stage;
|
|
||||||
ClutterActor *tex;
|
|
||||||
ClutterActor *box;
|
|
||||||
ClutterMotionEvent event;
|
|
||||||
guint idle_source;
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
|
||||||
test_stage_read_pixels_main (int argc, char **argv);
|
|
||||||
|
|
||||||
const char *
|
|
||||||
test_stage_read_pixels_describe (void);
|
|
||||||
|
|
||||||
static ClutterActor *
|
|
||||||
make_label (void)
|
|
||||||
{
|
|
||||||
ClutterActor *label;
|
|
||||||
gchar *text;
|
|
||||||
const char *argv[] = { "ls", "--help", NULL };
|
|
||||||
|
|
||||||
label = clutter_text_new ();
|
|
||||||
clutter_text_set_font_name (CLUTTER_TEXT (label), "Sans 10");
|
|
||||||
|
|
||||||
if (g_spawn_sync (NULL, (char **) argv, NULL,
|
|
||||||
G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_SEARCH_PATH,
|
|
||||||
NULL, NULL, &text, NULL, NULL, NULL))
|
|
||||||
{
|
|
||||||
clutter_text_set_text (CLUTTER_TEXT (label), text);
|
|
||||||
g_free (text);
|
|
||||||
}
|
|
||||||
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ClutterActor *
|
|
||||||
make_tex (void)
|
|
||||||
{
|
|
||||||
ClutterActor *tex = clutter_texture_new ();
|
|
||||||
|
|
||||||
clutter_actor_set_size (tex, TEX_SIZE * 2, TEX_SIZE * 2);
|
|
||||||
|
|
||||||
return tex;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ClutterActor *
|
|
||||||
make_box (void)
|
|
||||||
{
|
|
||||||
ClutterActor *box;
|
|
||||||
static const ClutterColor blue = { 0x00, 0x00, 0xff, 0xff };
|
|
||||||
|
|
||||||
box = clutter_rectangle_new_with_color (&blue);
|
|
||||||
clutter_actor_set_size (box, DOT_SIZE + 2, DOT_SIZE + 2);
|
|
||||||
clutter_actor_hide (box);
|
|
||||||
|
|
||||||
return box;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
on_motion_idle (gpointer user_data)
|
|
||||||
{
|
|
||||||
CallbackData *data = (CallbackData *) user_data;
|
|
||||||
guchar *pixels, *p;
|
|
||||||
gfloat stage_width, stage_height;
|
|
||||||
gint x, y;
|
|
||||||
|
|
||||||
data->idle_source = 0;
|
|
||||||
|
|
||||||
clutter_actor_get_size (data->stage, &stage_width, &stage_height);
|
|
||||||
|
|
||||||
x = CLAMP (data->event.x - TEX_SIZE / 2, 0, stage_width - TEX_SIZE);
|
|
||||||
y = CLAMP (data->event.y - TEX_SIZE / 2, 0, stage_height - TEX_SIZE);
|
|
||||||
|
|
||||||
clutter_actor_set_position (data->box,
|
|
||||||
x + TEX_SIZE / 2 - 1,
|
|
||||||
y + TEX_SIZE / 2 - 1);
|
|
||||||
clutter_actor_show (data->box);
|
|
||||||
|
|
||||||
/* Redraw so that the layouting will be done and the box will be
|
|
||||||
drawn in the right position */
|
|
||||||
clutter_stage_ensure_redraw (CLUTTER_STAGE (data->stage));
|
|
||||||
|
|
||||||
pixels = clutter_stage_read_pixels (CLUTTER_STAGE (data->stage),
|
|
||||||
x, y,
|
|
||||||
TEX_SIZE, TEX_SIZE);
|
|
||||||
|
|
||||||
/* Make a red dot in the center */
|
|
||||||
p = pixels + (TEX_SIZE / 2 - DOT_SIZE / 2) * TEX_SIZE * 4
|
|
||||||
+ (TEX_SIZE / 2 - DOT_SIZE / 2) * 4;
|
|
||||||
for (y = 0; y < DOT_SIZE; y++)
|
|
||||||
{
|
|
||||||
for (x = 0; x < DOT_SIZE; x++)
|
|
||||||
{
|
|
||||||
*(p++) = 255;
|
|
||||||
memset (p, 0, 3);
|
|
||||||
p += 3;
|
|
||||||
}
|
|
||||||
p += TEX_SIZE * 4 - DOT_SIZE * 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set all of the alpa values to full */
|
|
||||||
for (p = pixels + TEX_SIZE * TEX_SIZE * 4; p > pixels; p -= 4)
|
|
||||||
*(p - 1) = 255;
|
|
||||||
|
|
||||||
clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (data->tex),
|
|
||||||
pixels, TRUE,
|
|
||||||
TEX_SIZE, TEX_SIZE,
|
|
||||||
TEX_SIZE * 4, 4, 0, NULL);
|
|
||||||
g_free (pixels);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
on_motion (ClutterActor *stage, ClutterMotionEvent *event, CallbackData *data)
|
|
||||||
{
|
|
||||||
/* Handle the motion event in an idle handler so that multiple
|
|
||||||
events will be combined into one */
|
|
||||||
if (data->idle_source == 0)
|
|
||||||
data->idle_source = clutter_threads_add_idle (on_motion_idle, data);
|
|
||||||
|
|
||||||
data->event = *event;
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_MODULE_EXPORT int
|
|
||||||
test_stage_read_pixels_main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
CallbackData data;
|
|
||||||
|
|
||||||
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
data.idle_source = 0;
|
|
||||||
data.stage = clutter_stage_new ();
|
|
||||||
clutter_stage_set_title (CLUTTER_STAGE (data.stage), "Read Pixels");
|
|
||||||
g_signal_connect (data.stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
|
||||||
|
|
||||||
data.tex = make_tex ();
|
|
||||||
data.box = make_box ();
|
|
||||||
clutter_actor_set_position (data.tex,
|
|
||||||
clutter_actor_get_width (data.stage)
|
|
||||||
- clutter_actor_get_width (data.tex),
|
|
||||||
clutter_actor_get_height (data.stage)
|
|
||||||
- clutter_actor_get_height (data.tex));
|
|
||||||
|
|
||||||
clutter_container_add (CLUTTER_CONTAINER (data.stage),
|
|
||||||
make_label (), data.tex, data.box, NULL);
|
|
||||||
|
|
||||||
g_signal_connect (data.stage, "motion-event", G_CALLBACK (on_motion), &data);
|
|
||||||
|
|
||||||
clutter_actor_show (data.stage);
|
|
||||||
|
|
||||||
clutter_main ();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_MODULE_EXPORT const char *
|
|
||||||
test_stage_read_pixels_describe (void)
|
|
||||||
{
|
|
||||||
return "Read back pixels from a Stage.";
|
|
||||||
}
|
|
@ -1,160 +0,0 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <gmodule.h>
|
|
||||||
#include <clutter/clutter.h>
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
LOAD_SYNC,
|
|
||||||
LOAD_DATA_ASYNC,
|
|
||||||
LOAD_ASYNC
|
|
||||||
};
|
|
||||||
|
|
||||||
static ClutterActor *stage = NULL;
|
|
||||||
|
|
||||||
const char *
|
|
||||||
test_texture_async_describe (void);
|
|
||||||
|
|
||||||
gint
|
|
||||||
test_texture_async_main (int argc, char *argv[]);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
size_change_cb (ClutterTexture *texture,
|
|
||||||
gint width,
|
|
||||||
gint height,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
clutter_actor_set_size (user_data, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
gboolean task (gpointer user_data)
|
|
||||||
{
|
|
||||||
const gchar *path = user_data;
|
|
||||||
ClutterActor *image[3];
|
|
||||||
ClutterActor *clone[3];
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
image[1] = g_object_new (CLUTTER_TYPE_TEXTURE,
|
|
||||||
"load-data-async", TRUE,
|
|
||||||
NULL);
|
|
||||||
g_signal_connect (image[1], "load-finished",
|
|
||||||
G_CALLBACK (on_load_finished),
|
|
||||||
GINT_TO_POINTER (LOAD_DATA_ASYNC));
|
|
||||||
image[2] = g_object_new (CLUTTER_TYPE_TEXTURE,
|
|
||||||
"load-async", TRUE,
|
|
||||||
NULL);
|
|
||||||
g_signal_connect (image[2], "load-finished",
|
|
||||||
G_CALLBACK (on_load_finished),
|
|
||||||
GINT_TO_POINTER (LOAD_ASYNC));
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), image[i]);
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
clutter_actor_set_position (image[i], 50 + i * 100, 0 + i * 50);
|
|
||||||
clutter_actor_set_depth (image[i], -2500);
|
|
||||||
|
|
||||||
clone[i] = clutter_clone_new (image[i]);
|
|
||||||
g_signal_connect (image[i], "size-change",
|
|
||||||
G_CALLBACK (size_change_cb), clone[i]);
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), clone[i]);
|
|
||||||
clutter_actor_set_position (clone[i], 50 + i * 100, 150 + i * 50 + 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cleanup_task (gpointer data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
G_MODULE_EXPORT gint
|
|
||||||
test_texture_async_main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
gchar *path;
|
|
||||||
|
|
||||||
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
stage = clutter_stage_new ();
|
|
||||||
clutter_stage_set_title (CLUTTER_STAGE (stage), "Asynchronous Texture Loading");
|
|
||||||
clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue);
|
|
||||||
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
|
||||||
|
|
||||||
clutter_actor_show (stage);
|
|
||||||
|
|
||||||
path = (argc > 1)
|
|
||||||
? g_strdup (argv[1])
|
|
||||||
: g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
|
|
||||||
|
|
||||||
clutter_threads_add_timeout_full (G_PRIORITY_DEFAULT, 500,
|
|
||||||
task, path,
|
|
||||||
cleanup_task);
|
|
||||||
|
|
||||||
clutter_main ();
|
|
||||||
|
|
||||||
g_free (path);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_MODULE_EXPORT const char *
|
|
||||||
test_texture_async_describe (void)
|
|
||||||
{
|
|
||||||
return "Texture asynchronous loading using threads";
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include <gmodule.h>
|
|
||||||
#include <clutter/clutter.h>
|
|
||||||
|
|
||||||
int
|
|
||||||
test_texture_material_main (int argc, char *argv[]);
|
|
||||||
|
|
||||||
G_MODULE_EXPORT int
|
|
||||||
test_texture_material_main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
ClutterActor *stage, *box;
|
|
||||||
ClutterLayoutManager *manager;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
stage = clutter_stage_new ();
|
|
||||||
clutter_stage_set_title (CLUTTER_STAGE (stage), "Texture Material");
|
|
||||||
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
|
||||||
|
|
||||||
manager = clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL);
|
|
||||||
box = clutter_box_new (manager);
|
|
||||||
clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, -25.0));
|
|
||||||
clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_HEIGHT, -25.0));
|
|
||||||
clutter_actor_set_position (box, 25.0, 25.0);
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
|
||||||
|
|
||||||
for (i = 0; i < 48; i++)
|
|
||||||
{
|
|
||||||
ClutterActor *texture = clutter_texture_new ();
|
|
||||||
|
|
||||||
clutter_texture_set_load_data_async (CLUTTER_TEXTURE (texture), TRUE);
|
|
||||||
clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture), TRUE);
|
|
||||||
clutter_texture_set_from_file (CLUTTER_TEXTURE (texture),
|
|
||||||
TESTS_DATADIR "/redhand.png",
|
|
||||||
NULL);
|
|
||||||
clutter_actor_set_width (texture, 96);
|
|
||||||
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (box), texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
clutter_actor_show (stage);
|
|
||||||
|
|
||||||
clutter_main ();
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
@ -1,131 +0,0 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <gmodule.h>
|
|
||||||
|
|
||||||
#include <clutter/clutter.h>
|
|
||||||
|
|
||||||
int
|
|
||||||
test_textures_main (int argc, char *argv[]);
|
|
||||||
|
|
||||||
const char *
|
|
||||||
test_texture_slicing_describe (void);
|
|
||||||
|
|
||||||
static guchar *
|
|
||||||
make_rgba_data (int width, int height, int bpp, int has_alpha, int *rowstride_p)
|
|
||||||
{
|
|
||||||
#define CHECK_SIZE 20
|
|
||||||
|
|
||||||
gint x,y, rowstride, i = 0;
|
|
||||||
guchar *pixels;
|
|
||||||
|
|
||||||
g_assert(bpp == 4);
|
|
||||||
g_assert(has_alpha == TRUE);
|
|
||||||
|
|
||||||
rowstride = width * bpp;
|
|
||||||
*rowstride_p = rowstride;
|
|
||||||
|
|
||||||
pixels = g_try_malloc (height * rowstride);
|
|
||||||
if (!pixels)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
for (x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
guchar *p;
|
|
||||||
|
|
||||||
p = pixels + y * rowstride + x * bpp;
|
|
||||||
|
|
||||||
p[0] = p[1] = p[2] = 0; p[3] = 0xff;
|
|
||||||
|
|
||||||
if (x && y && y % CHECK_SIZE && x % CHECK_SIZE)
|
|
||||||
{
|
|
||||||
if (x % CHECK_SIZE == 1)
|
|
||||||
{
|
|
||||||
if (++i > 3)
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
p[i] = 0xff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pixels;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
exit_on_destroy (ClutterActor *actor)
|
|
||||||
{
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SPIN() while (g_main_context_pending (NULL)) \
|
|
||||||
g_main_context_iteration (NULL, FALSE);
|
|
||||||
|
|
||||||
G_MODULE_EXPORT int
|
|
||||||
test_textures_main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
ClutterActor *texture;
|
|
||||||
ClutterActor *stage;
|
|
||||||
gint i, j;
|
|
||||||
|
|
||||||
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
stage = clutter_stage_new ();
|
|
||||||
clutter_actor_show_all (CLUTTER_ACTOR (stage));
|
|
||||||
g_signal_connect (stage, "destroy", G_CALLBACK (exit_on_destroy), NULL);
|
|
||||||
|
|
||||||
SPIN();
|
|
||||||
|
|
||||||
for (i=100; i<=5000; i += 100)
|
|
||||||
for (j=0; j<4; j++)
|
|
||||||
{
|
|
||||||
const int width = i+j;
|
|
||||||
const int height = i+j;
|
|
||||||
const gboolean has_alpha = TRUE;
|
|
||||||
const int bpp = has_alpha ? 4 : 3;
|
|
||||||
int rowstride;
|
|
||||||
guchar *pixels;
|
|
||||||
|
|
||||||
pixels = make_rgba_data (width, height, bpp, has_alpha, &rowstride);
|
|
||||||
if (!pixels)
|
|
||||||
g_error("No memory for %ix%i RGBA data failed", width, height);
|
|
||||||
|
|
||||||
printf("o %ix%i texture... ", width, height);
|
|
||||||
|
|
||||||
texture = clutter_texture_new ();
|
|
||||||
if (!clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture),
|
|
||||||
pixels,
|
|
||||||
has_alpha,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
rowstride,
|
|
||||||
bpp,
|
|
||||||
0, NULL))
|
|
||||||
g_error("texture creation failed");
|
|
||||||
g_free(pixels);
|
|
||||||
|
|
||||||
printf("uploaded to texture...\n");
|
|
||||||
|
|
||||||
clutter_container_add (CLUTTER_CONTAINER (stage), texture, NULL);
|
|
||||||
clutter_actor_set_size (texture, 400, 400);
|
|
||||||
clutter_actor_show (texture);
|
|
||||||
|
|
||||||
/* Hide & show to unreaise then realise the texture */
|
|
||||||
clutter_actor_hide (texture);
|
|
||||||
clutter_actor_show (texture);
|
|
||||||
|
|
||||||
SPIN();
|
|
||||||
|
|
||||||
clutter_container_remove (CLUTTER_CONTAINER (stage), texture, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_MODULE_EXPORT const char *
|
|
||||||
test_texture_slicing_describe (void)
|
|
||||||
{
|
|
||||||
return "Check texture slicing support in CoglTexture";
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user