Changes in uspace/lib/gfxfont/test/tpf.c [1fa6292:120031a5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/tpf.c
r1fa6292 r120031a5 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2020 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #include "../private/font.h" 37 37 #include "../private/typeface.h" 38 #include "../private/testgc.h"39 38 40 39 PCUT_INIT; … … 42 41 PCUT_TEST_SUITE(tpf); 43 42 44 static const gfx_font_flags_t test_font_flags = gff_bold_italic; 43 static errno_t testgc_set_color(void *, gfx_color_t *); 44 static errno_t testgc_fill_rect(void *, gfx_rect_t *); 45 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *, 46 gfx_bitmap_alloc_t *, void **); 47 static errno_t testgc_bitmap_destroy(void *); 48 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 49 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 50 51 static gfx_context_ops_t test_ops = { 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 gfx_bitmap_params_t bm_params; 62 void *bm_pixels; 63 gfx_rect_t bm_srect; 64 gfx_coord2_t bm_offs; 65 } test_gc_t; 66 67 typedef struct { 68 test_gc_t *tgc; 69 gfx_bitmap_alloc_t alloc; 70 bool myalloc; 71 } testgc_bitmap_t; 45 72 46 73 enum { 47 74 test_font_size = 9, 75 test_font_flags = gff_bold_italic, 48 76 test_font_ascent = 4, 49 77 test_font_descent = 3, … … 180 208 } 181 209 210 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 211 { 212 return EOK; 213 } 214 215 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect) 216 { 217 return EOK; 218 } 219 220 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params, 221 gfx_bitmap_alloc_t *alloc, void **rbm) 222 { 223 test_gc_t *tgc = (test_gc_t *) arg; 224 testgc_bitmap_t *tbm; 225 226 tbm = calloc(1, sizeof(testgc_bitmap_t)); 227 if (tbm == NULL) 228 return ENOMEM; 229 230 if (alloc == NULL) { 231 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) * 232 sizeof(uint32_t); 233 tbm->alloc.off0 = 0; 234 tbm->alloc.pixels = calloc(sizeof(uint32_t), 235 tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y)); 236 tbm->myalloc = true; 237 if (tbm->alloc.pixels == NULL) { 238 free(tbm); 239 return ENOMEM; 240 } 241 } else { 242 tbm->alloc = *alloc; 243 } 244 245 tbm->tgc = tgc; 246 tgc->bm_params = *params; 247 tgc->bm_pixels = tbm->alloc.pixels; 248 *rbm = (void *)tbm; 249 return EOK; 250 } 251 252 static errno_t testgc_bitmap_destroy(void *bm) 253 { 254 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 255 if (tbm->myalloc) 256 free(tbm->alloc.pixels); 257 free(tbm); 258 return EOK; 259 } 260 261 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect, 262 gfx_coord2_t *offs) 263 { 264 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 265 tbm->tgc->bm_srect = *srect; 266 tbm->tgc->bm_offs = *offs; 267 return EOK; 268 } 269 270 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc) 271 { 272 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 273 *alloc = tbm->alloc; 274 return EOK; 275 } 276 182 277 PCUT_EXPORT(tpf);
Note:
See TracChangeset
for help on using the changeset viewer.