2016-05-05 14:21:51 +00:00
|
|
|
#include "cogl-config.h"
|
2013-05-30 12:22:22 +00:00
|
|
|
|
2011-05-05 22:34:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-05-30 12:22:22 +00:00
|
|
|
#include "test-unit.h"
|
2011-05-05 22:34:38 +00:00
|
|
|
#include "test-utils.h"
|
|
|
|
|
2020-10-17 23:39:21 +00:00
|
|
|
#include "cogl/winsys/cogl-onscreen-glx.h"
|
|
|
|
#include "cogl/winsys/cogl-onscreen-xlib.h"
|
|
|
|
|
2011-09-19 14:24:08 +00:00
|
|
|
#define FB_WIDTH 512
|
|
|
|
#define FB_HEIGHT 512
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean cogl_test_is_verbose;
|
2012-02-23 12:30:51 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
CoglContext *test_ctx;
|
|
|
|
CoglFramebuffer *test_fb;
|
2012-03-16 19:54:13 +00:00
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2012-11-09 16:47:01 +00:00
|
|
|
check_flags (TestFlags flags,
|
|
|
|
CoglRenderer *renderer)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2012-03-06 23:41:49 +00:00
|
|
|
if (flags & TEST_REQUIREMENT_GL &&
|
2012-09-26 19:32:36 +00:00
|
|
|
cogl_renderer_get_driver (renderer) != COGL_DRIVER_GL &&
|
|
|
|
cogl_renderer_get_driver (renderer) != COGL_DRIVER_GL3)
|
2012-02-23 12:30:51 +00:00
|
|
|
{
|
2012-11-09 16:47:01 +00:00
|
|
|
return FALSE;
|
2012-02-23 12:30:51 +00:00
|
|
|
}
|
|
|
|
|
2014-01-14 15:52:45 +00:00
|
|
|
if (flags & TEST_REQUIREMENT_TEXTURE_RG &&
|
|
|
|
!cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_RG))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-10-17 20:40:26 +00:00
|
|
|
if (flags & TEST_REQUIREMENT_MAP_WRITE &&
|
2013-01-18 17:57:06 +00:00
|
|
|
!cogl_has_feature (test_ctx, COGL_FEATURE_ID_MAP_BUFFER_FOR_WRITE))
|
2012-10-17 20:40:26 +00:00
|
|
|
{
|
2012-11-09 16:47:01 +00:00
|
|
|
return FALSE;
|
2012-10-17 20:40:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 01:13:34 +00:00
|
|
|
if (flags & TEST_REQUIREMENT_FENCE &&
|
|
|
|
!cogl_has_feature (test_ctx, COGL_FEATURE_ID_FENCE))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-06 23:41:49 +00:00
|
|
|
if (flags & TEST_KNOWN_FAILURE)
|
|
|
|
{
|
2012-11-09 16:47:01 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2013-02-15 17:21:04 +00:00
|
|
|
is_boolean_env_set (const char *variable)
|
|
|
|
{
|
|
|
|
char *val = getenv (variable);
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean ret;
|
2013-02-15 17:21:04 +00:00
|
|
|
|
|
|
|
if (!val)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (g_ascii_strcasecmp (val, "1") == 0 ||
|
|
|
|
g_ascii_strcasecmp (val, "on") == 0 ||
|
|
|
|
g_ascii_strcasecmp (val, "true") == 0)
|
|
|
|
ret = TRUE;
|
|
|
|
else if (g_ascii_strcasecmp (val, "0") == 0 ||
|
|
|
|
g_ascii_strcasecmp (val, "off") == 0 ||
|
|
|
|
g_ascii_strcasecmp (val, "false") == 0)
|
|
|
|
ret = FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_critical ("Spurious boolean environment variable value (%s=%s)",
|
|
|
|
variable, val);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-17 23:39:21 +00:00
|
|
|
static CoglOnscreen *
|
|
|
|
create_onscreen (CoglContext *cogl_context,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
CoglDisplay *display = cogl_context_get_display (test_ctx);
|
|
|
|
CoglRenderer *renderer = cogl_display_get_renderer (display);
|
|
|
|
|
|
|
|
switch (cogl_renderer_get_winsys_id (renderer))
|
|
|
|
{
|
|
|
|
case COGL_WINSYS_ID_GLX:
|
|
|
|
#ifdef COGL_HAS_GLX_SUPPORT
|
|
|
|
return COGL_ONSCREEN (cogl_onscreen_glx_new (cogl_context,
|
|
|
|
width, height));
|
|
|
|
#else
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case COGL_WINSYS_ID_EGL_XLIB:
|
2022-04-05 13:01:29 +00:00
|
|
|
#ifdef COGL_HAS_EGL_PLATFORM_XLIB_SUPPORT
|
2020-10-17 23:39:21 +00:00
|
|
|
return COGL_ONSCREEN (cogl_onscreen_xlib_new (cogl_context,
|
|
|
|
width, height));
|
|
|
|
#else
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 14:16:25 +00:00
|
|
|
gboolean
|
2012-11-09 16:47:01 +00:00
|
|
|
test_utils_init (TestFlags requirement_flags,
|
|
|
|
TestFlags known_failure_flags)
|
|
|
|
{
|
|
|
|
static int counter = 0;
|
2019-06-18 06:02:10 +00:00
|
|
|
GError *error = NULL;
|
2012-11-09 16:47:01 +00:00
|
|
|
CoglOnscreen *onscreen = NULL;
|
|
|
|
CoglDisplay *display;
|
|
|
|
CoglRenderer *renderer;
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean missing_requirement;
|
|
|
|
gboolean known_failure;
|
2012-11-09 16:47:01 +00:00
|
|
|
|
|
|
|
if (counter != 0)
|
|
|
|
g_critical ("We don't support running more than one test at a time\n"
|
|
|
|
"in a single test run due to the state leakage that can\n"
|
|
|
|
"cause subsequent tests to fail.\n"
|
|
|
|
"\n"
|
|
|
|
"If you want to run all the tests you should run\n"
|
|
|
|
"$ make test-report");
|
|
|
|
counter++;
|
|
|
|
|
2013-02-15 17:21:04 +00:00
|
|
|
if (is_boolean_env_set ("COGL_TEST_VERBOSE") ||
|
|
|
|
is_boolean_env_set ("V"))
|
2012-11-09 16:47:01 +00:00
|
|
|
cogl_test_is_verbose = TRUE;
|
|
|
|
|
2013-06-20 17:24:58 +00:00
|
|
|
/* NB: This doesn't have any effect since commit 47444dac of glib
|
|
|
|
* because the environment variable is read in a magic constructor
|
|
|
|
* so it is too late to set them here */
|
2012-11-09 16:47:01 +00:00
|
|
|
if (g_getenv ("G_DEBUG"))
|
|
|
|
{
|
|
|
|
char *debug = g_strconcat (g_getenv ("G_DEBUG"), ",fatal-warnings", NULL);
|
|
|
|
g_setenv ("G_DEBUG", debug, TRUE);
|
|
|
|
g_free (debug);
|
2012-03-06 23:41:49 +00:00
|
|
|
}
|
2012-11-09 16:47:01 +00:00
|
|
|
else
|
|
|
|
g_setenv ("G_DEBUG", "fatal-warnings", TRUE);
|
|
|
|
|
|
|
|
g_setenv ("COGL_X11_SYNC", "1", 0);
|
|
|
|
|
|
|
|
test_ctx = cogl_context_new (NULL, &error);
|
|
|
|
if (!test_ctx)
|
|
|
|
g_critical ("Failed to create a CoglContext: %s", error->message);
|
|
|
|
|
|
|
|
display = cogl_context_get_display (test_ctx);
|
|
|
|
renderer = cogl_display_get_renderer (display);
|
|
|
|
|
|
|
|
missing_requirement = !check_flags (requirement_flags, renderer);
|
|
|
|
known_failure = !check_flags (known_failure_flags, renderer);
|
2012-03-06 23:41:49 +00:00
|
|
|
|
2013-02-15 17:21:04 +00:00
|
|
|
if (is_boolean_env_set ("COGL_TEST_ONSCREEN"))
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2020-10-17 23:39:21 +00:00
|
|
|
onscreen = create_onscreen (test_ctx, 640, 480);
|
2013-01-18 17:57:06 +00:00
|
|
|
test_fb = COGL_FRAMEBUFFER (onscreen);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-16 13:14:10 +00:00
|
|
|
CoglOffscreen *offscreen;
|
2013-01-18 17:57:06 +00:00
|
|
|
CoglTexture2D *tex = cogl_texture_2d_new_with_size (test_ctx,
|
2013-07-02 00:48:54 +00:00
|
|
|
FB_WIDTH, FB_HEIGHT);
|
2013-08-16 21:43:19 +00:00
|
|
|
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex));
|
2013-01-18 17:57:06 +00:00
|
|
|
test_fb = COGL_FRAMEBUFFER (offscreen);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
if (!cogl_framebuffer_allocate (test_fb, &error))
|
2011-05-05 22:34:38 +00:00
|
|
|
g_critical ("Failed to allocate framebuffer: %s", error->message);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_clear4f (test_fb,
|
2011-05-05 22:34:38 +00:00
|
|
|
COGL_BUFFER_BIT_COLOR |
|
|
|
|
COGL_BUFFER_BIT_DEPTH |
|
|
|
|
COGL_BUFFER_BIT_STENCIL,
|
|
|
|
0, 0, 0, 1);
|
|
|
|
|
2012-02-23 12:30:51 +00:00
|
|
|
if (missing_requirement)
|
|
|
|
g_print ("WARNING: Missing required feature[s] for this test\n");
|
2012-11-09 16:47:01 +00:00
|
|
|
else if (known_failure)
|
|
|
|
g_print ("WARNING: Test is known to fail\n");
|
2020-05-27 14:16:25 +00:00
|
|
|
|
|
|
|
return (!missing_requirement && !known_failure);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_utils_fini (void)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2013-01-18 17:57:06 +00:00
|
|
|
if (test_fb)
|
2020-10-13 09:35:47 +00:00
|
|
|
g_object_unref (test_fb);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
if (test_ctx)
|
|
|
|
cogl_object_unref (test_ctx);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
2011-10-26 13:15:14 +00:00
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2011-12-07 12:38:38 +00:00
|
|
|
compare_component (int a, int b)
|
|
|
|
{
|
|
|
|
return ABS (a - b) <= 1;
|
|
|
|
}
|
|
|
|
|
2013-01-21 18:43:24 +00:00
|
|
|
void
|
|
|
|
test_utils_compare_pixel_and_alpha (const uint8_t *screen_pixel,
|
|
|
|
uint32_t expected_pixel)
|
|
|
|
{
|
|
|
|
/* Compare each component with a small fuzz factor */
|
|
|
|
if (!compare_component (screen_pixel[0], expected_pixel >> 24) ||
|
|
|
|
!compare_component (screen_pixel[1], (expected_pixel >> 16) & 0xff) ||
|
|
|
|
!compare_component (screen_pixel[2], (expected_pixel >> 8) & 0xff) ||
|
|
|
|
!compare_component (screen_pixel[3], (expected_pixel >> 0) & 0xff))
|
|
|
|
{
|
|
|
|
uint32_t screen_pixel_num = GUINT32_FROM_BE (*(uint32_t *) screen_pixel);
|
|
|
|
char *screen_pixel_string =
|
|
|
|
g_strdup_printf ("#%08x", screen_pixel_num);
|
|
|
|
char *expected_pixel_string =
|
|
|
|
g_strdup_printf ("#%08x", expected_pixel);
|
|
|
|
|
|
|
|
g_assert_cmpstr (screen_pixel_string, ==, expected_pixel_string);
|
|
|
|
|
|
|
|
g_free (screen_pixel_string);
|
|
|
|
g_free (expected_pixel_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-28 13:40:22 +00:00
|
|
|
void
|
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
|
|
|
test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel)
|
2011-12-07 12:38:38 +00:00
|
|
|
{
|
|
|
|
/* Compare each component with a small fuzz factor */
|
|
|
|
if (!compare_component (screen_pixel[0], expected_pixel >> 24) ||
|
|
|
|
!compare_component (screen_pixel[1], (expected_pixel >> 16) & 0xff) ||
|
|
|
|
!compare_component (screen_pixel[2], (expected_pixel >> 8) & 0xff))
|
|
|
|
{
|
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 screen_pixel_num = GUINT32_FROM_BE (*(uint32_t *) screen_pixel);
|
2011-12-07 12:38:38 +00:00
|
|
|
char *screen_pixel_string =
|
|
|
|
g_strdup_printf ("#%06x", screen_pixel_num >> 8);
|
|
|
|
char *expected_pixel_string =
|
|
|
|
g_strdup_printf ("#%06x", expected_pixel >> 8);
|
|
|
|
|
|
|
|
g_assert_cmpstr (screen_pixel_string, ==, expected_pixel_string);
|
|
|
|
|
|
|
|
g_free (screen_pixel_string);
|
|
|
|
g_free (expected_pixel_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-26 13:15:14 +00:00
|
|
|
void
|
2013-01-18 17:57:06 +00:00
|
|
|
test_utils_check_pixel (CoglFramebuffer *test_fb,
|
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
|
|
|
int x, int y, uint32_t expected_pixel)
|
2011-10-26 13:15:14 +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
|
|
|
uint8_t pixel[4];
|
2011-10-26 13:15:14 +00:00
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_read_pixels (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
x, y, 1, 1,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
pixel);
|
2011-10-26 13:15:14 +00:00
|
|
|
|
2012-01-28 13:40:22 +00:00
|
|
|
test_utils_compare_pixel (pixel, expected_pixel);
|
2011-10-26 13:15:14 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 18:49:05 +00:00
|
|
|
void
|
|
|
|
test_utils_check_pixel_and_alpha (CoglFramebuffer *test_fb,
|
|
|
|
int x, int y, uint32_t expected_pixel)
|
|
|
|
{
|
|
|
|
uint8_t pixel[4];
|
|
|
|
|
|
|
|
cogl_framebuffer_read_pixels (test_fb,
|
|
|
|
x, y, 1, 1,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
pixel);
|
|
|
|
|
|
|
|
test_utils_compare_pixel_and_alpha (pixel, expected_pixel);
|
|
|
|
}
|
|
|
|
|
2011-10-26 13:15:14 +00:00
|
|
|
void
|
2013-01-18 17:57:06 +00:00
|
|
|
test_utils_check_pixel_rgb (CoglFramebuffer *test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
int x, int y, int r, int g, int b)
|
2011-10-26 13:15:14 +00:00
|
|
|
{
|
2019-09-06 10:42:47 +00:00
|
|
|
g_return_if_fail (r >= 0);
|
|
|
|
g_return_if_fail (g >= 0);
|
|
|
|
g_return_if_fail (b >= 0);
|
|
|
|
g_return_if_fail (r <= 0xFF);
|
|
|
|
g_return_if_fail (g <= 0xFF);
|
|
|
|
g_return_if_fail (b <= 0xFF);
|
|
|
|
|
|
|
|
test_utils_check_pixel (test_fb, x, y,
|
|
|
|
(((guint32) r) << 24) |
|
|
|
|
(((guint32) g) << 16) |
|
|
|
|
(((guint32) b) << 8));
|
2011-10-26 13:15:14 +00:00
|
|
|
}
|
2011-10-31 14:55:20 +00:00
|
|
|
|
|
|
|
void
|
2013-01-18 17:57:06 +00:00
|
|
|
test_utils_check_region (CoglFramebuffer *test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
int x, int y,
|
2011-10-31 14:55:20 +00:00
|
|
|
int width, int height,
|
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 expected_rgba)
|
2011-10-31 14:55:20 +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
|
|
|
uint8_t *pixels, *p;
|
2011-10-31 14:55:20 +00:00
|
|
|
|
|
|
|
pixels = p = g_malloc (width * height * 4);
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_read_pixels (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
p);
|
2011-10-31 14:55:20 +00:00
|
|
|
|
|
|
|
/* Check whether the center of each division is the right color */
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
2012-01-28 13:40:22 +00:00
|
|
|
test_utils_compare_pixel (p, expected_rgba);
|
2011-10-31 14:55:20 +00:00
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (pixels);
|
|
|
|
}
|
|
|
|
|
2012-02-10 16:57:24 +00:00
|
|
|
CoglTexture *
|
|
|
|
test_utils_create_color_texture (CoglContext *context,
|
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 color)
|
2012-02-10 16:57:24 +00:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d;
|
|
|
|
|
|
|
|
color = GUINT32_TO_BE (color);
|
2011-10-31 14:55:20 +00:00
|
|
|
|
2012-02-10 16:57:24 +00:00
|
|
|
tex_2d = cogl_texture_2d_new_from_data (context,
|
|
|
|
1, 1, /* width/height */
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
4, /* rowstride */
|
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 *) &color,
|
2012-02-10 16:57:24 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
return COGL_TEXTURE (tex_2d);
|
|
|
|
}
|
2012-02-23 12:30:51 +00:00
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean
|
2012-02-23 12:30:51 +00:00
|
|
|
cogl_test_verbose (void)
|
|
|
|
{
|
|
|
|
return cogl_test_is_verbose;
|
|
|
|
}
|
2013-06-09 00:09:04 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
set_auto_mipmap_cb (CoglTexture *sub_texture,
|
|
|
|
const float *sub_texture_coords,
|
|
|
|
const float *meta_coords,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (sub_texture),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTexture *
|
|
|
|
test_utils_texture_new_with_size (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
TestUtilsTextureFlags flags,
|
2013-07-02 00:48:54 +00:00
|
|
|
CoglTextureComponents components)
|
2013-06-09 00:09:04 +00:00
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2019-06-18 06:02:10 +00:00
|
|
|
GError *skip_error = NULL;
|
2013-06-09 00:09:04 +00:00
|
|
|
|
2019-03-28 19:11:53 +00:00
|
|
|
/* First try creating a fast-path non-sliced texture */
|
|
|
|
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height));
|
2013-07-02 00:48:54 +00:00
|
|
|
|
2019-03-28 19:11:53 +00:00
|
|
|
cogl_texture_set_components (tex, components);
|
2013-06-09 00:09:04 +00:00
|
|
|
|
2019-03-28 19:11:53 +00:00
|
|
|
if (!cogl_texture_allocate (tex, &skip_error))
|
|
|
|
{
|
2019-06-18 06:02:10 +00:00
|
|
|
g_error_free (skip_error);
|
2019-03-28 19:11:53 +00:00
|
|
|
cogl_object_unref (tex);
|
|
|
|
tex = NULL;
|
2013-06-09 00:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!tex)
|
|
|
|
{
|
|
|
|
/* If it fails resort to sliced textures */
|
|
|
|
int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ?
|
|
|
|
-1 : COGL_TEXTURE_MAX_WASTE;
|
|
|
|
CoglTexture2DSliced *tex_2ds =
|
|
|
|
cogl_texture_2d_sliced_new_with_size (ctx,
|
|
|
|
width,
|
|
|
|
height,
|
2013-07-02 00:48:54 +00:00
|
|
|
max_waste);
|
2013-06-09 00:09:04 +00:00
|
|
|
tex = COGL_TEXTURE (tex_2ds);
|
2013-07-02 00:48:54 +00:00
|
|
|
|
|
|
|
cogl_texture_set_components (tex, components);
|
2013-06-09 00:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP)
|
|
|
|
{
|
|
|
|
/* To be able to iterate the slices of a #CoglTexture2DSliced we
|
|
|
|
* need to ensure the texture is allocated... */
|
|
|
|
cogl_texture_allocate (tex, NULL); /* don't catch exceptions */
|
|
|
|
|
|
|
|
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (tex),
|
|
|
|
0, 0, 1, 1,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
|
|
|
|
set_auto_mipmap_cb,
|
|
|
|
NULL); /* don't catch exceptions */
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_texture_allocate (tex, NULL);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTexture *
|
|
|
|
test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
|
|
|
|
TestUtilsTextureFlags flags,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean premultiplied)
|
2013-06-09 00:09:04 +00:00
|
|
|
{
|
|
|
|
CoglAtlasTexture *atlas_tex;
|
|
|
|
CoglTexture *tex;
|
2019-06-18 06:02:10 +00:00
|
|
|
GError *internal_error = NULL;
|
2013-06-09 00:09:04 +00:00
|
|
|
|
|
|
|
if (!flags)
|
|
|
|
{
|
|
|
|
/* First try putting the texture in the atlas */
|
2013-07-02 00:48:54 +00:00
|
|
|
atlas_tex = cogl_atlas_texture_new_from_bitmap (bitmap);
|
|
|
|
|
|
|
|
cogl_texture_set_premultiplied (COGL_TEXTURE (atlas_tex), premultiplied);
|
|
|
|
|
|
|
|
if (cogl_texture_allocate (COGL_TEXTURE (atlas_tex), &internal_error))
|
|
|
|
return COGL_TEXTURE (atlas_tex);
|
2013-06-09 00:09:04 +00:00
|
|
|
|
2013-07-02 00:48:54 +00:00
|
|
|
cogl_object_unref (atlas_tex);
|
2013-06-09 00:09:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 06:02:10 +00:00
|
|
|
g_clear_error (&internal_error);
|
|
|
|
|
2013-06-09 00:09:04 +00:00
|
|
|
/* If that doesn't work try a fast path 2D texture */
|
2019-03-28 19:11:53 +00:00
|
|
|
tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap));
|
2013-07-02 00:48:54 +00:00
|
|
|
|
2019-03-28 19:11:53 +00:00
|
|
|
cogl_texture_set_premultiplied (tex, premultiplied);
|
|
|
|
|
2019-06-18 06:02:10 +00:00
|
|
|
if (g_error_matches (internal_error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_NO_MEMORY))
|
2019-03-28 19:11:53 +00:00
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-06-09 00:09:04 +00:00
|
|
|
|
2019-06-18 06:02:10 +00:00
|
|
|
g_clear_error (&internal_error);
|
2013-06-09 00:09:04 +00:00
|
|
|
|
|
|
|
if (!tex)
|
|
|
|
{
|
|
|
|
/* Otherwise create a sliced texture */
|
|
|
|
int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ?
|
|
|
|
-1 : COGL_TEXTURE_MAX_WASTE;
|
|
|
|
CoglTexture2DSliced *tex_2ds =
|
2013-07-02 00:48:54 +00:00
|
|
|
cogl_texture_2d_sliced_new_from_bitmap (bitmap, max_waste);
|
2013-06-09 00:09:04 +00:00
|
|
|
tex = COGL_TEXTURE (tex_2ds);
|
2013-07-02 00:48:54 +00:00
|
|
|
|
|
|
|
cogl_texture_set_premultiplied (tex, premultiplied);
|
2013-06-09 00:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP)
|
|
|
|
{
|
|
|
|
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (tex),
|
|
|
|
0, 0, 1, 1,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
|
|
|
|
set_auto_mipmap_cb,
|
|
|
|
NULL); /* don't catch exceptions */
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_texture_allocate (tex, NULL);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTexture *
|
|
|
|
test_utils_texture_new_from_data (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
TestUtilsTextureFlags flags,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
int rowstride,
|
|
|
|
const uint8_t *data)
|
|
|
|
{
|
|
|
|
CoglBitmap *bmp;
|
|
|
|
CoglTexture *tex;
|
|
|
|
|
|
|
|
g_assert_cmpint (format, !=, COGL_PIXEL_FORMAT_ANY);
|
|
|
|
g_assert (data != NULL);
|
|
|
|
|
|
|
|
/* Wrap the data into a bitmap */
|
|
|
|
bmp = cogl_bitmap_new_for_data (ctx,
|
|
|
|
width, height,
|
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
(uint8_t *) data);
|
|
|
|
|
2013-07-02 00:48:54 +00:00
|
|
|
tex = test_utils_texture_new_from_bitmap (bmp, flags, TRUE);
|
2013-06-09 00:09:04 +00:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|