Changeset 9805cde in mainline for uspace/srv/console
- Timestamp:
- 2009-01-01T13:31:23Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7122bc7
- Parents:
- 666773c
- Location:
- uspace/srv/console
- Files:
-
- 4 edited
-
console.c (modified) (9 diffs)
-
gcons.c (modified) (3 diffs)
-
screenbuffer.c (modified) (6 diffs)
-
screenbuffer.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.
