Subversion Repositories HelenOS

Rev

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

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