Changeset 8c772c4 in mainline


Ignore:
Timestamp:
2020-11-07T22:12:12Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3583ffb
Parents:
d55ab823
Message:

Create UI controls based on UI object instead of based on UI resource

We want to be a bit more generic. Better not expose UI resource
(at least not in this particular case).

Location:
uspace
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/terminal/terminal.c

    rd55ab823 r8c772c4  
    835835
    836836        term->gc = ui_window_get_gc(term->window);
    837         term->ui_res = ui_window_get_res(term->window);
    838837
    839838        ui_window_set_cb(term->window, &terminal_window_cb, (void *) term);
  • uspace/app/terminal/terminal.h

    rd55ab823 r8c772c4  
    5757        ui_t *ui;
    5858        ui_window_t *window;
    59         ui_resource_t *ui_res;
    6059        gfx_context_t *gc;
    6160
  • uspace/app/uidemo/uidemo.c

    rd55ab823 r8c772c4  
    9999        ui_demo_t demo;
    100100        gfx_rect_t rect;
    101         ui_resource_t *ui_res;
    102101        errno_t rc;
    103102
     
    127126        demo.window = window;
    128127
    129         ui_res = ui_window_get_res(window);
    130 
    131128        rc = ui_fixed_create(&demo.fixed);
    132129        if (rc != EOK) {
     
    135132        }
    136133
    137         rc = ui_label_create(ui_res, "Hello there!", &demo.label);
     134        rc = ui_label_create(ui, "Hello there!", &demo.label);
    138135        if (rc != EOK) {
    139136                printf("Error creating label.\n");
     
    154151        }
    155152
    156         rc = ui_pbutton_create(ui_res, "Confirm", &demo.pb1);
     153        rc = ui_pbutton_create(ui, "Confirm", &demo.pb1);
    157154        if (rc != EOK) {
    158155                printf("Error creating button.\n");
     
    176173        }
    177174
    178         rc = ui_pbutton_create(ui_res, "Cancel", &demo.pb2);
     175        rc = ui_pbutton_create(ui, "Cancel", &demo.pb2);
    179176        if (rc != EOK) {
    180177                printf("Error creating button.\n");
  • uspace/lib/ui/include/ui/label.h

    rd55ab823 r8c772c4  
    4242#include <types/ui/control.h>
    4343#include <types/ui/label.h>
    44 #include <types/ui/resource.h>
     44#include <types/ui/ui.h>
    4545
    46 extern errno_t ui_label_create(ui_resource_t *, const char *,
     46extern errno_t ui_label_create(ui_t *, const char *,
    4747    ui_label_t **);
    4848extern void ui_label_destroy(ui_label_t *);
  • uspace/lib/ui/include/ui/pbutton.h

    rd55ab823 r8c772c4  
    4343#include <types/ui/event.h>
    4444#include <types/ui/pbutton.h>
    45 #include <types/ui/resource.h>
     45#include <types/ui/ui.h>
    4646#include <stdbool.h>
    4747
    48 extern errno_t ui_pbutton_create(ui_resource_t *, const char *,
     48extern errno_t ui_pbutton_create(ui_t *, const char *,
    4949    ui_pbutton_t **);
    5050extern void ui_pbutton_destroy(ui_pbutton_t *);
  • uspace/lib/ui/include/ui/wdecor.h

    rd55ab823 r8c772c4  
    4141#include <io/pos_event.h>
    4242#include <stdbool.h>
    43 #include <types/ui/resource.h>
     43#include <types/ui/ui.h>
    4444#include <types/ui/wdecor.h>
    4545
    46 extern errno_t ui_wdecor_create(ui_resource_t *, const char *,
     46extern errno_t ui_wdecor_create(ui_t *, const char *,
    4747    ui_wdecor_t **);
    4848extern void ui_wdecor_destroy(ui_wdecor_t *);
  • uspace/lib/ui/include/ui/window.h

    rd55ab823 r8c772c4  
    5353extern void ui_window_add(ui_window_t *, ui_control_t *);
    5454extern void ui_window_remove(ui_window_t *, ui_control_t *);
    55 extern ui_resource_t *ui_window_get_res(ui_window_t *);
    5655extern gfx_context_t *ui_window_get_gc(ui_window_t *);
    5756extern void ui_window_get_app_rect(ui_window_t *, gfx_rect_t *);
  • uspace/lib/ui/private/ui.h

    rd55ab823 r8c772c4  
    4848        /** Display */
    4949        display_t *display;
     50        /** UI resource */
     51        struct ui_resource *resource;
    5052        /** Output owned by UI, clean up when destroying UI */
    5153        bool myoutput;
  • uspace/lib/ui/src/label.c

    rd55ab823 r8c772c4  
    4545#include "../private/label.h"
    4646#include "../private/resource.h"
     47#include "../private/ui.h"
    4748
    4849static void ui_label_ctl_destroy(void *);
     
    6465 * @return EOK on success, ENOMEM if out of memory
    6566 */
    66 errno_t ui_label_create(ui_resource_t *resource, const char *text,
     67errno_t ui_label_create(ui_t *ui, const char *text,
    6768    ui_label_t **rlabel)
    6869{
     
    8788        }
    8889
    89         label->res = resource;
     90        label->res = ui->resource;
    9091        label->halign = gfx_halign_left;
    9192        *rlabel = label;
  • uspace/lib/ui/src/pbutton.c

    rd55ab823 r8c772c4  
    4747#include "../private/pbutton.h"
    4848#include "../private/resource.h"
     49#include "../private/ui.h"
    4950
    5051/** Caption movement when button is pressed down */
     
    7273 * @return EOK on success, ENOMEM if out of memory
    7374 */
    74 errno_t ui_pbutton_create(ui_resource_t *resource, const char *caption,
     75errno_t ui_pbutton_create(ui_t *ui, const char *caption,
    7576    ui_pbutton_t **rpbutton)
    7677{
     
    9697        }
    9798
    98         pbutton->res = resource;
     99        pbutton->res = ui->resource;
    99100        *rpbutton = pbutton;
    100101        return EOK;
  • uspace/lib/ui/src/wdecor.c

    rd55ab823 r8c772c4  
    4646#include <ui/wdecor.h>
    4747#include "../private/resource.h"
     48#include "../private/ui.h"
    4849#include "../private/wdecor.h"
    4950
     
    6162 * @return EOK on success, ENOMEM if out of memory
    6263 */
    63 errno_t ui_wdecor_create(ui_resource_t *resource, const char *caption,
     64errno_t ui_wdecor_create(ui_t *ui, const char *caption,
    6465    ui_wdecor_t **rwdecor)
    6566{
     
    7778        }
    7879
    79         rc = ui_pbutton_create(resource, "X", &wdecor->btn_close);
     80        rc = ui_pbutton_create(ui, "X", &wdecor->btn_close);
    8081        if (rc != EOK) {
    8182                free(wdecor->caption);
     
    8788            (void *)wdecor);
    8889
    89         wdecor->res = resource;
     90        wdecor->res = ui->resource;
    9091        wdecor->active = true;
    9192        *rwdecor = wdecor;
  • uspace/lib/ui/src/window.c

    rd55ab823 r8c772c4  
    135135                goto error;
    136136
    137         rc = ui_wdecor_create(res, params->caption, &wdecor);
     137        ui->resource = res;
     138
     139        rc = ui_wdecor_create(ui, params->caption, &wdecor);
    138140        if (rc != EOK)
    139141                goto error;
     
    223225}
    224226
    225 ui_resource_t *ui_window_get_res(ui_window_t *window)
    226 {
    227         return window->res;
    228 }
    229 
     227/** Get window GC.
     228 *
     229 * Return the grapic context of the window. It is relative to the upper-left
     230 * corner of the window.
     231 *
     232 * @param window Window
     233 * @return Graphic context
     234 */
    230235gfx_context_t *ui_window_get_gc(ui_window_t *window)
    231236{
     
    233238}
    234239
     240/** Get window application rectangle.
     241 *
     242 * Return the window's application rectangle. This is a rectangle covering
     243 * everything apart from the window frame and title bar.
     244 *
     245 * @param window Window
     246 * @param rect Place to store application rectangle
     247 */
    235248void ui_window_get_app_rect(ui_window_t *window, gfx_rect_t *rect)
    236249{
     
    241254}
    242255
     256/** Paint window.
     257 *
     258 * @param window Window
     259 * @return EOK on success or an error code
     260 */
    243261errno_t ui_window_paint(ui_window_t *window)
    244262{
  • uspace/lib/ui/test/label.c

    rd55ab823 r8c772c4  
    3434#include <ui/control.h>
    3535#include <ui/label.h>
    36 #include <ui/resource.h>
     36#include <ui/ui.h>
    3737#include "../private/label.h"
    3838
     
    4040
    4141PCUT_TEST_SUITE(label);
    42 
    43 static errno_t testgc_set_color(void *, gfx_color_t *);
    44 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    45 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    46     gfx_bitmap_alloc_t *, void **);
    47 static errno_t testgc_bitmap_destroy(void *);
    48 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    49 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    50 
    51 static gfx_context_ops_t ops = {
    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;
    7642
    7743typedef struct {
     
    183149{
    184150        errno_t rc;
    185         gfx_context_t *gc = NULL;
    186         test_gc_t tgc;
    187         ui_resource_t *resource = NULL;
     151        ui_t *ui;
    188152        ui_label_t *label;
    189153
    190         memset(&tgc, 0, sizeof(tgc));
    191         rc = gfx_context_new(&ops, &tgc, &gc);
     154        rc = ui_create_disp(NULL, &ui);
    192155        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    193156
    194         rc = ui_resource_create(gc, &resource);
    195         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    196         PCUT_ASSERT_NOT_NULL(resource);
    197 
    198         rc = ui_label_create(resource, "Hello", &label);
     157        rc = ui_label_create(ui, "Hello", &label);
    199158        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    200159
     
    203162
    204163        ui_label_destroy(label);
    205         ui_resource_destroy(resource);
    206 
    207         rc = gfx_context_delete(gc);
    208         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    209 }
    210 
    211 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    212 {
    213         (void) arg;
    214         (void) color;
    215         return EOK;
    216 }
    217 
    218 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    219 {
    220         (void) arg;
    221         (void) rect;
    222         return EOK;
    223 }
    224 
    225 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    226     gfx_bitmap_alloc_t *alloc, void **rbm)
    227 {
    228         test_gc_t *tgc = (test_gc_t *) arg;
    229         testgc_bitmap_t *tbm;
    230 
    231         tbm = calloc(1, sizeof(testgc_bitmap_t));
    232         if (tbm == NULL)
    233                 return ENOMEM;
    234 
    235         if (alloc == NULL) {
    236                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    237                     sizeof(uint32_t);
    238                 tbm->alloc.off0 = 0;
    239                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    240                     (params->rect.p1.x - params->rect.p0.x) *
    241                     (params->rect.p1.y - params->rect.p0.y));
    242                 tbm->myalloc = true;
    243                 if (tbm->alloc.pixels == NULL) {
    244                         free(tbm);
    245                         return ENOMEM;
    246                 }
    247         } else {
    248                 tbm->alloc = *alloc;
    249         }
    250 
    251         tbm->tgc = tgc;
    252         tgc->bm_created = true;
    253         tgc->bm_params = *params;
    254         tgc->bm_pixels = tbm->alloc.pixels;
    255         *rbm = (void *)tbm;
    256         return EOK;
    257 }
    258 
    259 static errno_t testgc_bitmap_destroy(void *bm)
    260 {
    261         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    262         if (tbm->myalloc)
    263                 free(tbm->alloc.pixels);
    264         tbm->tgc->bm_destroyed = true;
    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_rendered = true;
    274         tbm->tgc->bm_srect = *srect;
    275         tbm->tgc->bm_offs = *offs;
    276         return EOK;
    277 }
    278 
    279 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    280 {
    281         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    282         *alloc = tbm->alloc;
    283         tbm->tgc->bm_got_alloc = true;
    284         return EOK;
     164        ui_destroy(ui);
    285165}
    286166
  • uspace/lib/ui/test/pbutton.c

    rd55ab823 r8c772c4  
    3434#include <ui/control.h>
    3535#include <ui/pbutton.h>
    36 #include <ui/resource.h>
     36#include <ui/ui.h>
    3737#include "../private/pbutton.h"
    3838
     
    4040
    4141PCUT_TEST_SUITE(pbutton);
    42 
    43 static errno_t testgc_set_color(void *, gfx_color_t *);
    44 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    45 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    46     gfx_bitmap_alloc_t *, void **);
    47 static errno_t testgc_bitmap_destroy(void *);
    48 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    49 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    50 
    51 static gfx_context_ops_t ops = {
    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 };
    5942
    6043static void test_pbutton_clicked(ui_pbutton_t *, void *);
     
    6649static ui_pbutton_cb_t dummy_pbutton_cb = {
    6750};
    68 
    69 typedef struct {
    70         bool bm_created;
    71         bool bm_destroyed;
    72         gfx_bitmap_params_t bm_params;
    73         void *bm_pixels;
    74         gfx_rect_t bm_srect;
    75         gfx_coord2_t bm_offs;
    76         bool bm_rendered;
    77         bool bm_got_alloc;
    78 } test_gc_t;
    79 
    80 typedef struct {
    81         test_gc_t *tgc;
    82         gfx_bitmap_alloc_t alloc;
    83         bool myalloc;
    84 } testgc_bitmap_t;
    8551
    8652typedef struct {
     
    169135{
    170136        errno_t rc;
    171         gfx_context_t *gc = NULL;
    172         test_gc_t tgc;
    173         ui_resource_t *resource = NULL;
    174         ui_pbutton_t *pbutton;
    175 
    176         memset(&tgc, 0, sizeof(tgc));
    177         rc = gfx_context_new(&ops, &tgc, &gc);
    178         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    179 
    180         rc = ui_resource_create(gc, &resource);
    181         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    182         PCUT_ASSERT_NOT_NULL(resource);
    183 
    184         rc = ui_pbutton_create(resource, "Hello", &pbutton);
     137        ui_t *ui;
     138        ui_pbutton_t *pbutton;
     139
     140        rc = ui_create_disp(NULL, &ui);
     141        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     142
     143        rc = ui_pbutton_create(ui, "Hello", &pbutton);
    185144        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    186145
     
    189148
    190149        ui_pbutton_destroy(pbutton);
    191         ui_resource_destroy(resource);
    192 
    193         rc = gfx_context_delete(gc);
    194         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     150        ui_destroy(ui);
    195151}
    196152
     
    225181{
    226182        errno_t rc;
    227         gfx_context_t *gc = NULL;
    228         test_gc_t tgc;
    229         ui_resource_t *resource = NULL;
     183        ui_t *ui;
    230184        ui_pbutton_t *pbutton;
    231185        test_cb_resp_t resp;
    232186
    233         memset(&tgc, 0, sizeof(tgc));
    234         rc = gfx_context_new(&ops, &tgc, &gc);
    235         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    236 
    237         rc = ui_resource_create(gc, &resource);
    238         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    239         PCUT_ASSERT_NOT_NULL(resource);
    240 
    241         rc = ui_pbutton_create(resource, "Hello", &pbutton);
     187        rc = ui_create_disp(NULL, &ui);
     188        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     189
     190        rc = ui_pbutton_create(ui, "Hello", &pbutton);
    242191        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    243192
     
    259208
    260209        ui_pbutton_destroy(pbutton);
    261         ui_resource_destroy(resource);
    262 
    263         rc = gfx_context_delete(gc);
    264         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     210        ui_destroy(ui);
    265211}
    266212
     
    269215{
    270216        errno_t rc;
    271         gfx_context_t *gc = NULL;
    272         test_gc_t tgc;
    273         ui_resource_t *resource = NULL;
     217        ui_t *ui;
    274218        ui_pbutton_t *pbutton;
    275219        test_cb_resp_t resp;
    276220
    277         memset(&tgc, 0, sizeof(tgc));
    278         rc = gfx_context_new(&ops, &tgc, &gc);
    279         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    280 
    281         rc = ui_resource_create(gc, &resource);
    282         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    283         PCUT_ASSERT_NOT_NULL(resource);
    284 
    285         rc = ui_pbutton_create(resource, "Hello", &pbutton);
     221        rc = ui_create_disp(NULL, &ui);
     222        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     223
     224        rc = ui_pbutton_create(ui, "Hello", &pbutton);
    286225        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    287226
     
    308247
    309248        ui_pbutton_destroy(pbutton);
    310         ui_resource_destroy(resource);
    311 
    312         rc = gfx_context_delete(gc);
    313         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     249        ui_destroy(ui);
    314250}
    315251
     
    318254{
    319255        errno_t rc;
    320         gfx_context_t *gc = NULL;
    321         test_gc_t tgc;
    322         ui_resource_t *resource = NULL;
     256        ui_t *ui;
    323257        ui_pbutton_t *pbutton;
    324258        test_cb_resp_t resp;
    325259
    326         memset(&tgc, 0, sizeof(tgc));
    327         rc = gfx_context_new(&ops, &tgc, &gc);
    328         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    329 
    330         rc = ui_resource_create(gc, &resource);
    331         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    332         PCUT_ASSERT_NOT_NULL(resource);
    333 
    334         rc = ui_pbutton_create(resource, "Hello", &pbutton);
     260        rc = ui_create_disp(NULL, &ui);
     261        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     262
     263        rc = ui_pbutton_create(ui, "Hello", &pbutton);
    335264        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    336265
     
    362291
    363292        ui_pbutton_destroy(pbutton);
    364         ui_resource_destroy(resource);
    365 
    366         rc = gfx_context_delete(gc);
    367         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     293        ui_destroy(ui);
    368294}
    369295
     
    372298{
    373299        errno_t rc;
    374         gfx_context_t *gc = NULL;
    375         test_gc_t tgc;
    376         ui_resource_t *resource = NULL;
     300        ui_t *ui;
    377301        ui_pbutton_t *pbutton;
    378302        ui_evclaim_t claim;
     
    380304        gfx_rect_t rect;
    381305
    382         memset(&tgc, 0, sizeof(tgc));
    383         rc = gfx_context_new(&ops, &tgc, &gc);
    384         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    385 
    386         rc = ui_resource_create(gc, &resource);
    387         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    388         PCUT_ASSERT_NOT_NULL(resource);
    389 
    390         rc = ui_pbutton_create(resource, "Hello", &pbutton);
     306        rc = ui_create_disp(NULL, &ui);
     307        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     308
     309        rc = ui_pbutton_create(ui, "Hello", &pbutton);
    391310        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    392311
     
    424343
    425344        ui_pbutton_destroy(pbutton);
    426         ui_resource_destroy(resource);
    427 
    428         rc = gfx_context_delete(gc);
    429         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     345        ui_destroy(ui);
    430346}
    431347
     
    434350{
    435351        errno_t rc;
    436         gfx_context_t *gc = NULL;
    437         test_gc_t tgc;
    438         ui_resource_t *resource = NULL;
     352        ui_t *ui;
    439353        ui_pbutton_t *pbutton;
    440354        pos_event_t event;
    441355        gfx_rect_t rect;
    442356
    443         memset(&tgc, 0, sizeof(tgc));
    444         rc = gfx_context_new(&ops, &tgc, &gc);
    445         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    446 
    447         rc = ui_resource_create(gc, &resource);
    448         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    449         PCUT_ASSERT_NOT_NULL(resource);
    450 
    451         rc = ui_pbutton_create(resource, "Hello", &pbutton);
     357        rc = ui_create_disp(NULL, &ui);
     358        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     359
     360        rc = ui_pbutton_create(ui, "Hello", &pbutton);
    452361        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    453362
     
    482391
    483392        ui_pbutton_destroy(pbutton);
    484         ui_resource_destroy(resource);
    485 
    486         rc = gfx_context_delete(gc);
    487         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    488 }
    489 
    490 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    491 {
    492         (void) arg;
    493         (void) color;
    494         return EOK;
    495 }
    496 
    497 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    498 {
    499         (void) arg;
    500         (void) rect;
    501         return EOK;
    502 }
    503 
    504 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    505     gfx_bitmap_alloc_t *alloc, void **rbm)
    506 {
    507         test_gc_t *tgc = (test_gc_t *) arg;
    508         testgc_bitmap_t *tbm;
    509 
    510         tbm = calloc(1, sizeof(testgc_bitmap_t));
    511         if (tbm == NULL)
    512                 return ENOMEM;
    513 
    514         if (alloc == NULL) {
    515                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    516                     sizeof(uint32_t);
    517                 tbm->alloc.off0 = 0;
    518                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    519                     (params->rect.p1.x - params->rect.p0.x) *
    520                     (params->rect.p1.y - params->rect.p0.y));
    521                 tbm->myalloc = true;
    522                 if (tbm->alloc.pixels == NULL) {
    523                         free(tbm);
    524                         return ENOMEM;
    525                 }
    526         } else {
    527                 tbm->alloc = *alloc;
    528         }
    529 
    530         tbm->tgc = tgc;
    531         tgc->bm_created = true;
    532         tgc->bm_params = *params;
    533         tgc->bm_pixels = tbm->alloc.pixels;
    534         *rbm = (void *)tbm;
    535         return EOK;
    536 }
    537 
    538 static errno_t testgc_bitmap_destroy(void *bm)
    539 {
    540         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    541         if (tbm->myalloc)
    542                 free(tbm->alloc.pixels);
    543         tbm->tgc->bm_destroyed = true;
    544         free(tbm);
    545         return EOK;
    546 }
    547 
    548 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    549     gfx_coord2_t *offs)
    550 {
    551         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    552         tbm->tgc->bm_rendered = true;
    553         tbm->tgc->bm_srect = *srect;
    554         tbm->tgc->bm_offs = *offs;
    555         return EOK;
    556 }
    557 
    558 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    559 {
    560         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    561         *alloc = tbm->alloc;
    562         tbm->tgc->bm_got_alloc = true;
    563         return EOK;
     393        ui_destroy(ui);
    564394}
    565395
  • uspace/lib/ui/test/wdecor.c

    rd55ab823 r8c772c4  
    3333#include <stdbool.h>
    3434#include <ui/pbutton.h>
    35 #include <ui/resource.h>
     35#include <ui/ui.h>
    3636#include <ui/wdecor.h>
    3737#include "../private/wdecor.h"
     
    4040
    4141PCUT_TEST_SUITE(wdecor);
    42 
    43 static errno_t testgc_set_color(void *, gfx_color_t *);
    44 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    45 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    46     gfx_bitmap_alloc_t *, void **);
    47 static errno_t testgc_bitmap_destroy(void *);
    48 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    49 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    50 
    51 static gfx_context_ops_t ops = {
    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 };
    5942
    6043static void test_wdecor_close(ui_wdecor_t *, void *);
     
    6851static ui_wdecor_cb_t dummy_wdecor_cb = {
    6952};
    70 
    71 typedef struct {
    72         bool bm_created;
    73         bool bm_destroyed;
    74         gfx_bitmap_params_t bm_params;
    75         void *bm_pixels;
    76         gfx_rect_t bm_srect;
    77         gfx_coord2_t bm_offs;
    78         bool bm_rendered;
    79         bool bm_got_alloc;
    80 } test_gc_t;
    81 
    82 typedef struct {
    83         test_gc_t *tgc;
    84         gfx_bitmap_alloc_t alloc;
    85         bool myalloc;
    86 } testgc_bitmap_t;
    8753
    8854typedef struct {
     
    159125{
    160126        errno_t rc;
    161         gfx_context_t *gc = NULL;
    162         test_gc_t tgc;
    163         ui_resource_t *resource = NULL;
    164         ui_wdecor_t *wdecor;
    165 
    166         memset(&tgc, 0, sizeof(tgc));
    167         rc = gfx_context_new(&ops, &tgc, &gc);
    168         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    169 
    170         rc = ui_resource_create(gc, &resource);
    171         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    172         PCUT_ASSERT_NOT_NULL(resource);
    173 
    174         rc = ui_wdecor_create(resource, "Hello", &wdecor);
     127        ui_t *ui;
     128        ui_wdecor_t *wdecor;
     129
     130        rc = ui_create_disp(NULL, &ui);
     131        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     132
     133        rc = ui_wdecor_create(ui, "Hello", &wdecor);
    175134        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    176135
     
    179138
    180139        ui_wdecor_destroy(wdecor);
    181         ui_resource_destroy(resource);
    182 
    183         rc = gfx_context_delete(gc);
    184         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     140        ui_destroy(ui);
    185141}
    186142
     
    371327}
    372328
    373 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    374 {
    375         (void) arg;
    376         (void) color;
    377         return EOK;
    378 }
    379 
    380 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    381 {
    382         (void) arg;
    383         (void) rect;
    384         return EOK;
    385 }
    386 
    387 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    388     gfx_bitmap_alloc_t *alloc, void **rbm)
    389 {
    390         test_gc_t *tgc = (test_gc_t *) arg;
    391         testgc_bitmap_t *tbm;
    392 
    393         tbm = calloc(1, sizeof(testgc_bitmap_t));
    394         if (tbm == NULL)
    395                 return ENOMEM;
    396 
    397         if (alloc == NULL) {
    398                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    399                     sizeof(uint32_t);
    400                 tbm->alloc.off0 = 0;
    401                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    402                     (params->rect.p1.x - params->rect.p0.x) *
    403                     (params->rect.p1.y - params->rect.p0.y));
    404                 tbm->myalloc = true;
    405                 if (tbm->alloc.pixels == NULL) {
    406                         free(tbm);
    407                         return ENOMEM;
    408                 }
    409         } else {
    410                 tbm->alloc = *alloc;
    411         }
    412 
    413         tbm->tgc = tgc;
    414         tgc->bm_created = true;
    415         tgc->bm_params = *params;
    416         tgc->bm_pixels = tbm->alloc.pixels;
    417         *rbm = (void *)tbm;
    418         return EOK;
    419 }
    420 
    421 static errno_t testgc_bitmap_destroy(void *bm)
    422 {
    423         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    424         if (tbm->myalloc)
    425                 free(tbm->alloc.pixels);
    426         tbm->tgc->bm_destroyed = true;
    427         free(tbm);
    428         return EOK;
    429 }
    430 
    431 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    432     gfx_coord2_t *offs)
    433 {
    434         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    435         tbm->tgc->bm_rendered = true;
    436         tbm->tgc->bm_srect = *srect;
    437         tbm->tgc->bm_offs = *offs;
    438         return EOK;
    439 }
    440 
    441 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    442 {
    443         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    444         *alloc = tbm->alloc;
    445         tbm->tgc->bm_got_alloc = true;
    446         return EOK;
    447 }
    448 
    449329static void test_wdecor_close(ui_wdecor_t *wdecor, void *arg)
    450330{
  • uspace/lib/ui/test/window.c

    rd55ab823 r8c772c4  
    3535#include <stdbool.h>
    3636#include <ui/control.h>
    37 #include <ui/resource.h>
    3837#include <ui/ui.h>
    3938#include <ui/window.h>
     
    174173}
    175174
    176 /** ui_window_get_res/gc/rect() return valid objects */
    177 PCUT_TEST(get_res_gc_rect)
    178 {
    179         errno_t rc;
    180         ui_t *ui = NULL;
    181         ui_wnd_params_t params;
    182         ui_window_t *window = NULL;
    183         ui_resource_t *res;
     175/** ui_window_get_gc/rect() return valid objects */
     176PCUT_TEST(gc_rect)
     177{
     178        errno_t rc;
     179        ui_t *ui = NULL;
     180        ui_wnd_params_t params;
     181        ui_window_t *window = NULL;
    184182        gfx_context_t *gc;
    185183        gfx_rect_t rect;
     
    194192        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    195193        PCUT_ASSERT_NOT_NULL(window);
    196 
    197         res = ui_window_get_res(window);
    198         PCUT_ASSERT_NOT_NULL(res);
    199194
    200195        gc = ui_window_get_gc(window);
Note: See TracChangeset for help on using the changeset viewer.