Subversion Repositories HelenOS

Rev

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

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