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