Changeset 1fa6292 in mainline


Ignore:
Timestamp:
2025-01-28T14:48:04Z (3 weeks ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
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)
Message:

Remove a ton of duplicated code in libui/libgfxfont tests

Location:
uspace/lib
Files:
2 added
16 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);
  • uspace/lib/ui/src/dummygc.c

    r97116a2 r1fa6292  
    181181                    sizeof(uint32_t);
    182182                tbm->alloc.off0 = 0;
    183                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
     183                tbm->alloc.pixels = calloc(
    184184                    (params->rect.p1.x - params->rect.p0.x) *
    185                     (params->rect.p1.y - params->rect.p0.y));
     185                    (params->rect.p1.y - params->rect.p0.y),
     186                    sizeof(uint32_t));
    186187                tbm->myalloc = true;
    187188                if (tbm->alloc.pixels == NULL) {
  • uspace/lib/ui/test/checkbox.c

    r97116a2 r1fa6292  
    3636#include <ui/resource.h>
    3737#include "../private/checkbox.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(checkbox);
    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_update(void *);
    47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    48     gfx_bitmap_alloc_t *, void **);
    49 static errno_t testgc_bitmap_destroy(void *);
    50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    52 
    53 static gfx_context_ops_t ops = {
    54         .set_clip_rect = testgc_set_clip_rect,
    55         .set_color = testgc_set_color,
    56         .fill_rect = testgc_fill_rect,
    57         .update = testgc_update,
    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 };
    6343
    6444static void test_checkbox_switched(ui_checkbox_t *, void *, bool);
     
    7050static ui_checkbox_cb_t dummy_checkbox_cb = {
    7151};
    72 
    73 typedef struct {
    74         bool bm_created;
    75         bool bm_destroyed;
    76         gfx_bitmap_params_t bm_params;
    77         void *bm_pixels;
    78         gfx_rect_t bm_srect;
    79         gfx_coord2_t bm_offs;
    80         bool bm_rendered;
    81         bool bm_got_alloc;
    82 } test_gc_t;
    83 
    84 typedef struct {
    85         test_gc_t *tgc;
    86         gfx_bitmap_alloc_t alloc;
    87         bool myalloc;
    88 } testgc_bitmap_t;
    8952
    9053typedef struct {
     
    549512}
    550513
    551 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    552 {
    553         (void) arg;
    554         (void) rect;
    555         return EOK;
    556 }
    557 
    558 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    559 {
    560         (void) arg;
    561         (void) color;
    562         return EOK;
    563 }
    564 
    565 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    566 {
    567         (void) arg;
    568         (void) rect;
    569         return EOK;
    570 }
    571 
    572 static errno_t testgc_update(void *arg)
    573 {
    574         (void) arg;
    575         return EOK;
    576 }
    577 
    578 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    579     gfx_bitmap_alloc_t *alloc, void **rbm)
    580 {
    581         test_gc_t *tgc = (test_gc_t *) arg;
    582         testgc_bitmap_t *tbm;
    583 
    584         tbm = calloc(1, sizeof(testgc_bitmap_t));
    585         if (tbm == NULL)
    586                 return ENOMEM;
    587 
    588         if (alloc == NULL) {
    589                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    590                     sizeof(uint32_t);
    591                 tbm->alloc.off0 = 0;
    592                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    593                     (params->rect.p1.x - params->rect.p0.x) *
    594                     (params->rect.p1.y - params->rect.p0.y));
    595                 tbm->myalloc = true;
    596                 if (tbm->alloc.pixels == NULL) {
    597                         free(tbm);
    598                         return ENOMEM;
    599                 }
    600         } else {
    601                 tbm->alloc = *alloc;
    602         }
    603 
    604         tbm->tgc = tgc;
    605         tgc->bm_created = true;
    606         tgc->bm_params = *params;
    607         tgc->bm_pixels = tbm->alloc.pixels;
    608         *rbm = (void *)tbm;
    609         return EOK;
    610 }
    611 
    612 static errno_t testgc_bitmap_destroy(void *bm)
    613 {
    614         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    615         if (tbm->myalloc)
    616                 free(tbm->alloc.pixels);
    617         tbm->tgc->bm_destroyed = true;
    618         free(tbm);
    619         return EOK;
    620 }
    621 
    622 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    623     gfx_coord2_t *offs)
    624 {
    625         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    626         tbm->tgc->bm_rendered = true;
    627         tbm->tgc->bm_srect = *srect;
    628         tbm->tgc->bm_offs = *offs;
    629         return EOK;
    630 }
    631 
    632 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    633 {
    634         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    635         *alloc = tbm->alloc;
    636         tbm->tgc->bm_got_alloc = true;
    637         return EOK;
    638 }
    639 
    640514static void test_checkbox_switched(ui_checkbox_t *checkbox, void *arg,
    641515    bool checked)
  • uspace/lib/ui/test/label.c

    r97116a2 r1fa6292  
    3636#include <ui/resource.h>
    3737#include "../private/label.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(label);
    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_update(void *);
    47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    48     gfx_bitmap_alloc_t *, void **);
    49 static errno_t testgc_bitmap_destroy(void *);
    50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    52 
    53 static gfx_context_ops_t ops = {
    54         .set_clip_rect = testgc_set_clip_rect,
    55         .set_color = testgc_set_color,
    56         .fill_rect = testgc_fill_rect,
    57         .update = testgc_update,
    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         bool bm_created;
    66         bool bm_destroyed;
    67         gfx_bitmap_params_t bm_params;
    68         void *bm_pixels;
    69         gfx_rect_t bm_srect;
    70         gfx_coord2_t bm_offs;
    71         bool bm_rendered;
    72         bool bm_got_alloc;
    73 } test_gc_t;
    74 
    75 typedef struct {
    76         test_gc_t *tgc;
    77         gfx_bitmap_alloc_t alloc;
    78         bool myalloc;
    79 } testgc_bitmap_t;
    8043
    8144typedef struct {
     
    213176}
    214177
    215 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    216 {
    217         (void) arg;
    218         (void) rect;
    219         return EOK;
    220 }
    221 
    222 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    223 {
    224         (void) arg;
    225         (void) color;
    226         return EOK;
    227 }
    228 
    229 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    230 {
    231         (void) arg;
    232         (void) rect;
    233         return EOK;
    234 }
    235 
    236 static errno_t testgc_update(void *arg)
    237 {
    238         (void) arg;
    239         return EOK;
    240 }
    241 
    242 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    243     gfx_bitmap_alloc_t *alloc, void **rbm)
    244 {
    245         test_gc_t *tgc = (test_gc_t *) arg;
    246         testgc_bitmap_t *tbm;
    247 
    248         tbm = calloc(1, sizeof(testgc_bitmap_t));
    249         if (tbm == NULL)
    250                 return ENOMEM;
    251 
    252         if (alloc == NULL) {
    253                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    254                     sizeof(uint32_t);
    255                 tbm->alloc.off0 = 0;
    256                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    257                     (params->rect.p1.x - params->rect.p0.x) *
    258                     (params->rect.p1.y - params->rect.p0.y));
    259                 tbm->myalloc = true;
    260                 if (tbm->alloc.pixels == NULL) {
    261                         free(tbm);
    262                         return ENOMEM;
    263                 }
    264         } else {
    265                 tbm->alloc = *alloc;
    266         }
    267 
    268         tbm->tgc = tgc;
    269         tgc->bm_created = true;
    270         tgc->bm_params = *params;
    271         tgc->bm_pixels = tbm->alloc.pixels;
    272         *rbm = (void *)tbm;
    273         return EOK;
    274 }
    275 
    276 static errno_t testgc_bitmap_destroy(void *bm)
    277 {
    278         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    279         if (tbm->myalloc)
    280                 free(tbm->alloc.pixels);
    281         tbm->tgc->bm_destroyed = true;
    282         free(tbm);
    283         return EOK;
    284 }
    285 
    286 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    287     gfx_coord2_t *offs)
    288 {
    289         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    290         tbm->tgc->bm_rendered = true;
    291         tbm->tgc->bm_srect = *srect;
    292         tbm->tgc->bm_offs = *offs;
    293         return EOK;
    294 }
    295 
    296 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    297 {
    298         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    299         *alloc = tbm->alloc;
    300         tbm->tgc->bm_got_alloc = true;
    301         return EOK;
    302 }
    303 
    304178PCUT_EXPORT(label);
  • uspace/lib/ui/test/paint.c

    r97116a2 r1fa6292  
    3434#include <ui/paint.h>
    3535#include <ui/resource.h>
     36#include "../private/testgc.h"
    3637
    3738PCUT_INIT;
    3839
    3940PCUT_TEST_SUITE(paint);
    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 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         bool bm_created;
    62         bool bm_destroyed;
    63         gfx_bitmap_params_t bm_params;
    64         void *bm_pixels;
    65         gfx_rect_t bm_srect;
    66         gfx_coord2_t bm_offs;
    67         bool bm_rendered;
    68         bool bm_got_alloc;
    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;
    7641
    7742/** Test box characters */
     
    591556}
    592557
    593 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    594 {
    595         (void) arg;
    596         (void) rect;
    597         return EOK;
    598 }
    599 
    600 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    601 {
    602         (void) arg;
    603         (void) color;
    604         return EOK;
    605 }
    606 
    607 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    608 {
    609         (void) arg;
    610         (void) rect;
    611         return EOK;
    612 }
    613 
    614 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    615     gfx_bitmap_alloc_t *alloc, void **rbm)
    616 {
    617         test_gc_t *tgc = (test_gc_t *) arg;
    618         testgc_bitmap_t *tbm;
    619 
    620         tbm = calloc(1, sizeof(testgc_bitmap_t));
    621         if (tbm == NULL)
    622                 return ENOMEM;
    623 
    624         if (alloc == NULL) {
    625                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    626                     sizeof(uint32_t);
    627                 tbm->alloc.off0 = 0;
    628                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    629                     (params->rect.p1.x - params->rect.p0.x) *
    630                     (params->rect.p1.y - params->rect.p0.y));
    631                 tbm->myalloc = true;
    632                 if (tbm->alloc.pixels == NULL) {
    633                         free(tbm);
    634                         return ENOMEM;
    635                 }
    636         } else {
    637                 tbm->alloc = *alloc;
    638         }
    639 
    640         tbm->tgc = tgc;
    641         tgc->bm_created = true;
    642         tgc->bm_params = *params;
    643         tgc->bm_pixels = tbm->alloc.pixels;
    644         *rbm = (void *)tbm;
    645         return EOK;
    646 }
    647 
    648 static errno_t testgc_bitmap_destroy(void *bm)
    649 {
    650         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    651         if (tbm->myalloc)
    652                 free(tbm->alloc.pixels);
    653         tbm->tgc->bm_destroyed = true;
    654         free(tbm);
    655         return EOK;
    656 }
    657 
    658 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    659     gfx_coord2_t *offs)
    660 {
    661         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    662         tbm->tgc->bm_rendered = true;
    663         tbm->tgc->bm_srect = *srect;
    664         tbm->tgc->bm_offs = *offs;
    665         return EOK;
    666 }
    667 
    668 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    669 {
    670         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    671         *alloc = tbm->alloc;
    672         tbm->tgc->bm_got_alloc = true;
    673         return EOK;
    674 }
    675 
    676558PCUT_EXPORT(paint);
  • uspace/lib/ui/test/pbutton.c

    r97116a2 r1fa6292  
    3636#include <ui/resource.h>
    3737#include "../private/pbutton.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(pbutton);
    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_update(void *);
    47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    48     gfx_bitmap_alloc_t *, void **);
    49 static errno_t testgc_bitmap_destroy(void *);
    50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    52 
    53 static gfx_context_ops_t ops = {
    54         .set_clip_rect = testgc_set_clip_rect,
    55         .set_color = testgc_set_color,
    56         .fill_rect = testgc_fill_rect,
    57         .update = testgc_update,
    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 };
    6343
    6444static void test_pbutton_clicked(ui_pbutton_t *, void *);
     
    7454static ui_pbutton_cb_t dummy_pbutton_cb = {
    7555};
    76 
    77 typedef struct {
    78         bool bm_created;
    79         bool bm_destroyed;
    80         gfx_bitmap_params_t bm_params;
    81         void *bm_pixels;
    82         gfx_rect_t bm_srect;
    83         gfx_coord2_t bm_offs;
    84         bool bm_rendered;
    85         bool bm_got_alloc;
    86 } test_gc_t;
    87 
    88 typedef struct {
    89         test_gc_t *tgc;
    90         gfx_bitmap_alloc_t alloc;
    91         bool myalloc;
    92 } testgc_bitmap_t;
    9356
    9457typedef struct {
     
    625588}
    626589
    627 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    628 {
    629         (void) arg;
    630         (void) rect;
    631         return EOK;
    632 }
    633 
    634 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    635 {
    636         (void) arg;
    637         (void) color;
    638         return EOK;
    639 }
    640 
    641 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    642 {
    643         (void) arg;
    644         (void) rect;
    645         return EOK;
    646 }
    647 
    648 static errno_t testgc_update(void *arg)
    649 {
    650         (void) arg;
    651         return EOK;
    652 }
    653 
    654 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    655     gfx_bitmap_alloc_t *alloc, void **rbm)
    656 {
    657         test_gc_t *tgc = (test_gc_t *) arg;
    658         testgc_bitmap_t *tbm;
    659 
    660         tbm = calloc(1, sizeof(testgc_bitmap_t));
    661         if (tbm == NULL)
    662                 return ENOMEM;
    663 
    664         if (alloc == NULL) {
    665                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    666                     sizeof(uint32_t);
    667                 tbm->alloc.off0 = 0;
    668                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    669                     (params->rect.p1.x - params->rect.p0.x) *
    670                     (params->rect.p1.y - params->rect.p0.y));
    671                 tbm->myalloc = true;
    672                 if (tbm->alloc.pixels == NULL) {
    673                         free(tbm);
    674                         return ENOMEM;
    675                 }
    676         } else {
    677                 tbm->alloc = *alloc;
    678         }
    679 
    680         tbm->tgc = tgc;
    681         tgc->bm_created = true;
    682         tgc->bm_params = *params;
    683         tgc->bm_pixels = tbm->alloc.pixels;
    684         *rbm = (void *)tbm;
    685         return EOK;
    686 }
    687 
    688 static errno_t testgc_bitmap_destroy(void *bm)
    689 {
    690         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    691         if (tbm->myalloc)
    692                 free(tbm->alloc.pixels);
    693         tbm->tgc->bm_destroyed = true;
    694         free(tbm);
    695         return EOK;
    696 }
    697 
    698 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    699     gfx_coord2_t *offs)
    700 {
    701         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    702         tbm->tgc->bm_rendered = true;
    703         tbm->tgc->bm_srect = *srect;
    704         tbm->tgc->bm_offs = *offs;
    705         return EOK;
    706 }
    707 
    708 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    709 {
    710         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    711         *alloc = tbm->alloc;
    712         tbm->tgc->bm_got_alloc = true;
    713         return EOK;
    714 }
    715 
    716590static void test_pbutton_clicked(ui_pbutton_t *pbutton, void *arg)
    717591{
  • uspace/lib/ui/test/rbutton.c

    r97116a2 r1fa6292  
    3636#include <ui/resource.h>
    3737#include "../private/rbutton.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(rbutton);
    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_update(void *);
    47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    48     gfx_bitmap_alloc_t *, void **);
    49 static errno_t testgc_bitmap_destroy(void *);
    50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    52 
    53 static gfx_context_ops_t ops = {
    54         .set_clip_rect = testgc_set_clip_rect,
    55         .set_color = testgc_set_color,
    56         .fill_rect = testgc_fill_rect,
    57         .update = testgc_update,
    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 };
    6343
    6444static void test_rbutton_select(ui_rbutton_group_t *, void *, void *);
     
    7050static ui_rbutton_group_cb_t dummy_rbutton_group_cb = {
    7151};
    72 
    73 typedef struct {
    74         bool bm_created;
    75         bool bm_destroyed;
    76         gfx_bitmap_params_t bm_params;
    77         void *bm_pixels;
    78         gfx_rect_t bm_srect;
    79         gfx_coord2_t bm_offs;
    80         bool bm_rendered;
    81         bool bm_got_alloc;
    82 } test_gc_t;
    83 
    84 typedef struct {
    85         test_gc_t *tgc;
    86         gfx_bitmap_alloc_t alloc;
    87         bool myalloc;
    88 } testgc_bitmap_t;
    8952
    9053typedef struct {
     
    592555}
    593556
    594 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    595 {
    596         (void) arg;
    597         (void) rect;
    598         return EOK;
    599 }
    600 
    601 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    602 {
    603         (void) arg;
    604         (void) color;
    605         return EOK;
    606 }
    607 
    608 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    609 {
    610         (void) arg;
    611         (void) rect;
    612         return EOK;
    613 }
    614 
    615 static errno_t testgc_update(void *arg)
    616 {
    617         (void) arg;
    618         return EOK;
    619 }
    620 
    621 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    622     gfx_bitmap_alloc_t *alloc, void **rbm)
    623 {
    624         test_gc_t *tgc = (test_gc_t *) arg;
    625         testgc_bitmap_t *tbm;
    626 
    627         tbm = calloc(1, sizeof(testgc_bitmap_t));
    628         if (tbm == NULL)
    629                 return ENOMEM;
    630 
    631         if (alloc == NULL) {
    632                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    633                     sizeof(uint32_t);
    634                 tbm->alloc.off0 = 0;
    635                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    636                     (params->rect.p1.x - params->rect.p0.x) *
    637                     (params->rect.p1.y - params->rect.p0.y));
    638                 tbm->myalloc = true;
    639                 if (tbm->alloc.pixels == NULL) {
    640                         free(tbm);
    641                         return ENOMEM;
    642                 }
    643         } else {
    644                 tbm->alloc = *alloc;
    645         }
    646 
    647         tbm->tgc = tgc;
    648         tgc->bm_created = true;
    649         tgc->bm_params = *params;
    650         tgc->bm_pixels = tbm->alloc.pixels;
    651         *rbm = (void *)tbm;
    652         return EOK;
    653 }
    654 
    655 static errno_t testgc_bitmap_destroy(void *bm)
    656 {
    657         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    658         if (tbm->myalloc)
    659                 free(tbm->alloc.pixels);
    660         tbm->tgc->bm_destroyed = true;
    661         free(tbm);
    662         return EOK;
    663 }
    664 
    665 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    666     gfx_coord2_t *offs)
    667 {
    668         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    669         tbm->tgc->bm_rendered = true;
    670         tbm->tgc->bm_srect = *srect;
    671         tbm->tgc->bm_offs = *offs;
    672         return EOK;
    673 }
    674 
    675 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    676 {
    677         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    678         *alloc = tbm->alloc;
    679         tbm->tgc->bm_got_alloc = true;
    680         return EOK;
    681 }
    682 
    683557static void test_rbutton_select(ui_rbutton_group_t *group, void *arg,
    684558    void *barg)
  • uspace/lib/ui/test/resource.c

    r97116a2 r1fa6292  
    3333#include <ui/resource.h>
    3434#include "../private/resource.h"
     35#include "../private/testgc.h"
    3536
    3637PCUT_INIT;
     
    3839PCUT_TEST_SUITE(resource);
    3940
    40 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    41     gfx_bitmap_alloc_t *, void **);
    42 static errno_t testgc_bitmap_destroy(void *);
    43 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    44 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    45 
    4641static void test_expose(void *);
    47 
    48 static gfx_context_ops_t ops = {
    49         .bitmap_create = testgc_bitmap_create,
    50         .bitmap_destroy = testgc_bitmap_destroy,
    51         .bitmap_render = testgc_bitmap_render,
    52         .bitmap_get_alloc = testgc_bitmap_get_alloc
    53 };
    54 
    55 typedef struct {
    56         bool bm_created;
    57         bool bm_destroyed;
    58         gfx_bitmap_params_t bm_params;
    59         void *bm_pixels;
    60         gfx_rect_t bm_srect;
    61         gfx_coord2_t bm_offs;
    62         bool bm_rendered;
    63         bool bm_got_alloc;
    64 } test_gc_t;
    65 
    66 typedef struct {
    67         test_gc_t *tgc;
    68         gfx_bitmap_alloc_t alloc;
    69         bool myalloc;
    70 } testgc_bitmap_t;
    7142
    7243typedef struct {
     
    240211}
    241212
    242 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    243     gfx_bitmap_alloc_t *alloc, void **rbm)
    244 {
    245         test_gc_t *tgc = (test_gc_t *) arg;
    246         testgc_bitmap_t *tbm;
    247 
    248         tbm = calloc(1, sizeof(testgc_bitmap_t));
    249         if (tbm == NULL)
    250                 return ENOMEM;
    251 
    252         if (alloc == NULL) {
    253                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    254                     sizeof(uint32_t);
    255                 tbm->alloc.off0 = 0;
    256                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    257                     (params->rect.p1.x - params->rect.p0.x) *
    258                     (params->rect.p1.y - params->rect.p0.y));
    259                 tbm->myalloc = true;
    260                 if (tbm->alloc.pixels == NULL) {
    261                         free(tbm);
    262                         return ENOMEM;
    263                 }
    264         } else {
    265                 tbm->alloc = *alloc;
    266         }
    267 
    268         tbm->tgc = tgc;
    269         tgc->bm_created = true;
    270         tgc->bm_params = *params;
    271         tgc->bm_pixels = tbm->alloc.pixels;
    272         *rbm = (void *)tbm;
    273         return EOK;
    274 }
    275 
    276 static errno_t testgc_bitmap_destroy(void *bm)
    277 {
    278         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    279         if (tbm->myalloc)
    280                 free(tbm->alloc.pixels);
    281         tbm->tgc->bm_destroyed = true;
    282         free(tbm);
    283         return EOK;
    284 }
    285 
    286 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    287     gfx_coord2_t *offs)
    288 {
    289         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    290         tbm->tgc->bm_rendered = true;
    291         tbm->tgc->bm_srect = *srect;
    292         tbm->tgc->bm_offs = *offs;
    293         return EOK;
    294 }
    295 
    296 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    297 {
    298         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    299         *alloc = tbm->alloc;
    300         tbm->tgc->bm_got_alloc = true;
    301         return EOK;
    302 }
    303 
    304213static void test_expose(void *arg)
    305214{
  • uspace/lib/ui/test/slider.c

    r97116a2 r1fa6292  
    3636#include <ui/resource.h>
    3737#include "../private/slider.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(slider);
    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_update(void *);
    47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    48     gfx_bitmap_alloc_t *, void **);
    49 static errno_t testgc_bitmap_destroy(void *);
    50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    52 
    53 static gfx_context_ops_t ops = {
    54         .set_clip_rect = testgc_set_clip_rect,
    55         .set_color = testgc_set_color,
    56         .fill_rect = testgc_fill_rect,
    57         .update = testgc_update,
    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 };
    6343
    6444static void test_slider_moved(ui_slider_t *, void *, gfx_coord_t);
     
    7050static ui_slider_cb_t dummy_slider_cb = {
    7151};
    72 
    73 typedef struct {
    74         bool bm_created;
    75         bool bm_destroyed;
    76         gfx_bitmap_params_t bm_params;
    77         void *bm_pixels;
    78         gfx_rect_t bm_srect;
    79         gfx_coord2_t bm_offs;
    80         bool bm_rendered;
    81         bool bm_got_alloc;
    82 } test_gc_t;
    83 
    84 typedef struct {
    85         test_gc_t *tgc;
    86         gfx_bitmap_alloc_t alloc;
    87         bool myalloc;
    88 } testgc_bitmap_t;
    8952
    9053typedef struct {
     
    462425}
    463426
    464 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    465 {
    466         (void) arg;
    467         (void) rect;
    468         return EOK;
    469 }
    470 
    471 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    472 {
    473         (void) arg;
    474         (void) color;
    475         return EOK;
    476 }
    477 
    478 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    479 {
    480         (void) arg;
    481         (void) rect;
    482         return EOK;
    483 }
    484 
    485 static errno_t testgc_update(void *arg)
    486 {
    487         (void) arg;
    488         return EOK;
    489 }
    490 
    491 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    492     gfx_bitmap_alloc_t *alloc, void **rbm)
    493 {
    494         test_gc_t *tgc = (test_gc_t *) arg;
    495         testgc_bitmap_t *tbm;
    496 
    497         tbm = calloc(1, sizeof(testgc_bitmap_t));
    498         if (tbm == NULL)
    499                 return ENOMEM;
    500 
    501         if (alloc == NULL) {
    502                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    503                     sizeof(uint32_t);
    504                 tbm->alloc.off0 = 0;
    505                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    506                     (params->rect.p1.x - params->rect.p0.x) *
    507                     (params->rect.p1.y - params->rect.p0.y));
    508                 tbm->myalloc = true;
    509                 if (tbm->alloc.pixels == NULL) {
    510                         free(tbm);
    511                         return ENOMEM;
    512                 }
    513         } else {
    514                 tbm->alloc = *alloc;
    515         }
    516 
    517         tbm->tgc = tgc;
    518         tgc->bm_created = true;
    519         tgc->bm_params = *params;
    520         tgc->bm_pixels = tbm->alloc.pixels;
    521         *rbm = (void *)tbm;
    522         return EOK;
    523 }
    524 
    525 static errno_t testgc_bitmap_destroy(void *bm)
    526 {
    527         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    528         if (tbm->myalloc)
    529                 free(tbm->alloc.pixels);
    530         tbm->tgc->bm_destroyed = true;
    531         free(tbm);
    532         return EOK;
    533 }
    534 
    535 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    536     gfx_coord2_t *offs)
    537 {
    538         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    539         tbm->tgc->bm_rendered = true;
    540         tbm->tgc->bm_srect = *srect;
    541         tbm->tgc->bm_offs = *offs;
    542         return EOK;
    543 }
    544 
    545 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    546 {
    547         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    548         *alloc = tbm->alloc;
    549         tbm->tgc->bm_got_alloc = true;
    550         return EOK;
    551 }
    552 
    553427static void test_slider_moved(ui_slider_t *slider, void *arg, gfx_coord_t pos)
    554428{
  • uspace/lib/ui/test/wdecor.c

    r97116a2 r1fa6292  
    3737#include <ui/wdecor.h>
    3838#include "../private/wdecor.h"
     39#include "../private/testgc.h"
    3940
    4041PCUT_INIT;
    4142
    4243PCUT_TEST_SUITE(wdecor);
    43 
    44 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    45 static errno_t testgc_set_color(void *, gfx_color_t *);
    46 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    47 static errno_t testgc_update(void *);
    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 ops = {
    55         .set_clip_rect = testgc_set_clip_rect,
    56         .set_color = testgc_set_color,
    57         .fill_rect = testgc_fill_rect,
    58         .update = testgc_update,
    59         .bitmap_create = testgc_bitmap_create,
    60         .bitmap_destroy = testgc_bitmap_destroy,
    61         .bitmap_render = testgc_bitmap_render,
    62         .bitmap_get_alloc = testgc_bitmap_get_alloc
    63 };
    6444
    6545static void test_wdecor_sysmenu_open(ui_wdecor_t *, void *, sysarg_t);
     
    9373static ui_wdecor_cb_t dummy_wdecor_cb = {
    9474};
    95 
    96 typedef struct {
    97         bool bm_created;
    98         bool bm_destroyed;
    99         gfx_bitmap_params_t bm_params;
    100         void *bm_pixels;
    101         gfx_rect_t bm_srect;
    102         gfx_coord2_t bm_offs;
    103         bool bm_rendered;
    104         bool bm_got_alloc;
    105 } test_gc_t;
    106 
    107 typedef struct {
    108         test_gc_t *tgc;
    109         gfx_bitmap_alloc_t alloc;
    110         bool myalloc;
    111 } testgc_bitmap_t;
    11275
    11376typedef struct {
     
    15671530}
    15681531
    1569 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    1570 {
    1571         (void) arg;
    1572         (void) rect;
    1573         return EOK;
    1574 }
    1575 
    1576 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    1577 {
    1578         (void) arg;
    1579         (void) color;
    1580         return EOK;
    1581 }
    1582 
    1583 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    1584 {
    1585         (void) arg;
    1586         (void) rect;
    1587         return EOK;
    1588 }
    1589 
    1590 static errno_t testgc_update(void *arg)
    1591 {
    1592         (void) arg;
    1593         return EOK;
    1594 }
    1595 
    1596 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    1597     gfx_bitmap_alloc_t *alloc, void **rbm)
    1598 {
    1599         test_gc_t *tgc = (test_gc_t *) arg;
    1600         testgc_bitmap_t *tbm;
    1601 
    1602         tbm = calloc(1, sizeof(testgc_bitmap_t));
    1603         if (tbm == NULL)
    1604                 return ENOMEM;
    1605 
    1606         if (alloc == NULL) {
    1607                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    1608                     sizeof(uint32_t);
    1609                 tbm->alloc.off0 = 0;
    1610                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    1611                     (params->rect.p1.x - params->rect.p0.x) *
    1612                     (params->rect.p1.y - params->rect.p0.y));
    1613                 tbm->myalloc = true;
    1614                 if (tbm->alloc.pixels == NULL) {
    1615                         free(tbm);
    1616                         return ENOMEM;
    1617                 }
    1618         } else {
    1619                 tbm->alloc = *alloc;
    1620         }
    1621 
    1622         tbm->tgc = tgc;
    1623         tgc->bm_created = true;
    1624         tgc->bm_params = *params;
    1625         tgc->bm_pixels = tbm->alloc.pixels;
    1626         *rbm = (void *)tbm;
    1627         return EOK;
    1628 }
    1629 
    1630 static errno_t testgc_bitmap_destroy(void *bm)
    1631 {
    1632         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    1633         if (tbm->myalloc)
    1634                 free(tbm->alloc.pixels);
    1635         tbm->tgc->bm_destroyed = true;
    1636         free(tbm);
    1637         return EOK;
    1638 }
    1639 
    1640 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    1641     gfx_coord2_t *offs)
    1642 {
    1643         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    1644         tbm->tgc->bm_rendered = true;
    1645         tbm->tgc->bm_srect = *srect;
    1646         tbm->tgc->bm_offs = *offs;
    1647         return EOK;
    1648 }
    1649 
    1650 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    1651 {
    1652         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    1653         *alloc = tbm->alloc;
    1654         tbm->tgc->bm_got_alloc = true;
    1655         return EOK;
    1656 }
    1657 
    16581532static void test_wdecor_sysmenu_open(ui_wdecor_t *wdecor, void *arg,
    16591533    sysarg_t idev_id)
Note: See TracChangeset for help on using the changeset viewer.