4
#include "test-utils.h"
6
#define BITMAP_SIZE 256
9
* Creates a 256 x 256 with image data split into four quadrants. The
10
* colours of these in reading order will be: blue, green, cyan,
13
generate_bitmap_data (uint8_t *data,
18
for (y = 0; y < BITMAP_SIZE; y++)
20
for (x = 0; x < BITMAP_SIZE; x++)
22
int color_num = x / (BITMAP_SIZE / 2) + y / (BITMAP_SIZE / 2) * 2 + 1;
23
*(data++) = (color_num & 4) ? 255 : 0;
24
*(data++) = (color_num & 2) ? 255 : 0;
25
*(data++) = (color_num & 1) ? 255 : 0;
28
data += stride - BITMAP_SIZE * 4;
38
bitmap = cogl_bitmap_new_with_size (test_ctx,
41
COGL_PIXEL_FORMAT_RGBA_8888);
42
buffer = cogl_bitmap_get_buffer (bitmap);
44
g_assert (cogl_is_pixel_buffer (buffer));
45
g_assert (cogl_is_buffer (buffer));
47
cogl_buffer_set_update_hint (buffer, COGL_BUFFER_UPDATE_HINT_DYNAMIC);
48
g_assert_cmpint (cogl_buffer_get_update_hint (buffer),
50
COGL_BUFFER_UPDATE_HINT_DYNAMIC);
56
create_and_fill_bitmap (void)
58
CoglBitmap *bitmap = create_bitmap ();
59
CoglBuffer *buffer = cogl_bitmap_get_buffer (bitmap);
63
stride = cogl_bitmap_get_rowstride (bitmap);
65
map = cogl_buffer_map (buffer,
66
COGL_BUFFER_ACCESS_WRITE,
67
COGL_BUFFER_MAP_HINT_DISCARD);
70
generate_bitmap_data (map, stride);
72
cogl_buffer_unmap (buffer);
78
create_texture_from_bitmap (CoglBitmap *bitmap)
80
CoglTexture2D *texture;
82
texture = cogl_texture_2d_new_from_bitmap (bitmap);
84
g_assert (texture != NULL);
90
create_pipeline_from_texture (CoglTexture *texture)
92
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
94
cogl_pipeline_set_layer_texture (pipeline, 0, texture);
95
cogl_pipeline_set_layer_filters (pipeline,
97
COGL_PIPELINE_FILTER_NEAREST,
98
COGL_PIPELINE_FILTER_NEAREST);
104
check_colours (uint32_t color0,
109
int fb_width = cogl_framebuffer_get_width (test_fb);
110
int fb_height = cogl_framebuffer_get_height (test_fb);
112
test_utils_check_region (test_fb,
114
fb_width / 2 - 2, /* width */
115
fb_height / 2 - 2, /* height */
117
test_utils_check_region (test_fb,
118
fb_width / 2 + 1, /* x */
120
fb_width / 2 - 2, /* width */
121
fb_height / 2 - 2, /* height */
123
test_utils_check_region (test_fb,
125
fb_height / 2 + 1, /* y */
126
fb_width / 2 - 2, /* width */
127
fb_height / 2 - 2, /* height */
129
test_utils_check_region (test_fb,
130
fb_width / 2 + 1, /* x */
131
fb_height / 2 + 1, /* y */
132
fb_width / 2 - 2, /* width */
133
fb_height / 2 - 2, /* height */
138
test_pixel_buffer_map (void)
140
CoglBitmap *bitmap = create_and_fill_bitmap ();
141
CoglPipeline *pipeline;
142
CoglTexture *texture;
144
texture = create_texture_from_bitmap (bitmap);
145
pipeline = create_pipeline_from_texture (texture);
147
cogl_framebuffer_draw_rectangle (test_fb,
152
cogl_object_unref (bitmap);
153
cogl_object_unref (texture);
154
cogl_object_unref (pipeline);
156
check_colours (0x0000ffff,
161
if (cogl_test_verbose ())
166
test_pixel_buffer_set_data (void)
168
CoglBitmap *bitmap = create_bitmap ();
169
CoglBuffer *buffer = cogl_bitmap_get_buffer (bitmap);
170
CoglPipeline *pipeline;
171
CoglTexture *texture;
175
stride = cogl_bitmap_get_rowstride (bitmap);
177
data = g_malloc (stride * BITMAP_SIZE);
179
generate_bitmap_data (data, stride);
181
cogl_buffer_set_data (buffer,
184
stride * (BITMAP_SIZE - 1) +
189
texture = create_texture_from_bitmap (bitmap);
190
pipeline = create_pipeline_from_texture (texture);
192
cogl_framebuffer_draw_rectangle (test_fb,
197
cogl_object_unref (bitmap);
198
cogl_object_unref (texture);
199
cogl_object_unref (pipeline);
201
check_colours (0x0000ffff,
206
if (cogl_test_verbose ())
211
create_white_texture (void)
213
CoglTexture2D *texture;
214
uint8_t *data = g_malloc (BITMAP_SIZE * BITMAP_SIZE * 4);
216
memset (data, 255, BITMAP_SIZE * BITMAP_SIZE * 4);
218
texture = cogl_texture_2d_new_from_data (test_ctx,
221
COGL_PIXEL_FORMAT_RGBA_8888,
222
BITMAP_SIZE * 4, /* rowstride */
224
NULL); /* don't catch errors */
232
test_pixel_buffer_sub_region (void)
234
CoglBitmap *bitmap = create_and_fill_bitmap ();
235
CoglPipeline *pipeline;
236
CoglTexture *texture;
238
texture = create_white_texture ();
240
/* Replace the top-right quadrant of the texture with the red part
242
cogl_texture_set_region_from_bitmap (texture,
243
BITMAP_SIZE / 2, /* src_x */
244
BITMAP_SIZE / 2, /* src_y */
245
BITMAP_SIZE / 2, /* dst_x */
247
BITMAP_SIZE / 2, /* width */
248
BITMAP_SIZE / 2, /* height */
251
pipeline = create_pipeline_from_texture (texture);
253
cogl_framebuffer_draw_rectangle (test_fb,
258
cogl_object_unref (bitmap);
259
cogl_object_unref (texture);
260
cogl_object_unref (pipeline);
262
check_colours (0xffffffff,
267
if (cogl_test_verbose ())