Changeset 1fa6292 in mainline for uspace/lib/gfxfont


Ignore:
Timestamp:
2025-01-28T14:48:04Z (6 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
56210a7a
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)
Message:

Remove a ton of duplicated code in libui/libgfxfont tests

Location:
uspace/lib/gfxfont
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfxfont/src/glyph_bmp.c

    r97116a2 r1fa6292  
    293293
    294294        /* Allocate new pixel array */
    295         npixels = calloc(sizeof(int), 1);
     295        npixels = calloc(1, sizeof(int));
    296296        if (npixels == NULL)
    297297                return ENOMEM;
     
    332332
    333333        /* Allocate new pixel array */
    334         npixels = calloc(sizeof(int), (nrect.p1.x - nrect.p0.x) *
    335             (nrect.p1.y - nrect.p0.y));
     334        npixels = calloc((nrect.p1.x - nrect.p0.x) *
     335            (nrect.p1.y - nrect.p0.y), sizeof(int));
    336336        if (npixels == NULL)
    337337                return ENOMEM;
  • uspace/lib/gfxfont/test/font.c

    r97116a2 r1fa6292  
    3434#include "../private/font.h"
    3535#include "../private/typeface.h"
     36#include "../private/testgc.h"
    3637
    3738PCUT_INIT;
    3839
    3940PCUT_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;
    7241
    7342/** Test creating and destroying font */
     
    509478        height = 10;
    510479
    511         pixels = calloc(sizeof(uint32_t), width * height);
     480        pixels = calloc(width * height, sizeof(uint32_t));
    512481        PCUT_ASSERT_NOT_NULL(pixels);
    513482
     
    556525        }
    557526
    558         pixels = calloc(sizeof(uint32_t), width * height);
     527        pixels = calloc(width * height, sizeof(uint32_t));
    559528        PCUT_ASSERT_NOT_NULL(pixels);
    560529
     
    572541}
    573542
    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 
    646543PCUT_EXPORT(font);
  • uspace/lib/gfxfont/test/glyph.c

    r97116a2 r1fa6292  
    3838#include <str.h>
    3939#include "../private/glyph.h"
     40#include "../private/testgc.h"
    4041
    4142PCUT_INIT;
    4243
    4344PCUT_TEST_SUITE(glyph);
    44 
    45 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    46 static errno_t testgc_set_color(void *, gfx_color_t *);
    47 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    48 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    49     gfx_bitmap_alloc_t *, void **);
    50 static errno_t testgc_bitmap_destroy(void *);
    51 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    52 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    53 
    54 static gfx_context_ops_t test_ops = {
    55         .set_clip_rect = testgc_set_clip_rect,
    56         .set_color = testgc_set_color,
    57         .fill_rect = testgc_fill_rect,
    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         gfx_bitmap_params_t bm_params;
    66         void *bm_pixels;
    67         gfx_rect_t bm_srect;
    68         gfx_coord2_t bm_offs;
    69 } test_gc_t;
    70 
    71 typedef struct {
    72         test_gc_t *tgc;
    73         gfx_bitmap_alloc_t alloc;
    74         bool myalloc;
    75 } testgc_bitmap_t;
    7645
    7746/** Test creating and destroying glyph */
     
    571540}
    572541
    573 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    574 {
    575         return EOK;
    576 }
    577 
    578 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    579 {
    580         return EOK;
    581 }
    582 
    583 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    584 {
    585         return EOK;
    586 }
    587 
    588 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    589     gfx_bitmap_alloc_t *alloc, void **rbm)
    590 {
    591         test_gc_t *tgc = (test_gc_t *) arg;
    592         testgc_bitmap_t *tbm;
    593 
    594         tbm = calloc(1, sizeof(testgc_bitmap_t));
    595         if (tbm == NULL)
    596                 return ENOMEM;
    597 
    598         if (alloc == NULL) {
    599                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    600                     sizeof(uint32_t);
    601                 tbm->alloc.off0 = 0;
    602                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    603                     tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
    604                 tbm->myalloc = true;
    605                 if (tbm->alloc.pixels == NULL) {
    606                         free(tbm);
    607                         return ENOMEM;
    608                 }
    609         } else {
    610                 tbm->alloc = *alloc;
    611         }
    612 
    613         tbm->tgc = tgc;
    614         tgc->bm_params = *params;
    615         tgc->bm_pixels = tbm->alloc.pixels;
    616         *rbm = (void *)tbm;
    617         return EOK;
    618 }
    619 
    620 static errno_t testgc_bitmap_destroy(void *bm)
    621 {
    622         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    623         if (tbm->myalloc)
    624                 free(tbm->alloc.pixels);
    625         free(tbm);
    626         return EOK;
    627 }
    628 
    629 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    630     gfx_coord2_t *offs)
    631 {
    632         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    633         tbm->tgc->bm_srect = *srect;
    634         tbm->tgc->bm_offs = *offs;
    635         return EOK;
    636 }
    637 
    638 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    639 {
    640         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    641         *alloc = tbm->alloc;
    642         return EOK;
    643 }
    644 
    645542PCUT_EXPORT(glyph);
  • uspace/lib/gfxfont/test/glyph_bmp.c

    r97116a2 r1fa6292  
    3434#include <pcut/pcut.h>
    3535#include "../private/glyph_bmp.h"
     36#include "../private/testgc.h"
    3637
    3738PCUT_INIT;
    3839
    3940PCUT_TEST_SUITE(glyph_bmp);
    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;
    7241
    7342/** Test opening and closing glyph bitmap */
     
    585554}
    586555
    587 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    588 {
    589         return EOK;
    590 }
    591 
    592 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    593 {
    594         return EOK;
    595 }
    596 
    597 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    598 {
    599         return EOK;
    600 }
    601 
    602 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    603     gfx_bitmap_alloc_t *alloc, void **rbm)
    604 {
    605         test_gc_t *tgc = (test_gc_t *) arg;
    606         testgc_bitmap_t *tbm;
    607 
    608         tbm = calloc(1, sizeof(testgc_bitmap_t));
    609         if (tbm == NULL)
    610                 return ENOMEM;
    611 
    612         if (alloc == NULL) {
    613                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    614                     sizeof(uint32_t);
    615                 tbm->alloc.off0 = 0;
    616                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    617                     tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
    618                 tbm->myalloc = true;
    619                 if (tbm->alloc.pixels == NULL) {
    620                         free(tbm);
    621                         return ENOMEM;
    622                 }
    623         } else {
    624                 tbm->alloc = *alloc;
    625         }
    626 
    627         tbm->tgc = tgc;
    628         tgc->bm_params = *params;
    629         tgc->bm_pixels = tbm->alloc.pixels;
    630         *rbm = (void *)tbm;
    631         return EOK;
    632 }
    633 
    634 static errno_t testgc_bitmap_destroy(void *bm)
    635 {
    636         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    637         if (tbm->myalloc)
    638                 free(tbm->alloc.pixels);
    639         free(tbm);
    640         return EOK;
    641 }
    642 
    643 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    644     gfx_coord2_t *offs)
    645 {
    646         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    647         tbm->tgc->bm_srect = *srect;
    648         tbm->tgc->bm_offs = *offs;
    649         return EOK;
    650 }
    651 
    652 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    653 {
    654         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    655         *alloc = tbm->alloc;
    656         return EOK;
    657 }
    658 
    659556PCUT_EXPORT(glyph_bmp);
  • uspace/lib/gfxfont/test/text.c

    r97116a2 r1fa6292  
    3636#include "../private/font.h"
    3737#include "../private/typeface.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_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;
    7443
    7544/** Test text width computation with a dummy font */
     
    454423}
    455424
    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 
    528425PCUT_EXPORT(text);
  • uspace/lib/gfxfont/test/tpf.c

    r97116a2 r1fa6292  
    3636#include "../private/font.h"
    3737#include "../private/typeface.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(tpf);
    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;
    7443
    7544static const gfx_font_flags_t test_font_flags = gff_bold_italic;
     
    211180}
    212181
    213 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    214 {
    215         return EOK;
    216 }
    217 
    218 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    219 {
    220         return EOK;
    221 }
    222 
    223 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    224 {
    225         return EOK;
    226 }
    227 
    228 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    229     gfx_bitmap_alloc_t *alloc, void **rbm)
    230 {
    231         test_gc_t *tgc = (test_gc_t *) arg;
    232         testgc_bitmap_t *tbm;
    233 
    234         tbm = calloc(1, sizeof(testgc_bitmap_t));
    235         if (tbm == NULL)
    236                 return ENOMEM;
    237 
    238         if (alloc == NULL) {
    239                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    240                     sizeof(uint32_t);
    241                 tbm->alloc.off0 = 0;
    242                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    243                     tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
    244                 tbm->myalloc = true;
    245                 if (tbm->alloc.pixels == NULL) {
    246                         free(tbm);
    247                         return ENOMEM;
    248                 }
    249         } else {
    250                 tbm->alloc = *alloc;
    251         }
    252 
    253         tbm->tgc = tgc;
    254         tgc->bm_params = *params;
    255         tgc->bm_pixels = tbm->alloc.pixels;
    256         *rbm = (void *)tbm;
    257         return EOK;
    258 }
    259 
    260 static errno_t testgc_bitmap_destroy(void *bm)
    261 {
    262         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    263         if (tbm->myalloc)
    264                 free(tbm->alloc.pixels);
    265         free(tbm);
    266         return EOK;
    267 }
    268 
    269 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    270     gfx_coord2_t *offs)
    271 {
    272         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    273         tbm->tgc->bm_srect = *srect;
    274         tbm->tgc->bm_offs = *offs;
    275         return EOK;
    276 }
    277 
    278 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    279 {
    280         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    281         *alloc = tbm->alloc;
    282         return EOK;
    283 }
    284 
    285182PCUT_EXPORT(tpf);
  • uspace/lib/gfxfont/test/typeface.c

    r97116a2 r1fa6292  
    3232#include <pcut/pcut.h>
    3333#include "../private/typeface.h"
     34#include "../private/testgc.h"
    3435
    3536PCUT_INIT;
    3637
    3738PCUT_TEST_SUITE(typeface);
    38 
    39 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    40 static errno_t testgc_set_color(void *, gfx_color_t *);
    41 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    42 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    43     gfx_bitmap_alloc_t *, void **);
    44 static errno_t testgc_bitmap_destroy(void *);
    45 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    46 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    47 
    48 static gfx_context_ops_t test_ops = {
    49         .set_clip_rect = testgc_set_clip_rect,
    50         .set_color = testgc_set_color,
    51         .fill_rect = testgc_fill_rect,
    52         .bitmap_create = testgc_bitmap_create,
    53         .bitmap_destroy = testgc_bitmap_destroy,
    54         .bitmap_render = testgc_bitmap_render,
    55         .bitmap_get_alloc = testgc_bitmap_get_alloc
    56 };
    57 
    58 typedef struct {
    59         gfx_bitmap_params_t bm_params;
    60         void *bm_pixels;
    61         gfx_rect_t bm_srect;
    62         gfx_coord2_t bm_offs;
    63 } test_gc_t;
    64 
    65 typedef struct {
    66         test_gc_t *tgc;
    67         gfx_bitmap_alloc_t alloc;
    68         bool myalloc;
    69 } testgc_bitmap_t;
    7039
    7140/** Test creating and destroying typeface */
     
    9867}
    9968
    100 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    101 {
    102         return EOK;
    103 }
    104 
    105 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    106 {
    107         return EOK;
    108 }
    109 
    110 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    111 {
    112         return EOK;
    113 }
    114 
    115 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    116     gfx_bitmap_alloc_t *alloc, void **rbm)
    117 {
    118         test_gc_t *tgc = (test_gc_t *) arg;
    119         testgc_bitmap_t *tbm;
    120 
    121         tbm = calloc(1, sizeof(testgc_bitmap_t));
    122         if (tbm == NULL)
    123                 return ENOMEM;
    124 
    125         if (alloc == NULL) {
    126                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    127                     sizeof(uint32_t);
    128                 tbm->alloc.off0 = 0;
    129                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    130                     tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
    131                 tbm->myalloc = true;
    132                 if (tbm->alloc.pixels == NULL) {
    133                         free(tbm);
    134                         return ENOMEM;
    135                 }
    136         } else {
    137                 tbm->alloc = *alloc;
    138         }
    139 
    140         tbm->tgc = tgc;
    141         tgc->bm_params = *params;
    142         tgc->bm_pixels = tbm->alloc.pixels;
    143         *rbm = (void *)tbm;
    144         return EOK;
    145 }
    146 
    147 static errno_t testgc_bitmap_destroy(void *bm)
    148 {
    149         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    150         if (tbm->myalloc)
    151                 free(tbm->alloc.pixels);
    152         free(tbm);
    153         return EOK;
    154 }
    155 
    156 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    157     gfx_coord2_t *offs)
    158 {
    159         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    160         tbm->tgc->bm_srect = *srect;
    161         tbm->tgc->bm_offs = *offs;
    162         return EOK;
    163 }
    164 
    165 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    166 {
    167         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    168         *alloc = tbm->alloc;
    169         return EOK;
    170 }
    171 
    17269PCUT_EXPORT(typeface);
Note: See TracChangeset for help on using the changeset viewer.