Subversion Repositories HelenOS

Rev

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

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