1 | /*
|
---|
2 | * Copyright (c) 2021 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <errno.h>
|
---|
30 | #include <gfx/color.h>
|
---|
31 | #include <gfx/render.h>
|
---|
32 | #include <pcut/pcut.h>
|
---|
33 | #include <stdio.h>
|
---|
34 |
|
---|
35 | #include "../clonegc.h"
|
---|
36 |
|
---|
37 | PCUT_INIT;
|
---|
38 |
|
---|
39 | PCUT_TEST_SUITE(clonegc);
|
---|
40 |
|
---|
41 | static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
|
---|
42 | static errno_t testgc_set_color(void *, gfx_color_t *);
|
---|
43 | static errno_t testgc_fill_rect(void *, gfx_rect_t *);
|
---|
44 | static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
|
---|
45 | gfx_bitmap_alloc_t *, void **);
|
---|
46 | static errno_t testgc_bitmap_destroy(void *);
|
---|
47 | static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
|
---|
48 | static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
|
---|
49 |
|
---|
50 | static gfx_context_ops_t ops = {
|
---|
51 | .set_clip_rect = testgc_set_clip_rect,
|
---|
52 | .set_color = testgc_set_color,
|
---|
53 | .fill_rect = testgc_fill_rect,
|
---|
54 | .bitmap_create = testgc_bitmap_create,
|
---|
55 | .bitmap_destroy = testgc_bitmap_destroy,
|
---|
56 | .bitmap_render = testgc_bitmap_render,
|
---|
57 | .bitmap_get_alloc = testgc_bitmap_get_alloc
|
---|
58 | };
|
---|
59 |
|
---|
60 | typedef struct {
|
---|
61 | /** Error code to return */
|
---|
62 | errno_t rc;
|
---|
63 |
|
---|
64 | bool set_clip_rect_called;
|
---|
65 | gfx_rect_t *set_clip_rect_rect;
|
---|
66 |
|
---|
67 | bool set_color_called;
|
---|
68 | gfx_color_t *set_color_color;
|
---|
69 |
|
---|
70 | bool fill_rect_called;
|
---|
71 | gfx_rect_t *fill_rect_rect;
|
---|
72 |
|
---|
73 | bool bm_created;
|
---|
74 | bool bm_destroyed;
|
---|
75 | gfx_bitmap_params_t bm_params;
|
---|
76 | void *bm_pixels;
|
---|
77 | gfx_rect_t bm_srect;
|
---|
78 | gfx_coord2_t bm_offs;
|
---|
79 | bool bm_rendered;
|
---|
80 | bool bm_got_alloc;
|
---|
81 | } test_gc_t;
|
---|
82 |
|
---|
83 | typedef struct {
|
---|
84 | test_gc_t *tgc;
|
---|
85 | gfx_bitmap_alloc_t alloc;
|
---|
86 | bool myalloc;
|
---|
87 | } testgc_bitmap_t;
|
---|
88 |
|
---|
89 | enum {
|
---|
90 | alloc_pitch = 42,
|
---|
91 | alloc_off0 = 33
|
---|
92 | };
|
---|
93 |
|
---|
94 | /** Test creating and deleting clone GC */
|
---|
95 | PCUT_TEST(create_delete)
|
---|
96 | {
|
---|
97 | ds_clonegc_t *cgc;
|
---|
98 | errno_t rc;
|
---|
99 |
|
---|
100 | rc = ds_clonegc_create(NULL, &cgc);
|
---|
101 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
102 |
|
---|
103 | rc = ds_clonegc_delete(cgc);
|
---|
104 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /** Set clipping rectangle with two output GCs */
|
---|
108 | PCUT_TEST(set_clip_rect)
|
---|
109 | {
|
---|
110 | ds_clonegc_t *cgc;
|
---|
111 | gfx_context_t *gc;
|
---|
112 | test_gc_t tgc1;
|
---|
113 | gfx_context_t *gc1;
|
---|
114 | test_gc_t tgc2;
|
---|
115 | gfx_context_t *gc2;
|
---|
116 | gfx_rect_t rect;
|
---|
117 | errno_t rc;
|
---|
118 |
|
---|
119 | /* Create clone GC */
|
---|
120 | rc = ds_clonegc_create(NULL, &cgc);
|
---|
121 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
122 |
|
---|
123 | gc = ds_clonegc_get_ctx(cgc);
|
---|
124 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
125 |
|
---|
126 | /* Add two output GCs */
|
---|
127 |
|
---|
128 | rc = gfx_context_new(&ops, &tgc1, &gc1);
|
---|
129 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
130 |
|
---|
131 | rc = ds_clonegc_add_output(cgc, gc1);
|
---|
132 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
133 |
|
---|
134 | rc = gfx_context_new(&ops, &tgc2, &gc2);
|
---|
135 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
136 |
|
---|
137 | rc = ds_clonegc_add_output(cgc, gc2);
|
---|
138 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
139 |
|
---|
140 | rect.p0.x = 1;
|
---|
141 | rect.p0.y = 2;
|
---|
142 | rect.p1.x = 3;
|
---|
143 | rect.p1.y = 4;
|
---|
144 |
|
---|
145 | /* Set clipping rectangle returning error */
|
---|
146 |
|
---|
147 | tgc1.set_clip_rect_called = false;
|
---|
148 | tgc2.set_clip_rect_called = false;
|
---|
149 | tgc1.rc = EINVAL;
|
---|
150 | tgc2.rc = EINVAL;
|
---|
151 |
|
---|
152 | rc = gfx_set_clip_rect(gc, &rect);
|
---|
153 | PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
|
---|
154 |
|
---|
155 | PCUT_ASSERT_TRUE(tgc1.set_clip_rect_called);
|
---|
156 | PCUT_ASSERT_EQUALS(&rect, tgc1.set_clip_rect_rect);
|
---|
157 | PCUT_ASSERT_FALSE(tgc2.set_clip_rect_called);
|
---|
158 |
|
---|
159 | /* Set clipping rectangle returning success for all outputs */
|
---|
160 | tgc1.set_clip_rect_called = false;
|
---|
161 | tgc2.set_clip_rect_called = false;
|
---|
162 | tgc1.rc = EOK;
|
---|
163 | tgc2.rc = EOK;
|
---|
164 |
|
---|
165 | rc = gfx_set_clip_rect(gc, &rect);
|
---|
166 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
167 |
|
---|
168 | PCUT_ASSERT_TRUE(tgc1.set_clip_rect_called);
|
---|
169 | PCUT_ASSERT_EQUALS(&rect, tgc1.set_clip_rect_rect);
|
---|
170 | PCUT_ASSERT_TRUE(tgc2.set_clip_rect_called);
|
---|
171 | PCUT_ASSERT_EQUALS(&rect, tgc2.set_clip_rect_rect);
|
---|
172 |
|
---|
173 | rc = ds_clonegc_delete(cgc);
|
---|
174 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
175 | }
|
---|
176 |
|
---|
177 | /** Test set color operation with two output GCs */
|
---|
178 | PCUT_TEST(set_color)
|
---|
179 | {
|
---|
180 | ds_clonegc_t *cgc;
|
---|
181 | gfx_context_t *gc;
|
---|
182 | test_gc_t tgc1;
|
---|
183 | gfx_context_t *gc1;
|
---|
184 | test_gc_t tgc2;
|
---|
185 | gfx_context_t *gc2;
|
---|
186 | gfx_color_t *color;
|
---|
187 | errno_t rc;
|
---|
188 |
|
---|
189 | /* Create clone GC */
|
---|
190 | rc = ds_clonegc_create(NULL, &cgc);
|
---|
191 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
192 |
|
---|
193 | gc = ds_clonegc_get_ctx(cgc);
|
---|
194 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
195 |
|
---|
196 | /* Add two output GCs */
|
---|
197 |
|
---|
198 | rc = gfx_context_new(&ops, &tgc1, &gc1);
|
---|
199 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
200 |
|
---|
201 | rc = ds_clonegc_add_output(cgc, gc1);
|
---|
202 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
203 |
|
---|
204 | rc = gfx_context_new(&ops, &tgc2, &gc2);
|
---|
205 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
206 |
|
---|
207 | rc = ds_clonegc_add_output(cgc, gc2);
|
---|
208 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
209 |
|
---|
210 | rc = gfx_color_new_rgb_i16(0xaaaa, 0xbbbb, 0xcccc, &color);
|
---|
211 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
212 |
|
---|
213 | /* Set color returning error */
|
---|
214 |
|
---|
215 | tgc1.set_color_called = false;
|
---|
216 | tgc2.set_color_called = false;
|
---|
217 | tgc1.rc = EINVAL;
|
---|
218 | tgc2.rc = EINVAL;
|
---|
219 |
|
---|
220 | rc = gfx_set_color(gc, color);
|
---|
221 | PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
|
---|
222 |
|
---|
223 | PCUT_ASSERT_TRUE(tgc1.set_color_called);
|
---|
224 | PCUT_ASSERT_EQUALS(color, tgc1.set_color_color);
|
---|
225 | PCUT_ASSERT_FALSE(tgc2.set_color_called);
|
---|
226 |
|
---|
227 | /* Set color returning success for all outputs */
|
---|
228 | tgc1.set_color_called = false;
|
---|
229 | tgc2.set_color_called = false;
|
---|
230 | tgc1.rc = EOK;
|
---|
231 | tgc2.rc = EOK;
|
---|
232 |
|
---|
233 | rc = gfx_set_color(gc, color);
|
---|
234 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
235 |
|
---|
236 | PCUT_ASSERT_TRUE(tgc1.set_color_called);
|
---|
237 | PCUT_ASSERT_EQUALS(color, tgc1.set_color_color);
|
---|
238 | PCUT_ASSERT_TRUE(tgc2.set_color_called);
|
---|
239 | PCUT_ASSERT_EQUALS(color, tgc2.set_color_color);
|
---|
240 |
|
---|
241 | rc = ds_clonegc_delete(cgc);
|
---|
242 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
243 |
|
---|
244 | gfx_color_delete(color);
|
---|
245 | }
|
---|
246 |
|
---|
247 | /** Fill rectangle operation with two output GCs */
|
---|
248 | PCUT_TEST(fill_rect)
|
---|
249 | {
|
---|
250 | ds_clonegc_t *cgc;
|
---|
251 | gfx_context_t *gc;
|
---|
252 | test_gc_t tgc1;
|
---|
253 | gfx_context_t *gc1;
|
---|
254 | test_gc_t tgc2;
|
---|
255 | gfx_context_t *gc2;
|
---|
256 | gfx_rect_t rect;
|
---|
257 | errno_t rc;
|
---|
258 |
|
---|
259 | /* Create clone GC */
|
---|
260 | rc = ds_clonegc_create(NULL, &cgc);
|
---|
261 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
262 |
|
---|
263 | gc = ds_clonegc_get_ctx(cgc);
|
---|
264 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
265 |
|
---|
266 | /* Add two output GCs */
|
---|
267 |
|
---|
268 | rc = gfx_context_new(&ops, &tgc1, &gc1);
|
---|
269 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
270 |
|
---|
271 | rc = ds_clonegc_add_output(cgc, gc1);
|
---|
272 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
273 |
|
---|
274 | rc = gfx_context_new(&ops, &tgc2, &gc2);
|
---|
275 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
276 |
|
---|
277 | rc = ds_clonegc_add_output(cgc, gc2);
|
---|
278 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
279 |
|
---|
280 | rect.p0.x = 1;
|
---|
281 | rect.p0.y = 2;
|
---|
282 | rect.p1.x = 3;
|
---|
283 | rect.p1.y = 4;
|
---|
284 |
|
---|
285 | /* Fill rectangle returning error */
|
---|
286 |
|
---|
287 | tgc1.fill_rect_called = false;
|
---|
288 | tgc2.fill_rect_called = false;
|
---|
289 | tgc1.rc = EINVAL;
|
---|
290 | tgc2.rc = EINVAL;
|
---|
291 |
|
---|
292 | rc = gfx_fill_rect(gc, &rect);
|
---|
293 | PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
|
---|
294 |
|
---|
295 | PCUT_ASSERT_TRUE(tgc1.fill_rect_called);
|
---|
296 | PCUT_ASSERT_EQUALS(&rect, tgc1.fill_rect_rect);
|
---|
297 | PCUT_ASSERT_FALSE(tgc2.fill_rect_called);
|
---|
298 |
|
---|
299 | /* Fill rectangle returning success for all outputs */
|
---|
300 | tgc1.fill_rect_called = false;
|
---|
301 | tgc2.fill_rect_called = false;
|
---|
302 | tgc1.rc = EOK;
|
---|
303 | tgc2.rc = EOK;
|
---|
304 |
|
---|
305 | rc = gfx_fill_rect(gc, &rect);
|
---|
306 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
307 |
|
---|
308 | PCUT_ASSERT_TRUE(tgc1.fill_rect_called);
|
---|
309 | PCUT_ASSERT_EQUALS(&rect, tgc1.fill_rect_rect);
|
---|
310 | PCUT_ASSERT_TRUE(tgc2.fill_rect_called);
|
---|
311 | PCUT_ASSERT_EQUALS(&rect, tgc2.fill_rect_rect);
|
---|
312 |
|
---|
313 | rc = ds_clonegc_delete(cgc);
|
---|
314 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
315 | }
|
---|
316 |
|
---|
317 | /** Operations on regular bitmap with two output GCs, callee allocation */
|
---|
318 | PCUT_TEST(bitmap_twogc_callee_alloc)
|
---|
319 | {
|
---|
320 | ds_clonegc_t *cgc;
|
---|
321 | gfx_context_t *gc;
|
---|
322 | test_gc_t tgc1;
|
---|
323 | gfx_context_t *gc1;
|
---|
324 | test_gc_t tgc2;
|
---|
325 | gfx_context_t *gc2;
|
---|
326 | gfx_bitmap_params_t params;
|
---|
327 | gfx_bitmap_t *bitmap;
|
---|
328 | gfx_bitmap_alloc_t alloc;
|
---|
329 | gfx_rect_t rect;
|
---|
330 | gfx_coord2_t off;
|
---|
331 | errno_t rc;
|
---|
332 |
|
---|
333 | /* Create clone GC */
|
---|
334 | rc = ds_clonegc_create(NULL, &cgc);
|
---|
335 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
336 |
|
---|
337 | gc = ds_clonegc_get_ctx(cgc);
|
---|
338 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
339 |
|
---|
340 | /* Add two output GCs */
|
---|
341 |
|
---|
342 | rc = gfx_context_new(&ops, &tgc1, &gc1);
|
---|
343 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
344 |
|
---|
345 | rc = ds_clonegc_add_output(cgc, gc1);
|
---|
346 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
347 |
|
---|
348 | rc = gfx_context_new(&ops, &tgc2, &gc2);
|
---|
349 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
350 |
|
---|
351 | rc = ds_clonegc_add_output(cgc, gc2);
|
---|
352 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
353 |
|
---|
354 | /* Create bitmap with NULL allocation */
|
---|
355 | tgc1.bm_created = false;
|
---|
356 | tgc2.bm_created = false;
|
---|
357 | gfx_bitmap_params_init(¶ms);
|
---|
358 | params.rect.p0.x = 1;
|
---|
359 | params.rect.p0.y = 2;
|
---|
360 | params.rect.p1.x = 3;
|
---|
361 | params.rect.p1.y = 4;
|
---|
362 |
|
---|
363 | rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap);
|
---|
364 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
365 |
|
---|
366 | PCUT_ASSERT_TRUE(tgc1.bm_created);
|
---|
367 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, tgc1.bm_params.rect.p0.x);
|
---|
368 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, tgc1.bm_params.rect.p0.y);
|
---|
369 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, tgc1.bm_params.rect.p1.x);
|
---|
370 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, tgc1.bm_params.rect.p1.y);
|
---|
371 |
|
---|
372 | PCUT_ASSERT_TRUE(tgc2.bm_created);
|
---|
373 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, tgc2.bm_params.rect.p0.x);
|
---|
374 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, tgc2.bm_params.rect.p0.y);
|
---|
375 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, tgc2.bm_params.rect.p1.x);
|
---|
376 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, tgc2.bm_params.rect.p1.y);
|
---|
377 |
|
---|
378 | /* Get allocation */
|
---|
379 |
|
---|
380 | rc = gfx_bitmap_get_alloc(bitmap, &alloc);
|
---|
381 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
382 | PCUT_ASSERT_INT_EQUALS(alloc_pitch, alloc.pitch);
|
---|
383 | PCUT_ASSERT_EQUALS(tgc1.bm_pixels, alloc.pixels);
|
---|
384 | PCUT_ASSERT_EQUALS(tgc2.bm_pixels, alloc.pixels);
|
---|
385 |
|
---|
386 | /* Render bitmap */
|
---|
387 | tgc1.bm_rendered = false;
|
---|
388 | tgc1.bm_rendered = false;
|
---|
389 | rect.p0.x = 10;
|
---|
390 | rect.p0.y = 20;
|
---|
391 | rect.p1.x = 30;
|
---|
392 | rect.p1.y = 40;
|
---|
393 | off.x = 50;
|
---|
394 | off.y = 60;
|
---|
395 | rc = gfx_bitmap_render(bitmap, &rect, &off);
|
---|
396 | PCUT_ASSERT_TRUE(tgc1.bm_rendered);
|
---|
397 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc1.bm_srect.p0.x);
|
---|
398 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc1.bm_srect.p0.y);
|
---|
399 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc1.bm_srect.p1.x);
|
---|
400 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc1.bm_srect.p1.y);
|
---|
401 | PCUT_ASSERT_TRUE(tgc2.bm_rendered);
|
---|
402 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc2.bm_srect.p0.x);
|
---|
403 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc2.bm_srect.p0.y);
|
---|
404 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc2.bm_srect.p1.x);
|
---|
405 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc2.bm_srect.p1.y);
|
---|
406 |
|
---|
407 | rc = ds_clonegc_delete(cgc);
|
---|
408 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
409 | }
|
---|
410 |
|
---|
411 | /** Operations on regular bitmap with two output GCs, caller allocation */
|
---|
412 | PCUT_TEST(bitmap_twogc_caller_alloc)
|
---|
413 | {
|
---|
414 | ds_clonegc_t *cgc;
|
---|
415 | gfx_context_t *gc;
|
---|
416 | test_gc_t tgc1;
|
---|
417 | gfx_context_t *gc1;
|
---|
418 | test_gc_t tgc2;
|
---|
419 | gfx_context_t *gc2;
|
---|
420 | gfx_bitmap_params_t params;
|
---|
421 | gfx_bitmap_t *bitmap;
|
---|
422 | gfx_bitmap_alloc_t alloc;
|
---|
423 | gfx_bitmap_alloc_t galloc;
|
---|
424 | void *pixels;
|
---|
425 | gfx_rect_t rect;
|
---|
426 | gfx_coord2_t off;
|
---|
427 | errno_t rc;
|
---|
428 |
|
---|
429 | /* Create clone GC */
|
---|
430 | rc = ds_clonegc_create(NULL, &cgc);
|
---|
431 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
432 |
|
---|
433 | gc = ds_clonegc_get_ctx(cgc);
|
---|
434 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
435 |
|
---|
436 | /* Add two output GCs */
|
---|
437 | rc = gfx_context_new(&ops, &tgc1, &gc1);
|
---|
438 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
439 |
|
---|
440 | rc = ds_clonegc_add_output(cgc, gc1);
|
---|
441 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
442 |
|
---|
443 | rc = gfx_context_new(&ops, &tgc2, &gc2);
|
---|
444 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
445 |
|
---|
446 | rc = ds_clonegc_add_output(cgc, gc2);
|
---|
447 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
448 |
|
---|
449 | /* Create bitmap with caller allocation */
|
---|
450 | tgc1.bm_created = false;
|
---|
451 | tgc2.bm_created = false;
|
---|
452 | gfx_bitmap_params_init(¶ms);
|
---|
453 | params.rect.p0.x = 1;
|
---|
454 | params.rect.p0.y = 2;
|
---|
455 | params.rect.p1.x = 3;
|
---|
456 | params.rect.p1.y = 4;
|
---|
457 |
|
---|
458 | pixels = calloc(2 * 2, sizeof(uint32_t));
|
---|
459 | PCUT_ASSERT_NOT_NULL(pixels);
|
---|
460 |
|
---|
461 | alloc.pitch = 8;
|
---|
462 | alloc.off0 = 0;
|
---|
463 | alloc.pixels = pixels;
|
---|
464 |
|
---|
465 | rc = gfx_bitmap_create(gc, ¶ms, &alloc, &bitmap);
|
---|
466 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
467 |
|
---|
468 | PCUT_ASSERT_TRUE(tgc1.bm_created);
|
---|
469 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, tgc1.bm_params.rect.p0.x);
|
---|
470 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, tgc1.bm_params.rect.p0.y);
|
---|
471 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, tgc1.bm_params.rect.p1.x);
|
---|
472 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, tgc1.bm_params.rect.p1.y);
|
---|
473 |
|
---|
474 | PCUT_ASSERT_TRUE(tgc2.bm_created);
|
---|
475 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, tgc2.bm_params.rect.p0.x);
|
---|
476 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, tgc2.bm_params.rect.p0.y);
|
---|
477 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, tgc2.bm_params.rect.p1.x);
|
---|
478 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, tgc2.bm_params.rect.p1.y);
|
---|
479 |
|
---|
480 | /* Get allocation */
|
---|
481 | rc = gfx_bitmap_get_alloc(bitmap, &galloc);
|
---|
482 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
483 | PCUT_ASSERT_INT_EQUALS(alloc.pitch, galloc.pitch);
|
---|
484 | PCUT_ASSERT_INT_EQUALS(alloc.off0, galloc.off0);
|
---|
485 | PCUT_ASSERT_EQUALS(alloc.pixels, galloc.pixels);
|
---|
486 | PCUT_ASSERT_EQUALS(tgc1.bm_pixels, galloc.pixels);
|
---|
487 | PCUT_ASSERT_EQUALS(tgc2.bm_pixels, galloc.pixels);
|
---|
488 |
|
---|
489 | /* Render bitmap */
|
---|
490 | tgc1.bm_rendered = false;
|
---|
491 | tgc1.bm_rendered = false;
|
---|
492 | rect.p0.x = 10;
|
---|
493 | rect.p0.y = 20;
|
---|
494 | rect.p1.x = 30;
|
---|
495 | rect.p1.y = 40;
|
---|
496 | off.x = 50;
|
---|
497 | off.y = 60;
|
---|
498 | rc = gfx_bitmap_render(bitmap, &rect, &off);
|
---|
499 | PCUT_ASSERT_TRUE(tgc1.bm_rendered);
|
---|
500 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc1.bm_srect.p0.x);
|
---|
501 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc1.bm_srect.p0.y);
|
---|
502 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc1.bm_srect.p1.x);
|
---|
503 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc1.bm_srect.p1.y);
|
---|
504 | PCUT_ASSERT_TRUE(tgc2.bm_rendered);
|
---|
505 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc2.bm_srect.p0.x);
|
---|
506 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc2.bm_srect.p0.y);
|
---|
507 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc2.bm_srect.p1.x);
|
---|
508 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc2.bm_srect.p1.y);
|
---|
509 |
|
---|
510 | free(pixels);
|
---|
511 |
|
---|
512 | rc = ds_clonegc_delete(cgc);
|
---|
513 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
514 | }
|
---|
515 |
|
---|
516 | /** Create bitmap, then add second GC, callee allocation */
|
---|
517 | PCUT_TEST(bitmap_addgc_callee_alloc)
|
---|
518 | {
|
---|
519 | ds_clonegc_t *cgc;
|
---|
520 | gfx_context_t *gc;
|
---|
521 | test_gc_t tgc1;
|
---|
522 | gfx_context_t *gc1;
|
---|
523 | test_gc_t tgc2;
|
---|
524 | gfx_context_t *gc2;
|
---|
525 | gfx_bitmap_params_t params;
|
---|
526 | gfx_bitmap_t *bitmap;
|
---|
527 | gfx_bitmap_alloc_t alloc;
|
---|
528 | gfx_rect_t rect;
|
---|
529 | gfx_coord2_t off;
|
---|
530 | errno_t rc;
|
---|
531 |
|
---|
532 | /* Create clone GC */
|
---|
533 | rc = ds_clonegc_create(NULL, &cgc);
|
---|
534 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
535 |
|
---|
536 | gc = ds_clonegc_get_ctx(cgc);
|
---|
537 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
538 |
|
---|
539 | /* Add one output GC */
|
---|
540 | rc = gfx_context_new(&ops, &tgc1, &gc1);
|
---|
541 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
542 |
|
---|
543 | rc = ds_clonegc_add_output(cgc, gc1);
|
---|
544 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
545 |
|
---|
546 | /* Create bitmap with NULL allocation */
|
---|
547 | tgc1.bm_created = false;
|
---|
548 | tgc2.bm_created = false;
|
---|
549 | gfx_bitmap_params_init(¶ms);
|
---|
550 | params.rect.p0.x = 1;
|
---|
551 | params.rect.p0.y = 2;
|
---|
552 | params.rect.p1.x = 3;
|
---|
553 | params.rect.p1.y = 4;
|
---|
554 |
|
---|
555 | rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap);
|
---|
556 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
557 |
|
---|
558 | PCUT_ASSERT_TRUE(tgc1.bm_created);
|
---|
559 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, tgc1.bm_params.rect.p0.x);
|
---|
560 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, tgc1.bm_params.rect.p0.y);
|
---|
561 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, tgc1.bm_params.rect.p1.x);
|
---|
562 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, tgc1.bm_params.rect.p1.y);
|
---|
563 |
|
---|
564 | PCUT_ASSERT_FALSE(tgc2.bm_created);
|
---|
565 |
|
---|
566 | /* Get allocation */
|
---|
567 | rc = gfx_bitmap_get_alloc(bitmap, &alloc);
|
---|
568 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
569 | PCUT_ASSERT_INT_EQUALS(alloc_pitch, alloc.pitch);
|
---|
570 | PCUT_ASSERT_EQUALS(tgc1.bm_pixels, alloc.pixels);
|
---|
571 |
|
---|
572 | /* Add second output GC */
|
---|
573 | rc = gfx_context_new(&ops, &tgc2, &gc2);
|
---|
574 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
575 |
|
---|
576 | rc = ds_clonegc_add_output(cgc, gc2);
|
---|
577 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
578 |
|
---|
579 | /* Render bitmap */
|
---|
580 | tgc1.bm_rendered = false;
|
---|
581 | tgc1.bm_rendered = false;
|
---|
582 | rect.p0.x = 10;
|
---|
583 | rect.p0.y = 20;
|
---|
584 | rect.p1.x = 30;
|
---|
585 | rect.p1.y = 40;
|
---|
586 | off.x = 50;
|
---|
587 | off.y = 60;
|
---|
588 | rc = gfx_bitmap_render(bitmap, &rect, &off);
|
---|
589 | PCUT_ASSERT_TRUE(tgc1.bm_rendered);
|
---|
590 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc1.bm_srect.p0.x);
|
---|
591 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc1.bm_srect.p0.y);
|
---|
592 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc1.bm_srect.p1.x);
|
---|
593 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc1.bm_srect.p1.y);
|
---|
594 | PCUT_ASSERT_TRUE(tgc2.bm_rendered);
|
---|
595 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc2.bm_srect.p0.x);
|
---|
596 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc2.bm_srect.p0.y);
|
---|
597 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc2.bm_srect.p1.x);
|
---|
598 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc2.bm_srect.p1.y);
|
---|
599 |
|
---|
600 | rc = ds_clonegc_delete(cgc);
|
---|
601 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
602 | }
|
---|
603 |
|
---|
604 | /** Create bitmap, then add second GC, caller allocation */
|
---|
605 | PCUT_TEST(bitmap_addgc_caller_alloc)
|
---|
606 | {
|
---|
607 | ds_clonegc_t *cgc;
|
---|
608 | gfx_context_t *gc;
|
---|
609 | test_gc_t tgc1;
|
---|
610 | gfx_context_t *gc1;
|
---|
611 | test_gc_t tgc2;
|
---|
612 | gfx_context_t *gc2;
|
---|
613 | gfx_bitmap_params_t params;
|
---|
614 | gfx_bitmap_t *bitmap;
|
---|
615 | gfx_bitmap_alloc_t alloc;
|
---|
616 | gfx_bitmap_alloc_t galloc;
|
---|
617 | void *pixels;
|
---|
618 | gfx_rect_t rect;
|
---|
619 | gfx_coord2_t off;
|
---|
620 | errno_t rc;
|
---|
621 |
|
---|
622 | /* Create clone GC */
|
---|
623 | rc = ds_clonegc_create(NULL, &cgc);
|
---|
624 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
625 |
|
---|
626 | gc = ds_clonegc_get_ctx(cgc);
|
---|
627 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
628 |
|
---|
629 | /* Add one output GC */
|
---|
630 | rc = gfx_context_new(&ops, &tgc1, &gc1);
|
---|
631 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
632 |
|
---|
633 | rc = ds_clonegc_add_output(cgc, gc1);
|
---|
634 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
635 |
|
---|
636 | /* Create bitmap with caller allocation */
|
---|
637 | tgc1.bm_created = false;
|
---|
638 | tgc2.bm_created = false;
|
---|
639 | gfx_bitmap_params_init(¶ms);
|
---|
640 | params.rect.p0.x = 1;
|
---|
641 | params.rect.p0.y = 2;
|
---|
642 | params.rect.p1.x = 3;
|
---|
643 | params.rect.p1.y = 4;
|
---|
644 |
|
---|
645 | pixels = calloc(2 * 2, sizeof(uint32_t));
|
---|
646 | PCUT_ASSERT_NOT_NULL(pixels);
|
---|
647 |
|
---|
648 | alloc.pitch = 8;
|
---|
649 | alloc.off0 = 0;
|
---|
650 | alloc.pixels = pixels;
|
---|
651 |
|
---|
652 | rc = gfx_bitmap_create(gc, ¶ms, &alloc, &bitmap);
|
---|
653 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
654 |
|
---|
655 | PCUT_ASSERT_TRUE(tgc1.bm_created);
|
---|
656 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, tgc1.bm_params.rect.p0.x);
|
---|
657 | PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, tgc1.bm_params.rect.p0.y);
|
---|
658 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, tgc1.bm_params.rect.p1.x);
|
---|
659 | PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, tgc1.bm_params.rect.p1.y);
|
---|
660 |
|
---|
661 | PCUT_ASSERT_FALSE(tgc2.bm_created);
|
---|
662 |
|
---|
663 | /* Get allocation */
|
---|
664 | rc = gfx_bitmap_get_alloc(bitmap, &galloc);
|
---|
665 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
666 | PCUT_ASSERT_INT_EQUALS(alloc.pitch, galloc.pitch);
|
---|
667 | PCUT_ASSERT_INT_EQUALS(alloc.off0, galloc.off0);
|
---|
668 | PCUT_ASSERT_EQUALS(alloc.pixels, galloc.pixels);
|
---|
669 | PCUT_ASSERT_EQUALS(tgc1.bm_pixels, galloc.pixels);
|
---|
670 |
|
---|
671 | /* Add second output GC */
|
---|
672 | rc = gfx_context_new(&ops, &tgc2, &gc2);
|
---|
673 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
674 |
|
---|
675 | rc = ds_clonegc_add_output(cgc, gc2);
|
---|
676 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
677 |
|
---|
678 | /* Render bitmap */
|
---|
679 | tgc1.bm_rendered = false;
|
---|
680 | tgc1.bm_rendered = false;
|
---|
681 | rect.p0.x = 10;
|
---|
682 | rect.p0.y = 20;
|
---|
683 | rect.p1.x = 30;
|
---|
684 | rect.p1.y = 40;
|
---|
685 | off.x = 50;
|
---|
686 | off.y = 60;
|
---|
687 | rc = gfx_bitmap_render(bitmap, &rect, &off);
|
---|
688 | PCUT_ASSERT_TRUE(tgc1.bm_rendered);
|
---|
689 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc1.bm_srect.p0.x);
|
---|
690 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc1.bm_srect.p0.y);
|
---|
691 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc1.bm_srect.p1.x);
|
---|
692 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc1.bm_srect.p1.y);
|
---|
693 | PCUT_ASSERT_TRUE(tgc2.bm_rendered);
|
---|
694 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc2.bm_srect.p0.x);
|
---|
695 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc2.bm_srect.p0.y);
|
---|
696 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc2.bm_srect.p1.x);
|
---|
697 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc2.bm_srect.p1.y);
|
---|
698 |
|
---|
699 | free(pixels);
|
---|
700 |
|
---|
701 | rc = ds_clonegc_delete(cgc);
|
---|
702 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
703 | }
|
---|
704 |
|
---|
705 | static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
|
---|
706 | {
|
---|
707 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
708 |
|
---|
709 | tgc->set_clip_rect_called = true;
|
---|
710 | tgc->set_clip_rect_rect = rect;
|
---|
711 |
|
---|
712 | return tgc->rc;
|
---|
713 | }
|
---|
714 |
|
---|
715 | static errno_t testgc_set_color(void *arg, gfx_color_t *color)
|
---|
716 | {
|
---|
717 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
718 |
|
---|
719 | tgc->set_color_called = true;
|
---|
720 | tgc->set_color_color = color;
|
---|
721 |
|
---|
722 | return tgc->rc;
|
---|
723 | }
|
---|
724 |
|
---|
725 | static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
|
---|
726 | {
|
---|
727 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
728 |
|
---|
729 | tgc->fill_rect_called = true;
|
---|
730 | tgc->fill_rect_rect = rect;
|
---|
731 |
|
---|
732 | return tgc->rc;
|
---|
733 | }
|
---|
734 |
|
---|
735 | static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
|
---|
736 | gfx_bitmap_alloc_t *alloc, void **rbm)
|
---|
737 | {
|
---|
738 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
739 | testgc_bitmap_t *tbm;
|
---|
740 |
|
---|
741 | tbm = calloc(1, sizeof(testgc_bitmap_t));
|
---|
742 | if (tbm == NULL)
|
---|
743 | return ENOMEM;
|
---|
744 |
|
---|
745 | if (alloc == NULL) {
|
---|
746 | tbm->alloc.pitch = alloc_pitch;
|
---|
747 | tbm->alloc.off0 = alloc_off0;
|
---|
748 | tbm->alloc.pixels = calloc(1, 420);
|
---|
749 | tbm->myalloc = true;
|
---|
750 | if (tbm->alloc.pixels == NULL) {
|
---|
751 | free(tbm);
|
---|
752 | return ENOMEM;
|
---|
753 | }
|
---|
754 | } else {
|
---|
755 | tbm->alloc = *alloc;
|
---|
756 | }
|
---|
757 |
|
---|
758 | tbm->tgc = tgc;
|
---|
759 | tgc->bm_created = true;
|
---|
760 | tgc->bm_params = *params;
|
---|
761 | tgc->bm_pixels = tbm->alloc.pixels;
|
---|
762 | *rbm = (void *)tbm;
|
---|
763 | return EOK;
|
---|
764 | }
|
---|
765 |
|
---|
766 | static errno_t testgc_bitmap_destroy(void *bm)
|
---|
767 | {
|
---|
768 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
769 | if (tbm->myalloc)
|
---|
770 | free(tbm->alloc.pixels);
|
---|
771 | tbm->tgc->bm_destroyed = true;
|
---|
772 | free(tbm);
|
---|
773 | return EOK;
|
---|
774 | }
|
---|
775 |
|
---|
776 | static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
|
---|
777 | gfx_coord2_t *offs)
|
---|
778 | {
|
---|
779 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
780 | tbm->tgc->bm_rendered = true;
|
---|
781 | tbm->tgc->bm_srect = *srect;
|
---|
782 | tbm->tgc->bm_offs = *offs;
|
---|
783 | return EOK;
|
---|
784 | }
|
---|
785 |
|
---|
786 | static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
|
---|
787 | {
|
---|
788 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
789 | *alloc = tbm->alloc;
|
---|
790 | tbm->tgc->bm_got_alloc = true;
|
---|
791 | return EOK;
|
---|
792 | }
|
---|
793 |
|
---|
794 | PCUT_EXPORT(clonegc);
|
---|