Changes in uspace/lib/gfxfont/test/text.c [1fa6292:4583015] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/text.c
r1fa6292 r4583015 36 36 #include "../private/font.h" 37 37 #include "../private/typeface.h" 38 #include "../private/testgc.h"39 38 40 39 PCUT_INIT; 41 40 42 41 PCUT_TEST_SUITE(text); 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_bitmap_create(void *, gfx_bitmap_params_t *, 47 gfx_bitmap_alloc_t *, void **); 48 static errno_t testgc_bitmap_destroy(void *); 49 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 50 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 51 52 static gfx_context_ops_t test_ops = { 53 .set_clip_rect = testgc_set_clip_rect, 54 .set_color = testgc_set_color, 55 .fill_rect = testgc_fill_rect, 56 .bitmap_create = testgc_bitmap_create, 57 .bitmap_destroy = testgc_bitmap_destroy, 58 .bitmap_render = testgc_bitmap_render, 59 .bitmap_get_alloc = testgc_bitmap_get_alloc 60 }; 61 62 typedef struct { 63 gfx_bitmap_params_t bm_params; 64 void *bm_pixels; 65 gfx_rect_t bm_srect; 66 gfx_coord2_t bm_offs; 67 } test_gc_t; 68 69 typedef struct { 70 test_gc_t *tgc; 71 gfx_bitmap_alloc_t alloc; 72 bool myalloc; 73 } testgc_bitmap_t; 43 74 44 75 /** Test text width computation with a dummy font */ … … 423 454 } 424 455 456 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect) 457 { 458 return EOK; 459 } 460 461 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 462 { 463 return EOK; 464 } 465 466 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect) 467 { 468 return EOK; 469 } 470 471 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params, 472 gfx_bitmap_alloc_t *alloc, void **rbm) 473 { 474 test_gc_t *tgc = (test_gc_t *) arg; 475 testgc_bitmap_t *tbm; 476 477 tbm = calloc(1, sizeof(testgc_bitmap_t)); 478 if (tbm == NULL) 479 return ENOMEM; 480 481 if (alloc == NULL) { 482 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) * 483 sizeof(uint32_t); 484 tbm->alloc.off0 = 0; 485 tbm->alloc.pixels = calloc(sizeof(uint32_t), 486 tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y)); 487 tbm->myalloc = true; 488 if (tbm->alloc.pixels == NULL) { 489 free(tbm); 490 return ENOMEM; 491 } 492 } else { 493 tbm->alloc = *alloc; 494 } 495 496 tbm->tgc = tgc; 497 tgc->bm_params = *params; 498 tgc->bm_pixels = tbm->alloc.pixels; 499 *rbm = (void *)tbm; 500 return EOK; 501 } 502 503 static errno_t testgc_bitmap_destroy(void *bm) 504 { 505 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 506 if (tbm->myalloc) 507 free(tbm->alloc.pixels); 508 free(tbm); 509 return EOK; 510 } 511 512 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect, 513 gfx_coord2_t *offs) 514 { 515 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 516 tbm->tgc->bm_srect = *srect; 517 tbm->tgc->bm_offs = *offs; 518 return EOK; 519 } 520 521 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc) 522 { 523 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 524 *alloc = tbm->alloc; 525 return EOK; 526 } 527 425 528 PCUT_EXPORT(text);
Note:
See TracChangeset
for help on using the changeset viewer.