2
#include <clutter/clutter.h>
5
#include "test-conform-common.h"
11
#define FRAMEBUFFER_WIDTH 640
12
#define FRAMEBUFFER_HEIGHT 480
14
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
18
on_paint (ClutterActor *actor, void *state)
20
float saved_viewport[4];
21
CoglMatrix saved_projection;
22
CoglMatrix projection;
29
/* Save the Clutter viewport/matrices and load identity matrices */
31
cogl_get_viewport (saved_viewport);
32
cogl_get_projection_matrix (&saved_projection);
35
cogl_matrix_init_identity (&projection);
36
cogl_matrix_init_identity (&modelview);
38
cogl_set_projection_matrix (&projection);
39
cogl_set_modelview_matrix (&modelview);
41
data = g_malloc (FRAMEBUFFER_WIDTH * 4 * FRAMEBUFFER_HEIGHT);
42
tex = cogl_texture_new_from_data (FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT,
43
COGL_TEXTURE_NO_SLICING,
44
COGL_PIXEL_FORMAT_RGBA_8888, /* data fmt */
45
COGL_PIXEL_FORMAT_ANY, /* internal fmt */
46
FRAMEBUFFER_WIDTH * 4, /* rowstride */
49
offscreen = cogl_offscreen_new_to_texture (tex);
51
/* Set a scale and translate transform on the window framebuffer before
52
* switching to the offscreen framebuffer so we can verify it gets restored
55
* The test is going to draw a grid of 4 colors to a texture which we
56
* subsequently draw to the window with a fullscreen rectangle. This
57
* transform will flip the texture left to right, scale it to a quater of the
58
* window size and slide it to the top right of the window.
60
cogl_translate (0.5, 0.5, 0);
61
cogl_scale (-0.5, 0.5, 1);
63
cogl_push_framebuffer (offscreen);
65
/* Cogl should release the last reference when we call cogl_pop_framebuffer()
67
cogl_handle_unref (offscreen);
69
/* Setup something other than the identity matrix for the modelview so we can
70
* verify it gets restored when we call cogl_pop_framebuffer () */
74
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
75
cogl_rectangle (-0.5, 0.5, 0, 0);
76
/* green, top right */
77
cogl_set_source_color4ub (0x00, 0xff, 0x00, 0xff);
78
cogl_rectangle (0, 0.5, 0.5, 0);
79
/* blue, bottom left */
80
cogl_set_source_color4ub (0x00, 0x00, 0xff, 0xff);
81
cogl_rectangle (-0.5, 0, 0, -0.5);
82
/* white, bottom right */
83
cogl_set_source_color4ub (0xff, 0xff, 0xff, 0xff);
84
cogl_rectangle (0, 0, 0.5, -0.5);
86
cogl_pop_framebuffer ();
88
cogl_set_source_texture (tex);
89
cogl_rectangle (-1, 1, 1, -1);
91
cogl_handle_unref (tex);
93
/* NB: The texture is drawn flipped horizontally and scaled to fit in the
94
* top right corner of the window. */
97
cogl_read_pixels (FRAMEBUFFER_WIDTH - 1, 0, 1, 1,
98
COGL_READ_PIXELS_COLOR_BUFFER,
99
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
101
g_assert (pixel[RED] == 0xff && pixel[GREEN] == 0x00 && pixel[BLUE] == 0x00);
103
/* green, top left */
104
cogl_read_pixels ((FRAMEBUFFER_WIDTH/2), 0, 1, 1,
105
COGL_READ_PIXELS_COLOR_BUFFER,
106
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
108
g_assert (pixel[RED] == 0x00 && pixel[GREEN] == 0xff && pixel[BLUE] == 0x00);
110
/* blue, bottom right */
111
cogl_read_pixels (FRAMEBUFFER_WIDTH - 1, (FRAMEBUFFER_HEIGHT/2) - 1, 1, 1,
112
COGL_READ_PIXELS_COLOR_BUFFER,
113
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
115
g_assert (pixel[RED] == 0x00 && pixel[GREEN] == 0x00 && pixel[BLUE] == 0xff);
117
/* white, bottom left */
118
cogl_read_pixels ((FRAMEBUFFER_WIDTH/2), (FRAMEBUFFER_HEIGHT/2) - 1, 1, 1,
119
COGL_READ_PIXELS_COLOR_BUFFER,
120
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
122
g_assert (pixel[RED] == 0xff && pixel[GREEN] == 0xff && pixel[BLUE] == 0xff);
124
/* Comment this out if you want visual feedback of what this test
127
clutter_main_quit ();
131
queue_redraw (gpointer stage)
133
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
139
test_cogl_offscreen (TestConformSimpleFixture *fixture,
145
stage = clutter_stage_get_default ();
146
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
148
/* We force continuous redrawing of the stage, since we need to skip
149
* the first few frames, and we wont be doing anything else that
150
* will trigger redrawing. */
151
idle_source = g_idle_add (queue_redraw, stage);
152
g_signal_connect_after (stage, "paint", G_CALLBACK (on_paint), NULL);
154
clutter_actor_show (stage);
157
g_source_remove (idle_source);
159
/* Remove all of the actors from the stage */
160
clutter_container_foreach (CLUTTER_CONTAINER (stage),
161
(ClutterCallback) clutter_actor_destroy,
164
if (g_test_verbose ())