Changeset afcf704 in mainline for uspace/lib/memgfx/src/memgc.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/memgfx/src/memgc.c

    r28f8f6f2 rafcf704  
    3737 */
    3838
     39#include <as.h>
    3940#include <assert.h>
    4041#include <gfx/color.h>
     
    223224        errno_t rc;
    224225
     226        /* Check that we support all requested flags */
     227        if ((params->flags & ~(bmpf_color_key | bmpf_direct_output)) != 0)
     228                return ENOTSUP;
     229
    225230        mbm = calloc(1, sizeof(mem_gc_bitmap_t));
    226231        if (mbm == NULL)
     
    232237        mbm->key_color = params->key_color;
    233238
    234         if (alloc == NULL) {
     239        if ((params->flags & bmpf_direct_output) != 0) {
     240                /* Caller cannot specify allocation for direct output */
     241                if (alloc != NULL) {
     242                        rc = EINVAL;
     243                        goto error;
     244                }
     245
     246                /* Bounding rectangle must be within GC bounding rectangle */
     247                if (!gfx_rect_is_inside(&mbm->rect, &mgc->rect)) {
     248                        rc = EINVAL;
     249                        goto error;
     250                }
     251
     252                mbm->alloc = mgc->alloc;
     253
     254                /* Don't free pixel array when destroying bitmap */
     255                mbm->myalloc = false;
     256        } else if (alloc == NULL) {
     257#if 0
     258                /*
     259                 * TODO: If the bitmap is not required to be sharable,
     260                 * we could allocate it with a simple malloc.
     261                 * Need to have a bitmap flag specifying that the
     262                 * allocation should be sharable. IPC GC could
     263                 * automatically add this flag
     264                 */
    235265                mbm->alloc.pitch = dim.x * sizeof(uint32_t);
    236266                mbm->alloc.off0 = 0;
     
    242272                        goto error;
    243273                }
     274#endif
     275                mbm->alloc.pitch = dim.x * sizeof(uint32_t);
     276                mbm->alloc.off0 = 0;
     277                mbm->alloc.pixels = as_area_create(AS_AREA_ANY,
     278                    dim.x * dim.y * sizeof(uint32_t), AS_AREA_READ |
     279                    AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
     280                mbm->myalloc = true;
     281
     282                if (mbm->alloc.pixels == AS_MAP_FAILED) {
     283                        rc = ENOMEM;
     284                        goto error;
     285                }
    244286        } else {
    245287                mbm->alloc = *alloc;
     
    263305{
    264306        mem_gc_bitmap_t *mbm = (mem_gc_bitmap_t *)bm;
    265         if (mbm->myalloc)
     307        if (mbm->myalloc) {
     308#if 0
     309                /* TODO: if we alloc allocating the bitmap with malloc */
    266310                free(mbm->alloc.pixels);
     311#endif
     312                as_area_destroy(mbm->alloc.pixels);
     313        }
    267314
    268315        free(mbm);
     
    317364        dmap.data = mbm->mgc->alloc.pixels;
    318365
    319         if ((mbm->flags & bmpf_color_key) == 0) {
     366        if ((mbm->flags & bmpf_direct_output) != 0) {
     367                /* Nothing to do */
     368        } else if ((mbm->flags & bmpf_color_key) == 0) {
    320369                for (y = drect.p0.y; y < drect.p1.y; y++) {
    321370                        for (x = drect.p0.x; x < drect.p1.x; x++) {
Note: See TracChangeset for help on using the changeset viewer.