mirror of
https://github.com/brl/mutter.git
synced 2024-11-12 17:27:03 -05:00
tests: Port test-premult
This ports the test-offscreen test from being a Clutter test to a straight Cogl test. https://bugzilla.gnome.org/show_bug.cgi?id=660617 Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
bdb645e7f5
commit
d3215b802d
@ -17,7 +17,6 @@ unported_test_sources = \
|
||||
test-multitexture.c \
|
||||
test-npot-texture.c \
|
||||
test-object.c \
|
||||
test-premult.c \
|
||||
test-readpixels.c \
|
||||
test-texture-get-set-data.c \
|
||||
test-texture-mipmaps.c \
|
||||
@ -40,6 +39,7 @@ test_sources = \
|
||||
test-pipeline-user-matrix.c \
|
||||
test-pipeline-uniforms.c \
|
||||
test-pixel-buffer.c \
|
||||
test-premult.c \
|
||||
test-snippets.c \
|
||||
test-wrap-modes.c \
|
||||
test-sub-texture.c \
|
||||
|
@ -53,7 +53,7 @@ main (int argc, char **argv)
|
||||
UNPORTED_TEST (test_materials);
|
||||
ADD_TEST (test_pipeline_user_matrix, 0);
|
||||
ADD_TEST (test_blend_strings, 0);
|
||||
UNPORTED_TEST (test_premult);
|
||||
ADD_TEST (test_premult, 0);
|
||||
UNPORTED_TEST (test_readpixels);
|
||||
ADD_TEST (test_path, 0);
|
||||
ADD_TEST (test_depth_test, 0);
|
||||
|
@ -1,13 +1,10 @@
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
#include <cogl/cogl.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "test-conform-common.h"
|
||||
#include "test-utils.h"
|
||||
|
||||
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
|
||||
|
||||
#define QUAD_WIDTH 20
|
||||
#define QUAD_WIDTH 32
|
||||
|
||||
#define RED 0
|
||||
#define GREEN 1
|
||||
@ -19,12 +16,6 @@ static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
|
||||
#define MASK_BLUE(COLOR) ((COLOR & 0xff00) >> 8)
|
||||
#define MASK_ALPHA(COLOR) (COLOR & 0xff)
|
||||
|
||||
typedef struct _TestState
|
||||
{
|
||||
ClutterGeometry stage_geom;
|
||||
CoglHandle passthrough_material;
|
||||
} TestState;
|
||||
|
||||
static guchar *
|
||||
gen_tex_data (guint32 color)
|
||||
{
|
||||
@ -47,54 +38,104 @@ gen_tex_data (guint32 color)
|
||||
return tex_data;
|
||||
}
|
||||
|
||||
static CoglHandle
|
||||
static CoglTexture *
|
||||
make_texture (guint32 color,
|
||||
CoglPixelFormat src_format,
|
||||
CoglPixelFormat internal_format)
|
||||
CoglPixelFormat src_format,
|
||||
CoglPixelFormat internal_format)
|
||||
{
|
||||
CoglHandle tex;
|
||||
CoglTexture2D *tex_2d;
|
||||
guchar *tex_data = gen_tex_data (color);
|
||||
|
||||
tex = cogl_texture_new_from_data (QUAD_WIDTH,
|
||||
QUAD_WIDTH,
|
||||
COGL_TEXTURE_NONE,
|
||||
src_format,
|
||||
internal_format,
|
||||
QUAD_WIDTH * 4,
|
||||
tex_data);
|
||||
tex_2d = cogl_texture_2d_new_from_data (ctx,
|
||||
QUAD_WIDTH,
|
||||
QUAD_WIDTH,
|
||||
src_format,
|
||||
internal_format,
|
||||
QUAD_WIDTH * 4,
|
||||
tex_data,
|
||||
NULL);
|
||||
|
||||
g_free (tex_data);
|
||||
|
||||
return tex;
|
||||
return COGL_TEXTURE (tex_2d);
|
||||
}
|
||||
|
||||
static void
|
||||
check_texture (TestState *state,
|
||||
int x,
|
||||
int y,
|
||||
CoglHandle tex,
|
||||
guint32 expected_result)
|
||||
set_region (CoglTexture *tex,
|
||||
guint32 color,
|
||||
CoglPixelFormat format)
|
||||
{
|
||||
guchar pixel[4];
|
||||
int y_off;
|
||||
int x_off;
|
||||
guchar *tex_data = gen_tex_data (color);
|
||||
|
||||
cogl_material_set_layer (state->passthrough_material, 0, tex);
|
||||
cogl_texture_set_region (tex,
|
||||
0, 0, /* src x, y */
|
||||
0, 0, /* dst x, y */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* dst width, height */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* src width, height */
|
||||
format,
|
||||
0, /* auto compute row stride */
|
||||
tex_data);
|
||||
}
|
||||
|
||||
cogl_set_source (state->passthrough_material);
|
||||
static void
|
||||
check_texture (CoglPipeline *pipeline,
|
||||
CoglHandle material,
|
||||
int x,
|
||||
int y,
|
||||
CoglTexture *tex,
|
||||
guint32 expected_result)
|
||||
{
|
||||
/* Legacy */
|
||||
cogl_push_framebuffer (fb);
|
||||
cogl_material_set_layer (material, 0, tex);
|
||||
cogl_set_source (material);
|
||||
cogl_rectangle (x * QUAD_WIDTH,
|
||||
y * QUAD_WIDTH,
|
||||
x * QUAD_WIDTH + QUAD_WIDTH,
|
||||
y * QUAD_WIDTH + QUAD_WIDTH);
|
||||
y * QUAD_WIDTH,
|
||||
x * QUAD_WIDTH + QUAD_WIDTH,
|
||||
y * QUAD_WIDTH + QUAD_WIDTH);
|
||||
test_utils_check_pixel (fb, x * QUAD_WIDTH + QUAD_WIDTH / 2, y * QUAD_WIDTH + QUAD_WIDTH / 2, expected_result);
|
||||
cogl_pop_framebuffer ();
|
||||
|
||||
test_utils_check_pixel (x_off, y_off, expected_result);
|
||||
/* New API */
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (tex));
|
||||
cogl_framebuffer_draw_rectangle (fb, pipeline,
|
||||
x * QUAD_WIDTH,
|
||||
y * QUAD_WIDTH,
|
||||
x * QUAD_WIDTH + QUAD_WIDTH,
|
||||
y * QUAD_WIDTH + QUAD_WIDTH);
|
||||
test_utils_check_pixel (fb, x * QUAD_WIDTH + QUAD_WIDTH / 2, y * QUAD_WIDTH + QUAD_WIDTH / 2, expected_result);
|
||||
}
|
||||
|
||||
static void
|
||||
on_paint (ClutterActor *actor, TestState *state)
|
||||
void
|
||||
test_premult (void)
|
||||
{
|
||||
CoglHandle tex;
|
||||
guchar *tex_data;
|
||||
CoglPipeline *pipeline;
|
||||
CoglHandle material;
|
||||
CoglTexture *tex;
|
||||
|
||||
cogl_framebuffer_orthographic (fb, 0, 0,
|
||||
cogl_framebuffer_get_width (fb),
|
||||
cogl_framebuffer_get_height (fb),
|
||||
-1,
|
||||
100);
|
||||
|
||||
cogl_framebuffer_clear4f (fb,
|
||||
COGL_BUFFER_BIT_COLOR,
|
||||
1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
/* Legacy */
|
||||
material = cogl_material_new ();
|
||||
cogl_material_set_blend (material,
|
||||
"RGBA = ADD (SRC_COLOR, 0)", NULL);
|
||||
cogl_material_set_layer_combine (material, 0,
|
||||
"RGBA = REPLACE (TEXTURE)", NULL);
|
||||
|
||||
/* New API */
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_blend (pipeline,
|
||||
"RGBA = ADD (SRC_COLOR, 0)", NULL);
|
||||
cogl_pipeline_set_layer_combine (pipeline, 0,
|
||||
"RGBA = REPLACE (TEXTURE)", NULL);
|
||||
|
||||
/* If the user explicitly specifies an unmultiplied internal format then
|
||||
* Cogl shouldn't automatically premultiply the given texture data... */
|
||||
@ -104,9 +145,9 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
tex = make_texture (0xff00ff80,
|
||||
COGL_PIXEL_FORMAT_RGBA_8888, /* src format */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888); /* internal format */
|
||||
check_texture (state, 0, 0, /* position */
|
||||
tex,
|
||||
0xff00ff80); /* expected */
|
||||
check_texture (pipeline, material, 0, 0, /* position */
|
||||
tex,
|
||||
0xff00ff80); /* expected */
|
||||
|
||||
/* If the user explicitly requests a premultiplied internal format and
|
||||
* gives unmultiplied src data then Cogl should always premultiply that
|
||||
@ -117,9 +158,9 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
tex = make_texture (0xff00ff80,
|
||||
COGL_PIXEL_FORMAT_RGBA_8888, /* src format */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE); /* internal format */
|
||||
check_texture (state, 1, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
check_texture (pipeline, material, 1, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
|
||||
/* If the user gives COGL_PIXEL_FORMAT_ANY for the internal format then
|
||||
* by default Cogl should premultiply the given texture data...
|
||||
@ -131,9 +172,9 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
tex = make_texture (0xff00ff80,
|
||||
COGL_PIXEL_FORMAT_RGBA_8888, /* src format */
|
||||
COGL_PIXEL_FORMAT_ANY); /* internal format */
|
||||
check_texture (state, 2, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
check_texture (pipeline, material, 2, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
|
||||
/* If the user requests a premultiplied internal texture format and supplies
|
||||
* premultiplied source data, Cogl should never modify that source data...
|
||||
@ -145,9 +186,9 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
tex = make_texture (0x80008080,
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE); /* internal format */
|
||||
check_texture (state, 3, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
check_texture (pipeline, material, 3, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
|
||||
/* If the user requests an unmultiplied internal texture format, but
|
||||
* supplies premultiplied source data, then Cogl should always
|
||||
@ -158,9 +199,9 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
tex = make_texture (0x80008080,
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888); /* internal format */
|
||||
check_texture (state, 4, 0, /* position */
|
||||
tex,
|
||||
0xff00ff80); /* expected */
|
||||
check_texture (pipeline, material, 4, 0, /* position */
|
||||
tex,
|
||||
0xff00ff80); /* expected */
|
||||
|
||||
/* If the user allows any internal texture format and provides premultipled
|
||||
* source data then by default Cogl shouldn't modify the source data...
|
||||
@ -172,9 +213,9 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
tex = make_texture (0x80008080,
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */
|
||||
COGL_PIXEL_FORMAT_ANY); /* internal format */
|
||||
check_texture (state, 5, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
check_texture (pipeline, material, 5, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
|
||||
/*
|
||||
* Test cogl_texture_set_region() ....
|
||||
@ -188,18 +229,10 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
COGL_PIXEL_FORMAT_RGBA_8888); /* internal format */
|
||||
if (cogl_test_verbose ())
|
||||
g_print ("set_region (0xff00ff80, RGBA_8888)\n");
|
||||
tex_data = gen_tex_data (0xff00ff80);
|
||||
cogl_texture_set_region (tex,
|
||||
0, 0, /* src x, y */
|
||||
0, 0, /* dst x, y */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* dst width, height */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* src width, height */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888,
|
||||
0, /* auto compute row stride */
|
||||
tex_data);
|
||||
check_texture (state, 6, 0, /* position */
|
||||
tex,
|
||||
0xff00ff80); /* expected */
|
||||
set_region (tex, 0xff00ff80, COGL_PIXEL_FORMAT_RGBA_8888);
|
||||
check_texture (pipeline, material, 6, 0, /* position */
|
||||
tex,
|
||||
0xff00ff80); /* expected */
|
||||
|
||||
/* Updating a texture region for an unmultiplied texture using premultiplied
|
||||
* region data should result in Cogl unmultiplying the given region data...
|
||||
@ -212,18 +245,10 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
COGL_PIXEL_FORMAT_RGBA_8888); /* internal format */
|
||||
if (cogl_test_verbose ())
|
||||
g_print ("set_region (0x80008080, RGBA_8888_PRE)\n");
|
||||
tex_data = gen_tex_data (0x80008080);
|
||||
cogl_texture_set_region (tex,
|
||||
0, 0, /* src x, y */
|
||||
0, 0, /* dst x, y */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* dst width, height */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* src width, height */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
||||
0, /* auto compute row stride */
|
||||
tex_data);
|
||||
check_texture (state, 7, 0, /* position */
|
||||
tex,
|
||||
0xff00ff80); /* expected */
|
||||
set_region (tex, 0x80008080, COGL_PIXEL_FORMAT_RGBA_8888_PRE);
|
||||
check_texture (pipeline, material, 7, 0, /* position */
|
||||
tex,
|
||||
0xff00ff80); /* expected */
|
||||
|
||||
|
||||
if (cogl_test_verbose ())
|
||||
@ -235,18 +260,10 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE); /* internal format */
|
||||
if (cogl_test_verbose ())
|
||||
g_print ("set_region (0x80008080, RGBA_8888_PRE)\n");
|
||||
tex_data = gen_tex_data (0x80008080);
|
||||
cogl_texture_set_region (tex,
|
||||
0, 0, /* src x, y */
|
||||
0, 0, /* dst x, y */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* dst width, height */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* src width, height */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
||||
0, /* auto compute row stride */
|
||||
tex_data);
|
||||
check_texture (state, 8, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
set_region (tex, 0x80008080, COGL_PIXEL_FORMAT_RGBA_8888_PRE);
|
||||
check_texture (pipeline, material, 8, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
|
||||
|
||||
/* Updating a texture region for a premultiplied texture using unmultiplied
|
||||
@ -261,66 +278,11 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE); /* internal format */
|
||||
if (cogl_test_verbose ())
|
||||
g_print ("set_region (0xff00ff80, RGBA_8888)\n");
|
||||
tex_data = gen_tex_data (0xff00ff80);
|
||||
cogl_texture_set_region (tex,
|
||||
0, 0, /* src x, y */
|
||||
0, 0, /* dst x, y */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* dst width, height */
|
||||
QUAD_WIDTH, QUAD_WIDTH, /* src width, height */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888,
|
||||
0, /* auto compute row stride */
|
||||
tex_data);
|
||||
check_texture (state, 9, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
set_region (tex, 0xff00ff80, COGL_PIXEL_FORMAT_RGBA_8888);
|
||||
check_texture (pipeline, material, 9, 0, /* position */
|
||||
tex,
|
||||
0x80008080); /* expected */
|
||||
|
||||
/* Comment this out if you want visual feedback for what this test paints */
|
||||
clutter_main_quit ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
queue_redraw (gpointer stage)
|
||||
{
|
||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
test_premult (TestUtilsGTestFixture *fixture,
|
||||
void *data)
|
||||
{
|
||||
TestState state;
|
||||
ClutterActor *stage;
|
||||
ClutterActor *group;
|
||||
unsigned int idle_source;
|
||||
|
||||
state.passthrough_material = cogl_material_new ();
|
||||
cogl_material_set_blend (state.passthrough_material,
|
||||
"RGBA = ADD (SRC_COLOR, 0)", NULL);
|
||||
cogl_material_set_layer_combine (state.passthrough_material, 0,
|
||||
"RGBA = REPLACE (TEXTURE)", NULL);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
|
||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
||||
clutter_actor_get_geometry (stage, &state.stage_geom);
|
||||
|
||||
group = clutter_group_new ();
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
|
||||
|
||||
/* We force continuous redrawing incase someone comments out the
|
||||
* clutter_main_quit and wants visual feedback for the test since we
|
||||
* wont be doing anything else that will trigger redrawing. */
|
||||
idle_source = g_idle_add (queue_redraw, stage);
|
||||
|
||||
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
||||
|
||||
clutter_actor_show_all (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
g_source_remove (idle_source);
|
||||
|
||||
if (cogl_test_verbose ())
|
||||
g_print ("OK\n");
|
||||
|
Loading…
Reference in New Issue
Block a user