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