2011-05-05 22:34:38 +00:00
|
|
|
#include <cogl/cogl.h>
|
2013-04-28 02:22:24 +00:00
|
|
|
#include <cogl-path/cogl-path.h>
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-21 22:41:44 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-01-20 10:41:48 +00:00
|
|
|
#include "test-declarations.h"
|
2011-10-21 22:41:44 +00:00
|
|
|
#include "test-utils.h"
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
#define BLOCK_SIZE 16
|
|
|
|
|
|
|
|
/* Number of pixels at the border of a block quadrant to skip when verifying */
|
|
|
|
#define TEST_INSET 1
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
2011-10-21 22:41:44 +00:00
|
|
|
int dummy;
|
2011-05-05 22:34:38 +00:00
|
|
|
} TestState;
|
|
|
|
|
|
|
|
static void
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (CoglPath *path, CoglPipeline *pipeline, int x, int y)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_push_matrix (test_fb);
|
|
|
|
cogl_framebuffer_translate (test_fb, x * BLOCK_SIZE, y * BLOCK_SIZE, 0.0f);
|
2012-04-18 14:57:33 +00:00
|
|
|
|
2019-11-22 11:07:59 +00:00
|
|
|
cogl_framebuffer_fill_path (test_fb, pipeline, path);
|
2012-04-18 14:57:33 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_pop_matrix (test_fb);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-21 22:41:44 +00:00
|
|
|
check_block (int block_x, int block_y, int block_mask)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
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 data[BLOCK_SIZE * BLOCK_SIZE];
|
2011-05-05 22:34:38 +00:00
|
|
|
int qx, qy;
|
|
|
|
|
|
|
|
/* Block mask represents which quarters of the block should be
|
|
|
|
filled. The bits from 0->3 represent the top left, top right,
|
|
|
|
bottom left and bottom right respectively */
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_read_pixels (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
block_x * BLOCK_SIZE,
|
|
|
|
block_y * BLOCK_SIZE,
|
|
|
|
BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
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
|
|
|
(uint8_t *)data);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
for (qy = 0; qy < 2; qy++)
|
|
|
|
for (qx = 0; qx < 2; qx++)
|
|
|
|
{
|
|
|
|
int bit = qx | (qy << 1);
|
2011-10-21 22:41:44 +00:00
|
|
|
const char *intended_pixel = ((block_mask & (1 << bit)) ? "#ffffff" : "#000000");
|
2011-05-05 22:34:38 +00:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
for (x = 0; x < BLOCK_SIZE / 2 - TEST_INSET * 2; x++)
|
|
|
|
for (y = 0; y < BLOCK_SIZE / 2 - TEST_INSET * 2; y++)
|
|
|
|
{
|
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
|
|
|
const uint32_t *p = data + (qx * BLOCK_SIZE / 2 +
|
2011-10-21 22:41:44 +00:00
|
|
|
qy * BLOCK_SIZE * BLOCK_SIZE / 2 +
|
|
|
|
(x + TEST_INSET) +
|
|
|
|
(y + TEST_INSET) * BLOCK_SIZE);
|
|
|
|
char *screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (*p) >> 8);
|
|
|
|
g_assert_cmpstr (screen_pixel, ==, intended_pixel);
|
|
|
|
g_free (screen_pixel);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-21 22:41:44 +00:00
|
|
|
paint (TestState *state)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2012-04-18 14:57:33 +00:00
|
|
|
CoglPath *path_a, *path_b, *path_c;
|
2013-01-18 17:57:06 +00:00
|
|
|
CoglPipeline *white = cogl_pipeline_new (test_ctx);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-04-18 14:57:33 +00:00
|
|
|
cogl_pipeline_set_color4f (white, 1, 1, 1, 1);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Create a path filling just a quarter of a block. It will use two
|
|
|
|
rectangles so that we have a sub path in the path */
|
2013-04-28 02:22:24 +00:00
|
|
|
path_a = cogl_path_new ();
|
|
|
|
cogl_path_rectangle (path_a,
|
|
|
|
BLOCK_SIZE * 3 / 4, BLOCK_SIZE / 2,
|
2011-05-05 22:34:38 +00:00
|
|
|
BLOCK_SIZE, BLOCK_SIZE);
|
2013-04-28 02:22:24 +00:00
|
|
|
cogl_path_rectangle (path_a,
|
|
|
|
BLOCK_SIZE / 2, BLOCK_SIZE / 2,
|
2011-05-05 22:34:38 +00:00
|
|
|
BLOCK_SIZE * 3 / 4, BLOCK_SIZE);
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_a, white, 0, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Create another path filling the whole block */
|
2013-04-28 02:22:24 +00:00
|
|
|
path_b = cogl_path_new ();
|
|
|
|
cogl_path_rectangle (path_b, 0, 0, BLOCK_SIZE, BLOCK_SIZE);
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_b, white, 1, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Draw the first path again */
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_a, white, 2, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Draw a copy of path a */
|
|
|
|
path_c = cogl_path_copy (path_a);
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_c, white, 3, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Add another rectangle to path a. We'll use line_to's instead of
|
|
|
|
cogl_rectangle so that we don't create another sub-path because
|
|
|
|
that is more likely to break the copy */
|
2013-04-28 02:22:24 +00:00
|
|
|
cogl_path_line_to (path_a, 0, BLOCK_SIZE / 2);
|
|
|
|
cogl_path_line_to (path_a, 0, 0);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE / 2, 0);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE / 2, BLOCK_SIZE / 2);
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_a, white, 4, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Draw the copy again. It should not have changed */
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_c, white, 5, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Add another rectangle to path c. It will be added in two halves,
|
|
|
|
one as an extension of the previous path and the other as a new
|
|
|
|
sub path */
|
2013-04-28 02:22:24 +00:00
|
|
|
cogl_path_line_to (path_c, BLOCK_SIZE / 2, 0);
|
|
|
|
cogl_path_line_to (path_c, BLOCK_SIZE * 3 / 4, 0);
|
|
|
|
cogl_path_line_to (path_c, BLOCK_SIZE * 3 / 4, BLOCK_SIZE / 2);
|
|
|
|
cogl_path_line_to (path_c, BLOCK_SIZE / 2, BLOCK_SIZE / 2);
|
|
|
|
cogl_path_rectangle (path_c,
|
|
|
|
BLOCK_SIZE * 3 / 4, 0, BLOCK_SIZE, BLOCK_SIZE / 2);
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_c, white, 6, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Draw the original path again. It should not have changed */
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_a, white, 7, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-04-18 14:57:33 +00:00
|
|
|
cogl_object_unref (path_a);
|
|
|
|
cogl_object_unref (path_b);
|
|
|
|
cogl_object_unref (path_c);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Draw a self-intersecting path. The part that intersects should be
|
|
|
|
inverted */
|
2013-04-28 02:22:24 +00:00
|
|
|
path_a = cogl_path_new ();
|
|
|
|
cogl_path_rectangle (path_a, 0, 0, BLOCK_SIZE, BLOCK_SIZE);
|
|
|
|
cogl_path_line_to (path_a, 0, BLOCK_SIZE / 2);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE / 2, BLOCK_SIZE / 2);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE / 2, 0);
|
|
|
|
cogl_path_close (path_a);
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_a, white, 8, 0);
|
|
|
|
cogl_object_unref (path_a);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Draw two sub paths. Where the paths intersect it should be
|
|
|
|
inverted */
|
2013-04-28 02:22:24 +00:00
|
|
|
path_a = cogl_path_new ();
|
|
|
|
cogl_path_rectangle (path_a, 0, 0, BLOCK_SIZE, BLOCK_SIZE);
|
|
|
|
cogl_path_rectangle (path_a,
|
|
|
|
BLOCK_SIZE / 2, BLOCK_SIZE / 2, BLOCK_SIZE, BLOCK_SIZE);
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_a, white, 9, 0);
|
|
|
|
cogl_object_unref (path_a);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Draw a clockwise outer path */
|
2013-04-28 02:22:24 +00:00
|
|
|
path_a = cogl_path_new ();
|
|
|
|
cogl_path_move_to (path_a, 0, 0);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE, 0);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE, BLOCK_SIZE);
|
|
|
|
cogl_path_line_to (path_a, 0, BLOCK_SIZE);
|
|
|
|
cogl_path_close (path_a);
|
2011-05-05 22:34:38 +00:00
|
|
|
/* Add a clockwise sub path in the upper left quadrant */
|
2013-04-28 02:22:24 +00:00
|
|
|
cogl_path_move_to (path_a, 0, 0);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE / 2, 0);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE / 2, BLOCK_SIZE / 2);
|
|
|
|
cogl_path_line_to (path_a, 0, BLOCK_SIZE / 2);
|
|
|
|
cogl_path_close (path_a);
|
2011-05-05 22:34:38 +00:00
|
|
|
/* Add a counter-clockwise sub path in the upper right quadrant */
|
2013-04-28 02:22:24 +00:00
|
|
|
cogl_path_move_to (path_a, BLOCK_SIZE / 2, 0);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE / 2, BLOCK_SIZE / 2);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE, BLOCK_SIZE / 2);
|
|
|
|
cogl_path_line_to (path_a, BLOCK_SIZE, 0);
|
|
|
|
cogl_path_close (path_a);
|
2011-05-05 22:34:38 +00:00
|
|
|
/* Retain the path for the next test */
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_a, white, 10, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* Draw the same path again with the other fill rule */
|
2013-04-28 02:22:24 +00:00
|
|
|
cogl_path_set_fill_rule (path_a, COGL_PATH_FILL_RULE_NON_ZERO);
|
2012-04-18 14:57:33 +00:00
|
|
|
draw_path_at (path_a, white, 11, 0);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-04-18 14:57:33 +00:00
|
|
|
cogl_object_unref (path_a);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-21 22:41:44 +00:00
|
|
|
static void
|
2019-01-20 10:38:06 +00:00
|
|
|
validate_result (void)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2011-10-21 22:41:44 +00:00
|
|
|
check_block (0, 0, 0x8 /* bottom right */);
|
|
|
|
check_block (1, 0, 0xf /* all of them */);
|
|
|
|
check_block (2, 0, 0x8 /* bottom right */);
|
|
|
|
check_block (3, 0, 0x8 /* bottom right */);
|
|
|
|
check_block (4, 0, 0x9 /* top left and bottom right */);
|
|
|
|
check_block (5, 0, 0x8 /* bottom right */);
|
|
|
|
check_block (6, 0, 0xa /* bottom right and top right */);
|
|
|
|
check_block (7, 0, 0x9 /* top_left and bottom right */);
|
|
|
|
check_block (8, 0, 0xe /* all but top left */);
|
|
|
|
check_block (9, 0, 0x7 /* all but bottom right */);
|
|
|
|
check_block (10, 0, 0xc /* bottom two */);
|
|
|
|
check_block (11, 0, 0xd /* all but top right */);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_path (void)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_orthographic (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
0, 0,
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_get_width (test_fb),
|
|
|
|
cogl_framebuffer_get_height (test_fb),
|
2012-03-16 19:54:13 +00:00
|
|
|
-1,
|
|
|
|
100);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2011-10-21 22:41:44 +00:00
|
|
|
paint (&state);
|
|
|
|
validate_result ();
|
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");
|
|
|
|
}
|
|
|
|
|