Changeset afcf704 in mainline for uspace/lib/ipcgfx/src


Ignore:
Timestamp:
2020-06-14T22:23:34Z (5 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

Location:
uspace/lib/ipcgfx/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ipcgfx/src/client.c

    r28f8f6f2 rafcf704  
    108108}
    109109
    110 /** Create bitmap in IPC GC.
     110/** Create normal bitmap in IPC GC.
    111111 *
    112112 * @param arg IPC GC
     
    116116 * @return EOK on success or an error code
    117117 */
    118 errno_t ipc_gc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     118static errno_t ipc_gc_bitmap_create_normal(void *arg,
     119    gfx_bitmap_params_t *params,
    119120    gfx_bitmap_alloc_t *alloc, void **rbm)
    120121{
     
    209210}
    210211
     212/** Create direct output bitmap in IPC GC.
     213 *
     214 * @param arg IPC GC
     215 * @param params Bitmap params
     216 * @param alloc Bitmap allocation info or @c NULL
     217 * @param rbm Place to store pointer to new bitmap
     218 * @return EOK on success or an error code
     219 */
     220static errno_t ipc_gc_bitmap_create_direct_output(void *arg,
     221    gfx_bitmap_params_t *params,
     222    gfx_bitmap_alloc_t *alloc, void **rbm)
     223{
     224        ipc_gc_t *ipcgc = (ipc_gc_t *) arg;
     225        ipc_gc_bitmap_t *ipcbm = NULL;
     226        gfx_coord2_t dim;
     227        async_exch_t *exch = NULL;
     228        void *pixels;
     229        ipc_call_t answer;
     230        size_t asize;
     231        aid_t req;
     232        errno_t rc;
     233
     234        /* Cannot specify allocation for direct output bitmap */
     235        if (alloc != NULL)
     236                return EINVAL;
     237
     238        ipcbm = calloc(1, sizeof(ipc_gc_bitmap_t));
     239        if (ipcbm == NULL)
     240                return ENOMEM;
     241
     242        gfx_coord2_subtract(&params->rect.p1, &params->rect.p0, &dim);
     243        ipcbm->rect = params->rect;
     244
     245        ipcbm->alloc.pitch = dim.x * sizeof(uint32_t);
     246        ipcbm->alloc.off0 = 0;
     247        ipcbm->myalloc = true;
     248
     249        asize = PAGES2SIZE(SIZE2PAGES(ipcbm->alloc.pitch * dim.y));
     250
     251        exch = async_exchange_begin(ipcgc->sess);
     252        req = async_send_0(exch, GC_BITMAP_CREATE_DOUTPUT, &answer);
     253        rc = async_data_write_start(exch, params, sizeof (gfx_bitmap_params_t));
     254        if (rc != EOK) {
     255                async_forget(req);
     256                goto error;
     257        }
     258
     259        rc = async_share_in_start_0_0(exch, asize, &pixels);
     260        if (rc != EOK) {
     261                async_forget(req);
     262                goto error;
     263        }
     264        async_exchange_end(exch);
     265        exch = NULL;
     266
     267        async_wait_for(req, &rc);
     268        if (rc != EOK)
     269                goto error;
     270
     271        ipcbm->ipcgc = ipcgc;
     272        ipcbm->bmp_id = ipc_get_arg1(&answer);
     273        ipcbm->alloc.pixels = pixels;
     274        *rbm = (void *)ipcbm;
     275        return EOK;
     276error:
     277        if (exch != NULL)
     278                async_exchange_end(exch);
     279        if (ipcbm != NULL) {
     280                if (ipcbm->alloc.pixels != NULL)
     281                        as_area_destroy(ipcbm->alloc.pixels);
     282                free(ipcbm);
     283        }
     284        return rc;
     285}
     286
     287/** Create bitmap in IPC GC.
     288 *
     289 * @param arg IPC GC
     290 * @param params Bitmap params
     291 * @param alloc Bitmap allocation info or @c NULL
     292 * @param rbm Place to store pointer to new bitmap
     293 * @return EOK on success or an error code
     294 */
     295errno_t ipc_gc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     296    gfx_bitmap_alloc_t *alloc, void **rbm)
     297{
     298        if ((params->flags & bmpf_direct_output) != 0) {
     299                return ipc_gc_bitmap_create_direct_output(arg, params, alloc,
     300                    rbm);
     301        } else {
     302                return ipc_gc_bitmap_create_normal(arg, params, alloc, rbm);
     303        }
     304}
     305
    211306/** Destroy bitmap in IPC GC.
    212307 *
  • uspace/lib/ipcgfx/src/server.c

    r28f8f6f2 rafcf704  
    128128        /* Check size */
    129129        if (size != PAGES2SIZE(SIZE2PAGES(dim.x * dim.y * sizeof(uint32_t)))) {
    130                 printf("size=%zu, expected=%zu\n", size, dim.x * dim.y * sizeof(uint32_t));
    131130                async_answer_0(icall, EINVAL);
    132131                return;
     
    168167}
    169168
     169static void gc_bitmap_create_doutput_srv(ipc_gc_srv_t *srvgc, ipc_call_t *icall)
     170{
     171        gfx_bitmap_params_t params;
     172        gfx_bitmap_alloc_t alloc;
     173        gfx_bitmap_t *bitmap;
     174        gfx_coord2_t dim;
     175        ipc_gc_srv_bitmap_t *srvbmp = NULL;
     176        ipc_call_t call;
     177        size_t size;
     178        errno_t rc;
     179
     180        if (!async_data_write_receive(&call, &size)) {
     181                async_answer_0(&call, EREFUSED);
     182                async_answer_0(icall, EREFUSED);
     183                return;
     184        }
     185
     186        if (size != sizeof(gfx_bitmap_params_t)) {
     187                async_answer_0(&call, EINVAL);
     188                async_answer_0(icall, EINVAL);
     189                return;
     190        }
     191
     192        rc = async_data_write_finalize(&call, &params, size);
     193        if (rc != EOK) {
     194                async_answer_0(&call, rc);
     195                async_answer_0(icall, rc);
     196                return;
     197        }
     198
     199        /* Bitmap dimensions */
     200        gfx_coord2_subtract(&params.rect.p1, &params.rect.p0, &dim);
     201
     202        if (!async_share_in_receive(&call, &size)) {
     203                async_answer_0(icall, EINVAL);
     204                return;
     205        }
     206
     207        /* Check size */
     208        if (size != PAGES2SIZE(SIZE2PAGES(dim.x * dim.y * sizeof(uint32_t)))) {
     209                async_answer_0(&call, EINVAL);
     210                async_answer_0(icall, EINVAL);
     211                return;
     212        }
     213
     214        rc = gfx_bitmap_create(srvgc->gc, &params, NULL, &bitmap);
     215        if (rc != EOK) {
     216                async_answer_0(&call, rc);
     217                async_answer_0(icall, rc);
     218                return;
     219        }
     220
     221        rc = gfx_bitmap_get_alloc(bitmap, &alloc);
     222        if (rc != EOK) {
     223                gfx_bitmap_destroy(bitmap);
     224                async_answer_0(&call, rc);
     225                async_answer_0(icall, rc);
     226                return;
     227        }
     228
     229        rc = async_share_in_finalize(&call, alloc.pixels, AS_AREA_READ |
     230            AS_AREA_WRITE | AS_AREA_CACHEABLE);
     231        if (rc != EOK) {
     232                gfx_bitmap_destroy(bitmap);
     233                async_answer_0(icall, EIO);
     234                return;
     235        }
     236
     237        srvbmp = calloc(1, sizeof(ipc_gc_srv_bitmap_t));
     238        if (srvbmp == NULL) {
     239                gfx_bitmap_destroy(bitmap);
     240                async_answer_0(icall, ENOMEM);
     241                return;
     242        }
     243
     244        srvbmp->srvgc = srvgc;
     245        list_append(&srvbmp->lbitmaps, &srvgc->bitmaps);
     246        srvbmp->bmp = bitmap;
     247        srvbmp->bmp_id = srvgc->next_bmp_id++;
     248        printf("gc_bitmap_create_doutput_srv: storing bmp_id=%u\n",
     249            (unsigned) srvbmp->bmp_id);
     250
     251        async_answer_1(icall, EOK, srvbmp->bmp_id);
     252}
     253
    170254static void gc_bitmap_destroy_srv(ipc_gc_srv_t *srvgc, ipc_call_t *call)
    171255{
     
    270354                        gc_bitmap_create_srv(&srvgc, &call);
    271355                        break;
     356                case GC_BITMAP_CREATE_DOUTPUT:
     357                        gc_bitmap_create_doutput_srv(&srvgc, &call);
     358                        break;
    272359                case GC_BITMAP_DESTROY:
    273360                        gc_bitmap_destroy_srv(&srvgc, &call);
Note: See TracChangeset for help on using the changeset viewer.