clutter/tests: Remove interactive tests using gdk-pixbuf

As those tests are not really useful, see previous commit. Removing them
allows us
to get rid of gdk-pixbuf in this code path and so, allowing to
completely remove it
once the MetaBackground API is refactored.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4133>
This commit is contained in:
Bilal Elmoussaoui 2024-12-04 10:58:25 +01:00 committed by Marge Bot
parent a2dd7d6d1d
commit 9592aa0bda
9 changed files with 0 additions and 1212 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -15,9 +15,6 @@ clutter_tests_interactive_link_args = [
clutter_tests_interactive_test_sources = [
'test-events.c',
'test-grab.c',
'test-cogl-shader-glsl.c',
'test-cogl-tex-tile.c',
'test-cogl-offscreen.c',
'test-animation.c',
'test-binding-pool.c',
'test-text.c',
@ -55,7 +52,6 @@ executable('test-interactive',
link_args: clutter_tests_interactive_link_args,
dependencies: [
libmutter_test_dep,
gdk_pixbuf_dep,
],
install: false,
)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -1,239 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gmodule.h>
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "clutter/test-utils.h"
#include "tests/clutter-test-utils.h"
typedef struct _TestMultiLayerPipelineState
{
ClutterActor *group;
CoglTexture *alpha_tex;
CoglTexture *redhand_tex;
gfloat *tex_coords;
ClutterTimeline *timeline;
CoglPipeline *pipeline0;
graphene_matrix_t tex_matrix0;
graphene_matrix_t rot_matrix0;
CoglTexture *light_tex0;
CoglPipeline *pipeline1;
graphene_matrix_t tex_matrix1;
graphene_matrix_t rot_matrix1;
CoglTexture *light_tex1;
} TestMultiLayerPipelineState;
int
test_cogl_multitexture_main (int argc, char *argv[]);
const char *
test_cogl_multitexture_describe (void);
static void
frame_cb (ClutterTimeline *timeline,
int frame_no,
gpointer data)
{
TestMultiLayerPipelineState *state = data;
graphene_matrix_multiply (&state->rot_matrix0,
&state->tex_matrix0,
&state->tex_matrix0);
cogl_pipeline_set_layer_matrix (state->pipeline0, 2, &state->tex_matrix0);
graphene_matrix_multiply (&state->rot_matrix1,
&state->tex_matrix1,
&state->tex_matrix1);
cogl_pipeline_set_layer_matrix (state->pipeline1, 2, &state->tex_matrix1);
}
static void
pipeline_rectangle_paint (ClutterActor *actor,
ClutterPaintContext *paint_context,
gpointer data)
{
TestMultiLayerPipelineState *state = data;
CoglFramebuffer *framebuffer =
clutter_paint_context_get_framebuffer (paint_context);
cogl_framebuffer_push_matrix (framebuffer);
cogl_framebuffer_translate (framebuffer, 150, 15, 0);
cogl_framebuffer_draw_multitextured_rectangle (framebuffer,
COGL_FRAMEBUFFER (state->pipeline0),
0, 0, 200, 213,
state->tex_coords,
12);
cogl_framebuffer_translate (framebuffer, -300, -30, 0);
cogl_framebuffer_draw_multitextured_rectangle (framebuffer,
COGL_FRAMEBUFFER (state->pipeline1),
0, 0, 200, 213,
state->tex_coords,
12);
cogl_framebuffer_pop_matrix (framebuffer);
}
static void
animation_completed_cb (ClutterAnimation *animation,
TestMultiLayerPipelineState *state)
{
static gboolean go_back = FALSE;
gdouble new_rotation_y;
if (go_back)
new_rotation_y = 30;
else
new_rotation_y = -30;
go_back = !go_back;
clutter_actor_animate_with_timeline (state->group,
CLUTTER_LINEAR,
state->timeline,
"rotation-angle-y", new_rotation_y,
"signal-after::completed",
animation_completed_cb, state,
NULL);
}
G_MODULE_EXPORT int
test_cogl_multitexture_main (int argc, char *argv[])
{
GError *error = NULL;
ClutterActor *stage;
CoglColor stage_color = { 0x61, 0x56, 0x56, 0xff };
g_autofree TestMultiLayerPipelineState *state = g_new0 (TestMultiLayerPipelineState, 1);
gfloat stage_w, stage_h;
gchar **files;
gfloat tex_coords[] =
{
/* tx1 ty1 tx2 ty2 */
0, 0, 1, 1,
0, 0, 1, 1,
0, 0, 1, 1
};
CoglContext *ctx;
clutter_test_init (&argc, &argv);
stage = clutter_test_get_stage ();
clutter_actor_get_size (stage, &stage_w, &stage_h);
clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &stage_color);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL);
/* We create a non-descript actor that we know doesn't have a
* default paint handler, so that we can easily control
* painting in a paint signal handler, without having to
* sub-class anything etc. */
state->group = clutter_actor_new ();
clutter_actor_set_position (state->group, stage_w / 2, stage_h / 2);
g_signal_connect (state->group, "paint",
G_CALLBACK (pipeline_rectangle_paint), state);
files = g_new (gchar*, 4);
files[0] = g_build_filename (TESTS_DATADIR, "redhand_alpha.png", NULL);
files[1] = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
files[2] = g_build_filename (TESTS_DATADIR, "light0.png", NULL);
files[3] = NULL;
ctx = clutter_backend_get_cogl_context (clutter_test_get_backend ());
state->alpha_tex = clutter_test_texture_2d_new_from_file (ctx, files[0], &error);
if (!state->alpha_tex)
g_critical ("Failed to load redhand_alpha.png: %s", error->message);
state->redhand_tex = clutter_test_texture_2d_new_from_file (ctx, files[1], &error);
if (!state->redhand_tex)
g_critical ("Failed to load redhand.png: %s", error->message);
state->light_tex0 = clutter_test_texture_2d_new_from_file (ctx, files[2], &error);
if (!state->light_tex0)
g_critical ("Failed to load light0.png: %s", error->message);
state->light_tex1 = clutter_test_texture_2d_new_from_file (ctx, files[2], &error);
if (!state->light_tex1)
g_critical ("Failed to load light0.png: %s", error->message);
g_strfreev (files);
state->pipeline0 = cogl_pipeline_new ();
cogl_pipeline_set_layer (state->pipeline0, 0, state->alpha_tex);
cogl_pipeline_set_layer (state->pipeline0, 1, state->redhand_tex);
cogl_pipeline_set_layer (state->pipeline0, 2, state->light_tex0);
state->pipeline1 = cogl_pipeline_new ();
cogl_pipeline_set_layer (state->pipeline1, 0, state->alpha_tex);
cogl_pipeline_set_layer (state->pipeline1, 1, state->redhand_tex);
cogl_pipeline_set_layer (state->pipeline1, 2, state->light_tex1);
state->tex_coords = tex_coords;
graphene_matrix_init_identity (&state->tex_matrix0);
graphene_matrix_init_identity (&state->tex_matrix1);
graphene_matrix_init_identity (&state->rot_matrix0);
graphene_matrix_init_identity (&state->rot_matrix1);
graohene_matrix_translate (&state->rot_matrix0,
&GRAPHENE_POINT3D_INIT (-0.5, -0.5, 0));
graohene_matrix_rotate (&state->rot_matrix0, 10.0, graphene_vec3_z_axis ());
graphene_matrix_translate (&state->rot_matrix0,
&GRAPHENE_POINT3D_INIT (0.5, 0.5, 0));
graphene_matrix_translate (&state->rot_matrix1,
&GRAPHENE_POINT3D_INIT (-0.5, -0.5, 0));
graohene_matrix_rotate (&state->rot_matrix1, -10.0, graphene_vec3_z_axis ());
graphene_matrix_translate (&state->rot_matrix1,
&GRAPHENE_POINT3D_INIT (0.5, 0.5, 0));
clutter_actor_set_translation (data->parent_container, -86.f, -125.f, 0.f);
clutter_actor_add_child (stage, state->group);
state->timeline = clutter_timeline_new_for_actor (stage, 2812);
g_signal_connect (state->timeline, "new-frame", G_CALLBACK (frame_cb), state);
clutter_actor_animate_with_timeline (state->group,
CLUTTER_LINEAR,
state->timeline,
"rotation-angle-y", 30.0,
"signal-after::completed",
animation_completed_cb, state,
NULL);
/* start the timeline and thus the animations */
clutter_timeline_start (state->timeline);
clutter_actor_show (stage);
clutter_test_main ();
g_object_unref (state->pipeline1);
g_object_unref (state->pipeline0);
g_object_unref (state->alpha_tex);
g_object_unref (state->redhand_tex);
g_object_unref (state->light_tex0);
g_object_unref (state->light_tex1);
g_free (state);
return 0;
}
G_MODULE_EXPORT const char *
test_cogl_multitexture_describe (void)
{
return "Multi-texturing support in Cogl.";
}

View File

@ -1,304 +0,0 @@
#include <glib.h>
#include <gmodule.h>
#include <stdlib.h>
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "clutter/test-utils.h"
#include "tests/clutter-test-utils.h"
/* Coglbox declaration
*--------------------------------------------------*/
G_BEGIN_DECLS
#define TEST_TYPE_COGLBOX test_coglbox_get_type()
static
G_DECLARE_FINAL_TYPE (TestCoglbox, test_coglbox, TEST, COGLBOX, ClutterActor)
struct _TestCoglbox
{
ClutterActor parent;
CoglTexture *texhand_id;
CoglTexture *texture_id;
CoglFramebuffer *framebuffer;
};
G_DEFINE_TYPE (TestCoglbox, test_coglbox, CLUTTER_TYPE_ACTOR);
int
test_cogl_offscreen_main (int argc, char *argv[]);
const char *
test_cogl_offscreen_describe (void);
G_END_DECLS
/* Coglbox implementation
*--------------------------------------------------*/
static void
test_coglbox_paint (ClutterActor *self,
ClutterPaintContext *paint_context)
{
TestCoglbox *coglbox = TEST_COGLBOX (self);
CoglFramebuffer *framebuffer =
clutter_paint_context_get_framebuffer (paint_context);
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
gfloat texcoords[4] = { 0, 0, 1, 1 };
CoglPipeline *pipeline;
CoglColor color;
pipeline = cogl_pipeline_new (ctx);
cogl_color_init_from_4f (&color, 0.4f, 0.4f, 221.0f / 255.0f, 1.0f);
cogl_pipeline_set_color (pipeline, &color);
cogl_framebuffer_draw_rectangle (framebuffer, pipeline, 0, 0, 400, 400);
g_object_unref (pipeline);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 0, coglbox->texhand_id);
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
0, 0,
400, 400,
0, 0,
6, 6);
g_object_unref (pipeline);
pipeline = cogl_pipeline_new (ctx);
cogl_color_init_from_4f (&color, 1.0f, 0.0f, 0.0f, 1.0f);
cogl_pipeline_set_color (pipeline, &color);
cogl_framebuffer_draw_rectangle (coglbox->framebuffer, pipeline,
20, 20, 20 + 100, 20 + 100);
cogl_color_init_from_4f (&color, 0.0f, 1.0f, 0.0f, 1.0f);
cogl_pipeline_set_color (pipeline, &color);
cogl_framebuffer_draw_rectangle (coglbox->framebuffer, pipeline,
80, 80, 80 + 100, 80 + 100);
g_object_unref (pipeline);
pipeline = cogl_pipeline_new (ctx);
cogl_color_init_from_4f (&color,
136.0f / 255.0f, 136.0f / 255.0f,
136.0f / 255.0f, 136.0f / 255.0f);
cogl_pipeline_set_color (pipeline, &color);
cogl_pipeline_set_layer_texture (pipeline, 0, coglbox->texture_id);
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
100, 100,
300, 300,
texcoords[0],
texcoords[1],
texcoords[2],
texcoords[3]);
g_object_unref (pipeline);
}
static void
test_coglbox_dispose (GObject *object)
{
TestCoglbox *coglbox = TEST_COGLBOX (object);
g_object_unref (coglbox->texture_id);
g_object_unref (coglbox->framebuffer);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
}
/* A newly created Cogl framebuffer will be initialized with a
* viewport covering the size of the viewport i.e. equavalent to:
*
* calling cogl_framebuffer_set_viewport (
* fb,
* 0, 0,
* cogl_framebuffer_get_viewport_width (fb),
* cogl_framebuffer_get_viewport_width (fb));
*
* The projection matrix will be an identity matrix.
*
* The modelview matrix will be an identity matrix, and this will
* create a coordinate system - like OpenGL - with the viewport
* being mapped to a unit cube with the origin (0, 0, 0) in the
* center, x, y and z ranging from -1 to 1 with (-1, -1) being top
* left and (1, 1) bottom right.
*
* This sets up a Clutter like coordinate system for a Cogl
* framebuffer
*/
static void
setup_viewport (CoglFramebuffer *framebuffer,
unsigned int width,
unsigned int height,
float fovy,
float aspect,
float z_near,
float z_far)
{
float z_camera;
graphene_matrix_t projection_matrix;
graphene_matrix_t mv_matrix;
cogl_framebuffer_set_viewport (framebuffer, 0, 0, width, height);
/* For Ortho projection.
* _cogl_matrix_stack_ortho (projection_stack, 0, width, 0, height, -1, 1);
*/
cogl_framebuffer_perspective (framebuffer, fovy, aspect, z_near, z_far);
/*
* In theory, we can compute the camera distance from screen as:
*
* 0.5 * tan (FOV)
*
* However, it's better to compute the z_camera from our projection
* matrix so that we get a 1:1 mapping at the screen distance. Consider
* the upper-left corner of the screen. It has object coordinates
* (0,0,0), so by the transform below, ends up with eye coordinate
*
* x_eye = x_object / width - 0.5 = - 0.5
* y_eye = (height - y_object) / width - 0.5 = 0.5
* z_eye = z_object / width - z_camera = - z_camera
*
* From cogl_perspective(), we know that the projection matrix has
* the form:
*
* (x, 0, 0, 0)
* (0, y, 0, 0)
* (0, 0, c, d)
* (0, 0, -1, 0)
*
* Applied to the above, we get clip coordinates of
*
* x_clip = x * (- 0.5)
* y_clip = y * 0.5
* w_clip = - 1 * (- z_camera) = z_camera
*
* Dividing through by w to get normalized device coordinates, we
* have, x_nd = x * 0.5 / z_camera, y_nd = - y * 0.5 / z_camera.
* The upper left corner of the screen has normalized device coordinates,
* (-1, 1), so to have the correct 1:1 mapping, we have to have:
*
* z_camera = 0.5 * x = 0.5 * y
*
* If x != y, then we have a non-uniform aspect ration, and a 1:1 mapping
* doesn't make sense.
*/
cogl_framebuffer_get_projection_matrix (framebuffer, &projection_matrix);
z_camera = 0.5f * graphene_matrix_get_value (&projection_matrix, 0, 0);
graphene_matrix_init_translate (&mv_matrix,
&GRAPHENE_POINT3D_INIT (0.0f,
-1.0f * height,
0.0f));
graphene_matrix_scale (&mv_matrix, 1.0f / width, -1.0f / height, 1.0f / width);
graphene_matrix_translate (&mv_matrix,
&GRAPHENE_POINT3D_INIT (-0.5f, -0.5f, -z_camera));
cogl_framebuffer_set_modelview_matrix (framebuffer, &mv_matrix);
}
static void
test_coglbox_map (ClutterActor *actor)
{
TestCoglbox *coglbox = TEST_COGLBOX (actor);
ClutterActor *stage;
ClutterPerspective perspective;
float stage_width;
float stage_height;
GError *error = NULL;
CLUTTER_ACTOR_CLASS (test_coglbox_parent_class)->map (actor);
printf ("Creating offscreen\n");
coglbox->framebuffer =
COGL_FRAMEBUFFER (cogl_offscreen_new_with_texture (coglbox->texture_id));
if (!cogl_framebuffer_allocate (coglbox->framebuffer, &error))
g_error ("Failed to allocate framebuffer: %s", error->message);
stage = clutter_actor_get_stage (actor);
clutter_stage_get_perspective (CLUTTER_STAGE (stage), &perspective);
clutter_actor_get_size (stage, &stage_width, &stage_height);
setup_viewport (coglbox->framebuffer,
(int) stage_width,
(int) stage_height,
perspective.fovy,
perspective.aspect,
perspective.z_near,
perspective.z_far);
if (!coglbox->framebuffer)
printf ("Failed creating offscreen to texture!\n");
}
static void
test_coglbox_init (TestCoglbox *self)
{
g_autoptr (GError) error = NULL;
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_test_get_backend ());
gchar *file;
printf ("Loading redhand.png\n");
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
self->texhand_id = clutter_test_texture_2d_new_from_file (ctx, file, &error);
if (error)
g_warning ("Error loading redhand.png: %s", error->message);
g_free (file);
printf ("Creating texture with size\n");
self->texture_id = cogl_texture_2d_new_with_size (ctx, 200, 200);
if (self->texture_id == NULL)
printf ("Failed creating texture with size!\n");
}
static void
test_coglbox_class_init (TestCoglboxClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
gobject_class->dispose = test_coglbox_dispose;
actor_class->map = test_coglbox_map;
actor_class->paint = test_coglbox_paint;
}
static ClutterActor*
test_coglbox_new (void)
{
return g_object_new (TEST_TYPE_COGLBOX, NULL);
}
G_MODULE_EXPORT int
test_cogl_offscreen_main (int argc, char *argv[])
{
ClutterActor *stage;
ClutterActor *coglbox;
clutter_test_init (&argc, &argv);
/* Stage */
stage = clutter_test_get_stage ();
clutter_actor_set_size (stage, 400, 400);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL);
/* Cogl Box */
coglbox = test_coglbox_new ();
clutter_actor_add_child (stage, coglbox);
clutter_actor_show (stage);
clutter_test_main ();
return 0;
}
G_MODULE_EXPORT const char *
test_cogl_offscreen_describe (void)
{
return "Offscreen buffer support in Cogl.";
}

View File

@ -1,359 +0,0 @@
#define COGL_DISABLE_DEPRECATION_WARNINGS
#include <clutter/clutter.h>
#include <errno.h>
#include <stdlib.h>
#include <glib.h>
#include <gmodule.h>
#include "clutter/test-utils.h"
#include "tests/clutter-test-utils.h"
typedef struct
{
const char *name;
const char *source;
} ShaderSource;
int
test_cogl_shader_glsl_main (int argc, char *argv[]);
/* a couple of boilerplate defines that are common amongst all the
* sample shaders
*/
/* FRAGMENT_SHADER_BEGIN: generate boilerplate with a local vec4 color already
* initialized, from a sampler2D in a variable tex.
*/
#define FRAGMENT_SHADER_VARS \
"uniform sampler2D tex;" \
"uniform float x_step, y_step;"
#define FRAGMENT_SHADER_BEGIN \
"void main (){" \
" vec4 color = texture2D (tex, vec2(cogl_tex_coord_in[0]));"
/* FRAGMENT_SHADER_END: apply the changed color to the output buffer correctly
* blended with the gl specified color (makes the opacity of actors work
* correctly).
*/
#define FRAGMENT_SHADER_END \
" cogl_color_out = color;" \
" cogl_color_out = cogl_color_out * cogl_color_in;" \
"}"
static ShaderSource shaders[]=
{
{"brightness-contrast",
FRAGMENT_SHADER_VARS
"uniform float brightness, contrast;"
FRAGMENT_SHADER_BEGIN
" color.rgb /= color.a;"
" color.rgb = (color.rgb - vec3(0.5, 0.5, 0.5)) * contrast + "
"vec3 (brightness + 0.5, brightness + 0.5, brightness + 0.5);"
" color.rgb *= color.a;"
FRAGMENT_SHADER_END
},
{"box-blur",
FRAGMENT_SHADER_VARS
"vec4 get_rgba_rel(sampler2D tex, float dx, float dy)"
"{"
" return texture2D (tex, cogl_tex_coord_in[0].st "
" + vec2(dx, dy) * 2.0);"
"}"
FRAGMENT_SHADER_BEGIN
" float count = 1.0;"
" color += get_rgba_rel (tex, -x_step, -y_step); count++;"
" color += get_rgba_rel (tex, -x_step, 0.0); count++;"
" color += get_rgba_rel (tex, -x_step, y_step); count++;"
" color += get_rgba_rel (tex, 0.0, -y_step); count++;"
" color += get_rgba_rel (tex, 0.0, 0.0); count++;"
" color += get_rgba_rel (tex, 0.0, y_step); count++;"
" color += get_rgba_rel (tex, x_step, -y_step); count++;"
" color += get_rgba_rel (tex, x_step, 0.0); count++;"
" color += get_rgba_rel (tex, x_step, y_step); count++;"
" color = color / count;"
FRAGMENT_SHADER_END
},
{"invert",
FRAGMENT_SHADER_VARS
FRAGMENT_SHADER_BEGIN
" color.rgb /= color.a;"
" color.rgb = vec3(1.0, 1.0, 1.0) - color.rgb;\n"
" color.rgb *= color.a;"
FRAGMENT_SHADER_END
},
{"brightness-contrast",
FRAGMENT_SHADER_VARS
"uniform float brightness;"
"uniform float contrast;"
FRAGMENT_SHADER_BEGIN
" color.rgb /= color.a;"
" color.r = (color.r - 0.5) * contrast + brightness + 0.5;"
" color.g = (color.g - 0.5) * contrast + brightness + 0.5;"
" color.b = (color.b - 0.5) * contrast + brightness + 0.5;"
" color.rgb *= color.a;"
FRAGMENT_SHADER_END
},
{"gray",
FRAGMENT_SHADER_VARS
FRAGMENT_SHADER_BEGIN
" float avg = (color.r + color.g + color.b) / 3.0;"
" color.r = avg;"
" color.g = avg;"
" color.b = avg;"
FRAGMENT_SHADER_END
},
{"combined-mirror",
FRAGMENT_SHADER_VARS
FRAGMENT_SHADER_BEGIN
" vec4 colorB = texture2D (tex, vec2(cogl_tex_coord_in[0].ts));"
" float avg = (color.r + color.g + color.b) / 3.0;"
" color.r = avg;"
" color.g = avg;"
" color.b = avg;"
" color = (color + colorB)/2.0;"
FRAGMENT_SHADER_END
},
{"edge-detect",
FRAGMENT_SHADER_VARS
"float get_avg_rel(sampler2D texB, float dx, float dy)"
"{"
" vec4 colorB = texture2D (texB, cogl_tex_coord_in[0].st + vec2(dx, dy));"
" return (colorB.r + colorB.g + colorB.b) / 3.0;"
"}"
FRAGMENT_SHADER_BEGIN
" mat3 sobel_h = mat3( 1.0, 2.0, 1.0,"
" 0.0, 0.0, 0.0,"
" -1.0, -2.0, -1.0);"
" mat3 sobel_v = mat3( 1.0, 0.0, -1.0,"
" 2.0, 0.0, -2.0,"
" 1.0, 0.0, -1.0);"
" mat3 map = mat3( get_avg_rel(tex, -x_step, -y_step),"
" get_avg_rel(tex, -x_step, 0.0),"
" get_avg_rel(tex, -x_step, y_step),"
" get_avg_rel(tex, 0.0, -y_step),"
" get_avg_rel(tex, 0.0, 0.0),"
" get_avg_rel(tex, 0.0, y_step),"
" get_avg_rel(tex, x_step, -y_step),"
" get_avg_rel(tex, x_step, 0.0),"
" get_avg_rel(tex, x_step, y_step) );"
" mat3 gh = sobel_h * map;"
" mat3 gv = map * sobel_v;"
" float avgh = (gh[0][0] + gh[0][1] + gh[0][2] +"
" gh[1][0] + gh[1][1] + gh[1][2] +"
" gh[2][0] + gh[2][1] + gh[2][2]) / 18.0 + 0.5;"
" float avgv = (gv[0][0] + gv[0][1] + gv[0][2] +"
" gv[1][0] + gv[1][1] + gv[1][2] +"
" gv[2][0] + gv[2][1] + gv[2][2]) / 18.0 + 0.5;"
" float avg = (avgh + avgv) / 2.0;"
" color.r = avg * color.r;"
" color.g = avg * color.g;"
" color.b = avg * color.b;"
FRAGMENT_SHADER_END
}
};
static CoglTexture *redhand;
static CoglPipeline *pipeline;
static unsigned int timeout_id = 0;
static int shader_no = 0;
static void
on_paint (ClutterActor *actor,
ClutterPaintContext *paint_context)
{
CoglFramebuffer *framebuffer =
clutter_paint_context_get_framebuffer (paint_context);
float stage_width = clutter_actor_get_width (actor);
float stage_height = clutter_actor_get_height (actor);
float image_width = cogl_texture_get_width (redhand);
float image_height = cogl_texture_get_height (redhand);
cogl_framebuffer_draw_rectangle (framebuffer, pipeline,
stage_width / 2.0f - image_width / 2.0f,
stage_height / 2.0f - image_height / 2.0f,
stage_width / 2.0f + image_width / 2.0f,
stage_height / 2.0f + image_height / 2.0f);
}
static void
set_shader_num (int new_no)
{
CoglShader *shader;
CoglProgram *program;
CoglPipeline *shader_pipeline;
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_test_get_backend ());
int image_width = cogl_texture_get_width (redhand);
int image_height = cogl_texture_get_height (redhand);
int uniform_no;
g_print ("setting shaders[%i] named '%s'\n",
new_no,
shaders[new_no].name);
shader_pipeline = cogl_pipeline_new (ctx);
shader = cogl_shader_new (COGL_SHADER_TYPE_FRAGMENT);
cogl_shader_source (shader, shaders[new_no].source);
program = cogl_program_new ();
cogl_program_attach_shader (program, shader);
g_object_unref (shader);
cogl_program_link (program);
uniform_no = cogl_program_get_uniform_location (program, "tex");
cogl_program_set_uniform_1i (program, uniform_no, 0);
uniform_no = cogl_program_get_uniform_location (program, "radius");
cogl_program_set_uniform_1f (program, uniform_no, 3.0f);
uniform_no = cogl_program_get_uniform_location (program, "brightness");
cogl_program_set_uniform_1f (program, uniform_no, 0.4f);
uniform_no = cogl_program_get_uniform_location (program, "contrast");
cogl_program_set_uniform_1f (program, uniform_no, -1.9f);
uniform_no = cogl_program_get_uniform_location (program, "x_step");
cogl_program_set_uniform_1f (program, uniform_no, 1.0f / image_width);
uniform_no = cogl_program_get_uniform_location (program, "y_step");
cogl_program_set_uniform_1f (program, uniform_no, 1.0f / image_height);
cogl_pipeline_set_user_program (shader_pipeline, program);
g_object_unref (program);
shader_no = new_no;
}
static gboolean
button_release_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer data)
{
int new_no;
/* Stop the automatic cycling if the user want to manually control
* which shader to display */
g_clear_handle_id (&timeout_id, g_source_remove);
if (clutter_event_get_button (event) == 1)
{
new_no = shader_no - 1;
if (new_no < 0)
new_no = G_N_ELEMENTS (shaders) - 1;
}
else
{
new_no = shader_no + 1;
if (new_no >= G_N_ELEMENTS (shaders))
new_no = 0;
}
set_shader_num (new_no);
return CLUTTER_EVENT_STOP;
}
static gboolean
key_release_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer user_data)
{
guint keysym = clutter_event_get_key_symbol (event);
ClutterModifierType mods = clutter_event_get_state (event);
if (keysym == CLUTTER_KEY_q ||
((mods & CLUTTER_SHIFT_MASK) && keysym == CLUTTER_KEY_q))
clutter_test_quit ();
return CLUTTER_EVENT_STOP;
}
static gboolean
timeout_cb (gpointer user_data)
{
shader_no++;
if (shader_no > (G_N_ELEMENTS (shaders) - 1))
shader_no = 0;
set_shader_num (shader_no);
return G_SOURCE_CONTINUE;
}
static gboolean
idle_cb (gpointer data)
{
clutter_actor_queue_redraw (data);
return G_SOURCE_CONTINUE;
}
static gboolean
destroy_window_cb (ClutterStage *stage,
ClutterEvent *event,
gpointer user_data)
{
clutter_test_quit ();
return CLUTTER_EVENT_STOP;
}
G_MODULE_EXPORT int
test_cogl_shader_glsl_main (int argc, char *argv[])
{
ClutterActor *stage;
ClutterActor *actor;
char *file;
GError *error;
CoglColor stage_color = { 0x61, 0x64, 0x8c, 0xff };
CoglPipeline *shader_pipeline;
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_test_get_backend ());
clutter_test_init (&argc, &argv);
stage = clutter_test_get_stage ();
actor = g_object_new (CLUTTER_TYPE_TEST_ACTOR, NULL);
clutter_actor_add_child (stage, actor);
clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &stage_color);
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
error = NULL;
redhand = clutter_test_texture_2d_new_from_file (ctx, file, &error);
if (redhand == NULL)
g_error ("image load failed: %s", error->message);
shader_pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (shader_pipeline, 0, redhand);
set_shader_num (0);
g_signal_connect (actor, "paint", G_CALLBACK (on_paint), NULL);
clutter_actor_set_reactive (stage, TRUE);
g_signal_connect (stage, "button-release-event",
G_CALLBACK (button_release_cb), NULL);
g_signal_connect (stage, "key-release-event",
G_CALLBACK (key_release_cb), NULL);
g_signal_connect (stage, "delete-event",
G_CALLBACK (destroy_window_cb), NULL);
timeout_id = g_timeout_add (1000, timeout_cb, NULL);
g_idle_add (idle_cb, stage);
clutter_actor_show (stage);
clutter_test_main ();
return EXIT_SUCCESS;
}

View File

@ -1,180 +0,0 @@
#include <glib.h>
#include <gmodule.h>
#include <stdlib.h>
#include <math.h>
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "clutter/test-utils.h"
#include "tests/clutter-test-utils.h"
/* Coglbox declaration
*--------------------------------------------------*/
G_BEGIN_DECLS
#define TEST_TYPE_COGLBOX test_coglbox_get_type()
static
G_DECLARE_FINAL_TYPE (TestCoglbox, test_coglbox, TEST, COGLBOX, ClutterActor)
struct _TestCoglbox
{
ClutterActor parent;
CoglTexture *cogl_tex_id;
float animation_progress;
};
G_DEFINE_TYPE (TestCoglbox, test_coglbox, CLUTTER_TYPE_ACTOR);
int
test_cogl_tex_tile_main (int argc, char *argv[]);
const char *
test_cogl_tex_tile_describe (void);
G_END_DECLS
/* Coglbox implementation
*--------------------------------------------------*/
static void
test_coglbox_paint (ClutterActor *self,
ClutterPaintContext *paint_context)
{
TestCoglbox *coglbox = TEST_COGLBOX (self);
CoglFramebuffer *framebuffer =
clutter_paint_context_get_framebuffer (paint_context);
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
CoglPipeline *pipeline;
CoglColor color;
gfloat texcoords[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
gfloat angle;
gfloat frac;
gint t;
angle = (float) (coglbox->animation_progress * 2 * G_PI);
frac = ((coglbox->animation_progress <= 0.5f
? coglbox->animation_progress
: 1.0f - coglbox->animation_progress) + 0.5f) * 2.0f;
for (t=0; t<4; t+=2)
{
texcoords[t] += cosf (angle);
texcoords[t+1] += sinf (angle);
texcoords[t] *= frac;
texcoords[t+1] *= frac;
}
cogl_framebuffer_push_matrix (framebuffer);
pipeline = cogl_pipeline_new (ctx);
cogl_color_init_from_4f (&color, 0.4f, 0.4f, 221.0f / 255.0f, 1.0f);
cogl_pipeline_set_color (pipeline, &color);
cogl_framebuffer_draw_rectangle (framebuffer, pipeline, 0, 0, 400, 400);
g_object_unref (pipeline);
cogl_framebuffer_translate (framebuffer, 100, 100, 0);
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 0, coglbox->cogl_tex_id);
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
0, 0, 200, 213,
texcoords[0], texcoords[1],
texcoords[2], texcoords[3]);
g_object_unref (pipeline);
cogl_framebuffer_pop_matrix (framebuffer);
}
static void
test_coglbox_dispose (GObject *object)
{
TestCoglbox *coglbox = TEST_COGLBOX (object);
g_object_unref (coglbox->cogl_tex_id);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
}
static void
test_coglbox_init (TestCoglbox *self)
{
g_autoptr (GError) error = NULL;
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_test_get_backend ());
gchar *file;
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
self->cogl_tex_id = clutter_test_texture_2d_new_from_file (ctx, file, &error);
if (error)
g_warning ("Error loading redhand.png: %s", error->message);
g_free (file);
}
static void
test_coglbox_class_init (TestCoglboxClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
gobject_class->dispose = test_coglbox_dispose;
actor_class->paint = test_coglbox_paint;
}
static ClutterActor*
test_coglbox_new (void)
{
return g_object_new (TEST_TYPE_COGLBOX, NULL);
}
static void
frame_cb (ClutterTimeline *timeline,
int msecs,
gpointer data)
{
TestCoglbox *coglbox = TEST_COGLBOX (data);
coglbox->animation_progress = (float) clutter_timeline_get_progress (timeline);
clutter_actor_queue_redraw (CLUTTER_ACTOR (data));
}
G_MODULE_EXPORT int
test_cogl_tex_tile_main (int argc, char *argv[])
{
ClutterActor *stage;
ClutterActor *coglbox;
ClutterTimeline *timeline;
clutter_test_init (&argc, &argv);
/* Stage */
stage = clutter_test_get_stage ();
clutter_actor_set_size (stage, 400, 400);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL);
/* Cogl Box */
coglbox = test_coglbox_new ();
clutter_actor_add_child (stage, coglbox);
/* Timeline for animation */
timeline = clutter_timeline_new_for_actor (stage, 6000); /* 6 second duration */
clutter_timeline_set_repeat_count (timeline, -1);
g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), coglbox);
clutter_timeline_start (timeline);
clutter_actor_show (stage);
clutter_test_main ();
return 0;
}
G_MODULE_EXPORT const char *
test_cogl_tex_tile_describe (void)
{
return "Texture tiling.";
}

View File

@ -1,126 +0,0 @@
#include <clutter/clutter.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
static GQuark pixbuf_key = 0;
static inline CoglBitmap *
clutter_test_create_bitmap_from_file (CoglContext *ctx,
const char *filename,
GError **error)
{
pixbuf_key = g_quark_from_static_string ("-cogl-bitmap-pixbuf-key");
GdkPixbuf *pixbuf;
gboolean has_alpha;
GdkColorspace color_space;
CoglPixelFormat pixel_format;
int width;
int height;
int rowstride;
int bits_per_sample;
int n_channels;
CoglBitmap *bmp;
GError *glib_error = NULL;
/* Load from file using GdkPixbuf */
pixbuf = gdk_pixbuf_new_from_file (filename, &glib_error);
if (pixbuf == NULL)
{
g_propagate_error (error, glib_error);
return FALSE;
}
/* Get pixbuf properties */
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
color_space = gdk_pixbuf_get_colorspace (pixbuf);
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf);
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
/* According to current docs this should be true and so
* the translation to cogl pixel format below valid */
g_assert_cmpint (bits_per_sample, ==, 8);
if (has_alpha)
g_assert_cmpint (n_channels, ==, 4);
else
g_assert_cmpint (n_channels, ==, 3);
/* Translate to cogl pixel format */
switch (color_space)
{
case GDK_COLORSPACE_RGB:
/* The only format supported by GdkPixbuf so far */
pixel_format = has_alpha ?
COGL_PIXEL_FORMAT_RGBA_8888 :
COGL_PIXEL_FORMAT_RGB_888;
break;
default:
/* Ouch, spec changed! */
g_object_unref (pixbuf);
return FALSE;
}
/* We just use the data directly from the pixbuf so that we don't
have to copy to a separate buffer. Note that Cogl is expected not
to read past the end of bpp*width on the last row even if the
rowstride is much larger so we don't need to worry about
GdkPixbuf's semantics that it may under-allocate the buffer. */
bmp = cogl_bitmap_new_for_data (ctx,
width,
height,
pixel_format,
rowstride,
gdk_pixbuf_get_pixels (pixbuf));
g_object_set_qdata_full (G_OBJECT (bmp),
pixbuf_key,
pixbuf,
g_object_unref);
return bmp;
}
static inline CoglTexture *
clutter_test_texture_2d_sliced_new_from_file (CoglContext *ctx,
const char *filename,
GError **error)
{
CoglBitmap *bmp;
CoglTexture *tex_2ds = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
bmp = clutter_test_create_bitmap_from_file (ctx, filename, error);
if (bmp == NULL)
return NULL;
tex_2ds = cogl_texture_2d_sliced_new_from_bitmap (bmp, COGL_TEXTURE_MAX_WASTE);
g_object_unref (bmp);
return tex_2ds;
}
static inline CoglTexture *
clutter_test_texture_2d_new_from_file (CoglContext *ctx,
const char *filename,
GError **error)
{
CoglBitmap *bmp;
CoglTexture *tex_2d = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
bmp = clutter_test_create_bitmap_from_file (ctx, filename, error);
if (bmp == NULL)
return NULL;
tex_2d = cogl_texture_2d_new_from_bitmap (bmp);
g_object_unref (bmp);
return tex_2d;
}