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