Rev 1866 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1866 | Rev 1867 | ||
---|---|---|---|
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/mmap.h> |
39 | #include <sys/mman.h> |
40 | #include <string.h> |
40 | #include <string.h> |
41 | #include <align.h> |
41 | #include <align.h> |
42 | 42 | ||
43 | #include "console.h" |
43 | #include "console.h" |
44 | #include "gcons.h" |
44 | #include "gcons.h" |
45 | 45 | ||
46 | #define CONSOLE_TOP 66 |
46 | #define CONSOLE_TOP 66 |
47 | #define CONSOLE_MARGIN 6 |
47 | #define CONSOLE_MARGIN 6 |
48 | 48 | ||
49 | #define STATUS_START 110 |
49 | #define STATUS_START 110 |
50 | #define STATUS_TOP 8 |
50 | #define STATUS_TOP 8 |
51 | #define STATUS_SPACE 4 |
51 | #define STATUS_SPACE 4 |
52 | #define STATUS_WIDTH 48 |
52 | #define STATUS_WIDTH 48 |
53 | #define STATUS_HEIGHT 48 |
53 | #define STATUS_HEIGHT 48 |
54 | 54 | ||
55 | #define MAIN_COLOR 0xffffff |
55 | #define MAIN_COLOR 0xffffff |
56 | 56 | ||
57 | static int use_gcons = 0; |
57 | static int use_gcons = 0; |
58 | static ipcarg_t xres,yres; |
58 | static ipcarg_t xres,yres; |
59 | 59 | ||
60 | enum butstate { |
60 | enum butstate { |
61 | CONS_DISCONNECTED = 0, |
61 | CONS_DISCONNECTED = 0, |
62 | CONS_SELECTED, |
62 | CONS_SELECTED, |
63 | CONS_IDLE, |
63 | CONS_IDLE, |
64 | CONS_HAS_DATA, |
64 | CONS_HAS_DATA, |
65 | CONS_KERNEL, |
65 | CONS_KERNEL, |
66 | CONS_DISCONNECTED_SEL, |
66 | CONS_DISCONNECTED_SEL, |
67 | CONS_LAST |
67 | CONS_LAST |
68 | }; |
68 | }; |
69 | 69 | ||
70 | static int console_vp; |
70 | static int console_vp; |
71 | static int cstatus_vp[CONSOLE_COUNT]; |
71 | static int cstatus_vp[CONSOLE_COUNT]; |
72 | static enum butstate console_state[CONSOLE_COUNT]; |
72 | static enum butstate console_state[CONSOLE_COUNT]; |
73 | 73 | ||
74 | static int fbphone; |
74 | static int fbphone; |
75 | 75 | ||
76 | /** List of pixmaps identifying these icons */ |
76 | /** List of pixmaps identifying these icons */ |
77 | static int ic_pixmaps[CONS_LAST] = {-1,-1,-1,-1,-1,-1}; |
77 | static int ic_pixmaps[CONS_LAST] = {-1,-1,-1,-1,-1,-1}; |
78 | static int animation = -1; |
78 | static int animation = -1; |
79 | 79 | ||
80 | static int active_console = 0; |
80 | static int active_console = 0; |
81 | 81 | ||
82 | static void vp_switch(int vp) |
82 | static void vp_switch(int vp) |
83 | { |
83 | { |
84 | async_msg(fbphone,FB_VIEWPORT_SWITCH, vp); |
84 | async_msg(fbphone,FB_VIEWPORT_SWITCH, vp); |
85 | } |
85 | } |
86 | 86 | ||
87 | /** Create view port */ |
87 | /** Create view port */ |
88 | static int vp_create(unsigned int x, unsigned int y, |
88 | static int vp_create(unsigned int x, unsigned int y, |
89 | unsigned int width, unsigned int height) |
89 | unsigned int width, unsigned int height) |
90 | { |
90 | { |
91 | return async_req_2(fbphone, FB_VIEWPORT_CREATE, |
91 | return async_req_2(fbphone, FB_VIEWPORT_CREATE, |
92 | (x << 16) | y, (width << 16) | height, |
92 | (x << 16) | y, (width << 16) | height, |
93 | NULL, NULL); |
93 | NULL, NULL); |
94 | } |
94 | } |
95 | 95 | ||
96 | static void clear(void) |
96 | static void clear(void) |
97 | { |
97 | { |
98 | async_msg(fbphone, FB_CLEAR, 0); |
98 | async_msg(fbphone, FB_CLEAR, 0); |
99 | 99 | ||
100 | } |
100 | } |
101 | 101 | ||
102 | static void set_style(int fgcolor, int bgcolor) |
102 | static void set_style(int fgcolor, int bgcolor) |
103 | { |
103 | { |
104 | async_msg_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor); |
104 | async_msg_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor); |
105 | } |
105 | } |
106 | 106 | ||
107 | /** Transparent putchar */ |
107 | /** Transparent putchar */ |
108 | static void tran_putch(char c, int row, int col) |
108 | static void tran_putch(char c, int row, int col) |
109 | { |
109 | { |
110 | async_msg_3(fbphone, FB_TRANS_PUTCHAR, c, row, col); |
110 | async_msg_3(fbphone, FB_TRANS_PUTCHAR, c, row, col); |
111 | } |
111 | } |
112 | 112 | ||
113 | /** Redraw the button showing state of a given console */ |
113 | /** Redraw the button showing state of a given console */ |
114 | static void redraw_state(int consnum) |
114 | static void redraw_state(int consnum) |
115 | { |
115 | { |
116 | char data[5]; |
116 | char data[5]; |
117 | int i; |
117 | int i; |
118 | enum butstate state = console_state[consnum]; |
118 | enum butstate state = console_state[consnum]; |
119 | 119 | ||
120 | vp_switch(cstatus_vp[consnum]); |
120 | vp_switch(cstatus_vp[consnum]); |
121 | if (ic_pixmaps[state] != -1) |
121 | if (ic_pixmaps[state] != -1) |
122 | async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum], ic_pixmaps[state]); |
122 | async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum], ic_pixmaps[state]); |
123 | 123 | ||
124 | if (state != CONS_DISCONNECTED && state != CONS_KERNEL && state != CONS_DISCONNECTED_SEL) { |
124 | if (state != CONS_DISCONNECTED && state != CONS_KERNEL && state != CONS_DISCONNECTED_SEL) { |
125 | snprintf(data, 5, "%d", consnum+1); |
125 | snprintf(data, 5, "%d", consnum+1); |
126 | for (i=0;data[i];i++) |
126 | for (i=0;data[i];i++) |
127 | tran_putch(data[i], 1, 2+i); |
127 | tran_putch(data[i], 1, 2+i); |
128 | } |
128 | } |
129 | } |
129 | } |
130 | 130 | ||
131 | /** Notification run on changing console (except kernel console) */ |
131 | /** Notification run on changing console (except kernel console) */ |
132 | void gcons_change_console(int consnum) |
132 | void gcons_change_console(int consnum) |
133 | { |
133 | { |
134 | int i; |
134 | int i; |
135 | 135 | ||
136 | if (!use_gcons) |
136 | if (!use_gcons) |
137 | return; |
137 | return; |
138 | 138 | ||
139 | if (active_console == KERNEL_CONSOLE) { |
139 | if (active_console == KERNEL_CONSOLE) { |
140 | for (i=0; i < CONSOLE_COUNT; i++) |
140 | for (i=0; i < CONSOLE_COUNT; i++) |
141 | redraw_state(i); |
141 | redraw_state(i); |
142 | if (animation != -1) |
142 | if (animation != -1) |
143 | async_msg(fbphone, FB_ANIM_START, animation); |
143 | async_msg(fbphone, FB_ANIM_START, animation); |
144 | } else { |
144 | } else { |
145 | if (console_state[active_console] == CONS_DISCONNECTED_SEL) |
145 | if (console_state[active_console] == CONS_DISCONNECTED_SEL) |
146 | console_state[active_console] = CONS_DISCONNECTED; |
146 | console_state[active_console] = CONS_DISCONNECTED; |
147 | else |
147 | else |
148 | console_state[active_console] = CONS_IDLE; |
148 | console_state[active_console] = CONS_IDLE; |
149 | redraw_state(active_console); |
149 | redraw_state(active_console); |
150 | } |
150 | } |
151 | active_console = consnum; |
151 | active_console = consnum; |
152 | 152 | ||
153 | if (console_state[consnum] == CONS_DISCONNECTED) { |
153 | if (console_state[consnum] == CONS_DISCONNECTED) { |
154 | console_state[consnum] = CONS_DISCONNECTED_SEL; |
154 | console_state[consnum] = CONS_DISCONNECTED_SEL; |
155 | redraw_state(consnum); |
155 | redraw_state(consnum); |
156 | } else |
156 | } else |
157 | console_state[consnum] = CONS_SELECTED; |
157 | console_state[consnum] = CONS_SELECTED; |
158 | redraw_state(consnum); |
158 | redraw_state(consnum); |
159 | 159 | ||
160 | vp_switch(console_vp); |
160 | vp_switch(console_vp); |
161 | } |
161 | } |
162 | 162 | ||
163 | /** Notification function that gets called on new output to virtual console */ |
163 | /** Notification function that gets called on new output to virtual console */ |
164 | void gcons_notify_char(int consnum) |
164 | void gcons_notify_char(int consnum) |
165 | { |
165 | { |
166 | if (!use_gcons) |
166 | if (!use_gcons) |
167 | return; |
167 | return; |
168 | 168 | ||
169 | if (consnum == active_console || console_state[consnum] == CONS_HAS_DATA) |
169 | if (consnum == active_console || console_state[consnum] == CONS_HAS_DATA) |
170 | return; |
170 | return; |
171 | 171 | ||
172 | console_state[consnum] = CONS_HAS_DATA; |
172 | console_state[consnum] = CONS_HAS_DATA; |
173 | 173 | ||
174 | if (active_console == KERNEL_CONSOLE) |
174 | if (active_console == KERNEL_CONSOLE) |
175 | return; |
175 | return; |
176 | 176 | ||
177 | redraw_state(consnum); |
177 | redraw_state(consnum); |
178 | 178 | ||
179 | vp_switch(console_vp); |
179 | vp_switch(console_vp); |
180 | } |
180 | } |
181 | 181 | ||
182 | /** Notification function called on service disconnect from console */ |
182 | /** Notification function called on service disconnect from console */ |
183 | void gcons_notify_disconnect(int consnum) |
183 | void gcons_notify_disconnect(int consnum) |
184 | { |
184 | { |
185 | if (!use_gcons) |
185 | if (!use_gcons) |
186 | return; |
186 | return; |
187 | if (active_console == consnum) |
187 | if (active_console == consnum) |
188 | console_state[consnum] = CONS_DISCONNECTED_SEL; |
188 | console_state[consnum] = CONS_DISCONNECTED_SEL; |
189 | else |
189 | else |
190 | console_state[consnum] = CONS_DISCONNECTED; |
190 | console_state[consnum] = CONS_DISCONNECTED; |
191 | 191 | ||
192 | if (active_console == KERNEL_CONSOLE) |
192 | if (active_console == KERNEL_CONSOLE) |
193 | return; |
193 | return; |
194 | 194 | ||
195 | redraw_state(consnum); |
195 | redraw_state(consnum); |
196 | vp_switch(console_vp); |
196 | vp_switch(console_vp); |
197 | } |
197 | } |
198 | 198 | ||
199 | /** Notification function called on console connect */ |
199 | /** Notification function called on console connect */ |
200 | void gcons_notify_connect(int consnum) |
200 | void gcons_notify_connect(int consnum) |
201 | { |
201 | { |
202 | if (!use_gcons) |
202 | if (!use_gcons) |
203 | return; |
203 | return; |
204 | if (active_console == consnum) |
204 | if (active_console == consnum) |
205 | console_state[consnum] = CONS_SELECTED; |
205 | console_state[consnum] = CONS_SELECTED; |
206 | else |
206 | else |
207 | console_state[consnum] = CONS_IDLE; |
207 | console_state[consnum] = CONS_IDLE; |
208 | 208 | ||
209 | if (active_console == KERNEL_CONSOLE) |
209 | if (active_console == KERNEL_CONSOLE) |
210 | return; |
210 | return; |
211 | 211 | ||
212 | redraw_state(consnum); |
212 | redraw_state(consnum); |
213 | vp_switch(console_vp); |
213 | vp_switch(console_vp); |
214 | } |
214 | } |
215 | 215 | ||
216 | /** Change to kernel console */ |
216 | /** Change to kernel console */ |
217 | void gcons_in_kernel(void) |
217 | void gcons_in_kernel(void) |
218 | { |
218 | { |
219 | if (console_state[active_console] == CONS_DISCONNECTED_SEL) |
219 | if (console_state[active_console] == CONS_DISCONNECTED_SEL) |
220 | console_state[active_console] = CONS_DISCONNECTED; |
220 | console_state[active_console] = CONS_DISCONNECTED; |
221 | else |
221 | else |
222 | console_state[active_console] = CONS_IDLE; |
222 | console_state[active_console] = CONS_IDLE; |
223 | redraw_state(active_console); |
223 | redraw_state(active_console); |
224 | 224 | ||
225 | if (animation != -1) |
225 | if (animation != -1) |
226 | async_msg(fbphone, FB_ANIM_STOP, animation); |
226 | async_msg(fbphone, FB_ANIM_STOP, animation); |
227 | 227 | ||
228 | active_console = KERNEL_CONSOLE; /* Set to kernel console */ |
228 | active_console = KERNEL_CONSOLE; /* Set to kernel console */ |
229 | vp_switch(0); |
229 | vp_switch(0); |
230 | } |
230 | } |
231 | 231 | ||
232 | /** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */ |
232 | /** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */ |
233 | static inline int limit(int a,int left, int right) |
233 | static inline int limit(int a,int left, int right) |
234 | { |
234 | { |
235 | if (a < left) |
235 | if (a < left) |
236 | a = left; |
236 | a = left; |
237 | if (a >= right) |
237 | if (a >= right) |
238 | a = right - 1; |
238 | a = right - 1; |
239 | return a; |
239 | return a; |
240 | } |
240 | } |
241 | 241 | ||
242 | int mouse_x, mouse_y; |
242 | int mouse_x, mouse_y; |
243 | int btn_pressed, btn_x, btn_y; |
243 | int btn_pressed, btn_x, btn_y; |
244 | 244 | ||
245 | /** Handle mouse move |
245 | /** Handle mouse move |
246 | * |
246 | * |
247 | * @param dx Delta X of mouse move |
247 | * @param dx Delta X of mouse move |
248 | * @param dy Delta Y of mouse move |
248 | * @param dy Delta Y of mouse move |
249 | */ |
249 | */ |
250 | void gcons_mouse_move(int dx, int dy) |
250 | void gcons_mouse_move(int dx, int dy) |
251 | { |
251 | { |
252 | mouse_x = limit(mouse_x+dx, 0, xres); |
252 | mouse_x = limit(mouse_x+dx, 0, xres); |
253 | mouse_y = limit(mouse_y+dy, 0, yres); |
253 | mouse_y = limit(mouse_y+dy, 0, yres); |
254 | 254 | ||
255 | async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y); |
255 | async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y); |
256 | } |
256 | } |
257 | 257 | ||
258 | static int gcons_find_conbut(int x, int y) |
258 | static int gcons_find_conbut(int x, int y) |
259 | { |
259 | { |
260 | int status_start = STATUS_START + (xres-800) / 2;; |
260 | int status_start = STATUS_START + (xres-800) / 2;; |
261 | 261 | ||
262 | if (y < STATUS_TOP || y >= STATUS_TOP+STATUS_HEIGHT) |
262 | if (y < STATUS_TOP || y >= STATUS_TOP+STATUS_HEIGHT) |
263 | return -1; |
263 | return -1; |
264 | 264 | ||
265 | if (x < status_start) |
265 | if (x < status_start) |
266 | return -1; |
266 | return -1; |
267 | 267 | ||
268 | if (x >= status_start + (STATUS_WIDTH+STATUS_SPACE)*CONSOLE_COUNT) |
268 | if (x >= status_start + (STATUS_WIDTH+STATUS_SPACE)*CONSOLE_COUNT) |
269 | return -1; |
269 | return -1; |
270 | if (((x - status_start) % (STATUS_WIDTH+STATUS_SPACE)) < STATUS_SPACE) |
270 | if (((x - status_start) % (STATUS_WIDTH+STATUS_SPACE)) < STATUS_SPACE) |
271 | return -1; |
271 | return -1; |
272 | 272 | ||
273 | return (x-status_start) / (STATUS_WIDTH+STATUS_SPACE); |
273 | return (x-status_start) / (STATUS_WIDTH+STATUS_SPACE); |
274 | } |
274 | } |
275 | 275 | ||
276 | /** Handle mouse click |
276 | /** Handle mouse click |
277 | * |
277 | * |
278 | * @param state New state (1-pressed, 0-depressed) |
278 | * @param state New state (1-pressed, 0-depressed) |
279 | */ |
279 | */ |
280 | int gcons_mouse_btn(int state) |
280 | int gcons_mouse_btn(int state) |
281 | { |
281 | { |
282 | int conbut; |
282 | int conbut; |
283 | 283 | ||
284 | if (state) { |
284 | if (state) { |
285 | conbut = gcons_find_conbut(mouse_x, mouse_y); |
285 | conbut = gcons_find_conbut(mouse_x, mouse_y); |
286 | if (conbut != -1) { |
286 | if (conbut != -1) { |
287 | btn_pressed = 1; |
287 | btn_pressed = 1; |
288 | btn_x = mouse_x; |
288 | btn_x = mouse_x; |
289 | btn_y = mouse_y; |
289 | btn_y = mouse_y; |
290 | } |
290 | } |
291 | return -1; |
291 | return -1; |
292 | } |
292 | } |
293 | if (!state && !btn_pressed) |
293 | if (!state && !btn_pressed) |
294 | return -1; |
294 | return -1; |
295 | btn_pressed = 0; |
295 | btn_pressed = 0; |
296 | 296 | ||
297 | conbut = gcons_find_conbut(mouse_x, mouse_y); |
297 | conbut = gcons_find_conbut(mouse_x, mouse_y); |
298 | if (conbut == gcons_find_conbut(btn_x, btn_y)) |
298 | if (conbut == gcons_find_conbut(btn_x, btn_y)) |
299 | return conbut; |
299 | return conbut; |
300 | return -1; |
300 | return -1; |
301 | } |
301 | } |
302 | 302 | ||
303 | 303 | ||
304 | /** Draw a PPM pixmap to framebuffer |
304 | /** Draw a PPM pixmap to framebuffer |
305 | * |
305 | * |
306 | * @param logo Pointer to PPM data |
306 | * @param logo Pointer to PPM data |
307 | * @param size Size of PPM data |
307 | * @param size Size of PPM data |
308 | * @param x Coordinate of upper left corner |
308 | * @param x Coordinate of upper left corner |
309 | * @param y Coordinate of upper left corner |
309 | * @param y Coordinate of upper left corner |
310 | */ |
310 | */ |
311 | static void draw_pixmap(char *logo, size_t size, int x, int y) |
311 | static void draw_pixmap(char *logo, size_t size, int x, int y) |
312 | { |
312 | { |
313 | char *shm; |
313 | char *shm; |
314 | int rc; |
314 | int rc; |
315 | 315 | ||
316 | /* Create area */ |
316 | /* Create area */ |
317 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); |
317 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); |
318 | if (shm == MAP_FAILED) |
318 | if (shm == MAP_FAILED) |
319 | return; |
319 | return; |
320 | 320 | ||
321 | memcpy(shm, logo, size); |
321 | memcpy(shm, logo, size); |
322 | /* Send area */ |
322 | /* Send area */ |
323 | rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL); |
323 | rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL); |
324 | if (rc) |
324 | if (rc) |
325 | goto exit; |
325 | goto exit; |
326 | rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL); |
326 | rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL); |
327 | if (rc) |
327 | if (rc) |
328 | goto drop; |
328 | goto drop; |
329 | /* Draw logo */ |
329 | /* Draw logo */ |
330 | async_msg_2(fbphone, FB_DRAW_PPM, x, y); |
330 | async_msg_2(fbphone, FB_DRAW_PPM, x, y); |
331 | drop: |
331 | drop: |
332 | /* Drop area */ |
332 | /* Drop area */ |
333 | async_msg(fbphone, FB_DROP_SHM, 0); |
333 | async_msg(fbphone, FB_DROP_SHM, 0); |
334 | exit: |
334 | exit: |
335 | /* Remove area */ |
335 | /* Remove area */ |
336 | munmap(shm, size); |
336 | munmap(shm, size); |
337 | } |
337 | } |
338 | 338 | ||
339 | extern char _binary_helenos_ppm_start[0]; |
339 | extern char _binary_helenos_ppm_start[0]; |
340 | extern int _binary_helenos_ppm_size; |
340 | extern int _binary_helenos_ppm_size; |
341 | extern char _binary_nameic_ppm_start[0]; |
341 | extern char _binary_nameic_ppm_start[0]; |
342 | extern int _binary_nameic_ppm_size; |
342 | extern int _binary_nameic_ppm_size; |
343 | /** Redraws console graphics */ |
343 | /** Redraws console graphics */ |
344 | static void gcons_redraw_console(void) |
344 | static void gcons_redraw_console(void) |
345 | { |
345 | { |
346 | int i; |
346 | int i; |
347 | 347 | ||
348 | if (!use_gcons) |
348 | if (!use_gcons) |
349 | return; |
349 | return; |
350 | 350 | ||
351 | vp_switch(0); |
351 | vp_switch(0); |
352 | set_style(MAIN_COLOR, MAIN_COLOR); |
352 | set_style(MAIN_COLOR, MAIN_COLOR); |
353 | clear(); |
353 | clear(); |
354 | draw_pixmap(_binary_helenos_ppm_start, (size_t)&_binary_helenos_ppm_size, xres-66, 2); |
354 | draw_pixmap(_binary_helenos_ppm_start, (size_t)&_binary_helenos_ppm_size, xres-66, 2); |
355 | draw_pixmap(_binary_nameic_ppm_start, (size_t)&_binary_nameic_ppm_size, 5, 17); |
355 | draw_pixmap(_binary_nameic_ppm_start, (size_t)&_binary_nameic_ppm_size, 5, 17); |
356 | 356 | ||
357 | for (i=0;i < CONSOLE_COUNT; i++) |
357 | for (i=0;i < CONSOLE_COUNT; i++) |
358 | redraw_state(i); |
358 | redraw_state(i); |
359 | vp_switch(console_vp); |
359 | vp_switch(console_vp); |
360 | } |
360 | } |
361 | 361 | ||
362 | /** Creates a pixmap on framebuffer |
362 | /** Creates a pixmap on framebuffer |
363 | * |
363 | * |
364 | * @param data PPM data |
364 | * @param data PPM data |
365 | * @param size PPM data size |
365 | * @param size PPM data size |
366 | * @return Pixmap identification |
366 | * @return Pixmap identification |
367 | */ |
367 | */ |
368 | static int make_pixmap(char *data, int size) |
368 | static int make_pixmap(char *data, int size) |
369 | { |
369 | { |
370 | char *shm; |
370 | char *shm; |
371 | int rc; |
371 | int rc; |
372 | int pxid = -1; |
372 | int pxid = -1; |
373 | 373 | ||
374 | /* Create area */ |
374 | /* Create area */ |
375 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); |
375 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); |
376 | if (shm == MAP_FAILED) |
376 | if (shm == MAP_FAILED) |
377 | return -1; |
377 | return -1; |
378 | 378 | ||
379 | memcpy(shm, data, size); |
379 | memcpy(shm, data, size); |
380 | /* Send area */ |
380 | /* Send area */ |
381 | rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL); |
381 | rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL); |
382 | if (rc) |
382 | if (rc) |
383 | goto exit; |
383 | goto exit; |
384 | rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL); |
384 | rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL); |
385 | if (rc) |
385 | if (rc) |
386 | goto drop; |
386 | goto drop; |
387 | 387 | ||
388 | /* Obtain pixmap */ |
388 | /* Obtain pixmap */ |
389 | rc = async_req(fbphone, FB_SHM2PIXMAP, 0, NULL); |
389 | rc = async_req(fbphone, FB_SHM2PIXMAP, 0, NULL); |
390 | if (rc < 0) |
390 | if (rc < 0) |
391 | goto drop; |
391 | goto drop; |
392 | pxid = rc; |
392 | pxid = rc; |
393 | drop: |
393 | drop: |
394 | /* Drop area */ |
394 | /* Drop area */ |
395 | async_msg(fbphone, FB_DROP_SHM, 0); |
395 | async_msg(fbphone, FB_DROP_SHM, 0); |
396 | exit: |
396 | exit: |
397 | /* Remove area */ |
397 | /* Remove area */ |
398 | munmap(shm, size); |
398 | munmap(shm, size); |
399 | 399 | ||
400 | return pxid; |
400 | return pxid; |
401 | } |
401 | } |
402 | 402 | ||
403 | extern char _binary_anim_1_ppm_start[0]; |
403 | extern char _binary_anim_1_ppm_start[0]; |
404 | extern int _binary_anim_1_ppm_size; |
404 | extern int _binary_anim_1_ppm_size; |
405 | extern char _binary_anim_2_ppm_start[0]; |
405 | extern char _binary_anim_2_ppm_start[0]; |
406 | extern int _binary_anim_2_ppm_size; |
406 | extern int _binary_anim_2_ppm_size; |
407 | extern char _binary_anim_3_ppm_start[0]; |
407 | extern char _binary_anim_3_ppm_start[0]; |
408 | extern int _binary_anim_3_ppm_size; |
408 | extern int _binary_anim_3_ppm_size; |
409 | extern char _binary_anim_4_ppm_start[0]; |
409 | extern char _binary_anim_4_ppm_start[0]; |
410 | extern int _binary_anim_4_ppm_size; |
410 | extern int _binary_anim_4_ppm_size; |
411 | static void make_anim(void) |
411 | static void make_anim(void) |
412 | { |
412 | { |
413 | int an; |
413 | int an; |
414 | int pm; |
414 | int pm; |
415 | 415 | ||
416 | an = async_req(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE], NULL); |
416 | an = async_req(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE], NULL); |
417 | if (an < 0) |
417 | if (an < 0) |
418 | return; |
418 | return; |
419 | 419 | ||
420 | pm = make_pixmap(_binary_anim_1_ppm_start, (int)&_binary_anim_1_ppm_size); |
420 | pm = make_pixmap(_binary_anim_1_ppm_start, (int)&_binary_anim_1_ppm_size); |
421 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
421 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
422 | 422 | ||
423 | pm = make_pixmap(_binary_anim_2_ppm_start, (int)&_binary_anim_2_ppm_size); |
423 | pm = make_pixmap(_binary_anim_2_ppm_start, (int)&_binary_anim_2_ppm_size); |
424 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
424 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
425 | 425 | ||
426 | pm = make_pixmap(_binary_anim_3_ppm_start, (int)&_binary_anim_3_ppm_size); |
426 | pm = make_pixmap(_binary_anim_3_ppm_start, (int)&_binary_anim_3_ppm_size); |
427 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
427 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
428 | 428 | ||
429 | pm = make_pixmap(_binary_anim_4_ppm_start, (int)&_binary_anim_4_ppm_size); |
429 | pm = make_pixmap(_binary_anim_4_ppm_start, (int)&_binary_anim_4_ppm_size); |
430 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
430 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
431 | 431 | ||
432 | async_msg(fbphone, FB_ANIM_START, an); |
432 | async_msg(fbphone, FB_ANIM_START, an); |
433 | 433 | ||
434 | animation = an; |
434 | animation = an; |
435 | } |
435 | } |
436 | 436 | ||
437 | extern char _binary_cons_selected_ppm_start[0]; |
437 | extern char _binary_cons_selected_ppm_start[0]; |
438 | extern int _binary_cons_selected_ppm_size; |
438 | extern int _binary_cons_selected_ppm_size; |
439 | extern char _binary_cons_idle_ppm_start[0]; |
439 | extern char _binary_cons_idle_ppm_start[0]; |
440 | extern int _binary_cons_idle_ppm_size; |
440 | extern int _binary_cons_idle_ppm_size; |
441 | extern char _binary_cons_has_data_ppm_start[0]; |
441 | extern char _binary_cons_has_data_ppm_start[0]; |
442 | extern int _binary_cons_has_data_ppm_size; |
442 | extern int _binary_cons_has_data_ppm_size; |
443 | extern char _binary_cons_kernel_ppm_start[0]; |
443 | extern char _binary_cons_kernel_ppm_start[0]; |
444 | extern int _binary_cons_kernel_ppm_size; |
444 | extern int _binary_cons_kernel_ppm_size; |
445 | /** Initialize nice graphical console environment */ |
445 | /** Initialize nice graphical console environment */ |
446 | void gcons_init(int phone) |
446 | void gcons_init(int phone) |
447 | { |
447 | { |
448 | int rc; |
448 | int rc; |
449 | int i; |
449 | int i; |
450 | int status_start = STATUS_START; |
450 | int status_start = STATUS_START; |
451 | 451 | ||
452 | fbphone = phone; |
452 | fbphone = phone; |
453 | 453 | ||
454 | rc = async_req_2(phone, FB_GET_RESOLUTION, 0, 0, &xres, &yres); |
454 | rc = async_req_2(phone, FB_GET_RESOLUTION, 0, 0, &xres, &yres); |
455 | if (rc) |
455 | if (rc) |
456 | return; |
456 | return; |
457 | 457 | ||
458 | if (xres < 800 || yres < 600) |
458 | if (xres < 800 || yres < 600) |
459 | return; |
459 | return; |
460 | 460 | ||
461 | /* create console viewport */ |
461 | /* create console viewport */ |
462 | /* Align width & height to character size */ |
462 | /* Align width & height to character size */ |
463 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, |
463 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, |
464 | ALIGN_DOWN(xres-2*CONSOLE_MARGIN, 8), |
464 | ALIGN_DOWN(xres-2*CONSOLE_MARGIN, 8), |
465 | ALIGN_DOWN(yres-(CONSOLE_TOP+CONSOLE_MARGIN),16)); |
465 | ALIGN_DOWN(yres-(CONSOLE_TOP+CONSOLE_MARGIN),16)); |
466 | if (console_vp < 0) |
466 | if (console_vp < 0) |
467 | return; |
467 | return; |
468 | 468 | ||
469 | /* Create status buttons */ |
469 | /* Create status buttons */ |
470 | status_start += (xres-800) / 2; |
470 | status_start += (xres-800) / 2; |
471 | for (i=0; i < CONSOLE_COUNT; i++) { |
471 | for (i=0; i < CONSOLE_COUNT; i++) { |
472 | cstatus_vp[i] = vp_create(status_start+CONSOLE_MARGIN+i*(STATUS_WIDTH+STATUS_SPACE), |
472 | cstatus_vp[i] = vp_create(status_start+CONSOLE_MARGIN+i*(STATUS_WIDTH+STATUS_SPACE), |
473 | STATUS_TOP, STATUS_WIDTH, STATUS_HEIGHT); |
473 | STATUS_TOP, STATUS_WIDTH, STATUS_HEIGHT); |
474 | if (cstatus_vp[i] < 0) |
474 | if (cstatus_vp[i] < 0) |
475 | return; |
475 | return; |
476 | vp_switch(cstatus_vp[i]); |
476 | vp_switch(cstatus_vp[i]); |
477 | set_style(0x202020, 0xffffff); |
477 | set_style(0x202020, 0xffffff); |
478 | } |
478 | } |
479 | 479 | ||
480 | /* Initialize icons */ |
480 | /* Initialize icons */ |
481 | ic_pixmaps[CONS_SELECTED] = make_pixmap(_binary_cons_selected_ppm_start, |
481 | ic_pixmaps[CONS_SELECTED] = make_pixmap(_binary_cons_selected_ppm_start, |
482 | (int)&_binary_cons_selected_ppm_size); |
482 | (int)&_binary_cons_selected_ppm_size); |
483 | ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start, |
483 | ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start, |
484 | (int)&_binary_cons_idle_ppm_size); |
484 | (int)&_binary_cons_idle_ppm_size); |
485 | ic_pixmaps[CONS_HAS_DATA] = make_pixmap(_binary_cons_has_data_ppm_start, |
485 | ic_pixmaps[CONS_HAS_DATA] = make_pixmap(_binary_cons_has_data_ppm_start, |
486 | (int)&_binary_cons_has_data_ppm_size); |
486 | (int)&_binary_cons_has_data_ppm_size); |
487 | ic_pixmaps[CONS_DISCONNECTED] = make_pixmap(_binary_cons_idle_ppm_start, |
487 | ic_pixmaps[CONS_DISCONNECTED] = make_pixmap(_binary_cons_idle_ppm_start, |
488 | (int)&_binary_cons_idle_ppm_size); |
488 | (int)&_binary_cons_idle_ppm_size); |
489 | ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start, |
489 | ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start, |
490 | (int)&_binary_cons_kernel_ppm_size); |
490 | (int)&_binary_cons_kernel_ppm_size); |
491 | ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED]; |
491 | ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED]; |
492 | 492 | ||
493 | make_anim(); |
493 | make_anim(); |
494 | 494 | ||
495 | use_gcons = 1; |
495 | use_gcons = 1; |
496 | console_state[0] = CONS_DISCONNECTED_SEL; |
496 | console_state[0] = CONS_DISCONNECTED_SEL; |
497 | console_state[KERNEL_CONSOLE] = CONS_KERNEL; |
497 | console_state[KERNEL_CONSOLE] = CONS_KERNEL; |
498 | gcons_redraw_console(); |
498 | gcons_redraw_console(); |
499 | } |
499 | } |
500 | 500 | ||
501 | /** @} |
501 | /** @} |
502 | */ |
502 | */ |
503 | 503 | ||
504 | 504 |