2009-09-17 09:25:29 -04:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
|
|
|
#define SOURCE_SIZE 32
|
|
|
|
#define SOURCE_DIVISIONS_X 2
|
|
|
|
#define SOURCE_DIVISIONS_Y 2
|
|
|
|
#define DIVISION_WIDTH (SOURCE_SIZE / SOURCE_DIVISIONS_X)
|
|
|
|
#define DIVISION_HEIGHT (SOURCE_SIZE / SOURCE_DIVISIONS_Y)
|
|
|
|
|
|
|
|
static const ClutterColor
|
|
|
|
corner_colors[SOURCE_DIVISIONS_X * SOURCE_DIVISIONS_Y] =
|
|
|
|
{
|
2009-11-01 20:23:25 -05:00
|
|
|
{ 0xff, 0x00, 0x00, 0xff }, /* red top left */
|
|
|
|
{ 0x00, 0xff, 0x00, 0xff }, /* green top right */
|
|
|
|
{ 0x00, 0x00, 0xff, 0xff }, /* blue bottom left */
|
|
|
|
{ 0xff, 0x00, 0xff, 0xff } /* purple bottom right */
|
2009-09-17 09:25:29 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
|
|
|
guint frame;
|
2013-07-02 17:00:23 -04:00
|
|
|
gboolean was_painted;
|
2009-09-17 09:25:29 -04:00
|
|
|
} TestState;
|
|
|
|
|
|
|
|
static ClutterActor *
|
|
|
|
create_source (void)
|
|
|
|
{
|
|
|
|
int x, y;
|
2020-06-26 15:26:49 -04:00
|
|
|
ClutterActor *group = clutter_actor_new ();
|
2009-09-17 09:25:29 -04:00
|
|
|
|
|
|
|
/* Create a group with a different coloured rectangle at each
|
|
|
|
corner */
|
|
|
|
for (y = 0; y < SOURCE_DIVISIONS_Y; y++)
|
|
|
|
for (x = 0; x < SOURCE_DIVISIONS_X; x++)
|
|
|
|
{
|
|
|
|
ClutterActor *rect = clutter_rectangle_new ();
|
|
|
|
clutter_actor_set_size (rect, DIVISION_WIDTH, DIVISION_HEIGHT);
|
|
|
|
clutter_actor_set_position (rect,
|
|
|
|
DIVISION_WIDTH * x,
|
|
|
|
DIVISION_HEIGHT * y);
|
|
|
|
clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect),
|
|
|
|
corner_colors +
|
|
|
|
(y * SOURCE_DIVISIONS_X + x));
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pre_paint_clip_cb (void)
|
|
|
|
{
|
|
|
|
/* Generate a clip path that clips out the top left division */
|
|
|
|
cogl_path_move_to (DIVISION_WIDTH, 0);
|
|
|
|
cogl_path_line_to (SOURCE_SIZE, 0);
|
|
|
|
cogl_path_line_to (SOURCE_SIZE, SOURCE_SIZE);
|
|
|
|
cogl_path_line_to (0, SOURCE_SIZE);
|
|
|
|
cogl_path_line_to (0, DIVISION_HEIGHT);
|
|
|
|
cogl_path_line_to (DIVISION_WIDTH, DIVISION_HEIGHT);
|
|
|
|
cogl_path_close ();
|
|
|
|
cogl_clip_push_from_path ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
post_paint_clip_cb (void)
|
|
|
|
{
|
|
|
|
cogl_clip_pop ();
|
|
|
|
}
|
|
|
|
|
2013-08-27 08:47:16 -04:00
|
|
|
static void
|
2009-09-17 09:25:29 -04:00
|
|
|
validate_part (TestState *state,
|
|
|
|
int xpos, int ypos,
|
|
|
|
int clip_flags)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* Check whether the center of each division is the right color */
|
|
|
|
for (y = 0; y < SOURCE_DIVISIONS_Y; y++)
|
|
|
|
for (x = 0; x < SOURCE_DIVISIONS_X; x++)
|
|
|
|
{
|
|
|
|
guchar *pixels;
|
|
|
|
const ClutterColor *correct_color;
|
|
|
|
|
|
|
|
/* Read the center pixels of this division */
|
|
|
|
pixels = clutter_stage_read_pixels (CLUTTER_STAGE (state->stage),
|
|
|
|
x * DIVISION_WIDTH +
|
|
|
|
DIVISION_WIDTH / 2 + xpos,
|
|
|
|
y * DIVISION_HEIGHT +
|
|
|
|
DIVISION_HEIGHT / 2 + ypos,
|
|
|
|
1, 1);
|
|
|
|
|
|
|
|
/* If this division is clipped then it should be the stage
|
|
|
|
color */
|
|
|
|
if ((clip_flags & (1 << ((y * SOURCE_DIVISIONS_X) + x))))
|
|
|
|
correct_color = &stage_color;
|
|
|
|
else
|
|
|
|
/* Otherwise it should be the color for this division */
|
|
|
|
correct_color = corner_colors + (y * SOURCE_DIVISIONS_X) + x;
|
|
|
|
|
2013-06-24 15:30:40 -04:00
|
|
|
g_assert (pixels != NULL);
|
|
|
|
g_assert_cmpint (pixels[0], ==, correct_color->red);
|
|
|
|
g_assert_cmpint (pixels[1], ==, correct_color->green);
|
|
|
|
g_assert_cmpint (pixels[2], ==, correct_color->blue);
|
2009-09-17 09:25:29 -04:00
|
|
|
|
|
|
|
g_free (pixels);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
validate_result (TestState *state)
|
|
|
|
{
|
|
|
|
int ypos = 0;
|
|
|
|
|
2020-06-05 13:40:27 -04:00
|
|
|
if (!g_test_quiet ())
|
2009-09-17 09:25:29 -04:00
|
|
|
g_print ("Testing onscreen clone...\n");
|
2013-06-24 15:30:40 -04:00
|
|
|
validate_part (state, SOURCE_SIZE, ypos * SOURCE_SIZE, 0);
|
2009-09-17 09:25:29 -04:00
|
|
|
ypos++;
|
|
|
|
|
|
|
|
#if 0 /* this doesn't work */
|
2020-06-05 13:40:27 -04:00
|
|
|
if (!g_test_quiet ())
|
2009-09-17 09:25:29 -04:00
|
|
|
g_print ("Testing offscreen clone...\n");
|
2013-06-24 15:30:40 -04:00
|
|
|
validate_part (state, SOURCE_SIZE, ypos * SOURCE_SIZE, 0);
|
2009-09-17 09:25:29 -04:00
|
|
|
#endif
|
|
|
|
ypos++;
|
|
|
|
|
2020-06-05 13:40:27 -04:00
|
|
|
if (!g_test_quiet ())
|
2009-09-17 09:25:29 -04:00
|
|
|
g_print ("Testing onscreen clone with rectangular clip...\n");
|
2013-06-24 15:30:40 -04:00
|
|
|
validate_part (state, SOURCE_SIZE, ypos * SOURCE_SIZE, ~1);
|
2009-09-17 09:25:29 -04:00
|
|
|
ypos++;
|
|
|
|
|
2020-06-05 13:40:27 -04:00
|
|
|
if (!g_test_quiet ())
|
2009-09-17 09:25:29 -04:00
|
|
|
g_print ("Testing onscreen clone with path clip...\n");
|
2013-06-24 15:30:40 -04:00
|
|
|
validate_part (state, SOURCE_SIZE, ypos * SOURCE_SIZE, 1);
|
2009-09-17 09:25:29 -04:00
|
|
|
ypos++;
|
|
|
|
}
|
|
|
|
|
2013-07-02 17:00:23 -04:00
|
|
|
static gboolean
|
|
|
|
on_paint (gpointer data)
|
2009-09-17 09:25:29 -04:00
|
|
|
{
|
2013-07-02 17:00:23 -04:00
|
|
|
TestState *state = data;
|
2009-09-17 09:25:29 -04:00
|
|
|
int frame_num;
|
|
|
|
|
2010-07-08 14:20:33 -04:00
|
|
|
/* XXX: validate_result calls clutter_stage_read_pixels which will result in
|
|
|
|
* another paint run so to avoid infinite recursion we only aim to validate
|
|
|
|
* the first frame. */
|
2009-09-17 09:25:29 -04:00
|
|
|
frame_num = state->frame++;
|
2010-07-08 14:20:33 -04:00
|
|
|
if (frame_num == 1)
|
2009-09-17 09:25:29 -04:00
|
|
|
validate_result (state);
|
|
|
|
|
2013-07-02 17:00:23 -04:00
|
|
|
state->was_painted = TRUE;
|
2009-09-17 09:25:29 -04:00
|
|
|
|
2013-07-02 17:00:23 -04:00
|
|
|
return G_SOURCE_REMOVE;
|
2009-09-17 09:25:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-27 07:54:23 -05:00
|
|
|
texture_fbo (TestConformSimpleFixture *fixture,
|
|
|
|
gconstpointer data)
|
2009-09-17 09:25:29 -04:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
ClutterActor *actor;
|
|
|
|
int ypos = 0;
|
|
|
|
|
|
|
|
state.frame = 0;
|
|
|
|
|
2011-11-08 12:04:44 -05:00
|
|
|
state.stage = clutter_stage_new ();
|
2009-09-17 09:25:29 -04:00
|
|
|
|
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (state.stage), &stage_color);
|
|
|
|
|
|
|
|
/* Onscreen source with clone next to it */
|
|
|
|
actor = create_source ();
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
|
|
|
|
clutter_actor_set_position (actor, 0, ypos * SOURCE_SIZE);
|
|
|
|
actor = clutter_texture_new_from_actor (actor);
|
|
|
|
clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE);
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
|
|
|
|
ypos++;
|
|
|
|
|
|
|
|
/* Offscreen source with clone */
|
|
|
|
#if 0 /* this doesn't work */
|
|
|
|
actor = create_source ();
|
|
|
|
actor = clutter_texture_new_from_actor (actor);
|
|
|
|
clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE);
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
|
|
|
|
#endif
|
|
|
|
ypos++;
|
|
|
|
|
|
|
|
/* Source clipped to the top left division */
|
|
|
|
actor = create_source ();
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
|
|
|
|
clutter_actor_set_position (actor, 0, ypos * SOURCE_SIZE);
|
|
|
|
clutter_actor_set_clip (actor, 0, 0, DIVISION_WIDTH, DIVISION_HEIGHT);
|
|
|
|
actor = clutter_texture_new_from_actor (actor);
|
|
|
|
clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE);
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
|
|
|
|
ypos++;
|
|
|
|
|
|
|
|
/* Source clipped to everything but top left division using a
|
|
|
|
path */
|
|
|
|
actor = create_source ();
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
|
|
|
|
clutter_actor_set_position (actor, 0, ypos * SOURCE_SIZE);
|
|
|
|
g_signal_connect (actor, "paint",
|
|
|
|
G_CALLBACK (pre_paint_clip_cb), NULL);
|
|
|
|
g_signal_connect_after (actor, "paint",
|
|
|
|
G_CALLBACK (post_paint_clip_cb), NULL);
|
|
|
|
actor = clutter_texture_new_from_actor (actor);
|
|
|
|
clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE);
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
|
|
|
|
ypos++;
|
|
|
|
|
2013-07-02 17:00:23 -04:00
|
|
|
clutter_actor_show (state.stage);
|
2009-09-17 09:25:29 -04:00
|
|
|
|
2013-07-02 17:00:23 -04:00
|
|
|
clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT,
|
|
|
|
on_paint,
|
|
|
|
&state,
|
|
|
|
NULL);
|
2009-09-17 09:25:29 -04:00
|
|
|
|
2013-07-02 17:00:23 -04:00
|
|
|
while (!state.was_painted)
|
|
|
|
g_main_context_iteration (NULL, FALSE);
|
2009-09-17 09:25:29 -04:00
|
|
|
|
2011-11-08 12:04:44 -05:00
|
|
|
clutter_actor_destroy (state.stage);
|
2009-09-17 09:25:29 -04:00
|
|
|
}
|