Subversion Repositories HelenOS

Rev

Rev 2927 | Rev 4338 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2927 Rev 3674
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 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_1(fbphone,FB_VIEWPORT_SWITCH, vp);
84
    async_msg_1(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, unsigned int width,
88
static int vp_create(unsigned int x, unsigned int y, unsigned int width,
89
    unsigned int height)
89
    unsigned int height)
90
{
90
{
91
    return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
91
    return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
92
        (width << 16) | height);
92
        (width << 16) | height);
93
}
93
}
94
 
94
 
95
static void clear(void)
95
static void clear(void)
96
{
96
{
97
    async_msg_0(fbphone, FB_CLEAR);
97
    async_msg_0(fbphone, FB_CLEAR);
98
}
98
}
99
 
99
 
100
static void set_style(int fgcolor, int bgcolor)
100
static void set_style(int fgcolor, int bgcolor)
101
{
101
{
102
    async_msg_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor);
102
    async_msg_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor);
103
}
103
}
104
 
104
 
105
/** Transparent putchar */
105
/** Transparent putchar */
106
static void tran_putch(char c, int row, int col)
106
static void tran_putch(char c, int row, int col)
107
{
107
{
108
    async_msg_3(fbphone, FB_TRANS_PUTCHAR, c, row, col);
108
    async_msg_3(fbphone, FB_TRANS_PUTCHAR, c, row, col);
109
}
109
}
110
 
110
 
111
/** Redraw the button showing state of a given console */
111
/** Redraw the button showing state of a given console */
112
static void redraw_state(int consnum)
112
static void redraw_state(int consnum)
113
{
113
{
114
    char data[5];
114
    char data[5];
115
    int i;
115
    int i;
116
    enum butstate state = console_state[consnum];
116
    enum butstate state = console_state[consnum];
117
 
117
 
118
    vp_switch(cstatus_vp[consnum]);
118
    vp_switch(cstatus_vp[consnum]);
119
    if (ic_pixmaps[state] != -1)
119
    if (ic_pixmaps[state] != -1)
120
        async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum],
120
        async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum],
121
            ic_pixmaps[state]);
121
            ic_pixmaps[state]);
122
 
122
 
123
    if (state != CONS_DISCONNECTED && state != CONS_KERNEL &&
123
    if (state != CONS_DISCONNECTED && state != CONS_KERNEL &&
124
        state != CONS_DISCONNECTED_SEL) {
124
        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_1(fbphone, FB_ANIM_START, animation);
143
            async_msg_1(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 ||
169
    if (consnum == active_console ||
170
        console_state[consnum] == CONS_HAS_DATA)
170
        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_1(fbphone, FB_ANIM_STOP, animation);
227
        async_msg_1(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
/** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */
233
/** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */
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;
243
int mouse_x, mouse_y;
244
int btn_pressed, btn_x, btn_y;
244
int btn_pressed, btn_x, btn_y;
245
 
245
 
246
/** Handle mouse move
246
/** Handle mouse move
247
 *
247
 *
248
 * @param dx Delta X of mouse move
248
 * @param dx Delta X of mouse move
249
 * @param dy Delta Y of mouse move
249
 * @param dy Delta Y of mouse move
250
 */
250
 */
251
void gcons_mouse_move(int dx, int dy)
251
void gcons_mouse_move(int dx, int dy)
252
{
252
{
253
    mouse_x = limit(mouse_x+dx, 0, xres);
253
    mouse_x = limit(mouse_x + dx, 0, xres);
254
    mouse_y = limit(mouse_y+dy, 0, yres);
254
    mouse_y = limit(mouse_y + dy, 0, yres);
255
 
255
 
256
    async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
256
    async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
257
}
257
}
258
 
258
 
259
static int gcons_find_conbut(int x, int y)
259
static int gcons_find_conbut(int x, int y)
260
{
260
{
261
    int status_start = STATUS_START + (xres - 800) / 2;;
261
    int status_start = STATUS_START + (xres - 800) / 2;
262
 
262
 
263
    if (y < STATUS_TOP || y >= STATUS_TOP + STATUS_HEIGHT)
263
    if (y < STATUS_TOP || y >= STATUS_TOP + STATUS_HEIGHT)
264
        return -1;
264
        return -1;
265
   
265
   
266
    if (x < status_start)
266
    if (x < status_start)
267
        return -1;
267
        return -1;
268
   
268
   
269
    if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
269
    if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
270
        return -1;
270
        return -1;
271
    if (((x - status_start) % (STATUS_WIDTH+STATUS_SPACE)) < STATUS_SPACE)
271
    if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
272
        return -1;
272
        return -1;
273
   
273
   
274
    return (x - status_start) / (STATUS_WIDTH+STATUS_SPACE);
274
    return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
275
}
275
}
276
 
276
 
277
/** Handle mouse click
277
/** Handle mouse click
278
 *
278
 *
279
 * @param state New state (1-pressed, 0-depressed)
279
 * @param state New state (1-pressed, 0-depressed)
280
 */
280
 */
281
int gcons_mouse_btn(int state)
281
int gcons_mouse_btn(int state)
282
{
282
{
283
    int conbut;
283
    int conbut;
284
 
284
 
285
    if (state) {
285
    if (state) {
286
        conbut = gcons_find_conbut(mouse_x, mouse_y);
286
        conbut = gcons_find_conbut(mouse_x, mouse_y);
287
        if (conbut != -1) {
287
        if (conbut != -1) {
288
            btn_pressed = 1;
288
            btn_pressed = 1;
289
            btn_x = mouse_x;
289
            btn_x = mouse_x;
290
            btn_y = mouse_y;
290
            btn_y = mouse_y;
291
        }
291
        }
292
        return -1;
292
        return -1;
293
    }
293
    }
294
    if (!state && !btn_pressed)
294
    if (!state && !btn_pressed)
295
        return -1;
295
        return -1;
296
    btn_pressed = 0;
296
    btn_pressed = 0;
297
 
297
 
298
    conbut = gcons_find_conbut(mouse_x, mouse_y);
298
    conbut = gcons_find_conbut(mouse_x, mouse_y);
299
    if (conbut == gcons_find_conbut(btn_x, btn_y))
299
    if (conbut == gcons_find_conbut(btn_x, btn_y))
300
        return conbut;
300
        return conbut;
301
    return -1;
301
    return -1;
302
}
302
}
303
 
303
 
304
 
304
 
305
/** Draw a PPM pixmap to framebuffer
305
/** Draw a PPM pixmap to framebuffer
306
 *
306
 *
307
 * @param logo Pointer to PPM data
307
 * @param logo Pointer to PPM data
308
 * @param size Size of PPM data
308
 * @param size Size of PPM data
309
 * @param x Coordinate of upper left corner
309
 * @param x Coordinate of upper left corner
310
 * @param y Coordinate of upper left corner
310
 * @param y Coordinate of upper left corner
311
 */
311
 */
312
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)
313
{
313
{
314
    char *shm;
314
    char *shm;
315
    int rc;
315
    int rc;
316
 
316
 
317
    /* Create area */
317
    /* Create area */
318
    shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
318
    shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
319
        MAP_ANONYMOUS, 0, 0);
319
        MAP_ANONYMOUS, 0, 0);
320
    if (shm == MAP_FAILED)
320
    if (shm == MAP_FAILED)
321
        return;
321
        return;
322
 
322
 
323
    memcpy(shm, logo, size);
323
    memcpy(shm, logo, size);
324
    /* Send area */
324
    /* Send area */
325
    rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
325
    rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
326
    if (rc)
326
    if (rc)
327
        goto exit;
327
        goto exit;
328
    rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
328
    rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
329
    if (rc)
329
    if (rc)
330
        goto drop;
330
        goto drop;
331
    /* Draw logo */
331
    /* Draw logo */
332
    async_msg_2(fbphone, FB_DRAW_PPM, x, y);
332
    async_msg_2(fbphone, FB_DRAW_PPM, x, y);
333
drop:
333
drop:
334
    /* Drop area */
334
    /* Drop area */
335
    async_msg_0(fbphone, FB_DROP_SHM);
335
    async_msg_0(fbphone, FB_DROP_SHM);
336
exit:      
336
exit:      
337
    /* Remove area */
337
    /* Remove area */
338
    munmap(shm, size);
338
    munmap(shm, size);
339
}
339
}
340
 
340
 
341
extern char _binary_helenos_ppm_start[0];
341
extern char _binary_helenos_ppm_start[0];
342
extern int _binary_helenos_ppm_size;
342
extern int _binary_helenos_ppm_size;
343
extern char _binary_nameic_ppm_start[0];
343
extern char _binary_nameic_ppm_start[0];
344
extern int _binary_nameic_ppm_size;
344
extern int _binary_nameic_ppm_size;
345
/** Redraws console graphics  */
345
/** Redraws console graphics  */
346
static void gcons_redraw_console(void)
346
static void gcons_redraw_console(void)
347
{
347
{
348
    int i;
348
    int i;
349
 
349
 
350
    if (!use_gcons)
350
    if (!use_gcons)
351
        return;
351
        return;
352
   
352
   
353
    vp_switch(0);
353
    vp_switch(0);
354
    set_style(MAIN_COLOR, MAIN_COLOR);
354
    set_style(MAIN_COLOR, MAIN_COLOR);
355
    clear();
355
    clear();
356
    draw_pixmap(_binary_helenos_ppm_start,
356
    draw_pixmap(_binary_helenos_ppm_start,
357
        (size_t) &_binary_helenos_ppm_size, xres - 66, 2);
357
        (size_t) &_binary_helenos_ppm_size, xres - 66, 2);
358
    draw_pixmap(_binary_nameic_ppm_start,
358
    draw_pixmap(_binary_nameic_ppm_start,
359
        (size_t) &_binary_nameic_ppm_size, 5, 17);
359
        (size_t) &_binary_nameic_ppm_size, 5, 17);
360
 
360
 
361
    for (i = 0; i < CONSOLE_COUNT; i++)
361
    for (i = 0; i < CONSOLE_COUNT; i++)
362
        redraw_state(i);
362
        redraw_state(i);
363
    vp_switch(console_vp);
363
    vp_switch(console_vp);
364
}
364
}
365
 
365
 
366
/** Creates a pixmap on framebuffer
366
/** Creates a pixmap on framebuffer
367
 *
367
 *
368
 * @param data PPM data
368
 * @param data PPM data
369
 * @param size PPM data size
369
 * @param size PPM data size
370
 * @return Pixmap identification
370
 * @return Pixmap identification
371
 */
371
 */
372
static int make_pixmap(char *data, int size)
372
static int make_pixmap(char *data, int size)
373
{
373
{
374
    char *shm;
374
    char *shm;
375
    int rc;
375
    int rc;
376
    int pxid = -1;
376
    int pxid = -1;
377
 
377
 
378
    /* Create area */
378
    /* Create area */
379
    shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
379
    shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
380
        MAP_ANONYMOUS, 0, 0);
380
        MAP_ANONYMOUS, 0, 0);
381
    if (shm == MAP_FAILED)
381
    if (shm == MAP_FAILED)
382
        return -1;
382
        return -1;
383
 
383
 
384
    memcpy(shm, data, size);
384
    memcpy(shm, data, size);
385
    /* Send area */
385
    /* Send area */
386
    rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
386
    rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
387
    if (rc)
387
    if (rc)
388
        goto exit;
388
        goto exit;
389
    rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
389
    rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
390
    if (rc)
390
    if (rc)
391
        goto drop;
391
        goto drop;
392
 
392
 
393
    /* Obtain pixmap */
393
    /* Obtain pixmap */
394
    rc = async_req_0_0(fbphone, FB_SHM2PIXMAP);
394
    rc = async_req_0_0(fbphone, FB_SHM2PIXMAP);
395
    if (rc < 0)
395
    if (rc < 0)
396
        goto drop;
396
        goto drop;
397
    pxid = rc;
397
    pxid = rc;
398
drop:
398
drop:
399
    /* Drop area */
399
    /* Drop area */
400
    async_msg_0(fbphone, FB_DROP_SHM);
400
    async_msg_0(fbphone, FB_DROP_SHM);
401
exit:      
401
exit:      
402
    /* Remove area */
402
    /* Remove area */
403
    munmap(shm, size);
403
    munmap(shm, size);
404
 
404
 
405
    return pxid;
405
    return pxid;
406
}
406
}
407
 
407
 
408
extern char _binary_anim_1_ppm_start[0];
408
extern char _binary_anim_1_ppm_start[0];
409
extern int _binary_anim_1_ppm_size;
409
extern int _binary_anim_1_ppm_size;
410
extern char _binary_anim_2_ppm_start[0];
410
extern char _binary_anim_2_ppm_start[0];
411
extern int _binary_anim_2_ppm_size;
411
extern int _binary_anim_2_ppm_size;
412
extern char _binary_anim_3_ppm_start[0];
412
extern char _binary_anim_3_ppm_start[0];
413
extern int _binary_anim_3_ppm_size;
413
extern int _binary_anim_3_ppm_size;
414
extern char _binary_anim_4_ppm_start[0];
414
extern char _binary_anim_4_ppm_start[0];
415
extern int _binary_anim_4_ppm_size;
415
extern int _binary_anim_4_ppm_size;
416
 
416
 
417
static void make_anim(void)
417
static void make_anim(void)
418
{
418
{
419
    int an;
419
    int an;
420
    int pm;
420
    int pm;
421
 
421
 
422
    an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
422
    an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
423
    if (an < 0)
423
    if (an < 0)
424
        return;
424
        return;
425
 
425
 
426
    pm = make_pixmap(_binary_anim_1_ppm_start,
426
    pm = make_pixmap(_binary_anim_1_ppm_start,
427
        (int) &_binary_anim_1_ppm_size);
427
        (int) &_binary_anim_1_ppm_size);
428
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
428
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
429
 
429
 
430
    pm = make_pixmap(_binary_anim_2_ppm_start,
430
    pm = make_pixmap(_binary_anim_2_ppm_start,
431
        (int) &_binary_anim_2_ppm_size);
431
        (int) &_binary_anim_2_ppm_size);
432
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
432
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
433
 
433
 
434
    pm = make_pixmap(_binary_anim_3_ppm_start,
434
    pm = make_pixmap(_binary_anim_3_ppm_start,
435
        (int) &_binary_anim_3_ppm_size);
435
        (int) &_binary_anim_3_ppm_size);
436
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
436
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
437
 
437
 
438
    pm = make_pixmap(_binary_anim_4_ppm_start,
438
    pm = make_pixmap(_binary_anim_4_ppm_start,
439
        (int) &_binary_anim_4_ppm_size);
439
        (int) &_binary_anim_4_ppm_size);
440
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
440
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
441
 
441
 
442
    async_msg_1(fbphone, FB_ANIM_START, an);
442
    async_msg_1(fbphone, FB_ANIM_START, an);
443
 
443
 
444
    animation = an;
444
    animation = an;
445
}
445
}
446
 
446
 
447
extern char _binary_cons_selected_ppm_start[0];
447
extern char _binary_cons_selected_ppm_start[0];
448
extern int _binary_cons_selected_ppm_size;
448
extern int _binary_cons_selected_ppm_size;
449
extern char _binary_cons_idle_ppm_start[0];
449
extern char _binary_cons_idle_ppm_start[0];
450
extern int _binary_cons_idle_ppm_size;
450
extern int _binary_cons_idle_ppm_size;
451
extern char _binary_cons_has_data_ppm_start[0];
451
extern char _binary_cons_has_data_ppm_start[0];
452
extern int _binary_cons_has_data_ppm_size;
452
extern int _binary_cons_has_data_ppm_size;
453
extern char _binary_cons_kernel_ppm_start[0];
453
extern char _binary_cons_kernel_ppm_start[0];
454
extern int _binary_cons_kernel_ppm_size;
454
extern int _binary_cons_kernel_ppm_size;
455
 
455
 
456
/** Initialize nice graphical console environment */
456
/** Initialize nice graphical console environment */
457
void gcons_init(int phone)
457
void gcons_init(int phone)
458
{
458
{
459
    int rc;
459
    int rc;
460
    int i;
460
    int i;
461
    int status_start = STATUS_START;
461
    int status_start = STATUS_START;
462
 
462
 
463
    fbphone = phone;
463
    fbphone = phone;
464
 
464
 
465
    rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
465
    rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
466
    if (rc)
466
    if (rc)
467
        return;
467
        return;
468
   
468
   
469
    if (xres < 800 || yres < 600)
469
    if (xres < 800 || yres < 600)
470
        return;
470
        return;
471
 
471
 
472
    /* create console viewport */
472
    /* create console viewport */
473
    /* Align width & height to character size */
473
    /* Align width & height to character size */
474
    console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
474
    console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
475
        ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
475
        ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
476
        ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
476
        ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
477
    if (console_vp < 0)
477
    if (console_vp < 0)
478
        return;
478
        return;
479
   
479
   
480
    /* Create status buttons */
480
    /* Create status buttons */
481
    status_start += (xres - 800) / 2;
481
    status_start += (xres - 800) / 2;
482
    for (i = 0; i < CONSOLE_COUNT; i++) {
482
    for (i = 0; i < CONSOLE_COUNT; i++) {
483
        cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
483
        cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
484
            i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
484
            i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
485
            STATUS_WIDTH, STATUS_HEIGHT);
485
            STATUS_WIDTH, STATUS_HEIGHT);
486
        if (cstatus_vp[i] < 0)
486
        if (cstatus_vp[i] < 0)
487
            return;
487
            return;
488
        vp_switch(cstatus_vp[i]);
488
        vp_switch(cstatus_vp[i]);
489
        set_style(0x202020, 0xffffff);
489
        set_style(0x202020, 0xffffff);
490
    }
490
    }
491
   
491
   
492
    /* Initialize icons */
492
    /* Initialize icons */
493
    ic_pixmaps[CONS_SELECTED] =
493
    ic_pixmaps[CONS_SELECTED] =
494
        make_pixmap(_binary_cons_selected_ppm_start,
494
        make_pixmap(_binary_cons_selected_ppm_start,
495
        (int) &_binary_cons_selected_ppm_size);
495
        (int) &_binary_cons_selected_ppm_size);
496
    ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start,
496
    ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start,
497
        (int) &_binary_cons_idle_ppm_size);
497
        (int) &_binary_cons_idle_ppm_size);
498
    ic_pixmaps[CONS_HAS_DATA] =
498
    ic_pixmaps[CONS_HAS_DATA] =
499
        make_pixmap(_binary_cons_has_data_ppm_start,
499
        make_pixmap(_binary_cons_has_data_ppm_start,
500
        (int) &_binary_cons_has_data_ppm_size);
500
        (int) &_binary_cons_has_data_ppm_size);
501
    ic_pixmaps[CONS_DISCONNECTED] =
501
    ic_pixmaps[CONS_DISCONNECTED] =
502
        make_pixmap(_binary_cons_idle_ppm_start,
502
        make_pixmap(_binary_cons_idle_ppm_start,
503
        (int) &_binary_cons_idle_ppm_size);
503
        (int) &_binary_cons_idle_ppm_size);
504
    ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start,
504
    ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start,
505
        (int) &_binary_cons_kernel_ppm_size);
505
        (int) &_binary_cons_kernel_ppm_size);
506
    ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
506
    ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
507
   
507
   
508
    make_anim();
508
    make_anim();
509
 
509
 
510
    use_gcons = 1;
510
    use_gcons = 1;
511
    console_state[0] = CONS_DISCONNECTED_SEL;
511
    console_state[0] = CONS_DISCONNECTED_SEL;
512
    console_state[KERNEL_CONSOLE] = CONS_KERNEL;
512
    console_state[KERNEL_CONSOLE] = CONS_KERNEL;
513
    gcons_redraw_console();
513
    gcons_redraw_console();
514
}
514
}
515
 
515
 
516
/** @}
516
/** @}
517
 */
517
 */
518
 
518
 
519
 
519