Changeset 9805cde in mainline for uspace/srv/console


Ignore:
Timestamp:
2009-01-01T13:31:23Z (17 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7122bc7
Parents:
666773c
Message:

Console color support overhaul. Create C library console interface.

Location:
uspace/srv/console
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/console/console.c

    r666773c r9805cde  
    4141#include <errno.h>
    4242#include <key_buffer.h>
    43 #include <console.h>
    4443#include <ipc/console.h>
    4544#include <unistd.h>
     
    5150#include <sysinfo.h>
    5251
     52#include "console.h"
    5353#include "gcons.h"
    5454
     
    125125}
    126126
    127 static void set_style(style_t *style)
    128 {
    129         async_msg_2(fb_info.phone, FB_SET_STYLE, style->fg_color,
    130             style->bg_color);
    131 }
    132 
    133 static void set_style_col(int fgcolor, int bgcolor)
    134 {
    135         async_msg_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor);
     127static void set_style(int style)
     128{
     129        async_msg_1(fb_info.phone, FB_SET_STYLE, style);
     130}
     131
     132static void set_color(int fgcolor, int bgcolor, int flags)
     133{
     134        async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
     135}
     136
     137static void set_rgb_color(int fgcolor, int bgcolor)
     138{
     139        async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
     140}
     141
     142static void set_attrs(attrs_t *attrs)
     143{
     144        switch (attrs->t) {
     145        case at_style:
     146                set_style(attrs->a.s.style);
     147                break;
     148
     149        case at_idx:
     150                set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
     151                    attrs->a.i.flags);
     152                break;
     153
     154        case at_rgb:
     155                set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
     156                break;
     157        }
    136158}
    137159
     
    199221        int i, j, rc;
    200222        keyfield_t *field;
    201         style_t *style;
     223        attrs_t *attrs;
    202224       
    203225        if (newcons == active_console)
     
    227249                conn = &connections[active_console];
    228250               
    229                 set_style(&conn->screenbuffer.style);
     251                set_attrs(&conn->screenbuffer.attrs);
    230252                curs_visibility(false);
    231253                if (interbuffer) {
     
    243265               
    244266                if ((!interbuffer) || (rc != 0)) {
    245                         set_style(&conn->screenbuffer.style);
     267                        set_attrs(&conn->screenbuffer.attrs);
    246268                        clrscr();
    247                         style = &conn->screenbuffer.style;
     269                        attrs = &conn->screenbuffer.attrs;
    248270                       
    249271                        for (j = 0; j < conn->screenbuffer.size_y; j++)
    250272                                for (i = 0; i < conn->screenbuffer.size_x; i++) {
    251273                                        field = get_field_at(&conn->screenbuffer, i, j);
    252                                         if (!style_same(*style, field->style))
    253                                                 set_style(&field->style);
    254                                         style = &field->style;
     274                                        if (!attrs_same(*attrs, field->attrs))
     275                                                set_attrs(&field->attrs);
     276                                        attrs = &field->attrs;
    255277                                        if ((field->character == ' ') &&
    256                                             (style_same(field->style,
    257                                             conn->screenbuffer.style)))
     278                                            (attrs_same(field->attrs,
     279                                            conn->screenbuffer.attrs)))
    258280                                                continue;
    259                                        
     281
    260282                                        prtchr(field->character, j, i);
    261283                                }
     
    342364        ipc_call_t call;
    343365        int consnum;
    344         ipcarg_t arg1, arg2;
     366        ipcarg_t arg1, arg2, arg3;
    345367        connection_t *conn;
    346368       
     
    410432                case CONSOLE_SET_STYLE:
    411433                        arg1 = IPC_GET_ARG1(call);
     434                        screenbuffer_set_style(&conn->screenbuffer, arg1);
     435                        if (consnum == active_console)
     436                                set_style(arg1);
     437                        break;
     438                case CONSOLE_SET_COLOR:
     439                        arg1 = IPC_GET_ARG1(call);
    412440                        arg2 = IPC_GET_ARG2(call);
    413                         screenbuffer_set_style(&conn->screenbuffer, arg1,
     441                        arg3 = IPC_GET_ARG3(call);
     442                        screenbuffer_set_color(&conn->screenbuffer, arg1,
     443                            arg2, arg3);
     444                        if (consnum == active_console)
     445                                set_color(arg1, arg2, arg3);
     446                        break;
     447                case CONSOLE_SET_RGB_COLOR:
     448                        arg1 = IPC_GET_ARG1(call);
     449                        arg2 = IPC_GET_ARG2(call);
     450                        screenbuffer_set_rgb_color(&conn->screenbuffer, arg1,
    414451                            arg2);
    415452                        if (consnum == active_console)
    416                                 set_style_col(arg1, arg2);
     453                                set_rgb_color(arg1, arg2);
    417454                        break;
    418455                case CONSOLE_CURSOR_VISIBILITY:
     
    488525        async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows,
    489526            &fb_info.cols);
    490         set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
     527        set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
    491528        clrscr();
    492529       
  • uspace/srv/console/gcons.c

    r666773c r9805cde  
    9898}
    9999
    100 static void set_style(int fgcolor, int bgcolor)
    101 {
    102         async_msg_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor);
     100static void set_rgb_color(int fgcolor, int bgcolor)
     101{
     102        async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
    103103}
    104104
     
    347347       
    348348        vp_switch(0);
    349         set_style(MAIN_COLOR, MAIN_COLOR);
     349        set_rgb_color(MAIN_COLOR, MAIN_COLOR);
    350350        clear();
    351351        draw_pixmap(_binary_helenos_ppm_start,
     
    482482                        return;
    483483                vp_switch(cstatus_vp[i]);
    484                 set_style(0x202020, 0xffffff);
     484                set_rgb_color(0x202020, 0xffffff);
    485485        }
    486486       
  • uspace/srv/console/screenbuffer.c

    r666773c r9805cde  
    3434
    3535#include <screenbuffer.h>
     36#include <console/style.h>
    3637#include <malloc.h>
    3738#include <unistd.h>
     
    5051
    5152        field->character = c;
    52         field->style = scr->style;
     53        field->attrs = scr->attrs;
    5354}
    5455
     
    6869        scr->size_x = size_x;
    6970        scr->size_y = size_y;
    70         scr->style.fg_color = DEFAULT_FOREGROUND;
    71         scr->style.bg_color = DEFAULT_BACKGROUND;
     71        scr->attrs.t = at_style;
     72        scr->attrs.a.s.style = STYLE_NORMAL;
    7273        scr->is_cursor_visible = 1;
    7374       
     
    8687        for (i = 0; i < (scr->size_x * scr->size_y); i++) {
    8788                scr->buffer[i].character = ' ';
    88                 scr->buffer[i].style = scr->style;
     89                scr->buffer[i].attrs = scr->attrs;
    8990        }
    9091
     
    104105        for (i = 0; i < scr->size_x; i++) {
    105106                scr->buffer[i + line * scr->size_x].character = ' ';
    106                 scr->buffer[i + line * scr->size_x].style = scr->style;
     107                scr->buffer[i + line * scr->size_x].attrs = scr->attrs;
    107108        }
    108109}
     
    137138 * @param bg_color
    138139 */
    139 void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)
     140void screenbuffer_set_style(screenbuffer_t *scr, int style)
    140141{
    141         scr->style.fg_color = fg_color;
    142         scr->style.bg_color = bg_color;
     142        scr->attrs.t = at_style;
     143        scr->attrs.a.s.style = style;
     144}
     145
     146/** Set new color.
     147 * @param scr
     148 * @param fg_color
     149 * @param bg_color
     150 */
     151void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color, unsigned int flags)
     152{
     153        scr->attrs.t = at_idx;
     154        scr->attrs.a.i.fg_color = fg_color;
     155        scr->attrs.a.i.bg_color = bg_color;
     156        scr->attrs.a.i.flags = flags;
     157}
     158
     159/** Set new RGB color.
     160 * @param scr
     161 * @param fg_color
     162 * @param bg_color
     163 */
     164void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)
     165{
     166        scr->attrs.t = at_rgb;
     167        scr->attrs.a.r.fg_color = fg_color;
     168        scr->attrs.a.r.bg_color = bg_color;
    143169}
    144170
  • uspace/srv/console/screenbuffer.h

    r666773c r9805cde  
    4242
    4343typedef struct {
     44        uint8_t style;
     45} attr_style_t;
     46
     47typedef struct {
     48        uint8_t fg_color;
     49        uint8_t bg_color;
     50        uint8_t flags;
     51} attr_idx_t;
     52
     53typedef struct {
    4454        uint32_t bg_color;      /**< background color */
    4555        uint32_t fg_color;      /**< foreground color */
    46 } style_t;
     56} attr_rgb_t;
     57
     58typedef struct {
     59        enum {
     60                at_style,
     61                at_idx,
     62                at_rgb
     63        } t;
     64        union {
     65                attr_style_t s;
     66                attr_idx_t i;
     67                attr_rgb_t r;
     68        } a;
     69} attrs_t;
    4770
    4871/** One field on screen. It contain one character and its attributes. */
    4972typedef struct {
    5073        char character;                 /**< Character itself */
    51         style_t style;                  /**< Character`s attributes */
     74        attrs_t attrs;                  /**< Character`s attributes */
    5275} keyfield_t;
    5376
     
    5578 */
    5679typedef struct {
    57         keyfield_t *buffer;                     /**< Screen content - characters and its style. Used as cyclyc buffer. */
     80        keyfield_t *buffer;                     /**< Screen content - characters and their attributes. Used as a circular buffer. */
    5881        unsigned int size_x, size_y;            /**< Number of columns and rows */
    5982        unsigned int position_x, position_y;    /**< Coordinates of last printed character for determining cursor position */
    60         style_t style;                          /**< Current style */
     83        attrs_t attrs;                          /**< Current attributes. */
    6184        unsigned int top_line;                  /**< Points to buffer[][] line that will be printed at screen as the first line */
    6285        unsigned char is_cursor_visible;        /**< Cursor state - default is visible */
     
    7497}
    7598
    76 /** Compares two styles.
     99/** Compares two sets of attributes.
    77100 * @param s1 first style
    78101 * @param s2 second style
    79102 * @return nonzero on equality
    80103 */
    81 static inline int style_same(style_t s1, style_t s2)
     104static inline int attrs_same(attrs_t a1, attrs_t a2)
    82105{
    83         return s1.fg_color == s2.fg_color && s1.bg_color == s2.bg_color;
     106        if (a1.t != a2.t) return 0;
     107
     108        switch (a1.t) {
     109        case at_style: return a1.a.s.style == a2.a.s.style;
     110        case at_idx: return a1.a.i.fg_color == a2.a.i.fg_color &&
     111            a1.a.i.bg_color == a2.a.i.bg_color &&
     112            a1.a.i.flags == a2.a.i.flags;
     113        case at_rgb: return a1.a.r.fg_color == a2.a.r.fg_color &&
     114            a1.a.r.bg_color == a2.a.r.bg_color;
     115        }
    84116}
    85117
     
    92124void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest);
    93125void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y);
    94 void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color);
     126void screenbuffer_set_style(screenbuffer_t *scr, int style);
     127void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color,
     128    unsigned int bg_color, unsigned int attr);
     129void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color,
     130    unsigned int bg_color);
    95131
    96132#endif
Note: See TracChangeset for help on using the changeset viewer.