2012-05-16 11:57:32 +00:00
|
|
|
#include <cogl/cogl.h>
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2012-05-16 11:57:32 +00:00
|
|
|
#include "test-utils.h"
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
#define N_TEXTURES 128
|
|
|
|
|
|
|
|
#define OPACITY_FOR_ROW(y) \
|
|
|
|
(0xff - ((y) & 0xf) * 0x10)
|
|
|
|
|
|
|
|
#define COLOR_FOR_SIZE(size) \
|
|
|
|
(colors + (size) % 3)
|
|
|
|
|
2012-05-16 11:57:32 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t red, green, blue, alpha;
|
|
|
|
} TestColor;
|
|
|
|
|
|
|
|
static const TestColor colors[] =
|
2011-05-05 22:34:38 +00:00
|
|
|
{ { 0xff, 0x00, 0x00, 0xff },
|
|
|
|
{ 0x00, 0xff, 0x00, 0xff },
|
|
|
|
{ 0x00, 0x00, 0xff, 0xff } };
|
|
|
|
|
2012-05-16 11:57:32 +00:00
|
|
|
static CoglTexture *
|
2011-05-05 22:34:38 +00:00
|
|
|
create_texture (int size)
|
|
|
|
{
|
2012-05-16 11:57:32 +00:00
|
|
|
CoglTexture *texture;
|
|
|
|
const TestColor *color;
|
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, *p;
|
2011-05-05 22:34:38 +00:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* Create a red, green or blue texture depending on the size */
|
|
|
|
color = COLOR_FOR_SIZE (size);
|
|
|
|
|
|
|
|
p = data = g_malloc (size * size * 4);
|
|
|
|
|
|
|
|
/* Fill the data with the color but fade the opacity out with
|
|
|
|
increasing y coordinates so that we can see the blending it the
|
|
|
|
atlas migration accidentally blends with garbage in the
|
|
|
|
texture */
|
|
|
|
for (y = 0; y < size; y++)
|
|
|
|
{
|
|
|
|
int opacity = OPACITY_FOR_ROW (y);
|
|
|
|
|
|
|
|
for (x = 0; x < size; x++)
|
|
|
|
{
|
|
|
|
/* Store the colors premultiplied */
|
|
|
|
p[0] = color->red * opacity / 255;
|
|
|
|
p[1] = color->green * opacity / 255;
|
|
|
|
p[2] = color->blue * opacity / 255;
|
|
|
|
p[3] = opacity;
|
|
|
|
|
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
texture = cogl_texture_new_from_data (size, /* width */
|
|
|
|
size, /* height */
|
|
|
|
COGL_TEXTURE_NONE, /* flags */
|
|
|
|
/* format */
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
/* internal format */
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
/* rowstride */
|
|
|
|
size * 4,
|
|
|
|
data);
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 11:57:32 +00:00
|
|
|
verify_texture (CoglTexture *texture, int size)
|
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
|
|
|
uint8_t *data, *p;
|
2011-05-05 22:34:38 +00:00
|
|
|
int x, y;
|
2012-05-16 11:57:32 +00:00
|
|
|
const TestColor *color;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
color = COLOR_FOR_SIZE (size);
|
|
|
|
|
|
|
|
p = data = g_malloc (size * size * 4);
|
|
|
|
|
|
|
|
cogl_texture_get_data (texture,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
size * 4,
|
|
|
|
data);
|
|
|
|
|
|
|
|
for (y = 0; y < size; y++)
|
|
|
|
{
|
|
|
|
int opacity = OPACITY_FOR_ROW (y);
|
|
|
|
|
|
|
|
for (x = 0; x < size; x++)
|
|
|
|
{
|
2012-05-16 11:57:32 +00:00
|
|
|
TestColor real_color =
|
|
|
|
{
|
|
|
|
color->red * opacity / 255,
|
|
|
|
color->green * opacity / 255,
|
|
|
|
color->blue * opacity / 255
|
|
|
|
};
|
|
|
|
|
|
|
|
test_utils_compare_pixel (p,
|
|
|
|
(real_color.red << 24) |
|
|
|
|
(real_color.green << 16) |
|
|
|
|
(real_color.blue << 8) |
|
|
|
|
opacity);
|
2011-05-05 22:34:38 +00:00
|
|
|
g_assert_cmpint (p[3], ==, opacity);
|
|
|
|
|
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-16 11:57:32 +00:00
|
|
|
test_atlas_migration (void)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2012-05-16 11:57:32 +00:00
|
|
|
CoglTexture *textures[N_TEXTURES];
|
2011-05-05 22:34:38 +00:00
|
|
|
int i, tex_num;
|
|
|
|
|
|
|
|
/* Create and destroy all of the textures a few times to increase
|
|
|
|
the chances that we'll end up reusing the buffers for previously
|
|
|
|
discarded atlases */
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
|
|
|
|
textures[tex_num] = create_texture (tex_num + 1);
|
|
|
|
for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
|
|
|
|
cogl_object_unref (textures[tex_num]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create all the textures again */
|
|
|
|
for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
|
|
|
|
textures[tex_num] = create_texture (tex_num + 1);
|
|
|
|
|
|
|
|
/* Verify that they all still have the right data */
|
|
|
|
for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
|
|
|
|
verify_texture (textures[tex_num], tex_num + 1);
|
|
|
|
|
|
|
|
/* Destroy them all */
|
|
|
|
for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
|
|
|
|
cogl_object_unref (textures[tex_num]);
|
|
|
|
|
2012-02-23 12:30:51 +00:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 22:34:38 +00:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|