Changes in uspace/lib/ui/test/label.c [1fa6292:7470d97] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/label.c
r1fa6292 r7470d97 36 36 #include <ui/resource.h> 37 37 #include "../private/label.h" 38 #include "../private/testgc.h"39 38 40 39 PCUT_INIT; 41 40 42 41 PCUT_TEST_SUITE(label); 42 43 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *); 44 static errno_t testgc_set_color(void *, gfx_color_t *); 45 static errno_t testgc_fill_rect(void *, gfx_rect_t *); 46 static errno_t testgc_update(void *); 47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *, 48 gfx_bitmap_alloc_t *, void **); 49 static errno_t testgc_bitmap_destroy(void *); 50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 52 53 static gfx_context_ops_t ops = { 54 .set_clip_rect = testgc_set_clip_rect, 55 .set_color = testgc_set_color, 56 .fill_rect = testgc_fill_rect, 57 .update = testgc_update, 58 .bitmap_create = testgc_bitmap_create, 59 .bitmap_destroy = testgc_bitmap_destroy, 60 .bitmap_render = testgc_bitmap_render, 61 .bitmap_get_alloc = testgc_bitmap_get_alloc 62 }; 63 64 typedef struct { 65 bool bm_created; 66 bool bm_destroyed; 67 gfx_bitmap_params_t bm_params; 68 void *bm_pixels; 69 gfx_rect_t bm_srect; 70 gfx_coord2_t bm_offs; 71 bool bm_rendered; 72 bool bm_got_alloc; 73 } test_gc_t; 74 75 typedef struct { 76 test_gc_t *tgc; 77 gfx_bitmap_alloc_t alloc; 78 bool myalloc; 79 } testgc_bitmap_t; 43 80 44 81 typedef struct { … … 176 213 } 177 214 215 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect) 216 { 217 (void) arg; 218 (void) rect; 219 return EOK; 220 } 221 222 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 223 { 224 (void) arg; 225 (void) color; 226 return EOK; 227 } 228 229 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect) 230 { 231 (void) arg; 232 (void) rect; 233 return EOK; 234 } 235 236 static errno_t testgc_update(void *arg) 237 { 238 (void) arg; 239 return EOK; 240 } 241 242 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params, 243 gfx_bitmap_alloc_t *alloc, void **rbm) 244 { 245 test_gc_t *tgc = (test_gc_t *) arg; 246 testgc_bitmap_t *tbm; 247 248 tbm = calloc(1, sizeof(testgc_bitmap_t)); 249 if (tbm == NULL) 250 return ENOMEM; 251 252 if (alloc == NULL) { 253 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) * 254 sizeof(uint32_t); 255 tbm->alloc.off0 = 0; 256 tbm->alloc.pixels = calloc(sizeof(uint32_t), 257 (params->rect.p1.x - params->rect.p0.x) * 258 (params->rect.p1.y - params->rect.p0.y)); 259 tbm->myalloc = true; 260 if (tbm->alloc.pixels == NULL) { 261 free(tbm); 262 return ENOMEM; 263 } 264 } else { 265 tbm->alloc = *alloc; 266 } 267 268 tbm->tgc = tgc; 269 tgc->bm_created = true; 270 tgc->bm_params = *params; 271 tgc->bm_pixels = tbm->alloc.pixels; 272 *rbm = (void *)tbm; 273 return EOK; 274 } 275 276 static errno_t testgc_bitmap_destroy(void *bm) 277 { 278 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 279 if (tbm->myalloc) 280 free(tbm->alloc.pixels); 281 tbm->tgc->bm_destroyed = true; 282 free(tbm); 283 return EOK; 284 } 285 286 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect, 287 gfx_coord2_t *offs) 288 { 289 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 290 tbm->tgc->bm_rendered = true; 291 tbm->tgc->bm_srect = *srect; 292 tbm->tgc->bm_offs = *offs; 293 return EOK; 294 } 295 296 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc) 297 { 298 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 299 *alloc = tbm->alloc; 300 tbm->tgc->bm_got_alloc = true; 301 return EOK; 302 } 303 178 304 PCUT_EXPORT(label);
Note:
See TracChangeset
for help on using the changeset viewer.