Subversion Repositories HelenOS

Rev

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

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