Subversion Repositories HelenOS

Rev

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

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