Subversion Repositories HelenOS

Rev

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

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