Subversion Repositories HelenOS

Rev

Rev 3742 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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