Subversion Repositories HelenOS-historic

Rev

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

Rev 1649 Rev 1668
1
/*
1
/*
2
 * Copyright (C) 2006 Jakub Vana
2
 * Copyright (C) 2006 Jakub Vana
3
 * Copyright (C) 2006 Ondrej Palkovsky
3
 * Copyright (C) 2006 Ondrej Palkovsky
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
/** @defgroup fbs Framebuffers
30
/** @defgroup fbs Framebuffers
31
 * @brief   HelenOS framebuffers.
31
 * @brief   HelenOS framebuffers.
32
 * @{
32
 * @{
33
 * @}
33
 * @}
34
 */
34
 */
35
/** @defgroup fb Framebuffer
35
/** @defgroup fb Framebuffer
36
 * @brief   HelenOS framebuffer.
36
 * @brief   HelenOS framebuffer.
37
 * @ingroup fbs
37
 * @ingroup fbs
38
 * @{
38
 * @{
39
 */
39
 */
40
/** @file
40
/** @file
41
 */
41
 */
42
 
42
 
43
 
43
 
44
#include <stdlib.h>
44
#include <stdlib.h>
45
#include <unistd.h>
45
#include <unistd.h>
46
#include <string.h>
46
#include <string.h>
47
#include <ddi.h>
47
#include <ddi.h>
48
#include <sysinfo.h>
48
#include <sysinfo.h>
49
#include <align.h>
49
#include <align.h>
50
#include <as.h>
50
#include <as.h>
51
#include <ipc/fb.h>
51
#include <ipc/fb.h>
52
#include <ipc/ipc.h>
52
#include <ipc/ipc.h>
53
#include <ipc/ns.h>
53
#include <ipc/ns.h>
54
#include <ipc/services.h>
54
#include <ipc/services.h>
55
#include <kernel/errno.h>
55
#include <kernel/errno.h>
56
#include <async.h>
56
#include <async.h>
57
 
57
 
58
#include "font-8x16.h"
58
#include "font-8x16.h"
59
#include "fb.h"
59
#include "fb.h"
60
#include "main.h"
60
#include "main.h"
61
#include "../console/screenbuffer.h"
61
#include "../console/screenbuffer.h"
62
#include "ppm.h"
62
#include "ppm.h"
63
 
63
 
64
#define DEFAULT_BGCOLOR                0xf0f0f0
64
#define DEFAULT_BGCOLOR                0xf0f0f0
65
#define DEFAULT_FGCOLOR                0x0
65
#define DEFAULT_FGCOLOR                0x0
66
 
66
 
67
/***************************************************************/
67
/***************************************************************/
68
/* Pixel specific fuctions */
68
/* Pixel specific fuctions */
69
 
69
 
70
typedef void (*conv2scr_fn_t)(void *, int);
70
typedef void (*conv2scr_fn_t)(void *, int);
71
typedef int (*conv2rgb_fn_t)(void *);
71
typedef int (*conv2rgb_fn_t)(void *);
72
 
72
 
73
struct {
73
struct {
74
    __u8 *fbaddress ;
74
    __u8 *fbaddress ;
75
 
75
 
76
    unsigned int xres ;
76
    unsigned int xres ;
77
    unsigned int yres ;
77
    unsigned int yres ;
78
    unsigned int scanline ;
78
    unsigned int scanline ;
79
    unsigned int pixelbytes ;
79
    unsigned int pixelbytes ;
80
 
80
 
81
    conv2scr_fn_t rgb2scr;
81
    conv2scr_fn_t rgb2scr;
82
    conv2rgb_fn_t scr2rgb;
82
    conv2rgb_fn_t scr2rgb;
83
} screen;
83
} screen;
84
 
84
 
85
typedef struct {
85
typedef struct {
86
    int initialized;
86
    int initialized;
87
    unsigned int x, y;
87
    unsigned int x, y;
88
    unsigned int width, height;
88
    unsigned int width, height;
89
 
89
 
90
    /* Text support in window */
90
    /* Text support in window */
91
    unsigned int rows, cols;
91
    unsigned int rows, cols;
92
    /* Style for text printing */
92
    /* Style for text printing */
93
    style_t style;
93
    style_t style;
94
    /* Auto-cursor position */
94
    /* Auto-cursor position */
95
    int cursor_active, cur_col, cur_row;
95
    int cursor_active, cur_col, cur_row;
96
    int cursor_shown;
96
    int cursor_shown;
97
} viewport_t;
97
} viewport_t;
98
 
98
 
99
#define MAX_ANIM_LEN    8
99
#define MAX_ANIM_LEN    8
100
#define MAX_ANIMATIONS  4
100
#define MAX_ANIMATIONS  4
101
typedef struct {
101
typedef struct {
102
    int initialized;
102
    int initialized;
103
    int enabled;
103
    int enabled;
104
    unsigned int vp;
104
    unsigned int vp;
105
 
105
 
106
    unsigned int pos;
106
    unsigned int pos;
107
    unsigned int animlen;
107
    unsigned int animlen;
108
    unsigned int pixmaps[MAX_ANIM_LEN];
108
    unsigned int pixmaps[MAX_ANIM_LEN];
109
} animation_t;
109
} animation_t;
110
static animation_t animations[MAX_ANIMATIONS];
110
static animation_t animations[MAX_ANIMATIONS];
111
static int anims_enabled;
111
static int anims_enabled;
112
 
112
 
113
/** Maximum number of saved pixmaps
113
/** Maximum number of saved pixmaps
114
 * Pixmap is a saved rectangle
114
 * Pixmap is a saved rectangle
115
 */
115
 */
116
#define MAX_PIXMAPS        256
116
#define MAX_PIXMAPS        256
117
typedef struct {
117
typedef struct {
118
    unsigned int width;
118
    unsigned int width;
119
    unsigned int height;
119
    unsigned int height;
120
    __u8 *data;
120
    __u8 *data;
121
} pixmap_t;
121
} pixmap_t;
122
static pixmap_t pixmaps[MAX_PIXMAPS];
122
static pixmap_t pixmaps[MAX_PIXMAPS];
123
 
123
 
124
/* Viewport is a rectangular area on the screen */
124
/* Viewport is a rectangular area on the screen */
125
#define MAX_VIEWPORTS 128
125
#define MAX_VIEWPORTS 128
126
static viewport_t viewports[128];
126
static viewport_t viewports[128];
127
 
127
 
128
/* Allow only 1 connection */
128
/* Allow only 1 connection */
129
static int client_connected = 0;
129
static int client_connected = 0;
130
 
130
 
131
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
131
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
132
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
132
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
133
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
133
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
134
 
134
 
135
#define COL_WIDTH   8
135
#define COL_WIDTH   8
136
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
136
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
137
 
137
 
138
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
138
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
139
 
139
 
140
/* Conversion routines between different color representations */
140
/* Conversion routines between different color representations */
141
static void rgb_4byte(void *dst, int rgb)
141
static void rgb_4byte(void *dst, int rgb)
142
{
142
{
143
    *(int *)dst = rgb;
143
    *(int *)dst = rgb;
144
}
144
}
145
 
145
 
146
static int byte4_rgb(void *src)
146
static int byte4_rgb(void *src)
147
{
147
{
148
    return (*(int *)src) & 0xffffff;
148
    return (*(int *)src) & 0xffffff;
149
}
149
}
150
 
150
 
151
static void rgb_3byte(void *dst, int rgb)
151
static void rgb_3byte(void *dst, int rgb)
152
{
152
{
153
    __u8 *scr = dst;
153
    __u8 *scr = dst;
154
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
154
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
155
    scr[0] = RED(rgb, 8);
155
    scr[0] = RED(rgb, 8);
156
    scr[1] = GREEN(rgb, 8);
156
    scr[1] = GREEN(rgb, 8);
157
    scr[2] = BLUE(rgb, 8);
157
    scr[2] = BLUE(rgb, 8);
158
#else
158
#else
159
    scr[2] = RED(rgb, 8);
159
    scr[2] = RED(rgb, 8);
160
    scr[1] = GREEN(rgb, 8);
160
    scr[1] = GREEN(rgb, 8);
161
    scr[0] = BLUE(rgb, 8);
161
    scr[0] = BLUE(rgb, 8);
162
#endif
162
#endif
163
 
163
 
164
 
164
 
165
}
165
}
166
 
166
 
167
static int byte3_rgb(void *src)
167
static int byte3_rgb(void *src)
168
{
168
{
169
    __u8 *scr = src;
169
    __u8 *scr = src;
170
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
170
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
171
    return scr[0] << 16 | scr[1] << 8 | scr[2];
171
    return scr[0] << 16 | scr[1] << 8 | scr[2];
172
#else
172
#else
173
    return scr[2] << 16 | scr[1] << 8 | scr[0];
173
    return scr[2] << 16 | scr[1] << 8 | scr[0];
174
#endif  
174
#endif  
175
}
175
}
176
 
176
 
177
/**  16-bit depth (5:6:5) */
177
/**  16-bit depth (5:6:5) */
178
static void rgb_2byte(void *dst, int rgb)
178
static void rgb_2byte(void *dst, int rgb)
179
{
179
{
180
    /* 5-bit, 6-bits, 5-bits */
180
    /* 5-bit, 6-bits, 5-bits */
181
    *((__u16 *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
181
    *((__u16 *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
182
}
182
}
183
 
183
 
184
/** 16-bit depth (5:6:5) */
184
/** 16-bit depth (5:6:5) */
185
static int byte2_rgb(void *src)
185
static int byte2_rgb(void *src)
186
{
186
{
187
    int color = *(__u16 *)(src);
187
    int color = *(__u16 *)(src);
188
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
188
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
189
}
189
}
190
 
190
 
191
/** Put pixel - 8-bit depth (3:2:3) */
191
/** Put pixel - 8-bit depth (3:2:3) */
192
static void rgb_1byte(void *dst, int rgb)
192
static void rgb_1byte(void *dst, int rgb)
193
{
193
{
194
    *(__u8 *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
194
    *(__u8 *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
195
}
195
}
196
 
196
 
197
/** Return pixel color - 8-bit depth (3:2:3) */
197
/** Return pixel color - 8-bit depth (3:2:3) */
198
static int byte1_rgb(void *src)
198
static int byte1_rgb(void *src)
199
{
199
{
200
    int color = *(__u8 *)src;
200
    int color = *(__u8 *)src;
201
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
201
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
202
}
202
}
203
 
203
 
204
/** Put pixel into viewport
204
/** Put pixel into viewport
205
 *
205
 *
206
 * @param vp Viewport identification
206
 * @param vp Viewport identification
207
 * @param x X coord relative to viewport
207
 * @param x X coord relative to viewport
208
 * @param y Y coord relative to viewport
208
 * @param y Y coord relative to viewport
209
 * @param color RGB color
209
 * @param color RGB color
210
 */
210
 */
211
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
211
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
212
{
212
{
213
    int dx = viewports[vp].x + x;
213
    int dx = viewports[vp].x + x;
214
    int dy = viewports[vp].y + y;
214
    int dy = viewports[vp].y + y;
215
    (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],color);
215
    (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],color);
216
}
216
}
217
/** Get pixel from viewport */
217
/** Get pixel from viewport */
218
static int getpixel(int vp, unsigned int x, unsigned int y)
218
static int getpixel(int vp, unsigned int x, unsigned int y)
219
{
219
{
220
    int dx = viewports[vp].x + x;
220
    int dx = viewports[vp].x + x;
221
    int dy = viewports[vp].y + y;
221
    int dy = viewports[vp].y + y;
222
 
222
 
223
    return (*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx,dy)]);
223
    return (*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx,dy)]);
224
}
224
}
225
 
225
 
226
/** Fill line with color BGCOLOR */
-
 
227
static void clear_line(int vp, unsigned int y)
226
static inline void putpixel_mem(char *mem, unsigned int x, unsigned int y,
-
 
227
                int color)
228
{
228
{
229
    unsigned int x;
-
 
230
    for (x = 0; x < viewports[vp].width; x++)
-
 
231
        putpixel(vp, x, y, viewports[vp].style.bg_color);
229
    (*screen.rgb2scr)(&mem[POINTPOS(x,y)],color);
232
}
230
}
233
 
231
 
234
static void draw_rectangle(int vp, unsigned int sx, unsigned int sy,
232
static void draw_rectangle(int vp, unsigned int sx, unsigned int sy,
235
               unsigned int width, unsigned int height,
233
               unsigned int width, unsigned int height,
236
               int color)
234
               int color)
237
{
235
{
238
    unsigned int x, y;
236
    unsigned int x, y;
-
 
237
    static void *tmpline;
-
 
238
 
-
 
239
    if (!tmpline)
-
 
240
        tmpline = malloc(screen.scanline*screen.pixelbytes);
239
 
241
 
240
    /* Clear first line */
242
    /* Clear first line */
241
    for (x = 0; x < width; x++)
243
    for (x = 0; x < width; x++)
242
        putpixel(vp, sx + x, sy, color);
244
        putpixel_mem(tmpline, x, 0, color);
243
 
245
 
244
    /* Recompute to screen coords */
246
    /* Recompute to screen coords */
245
    sx += viewports[vp].x;
247
    sx += viewports[vp].x;
246
    sy += viewports[vp].y;
248
    sy += viewports[vp].y;
247
    /* Copy the rest */
249
    /* Copy the rest */
248
    for (y = sy+1;y < sy+height; y++)
250
    for (y = sy;y < sy+height; y++)
249
        memcpy(&screen.fbaddress[POINTPOS(sx,y)],
251
        memcpy(&screen.fbaddress[POINTPOS(sx,y)], tmpline,
250
               &screen.fbaddress[POINTPOS(sx,sy)],
-
 
251
               screen.pixelbytes * width);
252
               screen.pixelbytes * width);
252
 
253
 
253
}
254
}
254
 
255
 
255
/** Fill viewport with background color */
256
/** Fill viewport with background color */
256
static void clear_port(int vp)
257
static void clear_port(int vp)
257
{
258
{
258
    viewport_t *vport = &viewports[vp];
259
    viewport_t *vport = &viewports[vp];
259
 
260
 
260
    draw_rectangle(vp, 0, 0, vport->width, vport->height, vport->style.bg_color);
261
    draw_rectangle(vp, 0, 0, vport->width, vport->height, vport->style.bg_color);
261
}
262
}
262
 
263
 
263
/** Scroll port up/down
264
/** Scroll port up/down
264
 *
265
 *
265
 * @param vp Viewport to scroll
266
 * @param vp Viewport to scroll
266
 * @param rows Positive number - scroll up, negative - scroll down
267
 * @param rows Positive number - scroll up, negative - scroll down
267
 */
268
 */
268
static void scroll_port(int vp, int rows)
269
static void scroll_port(int vp, int rows)
269
{
270
{
270
    int y;
271
    int y;
271
    int startline;
272
    int startline;
272
    int endline;
273
    int endline;
273
    viewport_t *vport = &viewports[vp];
274
    viewport_t *vport = &viewports[vp];
274
   
275
   
275
    if (rows > 0) {
276
    if (rows > 0) {
276
        for (y=vport->y; y < vport->y+vport->height - rows*FONT_SCANLINES; y++)
277
        for (y=vport->y; y < vport->y+vport->height - rows*FONT_SCANLINES; y++)
277
            memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
278
            memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
278
                   &screen.fbaddress[POINTPOS(vport->x,y + rows*FONT_SCANLINES)],
279
                   &screen.fbaddress[POINTPOS(vport->x,y + rows*FONT_SCANLINES)],
279
                   screen.pixelbytes * vport->width);
280
                   screen.pixelbytes * vport->width);
280
        draw_rectangle(vp, 0, FONT_SCANLINES*(vport->rows - 1),
281
        draw_rectangle(vp, 0, FONT_SCANLINES*(vport->rows - 1),
281
                   vport->width, FONT_SCANLINES, vport->style.bg_color);
282
                   vport->width, FONT_SCANLINES, vport->style.bg_color);
282
    } else if (rows < 0) {
283
    } else if (rows < 0) {
283
        rows = -rows;
284
        rows = -rows;
284
        for (y=vport->y + vport->height-1; y >= vport->y + rows*FONT_SCANLINES; y--)
285
        for (y=vport->y + vport->height-1; y >= vport->y + rows*FONT_SCANLINES; y--)
285
            memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
286
            memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
286
                &screen.fbaddress[POINTPOS(vport->x,y - rows*FONT_SCANLINES)],
287
                &screen.fbaddress[POINTPOS(vport->x,y - rows*FONT_SCANLINES)],
287
                screen.pixelbytes * vport->width);
288
                screen.pixelbytes * vport->width);
288
        draw_rectangle(vp, 0, 0, vport->width, FONT_SCANLINES, vport->style.bg_color);
289
        draw_rectangle(vp, 0, 0, vport->width, FONT_SCANLINES, vport->style.bg_color);
289
    }
290
    }
290
}
291
}
291
 
292
 
292
static void invert_pixel(int vp,unsigned int x, unsigned int y)
293
static void invert_pixel(int vp,unsigned int x, unsigned int y)
293
{
294
{
294
    putpixel(vp, x, y, ~getpixel(vp, x, y));
295
    putpixel(vp, x, y, ~getpixel(vp, x, y));
295
}
296
}
296
 
297
 
297
 
298
 
298
/***************************************************************/
299
/***************************************************************/
299
/* Character-console functions */
300
/* Character-console functions */
300
 
301
 
301
/** Draw character at given position
302
/** Draw character at given position
302
 *
303
 *
303
 * @param vp Viewport where the character is printed
304
 * @param vp Viewport where the character is printed
304
 * @param sx Coordinates of top-left of the character
305
 * @param sx Coordinates of top-left of the character
305
 * @param sy Coordinates of top-left of the character
306
 * @param sy Coordinates of top-left of the character
306
 * @param style Color of the character
307
 * @param style Color of the character
307
 * @param transparent If false, print background color
308
 * @param transparent If false, print background color
308
 */
309
 */
309
static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy,
310
static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy,
310
               style_t style, int transparent)
311
               style_t style, int transparent)
311
{
312
{
312
    int i;
313
    int i;
313
    unsigned int y;
314
    unsigned int y;
314
    unsigned int glline;
315
    unsigned int glline;
315
 
316
 
316
    for (y = 0; y < FONT_SCANLINES; y++) {
317
    for (y = 0; y < FONT_SCANLINES; y++) {
317
        glline = fb_font[glyph * FONT_SCANLINES + y];
318
        glline = fb_font[glyph * FONT_SCANLINES + y];
318
        for (i = 0; i < 8; i++) {
319
        for (i = 0; i < 8; i++) {
319
            if (glline & (1 << (7 - i)))
320
            if (glline & (1 << (7 - i)))
320
                putpixel(vp, sx + i, sy + y, style.fg_color);
321
                putpixel(vp, sx + i, sy + y, style.fg_color);
321
            else if (!transparent)
322
            else if (!transparent)
322
                putpixel(vp, sx + i, sy + y, style.bg_color);
323
                putpixel(vp, sx + i, sy + y, style.bg_color);
323
        }
324
        }
324
    }
325
    }
325
}
326
}
326
 
327
 
327
/** Invert character at given position */
328
/** Invert character at given position */
328
static void invert_char(int vp,unsigned int row, unsigned int col)
329
static void invert_char(int vp,unsigned int row, unsigned int col)
329
{
330
{
330
    unsigned int x;
331
    unsigned int x;
331
    unsigned int y;
332
    unsigned int y;
332
 
333
 
333
    for (x = 0; x < COL_WIDTH; x++)
334
    for (x = 0; x < COL_WIDTH; x++)
334
        for (y = 0; y < FONT_SCANLINES; y++)
335
        for (y = 0; y < FONT_SCANLINES; y++)
335
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
336
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
336
}
337
}
337
 
338
 
338
/***************************************************************/
339
/***************************************************************/
339
/* Stdout specific functions */
340
/* Stdout specific functions */
340
 
341
 
341
 
342
 
342
/** Create new viewport
343
/** Create new viewport
343
 *
344
 *
344
 * @return New viewport number
345
 * @return New viewport number
345
 */
346
 */
346
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
347
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
347
               unsigned int height)
348
               unsigned int height)
348
{
349
{
349
    int i;
350
    int i;
350
 
351
 
351
    for (i=0; i < MAX_VIEWPORTS; i++) {
352
    for (i=0; i < MAX_VIEWPORTS; i++) {
352
        if (!viewports[i].initialized)
353
        if (!viewports[i].initialized)
353
            break;
354
            break;
354
    }
355
    }
355
    if (i == MAX_VIEWPORTS)
356
    if (i == MAX_VIEWPORTS)
356
        return ELIMIT;
357
        return ELIMIT;
357
 
358
 
358
    if (width ==0 || height == 0 ||
359
    if (width ==0 || height == 0 ||
359
        x+width > screen.xres || y+height > screen.yres)
360
        x+width > screen.xres || y+height > screen.yres)
360
        return EINVAL;
361
        return EINVAL;
361
    if (width < FONT_SCANLINES || height < COL_WIDTH)
362
    if (width < FONT_SCANLINES || height < COL_WIDTH)
362
        return EINVAL;
363
        return EINVAL;
363
 
364
 
364
    viewports[i].x = x;
365
    viewports[i].x = x;
365
    viewports[i].y = y;
366
    viewports[i].y = y;
366
    viewports[i].width = width;
367
    viewports[i].width = width;
367
    viewports[i].height = height;
368
    viewports[i].height = height;
368
   
369
   
369
    viewports[i].rows = height / FONT_SCANLINES;
370
    viewports[i].rows = height / FONT_SCANLINES;
370
    viewports[i].cols = width / COL_WIDTH;
371
    viewports[i].cols = width / COL_WIDTH;
371
 
372
 
372
    viewports[i].style.bg_color = DEFAULT_BGCOLOR;
373
    viewports[i].style.bg_color = DEFAULT_BGCOLOR;
373
    viewports[i].style.fg_color = DEFAULT_FGCOLOR;
374
    viewports[i].style.fg_color = DEFAULT_FGCOLOR;
374
   
375
   
375
    viewports[i].cur_col = 0;
376
    viewports[i].cur_col = 0;
376
    viewports[i].cur_row = 0;
377
    viewports[i].cur_row = 0;
377
    viewports[i].cursor_active = 0;
378
    viewports[i].cursor_active = 0;
378
 
379
 
379
    viewports[i].initialized = 1;
380
    viewports[i].initialized = 1;
380
 
381
 
381
    return i;
382
    return i;
382
}
383
}
383
 
384
 
384
 
385
 
385
/** Initialize framebuffer as a chardev output device
386
/** Initialize framebuffer as a chardev output device
386
 *
387
 *
387
 * @param addr Address of theframebuffer
388
 * @param addr Address of theframebuffer
388
 * @param x    Screen width in pixels
389
 * @param x    Screen width in pixels
389
 * @param y    Screen height in pixels
390
 * @param y    Screen height in pixels
390
 * @param bpp  Bits per pixel (8, 16, 24, 32)
391
 * @param bpp  Bits per pixel (8, 16, 24, 32)
391
 * @param scan Bytes per one scanline
392
 * @param scan Bytes per one scanline
392
 *
393
 *
393
 */
394
 */
394
static void screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
395
static void screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
395
{
396
{
396
    switch (bpp) {
397
    switch (bpp) {
397
        case 8:
398
        case 8:
398
            screen.rgb2scr = rgb_1byte;
399
            screen.rgb2scr = rgb_1byte;
399
            screen.scr2rgb = byte1_rgb;
400
            screen.scr2rgb = byte1_rgb;
400
            screen.pixelbytes = 1;
401
            screen.pixelbytes = 1;
401
            break;
402
            break;
402
        case 16:
403
        case 16:
403
            screen.rgb2scr = rgb_2byte;
404
            screen.rgb2scr = rgb_2byte;
404
            screen.scr2rgb = byte2_rgb;
405
            screen.scr2rgb = byte2_rgb;
405
            screen.pixelbytes = 2;
406
            screen.pixelbytes = 2;
406
            break;
407
            break;
407
        case 24:
408
        case 24:
408
            screen.rgb2scr = rgb_3byte;
409
            screen.rgb2scr = rgb_3byte;
409
            screen.scr2rgb = byte3_rgb;
410
            screen.scr2rgb = byte3_rgb;
410
            screen.pixelbytes = 3;
411
            screen.pixelbytes = 3;
411
            break;
412
            break;
412
        case 32:
413
        case 32:
413
            screen.rgb2scr = rgb_4byte;
414
            screen.rgb2scr = rgb_4byte;
414
            screen.scr2rgb = byte4_rgb;
415
            screen.scr2rgb = byte4_rgb;
415
            screen.pixelbytes = 4;
416
            screen.pixelbytes = 4;
416
            break;
417
            break;
417
    }
418
    }
418
 
419
 
419
       
420
       
420
    screen.fbaddress = (unsigned char *) addr;
421
    screen.fbaddress = (unsigned char *) addr;
421
    screen.xres = xres;
422
    screen.xres = xres;
422
    screen.yres = yres;
423
    screen.yres = yres;
423
    screen.scanline = scan;
424
    screen.scanline = scan;
424
   
425
   
425
    /* Create first viewport */
426
    /* Create first viewport */
426
    viewport_create(0,0,xres,yres);
427
    viewport_create(0,0,xres,yres);
427
}
428
}
428
 
429
 
429
/** Hide cursor if it is shown */
430
/** Hide cursor if it is shown */
430
static void cursor_hide(int vp)
431
static void cursor_hide(int vp)
431
{
432
{
432
    viewport_t *vport = &viewports[vp];
433
    viewport_t *vport = &viewports[vp];
433
 
434
 
434
    if (vport->cursor_active && vport->cursor_shown) {
435
    if (vport->cursor_active && vport->cursor_shown) {
435
        invert_char(vp, vport->cur_row, vport->cur_col);
436
        invert_char(vp, vport->cur_row, vport->cur_col);
436
        vport->cursor_shown = 0;
437
        vport->cursor_shown = 0;
437
    }
438
    }
438
}
439
}
439
 
440
 
440
/** Show cursor if cursor showing is enabled */
441
/** Show cursor if cursor showing is enabled */
441
static void cursor_print(int vp)
442
static void cursor_print(int vp)
442
{
443
{
443
    viewport_t *vport = &viewports[vp];
444
    viewport_t *vport = &viewports[vp];
444
 
445
 
445
    /* Do not check for cursor_shown */
446
    /* Do not check for cursor_shown */
446
    if (vport->cursor_active) {
447
    if (vport->cursor_active) {
447
        invert_char(vp, vport->cur_row, vport->cur_col);
448
        invert_char(vp, vport->cur_row, vport->cur_col);
448
        vport->cursor_shown = 1;
449
        vport->cursor_shown = 1;
449
    }
450
    }
450
}
451
}
451
 
452
 
452
/** Invert cursor, if it is enabled */
453
/** Invert cursor, if it is enabled */
453
static void cursor_blink(int vp)
454
static void cursor_blink(int vp)
454
{
455
{
455
    viewport_t *vport = &viewports[vp];
456
    viewport_t *vport = &viewports[vp];
456
 
457
 
457
    if (vport->cursor_shown)
458
    if (vport->cursor_shown)
458
        cursor_hide(vp);
459
        cursor_hide(vp);
459
    else
460
    else
460
        cursor_print(vp);
461
        cursor_print(vp);
461
}
462
}
462
 
463
 
463
/** Draw character at given position relative to viewport
464
/** Draw character at given position relative to viewport
464
 *
465
 *
465
 * @param vp Viewport identification
466
 * @param vp Viewport identification
466
 * @param c Character to print
467
 * @param c Character to print
467
 * @param row Screen position relative to viewport
468
 * @param row Screen position relative to viewport
468
 * @param col Screen position relative to viewport
469
 * @param col Screen position relative to viewport
469
 * @param transparent If false, print background color with character
470
 * @param transparent If false, print background color with character
470
 */
471
 */
471
static void draw_char(int vp, char c, unsigned int row, unsigned int col, style_t style, int transparent)
472
static void draw_char(int vp, char c, unsigned int row, unsigned int col, style_t style, int transparent)
472
{
473
{
473
    viewport_t *vport = &viewports[vp];
474
    viewport_t *vport = &viewports[vp];
474
 
475
 
475
    /* Optimize - do not hide cursor if we are going to overwrite it */
476
    /* Optimize - do not hide cursor if we are going to overwrite it */
476
    if (vport->cursor_active && vport->cursor_shown &&
477
    if (vport->cursor_active && vport->cursor_shown &&
477
        (vport->cur_col != col || vport->cur_row != row))
478
        (vport->cur_col != col || vport->cur_row != row))
478
        invert_char(vp, vport->cur_row, vport->cur_col);
479
        invert_char(vp, vport->cur_row, vport->cur_col);
479
   
480
   
480
    draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES, style, transparent);
481
    draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES, style, transparent);
481
 
482
 
482
    vport->cur_col = col;
483
    vport->cur_col = col;
483
    vport->cur_row = row;
484
    vport->cur_row = row;
484
 
485
 
485
    vport->cur_col++;
486
    vport->cur_col++;
486
    if (vport->cur_col>= vport->cols) {
487
    if (vport->cur_col>= vport->cols) {
487
        vport->cur_col = 0;
488
        vport->cur_col = 0;
488
        vport->cur_row++;
489
        vport->cur_row++;
489
        if (vport->cur_row >= vport->rows)
490
        if (vport->cur_row >= vport->rows)
490
            vport->cur_row--;
491
            vport->cur_row--;
491
    }
492
    }
492
    cursor_print(vp);
493
    cursor_print(vp);
493
}
494
}
494
 
495
 
495
/** Draw text data to viewport
496
/** Draw text data to viewport
496
 *
497
 *
497
 * @param vp Viewport id
498
 * @param vp Viewport id
498
 * @param data Text data fitting exactly into viewport
499
 * @param data Text data fitting exactly into viewport
499
 */
500
 */
500
static void draw_text_data(int vp, keyfield_t *data)
501
static void draw_text_data(int vp, keyfield_t *data)
501
{
502
{
502
    viewport_t *vport = &viewports[vp];
503
    viewport_t *vport = &viewports[vp];
503
    int i;
504
    int i;
504
    char c;
505
    char c;
505
    int col,row;
506
    int col,row;
506
 
507
 
507
    clear_port(vp);
508
    clear_port(vp);
508
    for (i=0; i < vport->cols * vport->rows; i++) {
509
    for (i=0; i < vport->cols * vport->rows; i++) {
509
        if (data[i].character == ' ' && style_same(data[i].style,vport->style))
510
        if (data[i].character == ' ' && style_same(data[i].style,vport->style))
510
            continue;
511
            continue;
511
        col = i % vport->cols;
512
        col = i % vport->cols;
512
        row = i / vport->cols;
513
        row = i / vport->cols;
513
        draw_glyph(vp, data[i].character, col * COL_WIDTH, row * FONT_SCANLINES,
514
        draw_glyph(vp, data[i].character, col * COL_WIDTH, row * FONT_SCANLINES,
514
               data[i].style, style_same(data[i].style,vport->style));
515
               data[i].style, style_same(data[i].style,vport->style));
515
    }
516
    }
516
    cursor_print(vp);
517
    cursor_print(vp);
517
}
518
}
518
 
519
 
519
 
520
 
520
/** Return first free pixmap */
521
/** Return first free pixmap */
521
static int find_free_pixmap(void)
522
static int find_free_pixmap(void)
522
{
523
{
523
    int i;
524
    int i;
524
   
525
   
525
    for (i=0;i < MAX_PIXMAPS;i++)
526
    for (i=0;i < MAX_PIXMAPS;i++)
526
        if (!pixmaps[i].data)
527
        if (!pixmaps[i].data)
527
            return i;
528
            return i;
528
    return -1;
529
    return -1;
529
}
530
}
530
 
531
 
531
static void putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color)
532
static void putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color)
532
{
533
{
533
    pixmap_t *pmap = &pixmaps[pm];
534
    pixmap_t *pmap = &pixmaps[pm];
534
    int pos = (y * pmap->width + x) * screen.pixelbytes;
535
    int pos = (y * pmap->width + x) * screen.pixelbytes;
535
 
536
 
536
    (*screen.rgb2scr)(&pmap->data[pos],color);
537
    (*screen.rgb2scr)(&pmap->data[pos],color);
537
}
538
}
538
 
539
 
539
/** Create a new pixmap and return appropriate ID */
540
/** Create a new pixmap and return appropriate ID */
540
static int shm2pixmap(char *shm, size_t size)
541
static int shm2pixmap(char *shm, size_t size)
541
{
542
{
542
    int pm;
543
    int pm;
543
    pixmap_t *pmap;
544
    pixmap_t *pmap;
544
 
545
 
545
    pm = find_free_pixmap();
546
    pm = find_free_pixmap();
546
    if (pm == -1)
547
    if (pm == -1)
547
        return ELIMIT;
548
        return ELIMIT;
548
    pmap = &pixmaps[pm];
549
    pmap = &pixmaps[pm];
549
   
550
   
550
    if (ppm_get_data(shm, size, &pmap->width, &pmap->height))
551
    if (ppm_get_data(shm, size, &pmap->width, &pmap->height))
551
        return EINVAL;
552
        return EINVAL;
552
   
553
   
553
    pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes);
554
    pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes);
554
    if (!pmap->data)
555
    if (!pmap->data)
555
        return ENOMEM;
556
        return ENOMEM;
556
 
557
 
557
    ppm_draw(shm, size, 0, 0, pmap->width, pmap->height,
558
    ppm_draw(shm, size, 0, 0, pmap->width, pmap->height,
558
         putpixel_pixmap, pm);
559
         putpixel_pixmap, pm);
559
 
560
 
560
    return pm;
561
    return pm;
561
}
562
}
562
 
563
 
563
/** Handle shared memory communication calls
564
/** Handle shared memory communication calls
564
 *
565
 *
565
 * Protocol for drawing pixmaps:
566
 * Protocol for drawing pixmaps:
566
 * - FB_PREPARE_SHM(client shm identification)
567
 * - FB_PREPARE_SHM(client shm identification)
567
 * - IPC_M_SEND_AS_AREA
568
 * - IPC_M_SEND_AS_AREA
568
 * - FB_DRAW_PPM(startx,starty)
569
 * - FB_DRAW_PPM(startx,starty)
569
 * - FB_DROP_SHM
570
 * - FB_DROP_SHM
570
 *
571
 *
571
 * Protocol for text drawing
572
 * Protocol for text drawing
572
 * - IPC_M_SEND_AS_AREA
573
 * - IPC_M_SEND_AS_AREA
573
 * - FB_DRAW_TEXT_DATA
574
 * - FB_DRAW_TEXT_DATA
574
 *
575
 *
575
 * @param callid Callid of the current call
576
 * @param callid Callid of the current call
576
 * @param call Current call data
577
 * @param call Current call data
577
 * @param vp Active viewport
578
 * @param vp Active viewport
578
 * @return 0 if the call was not handled byt this function, 1 otherwise
579
 * @return 0 if the call was not handled byt this function, 1 otherwise
579
 *
580
 *
580
 * note: this function is not threads safe, you would have
581
 * note: this function is not threads safe, you would have
581
 * to redefine static variables with __thread
582
 * to redefine static variables with __thread
582
 */
583
 */
583
static int shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
584
static int shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
584
{
585
{
585
    static keyfield_t *interbuffer = NULL;
586
    static keyfield_t *interbuffer = NULL;
586
    static size_t intersize = 0;
587
    static size_t intersize = 0;
587
 
588
 
588
    static char *shm = NULL;
589
    static char *shm = NULL;
589
    static ipcarg_t shm_id = 0;
590
    static ipcarg_t shm_id = 0;
590
    static size_t shm_size;
591
    static size_t shm_size;
591
 
592
 
592
    int handled = 1;
593
    int handled = 1;
593
    int retval = 0;
594
    int retval = 0;
594
    viewport_t *vport = &viewports[vp];
595
    viewport_t *vport = &viewports[vp];
595
    unsigned int x,y;
596
    unsigned int x,y;
596
 
597
 
597
    switch (IPC_GET_METHOD(*call)) {
598
    switch (IPC_GET_METHOD(*call)) {
598
    case IPC_M_AS_AREA_SEND:
599
    case IPC_M_AS_AREA_SEND:
599
        /* We accept one area for data interchange */
600
        /* We accept one area for data interchange */
600
        if (IPC_GET_ARG1(*call) == shm_id) {
601
        if (IPC_GET_ARG1(*call) == shm_id) {
601
            void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
602
            void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
602
            shm_size = IPC_GET_ARG2(*call);
603
            shm_size = IPC_GET_ARG2(*call);
603
            if (!ipc_answer_fast(callid, 0, (sysarg_t)dest, 0))
604
            if (!ipc_answer_fast(callid, 0, (sysarg_t)dest, 0))
604
                shm = dest;
605
                shm = dest;
605
            else
606
            else
606
                shm_id = 0;
607
                shm_id = 0;
607
            if (shm[0] != 'P')
608
            if (shm[0] != 'P')
608
                while (1)
609
                while (1)
609
                    ;
610
                    ;
610
            return 1;
611
            return 1;
611
        } else {
612
        } else {
612
            intersize = IPC_GET_ARG2(*call);
613
            intersize = IPC_GET_ARG2(*call);
613
            receive_comm_area(callid,call,(void **)&interbuffer);
614
            receive_comm_area(callid,call,(void **)&interbuffer);
614
        }
615
        }
615
        return 1;
616
        return 1;
616
    case FB_PREPARE_SHM:
617
    case FB_PREPARE_SHM:
617
        if (shm_id)
618
        if (shm_id)
618
            retval = EBUSY;
619
            retval = EBUSY;
619
        else
620
        else
620
            shm_id = IPC_GET_ARG1(*call);
621
            shm_id = IPC_GET_ARG1(*call);
621
        break;
622
        break;
622
       
623
       
623
    case FB_DROP_SHM:
624
    case FB_DROP_SHM:
624
        if (shm) {
625
        if (shm) {
625
            as_area_destroy(shm);
626
            as_area_destroy(shm);
626
            shm = NULL;
627
            shm = NULL;
627
        }
628
        }
628
        shm_id = 0;
629
        shm_id = 0;
629
        break;
630
        break;
630
 
631
 
631
    case FB_SHM2PIXMAP:
632
    case FB_SHM2PIXMAP:
632
        if (!shm) {
633
        if (!shm) {
633
            retval = EINVAL;
634
            retval = EINVAL;
634
            break;
635
            break;
635
        }
636
        }
636
        retval = shm2pixmap(shm, shm_size);
637
        retval = shm2pixmap(shm, shm_size);
637
        break;
638
        break;
638
    case FB_DRAW_PPM:
639
    case FB_DRAW_PPM:
639
        if (!shm) {
640
        if (!shm) {
640
            retval = EINVAL;
641
            retval = EINVAL;
641
            break;
642
            break;
642
        }
643
        }
643
        x = IPC_GET_ARG1(*call);
644
        x = IPC_GET_ARG1(*call);
644
        y = IPC_GET_ARG2(*call);
645
        y = IPC_GET_ARG2(*call);
645
        if (x > vport->width || y > vport->height) {
646
        if (x > vport->width || y > vport->height) {
646
            retval = EINVAL;
647
            retval = EINVAL;
647
            break;
648
            break;
648
        }
649
        }
649
       
650
       
650
        ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call),
651
        ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call),
651
             vport->width - x, vport->height - y, putpixel, vp);
652
             vport->width - x, vport->height - y, putpixel, vp);
652
        break;
653
        break;
653
    case FB_DRAW_TEXT_DATA:
654
    case FB_DRAW_TEXT_DATA:
654
        if (!interbuffer) {
655
        if (!interbuffer) {
655
            retval = EINVAL;
656
            retval = EINVAL;
656
            break;
657
            break;
657
        }
658
        }
658
        if (intersize < vport->cols*vport->rows*sizeof(*interbuffer)) {
659
        if (intersize < vport->cols*vport->rows*sizeof(*interbuffer)) {
659
            retval = EINVAL;
660
            retval = EINVAL;
660
            break;
661
            break;
661
        }
662
        }
662
        draw_text_data(vp, interbuffer);
663
        draw_text_data(vp, interbuffer);
663
        break;
664
        break;
664
    default:
665
    default:
665
        handled = 0;
666
        handled = 0;
666
    }
667
    }
667
   
668
   
668
    if (handled)
669
    if (handled)
669
        ipc_answer_fast(callid, retval, 0, 0);
670
        ipc_answer_fast(callid, retval, 0, 0);
670
    return handled;
671
    return handled;
671
}
672
}
672
 
673
 
673
/** Save viewport to pixmap */
674
/** Save viewport to pixmap */
674
static int save_vp_to_pixmap(int vp)
675
static int save_vp_to_pixmap(int vp)
675
{
676
{
676
    int pm;
677
    int pm;
677
    pixmap_t *pmap;
678
    pixmap_t *pmap;
678
    viewport_t *vport = &viewports[vp];
679
    viewport_t *vport = &viewports[vp];
679
    int x,y;
680
    int x,y;
680
    int rowsize;
681
    int rowsize;
681
    int tmp;
682
    int tmp;
682
 
683
 
683
    pm = find_free_pixmap();
684
    pm = find_free_pixmap();
684
    if (pm == -1)
685
    if (pm == -1)
685
        return ELIMIT;
686
        return ELIMIT;
686
   
687
   
687
    pmap = &pixmaps[pm];
688
    pmap = &pixmaps[pm];
688
    pmap->data = malloc(screen.pixelbytes * vport->width * vport->height);
689
    pmap->data = malloc(screen.pixelbytes * vport->width * vport->height);
689
    if (!pmap->data)
690
    if (!pmap->data)
690
        return ENOMEM;
691
        return ENOMEM;
691
 
692
 
692
    pmap->width = vport->width;
693
    pmap->width = vport->width;
693
    pmap->height = vport->height;
694
    pmap->height = vport->height;
694
   
695
   
695
    rowsize = vport->width * screen.pixelbytes;
696
    rowsize = vport->width * screen.pixelbytes;
696
    for (y=0;y < vport->height; y++) {
697
    for (y=0;y < vport->height; y++) {
697
        tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
698
        tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
698
        memcpy(pmap->data + rowsize*y, screen.fbaddress + tmp, rowsize);
699
        memcpy(pmap->data + rowsize*y, screen.fbaddress + tmp, rowsize);
699
    }
700
    }
700
    return pm;
701
    return pm;
701
}
702
}
702
 
703
 
703
/** Draw pixmap on screen
704
/** Draw pixmap on screen
704
 *
705
 *
705
 * @param vp Viewport to draw on
706
 * @param vp Viewport to draw on
706
 * @param pm Pixmap identifier
707
 * @param pm Pixmap identifier
707
 */
708
 */
708
static int draw_pixmap(int vp, int pm)
709
static int draw_pixmap(int vp, int pm)
709
{
710
{
710
    pixmap_t *pmap = &pixmaps[pm];
711
    pixmap_t *pmap = &pixmaps[pm];
711
    viewport_t *vport = &viewports[vp];
712
    viewport_t *vport = &viewports[vp];
712
    int x,y;
713
    int x,y;
713
    int tmp, srcrowsize;
714
    int tmp, srcrowsize;
714
    int realwidth, realheight, realrowsize;
715
    int realwidth, realheight, realrowsize;
715
 
716
 
716
    if (!pmap->data)
717
    if (!pmap->data)
717
        return EINVAL;
718
        return EINVAL;
718
 
719
 
719
    realwidth = pmap->width <= vport->width ? pmap->width : vport->width;
720
    realwidth = pmap->width <= vport->width ? pmap->width : vport->width;
720
    realheight = pmap->height <= vport->height ? pmap->height : vport->height;
721
    realheight = pmap->height <= vport->height ? pmap->height : vport->height;
721
 
722
 
722
    srcrowsize = vport->width * screen.pixelbytes;
723
    srcrowsize = vport->width * screen.pixelbytes;
723
    realrowsize = realwidth * screen.pixelbytes;
724
    realrowsize = realwidth * screen.pixelbytes;
724
 
725
 
725
    for (y=0; y < realheight; y++) {
726
    for (y=0; y < realheight; y++) {
726
        tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
727
        tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
727
        memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize, realrowsize);
728
        memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize, realrowsize);
728
    }
729
    }
729
    return 0;
730
    return 0;
730
}
731
}
731
 
732
 
732
/** Tick animation one step forward */
733
/** Tick animation one step forward */
733
static void anims_tick(void)
734
static void anims_tick(void)
734
{
735
{
735
    int i;
736
    int i;
736
    static int counts = 0;
737
    static int counts = 0;
737
   
738
   
738
    /* Limit redrawing */
739
    /* Limit redrawing */
739
    counts = (counts+1) % 8;
740
    counts = (counts+1) % 8;
740
    if (counts)
741
    if (counts)
741
        return;
742
        return;
742
 
743
 
743
    for (i=0; i < MAX_ANIMATIONS; i++) {
744
    for (i=0; i < MAX_ANIMATIONS; i++) {
744
        if (!animations[i].animlen || !animations[i].initialized || !animations[i].enabled)
745
        if (!animations[i].animlen || !animations[i].initialized || !animations[i].enabled)
745
            continue;
746
            continue;
746
        draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]);
747
        draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]);
747
        animations[i].pos = (animations[i].pos+1) % animations[i].animlen;
748
        animations[i].pos = (animations[i].pos+1) % animations[i].animlen;
748
    }
749
    }
749
}
750
}
750
 
751
 
751
static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
752
static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
752
{
753
{
753
    int handled = 1;
754
    int handled = 1;
754
    int retval = 0;
755
    int retval = 0;
755
    int i,nvp;
756
    int i,nvp;
756
    int newval;
757
    int newval;
757
 
758
 
758
    switch (IPC_GET_METHOD(*call)) {
759
    switch (IPC_GET_METHOD(*call)) {
759
    case FB_ANIM_CREATE:
760
    case FB_ANIM_CREATE:
760
        nvp = IPC_GET_ARG1(*call);
761
        nvp = IPC_GET_ARG1(*call);
761
        if (nvp == -1)
762
        if (nvp == -1)
762
            nvp = vp;
763
            nvp = vp;
763
        if (nvp >= MAX_VIEWPORTS || nvp < 0 || !viewports[nvp].initialized) {
764
        if (nvp >= MAX_VIEWPORTS || nvp < 0 || !viewports[nvp].initialized) {
764
            retval = EINVAL;
765
            retval = EINVAL;
765
            break;
766
            break;
766
        }
767
        }
767
        for (i=0; i < MAX_ANIMATIONS; i++) {
768
        for (i=0; i < MAX_ANIMATIONS; i++) {
768
            if (! animations[i].initialized)
769
            if (! animations[i].initialized)
769
                break;
770
                break;
770
        }
771
        }
771
        if (i == MAX_ANIMATIONS) {
772
        if (i == MAX_ANIMATIONS) {
772
            retval = ELIMIT;
773
            retval = ELIMIT;
773
            break;
774
            break;
774
        }
775
        }
775
        animations[i].initialized = 1;
776
        animations[i].initialized = 1;
776
        animations[i].animlen = 0;
777
        animations[i].animlen = 0;
777
        animations[i].pos = 0;
778
        animations[i].pos = 0;
778
        animations[i].enabled = 0;
779
        animations[i].enabled = 0;
779
        animations[i].vp = nvp;
780
        animations[i].vp = nvp;
780
        retval = i;
781
        retval = i;
781
        break;
782
        break;
782
    case FB_ANIM_DROP:
783
    case FB_ANIM_DROP:
783
        i = IPC_GET_ARG1(*call);
784
        i = IPC_GET_ARG1(*call);
784
        if (nvp >= MAX_ANIMATIONS || i < 0) {
785
        if (nvp >= MAX_ANIMATIONS || i < 0) {
785
            retval = EINVAL;
786
            retval = EINVAL;
786
            break;
787
            break;
787
        }
788
        }
788
        animations[i].initialized = 0;
789
        animations[i].initialized = 0;
789
        break;
790
        break;
790
    case FB_ANIM_ADDPIXMAP:
791
    case FB_ANIM_ADDPIXMAP:
791
        i = IPC_GET_ARG1(*call);
792
        i = IPC_GET_ARG1(*call);
792
        if (i >= MAX_ANIMATIONS || i < 0 || !animations[i].initialized) {
793
        if (i >= MAX_ANIMATIONS || i < 0 || !animations[i].initialized) {
793
            retval = EINVAL;
794
            retval = EINVAL;
794
            break;
795
            break;
795
        }
796
        }
796
        if (animations[i].animlen == MAX_ANIM_LEN) {
797
        if (animations[i].animlen == MAX_ANIM_LEN) {
797
            retval = ELIMIT;
798
            retval = ELIMIT;
798
            break;
799
            break;
799
        }
800
        }
800
        newval = IPC_GET_ARG2(*call);
801
        newval = IPC_GET_ARG2(*call);
801
        if (newval < 0 || newval > MAX_PIXMAPS || !pixmaps[newval].data) {
802
        if (newval < 0 || newval > MAX_PIXMAPS || !pixmaps[newval].data) {
802
            retval = EINVAL;
803
            retval = EINVAL;
803
            break;
804
            break;
804
        }
805
        }
805
        animations[i].pixmaps[animations[i].animlen++] = newval;
806
        animations[i].pixmaps[animations[i].animlen++] = newval;
806
        break;
807
        break;
807
    case FB_ANIM_CHGVP:
808
    case FB_ANIM_CHGVP:
808
        i = IPC_GET_ARG1(*call);
809
        i = IPC_GET_ARG1(*call);
809
        if (i >= MAX_ANIMATIONS || i < 0) {
810
        if (i >= MAX_ANIMATIONS || i < 0) {
810
            retval = EINVAL;
811
            retval = EINVAL;
811
            break;
812
            break;
812
        }
813
        }
813
        nvp = IPC_GET_ARG2(*call);
814
        nvp = IPC_GET_ARG2(*call);
814
        if (nvp == -1)
815
        if (nvp == -1)
815
            nvp = vp;
816
            nvp = vp;
816
        if (nvp >= MAX_VIEWPORTS || nvp < 0 || !viewports[nvp].initialized) {
817
        if (nvp >= MAX_VIEWPORTS || nvp < 0 || !viewports[nvp].initialized) {
817
            retval = EINVAL;
818
            retval = EINVAL;
818
            break;
819
            break;
819
        }
820
        }
820
        animations[i].vp = nvp;
821
        animations[i].vp = nvp;
821
        break;
822
        break;
822
    case FB_ANIM_START:
823
    case FB_ANIM_START:
823
    case FB_ANIM_STOP:
824
    case FB_ANIM_STOP:
824
        i = IPC_GET_ARG1(*call);
825
        i = IPC_GET_ARG1(*call);
825
        if (i >= MAX_ANIMATIONS || i < 0) {
826
        if (i >= MAX_ANIMATIONS || i < 0) {
826
            retval = EINVAL;
827
            retval = EINVAL;
827
            break;
828
            break;
828
        }
829
        }
829
        newval = (IPC_GET_METHOD(*call) == FB_ANIM_START);
830
        newval = (IPC_GET_METHOD(*call) == FB_ANIM_START);
830
        if (newval ^ animations[i].enabled) {
831
        if (newval ^ animations[i].enabled) {
831
            animations[i].enabled = newval;
832
            animations[i].enabled = newval;
832
            anims_enabled += newval ? 1 : -1;
833
            anims_enabled += newval ? 1 : -1;
833
        }
834
        }
834
        break;
835
        break;
835
    default:
836
    default:
836
        handled = 0;
837
        handled = 0;
837
    }
838
    }
838
    if (handled)
839
    if (handled)
839
        ipc_answer_fast(callid, retval, 0, 0);
840
        ipc_answer_fast(callid, retval, 0, 0);
840
    return handled;
841
    return handled;
841
}
842
}
842
 
843
 
843
/** Handler for messages concerning pixmap handling */
844
/** Handler for messages concerning pixmap handling */
844
static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
845
static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
845
{
846
{
846
    int handled = 1;
847
    int handled = 1;
847
    int retval = 0;
848
    int retval = 0;
848
    int i,nvp;
849
    int i,nvp;
849
 
850
 
850
    switch (IPC_GET_METHOD(*call)) {
851
    switch (IPC_GET_METHOD(*call)) {
851
    case FB_VP_DRAW_PIXMAP:
852
    case FB_VP_DRAW_PIXMAP:
852
        nvp = IPC_GET_ARG1(*call);
853
        nvp = IPC_GET_ARG1(*call);
853
        if (nvp == -1)
854
        if (nvp == -1)
854
            nvp = vp;
855
            nvp = vp;
855
        if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized) {
856
        if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized) {
856
            retval = EINVAL;
857
            retval = EINVAL;
857
            break;
858
            break;
858
        }
859
        }
859
        i = IPC_GET_ARG2(*call);
860
        i = IPC_GET_ARG2(*call);
860
        retval = draw_pixmap(nvp, i);
861
        retval = draw_pixmap(nvp, i);
861
        break;
862
        break;
862
    case FB_VP2PIXMAP:
863
    case FB_VP2PIXMAP:
863
        nvp = IPC_GET_ARG1(*call);
864
        nvp = IPC_GET_ARG1(*call);
864
        if (nvp == -1)
865
        if (nvp == -1)
865
            nvp = vp;
866
            nvp = vp;
866
        if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized)
867
        if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized)
867
            retval = EINVAL;
868
            retval = EINVAL;
868
        else
869
        else
869
            retval = save_vp_to_pixmap(nvp);
870
            retval = save_vp_to_pixmap(nvp);
870
        break;
871
        break;
871
    case FB_DROP_PIXMAP:
872
    case FB_DROP_PIXMAP:
872
        i = IPC_GET_ARG1(*call);
873
        i = IPC_GET_ARG1(*call);
873
        if (i >= MAX_PIXMAPS) {
874
        if (i >= MAX_PIXMAPS) {
874
            retval = EINVAL;
875
            retval = EINVAL;
875
            break;
876
            break;
876
        }
877
        }
877
        if (pixmaps[i].data) {
878
        if (pixmaps[i].data) {
878
            free(pixmaps[i].data);
879
            free(pixmaps[i].data);
879
            pixmaps[i].data = NULL;
880
            pixmaps[i].data = NULL;
880
        }
881
        }
881
        break;
882
        break;
882
    default:
883
    default:
883
        handled = 0;
884
        handled = 0;
884
    }
885
    }
885
 
886
 
886
    if (handled)
887
    if (handled)
887
        ipc_answer_fast(callid, retval, 0, 0);
888
        ipc_answer_fast(callid, retval, 0, 0);
888
    return handled;
889
    return handled;
889
   
890
   
890
}
891
}
891
 
892
 
892
/** Function for handling connections to FB
893
/** Function for handling connections to FB
893
 *
894
 *
894
 */
895
 */
895
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
896
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
896
{
897
{
897
    ipc_callid_t callid;
898
    ipc_callid_t callid;
898
    ipc_call_t call;
899
    ipc_call_t call;
899
    int retval;
900
    int retval;
900
    int i;
901
    int i;
901
    unsigned int row,col;
902
    unsigned int row,col;
902
    char c;
903
    char c;
903
 
904
 
904
    int vp = 0;
905
    int vp = 0;
905
    viewport_t *vport = &viewports[0];
906
    viewport_t *vport = &viewports[0];
906
 
907
 
907
    if (client_connected) {
908
    if (client_connected) {
908
        ipc_answer_fast(iid, ELIMIT, 0,0);
909
        ipc_answer_fast(iid, ELIMIT, 0,0);
909
        return;
910
        return;
910
    }
911
    }
911
    client_connected = 1;
912
    client_connected = 1;
912
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
913
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
913
 
914
 
914
    while (1) {
915
    while (1) {
915
        if (vport->cursor_active || anims_enabled)
916
        if (vport->cursor_active || anims_enabled)
916
            callid = async_get_call_timeout(&call,250000);
917
            callid = async_get_call_timeout(&call,250000);
917
        else
918
        else
918
            callid = async_get_call(&call);
919
            callid = async_get_call(&call);
919
 
920
 
920
        if (!callid) {
921
        if (!callid) {
921
            cursor_blink(vp);
922
            cursor_blink(vp);
922
            anims_tick();
923
            anims_tick();
923
            continue;
924
            continue;
924
        }
925
        }
925
        if (shm_handle(callid, &call, vp))
926
        if (shm_handle(callid, &call, vp))
926
            continue;
927
            continue;
927
        if (pixmap_handle(callid, &call, vp))
928
        if (pixmap_handle(callid, &call, vp))
928
            continue;
929
            continue;
929
        if (anim_handle(callid, &call, vp))
930
        if (anim_handle(callid, &call, vp))
930
            continue;
931
            continue;
931
 
932
 
932
        switch (IPC_GET_METHOD(call)) {
933
        switch (IPC_GET_METHOD(call)) {
933
        case IPC_M_PHONE_HUNGUP:
934
        case IPC_M_PHONE_HUNGUP:
934
            client_connected = 0;
935
            client_connected = 0;
935
            /* cleanup other viewports */
936
            /* cleanup other viewports */
936
            for (i=1; i < MAX_VIEWPORTS; i++)
937
            for (i=1; i < MAX_VIEWPORTS; i++)
937
                vport->initialized = 0;
938
                vport->initialized = 0;
938
            return; /* Exit thread */
939
            return; /* Exit thread */
939
 
940
 
940
        case FB_PUTCHAR:
941
        case FB_PUTCHAR:
941
        case FB_TRANS_PUTCHAR:
942
        case FB_TRANS_PUTCHAR:
942
            c = IPC_GET_ARG1(call);
943
            c = IPC_GET_ARG1(call);
943
            row = IPC_GET_ARG2(call);
944
            row = IPC_GET_ARG2(call);
944
            col = IPC_GET_ARG3(call);
945
            col = IPC_GET_ARG3(call);
945
            if (row >= vport->rows || col >= vport->cols) {
946
            if (row >= vport->rows || col >= vport->cols) {
946
                retval = EINVAL;
947
                retval = EINVAL;
947
                break;
948
                break;
948
            }
949
            }
949
            ipc_answer_fast(callid,0,0,0);
950
            ipc_answer_fast(callid,0,0,0);
950
 
951
 
951
            draw_char(vp, c, row, col, vport->style, IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR);
952
            draw_char(vp, c, row, col, vport->style, IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR);
952
            continue; /* msg already answered */
953
            continue; /* msg already answered */
953
        case FB_CLEAR:
954
        case FB_CLEAR:
954
            clear_port(vp);
955
            clear_port(vp);
955
            cursor_print(vp);
956
            cursor_print(vp);
956
            retval = 0;
957
            retval = 0;
957
            break;
958
            break;
958
        case FB_CURSOR_GOTO:
959
        case FB_CURSOR_GOTO:
959
            row = IPC_GET_ARG1(call);
960
            row = IPC_GET_ARG1(call);
960
            col = IPC_GET_ARG2(call);
961
            col = IPC_GET_ARG2(call);
961
            if (row >= vport->rows || col >= vport->cols) {
962
            if (row >= vport->rows || col >= vport->cols) {
962
                retval = EINVAL;
963
                retval = EINVAL;
963
                break;
964
                break;
964
            }
965
            }
965
            retval = 0;
966
            retval = 0;
966
            cursor_hide(vp);
967
            cursor_hide(vp);
967
            vport->cur_col = col;
968
            vport->cur_col = col;
968
            vport->cur_row = row;
969
            vport->cur_row = row;
969
            cursor_print(vp);
970
            cursor_print(vp);
970
            break;
971
            break;
971
        case FB_CURSOR_VISIBILITY:
972
        case FB_CURSOR_VISIBILITY:
972
            cursor_hide(vp);
973
            cursor_hide(vp);
973
            vport->cursor_active = IPC_GET_ARG1(call);
974
            vport->cursor_active = IPC_GET_ARG1(call);
974
            cursor_print(vp);
975
            cursor_print(vp);
975
            retval = 0;
976
            retval = 0;
976
            break;
977
            break;
977
        case FB_GET_CSIZE:
978
        case FB_GET_CSIZE:
978
            ipc_answer_fast(callid, 0, vport->rows, vport->cols);
979
            ipc_answer_fast(callid, 0, vport->rows, vport->cols);
979
            continue;
980
            continue;
980
        case FB_SCROLL:
981
        case FB_SCROLL:
981
            i = IPC_GET_ARG1(call);
982
            i = IPC_GET_ARG1(call);
982
            if (i > vport->rows || i < (- (int)vport->rows)) {
983
            if (i > vport->rows || i < (- (int)vport->rows)) {
983
                retval = EINVAL;
984
                retval = EINVAL;
984
                break;
985
                break;
985
            }
986
            }
986
            cursor_hide(vp);
987
            cursor_hide(vp);
987
            scroll_port(vp, i);
988
            scroll_port(vp, i);
988
            cursor_print(vp);
989
            cursor_print(vp);
989
            retval = 0;
990
            retval = 0;
990
            break;
991
            break;
991
        case FB_VIEWPORT_SWITCH:
992
        case FB_VIEWPORT_SWITCH:
992
            i = IPC_GET_ARG1(call);
993
            i = IPC_GET_ARG1(call);
993
            if (i < 0 || i >= MAX_VIEWPORTS) {
994
            if (i < 0 || i >= MAX_VIEWPORTS) {
994
                retval = EINVAL;
995
                retval = EINVAL;
995
                break;
996
                break;
996
            }
997
            }
997
            if (! viewports[i].initialized ) {
998
            if (! viewports[i].initialized ) {
998
                retval = EADDRNOTAVAIL;
999
                retval = EADDRNOTAVAIL;
999
                break;
1000
                break;
1000
            }
1001
            }
1001
            cursor_hide(vp);
1002
            cursor_hide(vp);
1002
            vp = i;
1003
            vp = i;
1003
            vport = &viewports[vp];
1004
            vport = &viewports[vp];
1004
            cursor_print(vp);
1005
            cursor_print(vp);
1005
            retval = 0;
1006
            retval = 0;
1006
            break;
1007
            break;
1007
        case FB_VIEWPORT_CREATE:
1008
        case FB_VIEWPORT_CREATE:
1008
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
1009
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
1009
                         IPC_GET_ARG1(call) & 0xffff,
1010
                         IPC_GET_ARG1(call) & 0xffff,
1010
                         IPC_GET_ARG2(call) >> 16,
1011
                         IPC_GET_ARG2(call) >> 16,
1011
                         IPC_GET_ARG2(call) & 0xffff);
1012
                         IPC_GET_ARG2(call) & 0xffff);
1012
            break;
1013
            break;
1013
        case FB_VIEWPORT_DELETE:
1014
        case FB_VIEWPORT_DELETE:
1014
            i = IPC_GET_ARG1(call);
1015
            i = IPC_GET_ARG1(call);
1015
            if (i < 0 || i >= MAX_VIEWPORTS) {
1016
            if (i < 0 || i >= MAX_VIEWPORTS) {
1016
                retval = EINVAL;
1017
                retval = EINVAL;
1017
                break;
1018
                break;
1018
            }
1019
            }
1019
            if (! viewports[i].initialized ) {
1020
            if (! viewports[i].initialized ) {
1020
                retval = EADDRNOTAVAIL;
1021
                retval = EADDRNOTAVAIL;
1021
                break;
1022
                break;
1022
            }
1023
            }
1023
            viewports[i].initialized = 0;
1024
            viewports[i].initialized = 0;
1024
            retval = 0;
1025
            retval = 0;
1025
            break;
1026
            break;
1026
        case FB_SET_STYLE:
1027
        case FB_SET_STYLE:
1027
            vport->style.fg_color = IPC_GET_ARG1(call);
1028
            vport->style.fg_color = IPC_GET_ARG1(call);
1028
            vport->style.bg_color = IPC_GET_ARG2(call);
1029
            vport->style.bg_color = IPC_GET_ARG2(call);
1029
            retval = 0;
1030
            retval = 0;
1030
            break;
1031
            break;
1031
        case FB_GET_RESOLUTION:
1032
        case FB_GET_RESOLUTION:
1032
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
1033
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
1033
            continue;
1034
            continue;
1034
        default:
1035
        default:
1035
            retval = ENOENT;
1036
            retval = ENOENT;
1036
        }
1037
        }
1037
        ipc_answer_fast(callid,retval,0,0);
1038
        ipc_answer_fast(callid,retval,0,0);
1038
    }
1039
    }
1039
}
1040
}
1040
 
1041
 
1041
/** Initialization of framebuffer */
1042
/** Initialization of framebuffer */
1042
int fb_init(void)
1043
int fb_init(void)
1043
{
1044
{
1044
    void *fb_ph_addr;
1045
    void *fb_ph_addr;
1045
    unsigned int fb_width;
1046
    unsigned int fb_width;
1046
    unsigned int fb_height;
1047
    unsigned int fb_height;
1047
    unsigned int fb_bpp;
1048
    unsigned int fb_bpp;
1048
    unsigned int fb_scanline;
1049
    unsigned int fb_scanline;
1049
    void *fb_addr;
1050
    void *fb_addr;
1050
    size_t asz;
1051
    size_t asz;
1051
 
1052
 
1052
    async_set_client_connection(fb_client_connection);
1053
    async_set_client_connection(fb_client_connection);
1053
 
1054
 
1054
    fb_ph_addr=(void *)sysinfo_value("fb.address.physical");
1055
    fb_ph_addr=(void *)sysinfo_value("fb.address.physical");
1055
    fb_width=sysinfo_value("fb.width");
1056
    fb_width=sysinfo_value("fb.width");
1056
    fb_height=sysinfo_value("fb.height");
1057
    fb_height=sysinfo_value("fb.height");
1057
    fb_bpp=sysinfo_value("fb.bpp");
1058
    fb_bpp=sysinfo_value("fb.bpp");
1058
    fb_scanline=sysinfo_value("fb.scanline");
1059
    fb_scanline=sysinfo_value("fb.scanline");
1059
 
1060
 
1060
    asz = fb_scanline*fb_height;
1061
    asz = fb_scanline*fb_height;
1061
    fb_addr = as_get_mappable_page(asz);
1062
    fb_addr = as_get_mappable_page(asz);
1062
   
1063
   
1063
    map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz,PAGE_SIZE) >>PAGE_WIDTH,
1064
    map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz,PAGE_SIZE) >>PAGE_WIDTH,
1064
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
1065
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
1065
   
1066
   
1066
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
1067
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
1067
 
1068
 
1068
    return 0;
1069
    return 0;
1069
}
1070
}
1070
 
1071
 
1071
 
1072
 
1072
/**
1073
/**
1073
 * @}
1074
 * @}
1074
 */
1075
 */
1075
 
1076