| 1 | /*
|
|---|
| 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup console
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #include <ipc/fb.h>
|
|---|
| 36 | #include <async.h>
|
|---|
| 37 | #include <async_obsolete.h>
|
|---|
| 38 | #include <stdio.h>
|
|---|
| 39 | #include <sys/mman.h>
|
|---|
| 40 | #include <str.h>
|
|---|
| 41 | #include <align.h>
|
|---|
| 42 | #include <bool.h>
|
|---|
| 43 |
|
|---|
| 44 | #include "console.h"
|
|---|
| 45 | #include "gcons.h"
|
|---|
| 46 |
|
|---|
| 47 | #define CONSOLE_TOP 66
|
|---|
| 48 | #define CONSOLE_MARGIN 6
|
|---|
| 49 |
|
|---|
| 50 | #define STATUS_START 110
|
|---|
| 51 | #define STATUS_TOP 8
|
|---|
| 52 | #define STATUS_SPACE 4
|
|---|
| 53 | #define STATUS_WIDTH 48
|
|---|
| 54 | #define STATUS_HEIGHT 48
|
|---|
| 55 |
|
|---|
| 56 | #define COLOR_MAIN 0xffffff
|
|---|
| 57 | #define COLOR_FOREGROUND 0x202020
|
|---|
| 58 | #define COLOR_BACKGROUND 0xffffff
|
|---|
| 59 |
|
|---|
| 60 | extern char _binary_gfx_helenos_ppm_start[0];
|
|---|
| 61 | extern int _binary_gfx_helenos_ppm_size;
|
|---|
| 62 | extern char _binary_gfx_nameic_ppm_start[0];
|
|---|
| 63 | extern int _binary_gfx_nameic_ppm_size;
|
|---|
| 64 |
|
|---|
| 65 | extern char _binary_gfx_anim_1_ppm_start[0];
|
|---|
| 66 | extern int _binary_gfx_anim_1_ppm_size;
|
|---|
| 67 | extern char _binary_gfx_anim_2_ppm_start[0];
|
|---|
| 68 | extern int _binary_gfx_anim_2_ppm_size;
|
|---|
| 69 | extern char _binary_gfx_anim_3_ppm_start[0];
|
|---|
| 70 | extern int _binary_gfx_anim_3_ppm_size;
|
|---|
| 71 | extern char _binary_gfx_anim_4_ppm_start[0];
|
|---|
| 72 | extern int _binary_gfx_anim_4_ppm_size;
|
|---|
| 73 |
|
|---|
| 74 | extern char _binary_gfx_cons_selected_ppm_start[0];
|
|---|
| 75 | extern int _binary_gfx_cons_selected_ppm_size;
|
|---|
| 76 | extern char _binary_gfx_cons_idle_ppm_start[0];
|
|---|
| 77 | extern int _binary_gfx_cons_idle_ppm_size;
|
|---|
| 78 | extern char _binary_gfx_cons_has_data_ppm_start[0];
|
|---|
| 79 | extern int _binary_gfx_cons_has_data_ppm_size;
|
|---|
| 80 | extern char _binary_gfx_cons_kernel_ppm_start[0];
|
|---|
| 81 | extern int _binary_gfx_cons_kernel_ppm_size;
|
|---|
| 82 |
|
|---|
| 83 | static bool use_gcons = false;
|
|---|
| 84 | static sysarg_t xres;
|
|---|
| 85 | static sysarg_t yres;
|
|---|
| 86 |
|
|---|
| 87 | enum butstate {
|
|---|
| 88 | CONS_DISCONNECTED = 0,
|
|---|
| 89 | CONS_SELECTED,
|
|---|
| 90 | CONS_IDLE,
|
|---|
| 91 | CONS_HAS_DATA,
|
|---|
| 92 | CONS_KERNEL,
|
|---|
| 93 | CONS_DISCONNECTED_SEL,
|
|---|
| 94 | CONS_LAST
|
|---|
| 95 | };
|
|---|
| 96 |
|
|---|
| 97 | static int console_vp;
|
|---|
| 98 | static int cstatus_vp[CONSOLE_COUNT];
|
|---|
| 99 | static enum butstate console_state[CONSOLE_COUNT];
|
|---|
| 100 |
|
|---|
| 101 | static int fbphone;
|
|---|
| 102 |
|
|---|
| 103 | /** List of pixmaps identifying these icons */
|
|---|
| 104 | static int ic_pixmaps[CONS_LAST] = {-1, -1, -1, -1, -1, -1};
|
|---|
| 105 | static int animation = -1;
|
|---|
| 106 |
|
|---|
| 107 | static size_t active_console = 0;
|
|---|
| 108 |
|
|---|
| 109 | static sysarg_t mouse_x = 0;
|
|---|
| 110 | static sysarg_t mouse_y= 0;
|
|---|
| 111 |
|
|---|
| 112 | static bool btn_pressed = false;
|
|---|
| 113 | static sysarg_t btn_x = 0;
|
|---|
| 114 | static sysarg_t btn_y = 0;
|
|---|
| 115 |
|
|---|
| 116 | static void vp_switch(int vp)
|
|---|
| 117 | {
|
|---|
| 118 | async_obsolete_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /** Create view port */
|
|---|
| 122 | static int vp_create(sysarg_t x, sysarg_t y, sysarg_t width, sysarg_t height)
|
|---|
| 123 | {
|
|---|
| 124 | return async_obsolete_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
|
|---|
| 125 | (width << 16) | height);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | static void clear(void)
|
|---|
| 129 | {
|
|---|
| 130 | async_obsolete_msg_0(fbphone, FB_CLEAR);
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
|
|---|
| 134 | {
|
|---|
| 135 | async_obsolete_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | /** Transparent putchar */
|
|---|
| 139 | static void tran_putch(wchar_t ch, sysarg_t col, sysarg_t row)
|
|---|
| 140 | {
|
|---|
| 141 | async_obsolete_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | /** Redraw the button showing state of a given console */
|
|---|
| 145 | static void redraw_state(size_t index)
|
|---|
| 146 | {
|
|---|
| 147 | vp_switch(cstatus_vp[index]);
|
|---|
| 148 |
|
|---|
| 149 | enum butstate state = console_state[index];
|
|---|
| 150 |
|
|---|
| 151 | if (ic_pixmaps[state] != -1)
|
|---|
| 152 | async_obsolete_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[index],
|
|---|
| 153 | ic_pixmaps[state]);
|
|---|
| 154 |
|
|---|
| 155 | if ((state != CONS_DISCONNECTED) && (state != CONS_KERNEL)
|
|---|
| 156 | && (state != CONS_DISCONNECTED_SEL)) {
|
|---|
| 157 |
|
|---|
| 158 | char data[5];
|
|---|
| 159 | snprintf(data, 5, "%zu", index + 1);
|
|---|
| 160 |
|
|---|
| 161 | size_t i;
|
|---|
| 162 | for (i = 0; data[i] != 0; i++)
|
|---|
| 163 | tran_putch(data[i], 2 + i, 1);
|
|---|
| 164 | }
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | /** Notification run on changing console (except kernel console) */
|
|---|
| 168 | void gcons_change_console(size_t index)
|
|---|
| 169 | {
|
|---|
| 170 | if (!use_gcons) {
|
|---|
| 171 | active_console = index;
|
|---|
| 172 | return;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | if (active_console == KERNEL_CONSOLE) {
|
|---|
| 176 | size_t i;
|
|---|
| 177 |
|
|---|
| 178 | for (i = 0; i < CONSOLE_COUNT; i++)
|
|---|
| 179 | redraw_state(i);
|
|---|
| 180 |
|
|---|
| 181 | if (animation != -1)
|
|---|
| 182 | async_obsolete_msg_1(fbphone, FB_ANIM_START, animation);
|
|---|
| 183 | } else {
|
|---|
| 184 | if (console_state[active_console] == CONS_DISCONNECTED_SEL)
|
|---|
| 185 | console_state[active_console] = CONS_DISCONNECTED;
|
|---|
| 186 | else
|
|---|
| 187 | console_state[active_console] = CONS_IDLE;
|
|---|
| 188 |
|
|---|
| 189 | redraw_state(active_console);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | active_console = index;
|
|---|
| 193 |
|
|---|
| 194 | if ((console_state[index] == CONS_DISCONNECTED)
|
|---|
| 195 | || (console_state[index] == CONS_DISCONNECTED_SEL))
|
|---|
| 196 | console_state[index] = CONS_DISCONNECTED_SEL;
|
|---|
| 197 | else
|
|---|
| 198 | console_state[index] = CONS_SELECTED;
|
|---|
| 199 |
|
|---|
| 200 | redraw_state(index);
|
|---|
| 201 | vp_switch(console_vp);
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | /** Notification function that gets called on new output to virtual console */
|
|---|
| 205 | void gcons_notify_char(size_t index)
|
|---|
| 206 | {
|
|---|
| 207 | if (!use_gcons)
|
|---|
| 208 | return;
|
|---|
| 209 |
|
|---|
| 210 | if ((index == active_console)
|
|---|
| 211 | || (console_state[index] == CONS_HAS_DATA))
|
|---|
| 212 | return;
|
|---|
| 213 |
|
|---|
| 214 | console_state[index] = CONS_HAS_DATA;
|
|---|
| 215 |
|
|---|
| 216 | if (active_console == KERNEL_CONSOLE)
|
|---|
| 217 | return;
|
|---|
| 218 |
|
|---|
| 219 | redraw_state(index);
|
|---|
| 220 | vp_switch(console_vp);
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | /** Notification function called on service disconnect from console */
|
|---|
| 224 | void gcons_notify_disconnect(size_t index)
|
|---|
| 225 | {
|
|---|
| 226 | if (!use_gcons)
|
|---|
| 227 | return;
|
|---|
| 228 |
|
|---|
| 229 | if (index == active_console)
|
|---|
| 230 | console_state[index] = CONS_DISCONNECTED_SEL;
|
|---|
| 231 | else
|
|---|
| 232 | console_state[index] = CONS_DISCONNECTED;
|
|---|
| 233 |
|
|---|
| 234 | if (active_console == KERNEL_CONSOLE)
|
|---|
| 235 | return;
|
|---|
| 236 |
|
|---|
| 237 | redraw_state(index);
|
|---|
| 238 | vp_switch(console_vp);
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | /** Notification function called on console connect */
|
|---|
| 242 | void gcons_notify_connect(size_t index)
|
|---|
| 243 | {
|
|---|
| 244 | if (!use_gcons)
|
|---|
| 245 | return;
|
|---|
| 246 |
|
|---|
| 247 | if (index == active_console)
|
|---|
| 248 | console_state[index] = CONS_SELECTED;
|
|---|
| 249 | else
|
|---|
| 250 | console_state[index] = CONS_IDLE;
|
|---|
| 251 |
|
|---|
| 252 | if (active_console == KERNEL_CONSOLE)
|
|---|
| 253 | return;
|
|---|
| 254 |
|
|---|
| 255 | redraw_state(index);
|
|---|
| 256 | vp_switch(console_vp);
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | /** Change to kernel console */
|
|---|
| 260 | void gcons_in_kernel(void)
|
|---|
| 261 | {
|
|---|
| 262 | if (animation != -1)
|
|---|
| 263 | async_obsolete_msg_1(fbphone, FB_ANIM_STOP, animation);
|
|---|
| 264 |
|
|---|
| 265 | active_console = KERNEL_CONSOLE;
|
|---|
| 266 | vp_switch(0);
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | /** Return x, where left <= x <= right && |a-x| == min(|a-x|) is smallest */
|
|---|
| 270 | static inline ssize_t limit(ssize_t a, ssize_t left, ssize_t right)
|
|---|
| 271 | {
|
|---|
| 272 | if (a < left)
|
|---|
| 273 | a = left;
|
|---|
| 274 |
|
|---|
| 275 | if (a >= right)
|
|---|
| 276 | a = right - 1;
|
|---|
| 277 |
|
|---|
| 278 | return a;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | /** Handle mouse move
|
|---|
| 282 | *
|
|---|
| 283 | * @param dx Delta X of mouse move
|
|---|
| 284 | * @param dy Delta Y of mouse move
|
|---|
| 285 | */
|
|---|
| 286 | void gcons_mouse_move(ssize_t dx, ssize_t dy)
|
|---|
| 287 | {
|
|---|
| 288 | ssize_t nx = (ssize_t) mouse_x + dx;
|
|---|
| 289 | ssize_t ny = (ssize_t) mouse_y + dy;
|
|---|
| 290 |
|
|---|
| 291 | /* Until gcons is initalized we don't have the screen resolution */
|
|---|
| 292 | if (xres == 0 || yres == 0)
|
|---|
| 293 | return;
|
|---|
| 294 |
|
|---|
| 295 | mouse_x = (size_t) limit(nx, 0, xres);
|
|---|
| 296 | mouse_y = (size_t) limit(ny, 0, yres);
|
|---|
| 297 |
|
|---|
| 298 | if (active_console != KERNEL_CONSOLE)
|
|---|
| 299 | async_obsolete_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | static int gcons_find_conbut(sysarg_t x, sysarg_t y)
|
|---|
| 303 | {
|
|---|
| 304 | sysarg_t status_start = STATUS_START + (xres - 800) / 2;
|
|---|
| 305 |
|
|---|
| 306 | if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
|
|---|
| 307 | return -1;
|
|---|
| 308 |
|
|---|
| 309 | if (x < status_start)
|
|---|
| 310 | return -1;
|
|---|
| 311 |
|
|---|
| 312 | if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
|
|---|
| 313 | return -1;
|
|---|
| 314 |
|
|---|
| 315 | if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
|
|---|
| 316 | return -1;
|
|---|
| 317 |
|
|---|
| 318 | sysarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
|
|---|
| 319 |
|
|---|
| 320 | if (btn < CONSOLE_COUNT)
|
|---|
| 321 | return btn;
|
|---|
| 322 |
|
|---|
| 323 | return -1;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | /** Handle mouse click
|
|---|
| 327 | *
|
|---|
| 328 | * @param state New state (true - pressed, false - depressed)
|
|---|
| 329 | *
|
|---|
| 330 | */
|
|---|
| 331 | int gcons_mouse_btn(bool state)
|
|---|
| 332 | {
|
|---|
| 333 | /* Ignore mouse clicks if no buttons
|
|---|
| 334 | are drawn at all */
|
|---|
| 335 | if (xres < 800)
|
|---|
| 336 | return -1;
|
|---|
| 337 |
|
|---|
| 338 | if (state) {
|
|---|
| 339 | int conbut = gcons_find_conbut(mouse_x, mouse_y);
|
|---|
| 340 | if (conbut != -1) {
|
|---|
| 341 | btn_pressed = true;
|
|---|
| 342 | btn_x = mouse_x;
|
|---|
| 343 | btn_y = mouse_y;
|
|---|
| 344 | }
|
|---|
| 345 | return -1;
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | if ((!state) && (!btn_pressed))
|
|---|
| 349 | return -1;
|
|---|
| 350 |
|
|---|
| 351 | btn_pressed = false;
|
|---|
| 352 |
|
|---|
| 353 | int conbut = gcons_find_conbut(mouse_x, mouse_y);
|
|---|
| 354 | if (conbut == gcons_find_conbut(btn_x, btn_y))
|
|---|
| 355 | return conbut;
|
|---|
| 356 |
|
|---|
| 357 | return -1;
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | /** Draw a PPM pixmap to framebuffer
|
|---|
| 361 | *
|
|---|
| 362 | * @param logo Pointer to PPM data
|
|---|
| 363 | * @param size Size of PPM data
|
|---|
| 364 | * @param x Coordinate of upper left corner
|
|---|
| 365 | * @param y Coordinate of upper left corner
|
|---|
| 366 | *
|
|---|
| 367 | */
|
|---|
| 368 | static void draw_pixmap(char *logo, size_t size, sysarg_t x, sysarg_t y)
|
|---|
| 369 | {
|
|---|
| 370 | /* Create area */
|
|---|
| 371 | char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
|
|---|
| 372 | MAP_ANONYMOUS, 0, 0);
|
|---|
| 373 | if (shm == MAP_FAILED)
|
|---|
| 374 | return;
|
|---|
| 375 |
|
|---|
| 376 | memcpy(shm, logo, size);
|
|---|
| 377 |
|
|---|
| 378 | /* Send area */
|
|---|
| 379 | int rc = async_obsolete_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm);
|
|---|
| 380 | if (rc)
|
|---|
| 381 | goto exit;
|
|---|
| 382 |
|
|---|
| 383 | rc = async_obsolete_share_out_start(fbphone, shm, PROTO_READ);
|
|---|
| 384 | if (rc)
|
|---|
| 385 | goto drop;
|
|---|
| 386 |
|
|---|
| 387 | /* Draw logo */
|
|---|
| 388 | async_obsolete_msg_2(fbphone, FB_DRAW_PPM, x, y);
|
|---|
| 389 |
|
|---|
| 390 | drop:
|
|---|
| 391 | /* Drop area */
|
|---|
| 392 | async_obsolete_msg_0(fbphone, FB_DROP_SHM);
|
|---|
| 393 |
|
|---|
| 394 | exit:
|
|---|
| 395 | /* Remove area */
|
|---|
| 396 | munmap(shm, size);
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | /** Redraws console graphics */
|
|---|
| 400 | void gcons_redraw_console(void)
|
|---|
| 401 | {
|
|---|
| 402 | if (!use_gcons)
|
|---|
| 403 | return;
|
|---|
| 404 |
|
|---|
| 405 | vp_switch(0);
|
|---|
| 406 | set_rgb_color(COLOR_MAIN, COLOR_MAIN);
|
|---|
| 407 | clear();
|
|---|
| 408 | draw_pixmap(_binary_gfx_helenos_ppm_start,
|
|---|
| 409 | (size_t) &_binary_gfx_helenos_ppm_size, xres - 66, 2);
|
|---|
| 410 | draw_pixmap(_binary_gfx_nameic_ppm_start,
|
|---|
| 411 | (size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
|
|---|
| 412 |
|
|---|
| 413 | unsigned int i;
|
|---|
| 414 | for (i = 0; i < CONSOLE_COUNT; i++)
|
|---|
| 415 | redraw_state(i);
|
|---|
| 416 |
|
|---|
| 417 | vp_switch(console_vp);
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | /** Creates a pixmap on framebuffer
|
|---|
| 421 | *
|
|---|
| 422 | * @param data PPM data
|
|---|
| 423 | * @param size PPM data size
|
|---|
| 424 | *
|
|---|
| 425 | * @return Pixmap identification
|
|---|
| 426 | *
|
|---|
| 427 | */
|
|---|
| 428 | static int make_pixmap(char *data, size_t size)
|
|---|
| 429 | {
|
|---|
| 430 | /* Create area */
|
|---|
| 431 | char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
|
|---|
| 432 | MAP_ANONYMOUS, 0, 0);
|
|---|
| 433 | if (shm == MAP_FAILED)
|
|---|
| 434 | return -1;
|
|---|
| 435 |
|
|---|
| 436 | memcpy(shm, data, size);
|
|---|
| 437 |
|
|---|
| 438 | int pxid = -1;
|
|---|
| 439 |
|
|---|
| 440 | /* Send area */
|
|---|
| 441 | int rc = async_obsolete_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm);
|
|---|
| 442 | if (rc)
|
|---|
| 443 | goto exit;
|
|---|
| 444 |
|
|---|
| 445 | rc = async_obsolete_share_out_start(fbphone, shm, PROTO_READ);
|
|---|
| 446 | if (rc)
|
|---|
| 447 | goto drop;
|
|---|
| 448 |
|
|---|
| 449 | /* Obtain pixmap */
|
|---|
| 450 | rc = async_obsolete_req_0_0(fbphone, FB_SHM2PIXMAP);
|
|---|
| 451 | if (rc < 0)
|
|---|
| 452 | goto drop;
|
|---|
| 453 |
|
|---|
| 454 | pxid = rc;
|
|---|
| 455 |
|
|---|
| 456 | drop:
|
|---|
| 457 | /* Drop area */
|
|---|
| 458 | async_obsolete_msg_0(fbphone, FB_DROP_SHM);
|
|---|
| 459 |
|
|---|
| 460 | exit:
|
|---|
| 461 | /* Remove area */
|
|---|
| 462 | munmap(shm, size);
|
|---|
| 463 |
|
|---|
| 464 | return pxid;
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | static void make_anim(void)
|
|---|
| 468 | {
|
|---|
| 469 | int an = async_obsolete_req_1_0(fbphone, FB_ANIM_CREATE,
|
|---|
| 470 | cstatus_vp[KERNEL_CONSOLE]);
|
|---|
| 471 | if (an < 0)
|
|---|
| 472 | return;
|
|---|
| 473 |
|
|---|
| 474 | int pm = make_pixmap(_binary_gfx_anim_1_ppm_start,
|
|---|
| 475 | (size_t) &_binary_gfx_anim_1_ppm_size);
|
|---|
| 476 | async_obsolete_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
|---|
| 477 |
|
|---|
| 478 | pm = make_pixmap(_binary_gfx_anim_2_ppm_start,
|
|---|
| 479 | (size_t) &_binary_gfx_anim_2_ppm_size);
|
|---|
| 480 | async_obsolete_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
|---|
| 481 |
|
|---|
| 482 | pm = make_pixmap(_binary_gfx_anim_3_ppm_start,
|
|---|
| 483 | (size_t) &_binary_gfx_anim_3_ppm_size);
|
|---|
| 484 | async_obsolete_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
|---|
| 485 |
|
|---|
| 486 | pm = make_pixmap(_binary_gfx_anim_4_ppm_start,
|
|---|
| 487 | (size_t) &_binary_gfx_anim_4_ppm_size);
|
|---|
| 488 | async_obsolete_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
|---|
| 489 |
|
|---|
| 490 | async_obsolete_msg_1(fbphone, FB_ANIM_START, an);
|
|---|
| 491 |
|
|---|
| 492 | animation = an;
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | /** Initialize nice graphical console environment */
|
|---|
| 496 | void gcons_init(int phone)
|
|---|
| 497 | {
|
|---|
| 498 | fbphone = phone;
|
|---|
| 499 |
|
|---|
| 500 | int rc = async_obsolete_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
|
|---|
| 501 | if (rc)
|
|---|
| 502 | return;
|
|---|
| 503 |
|
|---|
| 504 | if ((xres < 800) || (yres < 600))
|
|---|
| 505 | return;
|
|---|
| 506 |
|
|---|
| 507 | /* Create console viewport */
|
|---|
| 508 |
|
|---|
| 509 | /* Align width & height to character size */
|
|---|
| 510 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
|
|---|
| 511 | ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
|
|---|
| 512 | ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
|
|---|
| 513 |
|
|---|
| 514 | if (console_vp < 0)
|
|---|
| 515 | return;
|
|---|
| 516 |
|
|---|
| 517 | /* Create status buttons */
|
|---|
| 518 | sysarg_t status_start = STATUS_START + (xres - 800) / 2;
|
|---|
| 519 | size_t i;
|
|---|
| 520 | for (i = 0; i < CONSOLE_COUNT; i++) {
|
|---|
| 521 | cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
|
|---|
| 522 | i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
|
|---|
| 523 | STATUS_WIDTH, STATUS_HEIGHT);
|
|---|
| 524 |
|
|---|
| 525 | if (cstatus_vp[i] < 0)
|
|---|
| 526 | return;
|
|---|
| 527 |
|
|---|
| 528 | vp_switch(cstatus_vp[i]);
|
|---|
| 529 | set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND);
|
|---|
| 530 | }
|
|---|
| 531 |
|
|---|
| 532 | /* Initialize icons */
|
|---|
| 533 | ic_pixmaps[CONS_SELECTED] =
|
|---|
| 534 | make_pixmap(_binary_gfx_cons_selected_ppm_start,
|
|---|
| 535 | (size_t) &_binary_gfx_cons_selected_ppm_size);
|
|---|
| 536 | ic_pixmaps[CONS_IDLE] =
|
|---|
| 537 | make_pixmap(_binary_gfx_cons_idle_ppm_start,
|
|---|
| 538 | (size_t) &_binary_gfx_cons_idle_ppm_size);
|
|---|
| 539 | ic_pixmaps[CONS_HAS_DATA] =
|
|---|
| 540 | make_pixmap(_binary_gfx_cons_has_data_ppm_start,
|
|---|
| 541 | (size_t) &_binary_gfx_cons_has_data_ppm_size);
|
|---|
| 542 | ic_pixmaps[CONS_DISCONNECTED] =
|
|---|
| 543 | make_pixmap(_binary_gfx_cons_idle_ppm_start,
|
|---|
| 544 | (size_t) &_binary_gfx_cons_idle_ppm_size);
|
|---|
| 545 | ic_pixmaps[CONS_KERNEL] =
|
|---|
| 546 | make_pixmap(_binary_gfx_cons_kernel_ppm_start,
|
|---|
| 547 | (size_t) &_binary_gfx_cons_kernel_ppm_size);
|
|---|
| 548 | ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
|
|---|
| 549 |
|
|---|
| 550 | make_anim();
|
|---|
| 551 |
|
|---|
| 552 | use_gcons = true;
|
|---|
| 553 | console_state[0] = CONS_DISCONNECTED_SEL;
|
|---|
| 554 | console_state[KERNEL_CONSOLE] = CONS_KERNEL;
|
|---|
| 555 |
|
|---|
| 556 | vp_switch(console_vp);
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | /** @}
|
|---|
| 560 | */
|
|---|