Changes in uspace/srv/hid/console/console.c [111d2d6:2f90b46] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
r111d2d6 r2f90b46 36 36 #include <stdio.h> 37 37 #include <adt/prodcons.h> 38 #include <i o/input.h>38 #include <ipc/input.h> 39 39 #include <ipc/console.h> 40 40 #include <ipc/vfs.h> … … 43 43 #include <loc.h> 44 44 #include <event.h> 45 #include <io/kbd_event.h>46 45 #include <io/keycode.h> 47 #include < io/chargrid.h>48 #include < io/console.h>49 #include <i o/output.h>46 #include <screenbuffer.h> 47 #include <fb.h> 48 #include <imgmap.h> 50 49 #include <align.h> 51 50 #include <malloc.h> 52 51 #include <as.h> 53 52 #include <fibril_synch.h> 53 #include "images.h" 54 54 #include "console.h" 55 55 … … 57 57 #define NAMESPACE "term" 58 58 59 #define UTF8_CHAR_BUFFER_SIZE (STR_BOUNDS(1) + 1) 59 #define CONSOLE_TOP 66 60 #define CONSOLE_MARGIN 12 61 62 #define STATE_START 100 63 #define STATE_TOP 8 64 #define STATE_SPACE 4 65 #define STATE_WIDTH 48 66 #define STATE_HEIGHT 48 67 68 typedef enum { 69 CONS_DISCONNECTED = 0, 70 CONS_DISCONNECTED_SELECTED, 71 CONS_SELECTED, 72 CONS_IDLE, 73 CONS_DATA, 74 CONS_KERNEL, 75 CONS_LAST 76 } console_state_t; 60 77 61 78 typedef struct { 62 atomic_t refcnt; /**< Connection reference count */ 63 prodcons_t input_pc; /**< Incoming keyboard events */ 64 65 /** 66 * Not yet sent bytes of last char event. 67 */ 68 char char_remains[UTF8_CHAR_BUFFER_SIZE]; 69 size_t char_remains_len; /**< Number of not yet sent bytes. */ 70 71 fibril_mutex_t mtx; /**< Lock protecting mutable fields */ 72 73 size_t index; /**< Console index */ 74 service_id_t dsid; /**< Service handle */ 75 76 sysarg_t cols; /**< Number of columns */ 77 sysarg_t rows; /**< Number of rows */ 78 console_caps_t ccaps; /**< Console capabilities */ 79 80 chargrid_t *frontbuf; /**< Front buffer */ 81 frontbuf_handle_t fbid; /**< Front buffer handle */ 79 atomic_t refcnt; /**< Connection reference count */ 80 prodcons_t input_pc; /**< Incoming keyboard events */ 81 82 fibril_mutex_t mtx; /**< Lock protecting mutable fields */ 83 84 size_t index; /**< Console index */ 85 console_state_t state; /**< Console state */ 86 service_id_t dsid; /**< Service handle */ 87 88 vp_handle_t state_vp; /**< State icon viewport */ 89 sysarg_t cols; /**< Number of columns */ 90 sysarg_t rows; /**< Number of rows */ 91 console_caps_t ccaps; /**< Console capabilities */ 92 93 screenbuffer_t *frontbuf; /**< Front buffer */ 94 frontbuf_handle_t fbid; /**< Front buffer handle */ 82 95 } console_t; 83 96 84 /** Input server proxy */ 85 static input_t *input; 86 87 /** Session to the output server */ 88 static async_sess_t *output_sess; 89 90 /** Output dimensions */ 91 static sysarg_t cols; 92 static sysarg_t rows; 97 typedef enum { 98 GRAPHICS_NONE = 0, 99 GRAPHICS_BASIC = 1, 100 GRAPHICS_FULL = 2 101 } graphics_state_t; 102 103 /** Current console state */ 104 static graphics_state_t graphics_state = GRAPHICS_NONE; 105 106 /** State icons */ 107 static imagemap_handle_t state_icons[CONS_LAST]; 108 109 /** Session to the input server */ 110 static async_sess_t *input_sess; 111 112 /** Session to the framebuffer server */ 113 static async_sess_t *fb_sess; 114 115 /** Framebuffer resolution */ 116 static sysarg_t xres; 117 static sysarg_t yres; 93 118 94 119 /** Array of data for virtual consoles */ … … 102 127 static console_t *kernel_console = &consoles[KERNEL_CONSOLE]; 103 128 104 static int input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t); 105 static int input_ev_move(input_t *, int, int); 106 static int input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned); 107 static int input_ev_button(input_t *, int, int); 108 109 static input_ev_ops_t input_ev_ops = { 110 .key = input_ev_key, 111 .move = input_ev_move, 112 .abs_move = input_ev_abs_move, 113 .button = input_ev_button 114 }; 129 static imgmap_t *logo_img; 130 static imgmap_t *nameic_img; 131 132 static imgmap_t *anim_1_img; 133 static imgmap_t *anim_2_img; 134 static imgmap_t *anim_3_img; 135 static imgmap_t *anim_4_img; 136 137 static imagemap_handle_t anim_1; 138 static imagemap_handle_t anim_2; 139 static imagemap_handle_t anim_3; 140 static imagemap_handle_t anim_4; 141 142 static sequence_handle_t anim_seq; 143 144 static imgmap_t *cons_data_img; 145 static imgmap_t *cons_dis_img; 146 static imgmap_t *cons_dis_sel_img; 147 static imgmap_t *cons_idle_img; 148 static imgmap_t *cons_kernel_img; 149 static imgmap_t *cons_sel_img; 150 151 static vp_handle_t logo_vp; 152 static imagemap_handle_t logo_handle; 153 154 static vp_handle_t nameic_vp; 155 static imagemap_handle_t nameic_handle; 156 157 static vp_handle_t screen_vp; 158 static vp_handle_t console_vp; 159 160 struct { 161 sysarg_t x; 162 sysarg_t y; 163 164 sysarg_t btn_x; 165 sysarg_t btn_y; 166 167 bool pressed; 168 } mouse; 169 170 static void cons_redraw_state(console_t *cons) 171 { 172 if (graphics_state == GRAPHICS_FULL) { 173 fibril_mutex_lock(&cons->mtx); 174 175 fb_vp_imagemap_damage(fb_sess, cons->state_vp, 176 state_icons[cons->state], 0, 0, STATE_WIDTH, STATE_HEIGHT); 177 178 if ((cons->state != CONS_DISCONNECTED) && 179 (cons->state != CONS_KERNEL) && 180 (cons->state != CONS_DISCONNECTED_SELECTED)) { 181 char data[5]; 182 snprintf(data, 5, "%zu", cons->index + 1); 183 184 for (size_t i = 0; data[i] != 0; i++) 185 fb_vp_putchar(fb_sess, cons->state_vp, i + 2, 1, data[i]); 186 } 187 188 fibril_mutex_unlock(&cons->mtx); 189 } 190 } 191 192 static void cons_kernel_sequence_start(console_t *cons) 193 { 194 if (graphics_state == GRAPHICS_FULL) { 195 fibril_mutex_lock(&cons->mtx); 196 197 fb_vp_sequence_start(fb_sess, cons->state_vp, anim_seq); 198 fb_vp_imagemap_damage(fb_sess, cons->state_vp, 199 state_icons[cons->state], 0, 0, STATE_WIDTH, STATE_HEIGHT); 200 201 fibril_mutex_unlock(&cons->mtx); 202 } 203 } 204 205 static void cons_update_state(console_t *cons, console_state_t state) 206 { 207 bool update = false; 208 209 fibril_mutex_lock(&cons->mtx); 210 211 if (cons->state != state) { 212 cons->state = state; 213 update = true; 214 } 215 216 fibril_mutex_unlock(&cons->mtx); 217 218 if (update) 219 cons_redraw_state(cons); 220 } 221 222 static void cons_notify_data(console_t *cons) 223 { 224 fibril_mutex_lock(&switch_mtx); 225 226 if (cons != active_console) 227 cons_update_state(cons, CONS_DATA); 228 229 fibril_mutex_unlock(&switch_mtx); 230 } 231 232 static void cons_notify_connect(console_t *cons) 233 { 234 fibril_mutex_lock(&switch_mtx); 235 236 if (cons == active_console) 237 cons_update_state(cons, CONS_SELECTED); 238 else 239 cons_update_state(cons, CONS_IDLE); 240 241 fibril_mutex_unlock(&switch_mtx); 242 } 243 244 static void cons_notify_disconnect(console_t *cons) 245 { 246 fibril_mutex_lock(&switch_mtx); 247 248 if (cons == active_console) 249 cons_update_state(cons, CONS_DISCONNECTED_SELECTED); 250 else 251 cons_update_state(cons, CONS_DISCONNECTED); 252 253 fibril_mutex_unlock(&switch_mtx); 254 } 115 255 116 256 static void cons_update(console_t *cons) … … 120 260 121 261 if ((cons == active_console) && (active_console != kernel_console)) { 122 output_update(output_sess, cons->fbid);123 output_cursor_update(output_sess, cons->fbid);262 fb_vp_update(fb_sess, console_vp, cons->fbid); 263 fb_vp_cursor_update(fb_sess, console_vp, cons->fbid); 124 264 } 125 265 … … 134 274 135 275 if ((cons == active_console) && (active_console != kernel_console)) 136 output_cursor_update(output_sess, cons->fbid);276 fb_vp_cursor_update(fb_sess, console_vp, cons->fbid); 137 277 138 278 fibril_mutex_unlock(&cons->mtx); … … 143 283 { 144 284 fibril_mutex_lock(&cons->mtx); 145 chargrid_clear(cons->frontbuf);285 screenbuffer_clear(cons->frontbuf); 146 286 fibril_mutex_unlock(&cons->mtx); 147 287 … … 149 289 } 150 290 151 static void cons_damage (console_t *cons)291 static void cons_damage_all(console_t *cons) 152 292 { 153 293 fibril_mutex_lock(&switch_mtx); … … 155 295 156 296 if ((cons == active_console) && (active_console != kernel_console)) { 157 output_damage(output_sess, cons->fbid, 0, 0, cons->cols,297 fb_vp_damage(fb_sess, console_vp, cons->fbid, 0, 0, cons->cols, 158 298 cons->rows); 159 output_cursor_update(output_sess, cons->fbid);299 fb_vp_cursor_update(fb_sess, console_vp, cons->fbid); 160 300 } 161 301 … … 174 314 175 315 if (cons == kernel_console) { 176 output_yield(output_sess);316 fb_yield(fb_sess); 177 317 if (!console_kcon()) { 178 output_claim(output_sess);318 fb_claim(fb_sess); 179 319 fibril_mutex_unlock(&switch_mtx); 180 320 return; … … 183 323 184 324 if (active_console == kernel_console) 185 output_claim(output_sess);325 fb_claim(fb_sess); 186 326 187 327 prev_console = active_console; 188 328 active_console = cons; 189 329 330 if (prev_console->state == CONS_DISCONNECTED_SELECTED) 331 cons_update_state(prev_console, CONS_DISCONNECTED); 332 else 333 cons_update_state(prev_console, CONS_IDLE); 334 335 if ((cons->state == CONS_DISCONNECTED) || 336 (cons->state == CONS_DISCONNECTED_SELECTED)) 337 cons_update_state(cons, CONS_DISCONNECTED_SELECTED); 338 else 339 cons_update_state(cons, CONS_SELECTED); 340 190 341 fibril_mutex_unlock(&switch_mtx); 191 342 192 cons_damage (cons);343 cons_damage_all(cons); 193 344 } 194 345 … … 196 347 { 197 348 fibril_mutex_lock(&switch_mtx); 198 349 199 350 console_t *active_uspace = active_console; 200 if (active_uspace == kernel_console) 351 if (active_uspace == kernel_console) { 201 352 active_uspace = prev_console; 202 353 } 203 354 assert(active_uspace != kernel_console); 204 355 205 356 fibril_mutex_unlock(&switch_mtx); 206 357 207 358 return active_uspace; 208 359 } 209 360 210 static int input_ev_key(input_t *input, kbd_event_type_t type, keycode_t key, 211 keymod_t mods, wchar_t c) 212 { 213 if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) && 214 ((mods & KM_CTRL) == 0)) { 215 cons_switch(&consoles[key - KC_F1]); 216 } else { 217 /* Got key press/release event */ 218 kbd_event_t *event = 219 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 220 if (event == NULL) { 221 return ENOMEM; 222 } 223 224 link_initialize(&event->link); 225 event->type = type; 226 event->key = key; 227 event->mods = mods; 228 event->c = c; 229 230 /* 231 * Kernel console does not read events 232 * from us, so we will redirect them 233 * to the (last) active userspace console 234 * if necessary. 235 */ 236 console_t *target_console = cons_get_active_uspace(); 237 238 prodcons_produce(&target_console->input_pc, 239 &event->link); 240 } 241 242 return EOK; 243 } 244 245 static int input_ev_move(input_t *input, int dx, int dy) 246 { 247 return EOK; 248 } 249 250 static int input_ev_abs_move(input_t *input, unsigned x , unsigned y, 251 unsigned max_x, unsigned max_y) 252 { 253 return EOK; 254 } 255 256 static int input_ev_button(input_t *input, int bnum, int bpress) 257 { 258 return EOK; 361 static ssize_t limit(ssize_t val, ssize_t lo, ssize_t hi) 362 { 363 if (val > hi) 364 return hi; 365 366 if (val < lo) 367 return lo; 368 369 return val; 370 } 371 372 static void cons_mouse_move(sysarg_t dx, sysarg_t dy) 373 { 374 ssize_t sx = (ssize_t) dx; 375 ssize_t sy = (ssize_t) dy; 376 377 mouse.x = limit(mouse.x + sx, 0, xres); 378 mouse.y = limit(mouse.y + sy, 0, yres); 379 380 fb_pointer_update(fb_sess, mouse.x, mouse.y, true); 381 } 382 383 static console_t *cons_find_icon(sysarg_t x, sysarg_t y) 384 { 385 sysarg_t status_start = 386 STATE_START + (xres - 800) / 2 + CONSOLE_MARGIN; 387 388 if ((y < STATE_TOP) || (y >= STATE_TOP + STATE_HEIGHT)) 389 return NULL; 390 391 if (x < status_start) 392 return NULL; 393 394 if (x >= status_start + (STATE_WIDTH + STATE_SPACE) * CONSOLE_COUNT) 395 return NULL; 396 397 if (((x - status_start) % (STATE_WIDTH + STATE_SPACE)) >= STATE_WIDTH) 398 return NULL; 399 400 sysarg_t btn = (x - status_start) / (STATE_WIDTH + STATE_SPACE); 401 402 if (btn < CONSOLE_COUNT) 403 return consoles + btn; 404 405 return NULL; 406 } 407 408 /** Handle mouse click 409 * 410 * @param state Button state (true - pressed, false - depressed) 411 * 412 */ 413 static console_t *cons_mouse_button(bool state) 414 { 415 if (graphics_state != GRAPHICS_FULL) 416 return NULL; 417 418 if (state) { 419 console_t *cons = cons_find_icon(mouse.x, mouse.y); 420 if (cons != NULL) { 421 mouse.btn_x = mouse.x; 422 mouse.btn_y = mouse.y; 423 mouse.pressed = true; 424 } 425 426 return NULL; 427 } 428 429 if ((!state) && (!mouse.pressed)) 430 return NULL; 431 432 console_t *cons = cons_find_icon(mouse.x, mouse.y); 433 if (cons == cons_find_icon(mouse.btn_x, mouse.btn_y)) 434 return cons; 435 436 mouse.pressed = false; 437 return NULL; 438 } 439 440 static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 441 { 442 /* Ignore parameters, the connection is already opened */ 443 while (true) { 444 ipc_call_t call; 445 ipc_callid_t callid = async_get_call(&call); 446 447 if (!IPC_GET_IMETHOD(call)) { 448 /* TODO: Handle hangup */ 449 async_hangup(input_sess); 450 return; 451 } 452 453 kbd_event_type_t type; 454 keycode_t key; 455 keymod_t mods; 456 wchar_t c; 457 458 switch (IPC_GET_IMETHOD(call)) { 459 case INPUT_EVENT_KEY: 460 type = IPC_GET_ARG1(call); 461 key = IPC_GET_ARG2(call); 462 mods = IPC_GET_ARG3(call); 463 c = IPC_GET_ARG4(call); 464 465 if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) && 466 ((mods & KM_CTRL) == 0)) 467 cons_switch(&consoles[key - KC_F1]); 468 else { 469 /* Got key press/release event */ 470 kbd_event_t *event = 471 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 472 if (event == NULL) { 473 async_answer_0(callid, ENOMEM); 474 break; 475 } 476 477 link_initialize(&event->link); 478 event->type = type; 479 event->key = key; 480 event->mods = mods; 481 event->c = c; 482 483 /* 484 * Kernel console does not read events 485 * from us, so we will redirect them 486 * to the (last) active userspace console 487 * if necessary. 488 */ 489 console_t *target_console = cons_get_active_uspace(); 490 491 prodcons_produce(&target_console->input_pc, 492 &event->link); 493 } 494 495 async_answer_0(callid, EOK); 496 break; 497 case INPUT_EVENT_MOVE: 498 cons_mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 499 async_answer_0(callid, EOK); 500 break; 501 case INPUT_EVENT_BUTTON: 502 /* Got pointer button press/release event */ 503 if (IPC_GET_ARG1(call) == 1) { 504 console_t *cons = 505 cons_mouse_button((bool) IPC_GET_ARG2(call)); 506 if (cons != NULL) 507 cons_switch(cons); 508 } 509 async_answer_0(callid, EOK); 510 break; 511 default: 512 async_answer_0(callid, EINVAL); 513 } 514 } 259 515 } 260 516 … … 268 524 switch (ch) { 269 525 case '\n': 270 updated = chargrid_newline(cons->frontbuf);526 updated = screenbuffer_newline(cons->frontbuf); 271 527 break; 272 528 case '\r': 273 529 break; 274 530 case '\t': 275 updated = chargrid_tabstop(cons->frontbuf, 8);531 updated = screenbuffer_tabstop(cons->frontbuf, 8); 276 532 break; 277 533 case '\b': 278 updated = chargrid_backspace(cons->frontbuf);534 updated = screenbuffer_backspace(cons->frontbuf); 279 535 break; 280 536 default: 281 updated = chargrid_putchar(cons->frontbuf, ch, true);537 updated = screenbuffer_putchar(cons->frontbuf, ch, true); 282 538 } 283 539 … … 291 547 { 292 548 fibril_mutex_lock(&cons->mtx); 293 chargrid_set_cursor(cons->frontbuf, col, row);549 screenbuffer_set_cursor(cons->frontbuf, col, row); 294 550 fibril_mutex_unlock(&cons->mtx); 295 551 … … 300 556 { 301 557 fibril_mutex_lock(&cons->mtx); 302 chargrid_set_cursor_visibility(cons->frontbuf, visible);558 screenbuffer_set_cursor_visibility(cons->frontbuf, visible); 303 559 fibril_mutex_unlock(&cons->mtx); 304 560 … … 312 568 313 569 fibril_mutex_lock(&cons->mtx); 314 chargrid_get_cursor(cons->frontbuf, &col, &row);570 screenbuffer_get_cursor(cons->frontbuf, &col, &row); 315 571 fibril_mutex_unlock(&cons->mtx); 316 572 … … 335 591 async_answer_1(iid, EOK, size); 336 592 free(buf); 593 594 cons_notify_data(cons); 337 595 } 338 596 … … 355 613 356 614 size_t pos = 0; 357 358 /*359 * Read input from keyboard and copy it to the buffer.360 * We need to handle situation when wchar is split by 2 following361 * reads.362 */363 615 while (pos < size) { 364 /* Copy to the buffer remaining characters. */ 365 while ((pos < size) && (cons->char_remains_len > 0)) { 366 buf[pos] = cons->char_remains[0]; 616 link_t *link = prodcons_consume(&cons->input_pc); 617 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 618 619 if (event->type == KEY_PRESS) { 620 buf[pos] = event->c; 367 621 pos++; 368 369 /* Unshift the array. */ 370 for (size_t i = 1; i < cons->char_remains_len; i++) 371 cons->char_remains[i - 1] = cons->char_remains[i]; 372 373 cons->char_remains_len--; 374 } 375 376 /* Still not enough? Then get another key from the queue. */ 377 if (pos < size) { 378 link_t *link = prodcons_consume(&cons->input_pc); 379 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 380 381 /* Accept key presses of printable chars only. */ 382 if ((event->type == KEY_PRESS) && (event->c != 0)) { 383 wchar_t tmp[2] = { event->c, 0 }; 384 wstr_to_str(cons->char_remains, UTF8_CHAR_BUFFER_SIZE, tmp); 385 cons->char_remains_len = str_size(cons->char_remains); 386 } 387 388 free(event); 389 } 622 } 623 624 free(event); 390 625 } 391 626 … … 398 633 { 399 634 fibril_mutex_lock(&cons->mtx); 400 chargrid_set_style(cons->frontbuf, style);635 screenbuffer_set_style(cons->frontbuf, style); 401 636 fibril_mutex_unlock(&cons->mtx); 402 637 } … … 406 641 { 407 642 fibril_mutex_lock(&cons->mtx); 408 chargrid_set_color(cons->frontbuf, bgcolor, fgcolor, attr);643 screenbuffer_set_color(cons->frontbuf, bgcolor, fgcolor, attr); 409 644 fibril_mutex_unlock(&cons->mtx); 410 645 } … … 414 649 { 415 650 fibril_mutex_lock(&cons->mtx); 416 chargrid_set_rgb_color(cons->frontbuf, bgcolor, fgcolor);651 screenbuffer_set_rgb_color(cons->frontbuf, bgcolor, fgcolor); 417 652 fibril_mutex_unlock(&cons->mtx); 418 653 } … … 446 681 } 447 682 448 if (atomic_postinc(&cons->refcnt) == 0) 683 if (atomic_postinc(&cons->refcnt) == 0) { 449 684 cons_set_cursor_visibility(cons, true); 685 cons_notify_connect(cons); 686 } 450 687 451 688 /* Accept the connection */ … … 456 693 ipc_callid_t callid = async_get_call(&call); 457 694 458 if (!IPC_GET_IMETHOD(call)) 695 if (!IPC_GET_IMETHOD(call)) { 696 if (atomic_postdec(&cons->refcnt) == 1) 697 cons_notify_disconnect(cons); 698 459 699 return; 700 } 460 701 461 702 switch (IPC_GET_IMETHOD(call)) { … … 513 754 } 514 755 515 static intinput_connect(const char *svc)756 static async_sess_t *input_connect(const char *svc) 516 757 { 517 758 async_sess_t *sess; … … 519 760 520 761 int rc = loc_service_get_id(svc, &dsid, 0); 521 if (rc != EOK) { 522 printf("%s: Input service %s not found\n", NAME, svc); 523 return rc; 524 } 525 526 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 527 if (sess == NULL) { 528 printf("%s: Unable to connect to input service %s\n", NAME, 529 svc); 530 return EIO; 531 } 532 533 rc = input_open(sess, &input_ev_ops, NULL, &input); 762 if (rc == EOK) { 763 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 764 if (sess == NULL) { 765 printf("%s: Unable to connect to input service %s\n", NAME, 766 svc); 767 return NULL; 768 } 769 } else 770 return NULL; 771 772 async_exch_t *exch = async_exchange_begin(sess); 773 rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL); 774 async_exchange_end(exch); 775 534 776 if (rc != EOK) { 535 777 async_hangup(sess); 536 printf("%s: Unable to c ommunicate withservice %s (%s)\n",778 printf("%s: Unable to create callback connection to service %s (%s)\n", 537 779 NAME, svc, str_error(rc)); 538 return rc;539 } 540 541 return EOK;780 return NULL; 781 } 782 783 return sess; 542 784 } 543 785 … … 547 789 } 548 790 549 static async_sess_t * output_connect(const char *svc)791 static async_sess_t *fb_connect(const char *svc) 550 792 { 551 793 async_sess_t *sess; … … 556 798 sess = loc_service_connect(EXCHANGE_SERIALIZE, dsid, 0); 557 799 if (sess == NULL) { 558 printf("%s: Unable to connect to outputservice %s\n",800 printf("%s: Unable to connect to framebuffer service %s\n", 559 801 NAME, svc); 560 802 return NULL; … … 566 808 } 567 809 568 static bool console_srv_init(char *input_svc, char *output_svc) 569 { 570 int rc; 810 static bool console_srv_init(char *input_svc, char *fb_svc) 811 { 812 /* Avoid double initialization */ 813 if (graphics_state != GRAPHICS_NONE) 814 return false; 571 815 572 816 /* Connect to input service */ 573 rc= input_connect(input_svc);574 if ( rc != EOK)817 input_sess = input_connect(input_svc); 818 if (input_sess == NULL) 575 819 return false; 576 820 577 /* Connect to outputservice */578 output_sess = output_connect(output_svc);579 if ( output_sess == NULL)821 /* Connect to framebuffer service */ 822 fb_sess = fb_connect(fb_svc); 823 if (fb_sess == NULL) 580 824 return false; 581 825 582 826 /* Register server */ 583 827 async_set_client_connection(client_connection); 584 rc = loc_server_register(NAME);828 int rc = loc_server_register(NAME); 585 829 if (rc != EOK) { 586 830 printf("%s: Unable to register server (%s)\n", NAME, … … 589 833 } 590 834 591 output_get_dimensions(output_sess, &cols, &rows); 592 output_set_style(output_sess, STYLE_NORMAL); 835 fb_get_resolution(fb_sess, &xres, &yres); 836 837 /* Initialize the screen */ 838 screen_vp = fb_vp_create(fb_sess, 0, 0, xres, yres); 839 840 if ((xres >= 800) && (yres >= 600)) { 841 logo_vp = fb_vp_create(fb_sess, xres - 66, 2, 64, 60); 842 logo_img = imgmap_decode_tga((void *) helenos_tga, 843 helenos_tga_size, IMGMAP_FLAG_SHARED); 844 logo_handle = fb_imagemap_create(fb_sess, logo_img); 845 846 nameic_vp = fb_vp_create(fb_sess, 5, 17, 100, 26); 847 nameic_img = imgmap_decode_tga((void *) nameic_tga, 848 nameic_tga_size, IMGMAP_FLAG_SHARED); 849 nameic_handle = fb_imagemap_create(fb_sess, nameic_img); 850 851 cons_data_img = imgmap_decode_tga((void *) cons_data_tga, 852 cons_data_tga_size, IMGMAP_FLAG_SHARED); 853 cons_dis_img = imgmap_decode_tga((void *) cons_dis_tga, 854 cons_dis_tga_size, IMGMAP_FLAG_SHARED); 855 cons_dis_sel_img = imgmap_decode_tga((void *) cons_dis_sel_tga, 856 cons_dis_sel_tga_size, IMGMAP_FLAG_SHARED); 857 cons_idle_img = imgmap_decode_tga((void *) cons_idle_tga, 858 cons_idle_tga_size, IMGMAP_FLAG_SHARED); 859 cons_kernel_img = imgmap_decode_tga((void *) cons_kernel_tga, 860 cons_kernel_tga_size, IMGMAP_FLAG_SHARED); 861 cons_sel_img = imgmap_decode_tga((void *) cons_sel_tga, 862 cons_sel_tga_size, IMGMAP_FLAG_SHARED); 863 864 state_icons[CONS_DISCONNECTED] = 865 fb_imagemap_create(fb_sess, cons_dis_img); 866 state_icons[CONS_DISCONNECTED_SELECTED] = 867 fb_imagemap_create(fb_sess, cons_dis_sel_img); 868 state_icons[CONS_SELECTED] = 869 fb_imagemap_create(fb_sess, cons_sel_img); 870 state_icons[CONS_IDLE] = 871 fb_imagemap_create(fb_sess, cons_idle_img); 872 state_icons[CONS_DATA] = 873 fb_imagemap_create(fb_sess, cons_data_img); 874 state_icons[CONS_KERNEL] = 875 fb_imagemap_create(fb_sess, cons_kernel_img); 876 877 anim_1_img = imgmap_decode_tga((void *) anim_1_tga, 878 anim_1_tga_size, IMGMAP_FLAG_SHARED); 879 anim_2_img = imgmap_decode_tga((void *) anim_2_tga, 880 anim_2_tga_size, IMGMAP_FLAG_SHARED); 881 anim_3_img = imgmap_decode_tga((void *) anim_3_tga, 882 anim_3_tga_size, IMGMAP_FLAG_SHARED); 883 anim_4_img = imgmap_decode_tga((void *) anim_4_tga, 884 anim_4_tga_size, IMGMAP_FLAG_SHARED); 885 886 anim_1 = fb_imagemap_create(fb_sess, anim_1_img); 887 anim_2 = fb_imagemap_create(fb_sess, anim_2_img); 888 anim_3 = fb_imagemap_create(fb_sess, anim_3_img); 889 anim_4 = fb_imagemap_create(fb_sess, anim_4_img); 890 891 anim_seq = fb_sequence_create(fb_sess); 892 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_1); 893 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_2); 894 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_3); 895 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_4); 896 897 console_vp = fb_vp_create(fb_sess, CONSOLE_MARGIN, CONSOLE_TOP, 898 xres - 2 * CONSOLE_MARGIN, yres - (CONSOLE_TOP + CONSOLE_MARGIN)); 899 900 fb_vp_clear(fb_sess, screen_vp); 901 fb_vp_imagemap_damage(fb_sess, logo_vp, logo_handle, 902 0, 0, 64, 60); 903 fb_vp_imagemap_damage(fb_sess, nameic_vp, nameic_handle, 904 0, 0, 100, 26); 905 906 graphics_state = GRAPHICS_FULL; 907 } else { 908 console_vp = screen_vp; 909 graphics_state = GRAPHICS_BASIC; 910 } 911 912 fb_vp_set_style(fb_sess, console_vp, STYLE_NORMAL); 913 fb_vp_clear(fb_sess, console_vp); 914 915 sysarg_t cols; 916 sysarg_t rows; 917 fb_vp_get_dimensions(fb_sess, console_vp, &cols, &rows); 593 918 594 919 console_caps_t ccaps; 595 output_get_caps(output_sess, &ccaps); 920 fb_vp_get_caps(fb_sess, console_vp, &ccaps); 921 922 mouse.x = xres / 2; 923 mouse.y = yres / 2; 924 mouse.pressed = false; 596 925 597 926 /* Inititalize consoles */ … … 601 930 fibril_mutex_initialize(&consoles[i].mtx); 602 931 prodcons_initialize(&consoles[i].input_pc); 603 consoles[i].char_remains_len = 0; 604 605 if (i == KERNEL_CONSOLE) 932 933 if (graphics_state == GRAPHICS_FULL) { 934 /* Create state buttons */ 935 consoles[i].state_vp = 936 fb_vp_create(fb_sess, STATE_START + (xres - 800) / 2 + 937 CONSOLE_MARGIN + i * (STATE_WIDTH + STATE_SPACE), 938 STATE_TOP, STATE_WIDTH, STATE_HEIGHT); 939 } 940 941 if (i == KERNEL_CONSOLE) { 942 consoles[i].state = CONS_KERNEL; 943 cons_redraw_state(&consoles[i]); 944 cons_kernel_sequence_start(&consoles[i]); 606 945 continue; 946 } 947 948 if (i == 0) 949 consoles[i].state = CONS_DISCONNECTED_SELECTED; 950 else 951 consoles[i].state = CONS_DISCONNECTED; 607 952 608 953 consoles[i].cols = cols; … … 610 955 consoles[i].ccaps = ccaps; 611 956 consoles[i].frontbuf = 612 chargrid_create(cols, rows, CHARGRID_FLAG_SHARED);957 screenbuffer_create(cols, rows, SCREENBUFFER_FLAG_SHARED); 613 958 614 959 if (consoles[i].frontbuf == NULL) { … … 617 962 } 618 963 619 consoles[i].fbid = output_frontbuf_create(output_sess, 620 consoles[i].frontbuf); 964 consoles[i].fbid = fb_frontbuf_create(fb_sess, consoles[i].frontbuf); 621 965 if (consoles[i].fbid == 0) { 622 966 printf("%s: Unable to create frontbuffer %zu\n", NAME, i); … … 624 968 } 625 969 970 cons_redraw_state(&consoles[i]); 971 626 972 char vc[LOC_NAME_MAXLEN + 1]; 627 973 snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i); … … 632 978 } 633 979 } 634 635 cons_damage(active_console);636 980 637 981 /* Receive kernel notifications */ … … 645 989 } 646 990 647 static void usage( char *name)648 { 649 printf("Usage: %s <input_dev> <output_dev>\n", name);991 static void usage(void) 992 { 993 printf("Usage: console <input_dev> <framebuffer_dev>\n"); 650 994 } 651 995 … … 653 997 { 654 998 if (argc < 3) { 655 usage( argv[0]);999 usage(); 656 1000 return -1; 657 1001 } … … 666 1010 async_manager(); 667 1011 668 /* Never reached */669 1012 return 0; 670 1013 }
Note:
See TracChangeset
for help on using the changeset viewer.