[b1f51f0] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[b1f51f0] | 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 |
|
---|
[ce5bcb4] | 29 | /** @addtogroup console
|
---|
[1601f3c] | 30 | * @{
|
---|
[ce5bcb4] | 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[b1f51f0] | 35 | #include <ipc/fb.h>
|
---|
| 36 | #include <ipc/ipc.h>
|
---|
[e1c4849] | 37 | #include <async.h>
|
---|
| 38 | #include <stdio.h>
|
---|
[2def788] | 39 | #include <sys/mman.h>
|
---|
[19f857a] | 40 | #include <str.h>
|
---|
[a7d2d78] | 41 | #include <align.h>
|
---|
[424cd43] | 42 | #include <bool.h>
|
---|
[b1f51f0] | 43 |
|
---|
| 44 | #include "console.h"
|
---|
[e1c4849] | 45 | #include "gcons.h"
|
---|
[b1f51f0] | 46 |
|
---|
[1601f3c] | 47 | #define CONSOLE_TOP 66
|
---|
| 48 | #define CONSOLE_MARGIN 6
|
---|
[b1f51f0] | 49 |
|
---|
[1601f3c] | 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
|
---|
[b1f51f0] | 55 |
|
---|
[9f1362d4] | 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;
|
---|
[e1c4849] | 82 |
|
---|
[424cd43] | 83 | static bool use_gcons = false;
|
---|
| 84 | static ipcarg_t xres;
|
---|
| 85 | static ipcarg_t yres;
|
---|
[b1f51f0] | 86 |
|
---|
[a7d2d78] | 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 |
|
---|
[b1f51f0] | 97 | static int console_vp;
|
---|
| 98 | static int cstatus_vp[CONSOLE_COUNT];
|
---|
[a7d2d78] | 99 | static enum butstate console_state[CONSOLE_COUNT];
|
---|
[b1f51f0] | 100 |
|
---|
| 101 | static int fbphone;
|
---|
| 102 |
|
---|
[a7d2d78] | 103 | /** List of pixmaps identifying these icons */
|
---|
[00bb6965] | 104 | static int ic_pixmaps[CONS_LAST] = {-1, -1, -1, -1, -1, -1};
|
---|
[1fd7700] | 105 | static int animation = -1;
|
---|
[e1c4849] | 106 |
|
---|
[424cd43] | 107 | static size_t active_console = 0;
|
---|
| 108 |
|
---|
[9f1362d4] | 109 | static ipcarg_t mouse_x = 0;
|
---|
| 110 | static ipcarg_t mouse_y= 0;
|
---|
[424cd43] | 111 |
|
---|
[9f1362d4] | 112 | static bool btn_pressed = false;
|
---|
| 113 | static ipcarg_t btn_x = 0;
|
---|
| 114 | static ipcarg_t btn_y = 0;
|
---|
[e1c4849] | 115 |
|
---|
[b1f51f0] | 116 | static void vp_switch(int vp)
|
---|
| 117 | {
|
---|
[76fca31] | 118 | async_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp);
|
---|
[b1f51f0] | 119 | }
|
---|
| 120 |
|
---|
[e1c4849] | 121 | /** Create view port */
|
---|
[9f1362d4] | 122 | static int vp_create(ipcarg_t x, ipcarg_t y, ipcarg_t width, ipcarg_t height)
|
---|
[b1f51f0] | 123 | {
|
---|
[0cc4313] | 124 | return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
|
---|
| 125 | (width << 16) | height);
|
---|
[b1f51f0] | 126 | }
|
---|
| 127 |
|
---|
[e1c4849] | 128 | static void clear(void)
|
---|
[b1f51f0] | 129 | {
|
---|
[0cc4313] | 130 | async_msg_0(fbphone, FB_CLEAR);
|
---|
[b1f51f0] | 131 | }
|
---|
| 132 |
|
---|
[424cd43] | 133 | static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
|
---|
[e1c4849] | 134 | {
|
---|
[9805cde] | 135 | async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
|
---|
[e1c4849] | 136 | }
|
---|
| 137 |
|
---|
[d530237a] | 138 | /** Transparent putchar */
|
---|
[9f1362d4] | 139 | static void tran_putch(wchar_t ch, ipcarg_t col, ipcarg_t row)
|
---|
[e1c4849] | 140 | {
|
---|
[424cd43] | 141 | async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
|
---|
[e1c4849] | 142 | }
|
---|
| 143 |
|
---|
[d530237a] | 144 | /** Redraw the button showing state of a given console */
|
---|
[424cd43] | 145 | static void redraw_state(size_t index)
|
---|
[b1f51f0] | 146 | {
|
---|
[424cd43] | 147 | vp_switch(cstatus_vp[index]);
|
---|
| 148 |
|
---|
| 149 | enum butstate state = console_state[index];
|
---|
[1601f3c] | 150 |
|
---|
[a7d2d78] | 151 | if (ic_pixmaps[state] != -1)
|
---|
[424cd43] | 152 | async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[index],
|
---|
[0cc4313] | 153 | ic_pixmaps[state]);
|
---|
[1601f3c] | 154 |
|
---|
[424cd43] | 155 | if ((state != CONS_DISCONNECTED) && (state != CONS_KERNEL)
|
---|
| 156 | && (state != CONS_DISCONNECTED_SEL)) {
|
---|
| 157 |
|
---|
| 158 | char data[5];
|
---|
| 159 | snprintf(data, 5, "%u", index + 1);
|
---|
| 160 |
|
---|
| 161 | size_t i;
|
---|
| 162 | for (i = 0; data[i] != 0; i++)
|
---|
| 163 | tran_putch(data[i], 2 + i, 1);
|
---|
[1601f3c] | 164 | }
|
---|
[b1f51f0] | 165 | }
|
---|
| 166 |
|
---|
[a7d2d78] | 167 | /** Notification run on changing console (except kernel console) */
|
---|
[424cd43] | 168 | void gcons_change_console(size_t index)
|
---|
[b1f51f0] | 169 | {
|
---|
| 170 | if (!use_gcons)
|
---|
| 171 | return;
|
---|
[1601f3c] | 172 |
|
---|
[a7d2d78] | 173 | if (active_console == KERNEL_CONSOLE) {
|
---|
[424cd43] | 174 | size_t i;
|
---|
| 175 |
|
---|
[00bb6965] | 176 | for (i = 0; i < CONSOLE_COUNT; i++)
|
---|
[a7d2d78] | 177 | redraw_state(i);
|
---|
[424cd43] | 178 |
|
---|
[70178b74] | 179 | if (animation != -1)
|
---|
[0cc4313] | 180 | async_msg_1(fbphone, FB_ANIM_START, animation);
|
---|
[a7d2d78] | 181 | } else {
|
---|
| 182 | if (console_state[active_console] == CONS_DISCONNECTED_SEL)
|
---|
| 183 | console_state[active_console] = CONS_DISCONNECTED;
|
---|
| 184 | else
|
---|
| 185 | console_state[active_console] = CONS_IDLE;
|
---|
[424cd43] | 186 |
|
---|
[a7d2d78] | 187 | redraw_state(active_console);
|
---|
| 188 | }
|
---|
[1601f3c] | 189 |
|
---|
[424cd43] | 190 | active_console = index;
|
---|
| 191 |
|
---|
| 192 | if ((console_state[index] == CONS_DISCONNECTED)
|
---|
| 193 | || (console_state[index] == CONS_DISCONNECTED_SEL))
|
---|
| 194 | console_state[index] = CONS_DISCONNECTED_SEL;
|
---|
| 195 | else
|
---|
| 196 | console_state[index] = CONS_SELECTED;
|
---|
[1601f3c] | 197 |
|
---|
[424cd43] | 198 | redraw_state(index);
|
---|
[b1f51f0] | 199 | vp_switch(console_vp);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
[429acb9] | 202 | /** Notification function that gets called on new output to virtual console */
|
---|
[424cd43] | 203 | void gcons_notify_char(size_t index)
|
---|
[b1f51f0] | 204 | {
|
---|
| 205 | if (!use_gcons)
|
---|
| 206 | return;
|
---|
[1601f3c] | 207 |
|
---|
[424cd43] | 208 | if ((index == active_console)
|
---|
| 209 | || (console_state[index] == CONS_HAS_DATA))
|
---|
[d6cc453] | 210 | return;
|
---|
[1601f3c] | 211 |
|
---|
[424cd43] | 212 | console_state[index] = CONS_HAS_DATA;
|
---|
[1601f3c] | 213 |
|
---|
[a7d2d78] | 214 | if (active_console == KERNEL_CONSOLE)
|
---|
[429acb9] | 215 | return;
|
---|
[1601f3c] | 216 |
|
---|
[424cd43] | 217 | redraw_state(index);
|
---|
[b1f51f0] | 218 | vp_switch(console_vp);
|
---|
[a7d2d78] | 219 | }
|
---|
[429acb9] | 220 |
|
---|
[e9073f2] | 221 | /** Notification function called on service disconnect from console */
|
---|
[424cd43] | 222 | void gcons_notify_disconnect(size_t index)
|
---|
[e9073f2] | 223 | {
|
---|
| 224 | if (!use_gcons)
|
---|
| 225 | return;
|
---|
[1601f3c] | 226 |
|
---|
[424cd43] | 227 | if (index == active_console)
|
---|
| 228 | console_state[index] = CONS_DISCONNECTED_SEL;
|
---|
[e9073f2] | 229 | else
|
---|
[424cd43] | 230 | console_state[index] = CONS_DISCONNECTED;
|
---|
[76fca31] | 231 |
|
---|
[e9073f2] | 232 | if (active_console == KERNEL_CONSOLE)
|
---|
| 233 | return;
|
---|
[76fca31] | 234 |
|
---|
[424cd43] | 235 | redraw_state(index);
|
---|
[e9073f2] | 236 | vp_switch(console_vp);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
[d530237a] | 239 | /** Notification function called on console connect */
|
---|
[424cd43] | 240 | void gcons_notify_connect(size_t index)
|
---|
[a7d2d78] | 241 | {
|
---|
| 242 | if (!use_gcons)
|
---|
| 243 | return;
|
---|
[1601f3c] | 244 |
|
---|
[424cd43] | 245 | if (index == active_console)
|
---|
| 246 | console_state[index] = CONS_SELECTED;
|
---|
[a7d2d78] | 247 | else
|
---|
[424cd43] | 248 | console_state[index] = CONS_IDLE;
|
---|
[1601f3c] | 249 |
|
---|
[a7d2d78] | 250 | if (active_console == KERNEL_CONSOLE)
|
---|
| 251 | return;
|
---|
[1601f3c] | 252 |
|
---|
[424cd43] | 253 | redraw_state(index);
|
---|
[a7d2d78] | 254 | vp_switch(console_vp);
|
---|
[b1f51f0] | 255 | }
|
---|
| 256 |
|
---|
[429acb9] | 257 | /** Change to kernel console */
|
---|
| 258 | void gcons_in_kernel(void)
|
---|
| 259 | {
|
---|
[70178b74] | 260 | if (animation != -1)
|
---|
[0cc4313] | 261 | async_msg_1(fbphone, FB_ANIM_STOP, animation);
|
---|
[76fca31] | 262 |
|
---|
| 263 | active_console = KERNEL_CONSOLE;
|
---|
[429acb9] | 264 | vp_switch(0);
|
---|
| 265 | }
|
---|
| 266 |
|
---|
[424cd43] | 267 | /** Return x, where left <= x <= right && |a-x| == min(|a-x|) is smallest */
|
---|
[1e816c8] | 268 | static inline ssize_t limit(ssize_t a, ssize_t left, ssize_t right)
|
---|
[830ac99] | 269 | {
|
---|
| 270 | if (a < left)
|
---|
| 271 | a = left;
|
---|
[424cd43] | 272 |
|
---|
[830ac99] | 273 | if (a >= right)
|
---|
| 274 | a = right - 1;
|
---|
[424cd43] | 275 |
|
---|
[830ac99] | 276 | return a;
|
---|
| 277 | }
|
---|
| 278 |
|
---|
[1f83244] | 279 | /** Handle mouse move
|
---|
| 280 | *
|
---|
| 281 | * @param dx Delta X of mouse move
|
---|
| 282 | * @param dy Delta Y of mouse move
|
---|
| 283 | */
|
---|
[424cd43] | 284 | void gcons_mouse_move(ssize_t dx, ssize_t dy)
|
---|
[830ac99] | 285 | {
|
---|
[9f1362d4] | 286 | ssize_t nx = (ssize_t) mouse_x + dx;
|
---|
| 287 | ssize_t ny = (ssize_t) mouse_y + dy;
|
---|
| 288 |
|
---|
| 289 | mouse_x = (size_t) limit(nx, 0, xres);
|
---|
| 290 | mouse_y = (size_t) limit(ny, 0, yres);
|
---|
| 291 |
|
---|
[2ae1e6e] | 292 | if (active_console != KERNEL_CONSOLE)
|
---|
| 293 | async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
|
---|
[1f83244] | 294 | }
|
---|
| 295 |
|
---|
[9f1362d4] | 296 | static int gcons_find_conbut(ipcarg_t x, ipcarg_t y)
|
---|
[1f83244] | 297 | {
|
---|
[9f1362d4] | 298 | ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
|
---|
[1601f3c] | 299 |
|
---|
| 300 | if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
|
---|
[1f83244] | 301 | return -1;
|
---|
| 302 |
|
---|
| 303 | if (x < status_start)
|
---|
| 304 | return -1;
|
---|
| 305 |
|
---|
[00bb6965] | 306 | if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
|
---|
[1f83244] | 307 | return -1;
|
---|
[9f1362d4] | 308 |
|
---|
[f15cb3c4] | 309 | if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
|
---|
[1f83244] | 310 | return -1;
|
---|
| 311 |
|
---|
[9f1362d4] | 312 | ipcarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
|
---|
| 313 |
|
---|
| 314 | if (btn < CONSOLE_COUNT)
|
---|
| 315 | return btn;
|
---|
| 316 |
|
---|
| 317 | return -1;
|
---|
[1f83244] | 318 | }
|
---|
[830ac99] | 319 |
|
---|
[1f83244] | 320 | /** Handle mouse click
|
---|
| 321 | *
|
---|
[424cd43] | 322 | * @param state New state (true - pressed, false - depressed)
|
---|
[9f1362d4] | 323 | *
|
---|
[1f83244] | 324 | */
|
---|
[424cd43] | 325 | int gcons_mouse_btn(bool state)
|
---|
[1f83244] | 326 | {
|
---|
[9f1362d4] | 327 | /* Ignore mouse clicks if no buttons
|
---|
| 328 | are drawn at all */
|
---|
| 329 | if (xres < 800)
|
---|
| 330 | return -1;
|
---|
[1601f3c] | 331 |
|
---|
[1f83244] | 332 | if (state) {
|
---|
[9f1362d4] | 333 | int conbut = gcons_find_conbut(mouse_x, mouse_y);
|
---|
[1f83244] | 334 | if (conbut != -1) {
|
---|
[424cd43] | 335 | btn_pressed = true;
|
---|
[1f83244] | 336 | btn_x = mouse_x;
|
---|
| 337 | btn_y = mouse_y;
|
---|
| 338 | }
|
---|
| 339 | return -1;
|
---|
[1601f3c] | 340 | }
|
---|
| 341 |
|
---|
| 342 | if ((!state) && (!btn_pressed))
|
---|
[1f83244] | 343 | return -1;
|
---|
[1601f3c] | 344 |
|
---|
[424cd43] | 345 | btn_pressed = false;
|
---|
[1601f3c] | 346 |
|
---|
[9f1362d4] | 347 | int conbut = gcons_find_conbut(mouse_x, mouse_y);
|
---|
[1f83244] | 348 | if (conbut == gcons_find_conbut(btn_x, btn_y))
|
---|
| 349 | return conbut;
|
---|
[1601f3c] | 350 |
|
---|
[1f83244] | 351 | return -1;
|
---|
[830ac99] | 352 | }
|
---|
| 353 |
|
---|
[429acb9] | 354 | /** Draw a PPM pixmap to framebuffer
|
---|
| 355 | *
|
---|
| 356 | * @param logo Pointer to PPM data
|
---|
| 357 | * @param size Size of PPM data
|
---|
| 358 | * @param x Coordinate of upper left corner
|
---|
| 359 | * @param y Coordinate of upper left corner
|
---|
[9f1362d4] | 360 | *
|
---|
[429acb9] | 361 | */
|
---|
[9f1362d4] | 362 | static void draw_pixmap(char *logo, size_t size, ipcarg_t x, ipcarg_t y)
|
---|
[90f5d64] | 363 | {
|
---|
| 364 | /* Create area */
|
---|
[9f1362d4] | 365 | char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
|
---|
[0cc4313] | 366 | MAP_ANONYMOUS, 0, 0);
|
---|
[90f5d64] | 367 | if (shm == MAP_FAILED)
|
---|
| 368 | return;
|
---|
[1601f3c] | 369 |
|
---|
[90f5d64] | 370 | memcpy(shm, logo, size);
|
---|
[1601f3c] | 371 |
|
---|
[90f5d64] | 372 | /* Send area */
|
---|
[9f1362d4] | 373 | int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
|
---|
[90f5d64] | 374 | if (rc)
|
---|
| 375 | goto exit;
|
---|
[1601f3c] | 376 |
|
---|
[0da4e41] | 377 | rc = async_share_out_start(fbphone, shm, PROTO_READ);
|
---|
[90f5d64] | 378 | if (rc)
|
---|
| 379 | goto drop;
|
---|
[1601f3c] | 380 |
|
---|
[90f5d64] | 381 | /* Draw logo */
|
---|
[085bd54] | 382 | async_msg_2(fbphone, FB_DRAW_PPM, x, y);
|
---|
[1601f3c] | 383 |
|
---|
[90f5d64] | 384 | drop:
|
---|
| 385 | /* Drop area */
|
---|
[0cc4313] | 386 | async_msg_0(fbphone, FB_DROP_SHM);
|
---|
[1601f3c] | 387 |
|
---|
| 388 | exit:
|
---|
[90f5d64] | 389 | /* Remove area */
|
---|
| 390 | munmap(shm, size);
|
---|
| 391 | }
|
---|
| 392 |
|
---|
[76fca31] | 393 | /** Redraws console graphics */
|
---|
| 394 | void gcons_redraw_console(void)
|
---|
[b1f51f0] | 395 | {
|
---|
| 396 | if (!use_gcons)
|
---|
| 397 | return;
|
---|
| 398 |
|
---|
| 399 | vp_switch(0);
|
---|
[9f1362d4] | 400 | set_rgb_color(COLOR_MAIN, COLOR_MAIN);
|
---|
[e1c4849] | 401 | clear();
|
---|
[1601f3c] | 402 | draw_pixmap(_binary_gfx_helenos_ppm_start,
|
---|
| 403 | (size_t) &_binary_gfx_helenos_ppm_size, xres - 66, 2);
|
---|
| 404 | draw_pixmap(_binary_gfx_nameic_ppm_start,
|
---|
| 405 | (size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
|
---|
[76fca31] | 406 |
|
---|
[9f1362d4] | 407 | unsigned int i;
|
---|
[0cc4313] | 408 | for (i = 0; i < CONSOLE_COUNT; i++)
|
---|
[a7d2d78] | 409 | redraw_state(i);
|
---|
[1601f3c] | 410 |
|
---|
[b1f51f0] | 411 | vp_switch(console_vp);
|
---|
| 412 | }
|
---|
| 413 |
|
---|
[d530237a] | 414 | /** Creates a pixmap on framebuffer
|
---|
| 415 | *
|
---|
| 416 | * @param data PPM data
|
---|
| 417 | * @param size PPM data size
|
---|
[424cd43] | 418 | *
|
---|
[d530237a] | 419 | * @return Pixmap identification
|
---|
[424cd43] | 420 | *
|
---|
[d530237a] | 421 | */
|
---|
[424cd43] | 422 | static int make_pixmap(char *data, size_t size)
|
---|
[a7d2d78] | 423 | {
|
---|
| 424 | /* Create area */
|
---|
[9f1362d4] | 425 | char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
|
---|
[0cc4313] | 426 | MAP_ANONYMOUS, 0, 0);
|
---|
[a7d2d78] | 427 | if (shm == MAP_FAILED)
|
---|
| 428 | return -1;
|
---|
[1601f3c] | 429 |
|
---|
[a7d2d78] | 430 | memcpy(shm, data, size);
|
---|
[1601f3c] | 431 |
|
---|
[9f1362d4] | 432 | int pxid = -1;
|
---|
| 433 |
|
---|
[a7d2d78] | 434 | /* Send area */
|
---|
[9f1362d4] | 435 | int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
|
---|
[a7d2d78] | 436 | if (rc)
|
---|
| 437 | goto exit;
|
---|
[1601f3c] | 438 |
|
---|
[0da4e41] | 439 | rc = async_share_out_start(fbphone, shm, PROTO_READ);
|
---|
[a7d2d78] | 440 | if (rc)
|
---|
| 441 | goto drop;
|
---|
[1601f3c] | 442 |
|
---|
[a7d2d78] | 443 | /* Obtain pixmap */
|
---|
[0cc4313] | 444 | rc = async_req_0_0(fbphone, FB_SHM2PIXMAP);
|
---|
[a7d2d78] | 445 | if (rc < 0)
|
---|
| 446 | goto drop;
|
---|
[1601f3c] | 447 |
|
---|
[a7d2d78] | 448 | pxid = rc;
|
---|
[1601f3c] | 449 |
|
---|
[a7d2d78] | 450 | drop:
|
---|
| 451 | /* Drop area */
|
---|
[0cc4313] | 452 | async_msg_0(fbphone, FB_DROP_SHM);
|
---|
[1601f3c] | 453 |
|
---|
| 454 | exit:
|
---|
[a7d2d78] | 455 | /* Remove area */
|
---|
| 456 | munmap(shm, size);
|
---|
[1601f3c] | 457 |
|
---|
[a7d2d78] | 458 | return pxid;
|
---|
| 459 | }
|
---|
| 460 |
|
---|
[1fd7700] | 461 | static void make_anim(void)
|
---|
| 462 | {
|
---|
[9f1362d4] | 463 | int an = async_req_1_0(fbphone, FB_ANIM_CREATE,
|
---|
| 464 | cstatus_vp[KERNEL_CONSOLE]);
|
---|
[1fd7700] | 465 | if (an < 0)
|
---|
| 466 | return;
|
---|
[1601f3c] | 467 |
|
---|
| 468 | int pm = make_pixmap(_binary_gfx_anim_1_ppm_start,
|
---|
[36e9cd1] | 469 | (size_t) &_binary_gfx_anim_1_ppm_size);
|
---|
[1fd7700] | 470 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 471 |
|
---|
| 472 | pm = make_pixmap(_binary_gfx_anim_2_ppm_start,
|
---|
[36e9cd1] | 473 | (size_t) &_binary_gfx_anim_2_ppm_size);
|
---|
[1fd7700] | 474 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 475 |
|
---|
| 476 | pm = make_pixmap(_binary_gfx_anim_3_ppm_start,
|
---|
[36e9cd1] | 477 | (size_t) &_binary_gfx_anim_3_ppm_size);
|
---|
[1fd7700] | 478 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 479 |
|
---|
| 480 | pm = make_pixmap(_binary_gfx_anim_4_ppm_start,
|
---|
[36e9cd1] | 481 | (size_t) &_binary_gfx_anim_4_ppm_size);
|
---|
[1fd7700] | 482 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 483 |
|
---|
[0cc4313] | 484 | async_msg_1(fbphone, FB_ANIM_START, an);
|
---|
[1601f3c] | 485 |
|
---|
[1fd7700] | 486 | animation = an;
|
---|
| 487 | }
|
---|
| 488 |
|
---|
[b1f51f0] | 489 | /** Initialize nice graphical console environment */
|
---|
| 490 | void gcons_init(int phone)
|
---|
| 491 | {
|
---|
| 492 | fbphone = phone;
|
---|
[76fca31] | 493 |
|
---|
[424cd43] | 494 | int rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
|
---|
[b1f51f0] | 495 | if (rc)
|
---|
| 496 | return;
|
---|
| 497 |
|
---|
[76fca31] | 498 | if ((xres < 800) || (yres < 600))
|
---|
[b1f51f0] | 499 | return;
|
---|
[76fca31] | 500 |
|
---|
[1601f3c] | 501 | /* Create console viewport */
|
---|
| 502 |
|
---|
[a7d2d78] | 503 | /* Align width & height to character size */
|
---|
[d7baee6] | 504 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
|
---|
[0cc4313] | 505 | ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
|
---|
| 506 | ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
|
---|
[424cd43] | 507 |
|
---|
[b1f51f0] | 508 | if (console_vp < 0)
|
---|
| 509 | return;
|
---|
| 510 |
|
---|
| 511 | /* Create status buttons */
|
---|
[9f1362d4] | 512 | ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
|
---|
[424cd43] | 513 | size_t i;
|
---|
[00bb6965] | 514 | for (i = 0; i < CONSOLE_COUNT; i++) {
|
---|
[d7baee6] | 515 | cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
|
---|
[0cc4313] | 516 | i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
|
---|
| 517 | STATUS_WIDTH, STATUS_HEIGHT);
|
---|
[424cd43] | 518 |
|
---|
[b1f51f0] | 519 | if (cstatus_vp[i] < 0)
|
---|
| 520 | return;
|
---|
[424cd43] | 521 |
|
---|
[a7d2d78] | 522 | vp_switch(cstatus_vp[i]);
|
---|
[9f1362d4] | 523 | set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND);
|
---|
[b1f51f0] | 524 | }
|
---|
| 525 |
|
---|
[a7d2d78] | 526 | /* Initialize icons */
|
---|
[00bb6965] | 527 | ic_pixmaps[CONS_SELECTED] =
|
---|
[1601f3c] | 528 | make_pixmap(_binary_gfx_cons_selected_ppm_start,
|
---|
[424cd43] | 529 | (size_t) &_binary_gfx_cons_selected_ppm_size);
|
---|
[1601f3c] | 530 | ic_pixmaps[CONS_IDLE] =
|
---|
| 531 | make_pixmap(_binary_gfx_cons_idle_ppm_start,
|
---|
[424cd43] | 532 | (size_t) &_binary_gfx_cons_idle_ppm_size);
|
---|
[00bb6965] | 533 | ic_pixmaps[CONS_HAS_DATA] =
|
---|
[1601f3c] | 534 | make_pixmap(_binary_gfx_cons_has_data_ppm_start,
|
---|
[424cd43] | 535 | (size_t) &_binary_gfx_cons_has_data_ppm_size);
|
---|
[00bb6965] | 536 | ic_pixmaps[CONS_DISCONNECTED] =
|
---|
[1601f3c] | 537 | make_pixmap(_binary_gfx_cons_idle_ppm_start,
|
---|
[424cd43] | 538 | (size_t) &_binary_gfx_cons_idle_ppm_size);
|
---|
[1601f3c] | 539 | ic_pixmaps[CONS_KERNEL] =
|
---|
| 540 | make_pixmap(_binary_gfx_cons_kernel_ppm_start,
|
---|
[424cd43] | 541 | (size_t) &_binary_gfx_cons_kernel_ppm_size);
|
---|
[a7d2d78] | 542 | ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
|
---|
[1fd7700] | 543 |
|
---|
| 544 | make_anim();
|
---|
[76fca31] | 545 |
|
---|
[424cd43] | 546 | use_gcons = true;
|
---|
[a7d2d78] | 547 | console_state[0] = CONS_DISCONNECTED_SEL;
|
---|
| 548 | console_state[KERNEL_CONSOLE] = CONS_KERNEL;
|
---|
[424cd43] | 549 |
|
---|
[1035437] | 550 | vp_switch(console_vp);
|
---|
[b1f51f0] | 551 | }
|
---|
[76fca31] | 552 |
|
---|
[ce5bcb4] | 553 | /** @}
|
---|
| 554 | */
|
---|