Subversion Repositories HelenOS

Rev

Rev 2927 | Rev 4338 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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