Subversion Repositories HelenOS

Rev

Rev 3343 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3343 Rev 3742
Line 1... Line 1...
1
/*
1
/*
-
 
2
 * Copyright (c) 2008 Martin Decky
2
 * Copyright (c) 2006 Jakub Vana
3
 * Copyright (c) 2006 Jakub Vana
3
 * Copyright (c) 2006 Ondrej Palkovsky
4
 * Copyright (c) 2006 Ondrej Palkovsky
4
 * All rights reserved.
5
 * All rights reserved.
5
 *
6
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * Redistribution and use in source and binary forms, with or without
Line 30... Line 31...
30
/**
31
/**
31
 * @defgroup fb Graphical framebuffer
32
 * @defgroup fb Graphical framebuffer
32
 * @brief   HelenOS graphical framebuffer.
33
 * @brief   HelenOS graphical framebuffer.
33
 * @ingroup fbs
34
 * @ingroup fbs
34
 * @{
35
 * @{
35
 */
36
 */
36
 
37
 
37
/** @file
38
/** @file
38
 */
39
 */
39
 
40
 
40
#include <stdlib.h>
41
#include <stdlib.h>
Line 60... Line 61...
60
#include "ppm.h"
61
#include "ppm.h"
61
 
62
 
62
#include "pointer.xbm"
63
#include "pointer.xbm"
63
#include "pointer_mask.xbm"
64
#include "pointer_mask.xbm"
64
 
65
 
65
#define DEFAULT_BGCOLOR                0xf0f0f0
66
#define DEFAULT_BGCOLOR  0xf0f0f0
66
#define DEFAULT_FGCOLOR                0x0
67
#define DEFAULT_FGCOLOR  0x000000
67
 
68
 
-
 
69
#define MAX_ANIM_LEN     8
-
 
70
#define MAX_ANIMATIONS   4
68
/***************************************************************/
71
#define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
69
/* Pixel specific fuctions */
72
#define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
70
 
73
 
71
typedef void (*conv2scr_fn_t)(void *, int);
74
typedef void (*rgb_conv_t)(void *, uint32_t);
72
typedef int (*conv2rgb_fn_t)(void *);
-
 
73
 
75
 
74
struct {
76
struct {
75
    uint8_t *fbaddress;
77
    uint8_t *fb_addr;
76
 
78
   
77
    unsigned int xres;
79
    unsigned int xres;
78
    unsigned int yres;
80
    unsigned int yres;
-
 
81
   
79
    unsigned int scanline;
82
    unsigned int scanline;
-
 
83
    unsigned int glyphscanline;
-
 
84
   
80
    unsigned int pixelbytes;
85
    unsigned int pixelbytes;
81
    unsigned int invert_colors;
86
    unsigned int glyphbytes;
82
 
87
   
83
    conv2scr_fn_t rgb2scr;
88
    rgb_conv_t rgb_conv;
84
    conv2rgb_fn_t scr2rgb;
-
 
85
} screen;
89
} screen;
86
 
90
 
87
typedef struct {
91
typedef struct {
88
    int initialized;
92
    bool initialized;
89
    unsigned int x, y;
93
    unsigned int x;
-
 
94
    unsigned int y;
-
 
95
    unsigned int width;
90
    unsigned int width, height;
96
    unsigned int height;
91
 
97
   
92
    /* Text support in window */
98
    /* Text support in window */
-
 
99
    unsigned int cols;
93
    unsigned int rows, cols;
100
    unsigned int rows;
-
 
101
   
94
    /* Style for text printing */
102
    /* Style and glyphs for text printing */
95
    style_t style;
103
    style_t style;
-
 
104
    uint8_t *glyphs;
-
 
105
    uint8_t *bgpixel;
-
 
106
   
96
    /* Auto-cursor position */
107
    /* Auto-cursor position */
97
    int cursor_active, cur_col, cur_row;
108
    bool cursor_active;
-
 
109
    unsigned int cur_col;
-
 
110
    unsigned int cur_row;
98
    int cursor_shown;
111
    bool cursor_shown;
-
 
112
   
99
    /* Double buffering */
113
    /* Back buffer */
100
    uint8_t *dbdata;
-
 
101
    unsigned int dboffset;
114
    unsigned int bbsize;
102
    unsigned int paused;
115
    uint8_t *backbuf;
103
} viewport_t;
116
} viewport_t;
104
 
117
 
105
#define MAX_ANIM_LEN    8
-
 
106
#define MAX_ANIMATIONS  4
-
 
107
typedef struct {
118
typedef struct {
108
    int initialized;
119
    bool initialized;
109
    int enabled;
120
    bool enabled;
110
    unsigned int vp;
121
    unsigned int vp;
111
 
122
   
112
    unsigned int pos;
123
    unsigned int pos;
113
    unsigned int animlen;
124
    unsigned int animlen;
114
    unsigned int pixmaps[MAX_ANIM_LEN];
125
    unsigned int pixmaps[MAX_ANIM_LEN];
115
} animation_t;
126
} animation_t;
-
 
127
 
116
static animation_t animations[MAX_ANIMATIONS];
128
static animation_t animations[MAX_ANIMATIONS];
117
static int anims_enabled;
129
static bool anims_enabled;
118
 
130
 
119
/** Maximum number of saved pixmaps
-
 
120
 * Pixmap is a saved rectangle
-
 
121
 */
-
 
122
#define MAX_PIXMAPS        256
-
 
123
typedef struct {
131
typedef struct {
124
    unsigned int width;
132
    unsigned int width;
125
    unsigned int height;
133
    unsigned int height;
126
    uint8_t *data;
134
    uint8_t *data;
127
} pixmap_t;
135
} pixmap_t;
128
static pixmap_t pixmaps[MAX_PIXMAPS];
-
 
129
 
136
 
130
/* Viewport is a rectangular area on the screen */
137
static pixmap_t pixmaps[MAX_PIXMAPS];
131
#define MAX_VIEWPORTS 128
-
 
132
static viewport_t viewports[128];
138
static viewport_t viewports[128];
133
 
139
 
134
/* Allow only 1 connection */
-
 
135
static int client_connected = 0;
140
static bool client_connected = false;  /**< Allow only 1 connection */
136
 
141
 
137
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
142
#define RED(x, bits)                 ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
138
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
143
#define GREEN(x, bits)               ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
139
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
144
#define BLUE(x, bits)                ((x >> (8 - bits)) & ((1 << bits) - 1))
140
 
145
 
141
#define COL_WIDTH   8
146
#define COL2X(col)                   ((col) * FONT_WIDTH)
142
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
147
#define ROW2Y(row)                   ((row) * FONT_SCANLINES)
143
 
148
 
-
 
149
#define X2COL(x)                     ((x) / FONT_WIDTH)
144
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
150
#define Y2ROW(y)                     ((y) / FONT_SCANLINES)
145
 
151
 
146
static inline int COLOR(int color)
152
#define FB_POS(x, y)                 ((y) * screen.scanline + (x) * screen.pixelbytes)
147
{
-
 
148
    return screen.invert_colors ? ~color : color;
153
#define BB_POS(vport, col, row)      ((row) * vport->cols + (col))
149
}
-
 
-
 
154
#define GLYPH_POS(glyph, y, cursor)  (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline)
150
 
155
 
151
/* Conversion routines between different color representations */
-
 
152
static void
-
 
153
rgb_byte0888(void *dst, int rgb)
-
 
154
{
-
 
155
    *(int *)dst = rgb;
-
 
156
}
-
 
157
 
156
 
-
 
157
/** ARGB 8:8:8:8 conversion
-
 
158
 *
158
static int
159
 */
159
byte0888_rgb(void *src)
160
static void rgb_0888(void *dst, uint32_t rgb)
160
{
161
{
161
    return (*(int *)src) & 0xffffff;
162
    *((uint32_t *) dst) = rgb & 0xffffff;
162
}
163
}
163
 
164
 
164
static void
-
 
165
bgr_byte0888(void *dst, int rgb)
-
 
166
{
-
 
167
    *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 |
-
 
168
        RED(rgb, 8);
-
 
169
}
-
 
170
 
165
 
-
 
166
/** ABGR 8:8:8:8 conversion
-
 
167
 *
171
static int
168
 */
172
byte0888_bgr(void *src)
169
static void bgr_0888(void *dst, uint32_t rgb)
173
{
170
{
174
    int color = *(uint32_t *)(src);
171
    *((uint32_t *) dst)
175
    return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) |
172
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
176
        ((color >> 16) & 0xff);
-
 
177
}
173
}
178
 
174
 
-
 
175
 
179
static void
176
/** BGR 8:8:8 conversion
-
 
177
 *
-
 
178
 */
180
rgb_byte888(void *dst, int rgb)
179
static void rgb_888(void *dst, uint32_t rgb)
181
{
180
{
182
    uint8_t *scr = dst;
-
 
183
#if defined(FB_INVERT_ENDIAN)
181
#if defined(FB_INVERT_ENDIAN)
184
    scr[0] = RED(rgb, 8);
182
    ((uint8_t *) dst)[0] = RED(rgb, 8);
185
    scr[1] = GREEN(rgb, 8);
183
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
186
    scr[2] = BLUE(rgb, 8);
184
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
187
#else
185
#else
188
    scr[2] = RED(rgb, 8);
186
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
189
    scr[1] = GREEN(rgb, 8);
187
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
190
    scr[0] = BLUE(rgb, 8);
188
    ((uint8_t *) dst)[2] = RED(rgb, 8);
191
#endif
189
#endif
192
}
190
}
193
 
191
 
194
static int
-
 
195
byte888_rgb(void *src)
-
 
196
{
-
 
197
    uint8_t *scr = src;
-
 
198
#if defined(FB_INVERT_ENDIAN)
-
 
199
    return scr[0] << 16 | scr[1] << 8 | scr[2];
-
 
200
#else
-
 
201
    return scr[2] << 16 | scr[1] << 8 | scr[0];
-
 
202
#endif  
-
 
203
}
-
 
204
 
192
 
205
/**  16-bit depth (5:5:5) */
193
/** RGB 5:5:5 conversion
-
 
194
 *
206
static void
195
 */
207
rgb_byte555(void *dst, int rgb)
196
static void rgb_555(void *dst, uint32_t rgb)
208
{
197
{
209
    /* 5-bit, 5-bits, 5-bits */
198
    *((uint16_t *) dst)
210
    *((uint16_t *)(dst)) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 |
199
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
211
        BLUE(rgb, 5);
-
 
212
}
200
}
213
 
201
 
214
/** 16-bit depth (5:5:5) */
-
 
215
static int
-
 
216
byte555_rgb(void *src)
-
 
217
{
-
 
218
    int color = *(uint16_t *)(src);
-
 
219
    return (((color >> 10) & 0x1f) << (16 + 3)) |
-
 
220
        (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3);
-
 
221
}
-
 
222
 
202
 
223
/**  16-bit depth (5:6:5) */
203
/** RGB 5:6:5 conversion
-
 
204
 *
224
static void
205
 */
225
rgb_byte565(void *dst, int rgb)
206
static void rgb_565(void *dst, uint32_t rgb)
226
{
207
{
227
    /* 5-bit, 6-bits, 5-bits */
208
    *((uint16_t *) dst)
228
    *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 |
209
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
229
        BLUE(rgb, 5);
-
 
230
}
210
}
231
 
211
 
232
/** 16-bit depth (5:6:5) */
-
 
233
static int
-
 
234
byte565_rgb(void *src)
-
 
235
{
-
 
236
    int color = *(uint16_t *)(src);
-
 
237
    return (((color >> 11) & 0x1f) << (16 + 3)) |
-
 
238
        (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
-
 
239
}
-
 
240
 
212
 
241
/** Put pixel - 8-bit depth (3:2:3) */
213
/** RGB 3:2:3
-
 
214
 *
242
static void
215
 */
243
rgb_byte8(void *dst, int rgb)
216
static void rgb_323(void *dst, uint32_t rgb)
244
{
217
{
-
 
218
    *((uint8_t *) dst)
245
    *(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
219
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
246
}
220
}
247
 
221
 
248
/** Return pixel color - 8-bit depth (3:2:3) */
-
 
249
static int
-
 
250
byte8_rgb(void *src)
-
 
251
{
-
 
252
    int color = *(uint8_t *)src;
-
 
253
    return (((color >> 5) & 0x7) << (16 + 5)) |
-
 
254
        (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
-
 
255
}
-
 
256
 
222
 
257
/** Put pixel into viewport
223
/** Redraw viewport
-
 
224
 *
-
 
225
 * @param vport Viewport to redraw
258
 *
226
 *
259
 * @param vport Viewport identification
-
 
260
 * @param x X coord relative to viewport
-
 
261
 * @param y Y coord relative to viewport
-
 
262
 * @param color RGB color
-
 
263
 */
227
 */
264
static void
-
 
265
putpixel(viewport_t *vport, unsigned int x, unsigned int y, int color)
228
static void vport_redraw(viewport_t *vport)
266
{
229
{
267
    int dx = vport->x + x;
-
 
268
    int dy = vport->y + y;
230
    unsigned int row;
269
 
231
   
270
    if (! (vport->paused && vport->dbdata))
232
    for (row = 0; row < vport->rows; row++) {
271
        (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],
233
        unsigned int y = vport->y + ROW2Y(row);
272
            COLOR(color));
234
        unsigned int yd;
273
 
235
       
-
 
236
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
274
    if (vport->dbdata) {
237
            unsigned int x;
-
 
238
            unsigned int col;
-
 
239
           
275
        int dline = (y + vport->dboffset) % vport->height;
240
            for (col = 0, x = vport->x; col < vport->cols; col++, x += FONT_WIDTH)
276
        int doffset = screen.pixelbytes * (dline * vport->width + x);
241
                memcpy(&screen.fb_addr[FB_POS(x, y + yd)],
277
        (*screen.rgb2scr)(&vport->dbdata[doffset], COLOR(color));
242
                &vport->glyphs[GLYPH_POS(vport->backbuf[BB_POS(vport, col, row)], yd, false)],
-
 
243
                screen.glyphscanline);
-
 
244
        }
278
    }
245
    }
279
}
246
   
280
 
-
 
281
/** Get pixel from viewport */
247
    if (COL2X(vport->cols) < vport->width) {
282
static int
248
        unsigned int y;
283
getpixel(viewport_t *vport, unsigned int x, unsigned int y)
-
 
284
{
249
       
285
    int dx = vport->x + x;
-
 
286
    int dy = vport->y + y;
250
        for (y = 0; y < vport->height; y++) {
287
 
-
 
288
    return COLOR((*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx, dy)]));
-
 
289
}
-
 
290
 
-
 
291
static inline void
-
 
292
putpixel_mem(char *mem, unsigned int x, unsigned int y, int color)
-
 
293
{
-
 
294
    (*screen.rgb2scr)(&mem[POINTPOS(x, y)], COLOR(color));
-
 
295
}
-
 
296
 
-
 
297
static void
-
 
298
draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy,
-
 
299
    unsigned int width, unsigned int height, int color)
-
 
300
{
-
 
301
    unsigned int x, y;
251
            unsigned int x;
302
    static void *tmpline;
-
 
303
 
-
 
304
    if (!tmpline)
-
 
305
        tmpline = malloc(screen.scanline * screen.pixelbytes);
-
 
306
 
252
           
307
    /* Clear first line */
-
 
308
    for (x = 0; x < width; x++)
253
            for (x = COL2X(vport->cols); x < vport->width; x++)
309
        putpixel_mem(tmpline, x, 0, color);
254
                memcpy(&screen.fb_addr[FB_POS(x, y)], vport->bgpixel, screen.pixelbytes);
310
 
255
        }
311
    if (!vport->paused) {
-
 
312
        /* Recompute to screen coords */
-
 
313
        sx += vport->x;
-
 
314
        sy += vport->y;
-
 
315
        /* Copy the rest */
-
 
316
        for (y = sy;y < sy+height; y++)
-
 
317
            memcpy(&screen.fbaddress[POINTPOS(sx,y)], tmpline,
-
 
318
                screen.pixelbytes * width);
-
 
319
    }
256
    }
-
 
257
   
320
    if (vport->dbdata) {
258
    if (ROW2Y(vport->rows) < vport->height) {
321
        for (y = sy; y < sy + height; y++) {
259
        unsigned int y;
-
 
260
       
322
            int rline = (y + vport->dboffset) % vport->height;
261
        for (y = ROW2Y(vport->rows); y < vport->height; y++) {
323
            int rpos = (rline * vport->width + sx) *
-
 
324
                screen.pixelbytes;
262
            unsigned int x;
-
 
263
           
325
            memcpy(&vport->dbdata[rpos], tmpline,
264
            for (x = 0; x < vport->width; x++)
326
                screen.pixelbytes * width);
265
                memcpy(&screen.fb_addr[FB_POS(x, y)], vport->bgpixel, screen.pixelbytes);
327
        }
266
        }
328
    }
267
    }
329
 
-
 
330
}
268
}
331
 
269
 
332
/** Fill viewport with background color */
-
 
333
static void
-
 
334
clear_port(viewport_t *vport)
-
 
335
{
-
 
336
    draw_rectangle(vport, 0, 0, vport->width, vport->height,
-
 
337
        vport->style.bg_color);
-
 
338
}
-
 
339
 
270
 
-
 
271
/** Clear viewport
-
 
272
 *
340
/** Scroll unbuffered viewport up/down
273
 * @param vport Viewport to clear
341
 *
274
 *
342
 * @param vport Viewport to scroll
-
 
343
 * @param lines Positive number - scroll up, negative - scroll down
-
 
344
 */
275
 */
345
static void
-
 
346
scroll_port_nodb(viewport_t *vport, int lines)
276
static void vport_clear(viewport_t *vport)
347
{
277
{
348
    int y;
-
 
349
 
-
 
350
    if (lines > 0) {
-
 
351
        for (y = vport->y; y < vport->y+vport->height - lines; y++)
-
 
352
            memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
-
 
353
                &screen.fbaddress[POINTPOS(vport->x,y + lines)],
-
 
354
                screen.pixelbytes * vport->width);
-
 
355
        draw_rectangle(vport, 0, vport->height - lines, vport->width,
-
 
356
            lines, vport->style.bg_color);
-
 
357
    } else if (lines < 0) {
-
 
358
        lines = -lines;
-
 
359
        for (y = vport->y + vport->height-1; y >= vport->y + lines; y--)
-
 
360
            memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
-
 
361
                &screen.fbaddress[POINTPOS(vport->x,y - lines)],
-
 
362
                screen.pixelbytes * vport->width);
-
 
363
        draw_rectangle(vport, 0, 0, vport->width, lines,
278
    memset(vport->backbuf, 0, vport->bbsize);
364
            vport->style.bg_color);
279
    vport_redraw(vport);
365
    }
-
 
366
}
280
}
367
 
281
 
368
/** Refresh given viewport from double buffer */
-
 
369
static void
-
 
370
refresh_viewport_db(viewport_t *vport)
-
 
371
{
-
 
372
    unsigned int y, srcy, srcoff, dsty, dstx;
-
 
373
 
-
 
374
    for (y = 0; y < vport->height; y++) {
-
 
375
        srcy = (y + vport->dboffset) % vport->height;
-
 
376
        srcoff = (vport->width * srcy) * screen.pixelbytes;
-
 
377
 
-
 
378
        dstx = vport->x;
-
 
379
        dsty = vport->y + y;
-
 
380
 
-
 
381
        memcpy(&screen.fbaddress[POINTPOS(dstx,dsty)],
-
 
382
            &vport->dbdata[srcoff], vport->width * screen.pixelbytes);
-
 
383
    }
-
 
384
}
-
 
385
 
282
 
386
/** Scroll viewport that has double buffering enabled */
283
/** Scroll viewport by given number of lines
-
 
284
 *
-
 
285
 * @param vport Viewport to scroll
-
 
286
 * @param lines Number of lines to scroll
-
 
287
 *
387
static void
288
 */
388
scroll_port_db(viewport_t *vport, int lines)
289
static void vport_scroll(viewport_t *vport, int lines)
389
{
290
{
390
    ++vport->paused;
-
 
391
    if (lines > 0) {
-
 
392
        draw_rectangle(vport, 0, 0, vport->width, lines,
-
 
393
            vport->style.bg_color);
-
 
394
        vport->dboffset += lines;
-
 
395
        vport->dboffset %= vport->height;
-
 
396
    } else if (lines < 0) {
-
 
397
        lines = -lines;
291
    unsigned int row;
398
        draw_rectangle(vport, 0, vport->height-lines, vport->width,
-
 
399
            lines, vport->style.bg_color);
-
 
400
 
-
 
401
        if (vport->dboffset < lines)
-
 
402
            vport->dboffset += vport->height;
-
 
403
        vport->dboffset -= lines;
-
 
404
    }
-
 
405
   
-
 
406
    --vport->paused;
-
 
407
   
292
   
408
    refresh_viewport_db(vport);
293
    for (row = 0; row < vport->rows; row++) {
-
 
294
        unsigned int y = vport->y + ROW2Y(row);
-
 
295
        unsigned int yd;
409
}
296
       
410
 
-
 
411
/** Scrolls viewport given number of lines */
297
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
-
 
298
            unsigned int x;
412
static void
299
            unsigned int col;
-
 
300
           
413
scroll_port(viewport_t *vport, int lines)
301
            for (col = 0, x = vport->x; col < vport->cols; col++, x += FONT_WIDTH) {
-
 
302
                uint8_t glyph;
414
{
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)])
415
    if (vport->dbdata)
306
                        continue;
-
 
307
                   
416
        scroll_port_db(vport, lines);
308
                    glyph = vport->backbuf[BB_POS(vport, col, row + lines)];
417
    else
309
                } else
-
 
310
                    glyph = 0;
-
 
311
               
418
        scroll_port_nodb(vport, lines);
312
                memcpy(&screen.fb_addr[FB_POS(x, y + yd)],
-
 
313
                    &vport->glyphs[GLYPH_POS(glyph, yd, false)], screen.glyphscanline);
-
 
314
            }
-
 
315
        }
-
 
316
    }
419
   
317
   
-
 
318
    if (lines > 0) {
-
 
319
        memcpy(vport->backbuf, vport->backbuf + vport->cols * lines, vport->cols * (vport->rows - lines));
-
 
320
        memset(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], 0, vport->cols * lines);
-
 
321
    } else {
-
 
322
        memcpy(vport->backbuf - vport->cols * lines, vport->backbuf, vport->cols * (vport->rows + lines));
-
 
323
        memset(vport->backbuf, 0, - vport->cols * lines);
-
 
324
    }
420
}
325
}
421
 
326
 
422
static void
-
 
423
invert_pixel(viewport_t *vport, unsigned int x, unsigned int y)
-
 
424
{
-
 
425
    putpixel(vport, x, y, ~getpixel(vport, x, y));
-
 
426
}
-
 
427
 
-
 
428
 
-
 
429
/***************************************************************/
-
 
430
/* Character-console functions */
-
 
431
 
327
 
-
 
328
/** Render glyphs
-
 
329
 *
-
 
330
 * Convert glyphs from device independent font
-
 
331
 * description to current visual representation.
-
 
332
 *
432
/** Draw character at given position
333
 * @param vport Viewport
433
 *
334
 *
434
 * @param vport Viewport where the character is printed
-
 
435
 * @param sx Coordinates of top-left of the character
-
 
436
 * @param sy Coordinates of top-left of the character
-
 
437
 * @param style Color of the character
-
 
438
 * @param transparent If false, print background color
-
 
439
 */
335
 */
440
static void
-
 
441
draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx, unsigned int sy,
-
 
442
    style_t style, int transparent)
336
static void render_glyphs(viewport_t* vport)
443
{
337
{
444
    int i;
338
    unsigned int glyph;
-
 
339
   
-
 
340
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
445
    unsigned int y;
341
        unsigned int y;
-
 
342
       
-
 
343
        for (y = 0; y < FONT_SCANLINES; y++) {
446
    unsigned int glline;
344
            unsigned int x;
447
 
345
           
448
    for (y = 0; y < FONT_SCANLINES; y++) {
346
            for (x = 0; x < FONT_WIDTH; x++) {
-
 
347
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
449
        glline = fb_font[glyph * FONT_SCANLINES + y];
348
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
-
 
349
                    ? vport->style.fg_color : vport->style.bg_color);
-
 
350
               
450
        for (i = 0; i < 8; i++) {
351
                uint32_t curcolor;
-
 
352
               
451
            if (glline & (1 << (7 - i)))
353
                if (y < FONT_SCANLINES - 2)
-
 
354
                    curcolor =
-
 
355
                        (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
452
                putpixel(vport, sx + i, sy + y, style.fg_color);
356
                        ? vport->style.fg_color : vport->style.bg_color;
453
            else if (!transparent)
357
                else
454
                putpixel(vport, sx + i, sy + y, style.bg_color);
358
                    curcolor = vport->style.fg_color;
-
 
359
               
-
 
360
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], curcolor);
-
 
361
            }
455
        }
362
        }
456
    }
363
    }
-
 
364
   
-
 
365
    screen.rgb_conv(vport->bgpixel, vport->style.bg_color);
457
}
366
}
458
 
367
 
459
/** Invert character at given position */
-
 
460
static void
-
 
461
invert_char(viewport_t *vport,unsigned int row, unsigned int col)
-
 
462
{
-
 
463
    unsigned int x;
-
 
464
    unsigned int y;
-
 
465
 
-
 
466
    for (x = 0; x < COL_WIDTH; x++)
-
 
467
        for (y = 0; y < FONT_SCANLINES; y++)
-
 
468
            invert_pixel(vport, col * COL_WIDTH + x, row *
-
 
469
                FONT_SCANLINES + y);
-
 
470
}
-
 
471
 
-
 
472
/***************************************************************/
-
 
473
/* Stdout specific functions */
-
 
474
 
-
 
475
 
368
 
476
/** Create new viewport
369
/** Create new viewport
477
 *
370
 *
-
 
371
 * @param x      Origin of the viewport (x).
-
 
372
 * @param y      Origin of the viewport (y).
-
 
373
 * @param width  Width of the viewport.
-
 
374
 * @param height Height of the viewport.
-
 
375
 *
478
 * @return New viewport number
376
 * @return New viewport number.
-
 
377
 *
479
 */
378
 */
480
static int
-
 
481
viewport_create(unsigned int x, unsigned int y,unsigned int width,
379
static int vport_create(unsigned int x, unsigned int y,
482
    unsigned int height)
380
    unsigned int width, unsigned int height)
483
{
381
{
484
    int i;
382
    unsigned int i;
485
 
383
   
486
    for (i = 0; i < MAX_VIEWPORTS; i++) {
384
    for (i = 0; i < MAX_VIEWPORTS; i++) {
487
        if (!viewports[i].initialized)
385
        if (!viewports[i].initialized)
488
            break;
386
            break;
489
    }
387
    }
490
    if (i == MAX_VIEWPORTS)
388
    if (i == MAX_VIEWPORTS)
491
        return ELIMIT;
389
        return ELIMIT;
492
 
390
   
-
 
391
    unsigned int cols = width / FONT_WIDTH;
-
 
392
    unsigned int rows = height / FONT_SCANLINES;
-
 
393
    unsigned int bbsize = cols * rows;
-
 
394
    unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
-
 
395
   
-
 
396
    uint8_t *backbuf = (uint8_t *) malloc(bbsize);
-
 
397
    if (!backbuf)
-
 
398
        return ENOMEM;
-
 
399
   
-
 
400
    uint8_t *glyphs = (uint8_t *) malloc(glyphsize);
-
 
401
    if (!glyphs) {
-
 
402
        free(backbuf);
-
 
403
        return ENOMEM;
-
 
404
    }
-
 
405
   
-
 
406
    uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes);
-
 
407
    if (!bgpixel) {
-
 
408
        free(glyphs);
-
 
409
        free(backbuf);
-
 
410
        return ENOMEM;
-
 
411
    }
-
 
412
   
-
 
413
    memset(backbuf, 0, bbsize);
-
 
414
    memset(glyphs, 0, glyphsize);
-
 
415
    memset(bgpixel, 0, screen.pixelbytes);
-
 
416
   
493
    viewports[i].x = x;
417
    viewports[i].x = x;
494
    viewports[i].y = y;
418
    viewports[i].y = y;
495
    viewports[i].width = width;
419
    viewports[i].width = width;
496
    viewports[i].height = height;
420
    viewports[i].height = height;
497
   
421
   
498
    viewports[i].rows = height / FONT_SCANLINES;
422
    viewports[i].cols = cols;
499
    viewports[i].cols = width / COL_WIDTH;
423
    viewports[i].rows = rows;
500
 
424
   
501
    viewports[i].style.bg_color = DEFAULT_BGCOLOR;
425
    viewports[i].style.bg_color = DEFAULT_BGCOLOR;
502
    viewports[i].style.fg_color = DEFAULT_FGCOLOR;
426
    viewports[i].style.fg_color = DEFAULT_FGCOLOR;
503
   
427
   
-
 
428
    viewports[i].glyphs = glyphs;
-
 
429
    viewports[i].bgpixel = bgpixel;
-
 
430
   
504
    viewports[i].cur_col = 0;
431
    viewports[i].cur_col = 0;
505
    viewports[i].cur_row = 0;
432
    viewports[i].cur_row = 0;
506
    viewports[i].cursor_active = 0;
433
    viewports[i].cursor_active = false;
-
 
434
    viewports[i].cursor_shown = false;
-
 
435
   
-
 
436
    viewports[i].bbsize = bbsize;
-
 
437
    viewports[i].backbuf = backbuf;
507
 
438
   
508
    viewports[i].initialized = 1;
439
    viewports[i].initialized = true;
-
 
440
   
-
 
441
    render_glyphs(&viewports[i]);
509
 
442
   
510
    return i;
443
    return i;
511
}
444
}
512
 
445
 
-
 
446
 
513
/** Initialize framebuffer as a chardev output device
447
/** Initialize framebuffer as a chardev output device
514
 *
448
 *
515
 * @param addr          Address of theframebuffer
449
 * @param addr   Address of the framebuffer
516
 * @param xres          Screen width in pixels
450
 * @param xres   Screen width in pixels
517
 * @param yres          Screen height in pixels
451
 * @param yres   Screen height in pixels
518
 * @param visual        Bits per pixel (8, 16, 24, 32)
452
 * @param visual Bits per pixel (8, 16, 24, 32)
519
 * @param scan          Bytes per one scanline
453
 * @param scan   Bytes per one scanline
520
 * @param invert_colors Inverted colors.
-
 
521
 *
454
 *
522
 */
455
 */
523
static bool
-
 
524
screen_init(void *addr, unsigned int xres, unsigned int yres,
456
static bool screen_init(void *addr, unsigned int xres, unsigned int yres,
525
    unsigned int scan, unsigned int visual, bool invert_colors)
457
    unsigned int scan, unsigned int visual)
526
{
458
{
527
    switch (visual) {
459
    switch (visual) {
528
    case VISUAL_INDIRECT_8:
460
    case VISUAL_INDIRECT_8:
529
        screen.rgb2scr = rgb_byte8;
461
        screen.rgb_conv = rgb_323;
530
        screen.scr2rgb = byte8_rgb;
-
 
531
        screen.pixelbytes = 1;
462
        screen.pixelbytes = 1;
532
        break;
463
        break;
533
    case VISUAL_RGB_5_5_5:
464
    case VISUAL_RGB_5_5_5:
534
        screen.rgb2scr = rgb_byte555;
465
        screen.rgb_conv = rgb_555;
535
        screen.scr2rgb = byte555_rgb;
-
 
536
        screen.pixelbytes = 2;
466
        screen.pixelbytes = 2;
537
        break;
467
        break;
538
    case VISUAL_RGB_5_6_5:
468
    case VISUAL_RGB_5_6_5:
539
        screen.rgb2scr = rgb_byte565;
469
        screen.rgb_conv = rgb_565;
540
        screen.scr2rgb = byte565_rgb;
-
 
541
        screen.pixelbytes = 2;
470
        screen.pixelbytes = 2;
542
        break;
471
        break;
543
    case VISUAL_RGB_8_8_8:
472
    case VISUAL_RGB_8_8_8:
544
        screen.rgb2scr = rgb_byte888;
473
        screen.rgb_conv = rgb_888;
545
        screen.scr2rgb = byte888_rgb;
-
 
546
        screen.pixelbytes = 3;
474
        screen.pixelbytes = 3;
547
        break;
475
        break;
548
    case VISUAL_RGB_8_8_8_0:
476
    case VISUAL_RGB_8_8_8_0:
549
        screen.rgb2scr = rgb_byte888;
477
        screen.rgb_conv = rgb_888;
550
        screen.scr2rgb = byte888_rgb;
-
 
551
        screen.pixelbytes = 4;
478
        screen.pixelbytes = 4;
552
        break;
479
        break;
553
    case VISUAL_RGB_0_8_8_8:
480
    case VISUAL_RGB_0_8_8_8:
554
        screen.rgb2scr = rgb_byte0888;
481
        screen.rgb_conv = rgb_0888;
555
        screen.scr2rgb = byte0888_rgb;
-
 
556
        screen.pixelbytes = 4;
482
        screen.pixelbytes = 4;
557
        break;
483
        break;
558
    case VISUAL_BGR_0_8_8_8:
484
    case VISUAL_BGR_0_8_8_8:
559
        screen.rgb2scr = bgr_byte0888;
485
        screen.rgb_conv = bgr_0888;
560
        screen.scr2rgb = byte0888_bgr;
-
 
561
        screen.pixelbytes = 4;
486
        screen.pixelbytes = 4;
562
        break;
487
        break;
563
    default:
488
    default:
564
        return false;
489
        return false;
565
    }
490
    }
566
 
491
 
567
    screen.fbaddress = (unsigned char *) addr;
492
    screen.fb_addr = (unsigned char *) addr;
568
    screen.xres = xres;
493
    screen.xres = xres;
569
    screen.yres = yres;
494
    screen.yres = yres;
570
    screen.scanline = scan;
495
    screen.scanline = scan;
-
 
496
   
571
    screen.invert_colors = invert_colors;
497
    screen.glyphscanline = FONT_WIDTH * screen.pixelbytes;
-
 
498
    screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES;
572
   
499
   
573
    /* Create first viewport */
500
    /* Create first viewport */
574
    viewport_create(0, 0, xres, yres);
501
    vport_create(0, 0, xres, yres);
575
   
502
   
576
    return true;
503
    return true;
577
}
504
}
578
 
505
 
-
 
506
 
-
 
507
/** Draw glyph at given position relative to viewport
-
 
508
 *
-
 
509
 * @param vport  Viewport identification
-
 
510
 * @param cursor Draw glyph with cursor
-
 
511
 * @param col    Screen position relative to viewport
-
 
512
 * @param row    Screen position relative to viewport
-
 
513
 *
-
 
514
 */
-
 
515
static void draw_glyph(viewport_t *vport, bool cursor, unsigned int col, unsigned int row)
-
 
516
{
-
 
517
    unsigned int x = vport->x + COL2X(col);
-
 
518
    unsigned int y = vport->y + ROW2Y(row);
-
 
519
    unsigned int yd;
-
 
520
   
-
 
521
    uint8_t 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
 
-
 
528
 
579
/** Hide cursor if it is shown */
529
/** Hide cursor if it is shown
-
 
530
 *
580
static void
531
 */
581
cursor_hide(viewport_t *vport)
532
static void cursor_hide(viewport_t *vport)
582
{
533
{
583
    if (vport->cursor_active && vport->cursor_shown) {
534
    if ((vport->cursor_active) && (vport->cursor_shown)) {
584
        invert_char(vport, vport->cur_row, vport->cur_col);
535
        draw_glyph(vport, false, vport->cur_col, vport->cur_row);
585
        vport->cursor_shown = 0;
536
        vport->cursor_shown = false;
586
    }
537
    }
587
}
538
}
588
 
539
 
-
 
540
 
589
/** Show cursor if cursor showing is enabled */
541
/** Show cursor if cursor showing is enabled
-
 
542
 *
590
static void
543
 */
591
cursor_print(viewport_t *vport)
544
static void cursor_show(viewport_t *vport)
592
{
545
{
593
    /* Do not check for cursor_shown */
546
    /* Do not check for cursor_shown */
594
    if (vport->cursor_active) {
547
    if (vport->cursor_active) {
595
        invert_char(vport, vport->cur_row, vport->cur_col);
548
        draw_glyph(vport, true, vport->cur_col, vport->cur_row);
596
        vport->cursor_shown = 1;
549
        vport->cursor_shown = true;
597
    }
550
    }
598
}
551
}
599
 
552
 
-
 
553
 
600
/** Invert cursor, if it is enabled */
554
/** Invert cursor, if it is enabled
-
 
555
 *
601
static void
556
 */
602
cursor_blink(viewport_t *vport)
557
static void cursor_blink(viewport_t *vport)
603
{
558
{
604
    if (vport->cursor_shown)
559
    if (vport->cursor_shown)
605
        cursor_hide(vport);
560
        cursor_hide(vport);
606
    else
561
    else
607
        cursor_print(vport);
562
        cursor_show(vport);
608
}
563
}
609
 
564
 
610
/** Draw character at given position relative to viewport
-
 
611
 *
-
 
612
 * @param vport Viewport identification
-
 
613
 * @param c Character to print
-
 
614
 * @param row Screen position relative to viewport
-
 
615
 * @param col Screen position relative to viewport
-
 
616
 * @param transparent If false, print background color with character
-
 
617
 */
-
 
618
static void
-
 
619
draw_char(viewport_t *vport, char c, unsigned int row, unsigned int col,
-
 
620
    style_t style, int transparent)
-
 
621
{
-
 
622
    /* Optimize - do not hide cursor if we are going to overwrite it */
-
 
623
    if (vport->cursor_active && vport->cursor_shown &&
-
 
624
        (vport->cur_col != col || vport->cur_row != row))
-
 
625
        invert_char(vport, vport->cur_row, vport->cur_col);
-
 
626
   
-
 
627
    draw_glyph(vport, c, col * COL_WIDTH, row * FONT_SCANLINES, style,
-
 
628
        transparent);
-
 
629
 
565
 
-
 
566
/** Draw character at given position relative to viewport
-
 
567
 *
-
 
568
 * @param vport  Viewport identification
-
 
569
 * @param c      Character to draw
-
 
570
 * @param col    Screen position relative to viewport
-
 
571
 * @param row    Screen position relative to viewport
-
 
572
 *
-
 
573
 */
-
 
574
static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row)
-
 
575
{
-
 
576
    /* Do not hide cursor if we are going to overwrite it */
-
 
577
    if ((vport->cursor_active) && (vport->cursor_shown) &&
-
 
578
        ((vport->cur_col != col) || (vport->cur_row != row)))
-
 
579
        cursor_hide(vport);
-
 
580
   
-
 
581
    vport->backbuf[BB_POS(vport, col, row)] = c;
-
 
582
    draw_glyph(vport, false, col, row);
-
 
583
   
630
    vport->cur_col = col;
584
    vport->cur_col = col;
631
    vport->cur_row = row;
585
    vport->cur_row = row;
632
 
586
   
633
    vport->cur_col++;
587
    vport->cur_col++;
634
    if (vport->cur_col >= vport->cols) {
588
    if (vport->cur_col >= vport->cols) {
635
        vport->cur_col = 0;
589
        vport->cur_col = 0;
636
        vport->cur_row++;
590
        vport->cur_row++;
637
        if (vport->cur_row >= vport->rows)
591
        if (vport->cur_row >= vport->rows)
638
            vport->cur_row--;
592
            vport->cur_row--;
639
    }
593
    }
-
 
594
   
640
    cursor_print(vport);
595
    cursor_show(vport);
641
}
596
}
642
 
597
 
-
 
598
 
643
/** Draw text data to viewport
599
/** Draw text data to viewport
644
 *
600
 *
645
 * @param vport Viewport id
601
 * @param vport Viewport id
646
 * @param data Text data fitting exactly into viewport
602
 * @param data  Text data fitting exactly into viewport
-
 
603
 *
647
 */
604
 */
648
static void
-
 
649
draw_text_data(viewport_t *vport, keyfield_t *data)
605
static void draw_text_data(viewport_t *vport, keyfield_t *data)
650
{
606
{
651
    int i;
607
    unsigned int i;
652
    int col,row;
-
 
653
 
608
   
654
    clear_port(vport);
-
 
655
    for (i = 0; i < vport->cols * vport->rows; i++) {
609
    for (i = 0; i < vport->cols * vport->rows; i++) {
656
        if (data[i].character == ' ' && style_same(data[i].style,
610
        unsigned int col = i % vport->cols;
657
            vport->style))
611
        unsigned int row = i / vport->cols;
658
            continue;
612
       
659
        col = i % vport->cols;
613
        uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)];
-
 
614
       
660
        row = i / vport->cols;
615
        // TODO: use data[i].style
-
 
616
       
661
        draw_glyph(vport, data[i].character, col * COL_WIDTH, row *
617
        if (glyph != data[i].character) {
662
            FONT_SCANLINES, data[i].style, style_same(data[i].style,
618
            vport->backbuf[BB_POS(vport, col, row)] = data[i].character;
663
            vport->style));
619
            draw_glyph(vport, false, col, row);
-
 
620
        }
664
    }
621
    }
665
    cursor_print(vport);
622
    cursor_show(vport);
666
}
623
}
667
 
624
 
668
/** Return first free pixmap */
-
 
669
static int
625
 
670
find_free_pixmap(void)
626
static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color)
671
{
627
{
672
    int i;
628
    int pm = *((int *) data);
-
 
629
    pixmap_t *pmap = &pixmaps[pm];
-
 
630
    unsigned int pos = (y * pmap->width + x) * screen.pixelbytes;
673
   
631
   
674
    for (i = 0;i < MAX_PIXMAPS;i++)
632
    screen.rgb_conv(&pmap->data[pos], color);
675
        if (!pixmaps[i].data)
-
 
676
            return i;
-
 
677
    return -1;
-
 
678
}
633
}
679
 
634
 
680
static void
635
 
681
putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color)
636
static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color)
682
{
637
{
-
 
638
    viewport_t *vport = (viewport_t *) data;
-
 
639
    unsigned int dx = vport->x + x;
683
    pixmap_t *pmap = &pixmaps[pm];
640
    unsigned int dy = vport->y + y;
-
 
641
   
684
    int pos = (y * pmap->width + x) * screen.pixelbytes;
642
    screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color);
-
 
643
}
685
 
644
 
-
 
645
 
-
 
646
/** Return first free pixmap
-
 
647
 *
-
 
648
 */
686
    (*screen.rgb2scr)(&pmap->data[pos],COLOR(color));
649
static int find_free_pixmap(void)
-
 
650
{
-
 
651
    unsigned int i;
-
 
652
   
-
 
653
    for (i = 0; i < MAX_PIXMAPS; i++)
-
 
654
        if (!pixmaps[i].data)
-
 
655
            return i;
-
 
656
   
-
 
657
    return -1;
687
}
658
}
688
 
659
 
-
 
660
 
689
/** Create a new pixmap and return appropriate ID */
661
/** Create a new pixmap and return appropriate ID
-
 
662
 *
690
static int
663
 */
691
shm2pixmap(unsigned char *shm, size_t size)
664
static int shm2pixmap(unsigned char *shm, size_t size)
692
{
665
{
693
    int pm;
666
    int pm;
694
    pixmap_t *pmap;
667
    pixmap_t *pmap;
695
 
668
   
696
    pm = find_free_pixmap();
669
    pm = find_free_pixmap();
697
    if (pm == -1)
670
    if (pm == -1)
698
        return ELIMIT;
671
        return ELIMIT;
-
 
672
   
699
    pmap = &pixmaps[pm];
673
    pmap = &pixmaps[pm];
700
   
674
   
701
    if (ppm_get_data(shm, size, &pmap->width, &pmap->height))
675
    if (ppm_get_data(shm, size, &pmap->width, &pmap->height))
702
        return EINVAL;
676
        return EINVAL;
703
   
677
   
704
    pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes);
678
    pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes);
705
    if (!pmap->data)
679
    if (!pmap->data)
706
        return ENOMEM;
680
        return ENOMEM;
707
 
681
   
708
    ppm_draw(shm, size, 0, 0, pmap->width, pmap->height,
682
    ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm);
709
        (putpixel_cb_t)putpixel_pixmap, (void *)pm);
-
 
710
 
683
   
711
    return pm;
684
    return pm;
712
}
685
}
713
 
686
 
-
 
687
 
714
/** Handle shared memory communication calls
688
/** Handle shared memory communication calls
715
 *
689
 *
716
 * Protocol for drawing pixmaps:
690
 * Protocol for drawing pixmaps:
717
 * - FB_PREPARE_SHM(client shm identification)
691
 * - FB_PREPARE_SHM(client shm identification)
718
 * - IPC_M_AS_AREA_SEND
692
 * - IPC_M_AS_AREA_SEND
719
 * - FB_DRAW_PPM(startx,starty)
693
 * - FB_DRAW_PPM(startx, starty)
720
 * - FB_DROP_SHM
694
 * - FB_DROP_SHM
721
 *
695
 *
722
 * Protocol for text drawing
696
 * Protocol for text drawing
723
 * - IPC_M_AS_AREA_SEND
697
 * - IPC_M_AS_AREA_SEND
724
 * - FB_DRAW_TEXT_DATA
698
 * - FB_DRAW_TEXT_DATA
725
 *
699
 *
726
 * @param callid Callid of the current call
700
 * @param callid Callid of the current call
727
 * @param call Current call data
701
 * @param call   Current call data
728
 * @param vp Active viewport
702
 * @param vp     Active viewport
-
 
703
 *
729
 * @return 0 if the call was not handled byt this function, 1 otherwise
704
 * @return false if the call was not handled byt this function, true otherwise
730
 *
705
 *
731
 * note: this function is not threads safe, you would have
706
 * Note: this function is not threads safe, you would have
732
 * to redefine static variables with __thread
707
 * to redefine static variables with __thread
-
 
708
 *
733
 */
709
 */
734
static int
-
 
735
shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
710
static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
736
{
711
{
737
    static keyfield_t *interbuffer = NULL;
712
    static keyfield_t *interbuffer = NULL;
738
    static size_t intersize = 0;
713
    static size_t intersize = 0;
739
 
714
   
740
    static unsigned char *shm = NULL;
715
    static unsigned char *shm = NULL;
741
    static ipcarg_t shm_id = 0;
716
    static ipcarg_t shm_id = 0;
742
    static size_t shm_size;
717
    static size_t shm_size;
743
 
718
   
744
    int handled = 1;
719
    bool handled = true;
745
    int retval = 0;
720
    int retval = EOK;
746
    viewport_t *vport = &viewports[vp];
721
    viewport_t *vport = &viewports[vp];
-
 
722
    unsigned int x;
747
    unsigned int x, y;
723
    unsigned int y;
748
 
724
   
749
    switch (IPC_GET_METHOD(*call)) {
725
    switch (IPC_GET_METHOD(*call)) {
750
    case IPC_M_SHARE_OUT:
726
    case IPC_M_SHARE_OUT:
751
        /* We accept one area for data interchange */
727
        /* We accept one area for data interchange */
752
        if (IPC_GET_ARG1(*call) == shm_id) {
728
        if (IPC_GET_ARG1(*call) == shm_id) {
753
            void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
729
            void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
754
            shm_size = IPC_GET_ARG2(*call);
730
            shm_size = IPC_GET_ARG2(*call);
755
            if (!ipc_answer_1(callid, EOK, (sysarg_t) dest))
731
            if (!ipc_answer_1(callid, EOK, (sysarg_t) dest))
756
                shm = dest;
732
                shm = dest;
757
            else
733
            else
758
                shm_id = 0;
734
                shm_id = 0;
-
 
735
           
759
            if (shm[0] != 'P')
736
            if (shm[0] != 'P')
760
                while (1)
737
                return false;
761
                    ;
738
           
762
            return 1;
739
            return true;
763
        } else {
740
        } else {
764
            intersize = IPC_GET_ARG2(*call);
741
            intersize = IPC_GET_ARG2(*call);
765
            receive_comm_area(callid, call, (void *) &interbuffer);
742
            receive_comm_area(callid, call, (void *) &interbuffer);
766
        }
743
        }
767
        return 1;
744
        return true;
768
    case FB_PREPARE_SHM:
745
    case FB_PREPARE_SHM:
769
        if (shm_id)
746
        if (shm_id)
770
            retval = EBUSY;
747
            retval = EBUSY;
771
        else
748
        else
772
            shm_id = IPC_GET_ARG1(*call);
749
            shm_id = IPC_GET_ARG1(*call);
Line 777... Line 754...
777
            as_area_destroy(shm);
754
            as_area_destroy(shm);
778
            shm = NULL;
755
            shm = NULL;
779
        }
756
        }
780
        shm_id = 0;
757
        shm_id = 0;
781
        break;
758
        break;
782
 
759
       
783
    case FB_SHM2PIXMAP:
760
    case FB_SHM2PIXMAP:
784
        if (!shm) {
761
        if (!shm) {
785
            retval = EINVAL;
762
            retval = EINVAL;
786
            break;
763
            break;
787
        }
764
        }
Line 792... Line 769...
792
            retval = EINVAL;
769
            retval = EINVAL;
793
            break;
770
            break;
794
        }
771
        }
795
        x = IPC_GET_ARG1(*call);
772
        x = IPC_GET_ARG1(*call);
796
        y = IPC_GET_ARG2(*call);
773
        y = IPC_GET_ARG2(*call);
-
 
774
       
797
        if (x > vport->width || y > vport->height) {
775
        if ((x > vport->width) || (y > vport->height)) {
798
            retval = EINVAL;
776
            retval = EINVAL;
799
            break;
777
            break;
800
        }
778
        }
801
       
779
       
802
        ppm_draw(shm, shm_size, IPC_GET_ARG1(*call),
780
        ppm_draw(shm, shm_size, IPC_GET_ARG1(*call),
803
            IPC_GET_ARG2(*call), vport->width - x, vport->height - y,
781
            IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport);
804
            (putpixel_cb_t)putpixel, vport);
-
 
805
        break;
782
        break;
806
    case FB_DRAW_TEXT_DATA:
783
    case FB_DRAW_TEXT_DATA:
807
        if (!interbuffer) {
784
        if (!interbuffer) {
808
            retval = EINVAL;
785
            retval = EINVAL;
809
            break;
786
            break;
810
        }
787
        }
811
        if (intersize < vport->cols * vport->rows *
788
        if (intersize < vport->cols * vport->rows * sizeof(*interbuffer)) {
812
            sizeof(*interbuffer)) {
-
 
813
            retval = EINVAL;
789
            retval = EINVAL;
814
            break;
790
            break;
815
        }
791
        }
816
        draw_text_data(vport, interbuffer);
792
        draw_text_data(vport, interbuffer);
817
        break;
793
        break;
818
    default:
794
    default:
819
        handled = 0;
795
        handled = false;
820
    }
796
    }
821
   
797
   
822
    if (handled)
798
    if (handled)
823
        ipc_answer_0(callid, retval);
799
        ipc_answer_0(callid, retval);
824
    return handled;
800
    return handled;
825
}
801
}
826
 
802
 
827
static void
-
 
828
copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
-
 
829
{
-
 
830
    int y;
-
 
831
    int tmp, srcrowsize;
-
 
832
    int realwidth, realheight, realrowsize;
-
 
833
    int width = vport->width;
-
 
834
    int height = vport->height;
-
 
835
 
803
 
-
 
804
static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
-
 
805
{
-
 
806
    unsigned int width = vport->width;
-
 
807
    unsigned int height = vport->height;
-
 
808
   
836
    if (width + vport->x > screen.xres)
809
    if (width + vport->x > screen.xres)
837
        width = screen.xres - vport->x;
810
        width = screen.xres - vport->x;
838
    if (height + vport->y > screen.yres)
811
    if (height + vport->y > screen.yres)
839
        height = screen.yres - vport->y;
812
        height = screen.yres - vport->y;
840
   
813
   
841
    realwidth = pmap->width <= width ? pmap->width : width;
814
    unsigned int realwidth = pmap->width <= width ? pmap->width : width;
842
    realheight = pmap->height <= height ? pmap->height : height;
815
    unsigned int realheight = pmap->height <= height ? pmap->height : height;
843
 
-
 
844
    srcrowsize = vport->width * screen.pixelbytes;
-
 
845
    realrowsize = realwidth * screen.pixelbytes;
-
 
846
   
816
   
-
 
817
    unsigned int srcrowsize = vport->width * screen.pixelbytes;
-
 
818
    unsigned int realrowsize = realwidth * screen.pixelbytes;
-
 
819
   
-
 
820
    unsigned int y;
847
    for (y = 0; y < realheight; y++) {
821
    for (y = 0; y < realheight; y++) {
848
        tmp = (vport->y + y) * screen.scanline +
822
        unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
849
            vport->x * screen.pixelbytes;
-
 
850
        memcpy(pmap->data + srcrowsize * y, screen.fbaddress + tmp,
823
        memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize);
851
            realrowsize);
-
 
852
    }
824
    }
853
}
825
}
854
 
826
 
-
 
827
 
855
/** Save viewport to pixmap */
828
/** Save viewport to pixmap
-
 
829
 *
856
static int
830
 */
857
save_vp_to_pixmap(viewport_t *vport)
831
static int save_vp_to_pixmap(viewport_t *vport)
858
{
832
{
859
    int pm;
833
    int pm;
860
    pixmap_t *pmap;
834
    pixmap_t *pmap;
861
 
835
   
862
    pm = find_free_pixmap();
836
    pm = find_free_pixmap();
863
    if (pm == -1)
837
    if (pm == -1)
864
        return ELIMIT;
838
        return ELIMIT;
865
   
839
   
866
    pmap = &pixmaps[pm];
840
    pmap = &pixmaps[pm];
867
    pmap->data = malloc(screen.pixelbytes * vport->width * vport->height);
841
    pmap->data = malloc(screen.pixelbytes * vport->width * vport->height);
868
    if (!pmap->data)
842
    if (!pmap->data)
869
        return ENOMEM;
843
        return ENOMEM;
870
 
844
   
871
    pmap->width = vport->width;
845
    pmap->width = vport->width;
872
    pmap->height = vport->height;
846
    pmap->height = vport->height;
873
 
847
   
874
    copy_vp_to_pixmap(vport, pmap);
848
    copy_vp_to_pixmap(vport, pmap);
875
   
849
   
876
    return pm;
850
    return pm;
877
}
851
}
878
 
852
 
-
 
853
 
879
/** Draw pixmap on screen
854
/** Draw pixmap on screen
880
 *
855
 *
881
 * @param vp Viewport to draw on
856
 * @param vp Viewport to draw on
882
 * @param pm Pixmap identifier
857
 * @param pm Pixmap identifier
-
 
858
 *
883
 */
859
 */
884
static int draw_pixmap(int vp, int pm)
860
static int draw_pixmap(int vp, int pm)
885
{
861
{
886
    pixmap_t *pmap = &pixmaps[pm];
862
    pixmap_t *pmap = &pixmaps[pm];
887
    viewport_t *vport = &viewports[vp];
863
    viewport_t *vport = &viewports[vp];
888
    int y;
864
   
889
    int tmp, srcrowsize;
-
 
890
    int realwidth, realheight, realrowsize;
-
 
891
    int width = vport->width;
865
    unsigned int width = vport->width;
892
    int height = vport->height;
866
    unsigned int height = vport->height;
893
 
867
   
894
    if (width + vport->x > screen.xres)
868
    if (width + vport->x > screen.xres)
895
        width = screen.xres - vport->x;
869
        width = screen.xres - vport->x;
896
    if (height + vport->y > screen.yres)
870
    if (height + vport->y > screen.yres)
897
        height = screen.yres - vport->y;
871
        height = screen.yres - vport->y;
898
 
872
   
899
    if (!pmap->data)
873
    if (!pmap->data)
900
        return EINVAL;
874
        return EINVAL;
901
 
875
   
902
    realwidth = pmap->width <= width ? pmap->width : width;
876
    unsigned int realwidth = pmap->width <= width ? pmap->width : width;
903
    realheight = pmap->height <= height ? pmap->height : height;
877
    unsigned int realheight = pmap->height <= height ? pmap->height : height;
904
 
878
   
905
    srcrowsize = vport->width * screen.pixelbytes;
879
    unsigned int srcrowsize = vport->width * screen.pixelbytes;
906
    realrowsize = realwidth * screen.pixelbytes;
880
    unsigned int realrowsize = realwidth * screen.pixelbytes;
907
 
881
   
-
 
882
    unsigned int y;
908
    for (y = 0; y < realheight; y++) {
883
    for (y = 0; y < realheight; y++) {
909
        tmp = (vport->y + y) * screen.scanline +
884
        unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
910
            vport->x * screen.pixelbytes;
-
 
911
        memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize,
885
        memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize);
912
            realrowsize);
-
 
913
    }
886
    }
-
 
887
   
914
    return 0;
888
    return EOK;
915
}
889
}
916
 
890
 
-
 
891
 
917
/** Tick animation one step forward */
892
/** Tick animation one step forward
-
 
893
 *
918
static void
894
 */
919
anims_tick(void)
895
static void anims_tick(void)
920
{
896
{
921
    int i;
897
    unsigned int i;
922
    static int counts = 0;
898
    static int counts = 0;
923
   
899
   
924
    /* Limit redrawing */
900
    /* Limit redrawing */
925
    counts = (counts + 1) % 8;
901
    counts = (counts + 1) % 8;
926
    if (counts)
902
    if (counts)
927
        return;
903
        return;
928
 
904
 
929
    for (i = 0; i < MAX_ANIMATIONS; i++) {
905
    for (i = 0; i < MAX_ANIMATIONS; i++) {
930
        if (!animations[i].animlen || !animations[i].initialized ||
906
        if ((!animations[i].animlen) || (!animations[i].initialized) ||
931
            !animations[i].enabled)
907
            (!animations[i].enabled))
932
            continue;
908
            continue;
933
        draw_pixmap(animations[i].vp,
909
       
934
            animations[i].pixmaps[animations[i].pos]);
910
        draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]);
935
        animations[i].pos = (animations[i].pos + 1) %
911
        animations[i].pos = (animations[i].pos + 1) % animations[i].animlen;
936
            animations[i].animlen;
-
 
937
    }
912
    }
938
}
913
}
939
 
914
 
940
 
915
 
-
 
916
static unsigned int pointer_x;
941
static int pointer_x, pointer_y;
917
static unsigned int pointer_y;
942
static int pointer_shown, pointer_enabled;
918
static bool pointer_shown, pointer_enabled;
943
static int pointer_vport = -1;
919
static int pointer_vport = -1;
944
static int pointer_pixmap = -1;
920
static int pointer_pixmap = -1;
945
 
921
 
946
static void
922
 
947
mouse_show(void)
923
static void mouse_show(void)
948
{
924
{
949
    int i, j;
925
    int i, j;
950
    int visibility;
926
    int visibility;
951
    int color;
927
    int color;
952
    int bytepos;
928
    int bytepos;
953
 
929
   
954
    if (pointer_shown || !pointer_enabled)
930
    if ((pointer_shown) || (!pointer_enabled))
955
        return;
931
        return;
956
 
932
   
957
    /* Save image under the cursor */
933
    /* Save image under the cursor */
958
    if (pointer_vport == -1) {
934
    if (pointer_vport == -1) {
959
        pointer_vport = viewport_create(pointer_x, pointer_y,
935
        pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height);
960
            pointer_width, pointer_height);
-
 
961
        if (pointer_vport < 0)
936
        if (pointer_vport < 0)
962
            return;
937
            return;
963
    } else {
938
    } else {
964
        viewports[pointer_vport].x = pointer_x;
939
        viewports[pointer_vport].x = pointer_x;
965
        viewports[pointer_vport].y = pointer_y;
940
        viewports[pointer_vport].y = pointer_y;
966
    }
941
    }
967
 
942
   
968
    if (pointer_pixmap == -1)
943
    if (pointer_pixmap == -1)
969
        pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]);
944
        pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]);
970
    else
945
    else
971
        copy_vp_to_pixmap(&viewports[pointer_vport],
946
        copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]);
972
            &pixmaps[pointer_pixmap]);
-
 
973
 
947
   
974
    /* Draw cursor */
948
    /* Draw cursor */
975
    for (i = 0; i < pointer_height; i++)
949
    for (i = 0; i < pointer_height; i++)
976
        for (j = 0; j < pointer_width; j++) {
950
        for (j = 0; j < pointer_width; j++) {
977
            bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8;
951
            bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8;
978
            visibility = pointer_mask_bits[bytepos] &
952
            visibility = pointer_mask_bits[bytepos] &
Line 987... Line 961...
987
            }
961
            }
988
        }
962
        }
989
    pointer_shown = 1;
963
    pointer_shown = 1;
990
}
964
}
991
 
965
 
992
static void
966
 
993
mouse_hide(void)
967
static void mouse_hide(void)
994
{
968
{
995
    /* Restore image under the cursor */
969
    /* Restore image under the cursor */
996
    if (pointer_shown) {
970
    if (pointer_shown) {
997
        draw_pixmap(pointer_vport, pointer_pixmap);
971
        draw_pixmap(pointer_vport, pointer_pixmap);
998
        pointer_shown = 0;
972
        pointer_shown = 0;
999
    }
973
    }
1000
}
974
}
1001
 
975
 
1002
static void
976
 
1003
mouse_move(unsigned int x, unsigned int y)
977
static void mouse_move(unsigned int x, unsigned int y)
1004
{
978
{
1005
    mouse_hide();
979
    mouse_hide();
1006
    pointer_x = x;
980
    pointer_x = x;
1007
    pointer_y = y;
981
    pointer_y = y;
1008
    mouse_show();
982
    mouse_show();
1009
}
983
}
1010
 
984
 
1011
static int
985
 
1012
anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
986
static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
1013
{
987
{
1014
    int handled = 1;
988
    bool handled = true;
1015
    int retval = 0;
989
    int retval = EOK;
1016
    int i,nvp;
990
    int i, nvp;
1017
    int newval;
991
    int newval;
1018
 
992
   
1019
    switch (IPC_GET_METHOD(*call)) {
993
    switch (IPC_GET_METHOD(*call)) {
1020
    case FB_ANIM_CREATE:
994
    case FB_ANIM_CREATE:
1021
        nvp = IPC_GET_ARG1(*call);
995
        nvp = IPC_GET_ARG1(*call);
1022
        if (nvp == -1)
996
        if (nvp == -1)
1023
            nvp = vp;
997
            nvp = vp;
Line 1103... Line 1077...
1103
    if (handled)
1077
    if (handled)
1104
        ipc_answer_0(callid, retval);
1078
        ipc_answer_0(callid, retval);
1105
    return handled;
1079
    return handled;
1106
}
1080
}
1107
 
1081
 
1108
/** Handler for messages concerning pixmap handling */
-
 
1109
static int
-
 
1110
pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
-
 
1111
{
-
 
1112
    int handled = 1;
-
 
1113
    int retval = 0;
-
 
1114
    int i,nvp;
-
 
1115
 
1082
 
-
 
1083
/** Handler for messages concerning pixmap handling
-
 
1084
 *
-
 
1085
 */
-
 
1086
static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
-
 
1087
{
-
 
1088
    bool handled = true;
-
 
1089
    int retval = EOK;
-
 
1090
    int i, nvp;
-
 
1091
   
1116
    switch (IPC_GET_METHOD(*call)) {
1092
    switch (IPC_GET_METHOD(*call)) {
1117
    case FB_VP_DRAW_PIXMAP:
1093
    case FB_VP_DRAW_PIXMAP:
1118
        nvp = IPC_GET_ARG1(*call);
1094
        nvp = IPC_GET_ARG1(*call);
1119
        if (nvp == -1)
1095
        if (nvp == -1)
1120
            nvp = vp;
1096
            nvp = vp;
Line 1148... Line 1124...
1148
        }
1124
        }
1149
        break;
1125
        break;
1150
    default:
1126
    default:
1151
        handled = 0;
1127
        handled = 0;
1152
    }
1128
    }
1153
 
1129
   
1154
    if (handled)
1130
    if (handled)
1155
        ipc_answer_0(callid, retval);
1131
        ipc_answer_0(callid, retval);
1156
    return handled;
1132
    return handled;
1157
   
1133
   
1158
}
1134
}
1159
 
1135
 
1160
/** Function for handling connections to FB
1136
/** Function for handling connections to FB
1161
 *
1137
 *
1162
 */
1138
 */
1163
static void
-
 
1164
fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
1139
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
1165
{
1140
{
1166
    ipc_callid_t callid;
-
 
1167
    ipc_call_t call;
-
 
1168
    int retval;
-
 
1169
    int i;
-
 
1170
    unsigned int row,col;
1141
    unsigned int vp = 0;
1171
    char c;
-
 
1172
 
-
 
1173
    int vp = 0;
-
 
1174
    viewport_t *vport = &viewports[0];
1142
    viewport_t *vport = &viewports[vp];
1175
 
1143
   
1176
    if (client_connected) {
1144
    if (client_connected) {
1177
        ipc_answer_0(iid, ELIMIT);
1145
        ipc_answer_0(iid, ELIMIT);
1178
        return;
1146
        return;
1179
    }
1147
    }
-
 
1148
   
-
 
1149
    /* Accept connection */
1180
    client_connected = 1;
1150
    client_connected = true;
1181
    ipc_answer_0(iid, EOK); /* Accept connection */
1151
    ipc_answer_0(iid, EOK);
1182
 
1152
   
1183
    while (1) {
1153
    while (true) {
-
 
1154
        ipc_callid_t callid;
-
 
1155
        ipc_call_t call;
-
 
1156
        int retval;
-
 
1157
        unsigned int i;
-
 
1158
        int scroll;
-
 
1159
        uint8_t glyph;
-
 
1160
        unsigned int row, col;
-
 
1161
       
1184
        if (vport->cursor_active || anims_enabled)
1162
        if ((vport->cursor_active) || (anims_enabled))
1185
            callid = async_get_call_timeout(&call, 250000);
1163
            callid = async_get_call_timeout(&call, 250000);
1186
        else
1164
        else
1187
            callid = async_get_call(&call);
1165
            callid = async_get_call(&call);
1188
 
1166
       
1189
        mouse_hide();
1167
        mouse_hide();
1190
        if (!callid) {
1168
        if (!callid) {
1191
            cursor_blink(vport);
1169
            cursor_blink(vport);
1192
            anims_tick();
1170
            anims_tick();
1193
            mouse_show();
1171
            mouse_show();
1194
            continue;
1172
            continue;
1195
        }
1173
        }
-
 
1174
       
1196
        if (shm_handle(callid, &call, vp))
1175
        if (shm_handle(callid, &call, vp))
1197
            continue;
1176
            continue;
-
 
1177
       
1198
        if (pixmap_handle(callid, &call, vp))
1178
        if (pixmap_handle(callid, &call, vp))
1199
            continue;
1179
            continue;
-
 
1180
       
1200
        if (anim_handle(callid, &call, vp))
1181
        if (anim_handle(callid, &call, vp))
1201
            continue;
1182
            continue;
1202
 
1183
       
1203
        switch (IPC_GET_METHOD(call)) {
1184
        switch (IPC_GET_METHOD(call)) {
1204
        case IPC_M_PHONE_HUNGUP:
1185
        case IPC_M_PHONE_HUNGUP:
1205
            client_connected = 0;
1186
            client_connected = false;
-
 
1187
           
1206
            /* cleanup other viewports */
1188
            /* Cleanup other viewports */
1207
            for (i = 1; i < MAX_VIEWPORTS; i++)
1189
            for (i = 1; i < MAX_VIEWPORTS; i++)
1208
                vport->initialized = 0;
1190
                vport->initialized = false;
-
 
1191
           
1209
            return; /* Exit thread */
1192
            /* Exit thread */
-
 
1193
            return;
1210
 
1194
       
1211
        case FB_PUTCHAR:
1195
        case FB_PUTCHAR:
1212
        case FB_TRANS_PUTCHAR:
-
 
1213
            c = IPC_GET_ARG1(call);
1196
            glyph = IPC_GET_ARG1(call);
1214
            row = IPC_GET_ARG2(call);
1197
            row = IPC_GET_ARG2(call);
1215
            col = IPC_GET_ARG3(call);
1198
            col = IPC_GET_ARG3(call);
-
 
1199
           
1216
            if (row >= vport->rows || col >= vport->cols) {
1200
            if ((col >= vport->cols) || (row >= vport->rows)) {
1217
                retval = EINVAL;
1201
                retval = EINVAL;
1218
                break;
1202
                break;
1219
            }
1203
            }
1220
            ipc_answer_0(callid, EOK);
1204
            ipc_answer_0(callid, EOK);
1221
 
1205
           
1222
            draw_char(vport, c, row, col, vport->style,
1206
            draw_char(vport, glyph, col, row);
-
 
1207
           
1223
                IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR);
1208
            /* Message already answered */
1224
            continue; /* msg already answered */
1209
            continue;
1225
        case FB_CLEAR:
1210
        case FB_CLEAR:
1226
            clear_port(vport);
1211
            vport_clear(vport);
1227
            cursor_print(vport);
1212
            cursor_show(vport);
1228
            retval = 0;
1213
            retval = EOK;
1229
            break;
1214
            break;
1230
        case FB_CURSOR_GOTO:
1215
        case FB_CURSOR_GOTO:
1231
            row = IPC_GET_ARG1(call);
1216
            row = IPC_GET_ARG1(call);
1232
            col = IPC_GET_ARG2(call);
1217
            col = IPC_GET_ARG2(call);
-
 
1218
           
1233
            if (row >= vport->rows || col >= vport->cols) {
1219
            if ((col >= vport->cols) || (row >= vport->rows)) {
1234
                retval = EINVAL;
1220
                retval = EINVAL;
1235
                break;
1221
                break;
1236
            }
1222
            }
1237
            retval = 0;
1223
            retval = EOK;
-
 
1224
           
1238
            cursor_hide(vport);
1225
            cursor_hide(vport);
1239
            vport->cur_col = col;
1226
            vport->cur_col = col;
1240
            vport->cur_row = row;
1227
            vport->cur_row = row;
1241
            cursor_print(vport);
1228
            cursor_show(vport);
1242
            break;
1229
            break;
1243
        case FB_CURSOR_VISIBILITY:
1230
        case FB_CURSOR_VISIBILITY:
1244
            cursor_hide(vport);
1231
            cursor_hide(vport);
1245
            vport->cursor_active = IPC_GET_ARG1(call);
1232
            vport->cursor_active = IPC_GET_ARG1(call);
1246
            cursor_print(vport);
1233
            cursor_show(vport);
1247
            retval = 0;
1234
            retval = EOK;
1248
            break;
1235
            break;
1249
        case FB_GET_CSIZE:
1236
        case FB_GET_CSIZE:
1250
            ipc_answer_2(callid, EOK, vport->rows, vport->cols);
1237
            ipc_answer_2(callid, EOK, vport->rows, vport->cols);
1251
            continue;
1238
            continue;
1252
        case FB_SCROLL:
1239
        case FB_SCROLL:
1253
            i = IPC_GET_ARG1(call);
1240
            scroll = IPC_GET_ARG1(call);
1254
            if (i > vport->rows || i < (- (int)vport->rows)) {
1241
            if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) {
1255
                retval = EINVAL;
1242
                retval = EINVAL;
1256
                break;
1243
                break;
1257
            }
1244
            }
1258
            cursor_hide(vport);
1245
            cursor_hide(vport);
1259
            scroll_port(vport, i*FONT_SCANLINES);
1246
            vport_scroll(vport, scroll);
1260
            cursor_print(vport);
1247
            cursor_show(vport);
1261
            retval = 0;
-
 
1262
            break;
-
 
1263
        case FB_VIEWPORT_DB:
-
 
1264
            /* Enable double buffering */
-
 
1265
            i = IPC_GET_ARG1(call);
-
 
1266
            if (i == -1)
-
 
1267
                i = vp;
-
 
1268
            if (i < 0 || i >= MAX_VIEWPORTS) {
-
 
1269
                retval = EINVAL;
-
 
1270
                break;
-
 
1271
            }
-
 
1272
            if (!viewports[i].initialized ) {
-
 
1273
                retval = EADDRNOTAVAIL;
-
 
1274
                break;
-
 
1275
            }
-
 
1276
            viewports[i].dboffset = 0;
-
 
1277
            if (IPC_GET_ARG2(call) == 1 && !viewports[i].dbdata)
-
 
1278
                viewports[i].dbdata =
-
 
1279
                    malloc(screen.pixelbytes *
-
 
1280
                    viewports[i].width * viewports[i].height);
-
 
1281
            else if (IPC_GET_ARG2(call) == 0 &&
-
 
1282
                viewports[i].dbdata) {
-
 
1283
                free(viewports[i].dbdata);
-
 
1284
                viewports[i].dbdata = NULL;
-
 
1285
            }
-
 
1286
            retval = 0;
1248
            retval = EOK;
1287
            break;
1249
            break;
1288
        case FB_VIEWPORT_SWITCH:
1250
        case FB_VIEWPORT_SWITCH:
1289
            i = IPC_GET_ARG1(call);
1251
            i = IPC_GET_ARG1(call);
1290
            if (i < 0 || i >= MAX_VIEWPORTS) {
1252
            if (i >= MAX_VIEWPORTS) {
1291
                retval = EINVAL;
1253
                retval = EINVAL;
1292
                break;
1254
                break;
1293
            }
1255
            }
1294
            if (! viewports[i].initialized ) {
1256
            if (!viewports[i].initialized) {
1295
                retval = EADDRNOTAVAIL;
1257
                retval = EADDRNOTAVAIL;
1296
                break;
1258
                break;
1297
            }
1259
            }
1298
            cursor_hide(vport);
1260
            cursor_hide(vport);
1299
            vp = i;
1261
            vp = i;
1300
            vport = &viewports[vp];
1262
            vport = &viewports[vp];
1301
            cursor_print(vport);
1263
            cursor_show(vport);
1302
            retval = 0;
1264
            retval = EOK;
1303
            break;
1265
            break;
1304
        case FB_VIEWPORT_CREATE:
1266
        case FB_VIEWPORT_CREATE:
1305
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
1267
            retval = vport_create(IPC_GET_ARG1(call) >> 16,
1306
                IPC_GET_ARG1(call) & 0xffff,
1268
                IPC_GET_ARG1(call) & 0xffff,
1307
                IPC_GET_ARG2(call) >> 16,
1269
                IPC_GET_ARG2(call) >> 16,
1308
                IPC_GET_ARG2(call) & 0xffff);
1270
                IPC_GET_ARG2(call) & 0xffff);
1309
            break;
1271
            break;
1310
        case FB_VIEWPORT_DELETE:
1272
        case FB_VIEWPORT_DELETE:
1311
            i = IPC_GET_ARG1(call);
1273
            i = IPC_GET_ARG1(call);
1312
            if (i < 0 || i >= MAX_VIEWPORTS) {
1274
            if (i >= MAX_VIEWPORTS) {
1313
                retval = EINVAL;
1275
                retval = EINVAL;
1314
                break;
1276
                break;
1315
            }
1277
            }
1316
            if (! viewports[i].initialized ) {
1278
            if (!viewports[i].initialized) {
1317
                retval = EADDRNOTAVAIL;
1279
                retval = EADDRNOTAVAIL;
1318
                break;
1280
                break;
1319
            }
1281
            }
1320
            viewports[i].initialized = 0;
1282
            viewports[i].initialized = false;
1321
            if (viewports[i].dbdata) {
1283
            if (viewports[i].glyphs)
1322
                free(viewports[i].dbdata);
1284
                free(viewports[i].glyphs);
-
 
1285
            if (viewports[i].bgpixel)
1323
                viewports[i].dbdata = NULL;
1286
                free(viewports[i].bgpixel);
1324
            }
1287
            if (viewports[i].backbuf)
-
 
1288
                free(viewports[i].backbuf);
1325
            retval = 0;
1289
            retval = EOK;
1326
            break;
1290
            break;
1327
        case FB_SET_STYLE:
1291
        case FB_SET_STYLE:
1328
            vport->style.fg_color = IPC_GET_ARG1(call);
1292
            vport->style.fg_color = IPC_GET_ARG1(call);
1329
            vport->style.bg_color = IPC_GET_ARG2(call);
1293
            vport->style.bg_color = IPC_GET_ARG2(call);
-
 
1294
            render_glyphs(vport);
1330
            retval = 0;
1295
            retval = EOK;
1331
            break;
1296
            break;
1332
        case FB_GET_RESOLUTION:
1297
        case FB_GET_RESOLUTION:
1333
            ipc_answer_2(callid, EOK, screen.xres, screen.yres);
1298
            ipc_answer_2(callid, EOK, screen.xres, screen.yres);
1334
            continue;
1299
            continue;
1335
        case FB_POINTER_MOVE:
1300
        case FB_POINTER_MOVE:
1336
            pointer_enabled = 1;
1301
            pointer_enabled = true;
1337
            mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
1302
            mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
1338
            retval = 0;
1303
            retval = EOK;
1339
            break;
1304
            break;
1340
        default:
1305
        default:
1341
            retval = ENOENT;
1306
            retval = ENOENT;
1342
        }
1307
        }
1343
        ipc_answer_0(callid, retval);
1308
        ipc_answer_0(callid, retval);
1344
    }
1309
    }
1345
}
1310
}
1346
 
1311
 
1347
/** Initialization of framebuffer */
1312
/** Initialization of framebuffer
-
 
1313
 *
1348
int
1314
 */
1349
fb_init(void)
1315
int fb_init(void)
1350
{
1316
{
1351
    void *fb_ph_addr;
-
 
1352
    unsigned int fb_width;
-
 
1353
    unsigned int fb_height;
-
 
1354
    unsigned int fb_scanline;
-
 
1355
    unsigned int fb_visual;
-
 
1356
    bool fb_invert_colors;
-
 
1357
    void *fb_addr;
-
 
1358
    size_t asz;
-
 
1359
 
-
 
1360
    async_set_client_connection(fb_client_connection);
1317
    async_set_client_connection(fb_client_connection);
1361
 
-
 
1362
    fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
-
 
1363
    fb_width = sysinfo_value("fb.width");
-
 
1364
    fb_height = sysinfo_value("fb.height");
-
 
1365
    fb_scanline = sysinfo_value("fb.scanline");
-
 
1366
    fb_visual = sysinfo_value("fb.visual");
-
 
1367
    fb_invert_colors = sysinfo_value("fb.invert-colors");
-
 
1368
 
-
 
1369
    asz = fb_scanline * fb_height;
-
 
1370
    fb_addr = as_get_mappable_page(asz);
-
 
1371
   
1318
   
-
 
1319
    void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
-
 
1320
    unsigned int fb_offset = sysinfo_value("fb.offset");
-
 
1321
    unsigned int fb_width = sysinfo_value("fb.width");
-
 
1322
    unsigned int fb_height = sysinfo_value("fb.height");
-
 
1323
    unsigned int fb_scanline = sysinfo_value("fb.scanline");
-
 
1324
    unsigned int fb_visual = sysinfo_value("fb.visual");
-
 
1325
   
-
 
1326
    unsigned int fbsize = fb_scanline * fb_height;
-
 
1327
    void *fb_addr = as_get_mappable_page(fbsize);
-
 
1328
   
1372
    physmem_map(fb_ph_addr, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >>
1329
    physmem_map(fb_ph_addr + fb_offset, fb_addr,
1373
        PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
1330
        ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
1374
 
1331
   
1375
    if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual,
1332
    if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual))
1376
        fb_invert_colors))
-
 
1377
        return 0;
1333
        return 0;
1378
   
1334
   
1379
    return -1;
1335
    return -1;
1380
}
1336
}
1381
 
1337
 
1382
/**
1338
/**
1383
 * @}
1339
 * @}
1384
 */
1340
 */