Subversion Repositories HelenOS

Rev

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

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