Subversion Repositories HelenOS-historic

Rev

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

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