Changeset 9805cde in mainline
- Timestamp:
- 2009-01-01T13:31:23Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7122bc7
- Parents:
- 666773c
- Location:
- uspace
- Files:
-
- 4 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
r666773c r9805cde 34 34 #include <string.h> 35 35 #include <io/stream.h> 36 #include <console.h> 36 37 37 38 #include "config.h" … … 165 166 size_t len = 0; 166 167 168 console_set_style(STYLE_EMPHASIS); 167 169 printf("%s", usr->prompt); 170 console_set_style(STYLE_NORMAL); 171 168 172 read_line(line, INPUT_MAX); 169 173 len = strlen(line); -
uspace/app/tester/console/console1.c
r666773c r9805cde 33 33 #include "../tester.h" 34 34 35 #include < ipc/console.h>35 #include <console.h> 36 36 37 static void set_style(int fgcolor, int bgcolor) 38 { 39 int con_phone = get_cons_phone(); 40 async_msg_2(con_phone, CONSOLE_SET_STYLE, fgcolor, bgcolor); 41 } 37 const char *color_name[] = { 38 [COLOR_BLACK] = "black", 39 [COLOR_BLUE] = "blue", 40 [COLOR_GREEN] = "green", 41 [COLOR_CYAN] = "cyan", 42 [COLOR_RED] = "red", 43 [COLOR_MAGENTA] = "magenta", 44 [COLOR_YELLOW] = "yellow", 45 [COLOR_WHITE] = "white" 46 }; 42 47 43 48 char * test_console1(bool quiet) 44 49 { 45 set_style(0xff0000, 0xf0f0f0); 46 printf("Red on white background.\n"); 47 set_style(0x008080, 0x000080); 48 printf("Cyan on blue background.\n"); 49 set_style(0x000000, 0xf0f0f0); 50 printf("Black on white background.\n"); 50 int i, j; 51 52 printf("Style test: "); 53 console_set_style(STYLE_NORMAL); 54 printf("normal "); 55 console_set_style(STYLE_EMPHASIS); 56 printf("emphasized"); 57 console_set_style(STYLE_NORMAL); 58 printf(".\n"); 59 60 printf("Foreground color test:\n"); 61 for (j = 0; j < 2; j++) { 62 for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) { 63 console_set_color(i, COLOR_WHITE, 64 j ? CATTR_BRIGHT : 0); 65 printf(" %s ", color_name[i]); 66 } 67 console_set_color(COLOR_BLACK, COLOR_WHITE, 0); 68 putchar('\n'); 69 } 70 71 printf("Background color test:\n"); 72 for (j = 0; j < 2; j++) { 73 for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) { 74 console_set_color(COLOR_WHITE, i, 75 j ? CATTR_BRIGHT : 0); 76 printf(" %s ", color_name[i]); 77 } 78 console_set_color(COLOR_BLACK, COLOR_WHITE, 0); 79 putchar('\n'); 80 } 81 82 printf("Now let's test RGB colors:\n"); 83 84 for (i = 0; i < 255; i += 16) { 85 console_set_rgb_color(0xffffff, i << 16); 86 putchar('X'); 87 } 88 console_set_color(COLOR_BLACK, COLOR_WHITE, 0); 89 putchar('\n'); 90 91 for (i = 0; i < 255; i += 16) { 92 console_set_rgb_color(0xffffff, i << 8); 93 putchar('X'); 94 } 95 console_set_color(COLOR_BLACK, COLOR_WHITE, 0); 96 putchar('\n'); 97 98 for (i = 0; i < 255; i += 16) { 99 console_set_rgb_color(0xffffff, i); 100 putchar('X'); 101 } 102 console_set_color(COLOR_BLACK, COLOR_WHITE, 0); 103 putchar('\n'); 51 104 52 105 printf("[press a key]\n"); -
uspace/app/tetris/screen.c
r666773c r9805cde 52 52 #include <unistd.h> 53 53 #include <io/stream.h> 54 54 #include <console.h> 55 55 56 56 #include <async.h> … … 77 77 78 78 79 80 static void set_style(int fgcolor, int bgcolor)81 {82 async_msg_2(con_phone, CONSOLE_SET_STYLE, fgcolor, bgcolor);83 }84 85 79 static void start_standout(void) 86 80 { 87 set_style(0xf0f0f0, 0);81 console_set_rgb_color(0xf0f0f0, 0); 88 82 } 89 83 90 84 static void resume_normal(void) 91 85 { 92 set_style(0, 0xf0f0f0); 93 } 94 86 console_set_rgb_color(0, 0xf0f0f0); 87 } 95 88 96 89 void clear_screen(void) -
uspace/app/trace/trace.c
r666773c r9805cde 667 667 proto_add_oper(p, CONSOLE_FLUSH, o); 668 668 669 arg_def[0] = V_INTEGER; 670 o = oper_new("set_style", 1, arg_def, V_INTEGER, 0, resp_def); 671 proto_add_oper(p, CONSOLE_SET_STYLE, o); 672 arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; arg_def[2] = V_INTEGER; 673 o = oper_new("set_color", 3, arg_def, V_INTEGER, 0, resp_def); 674 proto_add_oper(p, CONSOLE_SET_COLOR, o); 669 675 arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; 670 o = oper_new("set_ style", 2, arg_def, V_INTEGER, 0, resp_def);671 proto_add_oper(p, CONSOLE_SET_ STYLE, o);676 o = oper_new("set_rgb_color", 2, arg_def, V_INTEGER, 0, resp_def); 677 proto_add_oper(p, CONSOLE_SET_RGB_COLOR, o); 672 678 o = oper_new("cursor_visibility", 1, arg_def, V_VOID, 0, resp_def); 673 679 proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o); -
uspace/lib/libc/Makefile
r666773c r9805cde 49 49 generic/as.c \ 50 50 generic/cap.c \ 51 generic/console.c \ 51 52 generic/mem.c \ 52 53 generic/string.c \ -
uspace/lib/libc/include/ipc/console.h
r666773c r9805cde 33 33 */ 34 34 35 #ifndef LIBC_ CONSOLE_H_36 #define LIBC_ CONSOLE_H_35 #ifndef LIBC_IPC_CONSOLE_H_ 36 #define LIBC_IPC_CONSOLE_H_ 37 37 38 #define CONSOLE_GETCHAR 1026 39 #define CONSOLE_PUTCHAR 1027 40 #define CONSOLE_CLEAR 1028 41 #define CONSOLE_GOTO 1029 42 #define CONSOLE_GETSIZE 1030 43 #define CONSOLE_FLUSH 1031 44 #define CONSOLE_SET_STYLE 1032 45 #define CONSOLE_CURSOR_VISIBILITY 1033 38 #include <ipc/ipc.h> 39 40 typedef enum { 41 CONSOLE_GETCHAR = IPC_FIRST_USER_METHOD, 42 CONSOLE_PUTCHAR, 43 CONSOLE_CLEAR, 44 CONSOLE_GOTO, 45 CONSOLE_GETSIZE, 46 CONSOLE_FLUSH, 47 CONSOLE_SET_STYLE, 48 CONSOLE_SET_COLOR, 49 CONSOLE_SET_RGB_COLOR, 50 CONSOLE_CURSOR_VISIBILITY 51 } console_request_t; 46 52 47 53 #endif -
uspace/lib/libc/include/ipc/fb.h
r666773c r9805cde 49 49 FB_VIEWPORT_DELETE, 50 50 FB_SET_STYLE, 51 FB_SET_COLOR, 52 FB_SET_RGB_COLOR, 51 53 FB_GET_RESOLUTION, 52 54 FB_DRAW_TEXT_DATA, … … 68 70 } fb_request_t; 69 71 70 71 72 #endif 72 73 -
uspace/srv/console/console.c
r666773c r9805cde 41 41 #include <errno.h> 42 42 #include <key_buffer.h> 43 #include <console.h>44 43 #include <ipc/console.h> 45 44 #include <unistd.h> … … 51 50 #include <sysinfo.h> 52 51 52 #include "console.h" 53 53 #include "gcons.h" 54 54 … … 125 125 } 126 126 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); 127 static void set_style(int style) 128 { 129 async_msg_1(fb_info.phone, FB_SET_STYLE, style); 130 } 131 132 static 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 137 static void set_rgb_color(int fgcolor, int bgcolor) 138 { 139 async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); 140 } 141 142 static 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 } 136 158 } 137 159 … … 199 221 int i, j, rc; 200 222 keyfield_t *field; 201 style_t *style;223 attrs_t *attrs; 202 224 203 225 if (newcons == active_console) … … 227 249 conn = &connections[active_console]; 228 250 229 set_ style(&conn->screenbuffer.style);251 set_attrs(&conn->screenbuffer.attrs); 230 252 curs_visibility(false); 231 253 if (interbuffer) { … … 243 265 244 266 if ((!interbuffer) || (rc != 0)) { 245 set_ style(&conn->screenbuffer.style);267 set_attrs(&conn->screenbuffer.attrs); 246 268 clrscr(); 247 style = &conn->screenbuffer.style;269 attrs = &conn->screenbuffer.attrs; 248 270 249 271 for (j = 0; j < conn->screenbuffer.size_y; j++) 250 272 for (i = 0; i < conn->screenbuffer.size_x; i++) { 251 273 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; 255 277 if ((field->character == ' ') && 256 ( style_same(field->style,257 conn->screenbuffer. style)))278 (attrs_same(field->attrs, 279 conn->screenbuffer.attrs))) 258 280 continue; 259 281 260 282 prtchr(field->character, j, i); 261 283 } … … 342 364 ipc_call_t call; 343 365 int consnum; 344 ipcarg_t arg1, arg2 ;366 ipcarg_t arg1, arg2, arg3; 345 367 connection_t *conn; 346 368 … … 410 432 case CONSOLE_SET_STYLE: 411 433 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); 412 440 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, 414 451 arg2); 415 452 if (consnum == active_console) 416 set_ style_col(arg1, arg2);453 set_rgb_color(arg1, arg2); 417 454 break; 418 455 case CONSOLE_CURSOR_VISIBILITY: … … 488 525 async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, 489 526 &fb_info.cols); 490 set_ style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);527 set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); 491 528 clrscr(); 492 529 -
uspace/srv/console/gcons.c
r666773c r9805cde 98 98 } 99 99 100 static void set_ style(int fgcolor, int bgcolor)101 { 102 async_msg_2(fbphone, FB_SET_ STYLE, fgcolor, bgcolor);100 static void set_rgb_color(int fgcolor, int bgcolor) 101 { 102 async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor); 103 103 } 104 104 … … 347 347 348 348 vp_switch(0); 349 set_ style(MAIN_COLOR, MAIN_COLOR);349 set_rgb_color(MAIN_COLOR, MAIN_COLOR); 350 350 clear(); 351 351 draw_pixmap(_binary_helenos_ppm_start, … … 482 482 return; 483 483 vp_switch(cstatus_vp[i]); 484 set_ style(0x202020, 0xffffff);484 set_rgb_color(0x202020, 0xffffff); 485 485 } 486 486 -
uspace/srv/console/screenbuffer.c
r666773c r9805cde 34 34 35 35 #include <screenbuffer.h> 36 #include <console/style.h> 36 37 #include <malloc.h> 37 38 #include <unistd.h> … … 50 51 51 52 field->character = c; 52 field-> style = scr->style;53 field->attrs = scr->attrs; 53 54 } 54 55 … … 68 69 scr->size_x = size_x; 69 70 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; 72 73 scr->is_cursor_visible = 1; 73 74 … … 86 87 for (i = 0; i < (scr->size_x * scr->size_y); i++) { 87 88 scr->buffer[i].character = ' '; 88 scr->buffer[i]. style = scr->style;89 scr->buffer[i].attrs = scr->attrs; 89 90 } 90 91 … … 104 105 for (i = 0; i < scr->size_x; i++) { 105 106 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; 107 108 } 108 109 } … … 137 138 * @param bg_color 138 139 */ 139 void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)140 void screenbuffer_set_style(screenbuffer_t *scr, int style) 140 141 { 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 */ 151 void 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 */ 164 void 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; 143 169 } 144 170 -
uspace/srv/console/screenbuffer.h
r666773c r9805cde 42 42 43 43 typedef struct { 44 uint8_t style; 45 } attr_style_t; 46 47 typedef struct { 48 uint8_t fg_color; 49 uint8_t bg_color; 50 uint8_t flags; 51 } attr_idx_t; 52 53 typedef struct { 44 54 uint32_t bg_color; /**< background color */ 45 55 uint32_t fg_color; /**< foreground color */ 46 } style_t; 56 } attr_rgb_t; 57 58 typedef 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; 47 70 48 71 /** One field on screen. It contain one character and its attributes. */ 49 72 typedef struct { 50 73 char character; /**< Character itself */ 51 style_t style; /**< Character`s attributes */74 attrs_t attrs; /**< Character`s attributes */ 52 75 } keyfield_t; 53 76 … … 55 78 */ 56 79 typedef struct { 57 keyfield_t *buffer; /**< Screen content - characters and its style. Used as cyclycbuffer. */80 keyfield_t *buffer; /**< Screen content - characters and their attributes. Used as a circular buffer. */ 58 81 unsigned int size_x, size_y; /**< Number of columns and rows */ 59 82 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. */ 61 84 unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */ 62 85 unsigned char is_cursor_visible; /**< Cursor state - default is visible */ … … 74 97 } 75 98 76 /** Compares two s tyles.99 /** Compares two sets of attributes. 77 100 * @param s1 first style 78 101 * @param s2 second style 79 102 * @return nonzero on equality 80 103 */ 81 static inline int style_same(style_t s1, style_t s2)104 static inline int attrs_same(attrs_t a1, attrs_t a2) 82 105 { 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 } 84 116 } 85 117 … … 92 124 void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest); 93 125 void 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); 126 void screenbuffer_set_style(screenbuffer_t *scr, int style); 127 void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color, 128 unsigned int bg_color, unsigned int attr); 129 void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, 130 unsigned int bg_color); 95 131 96 132 #endif -
uspace/srv/fb/ega.c
r666773c r9805cde 50 50 #include <ipc/services.h> 51 51 #include <libarch/ddi.h> 52 #include <console/style.h> 53 #include <console/color.h> 52 54 53 55 #include "ega.h" … … 65 67 #define EGA_IO_SIZE 2 66 68 67 int ega_normal_color =0x0f;68 int ega_inverted_color =0xf0;69 int ega_normal_color = 0x0f; 70 int ega_inverted_color = 0xf0; 69 71 70 72 #define NORMAL_COLOR ega_normal_color … … 155 157 for (i = 0; i < scr_width * scr_height; i++) { 156 158 scr_addr[i * 2] = data[i].character; 159 /* FIXME 157 160 scr_addr[i * 2 + 1] = EGA_STYLE(data[i].style.fg_color, 158 161 data[i].style.bg_color); 162 */ 159 163 } 160 164 } … … 276 280 break; 277 281 case FB_SET_STYLE: 282 retval = 0; 283 switch (IPC_GET_ARG1(call)) { 284 case STYLE_NORMAL: style = INVERTED_COLOR; break; 285 case STYLE_EMPHASIS: style = INVERTED_COLOR | 4; break; 286 default: retval = EINVAL; 287 } 288 break; 289 case FB_SET_COLOR: 290 fgcolor = IPC_GET_ARG1(call); 291 bgcolor = IPC_GET_ARG2(call); 292 style = (fgcolor & 7) | ((bgcolor & 7) << 4); 293 if (IPC_GET_ARG3(call) & CATTR_BRIGHT) 294 style = style | 0x08; 295 retval = 0; 296 break; 297 case FB_SET_RGB_COLOR: 278 298 fgcolor = IPC_GET_ARG1(call); 279 299 bgcolor = IPC_GET_ARG2(call); … … 318 338 if(sysinfo_value("fb.blinking")) 319 339 { 320 ega_normal_color &=0x77;321 ega_inverted_color &=0x77;340 ega_normal_color &= 0x77; 341 ega_inverted_color &= 0x77; 322 342 } 323 343 style = NORMAL_COLOR; -
uspace/srv/fb/fb.c
r666773c r9805cde 52 52 #include <kernel/errno.h> 53 53 #include <kernel/genarch/fb/visuals.h> 54 #include <console/color.h> 55 #include <console/style.h> 54 56 #include <async.h> 55 57 #include <bool.h> … … 93 95 rgb_conv_t rgb_conv; 94 96 } screen; 97 98 /** Backbuffer character cell. */ 99 typedef struct { 100 uint8_t glyph; 101 uint32_t fg_color; 102 uint32_t bg_color; 103 } bb_cell_t; 95 104 96 105 typedef struct { … … 109 118 */ 110 119 111 /** Current style. */112 style_t style;120 /** Current attributes. */ 121 attr_rgb_t attr; 113 122 114 123 /** Pre-rendered mask for rendering glyphs. Different viewports … … 129 138 130 139 /* Back buffer */ 140 bb_cell_t *backbuf; 131 141 unsigned int bbsize; 132 uint8_t *backbuf;133 142 } viewport_t; 134 143 … … 156 165 157 166 static bool client_connected = false; /**< Allow only 1 connection */ 167 168 static uint32_t color_table[16] = { 169 [COLOR_BLACK] = 0x000000, 170 [COLOR_BLUE] = 0x0000f0, 171 [COLOR_GREEN] = 0x00f000, 172 [COLOR_CYAN] = 0x00f0f0, 173 [COLOR_RED] = 0xf00000, 174 [COLOR_MAGENTA] = 0xf000f0, 175 [COLOR_YELLOW] = 0xf0f000, 176 [COLOR_WHITE] = 0xf0f0f0, 177 178 [8 + COLOR_BLACK] = 0x000000, 179 [8 + COLOR_BLUE] = 0x0000ff, 180 [8 + COLOR_GREEN] = 0x00ff00, 181 [8 + COLOR_CYAN] = 0x00ffff, 182 [8 + COLOR_RED] = 0xff0000, 183 [8 + COLOR_MAGENTA] = 0xff00ff, 184 [8 + COLOR_YELLOW] = 0xffff00, 185 [8 + COLOR_WHITE] = 0xffffff, 186 }; 187 188 static int rgb_from_style(attr_rgb_t *rgb, int style); 189 static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, 190 ipcarg_t bg_color, ipcarg_t flags); 191 192 static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, 193 ipcarg_t bg_color, ipcarg_t attr); 158 194 159 195 static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, … … 300 336 vport->x + COL2X(vport->cols), vport->y, 301 337 vport->x + vport->width, vport->y + vport->height, 302 vport-> style.bg_color);338 vport->attr.bg_color); 303 339 } 304 340 … … 307 343 vport->x, vport->y + ROW2Y(vport->rows), 308 344 vport->x + vport->width, vport->y + vport->height, 309 vport->style.bg_color); 310 } 311 } 312 345 vport->attr.bg_color); 346 } 347 } 348 349 static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color, 350 uint32_t bg_color) 351 { 352 unsigned i; 353 354 for (i = 0; i < len; i++) { 355 backbuf[i].glyph = 0; 356 backbuf[i].fg_color = fg_color; 357 backbuf[i].bg_color = bg_color; 358 } 359 } 313 360 314 361 /** Clear viewport. … … 319 366 static void vport_clear(viewport_t *vport) 320 367 { 321 memset(vport->backbuf, 0, vport->bbsize); 368 backbuf_clear(vport->backbuf, vport->cols * vport->rows, 369 vport->attr.fg_color, vport->attr.bg_color); 322 370 vport_redraw(vport); 323 371 } … … 334 382 unsigned int x, y; 335 383 uint8_t glyph; 384 uint32_t fg_color; 385 uint32_t bg_color; 386 bb_cell_t *bbp, *xbp; 336 387 337 388 /* … … 344 395 for (col = 0; col < vport->cols; col++) { 345 396 if ((row + lines >= 0) && (row + lines < vport->rows)) { 346 glyph = vport->backbuf[BB_POS(vport, col, row + lines)]; 347 348 if (vport->backbuf[BB_POS(vport, col, row)] == glyph) { 397 xbp = &vport->backbuf[BB_POS(vport, col, row + lines)]; 398 bbp = &vport->backbuf[BB_POS(vport, col, row)]; 399 400 glyph = xbp->glyph; 401 fg_color = xbp->fg_color; 402 bg_color = xbp->bg_color; 403 404 if (bbp->glyph == glyph && 405 bbp->fg_color == xbp->fg_color && 406 bbp->bg_color == xbp->bg_color) { 349 407 x += FONT_WIDTH; 350 408 continue; … … 352 410 } else { 353 411 glyph = 0; 412 fg_color = vport->attr.fg_color; 413 bg_color = vport->attr.bg_color; 354 414 } 355 415 356 416 (*vport->dglyph)(x, y, false, vport->glyphs, glyph, 357 vport->style.fg_color, vport->style.bg_color);417 fg_color, bg_color); 358 418 x += FONT_WIDTH; 359 419 } … … 367 427 if (lines > 0) { 368 428 memmove(vport->backbuf, vport->backbuf + vport->cols * lines, 369 vport->cols * (vport->rows - lines) );370 memset(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)],371 0, vport->cols * lines);429 vport->cols * (vport->rows - lines) * sizeof(bb_cell_t)); 430 backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], 431 vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color); 372 432 } else { 373 433 memmove(vport->backbuf - vport->cols * lines, vport->backbuf, 374 vport->cols * (vport->rows + lines)); 375 memset(vport->backbuf, 0, - vport->cols * lines); 434 vport->cols * (vport->rows + lines) * sizeof(bb_cell_t)); 435 backbuf_clear(vport->backbuf, - vport->cols * lines, 436 vport->attr.fg_color, vport->attr.bg_color); 376 437 } 377 438 } … … 407 468 } 408 469 409 screen.rgb_conv(vport->bgpixel, vport-> style.bg_color);470 screen.rgb_conv(vport->bgpixel, vport->attr.bg_color); 410 471 } 411 472 … … 435 496 unsigned int cols = width / FONT_WIDTH; 436 497 unsigned int rows = height / FONT_SCANLINES; 437 unsigned int bbsize = cols * rows ;498 unsigned int bbsize = cols * rows * sizeof(bb_cell_t); 438 499 unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes; 439 500 unsigned int word_size = sizeof(unsigned long); 440 501 441 uint8_t *backbuf = (uint8_t *) malloc(bbsize);502 bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize); 442 503 if (!backbuf) 443 504 return ENOMEM; … … 455 516 return ENOMEM; 456 517 } 457 458 memset(backbuf, 0, bbsize);518 519 backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR); 459 520 memset(glyphs, 0, glyphsize); 460 521 memset(bgpixel, 0, screen.pixelbytes); … … 468 529 viewports[i].rows = rows; 469 530 470 viewports[i]. style.bg_color = DEFAULT_BGCOLOR;471 viewports[i]. style.fg_color = DEFAULT_FGCOLOR;531 viewports[i].attr.bg_color = DEFAULT_BGCOLOR; 532 viewports[i].attr.fg_color = DEFAULT_FGCOLOR; 472 533 473 534 viewports[i].glyphs = glyphs; … … 708 769 unsigned int x = vport->x + COL2X(col); 709 770 unsigned int y = vport->y + ROW2Y(row); 771 710 772 uint8_t glyph; 711 712 glyph = vport->backbuf[BB_POS(vport, col, row)]; 773 uint32_t fg_color; 774 uint32_t bg_color; 775 776 glyph = vport->backbuf[BB_POS(vport, col, row)].glyph; 777 fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color; 778 bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color; 713 779 714 780 (*vport->dglyph)(x, y, cursor, vport->glyphs, glyph, 715 vport->style.fg_color, vport->style.bg_color);781 fg_color, bg_color); 716 782 } 717 783 … … 763 829 static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row) 764 830 { 831 bb_cell_t *bbp; 832 765 833 /* Do not hide cursor if we are going to overwrite it */ 766 834 if ((vport->cursor_active) && (vport->cursor_shown) && 767 835 ((vport->cur_col != col) || (vport->cur_row != row))) 768 836 cursor_hide(vport); 769 770 vport->backbuf[BB_POS(vport, col, row)] = c; 837 838 bbp = &vport->backbuf[BB_POS(vport, col, row)]; 839 bbp->glyph = c; 840 bbp->fg_color = vport->attr.fg_color; 841 bbp->bg_color = vport->attr.bg_color; 842 771 843 draw_vp_glyph(vport, false, col, row); 772 844 … … 795 867 { 796 868 unsigned int i; 869 bb_cell_t *bbp; 870 attrs_t *a; 871 attr_rgb_t rgb; 797 872 798 873 for (i = 0; i < vport->cols * vport->rows; i++) { … … 800 875 unsigned int row = i / vport->cols; 801 876 802 uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)]; 803 804 // TODO: use data[i].style 805 877 bbp = &vport->backbuf[BB_POS(vport, col, row)]; 878 uint8_t glyph = bbp->glyph; 879 806 880 if (glyph != data[i].character) { 807 vport->backbuf[BB_POS(vport, col, row)] = data[i].character; 881 bbp->glyph = data[i].character; 882 a = &data[i].attrs; 883 884 switch (a->t) { 885 case at_style: 886 rgb_from_style(&rgb, a->a.s.style); 887 break; 888 case at_idx: 889 rgb_from_idx(&rgb, a->a.i.fg_color, 890 a->a.i.bg_color, a->a.i.flags); 891 break; 892 case at_rgb: 893 rgb = a->a.r; 894 break; 895 } 896 897 bbp->fg_color = rgb.fg_color; 898 bbp->bg_color = rgb.bg_color; 899 808 900 draw_vp_glyph(vport, false, col, row); 809 901 } … … 1321 1413 return handled; 1322 1414 1415 } 1416 1417 static int rgb_from_style(attr_rgb_t *rgb, int style) 1418 { 1419 switch (style) { 1420 case STYLE_NORMAL: 1421 rgb->fg_color = color_table[COLOR_BLACK]; 1422 rgb->bg_color = color_table[COLOR_WHITE]; 1423 break; 1424 case STYLE_EMPHASIS: 1425 rgb->fg_color = color_table[COLOR_RED]; 1426 rgb->bg_color = color_table[COLOR_WHITE]; 1427 break; 1428 default: 1429 return EINVAL; 1430 } 1431 1432 return EOK; 1433 } 1434 1435 static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, 1436 ipcarg_t bg_color, ipcarg_t flags) 1437 { 1438 fg_color = (fg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); 1439 bg_color = (bg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); 1440 1441 rgb->fg_color = color_table[fg_color]; 1442 rgb->bg_color = color_table[bg_color]; 1443 1444 return EOK; 1445 } 1446 1447 static int fb_set_style(viewport_t *vport, ipcarg_t style) 1448 { 1449 return rgb_from_style(&vport->attr, (int) style); 1450 } 1451 1452 static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, 1453 ipcarg_t bg_color, ipcarg_t flags) 1454 { 1455 return rgb_from_idx(&vport->attr, fg_color, bg_color, flags); 1323 1456 } 1324 1457 … … 1479 1612 break; 1480 1613 case FB_SET_STYLE: 1481 vport->style.fg_color = IPC_GET_ARG1(call); 1482 vport->style.bg_color = IPC_GET_ARG2(call); 1614 retval = fb_set_style(vport, IPC_GET_ARG1(call)); 1615 break; 1616 case FB_SET_COLOR: 1617 retval = fb_set_color(vport, IPC_GET_ARG1(call), 1618 IPC_GET_ARG2(call), IPC_GET_ARG3(call)); 1619 break; 1620 case FB_SET_RGB_COLOR: 1621 vport->attr.fg_color = IPC_GET_ARG1(call); 1622 vport->attr.bg_color = IPC_GET_ARG2(call); 1483 1623 retval = EOK; 1484 1624 break; -
uspace/srv/fb/serial_console.c
r666773c r9805cde 44 44 #include <bool.h> 45 45 #include <errno.h> 46 #include <console/style.h> 46 47 47 48 #include "serial_console.h" … … 90 91 } 91 92 92 void serial_set_style(const unsigned int mode) 93 /** ECMA-48 Set Graphics Rendition. */ 94 static void serial_sgr(const unsigned int mode) 93 95 { 94 96 char control[MAX_CONTROL]; … … 137 139 int fgcolor; 138 140 int bgcolor; 141 int style; 139 142 int i; 140 143 … … 187 190 break; 188 191 case FB_SET_STYLE: 192 style = IPC_GET_ARG1(call); 193 if (style == STYLE_EMPHASIS) 194 serial_sgr(1); 195 else 196 serial_sgr(0); 197 retval = 0; 198 break; 199 case FB_SET_COLOR: 189 200 fgcolor = IPC_GET_ARG1(call); 190 201 bgcolor = IPC_GET_ARG2(call); 191 202 if (fgcolor < bgcolor) 192 serial_set_style(0); 193 else 194 serial_set_style(7); 203 serial_sgr(0); 204 else 205 serial_sgr(7); 206 retval = 0; 207 break; 208 case FB_SET_RGB_COLOR: 209 fgcolor = IPC_GET_ARG1(call); 210 bgcolor = IPC_GET_ARG2(call); 211 if (fgcolor < bgcolor) 212 serial_sgr(0); 213 else 214 serial_sgr(7); 195 215 retval = 0; 196 216 break;
Note:
See TracChangeset
for help on using the changeset viewer.