2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
|
|
|
#define RED 0
|
|
|
|
#define GREEN 1
|
|
|
|
#define BLUE 2
|
|
|
|
|
|
|
|
#define FRAMEBUFFER_WIDTH 640
|
|
|
|
#define FRAMEBUFFER_HEIGHT 480
|
|
|
|
|
|
|
|
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2020-10-23 19:14:38 +00:00
|
|
|
on_after_paint (ClutterActor *actor,
|
|
|
|
ClutterPaintContext *paint_context,
|
|
|
|
void *state)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
float saved_viewport[4];
|
2020-09-11 18:57:28 +00:00
|
|
|
graphene_matrix_t saved_projection;
|
|
|
|
graphene_matrix_t projection;
|
|
|
|
graphene_matrix_t modelview;
|
2011-05-05 22:34:38 +00:00
|
|
|
guchar *data;
|
|
|
|
CoglHandle tex;
|
|
|
|
CoglHandle offscreen;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint32_t *pixels;
|
|
|
|
uint8_t *pixelsc;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Save the Clutter viewport/matrices and load identity matrices */
|
|
|
|
|
|
|
|
cogl_get_viewport (saved_viewport);
|
|
|
|
cogl_get_projection_matrix (&saved_projection);
|
|
|
|
cogl_push_matrix ();
|
|
|
|
|
2020-09-11 22:46:31 +00:00
|
|
|
graphene_matrix_init_identity (&projection);
|
|
|
|
graphene_matrix_init_identity (&modelview);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
cogl_set_projection_matrix (&projection);
|
|
|
|
cogl_set_modelview_matrix (&modelview);
|
|
|
|
|
|
|
|
/* All offscreen rendering is done upside down so the first thing we
|
|
|
|
* verify is reading back grid of colors from a CoglOffscreen framebuffer
|
|
|
|
*/
|
|
|
|
|
|
|
|
data = g_malloc (FRAMEBUFFER_WIDTH * 4 * FRAMEBUFFER_HEIGHT);
|
2013-06-09 00:09:04 +00:00
|
|
|
tex = test_utils_texture_new_from_data (FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT,
|
|
|
|
TEST_UTILS_TEXTURE_NO_SLICING,
|
2011-05-05 22:34:38 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888, /* data fmt */
|
|
|
|
COGL_PIXEL_FORMAT_ANY, /* internal fmt */
|
|
|
|
FRAMEBUFFER_WIDTH * 4, /* rowstride */
|
|
|
|
data);
|
|
|
|
g_free (data);
|
2013-08-16 21:43:19 +00:00
|
|
|
offscreen = cogl_offscreen_new_with_texture (tex);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
cogl_push_framebuffer (offscreen);
|
|
|
|
|
|
|
|
/* red, top left */
|
|
|
|
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
|
|
|
cogl_rectangle (-1, 1, 0, 0);
|
|
|
|
/* green, top right */
|
|
|
|
cogl_set_source_color4ub (0x00, 0xff, 0x00, 0xff);
|
|
|
|
cogl_rectangle (0, 1, 1, 0);
|
|
|
|
/* blue, bottom left */
|
|
|
|
cogl_set_source_color4ub (0x00, 0x00, 0xff, 0xff);
|
|
|
|
cogl_rectangle (-1, 0, 0, -1);
|
|
|
|
/* white, bottom right */
|
|
|
|
cogl_set_source_color4ub (0xff, 0xff, 0xff, 0xff);
|
|
|
|
cogl_rectangle (0, 0, 1, -1);
|
|
|
|
|
|
|
|
pixels = g_malloc0 (FRAMEBUFFER_WIDTH * 4 * FRAMEBUFFER_HEIGHT);
|
|
|
|
cogl_read_pixels (0, 0, FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
(guchar *)pixels);
|
|
|
|
|
|
|
|
g_assert_cmpint (pixels[0], ==, 0xff0000ff);
|
|
|
|
g_assert_cmpint (pixels[FRAMEBUFFER_WIDTH - 1], ==, 0xff00ff00);
|
|
|
|
g_assert_cmpint (pixels[(FRAMEBUFFER_HEIGHT - 1) * FRAMEBUFFER_WIDTH], ==, 0xffff0000);
|
|
|
|
g_assert_cmpint (pixels[(FRAMEBUFFER_HEIGHT - 1) * FRAMEBUFFER_WIDTH + FRAMEBUFFER_WIDTH - 1], ==, 0xffffffff);
|
|
|
|
g_free (pixels);
|
|
|
|
|
|
|
|
cogl_pop_framebuffer ();
|
2020-10-13 09:35:47 +00:00
|
|
|
g_object_unref (offscreen);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Now verify reading back from an onscreen framebuffer...
|
|
|
|
*/
|
|
|
|
|
|
|
|
cogl_set_source_texture (tex);
|
|
|
|
cogl_rectangle (-1, 1, 1, -1);
|
|
|
|
|
|
|
|
pixels = g_malloc0 (FRAMEBUFFER_WIDTH * 4 * FRAMEBUFFER_HEIGHT);
|
|
|
|
cogl_read_pixels (0, 0, FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
(guchar *)pixels);
|
|
|
|
|
|
|
|
g_assert_cmpint (pixels[0], ==, 0xff0000ff);
|
|
|
|
g_assert_cmpint (pixels[FRAMEBUFFER_WIDTH - 1], ==, 0xff00ff00);
|
|
|
|
g_assert_cmpint (pixels[(FRAMEBUFFER_HEIGHT - 1) * FRAMEBUFFER_WIDTH], ==, 0xffff0000);
|
|
|
|
g_assert_cmpint (pixels[(FRAMEBUFFER_HEIGHT - 1) * FRAMEBUFFER_WIDTH + FRAMEBUFFER_WIDTH - 1], ==, 0xffffffff);
|
|
|
|
g_free (pixels);
|
|
|
|
|
|
|
|
/* Verify using BGR format */
|
|
|
|
|
|
|
|
cogl_set_source_texture (tex);
|
|
|
|
cogl_rectangle (-1, 1, 1, -1);
|
|
|
|
|
|
|
|
pixelsc = g_malloc0 (FRAMEBUFFER_WIDTH * 3 * FRAMEBUFFER_HEIGHT);
|
|
|
|
cogl_read_pixels (0, 0, FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
COGL_PIXEL_FORMAT_BGR_888,
|
|
|
|
(guchar *)pixelsc);
|
|
|
|
|
|
|
|
g_assert_cmpint (pixelsc[0], ==, 0x00);
|
|
|
|
g_assert_cmpint (pixelsc[1], ==, 0x00);
|
|
|
|
g_assert_cmpint (pixelsc[2], ==, 0xff);
|
|
|
|
|
|
|
|
g_assert_cmpint (pixelsc[(FRAMEBUFFER_WIDTH - 1) * 3 + 0], ==, 0x00);
|
|
|
|
g_assert_cmpint (pixelsc[(FRAMEBUFFER_WIDTH - 1) * 3 + 1], ==, 0xff);
|
|
|
|
g_assert_cmpint (pixelsc[(FRAMEBUFFER_WIDTH - 1) * 3 + 2], ==, 0x00);
|
|
|
|
|
|
|
|
g_free (pixelsc);
|
|
|
|
|
2019-02-20 13:51:12 +00:00
|
|
|
cogl_object_unref (tex);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Restore the viewport and matrices state */
|
|
|
|
cogl_set_viewport (saved_viewport[0],
|
|
|
|
saved_viewport[1],
|
|
|
|
saved_viewport[2],
|
|
|
|
saved_viewport[3]);
|
|
|
|
cogl_set_projection_matrix (&saved_projection);
|
|
|
|
cogl_pop_matrix ();
|
|
|
|
|
|
|
|
/* Comment this out if you want visual feedback of what this test
|
|
|
|
* paints.
|
|
|
|
*/
|
2020-07-09 19:28:57 +00:00
|
|
|
clutter_test_quit ();
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
queue_redraw (void *stage)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_readpixels (TestUtilsGTestFixture *fixture,
|
2011-05-05 22:34:38 +00:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
unsigned int idle_source;
|
|
|
|
ClutterActor *stage;
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
2020-06-26 19:43:45 +00:00
|
|
|
clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &stage_color);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* We force continuous redrawing of the stage, since we need to skip
|
2020-08-26 09:49:50 +00:00
|
|
|
* the first few frames, and we won't be doing anything else that
|
2011-05-05 22:34:38 +00:00
|
|
|
* will trigger redrawing. */
|
|
|
|
idle_source = g_idle_add (queue_redraw, stage);
|
2020-10-23 19:14:38 +00:00
|
|
|
g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), NULL);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
clutter_actor_show (stage);
|
2020-07-09 19:28:57 +00:00
|
|
|
clutter_test_main ();
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2019-11-21 23:25:30 +00:00
|
|
|
g_clear_handle_id (&idle_source, g_source_remove);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Remove all of the actors from the stage */
|
2019-10-14 14:38:59 +00:00
|
|
|
clutter_actor_remove_all_children (stage);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-02-23 12:30:51 +00:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 22:34:38 +00:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|
|
|
|
|