Subversion Repositories HelenOS

Rev

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

Rev 4226 Rev 4232
1
/*
1
/*
2
 * Copyright (c) 2008 Martin Decky
2
 * Copyright (c) 2008 Martin Decky
3
 * Copyright (c) 2006 Jakub Vana
3
 * Copyright (c) 2006 Jakub Vana
4
 * Copyright (c) 2006 Ondrej Palkovsky
4
 * Copyright (c) 2006 Ondrej Palkovsky
5
 * All rights reserved.
5
 * All rights reserved.
6
 *
6
 *
7
 * Redistribution and use in source and binary forms, with or without
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
8
 * modification, are permitted provided that the following conditions
9
 * are met:
9
 * are met:
10
 *
10
 *
11
 * - Redistributions of source code must retain the above copyright
11
 * - Redistributions of source code must retain the above copyright
12
 *   notice, this list of conditions and the following disclaimer.
12
 *   notice, this list of conditions and the following disclaimer.
13
 * - Redistributions in binary form must reproduce the above copyright
13
 * - Redistributions in binary form must reproduce the above copyright
14
 *   notice, this list of conditions and the following disclaimer in the
14
 *   notice, this list of conditions and the following disclaimer in the
15
 *   documentation and/or other materials provided with the distribution.
15
 *   documentation and/or other materials provided with the distribution.
16
 * - The name of the author may not be used to endorse or promote products
16
 * - The name of the author may not be used to endorse or promote products
17
 *   derived from this software without specific prior written permission.
17
 *   derived from this software without specific prior written permission.
18
 *
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
29
 */
30
 
30
 
31
/**
31
/**
32
 * @defgroup fb Graphical framebuffer
32
 * @defgroup fb Graphical framebuffer
33
 * @brief   HelenOS graphical framebuffer.
33
 * @brief   HelenOS graphical framebuffer.
34
 * @ingroup fbs
34
 * @ingroup fbs
35
 * @{
35
 * @{
36
 */
36
 */
37
 
37
 
38
/** @file
38
/** @file
39
 */
39
 */
40
 
40
 
41
#include <stdlib.h>
41
#include <stdlib.h>
42
#include <unistd.h>
42
#include <unistd.h>
43
#include <string.h>
43
#include <string.h>
44
#include <ddi.h>
44
#include <ddi.h>
45
#include <sysinfo.h>
45
#include <sysinfo.h>
46
#include <align.h>
46
#include <align.h>
47
#include <as.h>
47
#include <as.h>
48
#include <ipc/fb.h>
48
#include <ipc/fb.h>
49
#include <ipc/ipc.h>
49
#include <ipc/ipc.h>
50
#include <ipc/ns.h>
50
#include <ipc/ns.h>
51
#include <ipc/services.h>
51
#include <ipc/services.h>
52
#include <kernel/errno.h>
52
#include <kernel/errno.h>
53
#include <kernel/genarch/fb/visuals.h>
53
#include <kernel/genarch/fb/visuals.h>
54
#include <console/color.h>
54
#include <console/color.h>
55
#include <console/style.h>
55
#include <console/style.h>
56
#include <async.h>
56
#include <async.h>
57
#include <bool.h>
57
#include <bool.h>
58
 
58
 
59
#include "font-8x16.h"
59
#include "font-8x16.h"
60
#include "fb.h"
60
#include "fb.h"
61
#include "main.h"
61
#include "main.h"
62
#include "../console/screenbuffer.h"
62
#include "../console/screenbuffer.h"
63
#include "ppm.h"
63
#include "ppm.h"
64
 
64
 
65
#include "pointer.xbm"
65
#include "pointer.xbm"
66
#include "pointer_mask.xbm"
66
#include "pointer_mask.xbm"
67
 
67
 
68
#define DEFAULT_BGCOLOR  0xf0f0f0
68
#define DEFAULT_BGCOLOR  0xf0f0f0
69
#define DEFAULT_FGCOLOR  0x000000
69
#define DEFAULT_FGCOLOR  0x000000
70
 
70
 
71
#define GLYPH_UNAVAIL   '?'
71
#define GLYPH_UNAVAIL   '?'
72
 
72
 
73
#define MAX_ANIM_LEN     8
73
#define MAX_ANIM_LEN     8
74
#define MAX_ANIMATIONS   4
74
#define MAX_ANIMATIONS   4
75
#define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
75
#define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
76
#define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
76
#define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
77
 
77
 
78
/** Function to render a pixel from a RGB value. */
78
/** Function to render a pixel from a RGB value. */
79
typedef void (*rgb_conv_t)(void *, uint32_t);
79
typedef void (*rgb_conv_t)(void *, uint32_t);
80
 
80
 
81
/** Function to draw a glyph. */
81
/** Function to draw a glyph. */
82
typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor,
82
typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor,
83
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color);
83
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color);
84
 
84
 
85
struct {
85
struct {
86
    uint8_t *fb_addr;
86
    uint8_t *fb_addr;
87
   
87
   
88
    unsigned int xres;
88
    unsigned int xres;
89
    unsigned int yres;
89
    unsigned int yres;
90
   
90
   
91
    unsigned int scanline;
91
    unsigned int scanline;
92
    unsigned int glyphscanline;
92
    unsigned int glyphscanline;
93
   
93
   
94
    unsigned int pixelbytes;
94
    unsigned int pixelbytes;
95
    unsigned int glyphbytes;
95
    unsigned int glyphbytes;
96
   
96
   
97
    rgb_conv_t rgb_conv;
97
    rgb_conv_t rgb_conv;
98
} screen;
98
} screen;
99
 
99
 
100
/** Backbuffer character cell. */
100
/** Backbuffer character cell. */
101
typedef struct {
101
typedef struct {
102
    uint32_t glyph;
102
    uint32_t glyph;
103
    uint32_t fg_color;
103
    uint32_t fg_color;
104
    uint32_t bg_color;
104
    uint32_t bg_color;
105
} bb_cell_t;
105
} bb_cell_t;
106
 
106
 
107
typedef struct {
107
typedef struct {
108
    bool initialized;
108
    bool initialized;
109
    unsigned int x;
109
    unsigned int x;
110
    unsigned int y;
110
    unsigned int y;
111
    unsigned int width;
111
    unsigned int width;
112
    unsigned int height;
112
    unsigned int height;
113
   
113
   
114
    /* Text support in window */
114
    /* Text support in window */
115
    unsigned int cols;
115
    unsigned int cols;
116
    unsigned int rows;
116
    unsigned int rows;
117
   
117
   
118
    /*
118
    /*
119
     * Style and glyphs for text printing
119
     * Style and glyphs for text printing
120
     */
120
     */
121
 
121
 
122
    /** Current attributes. */
122
    /** Current attributes. */
123
    attr_rgb_t attr;
123
    attr_rgb_t attr;
124
 
124
 
125
    /** Pre-rendered mask for rendering glyphs. Different viewports
125
    /** Pre-rendered mask for rendering glyphs. Different viewports
126
     * might use different drawing functions depending on whether their
126
     * might use different drawing functions depending on whether their
127
     * scanlines are aligned on a word boundary.*/
127
     * scanlines are aligned on a word boundary.*/
128
    uint8_t *glyphs;
128
    uint8_t *glyphs;
129
 
129
 
130
    uint8_t *bgpixel;
130
    uint8_t *bgpixel;
131
 
131
 
132
    /** Glyph drawing function for this viewport. */
132
    /** Glyph drawing function for this viewport. */
133
    dg_t dglyph;
133
    dg_t dglyph;
134
   
134
   
135
    /* Auto-cursor position */
135
    /* Auto-cursor position */
136
    bool cursor_active;
136
    bool cursor_active;
137
    unsigned int cur_col;
137
    unsigned int cur_col;
138
    unsigned int cur_row;
138
    unsigned int cur_row;
139
    bool cursor_shown;
139
    bool cursor_shown;
140
   
140
   
141
    /* Back buffer */
141
    /* Back buffer */
142
    bb_cell_t *backbuf;
142
    bb_cell_t *backbuf;
143
    unsigned int bbsize;
143
    unsigned int bbsize;
144
} viewport_t;
144
} viewport_t;
145
 
145
 
146
typedef struct {
146
typedef struct {
147
    bool initialized;
147
    bool initialized;
148
    bool enabled;
148
    bool enabled;
149
    unsigned int vp;
149
    unsigned int vp;
150
   
150
   
151
    unsigned int pos;
151
    unsigned int pos;
152
    unsigned int animlen;
152
    unsigned int animlen;
153
    unsigned int pixmaps[MAX_ANIM_LEN];
153
    unsigned int pixmaps[MAX_ANIM_LEN];
154
} animation_t;
154
} animation_t;
155
 
155
 
156
static animation_t animations[MAX_ANIMATIONS];
156
static animation_t animations[MAX_ANIMATIONS];
157
static bool anims_enabled;
157
static bool anims_enabled;
158
 
158
 
159
typedef struct {
159
typedef struct {
160
    unsigned int width;
160
    unsigned int width;
161
    unsigned int height;
161
    unsigned int height;
162
    uint8_t *data;
162
    uint8_t *data;
163
} pixmap_t;
163
} pixmap_t;
164
 
164
 
165
static pixmap_t pixmaps[MAX_PIXMAPS];
165
static pixmap_t pixmaps[MAX_PIXMAPS];
166
static viewport_t viewports[128];
166
static viewport_t viewports[128];
167
 
167
 
168
static bool client_connected = false;  /**< Allow only 1 connection */
168
static bool client_connected = false;  /**< Allow only 1 connection */
169
 
169
 
170
static uint32_t color_table[16] = {
170
static uint32_t color_table[16] = {
171
    [COLOR_BLACK]       = 0x000000,
171
    [COLOR_BLACK]       = 0x000000,
172
    [COLOR_BLUE]        = 0x0000f0,
172
    [COLOR_BLUE]        = 0x0000f0,
173
    [COLOR_GREEN]       = 0x00f000,
173
    [COLOR_GREEN]       = 0x00f000,
174
    [COLOR_CYAN]        = 0x00f0f0,
174
    [COLOR_CYAN]        = 0x00f0f0,
175
    [COLOR_RED]     = 0xf00000,
175
    [COLOR_RED]     = 0xf00000,
176
    [COLOR_MAGENTA]     = 0xf000f0,
176
    [COLOR_MAGENTA]     = 0xf000f0,
177
    [COLOR_YELLOW]      = 0xf0f000,
177
    [COLOR_YELLOW]      = 0xf0f000,
178
    [COLOR_WHITE]       = 0xf0f0f0,
178
    [COLOR_WHITE]       = 0xf0f0f0,
179
 
179
 
180
    [8 + COLOR_BLACK]   = 0x000000,
180
    [8 + COLOR_BLACK]   = 0x000000,
181
    [8 + COLOR_BLUE]    = 0x0000ff,
181
    [8 + COLOR_BLUE]    = 0x0000ff,
182
    [8 + COLOR_GREEN]   = 0x00ff00,
182
    [8 + COLOR_GREEN]   = 0x00ff00,
183
    [8 + COLOR_CYAN]    = 0x00ffff,
183
    [8 + COLOR_CYAN]    = 0x00ffff,
184
    [8 + COLOR_RED]     = 0xff0000,
184
    [8 + COLOR_RED]     = 0xff0000,
185
    [8 + COLOR_MAGENTA] = 0xff00ff,
185
    [8 + COLOR_MAGENTA] = 0xff00ff,
186
    [8 + COLOR_YELLOW]  = 0xffff00,
186
    [8 + COLOR_YELLOW]  = 0xffff00,
187
    [8 + COLOR_WHITE]   = 0xffffff,
187
    [8 + COLOR_WHITE]   = 0xffffff,
188
};
188
};
189
 
189
 
190
static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a);
190
static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a);
191
static int rgb_from_style(attr_rgb_t *rgb, int style);
191
static int rgb_from_style(attr_rgb_t *rgb, int style);
192
static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color,
192
static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color,
193
    ipcarg_t bg_color, ipcarg_t flags);
193
    ipcarg_t bg_color, ipcarg_t flags);
194
 
194
 
195
static int fb_set_color(viewport_t *vport, ipcarg_t fg_color,
195
static int fb_set_color(viewport_t *vport, ipcarg_t fg_color,
196
    ipcarg_t bg_color, ipcarg_t attr);
196
    ipcarg_t bg_color, ipcarg_t attr);
197
 
197
 
198
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
198
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
199
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color);
199
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color);
200
static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
200
static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
201
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color);
201
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color);
202
 
202
 
203
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
203
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
204
    unsigned int row);
204
    unsigned int row);
205
 
205
 
206
 
206
 
207
#define RED(x, bits)                 ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
207
#define RED(x, bits)                 ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
208
#define GREEN(x, bits)               ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
208
#define GREEN(x, bits)               ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
209
#define BLUE(x, bits)                ((x >> (8 - bits)) & ((1 << bits) - 1))
209
#define BLUE(x, bits)                ((x >> (8 - bits)) & ((1 << bits) - 1))
210
 
210
 
211
#define COL2X(col)                   ((col) * FONT_WIDTH)
211
#define COL2X(col)                   ((col) * FONT_WIDTH)
212
#define ROW2Y(row)                   ((row) * FONT_SCANLINES)
212
#define ROW2Y(row)                   ((row) * FONT_SCANLINES)
213
 
213
 
214
#define X2COL(x)                     ((x) / FONT_WIDTH)
214
#define X2COL(x)                     ((x) / FONT_WIDTH)
215
#define Y2ROW(y)                     ((y) / FONT_SCANLINES)
215
#define Y2ROW(y)                     ((y) / FONT_SCANLINES)
216
 
216
 
217
#define FB_POS(x, y)                 ((y) * screen.scanline + (x) * screen.pixelbytes)
217
#define FB_POS(x, y)                 ((y) * screen.scanline + (x) * screen.pixelbytes)
218
#define BB_POS(vport, col, row)      ((row) * vport->cols + (col))
218
#define BB_POS(vport, col, row)      ((row) * vport->cols + (col))
219
#define GLYPH_POS(glyph, y, cursor)  (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline)
219
#define GLYPH_POS(glyph, y, cursor)  (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline)
220
 
220
 
221
 
221
 
222
/** ARGB 8:8:8:8 conversion
222
/** ARGB 8:8:8:8 conversion
223
 *
223
 *
224
 */
224
 */
225
static void rgb_0888(void *dst, uint32_t rgb)
225
static void rgb_0888(void *dst, uint32_t rgb)
226
{
226
{
227
    *((uint32_t *) dst) = rgb & 0xffffff;
227
    *((uint32_t *) dst) = rgb & 0xffffff;
228
}
228
}
229
 
229
 
230
 
230
 
231
/** ABGR 8:8:8:8 conversion
231
/** ABGR 8:8:8:8 conversion
232
 *
232
 *
233
 */
233
 */
234
static void bgr_0888(void *dst, uint32_t rgb)
234
static void bgr_0888(void *dst, uint32_t rgb)
235
{
235
{
236
    *((uint32_t *) dst)
236
    *((uint32_t *) dst)
237
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
237
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
238
}
238
}
239
 
239
 
240
 
240
 
241
/** RGB 8:8:8 conversion
241
/** RGB 8:8:8 conversion
242
 *
242
 *
243
 */
243
 */
244
static void rgb_888(void *dst, uint32_t rgb)
244
static void rgb_888(void *dst, uint32_t rgb)
245
{
245
{
246
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
246
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
247
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
247
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
248
    ((uint8_t *) dst)[2] = RED(rgb, 8);
248
    ((uint8_t *) dst)[2] = RED(rgb, 8);
249
}
249
}
250
 
250
 
251
 
251
 
252
/** BGR 8:8:8 conversion
252
/** BGR 8:8:8 conversion
253
 *
253
 *
254
 */
254
 */
255
static void bgr_888(void *dst, uint32_t rgb)
255
static void bgr_888(void *dst, uint32_t rgb)
256
{
256
{
257
    ((uint8_t *) dst)[0] = RED(rgb, 8);
257
    ((uint8_t *) dst)[0] = RED(rgb, 8);
258
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
258
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
259
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
259
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
260
}
260
}
261
 
261
 
262
 
262
 
263
/** RGB 5:5:5 conversion
263
/** RGB 5:5:5 conversion
264
 *
264
 *
265
 */
265
 */
266
static void rgb_555(void *dst, uint32_t rgb)
266
static void rgb_555(void *dst, uint32_t rgb)
267
{
267
{
268
    *((uint16_t *) dst)
268
    *((uint16_t *) dst)
269
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
269
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
270
}
270
}
271
 
271
 
272
 
272
 
273
/** RGB 5:6:5 conversion
273
/** RGB 5:6:5 conversion
274
 *
274
 *
275
 */
275
 */
276
static void rgb_565(void *dst, uint32_t rgb)
276
static void rgb_565(void *dst, uint32_t rgb)
277
{
277
{
278
    *((uint16_t *) dst)
278
    *((uint16_t *) dst)
279
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
279
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
280
}
280
}
281
 
281
 
282
 
282
 
283
/** RGB 3:2:3
283
/** RGB 3:2:3
284
 *
284
 *
285
 */
285
 */
286
static void rgb_323(void *dst, uint32_t rgb)
286
static void rgb_323(void *dst, uint32_t rgb)
287
{
287
{
288
    *((uint8_t *) dst)
288
    *((uint8_t *) dst)
289
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
289
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
290
}
290
}
291
 
291
 
292
/** Draw a filled rectangle.
292
/** Draw a filled rectangle.
293
 *
293
 *
294
 * @note Need real implementation that does not access VRAM twice.
294
 * @note Need real implementation that does not access VRAM twice.
295
 */
295
 */
296
static void draw_filled_rect(unsigned int x0, unsigned int y0, unsigned int x1,
296
static void draw_filled_rect(unsigned int x0, unsigned int y0, unsigned int x1,
297
    unsigned int y1, uint32_t color)
297
    unsigned int y1, uint32_t color)
298
{
298
{
299
    unsigned int x, y;
299
    unsigned int x, y;
300
    unsigned int copy_bytes;
300
    unsigned int copy_bytes;
301
 
301
 
302
    uint8_t *sp, *dp;
302
    uint8_t *sp, *dp;
303
    uint8_t cbuf[4];
303
    uint8_t cbuf[4];
304
 
304
 
305
    if (y0 >= y1 || x0 >= x1) return;
305
    if (y0 >= y1 || x0 >= x1) return;
306
    screen.rgb_conv(cbuf, color);
306
    screen.rgb_conv(cbuf, color);
307
 
307
 
308
    sp = &screen.fb_addr[FB_POS(x0, y0)];
308
    sp = &screen.fb_addr[FB_POS(x0, y0)];
309
    dp = sp;
309
    dp = sp;
310
 
310
 
311
    /* Draw the first line. */
311
    /* Draw the first line. */
312
    for (x = x0; x < x1; x++) {
312
    for (x = x0; x < x1; x++) {
313
        memcpy(dp, cbuf, screen.pixelbytes);
313
        memcpy(dp, cbuf, screen.pixelbytes);
314
        dp += screen.pixelbytes;
314
        dp += screen.pixelbytes;
315
    }
315
    }
316
 
316
 
317
    dp = sp + screen.scanline;
317
    dp = sp + screen.scanline;
318
    copy_bytes = (x1 - x0) * screen.pixelbytes;
318
    copy_bytes = (x1 - x0) * screen.pixelbytes;
319
 
319
 
320
    /* Draw the remaining lines by copying. */
320
    /* Draw the remaining lines by copying. */
321
    for (y = y0 + 1; y < y1; y++) {
321
    for (y = y0 + 1; y < y1; y++) {
322
        memcpy(dp, sp, copy_bytes);
322
        memcpy(dp, sp, copy_bytes);
323
        dp += screen.scanline;
323
        dp += screen.scanline;
324
    }
324
    }
325
}
325
}
326
 
326
 
327
/** Redraw viewport.
327
/** Redraw viewport.
328
 *
328
 *
329
 * @param vport Viewport to redraw
329
 * @param vport Viewport to redraw
330
 *
330
 *
331
 */
331
 */
332
static void vport_redraw(viewport_t *vport)
332
static void vport_redraw(viewport_t *vport)
333
{
333
{
334
    unsigned int row, col;
334
    unsigned int row, col;
335
 
335
 
336
    for (row = 0; row < vport->rows; row++) {
336
    for (row = 0; row < vport->rows; row++) {
337
        for (col = 0; col < vport->cols; col++) {
337
        for (col = 0; col < vport->cols; col++) {
338
            draw_vp_glyph(vport, false, col, row);
338
            draw_vp_glyph(vport, false, col, row);
339
        }
339
        }
340
    }
340
    }
341
 
341
 
342
    if (COL2X(vport->cols) < vport->width) {
342
    if (COL2X(vport->cols) < vport->width) {
343
        draw_filled_rect(
343
        draw_filled_rect(
344
            vport->x + COL2X(vport->cols), vport->y,
344
            vport->x + COL2X(vport->cols), vport->y,
345
            vport->x + vport->width, vport->y + vport->height,
345
            vport->x + vport->width, vport->y + vport->height,
346
            vport->attr.bg_color);
346
            vport->attr.bg_color);
347
    }
347
    }
348
 
348
 
349
    if (ROW2Y(vport->rows) < vport->height) {
349
    if (ROW2Y(vport->rows) < vport->height) {
350
        draw_filled_rect(
350
        draw_filled_rect(
351
            vport->x, vport->y + ROW2Y(vport->rows),
351
            vport->x, vport->y + ROW2Y(vport->rows),
352
            vport->x + vport->width, vport->y + vport->height,
352
            vport->x + vport->width, vport->y + vport->height,
353
            vport->attr.bg_color);
353
            vport->attr.bg_color);
354
    }
354
    }
355
}
355
}
356
 
356
 
357
static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color,
357
static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color,
358
    uint32_t bg_color)
358
    uint32_t bg_color)
359
{
359
{
360
    unsigned i;
360
    unsigned i;
361
 
361
 
362
    for (i = 0; i < len; i++) {
362
    for (i = 0; i < len; i++) {
363
        backbuf[i].glyph = 0;
363
        backbuf[i].glyph = 0;
364
        backbuf[i].fg_color = fg_color;
364
        backbuf[i].fg_color = fg_color;
365
        backbuf[i].bg_color = bg_color;
365
        backbuf[i].bg_color = bg_color;
366
    }
366
    }
367
}
367
}
368
 
368
 
369
/** Clear viewport.
369
/** Clear viewport.
370
 *
370
 *
371
 * @param vport Viewport to clear
371
 * @param vport Viewport to clear
372
 *
372
 *
373
 */
373
 */
374
static void vport_clear(viewport_t *vport)
374
static void vport_clear(viewport_t *vport)
375
{
375
{
376
    backbuf_clear(vport->backbuf, vport->cols * vport->rows,
376
    backbuf_clear(vport->backbuf, vport->cols * vport->rows,
377
        vport->attr.fg_color, vport->attr.bg_color);
377
        vport->attr.fg_color, vport->attr.bg_color);
378
    vport_redraw(vport);
378
    vport_redraw(vport);
379
}
379
}
380
 
380
 
381
/** Scroll viewport by the specified number of lines.
381
/** Scroll viewport by the specified number of lines.
382
 *
382
 *
383
 * @param vport Viewport to scroll
383
 * @param vport Viewport to scroll
384
 * @param lines Number of lines to scroll
384
 * @param lines Number of lines to scroll
385
 *
385
 *
386
 */
386
 */
387
static void vport_scroll(viewport_t *vport, int lines)
387
static void vport_scroll(viewport_t *vport, int lines)
388
{
388
{
389
    unsigned int row, col;
389
    unsigned int row, col;
390
    unsigned int x, y;
390
    unsigned int x, y;
391
    uint8_t glyph;
391
    uint32_t glyph;
392
    uint32_t fg_color;
392
    uint32_t fg_color;
393
    uint32_t bg_color;
393
    uint32_t bg_color;
394
    bb_cell_t *bbp, *xbp;
394
    bb_cell_t *bbp, *xbp;
395
 
395
 
396
    /*
396
    /*
397
     * Redraw.
397
     * Redraw.
398
     */
398
     */
399
 
399
 
400
    y = vport->y;
400
    y = vport->y;
401
    for (row = 0; row < vport->rows; row++) {
401
    for (row = 0; row < vport->rows; row++) {
402
        x = vport->x;
402
        x = vport->x;
403
        for (col = 0; col < vport->cols; col++) {
403
        for (col = 0; col < vport->cols; col++) {
404
            if ((row + lines >= 0) && (row + lines < vport->rows)) {
404
            if ((row + lines >= 0) && (row + lines < vport->rows)) {
405
                xbp = &vport->backbuf[BB_POS(vport, col, row + lines)];
405
                xbp = &vport->backbuf[BB_POS(vport, col, row + lines)];
406
                bbp = &vport->backbuf[BB_POS(vport, col, row)];
406
                bbp = &vport->backbuf[BB_POS(vport, col, row)];
407
 
407
 
408
                glyph = xbp->glyph;
408
                glyph = xbp->glyph;
409
                fg_color = xbp->fg_color;
409
                fg_color = xbp->fg_color;
410
                bg_color = xbp->bg_color;
410
                bg_color = xbp->bg_color;
411
 
411
 
412
                if (bbp->glyph == glyph &&
412
                if (bbp->glyph == glyph &&
413
                    bbp->fg_color == xbp->fg_color &&
413
                    bbp->fg_color == xbp->fg_color &&
414
                    bbp->bg_color == xbp->bg_color) {
414
                    bbp->bg_color == xbp->bg_color) {
415
                    x += FONT_WIDTH;
415
                    x += FONT_WIDTH;
416
                    continue;
416
                    continue;
417
                }
417
                }
418
            } else {
418
            } else {
419
                glyph = 0;
419
                glyph = 0;
420
                fg_color = vport->attr.fg_color;
420
                fg_color = vport->attr.fg_color;
421
                bg_color = vport->attr.bg_color;
421
                bg_color = vport->attr.bg_color;
422
            }
422
            }
423
 
423
 
424
            (*vport->dglyph)(x, y, false, vport->glyphs, glyph,
424
            (*vport->dglyph)(x, y, false, vport->glyphs, glyph,
425
                fg_color, bg_color);
425
                fg_color, bg_color);
426
            x += FONT_WIDTH;
426
            x += FONT_WIDTH;
427
        }
427
        }
428
        y += FONT_SCANLINES;
428
        y += FONT_SCANLINES;
429
    }
429
    }
430
 
430
 
431
    /*
431
    /*
432
     * Scroll backbuffer.
432
     * Scroll backbuffer.
433
     */
433
     */
434
 
434
 
435
    if (lines > 0) {
435
    if (lines > 0) {
436
        memmove(vport->backbuf, vport->backbuf + vport->cols * lines,
436
        memmove(vport->backbuf, vport->backbuf + vport->cols * lines,
437
            vport->cols * (vport->rows - lines) * sizeof(bb_cell_t));
437
            vport->cols * (vport->rows - lines) * sizeof(bb_cell_t));
438
        backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)],
438
        backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)],
439
            vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color);
439
            vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color);
440
    } else {
440
    } else {
441
        memmove(vport->backbuf - vport->cols * lines, vport->backbuf,
441
        memmove(vport->backbuf - vport->cols * lines, vport->backbuf,
442
            vport->cols * (vport->rows + lines) * sizeof(bb_cell_t));
442
            vport->cols * (vport->rows + lines) * sizeof(bb_cell_t));
443
        backbuf_clear(vport->backbuf, - vport->cols * lines,
443
        backbuf_clear(vport->backbuf, - vport->cols * lines,
444
            vport->attr.fg_color, vport->attr.bg_color);
444
            vport->attr.fg_color, vport->attr.bg_color);
445
    }
445
    }
446
}
446
}
447
 
447
 
448
/** Render glyphs
448
/** Render glyphs
449
 *
449
 *
450
 * Convert glyphs from device independent font
450
 * Convert glyphs from device independent font
451
 * description to current visual representation.
451
 * description to current visual representation.
452
 *
452
 *
453
 * @param vport Viewport
453
 * @param vport Viewport
454
 *
454
 *
455
 */
455
 */
456
static void render_glyphs(viewport_t* vport)
456
static void render_glyphs(viewport_t* vport)
457
{
457
{
458
    unsigned int glyph;
458
    unsigned int glyph;
459
   
459
   
460
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
460
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
461
        unsigned int y;
461
        unsigned int y;
462
       
462
       
463
        for (y = 0; y < FONT_SCANLINES; y++) {
463
        for (y = 0; y < FONT_SCANLINES; y++) {
464
            unsigned int x;
464
            unsigned int x;
465
           
465
           
466
            for (x = 0; x < FONT_WIDTH; x++) {
466
            for (x = 0; x < FONT_WIDTH; x++) {
467
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
467
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
468
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
468
                    (fb_font[glyph][y] & (1 << (7 - x)))
469
                    ? 0xffffff : 0x000000);
469
                    ? 0xffffff : 0x000000);
470
               
470
               
471
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes],
471
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes],
472
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
472
                    (fb_font[glyph][y] & (1 << (7 - x)))
473
                    ? 0x000000 : 0xffffff);
473
                    ? 0x000000 : 0xffffff);
474
            }
474
            }
475
        }
475
        }
476
    }
476
    }
477
   
477
   
478
    screen.rgb_conv(vport->bgpixel, vport->attr.bg_color);
478
    screen.rgb_conv(vport->bgpixel, vport->attr.bg_color);
479
}
479
}
480
 
480
 
481
 
481
 
482
/** Create new viewport
482
/** Create new viewport
483
 *
483
 *
484
 * @param x      Origin of the viewport (x).
484
 * @param x      Origin of the viewport (x).
485
 * @param y      Origin of the viewport (y).
485
 * @param y      Origin of the viewport (y).
486
 * @param width  Width of the viewport.
486
 * @param width  Width of the viewport.
487
 * @param height Height of the viewport.
487
 * @param height Height of the viewport.
488
 *
488
 *
489
 * @return New viewport number.
489
 * @return New viewport number.
490
 *
490
 *
491
 */
491
 */
492
static int vport_create(unsigned int x, unsigned int y,
492
static int vport_create(unsigned int x, unsigned int y,
493
    unsigned int width, unsigned int height)
493
    unsigned int width, unsigned int height)
494
{
494
{
495
    unsigned int i;
495
    unsigned int i;
496
   
496
   
497
    for (i = 0; i < MAX_VIEWPORTS; i++) {
497
    for (i = 0; i < MAX_VIEWPORTS; i++) {
498
        if (!viewports[i].initialized)
498
        if (!viewports[i].initialized)
499
            break;
499
            break;
500
    }
500
    }
501
    if (i == MAX_VIEWPORTS)
501
    if (i == MAX_VIEWPORTS)
502
        return ELIMIT;
502
        return ELIMIT;
503
   
503
   
504
    unsigned int cols = width / FONT_WIDTH;
504
    unsigned int cols = width / FONT_WIDTH;
505
    unsigned int rows = height / FONT_SCANLINES;
505
    unsigned int rows = height / FONT_SCANLINES;
506
    unsigned int bbsize = cols * rows * sizeof(bb_cell_t);
506
    unsigned int bbsize = cols * rows * sizeof(bb_cell_t);
507
    unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
507
    unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
508
    unsigned int word_size = sizeof(unsigned long);
508
    unsigned int word_size = sizeof(unsigned long);
509
   
509
   
510
    bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize);
510
    bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize);
511
    if (!backbuf)
511
    if (!backbuf)
512
        return ENOMEM;
512
        return ENOMEM;
513
   
513
   
514
    uint8_t *glyphs = (uint8_t *) malloc(glyphsize);
514
    uint8_t *glyphs = (uint8_t *) malloc(glyphsize);
515
    if (!glyphs) {
515
    if (!glyphs) {
516
        free(backbuf);
516
        free(backbuf);
517
        return ENOMEM;
517
        return ENOMEM;
518
    }
518
    }
519
   
519
   
520
    uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes);
520
    uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes);
521
    if (!bgpixel) {
521
    if (!bgpixel) {
522
        free(glyphs);
522
        free(glyphs);
523
        free(backbuf);
523
        free(backbuf);
524
        return ENOMEM;
524
        return ENOMEM;
525
    }
525
    }
526
 
526
 
527
    backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR);
527
    backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR);
528
    memset(glyphs, 0, glyphsize);
528
    memset(glyphs, 0, glyphsize);
529
    memset(bgpixel, 0, screen.pixelbytes);
529
    memset(bgpixel, 0, screen.pixelbytes);
530
   
530
   
531
    viewports[i].x = x;
531
    viewports[i].x = x;
532
    viewports[i].y = y;
532
    viewports[i].y = y;
533
    viewports[i].width = width;
533
    viewports[i].width = width;
534
    viewports[i].height = height;
534
    viewports[i].height = height;
535
   
535
   
536
    viewports[i].cols = cols;
536
    viewports[i].cols = cols;
537
    viewports[i].rows = rows;
537
    viewports[i].rows = rows;
538
   
538
   
539
    viewports[i].attr.bg_color = DEFAULT_BGCOLOR;
539
    viewports[i].attr.bg_color = DEFAULT_BGCOLOR;
540
    viewports[i].attr.fg_color = DEFAULT_FGCOLOR;
540
    viewports[i].attr.fg_color = DEFAULT_FGCOLOR;
541
   
541
   
542
    viewports[i].glyphs = glyphs;
542
    viewports[i].glyphs = glyphs;
543
    viewports[i].bgpixel = bgpixel;
543
    viewports[i].bgpixel = bgpixel;
544
 
544
 
545
    /*
545
    /*
546
     * Conditions necessary  to select aligned version:
546
     * Conditions necessary  to select aligned version:
547
     *
547
     *
548
     *   - word size is divisible by pixelbytes
548
     *   - word size is divisible by pixelbytes
549
     *   - cell scanline size is divisible by word size
549
     *   - cell scanline size is divisible by word size
550
     *   - cell scanlines are word-aligned
550
     *   - cell scanlines are word-aligned
551
     */
551
     */
552
    if ((word_size % screen.pixelbytes) == 0 &&
552
    if ((word_size % screen.pixelbytes) == 0 &&
553
        (FONT_WIDTH * screen.pixelbytes) % word_size == 0 &&
553
        (FONT_WIDTH * screen.pixelbytes) % word_size == 0 &&
554
        (x * screen.pixelbytes) % word_size == 0 &&
554
        (x * screen.pixelbytes) % word_size == 0 &&
555
        screen.scanline % word_size == 0) {
555
        screen.scanline % word_size == 0) {
556
 
556
 
557
        viewports[i].dglyph = draw_glyph_aligned;
557
        viewports[i].dglyph = draw_glyph_aligned;
558
    } else {
558
    } else {
559
        viewports[i].dglyph = draw_glyph_fallback;
559
        viewports[i].dglyph = draw_glyph_fallback;
560
    }
560
    }
561
 
561
 
562
    viewports[i].cur_col = 0;
562
    viewports[i].cur_col = 0;
563
    viewports[i].cur_row = 0;
563
    viewports[i].cur_row = 0;
564
    viewports[i].cursor_active = false;
564
    viewports[i].cursor_active = false;
565
    viewports[i].cursor_shown = false;
565
    viewports[i].cursor_shown = false;
566
   
566
   
567
    viewports[i].bbsize = bbsize;
567
    viewports[i].bbsize = bbsize;
568
    viewports[i].backbuf = backbuf;
568
    viewports[i].backbuf = backbuf;
569
   
569
   
570
    viewports[i].initialized = true;
570
    viewports[i].initialized = true;
571
   
571
   
572
    render_glyphs(&viewports[i]);
572
    render_glyphs(&viewports[i]);
573
   
573
   
574
    return i;
574
    return i;
575
}
575
}
576
 
576
 
577
 
577
 
578
/** Initialize framebuffer as a chardev output device
578
/** Initialize framebuffer as a chardev output device
579
 *
579
 *
580
 * @param addr   Address of the framebuffer
580
 * @param addr   Address of the framebuffer
581
 * @param xres   Screen width in pixels
581
 * @param xres   Screen width in pixels
582
 * @param yres   Screen height in pixels
582
 * @param yres   Screen height in pixels
583
 * @param visual Bits per pixel (8, 16, 24, 32)
583
 * @param visual Bits per pixel (8, 16, 24, 32)
584
 * @param scan   Bytes per one scanline
584
 * @param scan   Bytes per one scanline
585
 *
585
 *
586
 */
586
 */
587
static bool screen_init(void *addr, unsigned int xres, unsigned int yres,
587
static bool screen_init(void *addr, unsigned int xres, unsigned int yres,
588
    unsigned int scan, unsigned int visual)
588
    unsigned int scan, unsigned int visual)
589
{
589
{
590
    switch (visual) {
590
    switch (visual) {
591
    case VISUAL_INDIRECT_8:
591
    case VISUAL_INDIRECT_8:
592
        screen.rgb_conv = rgb_323;
592
        screen.rgb_conv = rgb_323;
593
        screen.pixelbytes = 1;
593
        screen.pixelbytes = 1;
594
        break;
594
        break;
595
    case VISUAL_RGB_5_5_5:
595
    case VISUAL_RGB_5_5_5:
596
        screen.rgb_conv = rgb_555;
596
        screen.rgb_conv = rgb_555;
597
        screen.pixelbytes = 2;
597
        screen.pixelbytes = 2;
598
        break;
598
        break;
599
    case VISUAL_RGB_5_6_5:
599
    case VISUAL_RGB_5_6_5:
600
        screen.rgb_conv = rgb_565;
600
        screen.rgb_conv = rgb_565;
601
        screen.pixelbytes = 2;
601
        screen.pixelbytes = 2;
602
        break;
602
        break;
603
    case VISUAL_RGB_8_8_8:
603
    case VISUAL_RGB_8_8_8:
604
        screen.rgb_conv = rgb_888;
604
        screen.rgb_conv = rgb_888;
605
        screen.pixelbytes = 3;
605
        screen.pixelbytes = 3;
606
        break;
606
        break;
607
    case VISUAL_BGR_8_8_8:
607
    case VISUAL_BGR_8_8_8:
608
        screen.rgb_conv = bgr_888;
608
        screen.rgb_conv = bgr_888;
609
        screen.pixelbytes = 3;
609
        screen.pixelbytes = 3;
610
        break;
610
        break;
611
    case VISUAL_RGB_8_8_8_0:
611
    case VISUAL_RGB_8_8_8_0:
612
        screen.rgb_conv = rgb_888;
612
        screen.rgb_conv = rgb_888;
613
        screen.pixelbytes = 4;
613
        screen.pixelbytes = 4;
614
        break;
614
        break;
615
    case VISUAL_RGB_0_8_8_8:
615
    case VISUAL_RGB_0_8_8_8:
616
        screen.rgb_conv = rgb_0888;
616
        screen.rgb_conv = rgb_0888;
617
        screen.pixelbytes = 4;
617
        screen.pixelbytes = 4;
618
        break;
618
        break;
619
    case VISUAL_BGR_0_8_8_8:
619
    case VISUAL_BGR_0_8_8_8:
620
        screen.rgb_conv = bgr_0888;
620
        screen.rgb_conv = bgr_0888;
621
        screen.pixelbytes = 4;
621
        screen.pixelbytes = 4;
622
        break;
622
        break;
623
    default:
623
    default:
624
        return false;
624
        return false;
625
    }
625
    }
626
 
626
 
627
    screen.fb_addr = (unsigned char *) addr;
627
    screen.fb_addr = (unsigned char *) addr;
628
    screen.xres = xres;
628
    screen.xres = xres;
629
    screen.yres = yres;
629
    screen.yres = yres;
630
    screen.scanline = scan;
630
    screen.scanline = scan;
631
   
631
   
632
    screen.glyphscanline = FONT_WIDTH * screen.pixelbytes;
632
    screen.glyphscanline = FONT_WIDTH * screen.pixelbytes;
633
    screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES;
633
    screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES;
634
   
634
   
635
    /* Create first viewport */
635
    /* Create first viewport */
636
    vport_create(0, 0, xres, yres);
636
    vport_create(0, 0, xres, yres);
637
   
637
   
638
    return true;
638
    return true;
639
}
639
}
640
 
640
 
641
 
641
 
642
/** Draw a glyph, takes advantage of alignment.
642
/** Draw a glyph, takes advantage of alignment.
643
 *
643
 *
644
 * This version can only be used if the following conditions are met:
644
 * This version can only be used if the following conditions are met:
645
 *
645
 *
646
 *   - word size is divisible by pixelbytes
646
 *   - word size is divisible by pixelbytes
647
 *   - cell scanline size is divisible by word size
647
 *   - cell scanline size is divisible by word size
648
 *   - cell scanlines are word-aligned
648
 *   - cell scanlines are word-aligned
649
 *
649
 *
650
 * It makes use of the pre-rendered mask to process (possibly) several
650
 * It makes use of the pre-rendered mask to process (possibly) several
651
 * pixels at once (word size / pixelbytes pixels at a time are processed)
651
 * pixels at once (word size / pixelbytes pixels at a time are processed)
652
 * making it very fast. Most notably this version is not applicable at 24 bits
652
 * making it very fast. Most notably this version is not applicable at 24 bits
653
 * per pixel.
653
 * per pixel.
654
 *
654
 *
655
 * @param x     x coordinate of top-left corner on screen.
655
 * @param x     x coordinate of top-left corner on screen.
656
 * @param y     y coordinate of top-left corner on screen.
656
 * @param y     y coordinate of top-left corner on screen.
657
 * @param cursor    Draw glyph with cursor
657
 * @param cursor    Draw glyph with cursor
658
 * @param glyphs    Pointer to font bitmap.
658
 * @param glyphs    Pointer to font bitmap.
659
 * @param glyph     Code of the glyph to draw.
659
 * @param glyph     Code of the glyph to draw.
660
 * @param fg_color  Foreground color.
660
 * @param fg_color  Foreground color.
661
 * @param bg_color  Backgroudn color.
661
 * @param bg_color  Backgroudn color.
662
 */
662
 */
663
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
663
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
664
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color)
664
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color)
665
{
665
{
666
    unsigned int i, yd;
666
    unsigned int i, yd;
667
    unsigned long fg_buf, bg_buf;
667
    unsigned long fg_buf, bg_buf;
668
    unsigned long *maskp, *dp;
668
    unsigned long *maskp, *dp;
669
    unsigned long mask;
669
    unsigned long mask;
670
    unsigned int ww, d_add;
670
    unsigned int ww, d_add;
671
 
671
 
672
    /* Check glyph range. */
-
 
673
    if (glyph >= FONT_GLYPHS)
-
 
674
        glyph = GLYPH_UNAVAIL;
-
 
675
 
-
 
676
    /*
672
    /*
677
     * Prepare a pair of words, one filled with foreground-color
673
     * Prepare a pair of words, one filled with foreground-color
678
     * pattern and the other filled with background-color pattern.
674
     * pattern and the other filled with background-color pattern.
679
     */
675
     */
680
    for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) {
676
    for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) {
681
        screen.rgb_conv(&((uint8_t *)&fg_buf)[i * screen.pixelbytes],
677
        screen.rgb_conv(&((uint8_t *)&fg_buf)[i * screen.pixelbytes],
682
            fg_color);
678
            fg_color);
683
        screen.rgb_conv(&((uint8_t *)&bg_buf)[i * screen.pixelbytes],
679
        screen.rgb_conv(&((uint8_t *)&bg_buf)[i * screen.pixelbytes],
684
            bg_color);
680
            bg_color);
685
    }
681
    }
686
 
682
 
687
    /* Pointer to the current position in the mask. */
683
    /* Pointer to the current position in the mask. */
688
    maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)];
684
    maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)];
689
 
685
 
690
    /* Pointer to the current position on the screen. */
686
    /* Pointer to the current position on the screen. */
691
    dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)];
687
    dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)];
692
 
688
 
693
    /* Width of the character cell in words. */
689
    /* Width of the character cell in words. */
694
    ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long);
690
    ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long);
695
 
691
 
696
    /* Offset to add when moving to another screen scanline. */
692
    /* Offset to add when moving to another screen scanline. */
697
    d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
693
    d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
698
 
694
 
699
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
695
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
700
        /*
696
        /*
701
         * Now process the cell scanline, combining foreground
697
         * Now process the cell scanline, combining foreground
702
         * and background color patters using the pre-rendered mask.
698
         * and background color patters using the pre-rendered mask.
703
         */
699
         */
704
        for (i = 0; i < ww; i++) {
700
        for (i = 0; i < ww; i++) {
705
            mask = *maskp++;
701
            mask = *maskp++;
706
            *dp++ = (fg_buf & mask) | (bg_buf & ~mask);
702
            *dp++ = (fg_buf & mask) | (bg_buf & ~mask);
707
        }
703
        }
708
 
704
 
709
        /* Move to the beginning of the next scanline of the cell. */
705
        /* Move to the beginning of the next scanline of the cell. */
710
        dp = (unsigned long *) ((uint8_t *) dp + d_add);
706
        dp = (unsigned long *) ((uint8_t *) dp + d_add);
711
    }
707
    }
712
}
708
}
713
 
709
 
714
/** Draw a glyph, fallback version.
710
/** Draw a glyph, fallback version.
715
 *
711
 *
716
 * This version does not make use of the pre-rendered mask, it uses
712
 * This version does not make use of the pre-rendered mask, it uses
717
 * the font bitmap directly. It works always, but it is slower.
713
 * the font bitmap directly. It works always, but it is slower.
718
 *
714
 *
719
 * @param x     x coordinate of top-left corner on screen.
715
 * @param x     x coordinate of top-left corner on screen.
720
 * @param y     y coordinate of top-left corner on screen.
716
 * @param y     y coordinate of top-left corner on screen.
721
 * @param cursor    Draw glyph with cursor
717
 * @param cursor    Draw glyph with cursor
722
 * @param glyphs    Pointer to font bitmap.
718
 * @param glyphs    Pointer to font bitmap.
723
 * @param glyph     Code of the glyph to draw.
719
 * @param glyph     Code of the glyph to draw.
724
 * @param fg_color  Foreground color.
720
 * @param fg_color  Foreground color.
725
 * @param bg_color  Backgroudn color.
721
 * @param bg_color  Backgroudn color.
726
 */
722
 */
727
void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
723
void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
728
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color)
724
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color)
729
{
725
{
730
    unsigned int i, j, yd;
726
    unsigned int i, j, yd;
731
    uint8_t fg_buf[4], bg_buf[4];
727
    uint8_t fg_buf[4], bg_buf[4];
732
    uint8_t *dp, *sp;
728
    uint8_t *dp, *sp;
733
    unsigned int d_add;
729
    unsigned int d_add;
734
    uint8_t b;
730
    uint8_t b;
735
 
731
 
736
    /* Check glyph range. */
-
 
737
    if (glyph >= FONT_GLYPHS)
-
 
738
        glyph = GLYPH_UNAVAIL;
-
 
739
 
-
 
740
    /* Pre-render 1x the foreground and background color pixels. */
732
    /* Pre-render 1x the foreground and background color pixels. */
741
    if (cursor) {
733
    if (cursor) {
742
        screen.rgb_conv(fg_buf, bg_color);
734
        screen.rgb_conv(fg_buf, bg_color);
743
        screen.rgb_conv(bg_buf, fg_color);
735
        screen.rgb_conv(bg_buf, fg_color);
744
    } else {
736
    } else {
745
        screen.rgb_conv(fg_buf, fg_color);
737
        screen.rgb_conv(fg_buf, fg_color);
746
        screen.rgb_conv(bg_buf, bg_color);
738
        screen.rgb_conv(bg_buf, bg_color);
747
    }
739
    }
748
 
740
 
749
    /* Pointer to the current position on the screen. */
741
    /* Pointer to the current position on the screen. */
750
    dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)];
742
    dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)];
751
 
743
 
752
    /* Offset to add when moving to another screen scanline. */
744
    /* Offset to add when moving to another screen scanline. */
753
    d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
745
    d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
754
 
746
 
755
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
747
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
756
        /* Byte containing bits of the glyph scanline. */
748
        /* Byte containing bits of the glyph scanline. */
757
        b = fb_font[glyph * FONT_SCANLINES + yd];
749
        b = fb_font[glyph][yd];
758
 
750
 
759
        for (i = 0; i < FONT_WIDTH; i++) {
751
        for (i = 0; i < FONT_WIDTH; i++) {
760
            /* Choose color based on the current bit. */
752
            /* Choose color based on the current bit. */
761
            sp = (b & 0x80) ? fg_buf : bg_buf;
753
            sp = (b & 0x80) ? fg_buf : bg_buf;
762
 
754
 
763
            /* Copy the pixel. */
755
            /* Copy the pixel. */
764
            for (j = 0; j < screen.pixelbytes; j++) {
756
            for (j = 0; j < screen.pixelbytes; j++) {
765
                *dp++ = *sp++;
757
                *dp++ = *sp++;
766
            }
758
            }
767
 
759
 
768
            /* Move to the next bit. */
760
            /* Move to the next bit. */
769
            b = b << 1;
761
            b = b << 1;
770
        }
762
        }
771
       
763
       
772
        /* Move to the beginning of the next scanline of the cell. */
764
        /* Move to the beginning of the next scanline of the cell. */
773
        dp += d_add;
765
        dp += d_add;
774
    }
766
    }
775
}
767
}
776
 
768
 
777
/** Draw glyph at specified position in viewport.
769
/** Draw glyph at specified position in viewport.
778
 *
770
 *
779
 * @param vport  Viewport identification
771
 * @param vport  Viewport identification
780
 * @param cursor Draw glyph with cursor
772
 * @param cursor Draw glyph with cursor
781
 * @param col    Screen position relative to viewport
773
 * @param col    Screen position relative to viewport
782
 * @param row    Screen position relative to viewport
774
 * @param row    Screen position relative to viewport
783
 *
775
 *
784
 */
776
 */
785
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
777
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
786
    unsigned int row)
778
    unsigned int row)
787
{
779
{
788
    unsigned int x = vport->x + COL2X(col);
780
    unsigned int x = vport->x + COL2X(col);
789
    unsigned int y = vport->y + ROW2Y(row);
781
    unsigned int y = vport->y + ROW2Y(row);
790
 
782
 
791
    uint32_t glyph;
783
    uint32_t glyph;
792
    uint32_t fg_color;
784
    uint32_t fg_color;
793
    uint32_t bg_color;
785
    uint32_t bg_color;
794
   
786
   
795
    glyph = vport->backbuf[BB_POS(vport, col, row)].glyph;
787
    glyph = vport->backbuf[BB_POS(vport, col, row)].glyph;
796
    fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color;
788
    fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color;
797
    bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color;
789
    bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color;
798
 
790
 
799
    (*vport->dglyph)(x, y, cursor, vport->glyphs, glyph,
791
    (*vport->dglyph)(x, y, cursor, vport->glyphs, glyph,
800
        fg_color, bg_color);
792
        fg_color, bg_color);
801
}
793
}
802
 
794
 
803
/** Hide cursor if it is shown
795
/** Hide cursor if it is shown
804
 *
796
 *
805
 */
797
 */
806
static void cursor_hide(viewport_t *vport)
798
static void cursor_hide(viewport_t *vport)
807
{
799
{
808
    if ((vport->cursor_active) && (vport->cursor_shown)) {
800
    if ((vport->cursor_active) && (vport->cursor_shown)) {
809
        draw_vp_glyph(vport, false, vport->cur_col, vport->cur_row);
801
        draw_vp_glyph(vport, false, vport->cur_col, vport->cur_row);
810
        vport->cursor_shown = false;
802
        vport->cursor_shown = false;
811
    }
803
    }
812
}
804
}
813
 
805
 
814
 
806
 
815
/** Show cursor if cursor showing is enabled
807
/** Show cursor if cursor showing is enabled
816
 *
808
 *
817
 */
809
 */
818
static void cursor_show(viewport_t *vport)
810
static void cursor_show(viewport_t *vport)
819
{
811
{
820
    /* Do not check for cursor_shown */
812
    /* Do not check for cursor_shown */
821
    if (vport->cursor_active) {
813
    if (vport->cursor_active) {
822
        draw_vp_glyph(vport, true, vport->cur_col, vport->cur_row);
814
        draw_vp_glyph(vport, true, vport->cur_col, vport->cur_row);
823
        vport->cursor_shown = true;
815
        vport->cursor_shown = true;
824
    }
816
    }
825
}
817
}
826
 
818
 
827
 
819
 
828
/** Invert cursor, if it is enabled
820
/** Invert cursor, if it is enabled
829
 *
821
 *
830
 */
822
 */
831
static void cursor_blink(viewport_t *vport)
823
static void cursor_blink(viewport_t *vport)
832
{
824
{
833
    if (vport->cursor_shown)
825
    if (vport->cursor_shown)
834
        cursor_hide(vport);
826
        cursor_hide(vport);
835
    else
827
    else
836
        cursor_show(vport);
828
        cursor_show(vport);
837
}
829
}
838
 
830
 
839
 
831
 
840
/** Draw character at given position relative to viewport
832
/** Draw character at given position relative to viewport
841
 *
833
 *
842
 * @param vport  Viewport identification
834
 * @param vport  Viewport identification
843
 * @param c      Character to draw
835
 * @param c      Character to draw
844
 * @param col    Screen position relative to viewport
836
 * @param col    Screen position relative to viewport
845
 * @param row    Screen position relative to viewport
837
 * @param row    Screen position relative to viewport
846
 *
838
 *
847
 */
839
 */
848
static void draw_char(viewport_t *vport, wchar_t c, unsigned int col, unsigned int row)
840
static void draw_char(viewport_t *vport, wchar_t c, unsigned int col, unsigned int row)
849
{
841
{
850
    bb_cell_t *bbp;
842
    bb_cell_t *bbp;
851
 
843
 
852
    /* Do not hide cursor if we are going to overwrite it */
844
    /* Do not hide cursor if we are going to overwrite it */
853
    if ((vport->cursor_active) && (vport->cursor_shown) &&
845
    if ((vport->cursor_active) && (vport->cursor_shown) &&
854
        ((vport->cur_col != col) || (vport->cur_row != row)))
846
        ((vport->cur_col != col) || (vport->cur_row != row)))
855
        cursor_hide(vport);
847
        cursor_hide(vport);
856
 
848
 
857
    bbp = &vport->backbuf[BB_POS(vport, col, row)];
849
    bbp = &vport->backbuf[BB_POS(vport, col, row)];
858
    bbp->glyph = (uint32_t) c;
850
    bbp->glyph = fb_font_glyph(c);
859
    bbp->fg_color = vport->attr.fg_color;
851
    bbp->fg_color = vport->attr.fg_color;
860
    bbp->bg_color = vport->attr.bg_color;
852
    bbp->bg_color = vport->attr.bg_color;
861
 
853
 
862
    draw_vp_glyph(vport, false, col, row);
854
    draw_vp_glyph(vport, false, col, row);
863
   
855
   
864
    vport->cur_col = col;
856
    vport->cur_col = col;
865
    vport->cur_row = row;
857
    vport->cur_row = row;
866
   
858
   
867
    vport->cur_col++;
859
    vport->cur_col++;
868
    if (vport->cur_col >= vport->cols) {
860
    if (vport->cur_col >= vport->cols) {
869
        vport->cur_col = 0;
861
        vport->cur_col = 0;
870
        vport->cur_row++;
862
        vport->cur_row++;
871
        if (vport->cur_row >= vport->rows)
863
        if (vport->cur_row >= vport->rows)
872
            vport->cur_row--;
864
            vport->cur_row--;
873
    }
865
    }
874
   
866
   
875
    cursor_show(vport);
867
    cursor_show(vport);
876
}
868
}
877
 
869
 
878
/** Draw text data to viewport.
870
/** Draw text data to viewport.
879
 *
871
 *
880
 * @param vport Viewport id
872
 * @param vport Viewport id
881
 * @param data  Text data.
873
 * @param data  Text data.
882
 * @param x Leftmost column of the area.
874
 * @param x Leftmost column of the area.
883
 * @param y Topmost row of the area.
875
 * @param y Topmost row of the area.
884
 * @param w Number of rows.
876
 * @param w Number of rows.
885
 * @param h Number of columns.
877
 * @param h Number of columns.
886
 */
878
 */
887
static void draw_text_data(viewport_t *vport, keyfield_t *data, unsigned int x,
879
static void draw_text_data(viewport_t *vport, keyfield_t *data, unsigned int x,
888
    unsigned int y, unsigned int w, unsigned int h)
880
    unsigned int y, unsigned int w, unsigned int h)
889
{
881
{
890
    unsigned int i, j;
882
    unsigned int i, j;
891
    bb_cell_t *bbp;
883
    bb_cell_t *bbp;
892
    attrs_t *a;
884
    attrs_t *a;
893
    attr_rgb_t rgb;
885
    attr_rgb_t rgb;
894
 
886
 
895
    for (j = 0; j < h; j++) {
887
    for (j = 0; j < h; j++) {
896
        for (i = 0; i < w; i++) {
888
        for (i = 0; i < w; i++) {
897
            unsigned int col = x + i;
889
            unsigned int col = x + i;
898
            unsigned int row = y + j;
890
            unsigned int row = y + j;
899
 
891
 
900
            bbp = &vport->backbuf[BB_POS(vport, col, row)];
892
            bbp = &vport->backbuf[BB_POS(vport, col, row)];
901
            uint32_t glyph = bbp->glyph;
-
 
902
 
893
 
903
            a = &data[j * w + i].attrs;
894
            a = &data[j * w + i].attrs;
904
            rgb_from_attr(&rgb, a);
895
            rgb_from_attr(&rgb, a);
905
 
896
 
906
            bbp->glyph = data[j * w + i].character;
897
            bbp->glyph = fb_font_glyph(data[j * w + i].character);
907
            bbp->fg_color = rgb.fg_color;
898
            bbp->fg_color = rgb.fg_color;
908
            bbp->bg_color = rgb.bg_color;
899
            bbp->bg_color = rgb.bg_color;
909
 
900
 
910
            draw_vp_glyph(vport, false, col, row);
901
            draw_vp_glyph(vport, false, col, row);
911
        }
902
        }
912
    }
903
    }
913
    cursor_show(vport);
904
    cursor_show(vport);
914
}
905
}
915
 
906
 
916
 
907
 
917
static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color)
908
static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color)
918
{
909
{
919
    int pm = *((int *) data);
910
    int pm = *((int *) data);
920
    pixmap_t *pmap = &pixmaps[pm];
911
    pixmap_t *pmap = &pixmaps[pm];
921
    unsigned int pos = (y * pmap->width + x) * screen.pixelbytes;
912
    unsigned int pos = (y * pmap->width + x) * screen.pixelbytes;
922
   
913
   
923
    screen.rgb_conv(&pmap->data[pos], color);
914
    screen.rgb_conv(&pmap->data[pos], color);
924
}
915
}
925
 
916
 
926
 
917
 
927
static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color)
918
static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color)
928
{
919
{
929
    viewport_t *vport = (viewport_t *) data;
920
    viewport_t *vport = (viewport_t *) data;
930
    unsigned int dx = vport->x + x;
921
    unsigned int dx = vport->x + x;
931
    unsigned int dy = vport->y + y;
922
    unsigned int dy = vport->y + y;
932
   
923
   
933
    screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color);
924
    screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color);
934
}
925
}
935
 
926
 
936
 
927
 
937
/** Return first free pixmap
928
/** Return first free pixmap
938
 *
929
 *
939
 */
930
 */
940
static int find_free_pixmap(void)
931
static int find_free_pixmap(void)
941
{
932
{
942
    unsigned int i;
933
    unsigned int i;
943
   
934
   
944
    for (i = 0; i < MAX_PIXMAPS; i++)
935
    for (i = 0; i < MAX_PIXMAPS; i++)
945
        if (!pixmaps[i].data)
936
        if (!pixmaps[i].data)
946
            return i;
937
            return i;
947
   
938
   
948
    return -1;
939
    return -1;
949
}
940
}
950
 
941
 
951
 
942
 
952
/** Create a new pixmap and return appropriate ID
943
/** Create a new pixmap and return appropriate ID
953
 *
944
 *
954
 */
945
 */
955
static int shm2pixmap(unsigned char *shm, size_t size)
946
static int shm2pixmap(unsigned char *shm, size_t size)
956
{
947
{
957
    int pm;
948
    int pm;
958
    pixmap_t *pmap;
949
    pixmap_t *pmap;
959
   
950
   
960
    pm = find_free_pixmap();
951
    pm = find_free_pixmap();
961
    if (pm == -1)
952
    if (pm == -1)
962
        return ELIMIT;
953
        return ELIMIT;
963
   
954
   
964
    pmap = &pixmaps[pm];
955
    pmap = &pixmaps[pm];
965
   
956
   
966
    if (ppm_get_data(shm, size, &pmap->width, &pmap->height))
957
    if (ppm_get_data(shm, size, &pmap->width, &pmap->height))
967
        return EINVAL;
958
        return EINVAL;
968
   
959
   
969
    pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes);
960
    pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes);
970
    if (!pmap->data)
961
    if (!pmap->data)
971
        return ENOMEM;
962
        return ENOMEM;
972
   
963
   
973
    ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm);
964
    ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm);
974
   
965
   
975
    return pm;
966
    return pm;
976
}
967
}
977
 
968
 
978
 
969
 
979
/** Handle shared memory communication calls
970
/** Handle shared memory communication calls
980
 *
971
 *
981
 * Protocol for drawing pixmaps:
972
 * Protocol for drawing pixmaps:
982
 * - FB_PREPARE_SHM(client shm identification)
973
 * - FB_PREPARE_SHM(client shm identification)
983
 * - IPC_M_AS_AREA_SEND
974
 * - IPC_M_AS_AREA_SEND
984
 * - FB_DRAW_PPM(startx, starty)
975
 * - FB_DRAW_PPM(startx, starty)
985
 * - FB_DROP_SHM
976
 * - FB_DROP_SHM
986
 *
977
 *
987
 * Protocol for text drawing
978
 * Protocol for text drawing
988
 * - IPC_M_AS_AREA_SEND
979
 * - IPC_M_AS_AREA_SEND
989
 * - FB_DRAW_TEXT_DATA
980
 * - FB_DRAW_TEXT_DATA
990
 *
981
 *
991
 * @param callid Callid of the current call
982
 * @param callid Callid of the current call
992
 * @param call   Current call data
983
 * @param call   Current call data
993
 * @param vp     Active viewport
984
 * @param vp     Active viewport
994
 *
985
 *
995
 * @return false if the call was not handled byt this function, true otherwise
986
 * @return false if the call was not handled byt this function, true otherwise
996
 *
987
 *
997
 * Note: this function is not threads safe, you would have
988
 * Note: this function is not threads safe, you would have
998
 * to redefine static variables with __thread
989
 * to redefine static variables with __thread
999
 *
990
 *
1000
 */
991
 */
1001
static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
992
static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
1002
{
993
{
1003
    static keyfield_t *interbuffer = NULL;
994
    static keyfield_t *interbuffer = NULL;
1004
    static size_t intersize = 0;
995
    static size_t intersize = 0;
1005
   
996
   
1006
    static unsigned char *shm = NULL;
997
    static unsigned char *shm = NULL;
1007
    static ipcarg_t shm_id = 0;
998
    static ipcarg_t shm_id = 0;
1008
    static size_t shm_size;
999
    static size_t shm_size;
1009
   
1000
   
1010
    bool handled = true;
1001
    bool handled = true;
1011
    int retval = EOK;
1002
    int retval = EOK;
1012
    viewport_t *vport = &viewports[vp];
1003
    viewport_t *vport = &viewports[vp];
1013
    unsigned int x;
1004
    unsigned int x;
1014
    unsigned int y;
1005
    unsigned int y;
1015
    unsigned int w;
1006
    unsigned int w;
1016
    unsigned int h;
1007
    unsigned int h;
1017
   
1008
   
1018
    switch (IPC_GET_METHOD(*call)) {
1009
    switch (IPC_GET_METHOD(*call)) {
1019
    case IPC_M_SHARE_OUT:
1010
    case IPC_M_SHARE_OUT:
1020
        /* We accept one area for data interchange */
1011
        /* We accept one area for data interchange */
1021
        if (IPC_GET_ARG1(*call) == shm_id) {
1012
        if (IPC_GET_ARG1(*call) == shm_id) {
1022
            void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
1013
            void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
1023
            shm_size = IPC_GET_ARG2(*call);
1014
            shm_size = IPC_GET_ARG2(*call);
1024
            if (!ipc_answer_1(callid, EOK, (sysarg_t) dest))
1015
            if (!ipc_answer_1(callid, EOK, (sysarg_t) dest))
1025
                shm = dest;
1016
                shm = dest;
1026
            else
1017
            else
1027
                shm_id = 0;
1018
                shm_id = 0;
1028
           
1019
           
1029
            if (shm[0] != 'P')
1020
            if (shm[0] != 'P')
1030
                return false;
1021
                return false;
1031
           
1022
           
1032
            return true;
1023
            return true;
1033
        } else {
1024
        } else {
1034
            intersize = IPC_GET_ARG2(*call);
1025
            intersize = IPC_GET_ARG2(*call);
1035
            receive_comm_area(callid, call, (void *) &interbuffer);
1026
            receive_comm_area(callid, call, (void *) &interbuffer);
1036
        }
1027
        }
1037
        return true;
1028
        return true;
1038
    case FB_PREPARE_SHM:
1029
    case FB_PREPARE_SHM:
1039
        if (shm_id)
1030
        if (shm_id)
1040
            retval = EBUSY;
1031
            retval = EBUSY;
1041
        else
1032
        else
1042
            shm_id = IPC_GET_ARG1(*call);
1033
            shm_id = IPC_GET_ARG1(*call);
1043
        break;
1034
        break;
1044
       
1035
       
1045
    case FB_DROP_SHM:
1036
    case FB_DROP_SHM:
1046
        if (shm) {
1037
        if (shm) {
1047
            as_area_destroy(shm);
1038
            as_area_destroy(shm);
1048
            shm = NULL;
1039
            shm = NULL;
1049
        }
1040
        }
1050
        shm_id = 0;
1041
        shm_id = 0;
1051
        break;
1042
        break;
1052
       
1043
       
1053
    case FB_SHM2PIXMAP:
1044
    case FB_SHM2PIXMAP:
1054
        if (!shm) {
1045
        if (!shm) {
1055
            retval = EINVAL;
1046
            retval = EINVAL;
1056
            break;
1047
            break;
1057
        }
1048
        }
1058
        retval = shm2pixmap(shm, shm_size);
1049
        retval = shm2pixmap(shm, shm_size);
1059
        break;
1050
        break;
1060
    case FB_DRAW_PPM:
1051
    case FB_DRAW_PPM:
1061
        if (!shm) {
1052
        if (!shm) {
1062
            retval = EINVAL;
1053
            retval = EINVAL;
1063
            break;
1054
            break;
1064
        }
1055
        }
1065
        x = IPC_GET_ARG1(*call);
1056
        x = IPC_GET_ARG1(*call);
1066
        y = IPC_GET_ARG2(*call);
1057
        y = IPC_GET_ARG2(*call);
1067
       
1058
       
1068
        if ((x > vport->width) || (y > vport->height)) {
1059
        if ((x > vport->width) || (y > vport->height)) {
1069
            retval = EINVAL;
1060
            retval = EINVAL;
1070
            break;
1061
            break;
1071
        }
1062
        }
1072
       
1063
       
1073
        ppm_draw(shm, shm_size, IPC_GET_ARG1(*call),
1064
        ppm_draw(shm, shm_size, IPC_GET_ARG1(*call),
1074
            IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport);
1065
            IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport);
1075
        break;
1066
        break;
1076
    case FB_DRAW_TEXT_DATA:
1067
    case FB_DRAW_TEXT_DATA:
1077
        x = IPC_GET_ARG1(*call);
1068
        x = IPC_GET_ARG1(*call);
1078
        y = IPC_GET_ARG2(*call);
1069
        y = IPC_GET_ARG2(*call);
1079
        w = IPC_GET_ARG3(*call);
1070
        w = IPC_GET_ARG3(*call);
1080
        h = IPC_GET_ARG4(*call);
1071
        h = IPC_GET_ARG4(*call);
1081
        if (!interbuffer) {
1072
        if (!interbuffer) {
1082
            retval = EINVAL;
1073
            retval = EINVAL;
1083
            break;
1074
            break;
1084
        }
1075
        }
1085
        if (x + w > vport->cols || y + h > vport->rows) {
1076
        if (x + w > vport->cols || y + h > vport->rows) {
1086
            retval = EINVAL;
1077
            retval = EINVAL;
1087
            break;
1078
            break;
1088
        }
1079
        }
1089
        if (intersize < w * h * sizeof(*interbuffer)) {
1080
        if (intersize < w * h * sizeof(*interbuffer)) {
1090
            retval = EINVAL;
1081
            retval = EINVAL;
1091
            break;
1082
            break;
1092
        }
1083
        }
1093
        draw_text_data(vport, interbuffer, x, y, w, h);
1084
        draw_text_data(vport, interbuffer, x, y, w, h);
1094
        break;
1085
        break;
1095
    default:
1086
    default:
1096
        handled = false;
1087
        handled = false;
1097
    }
1088
    }
1098
   
1089
   
1099
    if (handled)
1090
    if (handled)
1100
        ipc_answer_0(callid, retval);
1091
        ipc_answer_0(callid, retval);
1101
    return handled;
1092
    return handled;
1102
}
1093
}
1103
 
1094
 
1104
 
1095
 
1105
static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
1096
static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
1106
{
1097
{
1107
    unsigned int width = vport->width;
1098
    unsigned int width = vport->width;
1108
    unsigned int height = vport->height;
1099
    unsigned int height = vport->height;
1109
   
1100
   
1110
    if (width + vport->x > screen.xres)
1101
    if (width + vport->x > screen.xres)
1111
        width = screen.xres - vport->x;
1102
        width = screen.xres - vport->x;
1112
    if (height + vport->y > screen.yres)
1103
    if (height + vport->y > screen.yres)
1113
        height = screen.yres - vport->y;
1104
        height = screen.yres - vport->y;
1114
   
1105
   
1115
    unsigned int realwidth = pmap->width <= width ? pmap->width : width;
1106
    unsigned int realwidth = pmap->width <= width ? pmap->width : width;
1116
    unsigned int realheight = pmap->height <= height ? pmap->height : height;
1107
    unsigned int realheight = pmap->height <= height ? pmap->height : height;
1117
   
1108
   
1118
    unsigned int srcrowsize = vport->width * screen.pixelbytes;
1109
    unsigned int srcrowsize = vport->width * screen.pixelbytes;
1119
    unsigned int realrowsize = realwidth * screen.pixelbytes;
1110
    unsigned int realrowsize = realwidth * screen.pixelbytes;
1120
   
1111
   
1121
    unsigned int y;
1112
    unsigned int y;
1122
    for (y = 0; y < realheight; y++) {
1113
    for (y = 0; y < realheight; y++) {
1123
        unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
1114
        unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
1124
        memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize);
1115
        memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize);
1125
    }
1116
    }
1126
}
1117
}
1127
 
1118
 
1128
 
1119
 
1129
/** Save viewport to pixmap
1120
/** Save viewport to pixmap
1130
 *
1121
 *
1131
 */
1122
 */
1132
static int save_vp_to_pixmap(viewport_t *vport)
1123
static int save_vp_to_pixmap(viewport_t *vport)
1133
{
1124
{
1134
    int pm;
1125
    int pm;
1135
    pixmap_t *pmap;
1126
    pixmap_t *pmap;
1136
   
1127
   
1137
    pm = find_free_pixmap();
1128
    pm = find_free_pixmap();
1138
    if (pm == -1)
1129
    if (pm == -1)
1139
        return ELIMIT;
1130
        return ELIMIT;
1140
   
1131
   
1141
    pmap = &pixmaps[pm];
1132
    pmap = &pixmaps[pm];
1142
    pmap->data = malloc(screen.pixelbytes * vport->width * vport->height);
1133
    pmap->data = malloc(screen.pixelbytes * vport->width * vport->height);
1143
    if (!pmap->data)
1134
    if (!pmap->data)
1144
        return ENOMEM;
1135
        return ENOMEM;
1145
   
1136
   
1146
    pmap->width = vport->width;
1137
    pmap->width = vport->width;
1147
    pmap->height = vport->height;
1138
    pmap->height = vport->height;
1148
   
1139
   
1149
    copy_vp_to_pixmap(vport, pmap);
1140
    copy_vp_to_pixmap(vport, pmap);
1150
   
1141
   
1151
    return pm;
1142
    return pm;
1152
}
1143
}
1153
 
1144
 
1154
 
1145
 
1155
/** Draw pixmap on screen
1146
/** Draw pixmap on screen
1156
 *
1147
 *
1157
 * @param vp Viewport to draw on
1148
 * @param vp Viewport to draw on
1158
 * @param pm Pixmap identifier
1149
 * @param pm Pixmap identifier
1159
 *
1150
 *
1160
 */
1151
 */
1161
static int draw_pixmap(int vp, int pm)
1152
static int draw_pixmap(int vp, int pm)
1162
{
1153
{
1163
    pixmap_t *pmap = &pixmaps[pm];
1154
    pixmap_t *pmap = &pixmaps[pm];
1164
    viewport_t *vport = &viewports[vp];
1155
    viewport_t *vport = &viewports[vp];
1165
   
1156
   
1166
    unsigned int width = vport->width;
1157
    unsigned int width = vport->width;
1167
    unsigned int height = vport->height;
1158
    unsigned int height = vport->height;
1168
   
1159
   
1169
    if (width + vport->x > screen.xres)
1160
    if (width + vport->x > screen.xres)
1170
        width = screen.xres - vport->x;
1161
        width = screen.xres - vport->x;
1171
    if (height + vport->y > screen.yres)
1162
    if (height + vport->y > screen.yres)
1172
        height = screen.yres - vport->y;
1163
        height = screen.yres - vport->y;
1173
   
1164
   
1174
    if (!pmap->data)
1165
    if (!pmap->data)
1175
        return EINVAL;
1166
        return EINVAL;
1176
   
1167
   
1177
    unsigned int realwidth = pmap->width <= width ? pmap->width : width;
1168
    unsigned int realwidth = pmap->width <= width ? pmap->width : width;
1178
    unsigned int realheight = pmap->height <= height ? pmap->height : height;
1169
    unsigned int realheight = pmap->height <= height ? pmap->height : height;
1179
   
1170
   
1180
    unsigned int srcrowsize = vport->width * screen.pixelbytes;
1171
    unsigned int srcrowsize = vport->width * screen.pixelbytes;
1181
    unsigned int realrowsize = realwidth * screen.pixelbytes;
1172
    unsigned int realrowsize = realwidth * screen.pixelbytes;
1182
   
1173
   
1183
    unsigned int y;
1174
    unsigned int y;
1184
    for (y = 0; y < realheight; y++) {
1175
    for (y = 0; y < realheight; y++) {
1185
        unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
1176
        unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
1186
        memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize);
1177
        memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize);
1187
    }
1178
    }
1188
   
1179
   
1189
    return EOK;
1180
    return EOK;
1190
}
1181
}
1191
 
1182
 
1192
 
1183
 
1193
/** Tick animation one step forward
1184
/** Tick animation one step forward
1194
 *
1185
 *
1195
 */
1186
 */
1196
static void anims_tick(void)
1187
static void anims_tick(void)
1197
{
1188
{
1198
    unsigned int i;
1189
    unsigned int i;
1199
    static int counts = 0;
1190
    static int counts = 0;
1200
   
1191
   
1201
    /* Limit redrawing */
1192
    /* Limit redrawing */
1202
    counts = (counts + 1) % 8;
1193
    counts = (counts + 1) % 8;
1203
    if (counts)
1194
    if (counts)
1204
        return;
1195
        return;
1205
 
1196
 
1206
    for (i = 0; i < MAX_ANIMATIONS; i++) {
1197
    for (i = 0; i < MAX_ANIMATIONS; i++) {
1207
        if ((!animations[i].animlen) || (!animations[i].initialized) ||
1198
        if ((!animations[i].animlen) || (!animations[i].initialized) ||
1208
            (!animations[i].enabled))
1199
            (!animations[i].enabled))
1209
            continue;
1200
            continue;
1210
       
1201
       
1211
        draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]);
1202
        draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]);
1212
        animations[i].pos = (animations[i].pos + 1) % animations[i].animlen;
1203
        animations[i].pos = (animations[i].pos + 1) % animations[i].animlen;
1213
    }
1204
    }
1214
}
1205
}
1215
 
1206
 
1216
 
1207
 
1217
static unsigned int pointer_x;
1208
static unsigned int pointer_x;
1218
static unsigned int pointer_y;
1209
static unsigned int pointer_y;
1219
static bool pointer_shown, pointer_enabled;
1210
static bool pointer_shown, pointer_enabled;
1220
static int pointer_vport = -1;
1211
static int pointer_vport = -1;
1221
static int pointer_pixmap = -1;
1212
static int pointer_pixmap = -1;
1222
 
1213
 
1223
 
1214
 
1224
static void mouse_show(void)
1215
static void mouse_show(void)
1225
{
1216
{
1226
    int i, j;
1217
    int i, j;
1227
    int visibility;
1218
    int visibility;
1228
    int color;
1219
    int color;
1229
    int bytepos;
1220
    int bytepos;
1230
   
1221
   
1231
    if ((pointer_shown) || (!pointer_enabled))
1222
    if ((pointer_shown) || (!pointer_enabled))
1232
        return;
1223
        return;
1233
   
1224
   
1234
    /* Save image under the pointer. */
1225
    /* Save image under the pointer. */
1235
    if (pointer_vport == -1) {
1226
    if (pointer_vport == -1) {
1236
        pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height);
1227
        pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height);
1237
        if (pointer_vport < 0)
1228
        if (pointer_vport < 0)
1238
            return;
1229
            return;
1239
    } else {
1230
    } else {
1240
        viewports[pointer_vport].x = pointer_x;
1231
        viewports[pointer_vport].x = pointer_x;
1241
        viewports[pointer_vport].y = pointer_y;
1232
        viewports[pointer_vport].y = pointer_y;
1242
    }
1233
    }
1243
   
1234
   
1244
    if (pointer_pixmap == -1)
1235
    if (pointer_pixmap == -1)
1245
        pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]);
1236
        pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]);
1246
    else
1237
    else
1247
        copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]);
1238
        copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]);
1248
   
1239
   
1249
    /* Draw mouse pointer. */
1240
    /* Draw mouse pointer. */
1250
    for (i = 0; i < pointer_height; i++)
1241
    for (i = 0; i < pointer_height; i++)
1251
        for (j = 0; j < pointer_width; j++) {
1242
        for (j = 0; j < pointer_width; j++) {
1252
            bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8;
1243
            bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8;
1253
            visibility = pointer_mask_bits[bytepos] &
1244
            visibility = pointer_mask_bits[bytepos] &
1254
                (1 << (j % 8));
1245
                (1 << (j % 8));
1255
            if (visibility) {
1246
            if (visibility) {
1256
                color = pointer_bits[bytepos] &
1247
                color = pointer_bits[bytepos] &
1257
                    (1 << (j % 8)) ? 0 : 0xffffff;
1248
                    (1 << (j % 8)) ? 0 : 0xffffff;
1258
                if (pointer_x + j < screen.xres && pointer_y +
1249
                if (pointer_x + j < screen.xres && pointer_y +
1259
                    i < screen.yres)
1250
                    i < screen.yres)
1260
                    putpixel(&viewports[0], pointer_x + j,
1251
                    putpixel(&viewports[0], pointer_x + j,
1261
                        pointer_y + i, color);
1252
                        pointer_y + i, color);
1262
            }
1253
            }
1263
        }
1254
        }
1264
    pointer_shown = 1;
1255
    pointer_shown = 1;
1265
}
1256
}
1266
 
1257
 
1267
 
1258
 
1268
static void mouse_hide(void)
1259
static void mouse_hide(void)
1269
{
1260
{
1270
    /* Restore image under the pointer. */
1261
    /* Restore image under the pointer. */
1271
    if (pointer_shown) {
1262
    if (pointer_shown) {
1272
        draw_pixmap(pointer_vport, pointer_pixmap);
1263
        draw_pixmap(pointer_vport, pointer_pixmap);
1273
        pointer_shown = 0;
1264
        pointer_shown = 0;
1274
    }
1265
    }
1275
}
1266
}
1276
 
1267
 
1277
 
1268
 
1278
static void mouse_move(unsigned int x, unsigned int y)
1269
static void mouse_move(unsigned int x, unsigned int y)
1279
{
1270
{
1280
    mouse_hide();
1271
    mouse_hide();
1281
    pointer_x = x;
1272
    pointer_x = x;
1282
    pointer_y = y;
1273
    pointer_y = y;
1283
    mouse_show();
1274
    mouse_show();
1284
}
1275
}
1285
 
1276
 
1286
 
1277
 
1287
static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
1278
static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
1288
{
1279
{
1289
    bool handled = true;
1280
    bool handled = true;
1290
    int retval = EOK;
1281
    int retval = EOK;
1291
    int i, nvp;
1282
    int i, nvp;
1292
    int newval;
1283
    int newval;
1293
   
1284
   
1294
    switch (IPC_GET_METHOD(*call)) {
1285
    switch (IPC_GET_METHOD(*call)) {
1295
    case FB_ANIM_CREATE:
1286
    case FB_ANIM_CREATE:
1296
        nvp = IPC_GET_ARG1(*call);
1287
        nvp = IPC_GET_ARG1(*call);
1297
        if (nvp == -1)
1288
        if (nvp == -1)
1298
            nvp = vp;
1289
            nvp = vp;
1299
        if (nvp >= MAX_VIEWPORTS || nvp < 0 ||
1290
        if (nvp >= MAX_VIEWPORTS || nvp < 0 ||
1300
            !viewports[nvp].initialized) {
1291
            !viewports[nvp].initialized) {
1301
            retval = EINVAL;
1292
            retval = EINVAL;
1302
            break;
1293
            break;
1303
        }
1294
        }
1304
        for (i = 0; i < MAX_ANIMATIONS; i++) {
1295
        for (i = 0; i < MAX_ANIMATIONS; i++) {
1305
            if (!animations[i].initialized)
1296
            if (!animations[i].initialized)
1306
                break;
1297
                break;
1307
        }
1298
        }
1308
        if (i == MAX_ANIMATIONS) {
1299
        if (i == MAX_ANIMATIONS) {
1309
            retval = ELIMIT;
1300
            retval = ELIMIT;
1310
            break;
1301
            break;
1311
        }
1302
        }
1312
        animations[i].initialized = 1;
1303
        animations[i].initialized = 1;
1313
        animations[i].animlen = 0;
1304
        animations[i].animlen = 0;
1314
        animations[i].pos = 0;
1305
        animations[i].pos = 0;
1315
        animations[i].enabled = 0;
1306
        animations[i].enabled = 0;
1316
        animations[i].vp = nvp;
1307
        animations[i].vp = nvp;
1317
        retval = i;
1308
        retval = i;
1318
        break;
1309
        break;
1319
    case FB_ANIM_DROP:
1310
    case FB_ANIM_DROP:
1320
        i = IPC_GET_ARG1(*call);
1311
        i = IPC_GET_ARG1(*call);
1321
        if (i >= MAX_ANIMATIONS || i < 0) {
1312
        if (i >= MAX_ANIMATIONS || i < 0) {
1322
            retval = EINVAL;
1313
            retval = EINVAL;
1323
            break;
1314
            break;
1324
        }
1315
        }
1325
        animations[i].initialized = 0;
1316
        animations[i].initialized = 0;
1326
        break;
1317
        break;
1327
    case FB_ANIM_ADDPIXMAP:
1318
    case FB_ANIM_ADDPIXMAP:
1328
        i = IPC_GET_ARG1(*call);
1319
        i = IPC_GET_ARG1(*call);
1329
        if (i >= MAX_ANIMATIONS || i < 0 ||
1320
        if (i >= MAX_ANIMATIONS || i < 0 ||
1330
            !animations[i].initialized) {
1321
            !animations[i].initialized) {
1331
            retval = EINVAL;
1322
            retval = EINVAL;
1332
            break;
1323
            break;
1333
        }
1324
        }
1334
        if (animations[i].animlen == MAX_ANIM_LEN) {
1325
        if (animations[i].animlen == MAX_ANIM_LEN) {
1335
            retval = ELIMIT;
1326
            retval = ELIMIT;
1336
            break;
1327
            break;
1337
        }
1328
        }
1338
        newval = IPC_GET_ARG2(*call);
1329
        newval = IPC_GET_ARG2(*call);
1339
        if (newval < 0 || newval > MAX_PIXMAPS ||
1330
        if (newval < 0 || newval > MAX_PIXMAPS ||
1340
            !pixmaps[newval].data) {
1331
            !pixmaps[newval].data) {
1341
            retval = EINVAL;
1332
            retval = EINVAL;
1342
            break;
1333
            break;
1343
        }
1334
        }
1344
        animations[i].pixmaps[animations[i].animlen++] = newval;
1335
        animations[i].pixmaps[animations[i].animlen++] = newval;
1345
        break;
1336
        break;
1346
    case FB_ANIM_CHGVP:
1337
    case FB_ANIM_CHGVP:
1347
        i = IPC_GET_ARG1(*call);
1338
        i = IPC_GET_ARG1(*call);
1348
        if (i >= MAX_ANIMATIONS || i < 0) {
1339
        if (i >= MAX_ANIMATIONS || i < 0) {
1349
            retval = EINVAL;
1340
            retval = EINVAL;
1350
            break;
1341
            break;
1351
        }
1342
        }
1352
        nvp = IPC_GET_ARG2(*call);
1343
        nvp = IPC_GET_ARG2(*call);
1353
        if (nvp == -1)
1344
        if (nvp == -1)
1354
            nvp = vp;
1345
            nvp = vp;
1355
        if (nvp >= MAX_VIEWPORTS || nvp < 0 ||
1346
        if (nvp >= MAX_VIEWPORTS || nvp < 0 ||
1356
            !viewports[nvp].initialized) {
1347
            !viewports[nvp].initialized) {
1357
            retval = EINVAL;
1348
            retval = EINVAL;
1358
            break;
1349
            break;
1359
        }
1350
        }
1360
        animations[i].vp = nvp;
1351
        animations[i].vp = nvp;
1361
        break;
1352
        break;
1362
    case FB_ANIM_START:
1353
    case FB_ANIM_START:
1363
    case FB_ANIM_STOP:
1354
    case FB_ANIM_STOP:
1364
        i = IPC_GET_ARG1(*call);
1355
        i = IPC_GET_ARG1(*call);
1365
        if (i >= MAX_ANIMATIONS || i < 0) {
1356
        if (i >= MAX_ANIMATIONS || i < 0) {
1366
            retval = EINVAL;
1357
            retval = EINVAL;
1367
            break;
1358
            break;
1368
        }
1359
        }
1369
        newval = (IPC_GET_METHOD(*call) == FB_ANIM_START);
1360
        newval = (IPC_GET_METHOD(*call) == FB_ANIM_START);
1370
        if (newval ^ animations[i].enabled) {
1361
        if (newval ^ animations[i].enabled) {
1371
            animations[i].enabled = newval;
1362
            animations[i].enabled = newval;
1372
            anims_enabled += newval ? 1 : -1;
1363
            anims_enabled += newval ? 1 : -1;
1373
        }
1364
        }
1374
        break;
1365
        break;
1375
    default:
1366
    default:
1376
        handled = 0;
1367
        handled = 0;
1377
    }
1368
    }
1378
    if (handled)
1369
    if (handled)
1379
        ipc_answer_0(callid, retval);
1370
        ipc_answer_0(callid, retval);
1380
    return handled;
1371
    return handled;
1381
}
1372
}
1382
 
1373
 
1383
 
1374
 
1384
/** Handler for messages concerning pixmap handling
1375
/** Handler for messages concerning pixmap handling
1385
 *
1376
 *
1386
 */
1377
 */
1387
static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
1378
static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
1388
{
1379
{
1389
    bool handled = true;
1380
    bool handled = true;
1390
    int retval = EOK;
1381
    int retval = EOK;
1391
    int i, nvp;
1382
    int i, nvp;
1392
   
1383
   
1393
    switch (IPC_GET_METHOD(*call)) {
1384
    switch (IPC_GET_METHOD(*call)) {
1394
    case FB_VP_DRAW_PIXMAP:
1385
    case FB_VP_DRAW_PIXMAP:
1395
        nvp = IPC_GET_ARG1(*call);
1386
        nvp = IPC_GET_ARG1(*call);
1396
        if (nvp == -1)
1387
        if (nvp == -1)
1397
            nvp = vp;
1388
            nvp = vp;
1398
        if (nvp < 0 || nvp >= MAX_VIEWPORTS ||
1389
        if (nvp < 0 || nvp >= MAX_VIEWPORTS ||
1399
            !viewports[nvp].initialized) {
1390
            !viewports[nvp].initialized) {
1400
            retval = EINVAL;
1391
            retval = EINVAL;
1401
            break;
1392
            break;
1402
        }
1393
        }
1403
        i = IPC_GET_ARG2(*call);
1394
        i = IPC_GET_ARG2(*call);
1404
        retval = draw_pixmap(nvp, i);
1395
        retval = draw_pixmap(nvp, i);
1405
        break;
1396
        break;
1406
    case FB_VP2PIXMAP:
1397
    case FB_VP2PIXMAP:
1407
        nvp = IPC_GET_ARG1(*call);
1398
        nvp = IPC_GET_ARG1(*call);
1408
        if (nvp == -1)
1399
        if (nvp == -1)
1409
            nvp = vp;
1400
            nvp = vp;
1410
        if (nvp < 0 || nvp >= MAX_VIEWPORTS ||
1401
        if (nvp < 0 || nvp >= MAX_VIEWPORTS ||
1411
            !viewports[nvp].initialized)
1402
            !viewports[nvp].initialized)
1412
            retval = EINVAL;
1403
            retval = EINVAL;
1413
        else
1404
        else
1414
            retval = save_vp_to_pixmap(&viewports[nvp]);
1405
            retval = save_vp_to_pixmap(&viewports[nvp]);
1415
        break;
1406
        break;
1416
    case FB_DROP_PIXMAP:
1407
    case FB_DROP_PIXMAP:
1417
        i = IPC_GET_ARG1(*call);
1408
        i = IPC_GET_ARG1(*call);
1418
        if (i >= MAX_PIXMAPS) {
1409
        if (i >= MAX_PIXMAPS) {
1419
            retval = EINVAL;
1410
            retval = EINVAL;
1420
            break;
1411
            break;
1421
        }
1412
        }
1422
        if (pixmaps[i].data) {
1413
        if (pixmaps[i].data) {
1423
            free(pixmaps[i].data);
1414
            free(pixmaps[i].data);
1424
            pixmaps[i].data = NULL;
1415
            pixmaps[i].data = NULL;
1425
        }
1416
        }
1426
        break;
1417
        break;
1427
    default:
1418
    default:
1428
        handled = 0;
1419
        handled = 0;
1429
    }
1420
    }
1430
   
1421
   
1431
    if (handled)
1422
    if (handled)
1432
        ipc_answer_0(callid, retval);
1423
        ipc_answer_0(callid, retval);
1433
    return handled;
1424
    return handled;
1434
   
1425
   
1435
}
1426
}
1436
 
1427
 
1437
static int rgb_from_style(attr_rgb_t *rgb, int style)
1428
static int rgb_from_style(attr_rgb_t *rgb, int style)
1438
{
1429
{
1439
    switch (style) {
1430
    switch (style) {
1440
    case STYLE_NORMAL:
1431
    case STYLE_NORMAL:
1441
        rgb->fg_color = color_table[COLOR_BLACK];
1432
        rgb->fg_color = color_table[COLOR_BLACK];
1442
        rgb->bg_color = color_table[COLOR_WHITE];
1433
        rgb->bg_color = color_table[COLOR_WHITE];
1443
        break;
1434
        break;
1444
    case STYLE_EMPHASIS:
1435
    case STYLE_EMPHASIS:
1445
        rgb->fg_color = color_table[COLOR_RED];
1436
        rgb->fg_color = color_table[COLOR_RED];
1446
        rgb->bg_color = color_table[COLOR_WHITE];
1437
        rgb->bg_color = color_table[COLOR_WHITE];
1447
        break;
1438
        break;
1448
    default:
1439
    default:
1449
        return EINVAL;
1440
        return EINVAL;
1450
    }
1441
    }
1451
 
1442
 
1452
    return EOK;
1443
    return EOK;
1453
}
1444
}
1454
 
1445
 
1455
static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color,
1446
static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color,
1456
    ipcarg_t bg_color, ipcarg_t flags)
1447
    ipcarg_t bg_color, ipcarg_t flags)
1457
{
1448
{
1458
    fg_color = (fg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0);
1449
    fg_color = (fg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0);
1459
    bg_color = (bg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0);
1450
    bg_color = (bg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0);
1460
 
1451
 
1461
    rgb->fg_color = color_table[fg_color];
1452
    rgb->fg_color = color_table[fg_color];
1462
    rgb->bg_color = color_table[bg_color];
1453
    rgb->bg_color = color_table[bg_color];
1463
 
1454
 
1464
    return EOK;
1455
    return EOK;
1465
}
1456
}
1466
 
1457
 
1467
static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a)
1458
static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a)
1468
{
1459
{
1469
    int rc;
1460
    int rc;
1470
 
1461
 
1471
    switch (a->t) {
1462
    switch (a->t) {
1472
    case at_style:
1463
    case at_style:
1473
        rc = rgb_from_style(rgb, a->a.s.style);
1464
        rc = rgb_from_style(rgb, a->a.s.style);
1474
        break;
1465
        break;
1475
    case at_idx:
1466
    case at_idx:
1476
        rc = rgb_from_idx(rgb, a->a.i.fg_color,
1467
        rc = rgb_from_idx(rgb, a->a.i.fg_color,
1477
            a->a.i.bg_color, a->a.i.flags);
1468
            a->a.i.bg_color, a->a.i.flags);
1478
        break;
1469
        break;
1479
    case at_rgb:
1470
    case at_rgb:
1480
        *rgb = a->a.r;
1471
        *rgb = a->a.r;
1481
        rc = EOK;
1472
        rc = EOK;
1482
        break;
1473
        break;
1483
    }
1474
    }
1484
 
1475
 
1485
    return rc;
1476
    return rc;
1486
}
1477
}
1487
 
1478
 
1488
static int fb_set_style(viewport_t *vport, ipcarg_t style)
1479
static int fb_set_style(viewport_t *vport, ipcarg_t style)
1489
{
1480
{
1490
    return rgb_from_style(&vport->attr, (int) style);
1481
    return rgb_from_style(&vport->attr, (int) style);
1491
}
1482
}
1492
 
1483
 
1493
static int fb_set_color(viewport_t *vport, ipcarg_t fg_color,
1484
static int fb_set_color(viewport_t *vport, ipcarg_t fg_color,
1494
    ipcarg_t bg_color, ipcarg_t flags)
1485
    ipcarg_t bg_color, ipcarg_t flags)
1495
{
1486
{
1496
    return rgb_from_idx(&vport->attr, fg_color, bg_color, flags);
1487
    return rgb_from_idx(&vport->attr, fg_color, bg_color, flags);
1497
}
1488
}
1498
 
1489
 
1499
/** Function for handling connections to FB
1490
/** Function for handling connections to FB
1500
 *
1491
 *
1501
 */
1492
 */
1502
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
1493
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
1503
{
1494
{
1504
    unsigned int vp = 0;
1495
    unsigned int vp = 0;
1505
    viewport_t *vport = &viewports[vp];
1496
    viewport_t *vport = &viewports[vp];
1506
   
1497
   
1507
    if (client_connected) {
1498
    if (client_connected) {
1508
        ipc_answer_0(iid, ELIMIT);
1499
        ipc_answer_0(iid, ELIMIT);
1509
        return;
1500
        return;
1510
    }
1501
    }
1511
   
1502
   
1512
    /* Accept connection */
1503
    /* Accept connection */
1513
    client_connected = true;
1504
    client_connected = true;
1514
    ipc_answer_0(iid, EOK);
1505
    ipc_answer_0(iid, EOK);
1515
   
1506
   
1516
    while (true) {
1507
    while (true) {
1517
        ipc_callid_t callid;
1508
        ipc_callid_t callid;
1518
        ipc_call_t call;
1509
        ipc_call_t call;
1519
        int retval;
1510
        int retval;
1520
        unsigned int i;
1511
        unsigned int i;
1521
        int scroll;
1512
        int scroll;
1522
        uint32_t glyph;
1513
        wchar_t ch;
1523
        unsigned int row, col;
1514
        unsigned int row, col;
1524
       
1515
       
1525
        if ((vport->cursor_active) || (anims_enabled))
1516
        if ((vport->cursor_active) || (anims_enabled))
1526
            callid = async_get_call_timeout(&call, 250000);
1517
            callid = async_get_call_timeout(&call, 250000);
1527
        else
1518
        else
1528
            callid = async_get_call(&call);
1519
            callid = async_get_call(&call);
1529
       
1520
       
1530
        mouse_hide();
1521
        mouse_hide();
1531
        if (!callid) {
1522
        if (!callid) {
1532
            cursor_blink(vport);
1523
            cursor_blink(vport);
1533
            anims_tick();
1524
            anims_tick();
1534
            mouse_show();
1525
            mouse_show();
1535
            continue;
1526
            continue;
1536
        }
1527
        }
1537
       
1528
       
1538
        if (shm_handle(callid, &call, vp))
1529
        if (shm_handle(callid, &call, vp))
1539
            continue;
1530
            continue;
1540
       
1531
       
1541
        if (pixmap_handle(callid, &call, vp))
1532
        if (pixmap_handle(callid, &call, vp))
1542
            continue;
1533
            continue;
1543
       
1534
       
1544
        if (anim_handle(callid, &call, vp))
1535
        if (anim_handle(callid, &call, vp))
1545
            continue;
1536
            continue;
1546
       
1537
       
1547
        switch (IPC_GET_METHOD(call)) {
1538
        switch (IPC_GET_METHOD(call)) {
1548
        case IPC_M_PHONE_HUNGUP:
1539
        case IPC_M_PHONE_HUNGUP:
1549
            client_connected = false;
1540
            client_connected = false;
1550
           
1541
           
1551
            /* Cleanup other viewports */
1542
            /* Cleanup other viewports */
1552
            for (i = 1; i < MAX_VIEWPORTS; i++)
1543
            for (i = 1; i < MAX_VIEWPORTS; i++)
1553
                vport->initialized = false;
1544
                vport->initialized = false;
1554
           
1545
           
1555
            /* Exit thread */
1546
            /* Exit thread */
1556
            return;
1547
            return;
1557
       
1548
       
1558
        case FB_PUTCHAR:
1549
        case FB_PUTCHAR:
1559
            glyph = IPC_GET_ARG1(call);
1550
            ch = IPC_GET_ARG1(call);
1560
            row = IPC_GET_ARG2(call);
1551
            row = IPC_GET_ARG2(call);
1561
            col = IPC_GET_ARG3(call);
1552
            col = IPC_GET_ARG3(call);
1562
           
1553
           
1563
            if ((col >= vport->cols) || (row >= vport->rows)) {
1554
            if ((col >= vport->cols) || (row >= vport->rows)) {
1564
                retval = EINVAL;
1555
                retval = EINVAL;
1565
                break;
1556
                break;
1566
            }
1557
            }
1567
            ipc_answer_0(callid, EOK);
1558
            ipc_answer_0(callid, EOK);
1568
           
1559
           
1569
            draw_char(vport, glyph, col, row);
1560
            draw_char(vport, ch, col, row);
1570
           
1561
           
1571
            /* Message already answered */
1562
            /* Message already answered */
1572
            continue;
1563
            continue;
1573
        case FB_CLEAR:
1564
        case FB_CLEAR:
1574
            vport_clear(vport);
1565
            vport_clear(vport);
1575
            cursor_show(vport);
1566
            cursor_show(vport);
1576
            retval = EOK;
1567
            retval = EOK;
1577
            break;
1568
            break;
1578
        case FB_CURSOR_GOTO:
1569
        case FB_CURSOR_GOTO:
1579
            row = IPC_GET_ARG1(call);
1570
            row = IPC_GET_ARG1(call);
1580
            col = IPC_GET_ARG2(call);
1571
            col = IPC_GET_ARG2(call);
1581
           
1572
           
1582
            if ((col >= vport->cols) || (row >= vport->rows)) {
1573
            if ((col >= vport->cols) || (row >= vport->rows)) {
1583
                retval = EINVAL;
1574
                retval = EINVAL;
1584
                break;
1575
                break;
1585
            }
1576
            }
1586
            retval = EOK;
1577
            retval = EOK;
1587
           
1578
           
1588
            cursor_hide(vport);
1579
            cursor_hide(vport);
1589
            vport->cur_col = col;
1580
            vport->cur_col = col;
1590
            vport->cur_row = row;
1581
            vport->cur_row = row;
1591
            cursor_show(vport);
1582
            cursor_show(vport);
1592
            break;
1583
            break;
1593
        case FB_CURSOR_VISIBILITY:
1584
        case FB_CURSOR_VISIBILITY:
1594
            cursor_hide(vport);
1585
            cursor_hide(vport);
1595
            vport->cursor_active = IPC_GET_ARG1(call);
1586
            vport->cursor_active = IPC_GET_ARG1(call);
1596
            cursor_show(vport);
1587
            cursor_show(vport);
1597
            retval = EOK;
1588
            retval = EOK;
1598
            break;
1589
            break;
1599
        case FB_GET_CSIZE:
1590
        case FB_GET_CSIZE:
1600
            ipc_answer_2(callid, EOK, vport->rows, vport->cols);
1591
            ipc_answer_2(callid, EOK, vport->rows, vport->cols);
1601
            continue;
1592
            continue;
1602
        case FB_SCROLL:
1593
        case FB_SCROLL:
1603
            scroll = IPC_GET_ARG1(call);
1594
            scroll = IPC_GET_ARG1(call);
1604
            if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) {
1595
            if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) {
1605
                retval = EINVAL;
1596
                retval = EINVAL;
1606
                break;
1597
                break;
1607
            }
1598
            }
1608
            cursor_hide(vport);
1599
            cursor_hide(vport);
1609
            vport_scroll(vport, scroll);
1600
            vport_scroll(vport, scroll);
1610
            cursor_show(vport);
1601
            cursor_show(vport);
1611
            retval = EOK;
1602
            retval = EOK;
1612
            break;
1603
            break;
1613
        case FB_VIEWPORT_SWITCH:
1604
        case FB_VIEWPORT_SWITCH:
1614
            i = IPC_GET_ARG1(call);
1605
            i = IPC_GET_ARG1(call);
1615
            if (i >= MAX_VIEWPORTS) {
1606
            if (i >= MAX_VIEWPORTS) {
1616
                retval = EINVAL;
1607
                retval = EINVAL;
1617
                break;
1608
                break;
1618
            }
1609
            }
1619
            if (!viewports[i].initialized) {
1610
            if (!viewports[i].initialized) {
1620
                retval = EADDRNOTAVAIL;
1611
                retval = EADDRNOTAVAIL;
1621
                break;
1612
                break;
1622
            }
1613
            }
1623
            cursor_hide(vport);
1614
            cursor_hide(vport);
1624
            vp = i;
1615
            vp = i;
1625
            vport = &viewports[vp];
1616
            vport = &viewports[vp];
1626
            cursor_show(vport);
1617
            cursor_show(vport);
1627
            retval = EOK;
1618
            retval = EOK;
1628
            break;
1619
            break;
1629
        case FB_VIEWPORT_CREATE:
1620
        case FB_VIEWPORT_CREATE:
1630
            retval = vport_create(IPC_GET_ARG1(call) >> 16,
1621
            retval = vport_create(IPC_GET_ARG1(call) >> 16,
1631
                IPC_GET_ARG1(call) & 0xffff,
1622
                IPC_GET_ARG1(call) & 0xffff,
1632
                IPC_GET_ARG2(call) >> 16,
1623
                IPC_GET_ARG2(call) >> 16,
1633
                IPC_GET_ARG2(call) & 0xffff);
1624
                IPC_GET_ARG2(call) & 0xffff);
1634
            break;
1625
            break;
1635
        case FB_VIEWPORT_DELETE:
1626
        case FB_VIEWPORT_DELETE:
1636
            i = IPC_GET_ARG1(call);
1627
            i = IPC_GET_ARG1(call);
1637
            if (i >= MAX_VIEWPORTS) {
1628
            if (i >= MAX_VIEWPORTS) {
1638
                retval = EINVAL;
1629
                retval = EINVAL;
1639
                break;
1630
                break;
1640
            }
1631
            }
1641
            if (!viewports[i].initialized) {
1632
            if (!viewports[i].initialized) {
1642
                retval = EADDRNOTAVAIL;
1633
                retval = EADDRNOTAVAIL;
1643
                break;
1634
                break;
1644
            }
1635
            }
1645
            viewports[i].initialized = false;
1636
            viewports[i].initialized = false;
1646
            if (viewports[i].glyphs)
1637
            if (viewports[i].glyphs)
1647
                free(viewports[i].glyphs);
1638
                free(viewports[i].glyphs);
1648
            if (viewports[i].bgpixel)
1639
            if (viewports[i].bgpixel)
1649
                free(viewports[i].bgpixel);
1640
                free(viewports[i].bgpixel);
1650
            if (viewports[i].backbuf)
1641
            if (viewports[i].backbuf)
1651
                free(viewports[i].backbuf);
1642
                free(viewports[i].backbuf);
1652
            retval = EOK;
1643
            retval = EOK;
1653
            break;
1644
            break;
1654
        case FB_SET_STYLE:
1645
        case FB_SET_STYLE:
1655
            retval = fb_set_style(vport, IPC_GET_ARG1(call));
1646
            retval = fb_set_style(vport, IPC_GET_ARG1(call));
1656
            break;
1647
            break;
1657
        case FB_SET_COLOR:
1648
        case FB_SET_COLOR:
1658
            retval = fb_set_color(vport, IPC_GET_ARG1(call),
1649
            retval = fb_set_color(vport, IPC_GET_ARG1(call),
1659
                IPC_GET_ARG2(call), IPC_GET_ARG3(call));
1650
                IPC_GET_ARG2(call), IPC_GET_ARG3(call));
1660
            break;
1651
            break;
1661
        case FB_SET_RGB_COLOR:
1652
        case FB_SET_RGB_COLOR:
1662
            vport->attr.fg_color = IPC_GET_ARG1(call);
1653
            vport->attr.fg_color = IPC_GET_ARG1(call);
1663
            vport->attr.bg_color = IPC_GET_ARG2(call);
1654
            vport->attr.bg_color = IPC_GET_ARG2(call);
1664
            retval = EOK;
1655
            retval = EOK;
1665
            break;
1656
            break;
1666
        case FB_GET_RESOLUTION:
1657
        case FB_GET_RESOLUTION:
1667
            ipc_answer_2(callid, EOK, screen.xres, screen.yres);
1658
            ipc_answer_2(callid, EOK, screen.xres, screen.yres);
1668
            continue;
1659
            continue;
1669
        case FB_POINTER_MOVE:
1660
        case FB_POINTER_MOVE:
1670
            pointer_enabled = true;
1661
            pointer_enabled = true;
1671
            mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
1662
            mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
1672
            retval = EOK;
1663
            retval = EOK;
1673
            break;
1664
            break;
1674
        default:
1665
        default:
1675
            retval = ENOENT;
1666
            retval = ENOENT;
1676
        }
1667
        }
1677
        ipc_answer_0(callid, retval);
1668
        ipc_answer_0(callid, retval);
1678
    }
1669
    }
1679
}
1670
}
1680
 
1671
 
1681
/** Initialization of framebuffer
1672
/** Initialization of framebuffer
1682
 *
1673
 *
1683
 */
1674
 */
1684
int fb_init(void)
1675
int fb_init(void)
1685
{
1676
{
1686
    async_set_client_connection(fb_client_connection);
1677
    async_set_client_connection(fb_client_connection);
1687
   
1678
   
1688
    void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
1679
    void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
1689
    unsigned int fb_offset = sysinfo_value("fb.offset");
1680
    unsigned int fb_offset = sysinfo_value("fb.offset");
1690
    unsigned int fb_width = sysinfo_value("fb.width");
1681
    unsigned int fb_width = sysinfo_value("fb.width");
1691
    unsigned int fb_height = sysinfo_value("fb.height");
1682
    unsigned int fb_height = sysinfo_value("fb.height");
1692
    unsigned int fb_scanline = sysinfo_value("fb.scanline");
1683
    unsigned int fb_scanline = sysinfo_value("fb.scanline");
1693
    unsigned int fb_visual = sysinfo_value("fb.visual");
1684
    unsigned int fb_visual = sysinfo_value("fb.visual");
1694
   
1685
   
1695
    unsigned int fbsize = fb_scanline * fb_height;
1686
    unsigned int fbsize = fb_scanline * fb_height;
1696
    void *fb_addr = as_get_mappable_page(fbsize);
1687
    void *fb_addr = as_get_mappable_page(fbsize);
1697
   
1688
   
1698
    if (physmem_map(fb_ph_addr + fb_offset, fb_addr,
1689
    if (physmem_map(fb_ph_addr + fb_offset, fb_addr,
1699
        ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
1690
        ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
1700
        return -1;
1691
        return -1;
1701
   
1692
   
1702
    if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual))
1693
    if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual))
1703
        return 0;
1694
        return 0;
1704
   
1695
   
1705
    return -1;
1696
    return -1;
1706
}
1697
}
1707
 
1698
 
1708
/**
1699
/**
1709
 * @}
1700
 * @}
1710
 */
1701
 */
1711
 
1702