Changeset 1fa6292 in mainline for uspace/lib/gfxfont/test/font.c
- Timestamp:
- 2025-01-28T14:48:04Z (3 months ago)
- Branches:
- master
- Children:
- 56210a7
- Parents:
- 97116a2
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2025-01-28 14:46:24)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2025-01-28 14:48:04)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/font.c
r97116a2 r1fa6292 34 34 #include "../private/font.h" 35 35 #include "../private/typeface.h" 36 #include "../private/testgc.h" 36 37 37 38 PCUT_INIT; 38 39 39 40 PCUT_TEST_SUITE(font); 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 test_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_alloc58 };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;72 41 73 42 /** Test creating and destroying font */ … … 509 478 height = 10; 510 479 511 pixels = calloc( sizeof(uint32_t), width * height);480 pixels = calloc(width * height, sizeof(uint32_t)); 512 481 PCUT_ASSERT_NOT_NULL(pixels); 513 482 … … 556 525 } 557 526 558 pixels = calloc( sizeof(uint32_t), width * height);527 pixels = calloc(width * height, sizeof(uint32_t)); 559 528 PCUT_ASSERT_NOT_NULL(pixels); 560 529 … … 572 541 } 573 542 574 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)575 {576 return EOK;577 }578 579 static errno_t testgc_set_color(void *arg, gfx_color_t *color)580 {581 return EOK;582 }583 584 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)585 {586 return EOK;587 }588 589 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,590 gfx_bitmap_alloc_t *alloc, void **rbm)591 {592 test_gc_t *tgc = (test_gc_t *) arg;593 testgc_bitmap_t *tbm;594 595 tbm = calloc(1, sizeof(testgc_bitmap_t));596 if (tbm == NULL)597 return ENOMEM;598 599 if (alloc == NULL) {600 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *601 sizeof(uint32_t);602 tbm->alloc.off0 = 0;603 tbm->alloc.pixels = calloc(sizeof(uint32_t),604 tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));605 tbm->myalloc = true;606 if (tbm->alloc.pixels == NULL) {607 free(tbm);608 return ENOMEM;609 }610 } else {611 tbm->alloc = *alloc;612 }613 614 tbm->tgc = tgc;615 tgc->bm_params = *params;616 tgc->bm_pixels = tbm->alloc.pixels;617 *rbm = (void *)tbm;618 return EOK;619 }620 621 static errno_t testgc_bitmap_destroy(void *bm)622 {623 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;624 if (tbm->myalloc)625 free(tbm->alloc.pixels);626 free(tbm);627 return EOK;628 }629 630 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,631 gfx_coord2_t *offs)632 {633 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;634 tbm->tgc->bm_srect = *srect;635 tbm->tgc->bm_offs = *offs;636 return EOK;637 }638 639 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)640 {641 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;642 *alloc = tbm->alloc;643 return EOK;644 }645 646 543 PCUT_EXPORT(font);
Note:
See TracChangeset
for help on using the changeset viewer.