1 #include <cogl/cogl.h>
2
3 #include "test-utils.h"
4
5 #define TEST_SQUARE_SIZE 10
6
7 static CoglPipeline *
create_two_layer_pipeline(void)8 create_two_layer_pipeline (void)
9 {
10 CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
11 CoglColor color;
12
13 /* The pipeline is initially black */
14 cogl_pipeline_set_color4ub (pipeline, 0, 0, 0, 255);
15
16 /* The first layer adds a full red component */
17 cogl_color_init_from_4ub (&color, 255, 0, 0, 255);
18 cogl_pipeline_set_layer_combine_constant (pipeline, 0, &color);
19 cogl_pipeline_set_layer_combine (pipeline,
20 0, /* layer_num */
21 "RGBA=ADD(PREVIOUS,CONSTANT)",
22 NULL);
23
24 /* The second layer adds a full green component */
25 cogl_color_init_from_4ub (&color, 0, 255, 0, 255);
26 cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color);
27 cogl_pipeline_set_layer_combine (pipeline,
28 1, /* layer_num */
29 "RGBA=ADD(PREVIOUS,CONSTANT)",
30 NULL);
31
32 return pipeline;
33 }
34
35 static void
test_color(CoglPipeline * pipeline,uint32_t color,int pos)36 test_color (CoglPipeline *pipeline,
37 uint32_t color,
38 int pos)
39 {
40 cogl_framebuffer_draw_rectangle (test_fb,
41 pipeline,
42 pos * TEST_SQUARE_SIZE,
43 0,
44 pos * TEST_SQUARE_SIZE + TEST_SQUARE_SIZE,
45 TEST_SQUARE_SIZE);
46 test_utils_check_pixel (test_fb,
47 pos * TEST_SQUARE_SIZE + TEST_SQUARE_SIZE / 2,
48 TEST_SQUARE_SIZE / 2,
49 color);
50 }
51
52 void
test_layer_remove(void)53 test_layer_remove (void)
54 {
55 CoglPipeline *pipeline0, *pipeline1;
56 CoglColor color;
57 int pos = 0;
58
59 cogl_framebuffer_orthographic (test_fb,
60 0, 0,
61 cogl_framebuffer_get_width (test_fb),
62 cogl_framebuffer_get_height (test_fb),
63 -1,
64 100);
65
66 /** TEST 1 **/
67 /* Basic sanity check that the pipeline combines the two colors
68 * together properly */
69 pipeline0 = create_two_layer_pipeline ();
70 test_color (pipeline0, 0xffff00ff, pos++);
71 cogl_object_unref (pipeline0);
72
73 /** TEST 2 **/
74 /* Check that we can remove the second layer */
75 pipeline0 = create_two_layer_pipeline ();
76 cogl_pipeline_remove_layer (pipeline0, 1);
77 test_color (pipeline0, 0xff0000ff, pos++);
78 cogl_object_unref (pipeline0);
79
80 /** TEST 3 **/
81 /* Check that we can remove the first layer */
82 pipeline0 = create_two_layer_pipeline ();
83 cogl_pipeline_remove_layer (pipeline0, 0);
84 test_color (pipeline0, 0x00ff00ff, pos++);
85 cogl_object_unref (pipeline0);
86
87 /** TEST 4 **/
88 /* Check that we can make a copy and remove a layer from the
89 * original pipeline */
90 pipeline0 = create_two_layer_pipeline ();
91 pipeline1 = cogl_pipeline_copy (pipeline0);
92 cogl_pipeline_remove_layer (pipeline0, 1);
93 test_color (pipeline0, 0xff0000ff, pos++);
94 test_color (pipeline1, 0xffff00ff, pos++);
95 cogl_object_unref (pipeline0);
96 cogl_object_unref (pipeline1);
97
98 /** TEST 5 **/
99 /* Check that we can make a copy and remove the second layer from the
100 * new pipeline */
101 pipeline0 = create_two_layer_pipeline ();
102 pipeline1 = cogl_pipeline_copy (pipeline0);
103 cogl_pipeline_remove_layer (pipeline1, 1);
104 test_color (pipeline0, 0xffff00ff, pos++);
105 test_color (pipeline1, 0xff0000ff, pos++);
106 cogl_object_unref (pipeline0);
107 cogl_object_unref (pipeline1);
108
109 /** TEST 6 **/
110 /* Check that we can make a copy and remove the first layer from the
111 * new pipeline */
112 pipeline0 = create_two_layer_pipeline ();
113 pipeline1 = cogl_pipeline_copy (pipeline0);
114 cogl_pipeline_remove_layer (pipeline1, 0);
115 test_color (pipeline0, 0xffff00ff, pos++);
116 test_color (pipeline1, 0x00ff00ff, pos++);
117 cogl_object_unref (pipeline0);
118 cogl_object_unref (pipeline1);
119
120 /** TEST 7 **/
121 /* Check that we can modify a layer in a child pipeline */
122 pipeline0 = create_two_layer_pipeline ();
123 pipeline1 = cogl_pipeline_copy (pipeline0);
124 cogl_color_init_from_4ub (&color, 0, 0, 255, 255);
125 cogl_pipeline_set_layer_combine_constant (pipeline1, 0, &color);
126 test_color (pipeline0, 0xffff00ff, pos++);
127 test_color (pipeline1, 0x00ffffff, pos++);
128 cogl_object_unref (pipeline0);
129 cogl_object_unref (pipeline1);
130
131 /** TEST 8 **/
132 /* Check that we can modify a layer in a child pipeline but then remove it */
133 pipeline0 = create_two_layer_pipeline ();
134 pipeline1 = cogl_pipeline_copy (pipeline0);
135 cogl_color_init_from_4ub (&color, 0, 0, 255, 255);
136 cogl_pipeline_set_layer_combine_constant (pipeline1, 0, &color);
137 cogl_pipeline_remove_layer (pipeline1, 0);
138 test_color (pipeline0, 0xffff00ff, pos++);
139 test_color (pipeline1, 0x00ff00ff, pos++);
140 cogl_object_unref (pipeline0);
141 cogl_object_unref (pipeline1);
142
143 if (cogl_test_verbose ())
144 g_print ("OK\n");
145 }
146