Subversion Repositories HelenOS

Rev

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

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