Changeset 0008c0f in mainline for uspace/lib/ipcgfx/src/client.c


Ignore:
Timestamp:
2019-10-26T23:30:51Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
587b4cb
Parents:
7b882c1f
Message:

Bitmaps in IPC GC and in display server

File:
1 edited

Legend:

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

    r7b882c1f r0008c0f  
    3636 */
    3737
     38#include <as.h>
    3839#include <ipcgfx/client.h>
    3940#include <ipcgfx/ipc/gc.h>
    4041#include <gfx/color.h>
     42#include <gfx/coord.h>
    4143#include <gfx/context.h>
    4244#include <stdlib.h>
     
    4547static errno_t ipc_gc_set_color(void *, gfx_color_t *);
    4648static errno_t ipc_gc_fill_rect(void *, gfx_rect_t *);
     49static errno_t ipc_gc_bitmap_create(void *, gfx_bitmap_params_t *,
     50    gfx_bitmap_alloc_t *, void **);
     51static errno_t ipc_gc_bitmap_destroy(void *);
     52static errno_t ipc_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
     53static errno_t ipc_gc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    4754
    4855gfx_context_ops_t ipc_gc_ops = {
    4956        .set_color = ipc_gc_set_color,
    50         .fill_rect = ipc_gc_fill_rect
     57        .fill_rect = ipc_gc_fill_rect,
     58        .bitmap_create = ipc_gc_bitmap_create,
     59        .bitmap_destroy = ipc_gc_bitmap_destroy,
     60        .bitmap_render = ipc_gc_bitmap_render,
     61        .bitmap_get_alloc = ipc_gc_bitmap_get_alloc
    5162};
    5263
     
    101112}
    102113
     114/** Create bitmap in IPC GC.
     115 *
     116 * @param arg IPC GC
     117 * @param params Bitmap params
     118 * @param alloc Bitmap allocation info or @c NULL
     119 * @param rbm Place to store pointer to new bitmap
     120 * @return EOK on success or an error code
     121 */
     122errno_t ipc_gc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     123    gfx_bitmap_alloc_t *alloc, void **rbm)
     124{
     125        ipc_gc_t *ipcgc = (ipc_gc_t *) arg;
     126        ipc_gc_bitmap_t *ipcbm = NULL;
     127        gfx_coord2_t dim;
     128        async_exch_t *exch = NULL;
     129        ipc_call_t answer;
     130        aid_t req;
     131        errno_t rc;
     132
     133        ipcbm = calloc(1, sizeof(ipc_gc_bitmap_t));
     134        if (ipcbm == NULL)
     135                return ENOMEM;
     136
     137        gfx_coord2_subtract(&params->rect.p1, &params->rect.p0, &dim);
     138        ipcbm->rect = params->rect;
     139
     140        if (alloc == NULL) {
     141                ipcbm->alloc.pitch = dim.x * sizeof(uint32_t);
     142                ipcbm->alloc.off0 = 0;
     143                ipcbm->alloc.pixels = as_area_create(AS_AREA_ANY,
     144                    dim.x * dim.y * sizeof(uint32_t), AS_AREA_READ |
     145                    AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
     146                if (ipcbm->alloc.pixels == NULL) {
     147                        rc = ENOMEM;
     148                        goto error;
     149                }
     150
     151                ipcbm->myalloc = true;
     152        } else {
     153                /*
     154                 * XXX We could allow this if the pixels point to a shareable
     155                 * area or we could do a copy of the data when rendering
     156                 */
     157                rc = ENOTSUP;
     158                goto error;
     159        }
     160
     161        exch = async_exchange_begin(ipcgc->sess);
     162        req = async_send_0(exch, GC_BITMAP_CREATE, &answer);
     163        rc = async_data_write_start(exch, params, sizeof (gfx_bitmap_params_t));
     164        if (rc != EOK) {
     165                async_forget(req);
     166                goto error;
     167        }
     168
     169        rc = async_share_out_start(exch, ipcbm->alloc.pixels,
     170            AS_AREA_READ | AS_AREA_CACHEABLE);
     171        if (rc != EOK) {
     172                async_forget(req);
     173                goto error;
     174        }
     175        async_exchange_end(exch);
     176        exch = NULL;
     177
     178        async_wait_for(req, &rc);
     179        if (rc != EOK)
     180                goto error;
     181
     182        ipcbm->ipcgc = ipcgc;
     183        ipcbm->bmp_id = ipc_get_arg1(&answer);
     184        *rbm = (void *)ipcbm;
     185        return EOK;
     186error:
     187        if (exch != NULL)
     188                async_exchange_end(exch);
     189        if (ipcbm != NULL) {
     190                if (ipcbm->alloc.pixels != NULL)
     191                        as_area_destroy(ipcbm->alloc.pixels);
     192                free(ipcbm);
     193        }
     194        return rc;
     195}
     196
     197/** Destroy bitmap in IPC GC.
     198 *
     199 * @param bm Bitmap
     200 * @return EOK on success or an error code
     201 */
     202static errno_t ipc_gc_bitmap_destroy(void *bm)
     203{
     204        ipc_gc_bitmap_t *ipcbm = (ipc_gc_bitmap_t *)bm;
     205        async_exch_t *exch;
     206        errno_t rc;
     207
     208        printf("ipc_gc_bitmap_destroy\n");
     209
     210        exch = async_exchange_begin(ipcbm->ipcgc->sess);
     211        rc = async_req_1_0(exch, GC_BITMAP_DESTROY, ipcbm->bmp_id);
     212        async_exchange_end(exch);
     213
     214        if (rc != EOK)
     215                return rc;
     216
     217        if (ipcbm->myalloc)
     218                as_area_destroy(ipcbm->alloc.pixels);
     219        free(ipcbm);
     220        return EOK;
     221}
     222
     223/** Render bitmap in IPC GC.
     224 *
     225 * @param bm Bitmap
     226 * @param srect0 Source rectangle or @c NULL
     227 * @param offs0 Offset or @c NULL
     228 * @return EOK on success or an error code
     229 */
     230static errno_t ipc_gc_bitmap_render(void *bm, gfx_rect_t *srect0,
     231    gfx_coord2_t *offs0)
     232{
     233        ipc_gc_bitmap_t *ipcbm = (ipc_gc_bitmap_t *)bm;
     234        gfx_rect_t srect;
     235        gfx_rect_t drect;
     236        gfx_coord2_t offs;
     237        async_exch_t *exch = NULL;
     238        ipc_call_t answer;
     239        aid_t req;
     240        errno_t rc;
     241
     242        if (srect0 != NULL)
     243                srect = *srect0;
     244        else
     245                srect = ipcbm->rect;
     246
     247        if (offs0 != NULL) {
     248                offs = *offs0;
     249        } else {
     250                offs.x = 0;
     251                offs.y = 0;
     252        }
     253
     254        /* Destination rectangle */
     255        gfx_rect_translate(&offs, &srect, &drect);
     256
     257        exch = async_exchange_begin(ipcbm->ipcgc->sess);
     258        req = async_send_3(exch, GC_BITMAP_RENDER, ipcbm->bmp_id, offs.x,
     259            offs.y, &answer);
     260
     261        rc = async_data_write_start(exch, &srect, sizeof (gfx_rect_t));
     262        if (rc != EOK) {
     263                async_forget(req);
     264                goto error;
     265        }
     266
     267        async_exchange_end(exch);
     268        exch = NULL;
     269
     270        async_wait_for(req, &rc);
     271        if (rc != EOK)
     272                goto error;
     273
     274        return EOK;
     275error:
     276        if (exch != NULL)
     277                async_exchange_end(exch);
     278        return rc;
     279}
     280
     281/** Get allocation info for bitmap in IPC GC.
     282 *
     283 * @param bm Bitmap
     284 * @param alloc Place to store allocation info
     285 * @return EOK on success or an error code
     286 */
     287static errno_t ipc_gc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     288{
     289        ipc_gc_bitmap_t *ipcbm = (ipc_gc_bitmap_t *)bm;
     290        *alloc = ipcbm->alloc;
     291        return EOK;
     292}
     293
    103294/** Create IPC GC.
    104295 *
Note: See TracChangeset for help on using the changeset viewer.