Changeset 946a666 in mainline


Ignore:
Timestamp:
2020-01-17T15:40:43Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c79545e
Parents:
a40ae0d
git-author:
Jiri Svoboda <jiri@…> (2020-01-16 18:38:00)
git-committer:
Jiri Svoboda <jiri@…> (2020-01-17 15:40:43)
Message:

Backbuffer for repainting a window

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

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/types/display/window.h

    ra40ae0d r946a666  
    4141#include <gfx/context.h>
    4242#include <gfx/coord.h>
     43#include <io/pixelmap.h>
    4344
    4445typedef sysarg_t ds_wnd_id_t;
     
    7071        /** Graphic context */
    7172        gfx_context_t *gc;
     73        /** Bitmap in the display device */
     74        gfx_bitmap_t *bitmap;
     75        /** Pixel map for accessing the window bitmap */
     76        pixelmap_t pixelmap;
     77        /** Current drawing color */
     78        pixel_t color;
    7279
    7380        /** State */
  • uspace/srv/hid/display/window.c

    ra40ae0d r946a666  
    4242#include <gfx/render.h>
    4343#include <io/log.h>
     44#include <io/pixelmap.h>
    4445#include <stdlib.h>
    4546#include "client.h"
     
    7677{
    7778        ds_window_t *wnd = (ds_window_t *) arg;
     79        uint16_t r, g, b;
    7880
    7981        log_msg(LOG_DEFAULT, LVL_NOTE, "gc_set_color gc=%p",
    8082            ds_display_get_gc(wnd->display));
     83
     84        gfx_color_get_rgb_i16(color, &r, &g, &b);
     85        wnd->color = PIXEL(0, r >> 8, g >> 8, b >> 8);
     86
    8187        return gfx_set_color(ds_display_get_gc(wnd->display), color);
    8288}
     
    94100        gfx_rect_t crect;
    95101        gfx_rect_t drect;
     102        gfx_coord_t x, y;
    96103
    97104        log_msg(LOG_DEFAULT, LVL_NOTE, "gc_fill_rect");
     105
    98106        gfx_rect_clip(rect, &wnd->rect, &crect);
    99107        gfx_rect_translate(&wnd->dpos, &crect, &drect);
     108
     109        /* Render a copy to the backbuffer */
     110        for (y = crect.p0.y; y < crect.p1.y; y++) {
     111                for (x = crect.p0.x; x < crect.p1.x; x++) {
     112                        pixelmap_put_pixel(&wnd->pixelmap, x - wnd->rect.p0.x,
     113                            y - wnd->rect.p0.y, wnd->color);
     114                }
     115        }
     116
    100117        return gfx_fill_rect(ds_display_get_gc(wnd->display), &drect);
    101118}
    102119
    103 /** Create bitmap in canvas GC.
    104  *
    105  * @param arg Canvas GC
     120/** Create bitmap in window GC.
     121 *
     122 * @param arg Window GC
    106123 * @param params Bitmap params
    107124 * @param alloc Bitmap allocation info or @c NULL
     
    135152}
    136153
    137 /** Destroy bitmap in canvas GC.
     154/** Destroy bitmap in window GC.
    138155 *
    139156 * @param bm Bitmap
     
    149166}
    150167
    151 /** Render bitmap in canvas GC.
     168/** Render bitmap in window GC.
    152169 *
    153170 * @param bm Bitmap
     
    165182        gfx_rect_t swrect;
    166183        gfx_rect_t crect;
     184        gfx_coord_t x, y;
     185        pixelmap_t pixelmap;
     186        gfx_bitmap_alloc_t alloc;
     187        pixel_t pixel;
     188        errno_t rc;
    167189
    168190        if (srect0 != NULL) {
     
    190212        gfx_coord2_add(&cbm->wnd->dpos, &offs, &doffs);
    191213
    192         return gfx_bitmap_render(cbm->bitmap, srect0, &doffs);
    193 }
    194 
    195 /** Get allocation info for bitmap in canvas GC.
     214        rc = gfx_bitmap_get_alloc(cbm->bitmap, &alloc);
     215        if (rc != EOK)
     216                return rc;
     217
     218        pixelmap.width = cbm->rect.p1.x - cbm->rect.p0.x;
     219        pixelmap.height = cbm->rect.p1.y - cbm->rect.p0.y;
     220        pixelmap.data = alloc.pixels;
     221
     222        /* Render a copy to the backbuffer */
     223        for (y = crect.p0.y; y < crect.p1.y; y++) {
     224                for (x = crect.p0.x; x < crect.p1.x; x++) {
     225                        pixel = pixelmap_get_pixel(&pixelmap,
     226                            x - cbm->rect.p0.x, y - cbm->rect.p0.y);
     227                        pixelmap_put_pixel(&cbm->wnd->pixelmap,
     228                            x + offs.x - cbm->rect.p0.x + cbm->wnd->rect.p0.x,
     229                            y + offs.y - cbm->rect.p0.y + cbm->wnd->rect.p0.y,
     230                            pixel);
     231                }
     232        }
     233
     234        return gfx_bitmap_render(cbm->bitmap, &crect, &doffs);
     235}
     236
     237/** Get allocation info for bitmap in window GC.
    196238 *
    197239 * @param bm Bitmap
     
    221263        ds_window_t *wnd = NULL;
    222264        gfx_context_t *gc = NULL;
     265        gfx_context_t *dgc;
     266        gfx_rect_t rect;
     267        gfx_coord2_t dims;
     268        gfx_bitmap_params_t bparams;
     269        gfx_bitmap_alloc_t alloc;
    223270        errno_t rc;
    224271
     
    235282        ds_client_add_window(client, wnd);
    236283        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);
     287
     288        bparams.rect = params->rect;
     289
     290        dgc = ds_display_get_gc(wnd->display); // XXX
     291        if (dgc != NULL) {
     292                rc = gfx_bitmap_create(dgc, &bparams, NULL, &wnd->bitmap);
     293                if (rc != EOK)
     294                        goto error;
     295
     296                rc = gfx_bitmap_get_alloc(wnd->bitmap, &alloc);
     297                if (rc != EOK)
     298                        goto error;
     299
     300                wnd->pixelmap.width = dims.x;
     301                wnd->pixelmap.height = dims.y;
     302                wnd->pixelmap.data = alloc.pixels;
     303        }
     304
     305        if (wnd->pixelmap.data == NULL) {
     306                rc = ENOMEM;
     307                goto error;
     308        }
    237309
    238310        wnd->rect = params->rect;
     
    241313        return EOK;
    242314error:
    243         if (wnd != NULL)
     315        if (wnd != NULL) {
     316                if (wnd->bitmap != NULL)
     317                        gfx_bitmap_destroy(wnd->bitmap);
    244318                free(wnd);
     319        }
     320
    245321        gfx_context_delete(gc);
    246322        return rc;
     
    256332        ds_display_remove_window(wnd);
    257333        (void) gfx_context_delete(wnd->gc);
     334        if (wnd->bitmap != NULL)
     335                gfx_bitmap_destroy(wnd->bitmap);
    258336
    259337        free(wnd);
     
    268346{
    269347        return wnd->gc;
     348}
     349
     350/** Repaint a window using its backing bitmap.
     351 *
     352 * @param wnd Window to repaint
     353 * @return EOK on success or an error code
     354 */
     355static errno_t ds_window_repaint(ds_window_t *wnd)
     356{
     357        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_start_repaint");
     358        return gfx_bitmap_render(wnd->bitmap, NULL, &wnd->dpos);
    270359}
    271360
     
    309398        wnd->dpos = nwpos;
    310399        wnd->state = dsw_idle;
     400
     401        (void) ds_window_repaint(wnd);
    311402}
    312403
     
    343434        gc = ds_display_get_gc(wnd->display); // XXX
    344435        if (gc != NULL) {
    345                 gfx_set_color(ds_display_get_gc(wnd->display), color);
    346                 gfx_fill_rect(ds_display_get_gc(wnd->display), &drect);
     436                gfx_set_color(gc, color);
     437                gfx_fill_rect(gc, &drect);
    347438        }
    348439
Note: See TracChangeset for help on using the changeset viewer.