Changeset 0e6e77f in mainline for uspace/srv


Ignore:
Timestamp:
2020-02-28T15:44:55Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a8eed5f
Parents:
2a515dcd
git-author:
Jiri Svoboda <jiri@…> (2020-02-26 18:26:13)
git-committer:
Jiri Svoboda <jiri@…> (2020-02-28 15:44:55)
Message:

Window resize by client request

Location:
uspace/srv/hid/display
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/dsops.c

    r2a515dcd r0e6e77f  
    3636#include <disp_srv.h>
    3737#include <errno.h>
     38#include <gfx/coord.h>
    3839#include <io/log.h>
    3940#include "client.h"
     
    4546static errno_t disp_window_create(void *, display_wnd_params_t *, sysarg_t *);
    4647static errno_t disp_window_destroy(void *, sysarg_t);
     48static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *,
     49    gfx_rect_t *);
    4750static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
    4851
     
    5053        .window_create = disp_window_create,
    5154        .window_destroy = disp_window_destroy,
     55        .window_resize = disp_window_resize,
    5256        .get_event = disp_get_event
    5357};
     
    98102}
    99103
     104static errno_t disp_window_resize(void *arg, sysarg_t wnd_id,
     105    gfx_coord2_t *offs, gfx_rect_t *nbound)
     106{
     107        ds_client_t *client = (ds_client_t *) arg;
     108        ds_window_t *wnd;
     109
     110        wnd = ds_client_find_window(client, wnd_id);
     111        if (wnd == NULL)
     112                return ENOENT;
     113
     114        log_msg(LOG_DEFAULT, LVL_NOTE, "disp_window_resize()");
     115        return ds_window_resize(wnd, offs, nbound);
     116}
     117
    100118static errno_t disp_get_event(void *arg, sysarg_t *wnd_id,
    101119    display_wnd_ev_t *event)
  • uspace/srv/hid/display/test/display.c

    r2a515dcd r0e6e77f  
    5353        printf("test_ds_ev_pending\n");
    5454        *called_cb = true;
    55 
    5655}
    5756
     
    265264        event.c = L'\0';
    266265
    267         PCUT_ASSERT_FALSE(called_cb);
     266        called_cb = false;
    268267
    269268        rc = ds_display_post_kbd_event(disp, &event);
     
    316315        event.c = L'\0';
    317316
    318         PCUT_ASSERT_FALSE(called_cb);
     317        called_cb = false;
    319318
    320319        rc = ds_display_post_kbd_event(disp, &event);
    321320        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    322         PCUT_ASSERT_FALSE(called_cb);
     321
     322        /* Got gocus/unfocus events */
     323        PCUT_ASSERT_TRUE(called_cb);
    323324
    324325        /* Next window should be focused */
    325326        PCUT_ASSERT_EQUALS(w1, seat->focus);
    326327
     328        called_cb = false;
     329
    327330        rc = ds_display_post_kbd_event(disp, &event);
    328331        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    329         PCUT_ASSERT_FALSE(called_cb);
     332
     333        /* Got gocus/unfocus events */
     334        PCUT_ASSERT_TRUE(called_cb);
    330335
    331336        /* Focus should be back to the first window */
     
    361366        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    362367
     368        /*
     369         * For PTD_MOVE to work we need to set display dimensions (as pointer
     370         * move is clipped to the display rectangle. Here we do it directly
     371         * instead of adding a display device.
     372         */
     373        disp->rect.p0.x = 0;
     374        disp->rect.p0.y = 0;
     375        disp->rect.p1.x = 500;
     376        disp->rect.p1.y = 500;
     377
    363378        display_wnd_params_init(&params);
    364379        params.rect.p0.x = params.rect.p0.y = 0;
  • uspace/srv/hid/display/test/window.c

    r2a515dcd r0e6e77f  
    4949        .fill_rect = dummy_fill_rect
    5050};
     51
     52/** Test ds_window_resize(). */
     53PCUT_TEST(window_resize)
     54{
     55        ds_display_t *disp;
     56        ds_client_t *client;
     57        ds_window_t *wnd;
     58        display_wnd_params_t params;
     59        gfx_coord2_t offs;
     60        gfx_rect_t nrect;
     61        errno_t rc;
     62
     63        rc = ds_display_create(NULL, &disp);
     64        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     65
     66        rc = ds_client_create(disp, NULL, NULL, &client);
     67        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     68
     69        display_wnd_params_init(&params);
     70        params.rect.p0.x = params.rect.p0.y = 0;
     71        params.rect.p1.x = params.rect.p1.y = 10;
     72
     73        rc = ds_window_create(client, &params, &wnd);
     74        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     75
     76        wnd->dpos.x = 100;
     77        wnd->dpos.y = 100;
     78
     79        offs.x = -2;
     80        offs.y = -3;
     81        params.rect.p0.x = params.rect.p0.y = 0;
     82        params.rect.p1.x = 12;
     83        params.rect.p1.y = 13;
     84        rc = ds_window_resize(wnd, &offs, &nrect);
     85        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     86
     87        PCUT_ASSERT_INT_EQUALS(98, wnd->dpos.x);
     88        PCUT_ASSERT_INT_EQUALS(97, wnd->dpos.y);
     89
     90        ds_window_destroy(wnd);
     91        ds_client_destroy(client);
     92        ds_display_destroy(disp);
     93}
    5194
    5295/** Test ds_window_get_ctx(). */
  • uspace/srv/hid/display/window.c

    r2a515dcd r0e6e77f  
    264264        gfx_context_t *gc = NULL;
    265265        gfx_context_t *dgc;
    266         gfx_rect_t rect;
    267266        gfx_coord2_t dims;
    268267        gfx_bitmap_params_t bparams;
     
    282281        ds_client_add_window(client, wnd);
    283282        ds_display_add_window(client->display, wnd);
    284 
    285         gfx_rect_points_sort(&params->rect, &rect);
    286         gfx_coord2_subtract(&rect.p1, &rect.p0, &dims);
    287283
    288284        bparams.rect = params->rect;
     
    298294                        goto error;
    299295
     296                gfx_rect_dims(&params->rect, &dims);
    300297                wnd->pixelmap.width = dims.x;
    301298                wnd->pixelmap.height = dims.y;
    302299                wnd->pixelmap.data = alloc.pixels;
    303 
    304                 if (wnd->pixelmap.data == NULL) {
    305                         rc = ENOMEM;
    306                         goto error;
    307                 }
    308300        }
    309301
     
    323315}
    324316
    325 /** Delete window GC.
    326  *
    327  * @param wnd Window GC
     317/** Destroy window.
     318 *
     319 * @param wnd Window
    328320 */
    329321void ds_window_destroy(ds_window_t *wnd)
     
    343335
    344336        (void) ds_display_paint(disp, NULL);
     337}
     338
     339/** Resize window.
     340 *
     341 * @param wnd Window
     342 */
     343errno_t ds_window_resize(ds_window_t *wnd, gfx_coord2_t *offs,
     344    gfx_rect_t *nrect)
     345{
     346        gfx_context_t *dgc;
     347        gfx_bitmap_params_t bparams;
     348        gfx_bitmap_t *nbitmap;
     349        pixelmap_t npixelmap;
     350        gfx_coord2_t dims;
     351        gfx_bitmap_alloc_t alloc;
     352        gfx_coord2_t ndpos;
     353        errno_t rc;
     354
     355        dgc = ds_display_get_gc(wnd->display); // XXX
     356        if (dgc != NULL) {
     357                bparams.rect = *nrect;
     358
     359                rc = gfx_bitmap_create(dgc, &bparams, NULL, &nbitmap);
     360                if (rc != EOK)
     361                        return ENOMEM;
     362
     363                rc = gfx_bitmap_get_alloc(nbitmap, &alloc);
     364                if (rc != EOK) {
     365                        gfx_bitmap_destroy(nbitmap);
     366                        return ENOMEM;
     367                }
     368
     369                gfx_rect_dims(nrect, &dims);
     370                npixelmap.width = dims.x;
     371                npixelmap.height = dims.y;
     372                npixelmap.data = alloc.pixels;
     373
     374                /* TODO: Transfer contents within overlap */
     375
     376                if (wnd->bitmap != NULL)
     377                        gfx_bitmap_destroy(wnd->bitmap);
     378
     379                wnd->bitmap = nbitmap;
     380                wnd->pixelmap = npixelmap;
     381        }
     382
     383        gfx_coord2_add(&wnd->dpos, offs, &ndpos);
     384
     385        wnd->dpos = ndpos;
     386        wnd->rect = *nrect;
     387
     388        (void) ds_display_paint(wnd->display, NULL);
     389        return EOK;
    345390}
    346391
  • uspace/srv/hid/display/window.h

    r2a515dcd r0e6e77f  
    5151    ds_window_t **);
    5252extern void ds_window_destroy(ds_window_t *);
     53extern errno_t ds_window_resize(ds_window_t *, gfx_coord2_t *, gfx_rect_t *);
    5354extern gfx_context_t *ds_window_get_ctx(ds_window_t *);
    5455extern errno_t ds_window_paint(ds_window_t *, gfx_rect_t *);
Note: See TracChangeset for help on using the changeset viewer.