Changeset 1fa6292 in mainline for uspace/lib/ui/test/wdecor.c


Ignore:
Timestamp:
2025-01-28T14:48:04Z (3 months 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.