Changeset afcf704 in mainline for uspace/lib/ipcgfx/test/ipcgfx.c


Ignore:
Timestamp:
2020-06-14T22:23:34Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c45d8696
Parents:
28f8f6f2
Message:

Allow GUI direct access to window buffer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ipcgfx/test/ipcgfx.c

    r28f8f6f2 rafcf704  
    2727 */
    2828
     29#include <as.h>
    2930#include <async.h>
    3031#include <errno.h>
     
    9697typedef struct {
    9798        test_response_t *resp;
     99        gfx_bitmap_alloc_t alloc;
    98100} test_bitmap_t;
    99101
     
    474476}
    475477
     478/** gfx_bitmap_create direct output bitmap with server returning failure */
     479PCUT_TEST(bitmap_create_dout_failure)
     480{
     481        errno_t rc;
     482        service_id_t sid;
     483        test_response_t resp;
     484        gfx_context_t *gc;
     485        gfx_bitmap_params_t params;
     486        gfx_bitmap_t *bitmap;
     487        async_sess_t *sess;
     488        ipc_gc_t *ipcgc;
     489
     490        async_set_fallback_port_handler(test_ipcgc_conn, &resp);
     491
     492        // FIXME This causes this test to be non-reentrant!
     493        rc = loc_server_register(test_ipcgfx_server);
     494        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     495
     496        rc = loc_service_register(test_ipcgfx_svc, &sid);
     497        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     498
     499        sess = loc_service_connect(sid, INTERFACE_GC, 0);
     500        PCUT_ASSERT_NOT_NULL(sess);
     501
     502        rc = ipc_gc_create(sess, &ipcgc);
     503        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     504
     505        gc = ipc_gc_get_ctx(ipcgc);
     506        PCUT_ASSERT_NOT_NULL(gc);
     507
     508        resp.rc = ENOMEM;
     509        resp.bitmap_create_called = false;
     510
     511        gfx_bitmap_params_init(&params);
     512        params.flags = bmpf_direct_output;
     513        params.rect.p0.x = 1;
     514        params.rect.p0.y = 2;
     515        params.rect.p1.x = 3;
     516        params.rect.p1.y = 4;
     517        bitmap = NULL;
     518        rc = gfx_bitmap_create(gc, &params, NULL, &bitmap);
     519        PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
     520        PCUT_ASSERT_TRUE(resp.bitmap_create_called);
     521        PCUT_ASSERT_EQUALS(params.rect.p0.x, resp.bitmap_create_params.rect.p0.x);
     522        PCUT_ASSERT_EQUALS(params.rect.p0.y, resp.bitmap_create_params.rect.p0.y);
     523        PCUT_ASSERT_EQUALS(params.rect.p1.x, resp.bitmap_create_params.rect.p1.x);
     524        PCUT_ASSERT_EQUALS(params.rect.p1.y, resp.bitmap_create_params.rect.p1.y);
     525        PCUT_ASSERT_EQUALS((params.rect.p1.x - params.rect.p0.x) *
     526            sizeof(uint32_t), (unsigned) resp.bitmap_create_alloc.pitch);
     527        PCUT_ASSERT_EQUALS(0, resp.bitmap_create_alloc.off0);
     528        PCUT_ASSERT_NOT_NULL(resp.bitmap_create_alloc.pixels);
     529        PCUT_ASSERT_NULL(bitmap);
     530
     531        ipc_gc_delete(ipcgc);
     532        async_hangup(sess);
     533
     534        rc = loc_service_unregister(sid);
     535        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     536}
     537
     538/** gfx_bitmap_create direct output bitmap with server returning success */
     539PCUT_TEST(bitmap_create_dout_success)
     540{
     541        errno_t rc;
     542        service_id_t sid;
     543        test_response_t resp;
     544        gfx_context_t *gc;
     545        gfx_bitmap_params_t params;
     546        gfx_bitmap_t *bitmap;
     547        async_sess_t *sess;
     548        ipc_gc_t *ipcgc;
     549
     550        async_set_fallback_port_handler(test_ipcgc_conn, &resp);
     551
     552        // FIXME This causes this test to be non-reentrant!
     553        rc = loc_server_register(test_ipcgfx_server);
     554        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     555
     556        rc = loc_service_register(test_ipcgfx_svc, &sid);
     557        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     558
     559        sess = loc_service_connect(sid, INTERFACE_GC, 0);
     560        PCUT_ASSERT_NOT_NULL(sess);
     561
     562        rc = ipc_gc_create(sess, &ipcgc);
     563        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     564
     565        gc = ipc_gc_get_ctx(ipcgc);
     566        PCUT_ASSERT_NOT_NULL(gc);
     567
     568        resp.rc = EOK;
     569        resp.bitmap_create_called = false;
     570
     571        gfx_bitmap_params_init(&params);
     572        params.flags = bmpf_direct_output;
     573        params.rect.p0.x = 1;
     574        params.rect.p0.y = 2;
     575        params.rect.p1.x = 3;
     576        params.rect.p1.y = 4;
     577        bitmap = NULL;
     578        rc = gfx_bitmap_create(gc, &params, NULL, &bitmap);
     579        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     580        PCUT_ASSERT_TRUE(resp.bitmap_create_called);
     581        PCUT_ASSERT_EQUALS(params.rect.p0.x, resp.bitmap_create_params.rect.p0.x);
     582        PCUT_ASSERT_EQUALS(params.rect.p0.y, resp.bitmap_create_params.rect.p0.y);
     583        PCUT_ASSERT_EQUALS(params.rect.p1.x, resp.bitmap_create_params.rect.p1.x);
     584        PCUT_ASSERT_EQUALS(params.rect.p1.y, resp.bitmap_create_params.rect.p1.y);
     585        PCUT_ASSERT_EQUALS((params.rect.p1.x - params.rect.p0.x) *
     586            sizeof(uint32_t), (unsigned) resp.bitmap_create_alloc.pitch);
     587        PCUT_ASSERT_EQUALS(0, resp.bitmap_create_alloc.off0);
     588        PCUT_ASSERT_NOT_NULL(resp.bitmap_create_alloc.pixels);
     589        PCUT_ASSERT_NOT_NULL(bitmap);
     590
     591        resp.bitmap_destroy_called = false;
     592        rc = gfx_bitmap_destroy(bitmap);
     593        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     594        PCUT_ASSERT_TRUE(resp.bitmap_destroy_called);
     595
     596        ipc_gc_delete(ipcgc);
     597        async_hangup(sess);
     598
     599        rc = loc_service_unregister(sid);
     600        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     601}
     602
    476603/** gfx_bitmap_render with server returning failure */
    477604PCUT_TEST(bitmap_render_failure)
     
    733860        test_response_t *resp = (test_response_t *) arg;
    734861        test_bitmap_t *bitmap;
     862        gfx_coord2_t dim;
    735863
    736864        resp->bitmap_create_called = true;
    737865        resp->bitmap_create_params = *params;
    738         resp->bitmap_create_alloc = *alloc;
     866
     867        if ((params->flags & bmpf_direct_output) != 0) {
     868                gfx_coord2_subtract(&params->rect.p1, &params->rect.p0, &dim);
     869
     870                resp->bitmap_create_alloc.pitch = dim.x * sizeof(uint32_t);
     871                resp->bitmap_create_alloc.off0 = 0;
     872                resp->bitmap_create_alloc.pixels = as_area_create(AS_AREA_ANY,
     873                    dim.x * dim.y * sizeof(uint32_t), AS_AREA_READ |
     874                    AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
     875                if (resp->bitmap_create_alloc.pixels == AS_MAP_FAILED)
     876                        return ENOMEM;
     877        } else {
     878                resp->bitmap_create_alloc = *alloc;
     879        }
    739880
    740881        if (resp->rc != EOK)
     
    746887
    747888        bitmap->resp = resp;
     889        bitmap->alloc = resp->bitmap_create_alloc;
    748890        *rbm = (void *) bitmap;
    749891        return EOK;
     
    763905        if (resp->rc != EOK)
    764906                return resp->rc;
     907
     908        if ((resp->bitmap_create_params.flags & bmpf_direct_output) != 0)
     909                as_area_destroy(resp->bitmap_create_alloc.pixels);
    765910
    766911        free(bitmap);
     
    795940static errno_t test_gc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    796941{
    797         /* Currently IPC GC does not pass this method to the server */
    798         return ENOTSUP;
     942        test_bitmap_t *bitmap = (test_bitmap_t *) bm;
     943
     944        *alloc = bitmap->alloc;
     945        return EOK;
    799946}
    800947
Note: See TracChangeset for help on using the changeset viewer.