Changeset 68a552f in mainline for uspace/lib/c


Ignore:
Timestamp:
2021-02-22T19:52:08Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
26853ebc
Parents:
2ab8ab3
Message:

Efficient way of rendering to the console via shared buffer

Makes congfx reasonably fast

Location:
uspace/lib/c
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/con_srv.c

    r2ab8ab3 r68a552f  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3434 * @brief Console protocol server stub
    3535 */
     36#include <as.h>
    3637#include <errno.h>
    3738#include <io/cons_event.h>
     
    307308}
    308309
     310/** Create shared buffer for efficient rendering */
     311static void con_map_srv(con_srv_t *srv, ipc_call_t *icall)
     312{
     313        errno_t rc;
     314        charfield_t *buf;
     315        sysarg_t cols, rows;
     316        ipc_call_t call;
     317        size_t size;
     318
     319        if (srv->srvs->ops->map == NULL || srv->srvs->ops->unmap == NULL) {
     320                async_answer_0(icall, ENOTSUP);
     321                return;
     322        }
     323
     324        cols = ipc_get_arg1(icall);
     325        rows = ipc_get_arg2(icall);
     326
     327        if (!async_share_in_receive(&call, &size)) {
     328                async_answer_0(icall, EINVAL);
     329                return;
     330        }
     331
     332        /* Check size */
     333        if (size != PAGES2SIZE(SIZE2PAGES(cols * rows * sizeof(charfield_t)))) {
     334                async_answer_0(&call, EINVAL);
     335                async_answer_0(icall, EINVAL);
     336                return;
     337        }
     338
     339        rc = srv->srvs->ops->map(srv, cols, rows, &buf);
     340        if (rc != EOK) {
     341                async_answer_0(&call, rc);
     342                async_answer_0(icall, rc);
     343                return;
     344        }
     345
     346        rc = async_share_in_finalize(&call, buf, AS_AREA_READ |
     347            AS_AREA_WRITE | AS_AREA_CACHEABLE);
     348        if (rc != EOK) {
     349                srv->srvs->ops->unmap(srv);
     350                async_answer_0(icall, EIO);
     351                return;
     352        }
     353
     354        async_answer_0(icall, EOK);
     355}
     356
     357/** Delete shared buffer */
     358static void con_unmap_srv(con_srv_t *srv, ipc_call_t *icall)
     359{
     360        if (srv->srvs->ops->unmap == NULL) {
     361                async_answer_0(icall, ENOTSUP);
     362                return;
     363        }
     364
     365        srv->srvs->ops->unmap(srv);
     366        async_answer_0(icall, EOK);
     367}
     368
     369/** Update console area from shared buffer */
     370static void con_update_srv(con_srv_t *srv, ipc_call_t *icall)
     371{
     372        sysarg_t c0, r0, c1, r1;
     373
     374        c0 = ipc_get_arg1(icall);
     375        r0 = ipc_get_arg2(icall);
     376        c1 = ipc_get_arg3(icall);
     377        r1 = ipc_get_arg4(icall);
     378
     379        if (srv->srvs->ops->update == NULL) {
     380                async_answer_0(icall, ENOTSUP);
     381                return;
     382        }
     383
     384        srv->srvs->ops->update(srv, c0, r0, c1, r1);
     385        async_answer_0(icall, EOK);
     386}
     387
    309388static con_srv_t *con_srv_create(con_srvs_t *srvs)
    310389{
     
    412491                        con_get_event_srv(srv, &call);
    413492                        break;
     493                case CONSOLE_MAP:
     494                        con_map_srv(srv, &call);
     495                        break;
     496                case CONSOLE_UNMAP:
     497                        con_unmap_srv(srv, &call);
     498                        break;
     499                case CONSOLE_UPDATE:
     500                        con_update_srv(srv, &call);
     501                        break;
    414502                default:
    415503                        async_answer_0(&call, ENOTSUP);
  • uspace/lib/c/generic/io/console.c

    r2ab8ab3 r68a552f  
    11/*
     2 * Copyright (c) 2021 Jiri Svoboda
    23 * Copyright (c) 2006 Josef Cejka
    34 * Copyright (c) 2006 Jakub Vana
    4  * Copyright (c) 2008 Jiri Svoboda
    55 * All rights reserved.
    66 *
     
    3535 */
    3636
     37#include <as.h>
    3738#include <libc.h>
    3839#include <async.h>
     
    264265}
    265266
     267/** Create a shared buffer for fast rendering to the console.
     268 *
     269 * @param ctrl Console
     270 * @param cols Number of columns
     271 * @param rows Number of rows
     272 * @param rbuf Place to store pointer to the shared buffer
     273 * @return EOK on success or an error code
     274 */
     275errno_t console_map(console_ctrl_t *ctrl, sysarg_t cols, sysarg_t rows,
     276    charfield_t **rbuf)
     277{
     278        async_exch_t *exch = NULL;
     279        void *buf;
     280        aid_t req;
     281        ipc_call_t answer;
     282        size_t asize;
     283        errno_t rc;
     284
     285        exch = async_exchange_begin(ctrl->output_sess);
     286        req = async_send_2(exch, CONSOLE_MAP, cols, rows, &answer);
     287        if (rc != EOK)
     288                goto error;
     289
     290        asize = PAGES2SIZE(SIZE2PAGES(cols * rows * sizeof(charfield_t)));
     291
     292        rc = async_share_in_start_0_0(exch, asize, &buf);
     293        if (rc != EOK) {
     294                async_forget(req);
     295                goto error;
     296        }
     297
     298        async_exchange_end(exch);
     299        exch = NULL;
     300
     301        async_wait_for(req, &rc);
     302        if (rc != EOK)
     303                goto error;
     304
     305        *rbuf = (charfield_t *)buf;
     306        return EOK;
     307error:
     308        if (exch != NULL)
     309                async_exchange_end(exch);
     310        return rc;
     311}
     312
     313/** Unmap console shared buffer.
     314 *
     315 * @param ctrl Console
     316 * @param buf Buffer
     317 */
     318void console_unmap(console_ctrl_t *ctrl, charfield_t *buf)
     319{
     320        as_area_destroy(buf);
     321}
     322
     323/** Update console rectangle from shared buffer.
     324 *
     325 * @param ctrl Console
     326 * @param c0 Column coordinate of top-left corner (inclusive)
     327 * @param r0 Row coordinate of top-left corner (inclusive)
     328 * @param c1 Column coordinate of bottom-right corner (exclusive)
     329 * @param r1 Row coordinate of bottom-right corner (exclusive)
     330 *
     331 * @return EOK on sucess or an error code
     332 */
     333errno_t console_update(console_ctrl_t *ctrl, sysarg_t c0, sysarg_t r0,
     334    sysarg_t c1, sysarg_t r1)
     335{
     336        async_exch_t *exch = async_exchange_begin(ctrl->output_sess);
     337        errno_t rc = async_req_4_0(exch, CONSOLE_UPDATE, c0, r0, c1, r1);
     338        async_exchange_end(exch);
     339
     340        return rc;
     341}
     342
    266343/** @}
    267344 */
  • uspace/lib/c/include/io/con_srv.h

    r2ab8ab3 r68a552f  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939#include <async.h>
    4040#include <fibril_synch.h>
     41#include <io/charfield.h>
    4142#include <io/color.h>
    4243#include <io/concaps.h>
     
    8384        void (*set_cursor_visibility)(con_srv_t *, bool);
    8485        errno_t (*get_event)(con_srv_t *, cons_event_t *);
     86        errno_t (*map)(con_srv_t *, sysarg_t, sysarg_t, charfield_t **);
     87        void (*unmap)(con_srv_t *);
     88        void (*update)(con_srv_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t);
    8589};
    8690
  • uspace/lib/c/include/io/console.h

    r2ab8ab3 r68a552f  
    11/*
    2  * Copyright (c) 2008 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3737
    3838#include <time.h>
     39#include <io/charfield.h>
    3940#include <io/concaps.h>
    4041#include <io/kbd_event.h>
     
    8687extern bool console_get_event_timeout(console_ctrl_t *, cons_event_t *,
    8788    usec_t *);
     89extern errno_t console_map(console_ctrl_t *, sysarg_t, sysarg_t,
     90    charfield_t **);
     91extern void console_unmap(console_ctrl_t *, charfield_t *);
     92extern errno_t console_update(console_ctrl_t *, sysarg_t, sysarg_t, sysarg_t,
     93    sysarg_t);
    8894
    8995#endif
  • uspace/lib/c/include/ipc/console.h

    r2ab8ab3 r68a552f  
    11/*
     2 * Copyright (c) 2021 Jiri Svoboda
    23 * Copyright (c) 2006 Josef Cejka
    34 * All rights reserved.
     
    4849        CONSOLE_SET_COLOR,
    4950        CONSOLE_SET_RGB_COLOR,
    50         CONSOLE_SET_CURSOR_VISIBILITY
     51        CONSOLE_SET_CURSOR_VISIBILITY,
     52        CONSOLE_MAP,
     53        CONSOLE_UNMAP,
     54        CONSOLE_UPDATE
    5155} console_request_t;
    5256
Note: See TracChangeset for help on using the changeset viewer.