Changes in uspace/lib/gfxfont/test/font.c [1fa6292:7470d97] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/font.c
r1fa6292 r7470d97 34 34 #include "../private/font.h" 35 35 #include "../private/typeface.h" 36 #include "../private/testgc.h"37 36 38 37 PCUT_INIT; 39 38 40 39 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_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; 41 72 42 73 /** Test creating and destroying font */ … … 478 509 height = 10; 479 510 480 pixels = calloc( width * height, sizeof(uint32_t));511 pixels = calloc(sizeof(uint32_t), width * height); 481 512 PCUT_ASSERT_NOT_NULL(pixels); 482 513 … … 525 556 } 526 557 527 pixels = calloc( width * height, sizeof(uint32_t));558 pixels = calloc(sizeof(uint32_t), width * height); 528 559 PCUT_ASSERT_NOT_NULL(pixels); 529 560 … … 541 572 } 542 573 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 543 646 PCUT_EXPORT(font);
Note:
See TracChangeset
for help on using the changeset viewer.