Subversion Repositories HelenOS

Rev

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

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