Changeset 16e9c476 in mainline for uspace/srv/fb/serial_console.c


Ignore:
Timestamp:
2009-03-17T22:18:47Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7e15496
Parents:
f6377f72
Message:

Interbuffer support in serial framebuffer driver for faster VC switches.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fb/serial_console.c

    rf6377f72 r16e9c476  
    4747#include <console/style.h>
    4848
     49#include "../console/screenbuffer.h"
     50#include "main.h"
    4951#include "serial_console.h"
    5052
     
    5355static void serial_sgr(const unsigned int mode);
    5456
    55 static int width;
    56 static int height;
     57static int scr_width;
     58static int scr_height;
    5759static bool color = true;       /** True if producing color output. */
    5860static putc_function_t putc_function;
     
    103105void serial_goto(const unsigned int row, const unsigned int col)
    104106{
    105         if ((row > height) || (col > width))
     107        if ((row > scr_height) || (col > scr_width))
    106108                return;
    107109       
     
    126128{
    127129        if (i > 0) {
    128                 serial_goto(height - 1, 0);
     130                serial_goto(scr_height - 1, 0);
    129131                while (i--)
    130132                        serial_puts("\033D");
     
    164166void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h)
    165167{
    166         width = w;
    167         height = h;
     168        scr_width = w;
     169        scr_height = h;
    168170        putc_function = putc_fn;
     171}
     172
     173static void serial_set_style(int style)
     174{
     175        if (style == STYLE_EMPHASIS) {
     176                if (color) {
     177                        serial_sgr(SGR_RESET);
     178                        serial_sgr(SGR_FGCOLOR + CI_RED);
     179                        serial_sgr(SGR_BGCOLOR + CI_WHITE);
     180                }
     181                serial_sgr(SGR_BOLD);
     182        } else {
     183                if (color) {
     184                        serial_sgr(SGR_RESET);
     185                        serial_sgr(SGR_FGCOLOR + CI_BLACK);
     186                        serial_sgr(SGR_BGCOLOR + CI_WHITE);
     187                }
     188                serial_sgr(SGR_NORMAL_INT);
     189        }
     190}
     191
     192static void serial_set_idx(unsigned fgcolor, unsigned bgcolor,
     193    unsigned flags)
     194{
     195        if (color) {
     196                serial_sgr(SGR_RESET);
     197                serial_sgr(SGR_FGCOLOR + color_map[fgcolor]);
     198                serial_sgr(SGR_BGCOLOR + color_map[bgcolor]);
     199        } else {
     200                if (fgcolor < bgcolor)
     201                        serial_sgr(SGR_RESET);
     202                else
     203                        serial_sgr(SGR_REVERSE);
     204        }       
     205}
     206
     207static void serial_set_rgb(uint32_t fgcolor, uint32_t bgcolor)
     208{
     209        if (fgcolor < bgcolor)
     210                serial_sgr(SGR_REVERSE_OFF);
     211        else
     212                serial_sgr(SGR_REVERSE);       
     213}
     214
     215static void serial_set_attrs(const attrs_t *a)
     216{
     217        switch (a->t) {
     218        case at_style: serial_set_style(a->a.s.style); break;
     219        case at_rgb: serial_set_rgb(a->a.r.fg_color, a->a.r.bg_color); break;
     220        case at_idx: serial_set_idx(a->a.i.fg_color,
     221            a->a.i.bg_color, a->a.i.flags); break;
     222        default: break;
     223        }
     224}
     225
     226static void draw_text_data(keyfield_t *data)
     227{
     228        int i, j;
     229        attrs_t *a0, *a1;
     230
     231        serial_goto(0, 0);
     232        a0 = &data[0].attrs;
     233        serial_set_attrs(a0);
     234
     235        for (i = 0; i < scr_height; i++) {
     236                for (j = 0; j < scr_width; j++) {
     237                        a1 = &data[i * scr_width + j].attrs;
     238                        if (!attrs_same(*a0, *a1))
     239                                serial_set_attrs(a1);
     240                        (*putc_function)(data[i * scr_width + j].character);
     241                        a0 = a1;
     242/*              scr_addr[i * 2] = data[i].character;
     243                scr_addr[i * 2 + 1] = attr_to_ega_style(&data[i].attrs);*/
     244                }
     245        }
    169246}
    170247
     
    177254        ipc_callid_t callid;
    178255        ipc_call_t call;
     256        keyfield_t *interbuf = NULL;
     257        size_t intersize = 0;
     258
    179259        char c;
    180260        int lastcol = 0;
     
    184264        int fgcolor;
    185265        int bgcolor;
     266        int flags;
    186267        int style;
    187268        int i;
     269
    188270       
    189271        if (client_connected) {
     
    199281        serial_clrscr();
    200282        serial_goto(0, 0);
    201         serial_set_scroll_region(height);
     283        serial_set_scroll_region(scr_height);
    202284       
    203285        while (true) {
     
    208290                        ipc_answer_0(callid, EOK);
    209291                        return;
     292                case IPC_M_SHARE_OUT:
     293                        /* We accept one area for data interchange */
     294                        intersize = IPC_GET_ARG2(call);
     295                        if (intersize >= scr_width * scr_height *
     296                            sizeof(*interbuf)) {
     297                                receive_comm_area(callid, &call,
     298                                    (void *) &interbuf);
     299                                continue;
     300                        }
     301                        retval = EINVAL;
     302                        break;
     303                case FB_DRAW_TEXT_DATA:
     304                        if (!interbuf) {
     305                                retval = EINVAL;
     306                                break;
     307                        }
     308                        draw_text_data(interbuf);
     309                        retval = 0;
     310                        break;
    210311                case FB_PUTCHAR:
    211312                        c = IPC_GET_ARG1(call);
     
    228329                        break;
    229330                case FB_GET_CSIZE:
    230                         ipc_answer_2(callid, EOK, height, width);
     331                        ipc_answer_2(callid, EOK, scr_height, scr_width);
    231332                        continue;
    232333                case FB_CLEAR:
     
    235336                        break;
    236337                case FB_SET_STYLE:
    237                         style =  IPC_GET_ARG1(call);
    238                         if (style == STYLE_EMPHASIS) {
    239                                 if (color) {
    240                                         serial_sgr(SGR_RESET);
    241                                         serial_sgr(SGR_FGCOLOR + CI_RED);
    242                                         serial_sgr(SGR_BGCOLOR + CI_WHITE);
    243                                 }
    244                                 serial_sgr(SGR_BOLD);
    245                         } else {
    246                                 if (color) {
    247                                         serial_sgr(SGR_RESET);
    248                                         serial_sgr(SGR_FGCOLOR + CI_BLACK);
    249                                         serial_sgr(SGR_BGCOLOR + CI_WHITE);
    250                                 }
    251                                 serial_sgr(SGR_NORMAL_INT);
    252                         }
     338                        style = IPC_GET_ARG1(call);
     339                        serial_set_style(style);
    253340                        retval = 0;
    254341                        break;
     
    256343                        fgcolor = IPC_GET_ARG1(call);
    257344                        bgcolor = IPC_GET_ARG2(call);
    258 
    259                         if (color) {
    260                                 serial_sgr(SGR_RESET);
    261                                 serial_sgr(SGR_FGCOLOR + color_map[fgcolor]);
    262                                 serial_sgr(SGR_BGCOLOR + color_map[bgcolor]);
    263                         } else {
    264                                 if (fgcolor < bgcolor)
    265                                         serial_sgr(SGR_RESET);
    266                                 else
    267                                         serial_sgr(SGR_REVERSE);
    268                         }
     345                        flags = IPC_GET_ARG3(call);
     346
     347                        serial_set_idx(fgcolor, bgcolor, flags);
    269348                        retval = 0;
    270349                        break;
     
    272351                        fgcolor = IPC_GET_ARG1(call);
    273352                        bgcolor = IPC_GET_ARG2(call);
    274                         if (fgcolor < bgcolor)
    275                                 serial_sgr(SGR_REVERSE_OFF);
    276                         else
    277                                 serial_sgr(SGR_REVERSE);
     353
     354                        serial_set_rgb(fgcolor, bgcolor);
    278355                        retval = 0;
    279356                        break;
    280357                case FB_SCROLL:
    281358                        i = IPC_GET_ARG1(call);
    282                         if ((i > height) || (i < -height)) {
     359                        if ((i > scr_height) || (i < -scr_height)) {
    283360                                retval = EINVAL;
    284361                                break;
Note: See TracChangeset for help on using the changeset viewer.