[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>
|
---|
[e1c4849] | 36 | #include <async.h>
|
---|
[79ae36dd] | 37 | #include <async_obsolete.h>
|
---|
[e1c4849] | 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;
|
---|
[96b02eb9] | 84 | static sysarg_t xres;
|
---|
| 85 | static sysarg_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 |
|
---|
[96b02eb9] | 109 | static sysarg_t mouse_x = 0;
|
---|
| 110 | static sysarg_t mouse_y= 0;
|
---|
[424cd43] | 111 |
|
---|
[9f1362d4] | 112 | static bool btn_pressed = false;
|
---|
[96b02eb9] | 113 | static sysarg_t btn_x = 0;
|
---|
| 114 | static sysarg_t btn_y = 0;
|
---|
[e1c4849] | 115 |
|
---|
[b1f51f0] | 116 | static void vp_switch(int vp)
|
---|
| 117 | {
|
---|
[79ae36dd] | 118 | async_obsolete_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp);
|
---|
[b1f51f0] | 119 | }
|
---|
| 120 |
|
---|
[e1c4849] | 121 | /** Create view port */
|
---|
[96b02eb9] | 122 | static int vp_create(sysarg_t x, sysarg_t y, sysarg_t width, sysarg_t height)
|
---|
[b1f51f0] | 123 | {
|
---|
[79ae36dd] | 124 | return async_obsolete_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
|
---|
[0cc4313] | 125 | (width << 16) | height);
|
---|
[b1f51f0] | 126 | }
|
---|
| 127 |
|
---|
[e1c4849] | 128 | static void clear(void)
|
---|
[b1f51f0] | 129 | {
|
---|
[79ae36dd] | 130 | async_obsolete_msg_0(fbphone, FB_CLEAR);
|
---|
[b1f51f0] | 131 | }
|
---|
| 132 |
|
---|
[424cd43] | 133 | static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
|
---|
[e1c4849] | 134 | {
|
---|
[79ae36dd] | 135 | async_obsolete_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
|
---|
[e1c4849] | 136 | }
|
---|
| 137 |
|
---|
[d530237a] | 138 | /** Transparent putchar */
|
---|
[96b02eb9] | 139 | static void tran_putch(wchar_t ch, sysarg_t col, sysarg_t row)
|
---|
[e1c4849] | 140 | {
|
---|
[79ae36dd] | 141 | async_obsolete_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)
|
---|
[79ae36dd] | 152 | async_obsolete_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];
|
---|
[7e752b2] | 159 | snprintf(data, 5, "%zu", index + 1);
|
---|
[424cd43] | 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 | {
|
---|
[e3a46c2] | 170 | if (!use_gcons) {
|
---|
| 171 | active_console = index;
|
---|
[b1f51f0] | 172 | return;
|
---|
[e3a46c2] | 173 | }
|
---|
[1601f3c] | 174 |
|
---|
[a7d2d78] | 175 | if (active_console == KERNEL_CONSOLE) {
|
---|
[424cd43] | 176 | size_t i;
|
---|
| 177 |
|
---|
[00bb6965] | 178 | for (i = 0; i < CONSOLE_COUNT; i++)
|
---|
[a7d2d78] | 179 | redraw_state(i);
|
---|
[424cd43] | 180 |
|
---|
[70178b74] | 181 | if (animation != -1)
|
---|
[79ae36dd] | 182 | async_obsolete_msg_1(fbphone, FB_ANIM_START, animation);
|
---|
[a7d2d78] | 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;
|
---|
[424cd43] | 188 |
|
---|
[a7d2d78] | 189 | redraw_state(active_console);
|
---|
| 190 | }
|
---|
[1601f3c] | 191 |
|
---|
[424cd43] | 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;
|
---|
[1601f3c] | 199 |
|
---|
[424cd43] | 200 | redraw_state(index);
|
---|
[b1f51f0] | 201 | vp_switch(console_vp);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[429acb9] | 204 | /** Notification function that gets called on new output to virtual console */
|
---|
[424cd43] | 205 | void gcons_notify_char(size_t index)
|
---|
[b1f51f0] | 206 | {
|
---|
| 207 | if (!use_gcons)
|
---|
| 208 | return;
|
---|
[1601f3c] | 209 |
|
---|
[424cd43] | 210 | if ((index == active_console)
|
---|
| 211 | || (console_state[index] == CONS_HAS_DATA))
|
---|
[d6cc453] | 212 | return;
|
---|
[1601f3c] | 213 |
|
---|
[424cd43] | 214 | console_state[index] = CONS_HAS_DATA;
|
---|
[1601f3c] | 215 |
|
---|
[a7d2d78] | 216 | if (active_console == KERNEL_CONSOLE)
|
---|
[429acb9] | 217 | return;
|
---|
[1601f3c] | 218 |
|
---|
[424cd43] | 219 | redraw_state(index);
|
---|
[b1f51f0] | 220 | vp_switch(console_vp);
|
---|
[a7d2d78] | 221 | }
|
---|
[429acb9] | 222 |
|
---|
[e9073f2] | 223 | /** Notification function called on service disconnect from console */
|
---|
[424cd43] | 224 | void gcons_notify_disconnect(size_t index)
|
---|
[e9073f2] | 225 | {
|
---|
| 226 | if (!use_gcons)
|
---|
| 227 | return;
|
---|
[1601f3c] | 228 |
|
---|
[424cd43] | 229 | if (index == active_console)
|
---|
| 230 | console_state[index] = CONS_DISCONNECTED_SEL;
|
---|
[e9073f2] | 231 | else
|
---|
[424cd43] | 232 | console_state[index] = CONS_DISCONNECTED;
|
---|
[76fca31] | 233 |
|
---|
[e9073f2] | 234 | if (active_console == KERNEL_CONSOLE)
|
---|
| 235 | return;
|
---|
[76fca31] | 236 |
|
---|
[424cd43] | 237 | redraw_state(index);
|
---|
[e9073f2] | 238 | vp_switch(console_vp);
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[d530237a] | 241 | /** Notification function called on console connect */
|
---|
[424cd43] | 242 | void gcons_notify_connect(size_t index)
|
---|
[a7d2d78] | 243 | {
|
---|
| 244 | if (!use_gcons)
|
---|
| 245 | return;
|
---|
[1601f3c] | 246 |
|
---|
[424cd43] | 247 | if (index == active_console)
|
---|
| 248 | console_state[index] = CONS_SELECTED;
|
---|
[a7d2d78] | 249 | else
|
---|
[424cd43] | 250 | console_state[index] = CONS_IDLE;
|
---|
[1601f3c] | 251 |
|
---|
[a7d2d78] | 252 | if (active_console == KERNEL_CONSOLE)
|
---|
| 253 | return;
|
---|
[1601f3c] | 254 |
|
---|
[424cd43] | 255 | redraw_state(index);
|
---|
[a7d2d78] | 256 | vp_switch(console_vp);
|
---|
[b1f51f0] | 257 | }
|
---|
| 258 |
|
---|
[429acb9] | 259 | /** Change to kernel console */
|
---|
| 260 | void gcons_in_kernel(void)
|
---|
| 261 | {
|
---|
[70178b74] | 262 | if (animation != -1)
|
---|
[79ae36dd] | 263 | async_obsolete_msg_1(fbphone, FB_ANIM_STOP, animation);
|
---|
[76fca31] | 264 |
|
---|
| 265 | active_console = KERNEL_CONSOLE;
|
---|
[429acb9] | 266 | vp_switch(0);
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[424cd43] | 269 | /** Return x, where left <= x <= right && |a-x| == min(|a-x|) is smallest */
|
---|
[1e816c8] | 270 | static inline ssize_t limit(ssize_t a, ssize_t left, ssize_t right)
|
---|
[830ac99] | 271 | {
|
---|
| 272 | if (a < left)
|
---|
| 273 | a = left;
|
---|
[424cd43] | 274 |
|
---|
[830ac99] | 275 | if (a >= right)
|
---|
| 276 | a = right - 1;
|
---|
[424cd43] | 277 |
|
---|
[830ac99] | 278 | return a;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
[1f83244] | 281 | /** Handle mouse move
|
---|
| 282 | *
|
---|
| 283 | * @param dx Delta X of mouse move
|
---|
| 284 | * @param dy Delta Y of mouse move
|
---|
| 285 | */
|
---|
[424cd43] | 286 | void gcons_mouse_move(ssize_t dx, ssize_t dy)
|
---|
[830ac99] | 287 | {
|
---|
[9f1362d4] | 288 | ssize_t nx = (ssize_t) mouse_x + dx;
|
---|
| 289 | ssize_t ny = (ssize_t) mouse_y + dy;
|
---|
[306061a] | 290 |
|
---|
| 291 | /* Until gcons is initalized we don't have the screen resolution */
|
---|
| 292 | if (xres == 0 || yres == 0)
|
---|
[ecd2775] | 293 | return;
|
---|
[9f1362d4] | 294 |
|
---|
| 295 | mouse_x = (size_t) limit(nx, 0, xres);
|
---|
| 296 | mouse_y = (size_t) limit(ny, 0, yres);
|
---|
| 297 |
|
---|
[2ae1e6e] | 298 | if (active_console != KERNEL_CONSOLE)
|
---|
[79ae36dd] | 299 | async_obsolete_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
|
---|
[1f83244] | 300 | }
|
---|
| 301 |
|
---|
[96b02eb9] | 302 | static int gcons_find_conbut(sysarg_t x, sysarg_t y)
|
---|
[1f83244] | 303 | {
|
---|
[96b02eb9] | 304 | sysarg_t status_start = STATUS_START + (xres - 800) / 2;
|
---|
[1601f3c] | 305 |
|
---|
| 306 | if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
|
---|
[1f83244] | 307 | return -1;
|
---|
| 308 |
|
---|
| 309 | if (x < status_start)
|
---|
| 310 | return -1;
|
---|
| 311 |
|
---|
[00bb6965] | 312 | if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
|
---|
[1f83244] | 313 | return -1;
|
---|
[9f1362d4] | 314 |
|
---|
[f15cb3c4] | 315 | if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
|
---|
[1f83244] | 316 | return -1;
|
---|
| 317 |
|
---|
[96b02eb9] | 318 | sysarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
|
---|
[9f1362d4] | 319 |
|
---|
| 320 | if (btn < CONSOLE_COUNT)
|
---|
| 321 | return btn;
|
---|
| 322 |
|
---|
| 323 | return -1;
|
---|
[1f83244] | 324 | }
|
---|
[830ac99] | 325 |
|
---|
[1f83244] | 326 | /** Handle mouse click
|
---|
| 327 | *
|
---|
[424cd43] | 328 | * @param state New state (true - pressed, false - depressed)
|
---|
[9f1362d4] | 329 | *
|
---|
[1f83244] | 330 | */
|
---|
[424cd43] | 331 | int gcons_mouse_btn(bool state)
|
---|
[1f83244] | 332 | {
|
---|
[9f1362d4] | 333 | /* Ignore mouse clicks if no buttons
|
---|
| 334 | are drawn at all */
|
---|
| 335 | if (xres < 800)
|
---|
| 336 | return -1;
|
---|
[1601f3c] | 337 |
|
---|
[1f83244] | 338 | if (state) {
|
---|
[9f1362d4] | 339 | int conbut = gcons_find_conbut(mouse_x, mouse_y);
|
---|
[1f83244] | 340 | if (conbut != -1) {
|
---|
[424cd43] | 341 | btn_pressed = true;
|
---|
[1f83244] | 342 | btn_x = mouse_x;
|
---|
| 343 | btn_y = mouse_y;
|
---|
| 344 | }
|
---|
| 345 | return -1;
|
---|
[1601f3c] | 346 | }
|
---|
| 347 |
|
---|
| 348 | if ((!state) && (!btn_pressed))
|
---|
[1f83244] | 349 | return -1;
|
---|
[1601f3c] | 350 |
|
---|
[424cd43] | 351 | btn_pressed = false;
|
---|
[1601f3c] | 352 |
|
---|
[9f1362d4] | 353 | int conbut = gcons_find_conbut(mouse_x, mouse_y);
|
---|
[1f83244] | 354 | if (conbut == gcons_find_conbut(btn_x, btn_y))
|
---|
| 355 | return conbut;
|
---|
[1601f3c] | 356 |
|
---|
[1f83244] | 357 | return -1;
|
---|
[830ac99] | 358 | }
|
---|
| 359 |
|
---|
[429acb9] | 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
|
---|
[9f1362d4] | 366 | *
|
---|
[429acb9] | 367 | */
|
---|
[96b02eb9] | 368 | static void draw_pixmap(char *logo, size_t size, sysarg_t x, sysarg_t y)
|
---|
[90f5d64] | 369 | {
|
---|
| 370 | /* Create area */
|
---|
[9f1362d4] | 371 | char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
|
---|
[0cc4313] | 372 | MAP_ANONYMOUS, 0, 0);
|
---|
[90f5d64] | 373 | if (shm == MAP_FAILED)
|
---|
| 374 | return;
|
---|
[1601f3c] | 375 |
|
---|
[90f5d64] | 376 | memcpy(shm, logo, size);
|
---|
[1601f3c] | 377 |
|
---|
[90f5d64] | 378 | /* Send area */
|
---|
[79ae36dd] | 379 | int rc = async_obsolete_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm);
|
---|
[90f5d64] | 380 | if (rc)
|
---|
| 381 | goto exit;
|
---|
[1601f3c] | 382 |
|
---|
[79ae36dd] | 383 | rc = async_obsolete_share_out_start(fbphone, shm, PROTO_READ);
|
---|
[90f5d64] | 384 | if (rc)
|
---|
| 385 | goto drop;
|
---|
[1601f3c] | 386 |
|
---|
[90f5d64] | 387 | /* Draw logo */
|
---|
[79ae36dd] | 388 | async_obsolete_msg_2(fbphone, FB_DRAW_PPM, x, y);
|
---|
[1601f3c] | 389 |
|
---|
[90f5d64] | 390 | drop:
|
---|
| 391 | /* Drop area */
|
---|
[79ae36dd] | 392 | async_obsolete_msg_0(fbphone, FB_DROP_SHM);
|
---|
[1601f3c] | 393 |
|
---|
| 394 | exit:
|
---|
[90f5d64] | 395 | /* Remove area */
|
---|
| 396 | munmap(shm, size);
|
---|
| 397 | }
|
---|
| 398 |
|
---|
[76fca31] | 399 | /** Redraws console graphics */
|
---|
| 400 | void gcons_redraw_console(void)
|
---|
[b1f51f0] | 401 | {
|
---|
| 402 | if (!use_gcons)
|
---|
| 403 | return;
|
---|
| 404 |
|
---|
| 405 | vp_switch(0);
|
---|
[9f1362d4] | 406 | set_rgb_color(COLOR_MAIN, COLOR_MAIN);
|
---|
[e1c4849] | 407 | clear();
|
---|
[1601f3c] | 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);
|
---|
[76fca31] | 412 |
|
---|
[9f1362d4] | 413 | unsigned int i;
|
---|
[0cc4313] | 414 | for (i = 0; i < CONSOLE_COUNT; i++)
|
---|
[a7d2d78] | 415 | redraw_state(i);
|
---|
[1601f3c] | 416 |
|
---|
[b1f51f0] | 417 | vp_switch(console_vp);
|
---|
| 418 | }
|
---|
| 419 |
|
---|
[d530237a] | 420 | /** Creates a pixmap on framebuffer
|
---|
| 421 | *
|
---|
| 422 | * @param data PPM data
|
---|
| 423 | * @param size PPM data size
|
---|
[424cd43] | 424 | *
|
---|
[d530237a] | 425 | * @return Pixmap identification
|
---|
[424cd43] | 426 | *
|
---|
[d530237a] | 427 | */
|
---|
[424cd43] | 428 | static int make_pixmap(char *data, size_t size)
|
---|
[a7d2d78] | 429 | {
|
---|
| 430 | /* Create area */
|
---|
[9f1362d4] | 431 | char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
|
---|
[0cc4313] | 432 | MAP_ANONYMOUS, 0, 0);
|
---|
[a7d2d78] | 433 | if (shm == MAP_FAILED)
|
---|
| 434 | return -1;
|
---|
[1601f3c] | 435 |
|
---|
[a7d2d78] | 436 | memcpy(shm, data, size);
|
---|
[1601f3c] | 437 |
|
---|
[9f1362d4] | 438 | int pxid = -1;
|
---|
| 439 |
|
---|
[a7d2d78] | 440 | /* Send area */
|
---|
[79ae36dd] | 441 | int rc = async_obsolete_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm);
|
---|
[a7d2d78] | 442 | if (rc)
|
---|
| 443 | goto exit;
|
---|
[1601f3c] | 444 |
|
---|
[79ae36dd] | 445 | rc = async_obsolete_share_out_start(fbphone, shm, PROTO_READ);
|
---|
[a7d2d78] | 446 | if (rc)
|
---|
| 447 | goto drop;
|
---|
[1601f3c] | 448 |
|
---|
[a7d2d78] | 449 | /* Obtain pixmap */
|
---|
[79ae36dd] | 450 | rc = async_obsolete_req_0_0(fbphone, FB_SHM2PIXMAP);
|
---|
[a7d2d78] | 451 | if (rc < 0)
|
---|
| 452 | goto drop;
|
---|
[1601f3c] | 453 |
|
---|
[a7d2d78] | 454 | pxid = rc;
|
---|
[1601f3c] | 455 |
|
---|
[a7d2d78] | 456 | drop:
|
---|
| 457 | /* Drop area */
|
---|
[79ae36dd] | 458 | async_obsolete_msg_0(fbphone, FB_DROP_SHM);
|
---|
[1601f3c] | 459 |
|
---|
| 460 | exit:
|
---|
[a7d2d78] | 461 | /* Remove area */
|
---|
| 462 | munmap(shm, size);
|
---|
[1601f3c] | 463 |
|
---|
[a7d2d78] | 464 | return pxid;
|
---|
| 465 | }
|
---|
| 466 |
|
---|
[1fd7700] | 467 | static void make_anim(void)
|
---|
| 468 | {
|
---|
[79ae36dd] | 469 | int an = async_obsolete_req_1_0(fbphone, FB_ANIM_CREATE,
|
---|
[9f1362d4] | 470 | cstatus_vp[KERNEL_CONSOLE]);
|
---|
[1fd7700] | 471 | if (an < 0)
|
---|
| 472 | return;
|
---|
[1601f3c] | 473 |
|
---|
| 474 | int pm = make_pixmap(_binary_gfx_anim_1_ppm_start,
|
---|
[36e9cd1] | 475 | (size_t) &_binary_gfx_anim_1_ppm_size);
|
---|
[79ae36dd] | 476 | async_obsolete_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 477 |
|
---|
| 478 | pm = make_pixmap(_binary_gfx_anim_2_ppm_start,
|
---|
[36e9cd1] | 479 | (size_t) &_binary_gfx_anim_2_ppm_size);
|
---|
[79ae36dd] | 480 | async_obsolete_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 481 |
|
---|
| 482 | pm = make_pixmap(_binary_gfx_anim_3_ppm_start,
|
---|
[36e9cd1] | 483 | (size_t) &_binary_gfx_anim_3_ppm_size);
|
---|
[79ae36dd] | 484 | async_obsolete_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 485 |
|
---|
| 486 | pm = make_pixmap(_binary_gfx_anim_4_ppm_start,
|
---|
[36e9cd1] | 487 | (size_t) &_binary_gfx_anim_4_ppm_size);
|
---|
[79ae36dd] | 488 | async_obsolete_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 489 |
|
---|
[79ae36dd] | 490 | async_obsolete_msg_1(fbphone, FB_ANIM_START, an);
|
---|
[1601f3c] | 491 |
|
---|
[1fd7700] | 492 | animation = an;
|
---|
| 493 | }
|
---|
| 494 |
|
---|
[b1f51f0] | 495 | /** Initialize nice graphical console environment */
|
---|
| 496 | void gcons_init(int phone)
|
---|
| 497 | {
|
---|
| 498 | fbphone = phone;
|
---|
[76fca31] | 499 |
|
---|
[79ae36dd] | 500 | int rc = async_obsolete_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
|
---|
[b1f51f0] | 501 | if (rc)
|
---|
| 502 | return;
|
---|
| 503 |
|
---|
[76fca31] | 504 | if ((xres < 800) || (yres < 600))
|
---|
[b1f51f0] | 505 | return;
|
---|
[76fca31] | 506 |
|
---|
[1601f3c] | 507 | /* Create console viewport */
|
---|
| 508 |
|
---|
[a7d2d78] | 509 | /* Align width & height to character size */
|
---|
[d7baee6] | 510 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
|
---|
[0cc4313] | 511 | ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
|
---|
| 512 | ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
|
---|
[424cd43] | 513 |
|
---|
[b1f51f0] | 514 | if (console_vp < 0)
|
---|
| 515 | return;
|
---|
| 516 |
|
---|
| 517 | /* Create status buttons */
|
---|
[96b02eb9] | 518 | sysarg_t status_start = STATUS_START + (xres - 800) / 2;
|
---|
[424cd43] | 519 | size_t i;
|
---|
[00bb6965] | 520 | for (i = 0; i < CONSOLE_COUNT; i++) {
|
---|
[d7baee6] | 521 | cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
|
---|
[0cc4313] | 522 | i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
|
---|
| 523 | STATUS_WIDTH, STATUS_HEIGHT);
|
---|
[424cd43] | 524 |
|
---|
[b1f51f0] | 525 | if (cstatus_vp[i] < 0)
|
---|
| 526 | return;
|
---|
[424cd43] | 527 |
|
---|
[a7d2d78] | 528 | vp_switch(cstatus_vp[i]);
|
---|
[9f1362d4] | 529 | set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND);
|
---|
[b1f51f0] | 530 | }
|
---|
| 531 |
|
---|
[a7d2d78] | 532 | /* Initialize icons */
|
---|
[00bb6965] | 533 | ic_pixmaps[CONS_SELECTED] =
|
---|
[1601f3c] | 534 | make_pixmap(_binary_gfx_cons_selected_ppm_start,
|
---|
[424cd43] | 535 | (size_t) &_binary_gfx_cons_selected_ppm_size);
|
---|
[1601f3c] | 536 | ic_pixmaps[CONS_IDLE] =
|
---|
| 537 | make_pixmap(_binary_gfx_cons_idle_ppm_start,
|
---|
[424cd43] | 538 | (size_t) &_binary_gfx_cons_idle_ppm_size);
|
---|
[00bb6965] | 539 | ic_pixmaps[CONS_HAS_DATA] =
|
---|
[1601f3c] | 540 | make_pixmap(_binary_gfx_cons_has_data_ppm_start,
|
---|
[424cd43] | 541 | (size_t) &_binary_gfx_cons_has_data_ppm_size);
|
---|
[00bb6965] | 542 | ic_pixmaps[CONS_DISCONNECTED] =
|
---|
[1601f3c] | 543 | make_pixmap(_binary_gfx_cons_idle_ppm_start,
|
---|
[424cd43] | 544 | (size_t) &_binary_gfx_cons_idle_ppm_size);
|
---|
[1601f3c] | 545 | ic_pixmaps[CONS_KERNEL] =
|
---|
| 546 | make_pixmap(_binary_gfx_cons_kernel_ppm_start,
|
---|
[424cd43] | 547 | (size_t) &_binary_gfx_cons_kernel_ppm_size);
|
---|
[a7d2d78] | 548 | ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
|
---|
[1fd7700] | 549 |
|
---|
| 550 | make_anim();
|
---|
[76fca31] | 551 |
|
---|
[424cd43] | 552 | use_gcons = true;
|
---|
[a7d2d78] | 553 | console_state[0] = CONS_DISCONNECTED_SEL;
|
---|
| 554 | console_state[KERNEL_CONSOLE] = CONS_KERNEL;
|
---|
[424cd43] | 555 |
|
---|
[1035437] | 556 | vp_switch(console_vp);
|
---|
[b1f51f0] | 557 | }
|
---|
[76fca31] | 558 |
|
---|
[ce5bcb4] | 559 | /** @}
|
---|
| 560 | */
|
---|