Subversion Repositories HelenOS

Rev

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

Rev 4347 Rev 4348
Line 28... Line 28...
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
29
 */
30
 
30
 
31
/**
31
/**
32
 * @defgroup fb Graphical framebuffer
32
 * @defgroup fb Graphical framebuffer
33
 * @brief   HelenOS graphical framebuffer.
33
 * @brief HelenOS graphical framebuffer.
34
 * @ingroup fbs
34
 * @ingroup fbs
35
 * @{
35
 * @{
36
 */
36
 */
37
 
37
 
38
/** @file
38
/** @file
Line 66... Line 66...
66
#include "pointer_mask.xbm"
66
#include "pointer_mask.xbm"
67
 
67
 
68
#define DEFAULT_BGCOLOR  0xf0f0f0
68
#define DEFAULT_BGCOLOR  0xf0f0f0
69
#define DEFAULT_FGCOLOR  0x000000
69
#define DEFAULT_FGCOLOR  0x000000
70
 
70
 
-
 
71
#define GLYPH_UNAVAIL    '?'
-
 
72
 
71
#define MAX_ANIM_LEN     8
73
#define MAX_ANIM_LEN     8
72
#define MAX_ANIMATIONS   4
74
#define MAX_ANIMATIONS   4
73
#define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
75
#define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
74
#define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
76
#define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
75
 
77
 
76
/** Function to render a pixel from a RGB value. */
78
/** Function to render a pixel from a RGB value. */
77
typedef void (*rgb_conv_t)(void *, uint32_t);
79
typedef void (*rgb_conv_t)(void *, uint32_t);
78
 
80
 
-
 
81
/** Function to render a bit mask. */
-
 
82
typedef void (*mask_conv_t)(void *, bool);
-
 
83
 
79
/** Function to draw a glyph. */
84
/** Function to draw a glyph. */
80
typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor,
85
typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor,
81
    uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color);
86
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color);
82
 
87
 
83
struct {
88
struct {
84
    uint8_t *fb_addr;
89
    uint8_t *fb_addr;
85
   
90
   
86
    unsigned int xres;
91
    unsigned int xres;
Line 90... Line 95...
90
    unsigned int glyphscanline;
95
    unsigned int glyphscanline;
91
   
96
   
92
    unsigned int pixelbytes;
97
    unsigned int pixelbytes;
93
    unsigned int glyphbytes;
98
    unsigned int glyphbytes;
94
   
99
   
-
 
100
    /** Pre-rendered mask for rendering glyphs. Specific for the visual. */
-
 
101
    uint8_t *glyphs;
-
 
102
   
95
    rgb_conv_t rgb_conv;
103
    rgb_conv_t rgb_conv;
-
 
104
    mask_conv_t mask_conv;
96
} screen;
105
} screen;
97
 
106
 
98
/** Backbuffer character cell. */
107
/** Backbuffer character cell. */
99
typedef struct {
108
typedef struct {
100
    uint8_t glyph;
109
    uint32_t glyph;
101
    uint32_t fg_color;
110
    uint32_t fg_color;
102
    uint32_t bg_color;
111
    uint32_t bg_color;
103
} bb_cell_t;
112
} bb_cell_t;
104
 
113
 
105
typedef struct {
114
typedef struct {
Line 114... Line 123...
114
    unsigned int rows;
123
    unsigned int rows;
115
   
124
   
116
    /*
125
    /*
117
     * Style and glyphs for text printing
126
     * Style and glyphs for text printing
118
     */
127
     */
119
 
128
   
120
    /** Current attributes. */
129
    /** Current attributes. */
121
    attr_rgb_t attr;
130
    attr_rgb_t attr;
122
 
131
   
123
    /** Pre-rendered mask for rendering glyphs. Different viewports
-
 
124
     * might use different drawing functions depending on whether their
-
 
125
     * scanlines are aligned on a word boundary.*/
-
 
126
    uint8_t *glyphs;
-
 
127
 
-
 
128
    uint8_t *bgpixel;
132
    uint8_t *bgpixel;
129
 
133
   
-
 
134
    /**
130
    /** Glyph drawing function for this viewport. */
135
     * Glyph drawing function for this viewport.  Different viewports
-
 
136
     * might use different drawing functions depending on whether their
-
 
137
     * scanlines are aligned on a word boundary.
-
 
138
     */
131
    dg_t dglyph;
139
    dg_t dglyph;
132
   
140
   
133
    /* Auto-cursor position */
141
    /* Auto-cursor position */
134
    bool cursor_active;
142
    bool cursor_active;
135
    unsigned int cur_col;
143
    unsigned int cur_col;
Line 164... Line 172...
164
static viewport_t viewports[128];
172
static viewport_t viewports[128];
165
 
173
 
166
static bool client_connected = false;  /**< Allow only 1 connection */
174
static bool client_connected = false;  /**< Allow only 1 connection */
167
 
175
 
168
static uint32_t color_table[16] = {
176
static uint32_t color_table[16] = {
169
    [COLOR_BLACK]       = 0x000000,
177
    [COLOR_BLACK]       = 0x000000,
170
    [COLOR_BLUE]        = 0x0000f0,
178
    [COLOR_BLUE]        = 0x0000f0,
171
    [COLOR_GREEN]       = 0x00f000,
179
    [COLOR_GREEN]       = 0x00f000,
172
    [COLOR_CYAN]        = 0x00f0f0,
180
    [COLOR_CYAN]        = 0x00f0f0,
173
    [COLOR_RED]     = 0xf00000,
181
    [COLOR_RED]         = 0xf00000,
174
    [COLOR_MAGENTA]     = 0xf000f0,
182
    [COLOR_MAGENTA]     = 0xf000f0,
175
    [COLOR_YELLOW]      = 0xf0f000,
183
    [COLOR_YELLOW]      = 0xf0f000,
176
    [COLOR_WHITE]       = 0xf0f0f0,
184
    [COLOR_WHITE]       = 0xf0f0f0,
177
 
185
   
178
    [8 + COLOR_BLACK]   = 0x000000,
186
    [8 + COLOR_BLACK]   = 0x000000,
179
    [8 + COLOR_BLUE]    = 0x0000ff,
187
    [8 + COLOR_BLUE]    = 0x0000ff,
180
    [8 + COLOR_GREEN]   = 0x00ff00,
188
    [8 + COLOR_GREEN]   = 0x00ff00,
181
    [8 + COLOR_CYAN]    = 0x00ffff,
189
    [8 + COLOR_CYAN]    = 0x00ffff,
182
    [8 + COLOR_RED]     = 0xff0000,
190
    [8 + COLOR_RED]     = 0xff0000,
183
    [8 + COLOR_MAGENTA] = 0xff00ff,
191
    [8 + COLOR_MAGENTA] = 0xff00ff,
184
    [8 + COLOR_YELLOW]  = 0xffff00,
192
    [8 + COLOR_YELLOW]  = 0xffff00,
185
    [8 + COLOR_WHITE]   = 0xffffff,
193
    [8 + COLOR_WHITE]   = 0xffffff,
186
};
194
};
187
 
195
 
188
static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a);
196
static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a);
189
static int rgb_from_style(attr_rgb_t *rgb, int style);
197
static int rgb_from_style(attr_rgb_t *rgb, int style);
190
static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color,
198
static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color,
Line 192... Line 200...
192
 
200
 
193
static int fb_set_color(viewport_t *vport, ipcarg_t fg_color,
201
static int fb_set_color(viewport_t *vport, ipcarg_t fg_color,
194
    ipcarg_t bg_color, ipcarg_t attr);
202
    ipcarg_t bg_color, ipcarg_t attr);
195
 
203
 
196
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
204
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
197
    uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color);
205
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color);
198
static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
206
static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
199
    uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color);
207
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color);
200
 
208
 
201
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
209
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
202
    unsigned int row);
210
    unsigned int row);
203
 
211
 
204
 
212
 
Line 220... Line 228...
220
/** ARGB 8:8:8:8 conversion
228
/** ARGB 8:8:8:8 conversion
221
 *
229
 *
222
 */
230
 */
223
static void rgb_0888(void *dst, uint32_t rgb)
231
static void rgb_0888(void *dst, uint32_t rgb)
224
{
232
{
225
    *((uint32_t *) dst) = rgb & 0xffffff;
233
    *((uint32_t *) dst) = rgb & 0x00ffffff;
-
 
234
}
-
 
235
 
-
 
236
static void mask_0888(void *dst, bool mask)
-
 
237
{
-
 
238
    *((uint32_t *) dst) = (mask ? 0x00ffffff : 0);
226
}
239
}
227
 
240
 
228
 
241
 
229
/** ABGR 8:8:8:8 conversion
242
/** ABGR 8:8:8:8 conversion
230
 *
243
 *
Line 244... Line 257...
244
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
257
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
245
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
258
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
246
    ((uint8_t *) dst)[2] = RED(rgb, 8);
259
    ((uint8_t *) dst)[2] = RED(rgb, 8);
247
}
260
}
248
 
261
 
-
 
262
static void mask_888(void *dst, bool mask)
-
 
263
{
-
 
264
    if (mask) {
-
 
265
        ((uint8_t *) dst)[0] = 0xff;
-
 
266
        ((uint8_t *) dst)[1] = 0xff;
-
 
267
        ((uint8_t *) dst)[2] = 0xff;
-
 
268
    } else {
-
 
269
        ((uint8_t *) dst)[0] = 0;
-
 
270
        ((uint8_t *) dst)[1] = 0;
-
 
271
        ((uint8_t *) dst)[2] = 0;
-
 
272
    }
-
 
273
}
-
 
274
 
249
 
275
 
250
/** BGR 8:8:8 conversion
276
/** BGR 8:8:8 conversion
251
 *
277
 *
252
 */
278
 */
253
static void bgr_888(void *dst, uint32_t rgb)
279
static void bgr_888(void *dst, uint32_t rgb)
Line 265... Line 291...
265
{
291
{
266
    *((uint16_t *) dst)
292
    *((uint16_t *) dst)
267
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
293
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
268
}
294
}
269
 
295
 
-
 
296
static void mask_555(void *dst, bool mask)
-
 
297
{
-
 
298
    *((uint16_t *) dst) = (mask ? 0x7fff : 0);
-
 
299
}
-
 
300
 
270
 
301
 
271
/** RGB 5:6:5 conversion
302
/** RGB 5:6:5 conversion
272
 *
303
 *
273
 */
304
 */
274
static void rgb_565(void *dst, uint32_t rgb)
305
static void rgb_565(void *dst, uint32_t rgb)
275
{
306
{
276
    *((uint16_t *) dst)
307
    *((uint16_t *) dst)
277
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
308
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
278
}
309
}
279
 
310
 
-
 
311
static void mask_565(void *dst, bool mask)
-
 
312
{
-
 
313
    *((uint16_t *) dst) = (mask ? 0xffff : 0);
-
 
314
}
-
 
315
 
280
 
316
 
281
/** RGB 3:2:3
317
/** RGB 3:2:3
282
 *
318
 *
283
 */
319
 */
284
static void rgb_323(void *dst, uint32_t rgb)
320
static void rgb_323(void *dst, uint32_t rgb)
285
{
321
{
286
    *((uint8_t *) dst)
322
    *((uint8_t *) dst)
287
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
323
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
288
}
324
}
289
 
325
 
-
 
326
static void mask_323(void *dst, bool mask)
-
 
327
{
-
 
328
    *((uint8_t *) dst) = (mask ? 0xff : 0);
-
 
329
}
-
 
330
 
290
/** Draw a filled rectangle.
331
/** Draw a filled rectangle.
291
 *
332
 *
292
 * @note Need real implementation that does not access VRAM twice.
333
 * @note Need real implementation that does not access VRAM twice.
-
 
334
 *
293
 */
335
 */
294
static void draw_filled_rect(unsigned int x0, unsigned int y0, unsigned int x1,
336
static void draw_filled_rect(unsigned int x0, unsigned int y0, unsigned int x1,
295
    unsigned int y1, uint32_t color)
337
    unsigned int y1, uint32_t color)
296
{
338
{
-
 
339
    unsigned int x;
297
    unsigned int x, y;
340
    unsigned int y;
298
    unsigned int copy_bytes;
341
    unsigned int copy_bytes;
299
 
342
   
300
    uint8_t *sp, *dp;
343
    uint8_t *sp;
-
 
344
    uint8_t *dp;
301
    uint8_t cbuf[4];
345
    uint8_t cbuf[4];
302
 
346
   
303
    if (y0 >= y1 || x0 >= x1) return;
347
    if ((y0 >= y1) || (x0 >= x1))
-
 
348
        return;
-
 
349
   
304
    screen.rgb_conv(cbuf, color);
350
    screen.rgb_conv(cbuf, color);
305
 
351
   
306
    sp = &screen.fb_addr[FB_POS(x0, y0)];
352
    sp = &screen.fb_addr[FB_POS(x0, y0)];
307
    dp = sp;
353
    dp = sp;
308
 
354
   
309
    /* Draw the first line. */
355
    /* Draw the first line. */
310
    for (x = x0; x < x1; x++) {
356
    for (x = x0; x < x1; x++) {
311
        memcpy(dp, cbuf, screen.pixelbytes);
357
        memcpy(dp, cbuf, screen.pixelbytes);
312
        dp += screen.pixelbytes;
358
        dp += screen.pixelbytes;
313
    }
359
    }
314
 
360
   
315
    dp = sp + screen.scanline;
361
    dp = sp + screen.scanline;
316
    copy_bytes = (x1 - x0) * screen.pixelbytes;
362
    copy_bytes = (x1 - x0) * screen.pixelbytes;
317
 
363
   
318
    /* Draw the remaining lines by copying. */
364
    /* Draw the remaining lines by copying. */
319
    for (y = y0 + 1; y < y1; y++) {
365
    for (y = y0 + 1; y < y1; y++) {
320
        memcpy(dp, sp, copy_bytes);
366
        memcpy(dp, sp, copy_bytes);
321
        dp += screen.scanline;
367
        dp += screen.scanline;
322
    }
368
    }
Line 327... Line 373...
327
 * @param vport Viewport to redraw
373
 * @param vport Viewport to redraw
328
 *
374
 *
329
 */
375
 */
330
static void vport_redraw(viewport_t *vport)
376
static void vport_redraw(viewport_t *vport)
331
{
377
{
-
 
378
    unsigned int row;
332
    unsigned int row, col;
379
    unsigned int col;
333
 
380
   
334
    for (row = 0; row < vport->rows; row++) {
381
    for (row = 0; row < vport->rows; row++) {
335
        for (col = 0; col < vport->cols; col++) {
382
        for (col = 0; col < vport->cols; col++) {
336
            draw_vp_glyph(vport, false, col, row);
383
            draw_vp_glyph(vport, false, col, row);
337
        }
384
        }
338
    }
385
    }
339
 
386
   
340
    if (COL2X(vport->cols) < vport->width) {
387
    if (COL2X(vport->cols) < vport->width) {
341
        draw_filled_rect(
388
        draw_filled_rect(
342
            vport->x + COL2X(vport->cols), vport->y,
389
            vport->x + COL2X(vport->cols), vport->y,
343
            vport->x + vport->width, vport->y + vport->height,
390
            vport->x + vport->width, vport->y + vport->height,
344
            vport->attr.bg_color);
391
            vport->attr.bg_color);
345
    }
392
    }
346
 
393
   
347
    if (ROW2Y(vport->rows) < vport->height) {
394
    if (ROW2Y(vport->rows) < vport->height) {
348
        draw_filled_rect(
395
        draw_filled_rect(
349
            vport->x, vport->y + ROW2Y(vport->rows),
396
            vport->x, vport->y + ROW2Y(vport->rows),
350
            vport->x + vport->width, vport->y + vport->height,
397
            vport->x + vport->width, vport->y + vport->height,
351
            vport->attr.bg_color);
398
            vport->attr.bg_color);
Line 353... Line 400...
353
}
400
}
354
 
401
 
355
static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color,
402
static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color,
356
    uint32_t bg_color)
403
    uint32_t bg_color)
357
{
404
{
358
    unsigned i;
405
    size_t i;
359
 
406
   
360
    for (i = 0; i < len; i++) {
407
    for (i = 0; i < len; i++) {
361
        backbuf[i].glyph = 0;
408
        backbuf[i].glyph = 0;
362
        backbuf[i].fg_color = fg_color;
409
        backbuf[i].fg_color = fg_color;
363
        backbuf[i].bg_color = bg_color;
410
        backbuf[i].bg_color = bg_color;
364
    }
411
    }
Line 382... Line 429...
382
 * @param lines Number of lines to scroll
429
 * @param lines Number of lines to scroll
383
 *
430
 *
384
 */
431
 */
385
static void vport_scroll(viewport_t *vport, int lines)
432
static void vport_scroll(viewport_t *vport, int lines)
386
{
433
{
-
 
434
    unsigned int row;
387
    unsigned int row, col;
435
    unsigned int col;
-
 
436
    unsigned int x;
388
    unsigned int x, y;
437
    unsigned int y;
389
    uint8_t glyph;
438
    uint32_t glyph;
390
    uint32_t fg_color;
439
    uint32_t fg_color;
391
    uint32_t bg_color;
440
    uint32_t bg_color;
-
 
441
    bb_cell_t *bbp;
392
    bb_cell_t *bbp, *xbp;
442
    bb_cell_t *xbp;
393
 
443
   
394
    /*
444
    /*
395
     * Redraw.
445
     * Redraw.
396
     */
446
     */
397
 
447
   
398
    y = vport->y;
448
    y = vport->y;
399
    for (row = 0; row < vport->rows; row++) {
449
    for (row = 0; row < vport->rows; row++) {
400
        x = vport->x;
450
        x = vport->x;
401
        for (col = 0; col < vport->cols; col++) {
451
        for (col = 0; col < vport->cols; col++) {
402
            if ((row + lines >= 0) && (row + lines < vport->rows)) {
452
            if ((row + lines >= 0) && (row + lines < vport->rows)) {
403
                xbp = &vport->backbuf[BB_POS(vport, col, row + lines)];
453
                xbp = &vport->backbuf[BB_POS(vport, col, row + lines)];
404
                bbp = &vport->backbuf[BB_POS(vport, col, row)];
454
                bbp = &vport->backbuf[BB_POS(vport, col, row)];
405
 
455
               
406
                glyph = xbp->glyph;
456
                glyph = xbp->glyph;
407
                fg_color = xbp->fg_color;
457
                fg_color = xbp->fg_color;
408
                bg_color = xbp->bg_color;
458
                bg_color = xbp->bg_color;
409
 
459
               
410
                if (bbp->glyph == glyph &&
460
                if ((bbp->glyph == glyph)
411
                    bbp->fg_color == xbp->fg_color &&
461
                   && (bbp->fg_color == xbp->fg_color)
412
                    bbp->bg_color == xbp->bg_color) {
462
                   && (bbp->bg_color == xbp->bg_color)) {
413
                    x += FONT_WIDTH;
463
                    x += FONT_WIDTH;
414
                    continue;
464
                    continue;
415
                }
465
                }
416
            } else {
466
            } else {
417
                glyph = 0;
467
                glyph = 0;
418
                fg_color = vport->attr.fg_color;
468
                fg_color = vport->attr.fg_color;
419
                bg_color = vport->attr.bg_color;
469
                bg_color = vport->attr.bg_color;
420
            }
470
            }
421
 
471
           
422
            (*vport->dglyph)(x, y, false, vport->glyphs, glyph,
472
            (*vport->dglyph)(x, y, false, screen.glyphs, glyph,
423
                fg_color, bg_color);
473
                fg_color, bg_color);
424
            x += FONT_WIDTH;
474
            x += FONT_WIDTH;
425
        }
475
        }
426
        y += FONT_SCANLINES;
476
        y += FONT_SCANLINES;
427
    }
477
    }
428
 
478
   
429
    /*
479
    /*
430
     * Scroll backbuffer.
480
     * Scroll backbuffer.
431
     */
481
     */
432
 
482
   
433
    if (lines > 0) {
483
    if (lines > 0) {
434
        memmove(vport->backbuf, vport->backbuf + vport->cols * lines,
484
        memmove(vport->backbuf, vport->backbuf + vport->cols * lines,
435
            vport->cols * (vport->rows - lines) * sizeof(bb_cell_t));
485
            vport->cols * (vport->rows - lines) * sizeof(bb_cell_t));
436
        backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)],
486
        backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)],
437
            vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color);
487
            vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color);
Line 446... Line 496...
446
/** Render glyphs
496
/** Render glyphs
447
 *
497
 *
448
 * Convert glyphs from device independent font
498
 * Convert glyphs from device independent font
449
 * description to current visual representation.
499
 * description to current visual representation.
450
 *
500
 *
451
 * @param vport Viewport
-
 
452
 *
-
 
453
 */
501
 */
454
static void render_glyphs(viewport_t* vport)
502
static void render_glyphs(void)
455
{
503
{
456
    unsigned int glyph;
504
    unsigned int glyph;
457
   
505
   
458
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
506
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
459
        unsigned int y;
507
        unsigned int y;
460
       
508
       
461
        for (y = 0; y < FONT_SCANLINES; y++) {
509
        for (y = 0; y < FONT_SCANLINES; y++) {
462
            unsigned int x;
510
            unsigned int x;
463
           
511
           
464
            for (x = 0; x < FONT_WIDTH; x++) {
512
            for (x = 0; x < FONT_WIDTH; x++) {
465
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
513
                screen.mask_conv(&screen.glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
466
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
514
                    (fb_font[glyph][y] & (1 << (7 - x))) ? true : false);
467
                    ? 0xffffff : 0x000000);
-
 
468
               
515
               
469
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes],
516
                screen.mask_conv(&screen.glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes],
470
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
517
                    (fb_font[glyph][y] & (1 << (7 - x))) ? false : true);
471
                    ? 0x000000 : 0xffffff);
-
 
472
            }
518
            }
473
        }
519
        }
474
    }
520
    }
475
   
-
 
476
    screen.rgb_conv(vport->bgpixel, vport->attr.bg_color);
-
 
477
}
521
}
478
 
522
 
479
 
-
 
480
/** Create new viewport
523
/** Create new viewport
481
 *
524
 *
482
 * @param x      Origin of the viewport (x).
525
 * @param x      Origin of the viewport (x).
483
 * @param y      Origin of the viewport (y).
526
 * @param y      Origin of the viewport (y).
484
 * @param width  Width of the viewport.
527
 * @param width  Width of the viewport.
Line 494... Line 537...
494
   
537
   
495
    for (i = 0; i < MAX_VIEWPORTS; i++) {
538
    for (i = 0; i < MAX_VIEWPORTS; i++) {
496
        if (!viewports[i].initialized)
539
        if (!viewports[i].initialized)
497
            break;
540
            break;
498
    }
541
    }
-
 
542
   
499
    if (i == MAX_VIEWPORTS)
543
    if (i == MAX_VIEWPORTS)
500
        return ELIMIT;
544
        return ELIMIT;
501
   
545
   
502
    unsigned int cols = width / FONT_WIDTH;
546
    unsigned int cols = width / FONT_WIDTH;
503
    unsigned int rows = height / FONT_SCANLINES;
547
    unsigned int rows = height / FONT_SCANLINES;
504
    unsigned int bbsize = cols * rows * sizeof(bb_cell_t);
548
    unsigned int bbsize = cols * rows * sizeof(bb_cell_t);
505
    unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
-
 
506
    unsigned int word_size = sizeof(unsigned long);
549
    unsigned int word_size = sizeof(unsigned long);
507
   
550
   
508
    bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize);
551
    bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize);
509
    if (!backbuf)
552
    if (!backbuf)
510
        return ENOMEM;
553
        return ENOMEM;
511
   
554
   
512
    uint8_t *glyphs = (uint8_t *) malloc(glyphsize);
-
 
513
    if (!glyphs) {
-
 
514
        free(backbuf);
-
 
515
        return ENOMEM;
-
 
516
    }
-
 
517
   
-
 
518
    uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes);
555
    uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes);
519
    if (!bgpixel) {
556
    if (!bgpixel) {
520
        free(glyphs);
-
 
521
        free(backbuf);
557
        free(backbuf);
522
        return ENOMEM;
558
        return ENOMEM;
523
    }
559
    }
524
 
560
   
525
    backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR);
561
    backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR);
526
    memset(glyphs, 0, glyphsize);
-
 
527
    memset(bgpixel, 0, screen.pixelbytes);
562
    memset(bgpixel, 0, screen.pixelbytes);
528
   
563
   
529
    viewports[i].x = x;
564
    viewports[i].x = x;
530
    viewports[i].y = y;
565
    viewports[i].y = y;
531
    viewports[i].width = width;
566
    viewports[i].width = width;
Line 535... Line 570...
535
    viewports[i].rows = rows;
570
    viewports[i].rows = rows;
536
   
571
   
537
    viewports[i].attr.bg_color = DEFAULT_BGCOLOR;
572
    viewports[i].attr.bg_color = DEFAULT_BGCOLOR;
538
    viewports[i].attr.fg_color = DEFAULT_FGCOLOR;
573
    viewports[i].attr.fg_color = DEFAULT_FGCOLOR;
539
   
574
   
540
    viewports[i].glyphs = glyphs;
-
 
541
    viewports[i].bgpixel = bgpixel;
575
    viewports[i].bgpixel = bgpixel;
542
 
576
   
543
    /*
577
    /*
544
     * Conditions necessary  to select aligned version:
578
     * Conditions necessary to select aligned version:
-
 
579
     *  - word size is divisible by pixelbytes
-
 
580
     *  - cell scanline size is divisible by word size
-
 
581
     *  - cell scanlines are word-aligned
545
     *
582
     *
546
     *   - word size is divisible by pixelbytes
-
 
547
     *   - cell scanline size is divisible by word size
-
 
548
     *   - cell scanlines are word-aligned
-
 
549
     */
583
     */
550
    if ((word_size % screen.pixelbytes) == 0 &&
584
    if (((word_size % screen.pixelbytes) == 0)
551
        (FONT_WIDTH * screen.pixelbytes) % word_size == 0 &&
585
        && ((FONT_WIDTH * screen.pixelbytes) % word_size == 0)
552
        (x * screen.pixelbytes) % word_size == 0 &&
586
        && ((x * screen.pixelbytes) % word_size == 0)
553
        screen.scanline % word_size == 0) {
587
        && (screen.scanline % word_size == 0)) {
554
 
-
 
555
        viewports[i].dglyph = draw_glyph_aligned;
588
        viewports[i].dglyph = draw_glyph_aligned;
556
    } else {
589
    } else {
557
        viewports[i].dglyph = draw_glyph_fallback;
590
        viewports[i].dglyph = draw_glyph_fallback;
558
    }
591
    }
559
 
592
   
560
    viewports[i].cur_col = 0;
593
    viewports[i].cur_col = 0;
561
    viewports[i].cur_row = 0;
594
    viewports[i].cur_row = 0;
562
    viewports[i].cursor_active = false;
595
    viewports[i].cursor_active = false;
563
    viewports[i].cursor_shown = false;
596
    viewports[i].cursor_shown = false;
564
   
597
   
565
    viewports[i].bbsize = bbsize;
598
    viewports[i].bbsize = bbsize;
566
    viewports[i].backbuf = backbuf;
599
    viewports[i].backbuf = backbuf;
567
   
600
   
568
    viewports[i].initialized = true;
601
    viewports[i].initialized = true;
569
   
602
   
570
    render_glyphs(&viewports[i]);
603
    screen.rgb_conv(viewports[i].bgpixel, viewports[i].attr.bg_color);
571
   
604
   
572
    return i;
605
    return i;
573
}
606
}
574
 
607
 
575
 
608
 
Line 583... Line 616...
583
 *
616
 *
584
 */
617
 */
585
static bool screen_init(void *addr, unsigned int xres, unsigned int yres,
618
static bool screen_init(void *addr, unsigned int xres, unsigned int yres,
586
    unsigned int scan, unsigned int visual)
619
    unsigned int scan, unsigned int visual)
587
{
620
{
-
 
621
   
-
 
622
   
588
    switch (visual) {
623
    switch (visual) {
589
    case VISUAL_INDIRECT_8:
624
    case VISUAL_INDIRECT_8:
590
        screen.rgb_conv = rgb_323;
625
        screen.rgb_conv = rgb_323;
-
 
626
        screen.mask_conv = mask_323;
591
        screen.pixelbytes = 1;
627
        screen.pixelbytes = 1;
592
        break;
628
        break;
593
    case VISUAL_RGB_5_5_5:
629
    case VISUAL_RGB_5_5_5:
594
        screen.rgb_conv = rgb_555;
630
        screen.rgb_conv = rgb_555;
-
 
631
        screen.mask_conv = mask_555;
595
        screen.pixelbytes = 2;
632
        screen.pixelbytes = 2;
596
        break;
633
        break;
597
    case VISUAL_RGB_5_6_5:
634
    case VISUAL_RGB_5_6_5:
598
        screen.rgb_conv = rgb_565;
635
        screen.rgb_conv = rgb_565;
-
 
636
        screen.mask_conv = mask_565;
599
        screen.pixelbytes = 2;
637
        screen.pixelbytes = 2;
600
        break;
638
        break;
601
    case VISUAL_RGB_8_8_8:
639
    case VISUAL_RGB_8_8_8:
602
        screen.rgb_conv = rgb_888;
640
        screen.rgb_conv = rgb_888;
-
 
641
        screen.mask_conv = mask_888;
603
        screen.pixelbytes = 3;
642
        screen.pixelbytes = 3;
604
        break;
643
        break;
605
    case VISUAL_BGR_8_8_8:
644
    case VISUAL_BGR_8_8_8:
606
        screen.rgb_conv = bgr_888;
645
        screen.rgb_conv = bgr_888;
-
 
646
        screen.mask_conv = mask_888;
607
        screen.pixelbytes = 3;
647
        screen.pixelbytes = 3;
608
        break;
648
        break;
609
    case VISUAL_RGB_8_8_8_0:
649
    case VISUAL_RGB_8_8_8_0:
610
        screen.rgb_conv = rgb_888;
650
        screen.rgb_conv = rgb_888;
-
 
651
        screen.mask_conv = mask_888;
611
        screen.pixelbytes = 4;
652
        screen.pixelbytes = 4;
612
        break;
653
        break;
613
    case VISUAL_RGB_0_8_8_8:
654
    case VISUAL_RGB_0_8_8_8:
614
        screen.rgb_conv = rgb_0888;
655
        screen.rgb_conv = rgb_0888;
-
 
656
        screen.mask_conv = mask_0888;
615
        screen.pixelbytes = 4;
657
        screen.pixelbytes = 4;
616
        break;
658
        break;
617
    case VISUAL_BGR_0_8_8_8:
659
    case VISUAL_BGR_0_8_8_8:
618
        screen.rgb_conv = bgr_0888;
660
        screen.rgb_conv = bgr_0888;
-
 
661
        screen.mask_conv = mask_0888;
619
        screen.pixelbytes = 4;
662
        screen.pixelbytes = 4;
620
        break;
663
        break;
621
    default:
664
    default:
622
        return false;
665
        return false;
623
    }
666
    }
624
 
667
   
625
    screen.fb_addr = (unsigned char *) addr;
668
    screen.fb_addr = (unsigned char *) addr;
626
    screen.xres = xres;
669
    screen.xres = xres;
627
    screen.yres = yres;
670
    screen.yres = yres;
628
    screen.scanline = scan;
671
    screen.scanline = scan;
629
   
672
   
630
    screen.glyphscanline = FONT_WIDTH * screen.pixelbytes;
673
    screen.glyphscanline = FONT_WIDTH * screen.pixelbytes;
631
    screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES;
674
    screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES;
632
   
675
   
-
 
676
    size_t glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
-
 
677
    uint8_t *glyphs = (uint8_t *) malloc(glyphsize);
-
 
678
    if (!glyphs)
-
 
679
        return false;
-
 
680
   
-
 
681
    memset(glyphs, 0, glyphsize);
-
 
682
    screen.glyphs = glyphs;
-
 
683
   
-
 
684
    render_glyphs();
-
 
685
   
633
    /* Create first viewport */
686
    /* Create first viewport */
634
    vport_create(0, 0, xres, yres);
687
    vport_create(0, 0, xres, yres);
635
   
688
   
636
    return true;
689
    return true;
637
}
690
}
Line 648... Line 701...
648
 * It makes use of the pre-rendered mask to process (possibly) several
701
 * It makes use of the pre-rendered mask to process (possibly) several
649
 * pixels at once (word size / pixelbytes pixels at a time are processed)
702
 * pixels at once (word size / pixelbytes pixels at a time are processed)
650
 * making it very fast. Most notably this version is not applicable at 24 bits
703
 * making it very fast. Most notably this version is not applicable at 24 bits
651
 * per pixel.
704
 * per pixel.
652
 *
705
 *
653
 * @param x     x coordinate of top-left corner on screen.
706
 * @param x        x coordinate of top-left corner on screen.
654
 * @param y     y coordinate of top-left corner on screen.
707
 * @param y        y coordinate of top-left corner on screen.
655
 * @param cursor    Draw glyph with cursor
708
 * @param cursor   Draw glyph with cursor
656
 * @param glyphs    Pointer to font bitmap.
709
 * @param glyphs   Pointer to font bitmap.
657
 * @param glyph     Code of the glyph to draw.
710
 * @param glyph    Code of the glyph to draw.
658
 * @param fg_color  Foreground color.
711
 * @param fg_color Foreground color.
659
 * @param bg_color  Backgroudn color.
712
 * @param bg_color Backgroudn color.
-
 
713
 *
660
 */
714
 */
661
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
715
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
662
    uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color)
716
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color)
663
{
717
{
-
 
718
    unsigned int i;
664
    unsigned int i, yd;
719
    unsigned int yd;
665
    unsigned long fg_buf, bg_buf;
720
    unsigned long fg_buf;
666
    unsigned long *maskp, *dp;
721
    unsigned long bg_buf;
667
    unsigned long mask;
722
    unsigned long mask;
668
    unsigned int ww, d_add;
-
 
669
 
723
   
670
    /*
724
    /*
671
     * Prepare a pair of words, one filled with foreground-color
725
     * Prepare a pair of words, one filled with foreground-color
672
     * pattern and the other filled with background-color pattern.
726
     * pattern and the other filled with background-color pattern.
673
     */
727
     */
674
    for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) {
728
    for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) {
675
        screen.rgb_conv(&((uint8_t *)&fg_buf)[i * screen.pixelbytes],
729
        screen.rgb_conv(&((uint8_t *) &fg_buf)[i * screen.pixelbytes],
676
            fg_color);
730
            fg_color);
677
        screen.rgb_conv(&((uint8_t *)&bg_buf)[i * screen.pixelbytes],
731
        screen.rgb_conv(&((uint8_t *) &bg_buf)[i * screen.pixelbytes],
678
            bg_color);
732
            bg_color);
679
    }
733
    }
680
 
-
 
681
 
734
   
682
    /* Pointer to the current position in the mask. */
735
    /* Pointer to the current position in the mask. */
683
    maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)];
736
    unsigned long *maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)];
684
 
737
   
685
    /* Pointer to the current position on the screen. */
738
    /* Pointer to the current position on the screen. */
686
    dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)];
739
    unsigned long *dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)];
687
 
740
   
688
    /* Width of the character cell in words. */
741
    /* Width of the character cell in words. */
689
    ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long);
742
    unsigned int ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long);
690
 
743
   
691
    /* Offset to add when moving to another screen scanline. */
744
    /* Offset to add when moving to another screen scanline. */
692
    d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
745
    unsigned int d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
693
 
746
   
694
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
747
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
695
        /*
748
        /*
696
         * Now process the cell scanline, combining foreground
749
         * Now process the cell scanline, combining foreground
697
         * and background color patters using the pre-rendered mask.
750
         * and background color patters using the pre-rendered mask.
698
         */
751
         */
699
        for (i = 0; i < ww; i++) {
752
        for (i = 0; i < ww; i++) {
700
            mask = *maskp++;
753
            mask = *maskp++;
701
            *dp++ = (fg_buf & mask) | (bg_buf & ~mask);
754
            *dp++ = (fg_buf & mask) | (bg_buf & ~mask);
702
        }
755
        }
703
 
756
       
704
        /* Move to the beginning of the next scanline of the cell. */
757
        /* Move to the beginning of the next scanline of the cell. */
705
        dp = (unsigned long *) ((uint8_t *) dp + d_add);
758
        dp = (unsigned long *) ((uint8_t *) dp + d_add);
706
    }
759
    }
707
}
760
}
708
 
761
 
709
/** Draw a glyph, fallback version.
762
/** Draw a glyph, fallback version.
710
 *
763
 *
711
 * This version does not make use of the pre-rendered mask, it uses
764
 * This version does not make use of the pre-rendered mask, it uses
712
 * the font bitmap directly. It works always, but it is slower.
765
 * the font bitmap directly. It works always, but it is slower.
713
 *
766
 *
714
 * @param x     x coordinate of top-left corner on screen.
767
 * @param x        x coordinate of top-left corner on screen.
715
 * @param y     y coordinate of top-left corner on screen.
768
 * @param y        y coordinate of top-left corner on screen.
716
 * @param cursor    Draw glyph with cursor
769
 * @param cursor   Draw glyph with cursor
717
 * @param glyphs    Pointer to font bitmap.
770
 * @param glyphs   Pointer to font bitmap.
718
 * @param glyph     Code of the glyph to draw.
771
 * @param glyph    Code of the glyph to draw.
719
 * @param fg_color  Foreground color.
772
 * @param fg_color Foreground color.
720
 * @param bg_color  Backgroudn color.
773
 * @param bg_color Backgroudn color.
-
 
774
 *
721
 */
775
 */
722
void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
776
void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
723
    uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color)
777
    uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color)
724
{
778
{
-
 
779
    unsigned int i;
-
 
780
    unsigned int j;
725
    unsigned int i, j, yd;
781
    unsigned int yd;
726
    uint8_t fg_buf[4], bg_buf[4];
782
    uint8_t fg_buf[4];
727
    uint8_t *dp, *sp;
783
    uint8_t bg_buf[4];
728
    unsigned int d_add;
784
    uint8_t *sp;
729
    uint8_t b;
785
    uint8_t b;
730
 
786
   
731
    /* Pre-render 1x the foreground and background color pixels. */
787
    /* Pre-render 1x the foreground and background color pixels. */
732
    if (cursor) {
788
    if (cursor) {
733
        screen.rgb_conv(fg_buf, bg_color);
789
        screen.rgb_conv(fg_buf, bg_color);
734
        screen.rgb_conv(bg_buf, fg_color);
790
        screen.rgb_conv(bg_buf, fg_color);
735
    } else {
791
    } else {
736
        screen.rgb_conv(fg_buf, fg_color);
792
        screen.rgb_conv(fg_buf, fg_color);
737
        screen.rgb_conv(bg_buf, bg_color);
793
        screen.rgb_conv(bg_buf, bg_color);
738
    }
794
    }
739
 
795
   
740
    /* Pointer to the current position on the screen. */
796
    /* Pointer to the current position on the screen. */
741
    dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)];
797
    uint8_t *dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)];
742
 
798
   
743
    /* Offset to add when moving to another screen scanline. */
799
    /* Offset to add when moving to another screen scanline. */
744
    d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
800
    unsigned int d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
745
 
801
   
746
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
802
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
747
        /* Byte containing bits of the glyph scanline. */
803
        /* Byte containing bits of the glyph scanline. */
748
        b = fb_font[glyph * FONT_SCANLINES + yd];
804
        b = fb_font[glyph][yd];
749
 
805
       
750
        for (i = 0; i < FONT_WIDTH; i++) {
806
        for (i = 0; i < FONT_WIDTH; i++) {
751
            /* Choose color based on the current bit. */
807
            /* Choose color based on the current bit. */
752
            sp = (b & 0x80) ? fg_buf : bg_buf;
808
            sp = (b & 0x80) ? fg_buf : bg_buf;
753
 
809
           
754
            /* Copy the pixel. */
810
            /* Copy the pixel. */
755
            for (j = 0; j < screen.pixelbytes; j++) {
811
            for (j = 0; j < screen.pixelbytes; j++) {
756
                *dp++ = *sp++;
812
                *dp++ = *sp++;
757
            }
813
            }
758
 
814
           
759
            /* Move to the next bit. */
815
            /* Move to the next bit. */
760
            b = b << 1;
816
            b = b << 1;
761
        }
817
        }
762
       
818
       
763
        /* Move to the beginning of the next scanline of the cell. */
819
        /* Move to the beginning of the next scanline of the cell. */
764
        dp += d_add;
820
        dp += d_add;
765
    }
821
    }
766
}
822
}
767
 
823
 
768
/** Draw glyph at specified position in viewport.
824
/** Draw glyph at specified position in viewport.
769
 *
825
 *
770
 * @param vport  Viewport identification
826
 * @param vport  Viewport identification
771
 * @param cursor Draw glyph with cursor
827
 * @param cursor Draw glyph with cursor
772
 * @param col    Screen position relative to viewport
828
 * @param col    Screen position relative to viewport
773
 * @param row    Screen position relative to viewport
829
 * @param row    Screen position relative to viewport
Line 776... Line 832...
776
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
832
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
777
    unsigned int row)
833
    unsigned int row)
778
{
834
{
779
    unsigned int x = vport->x + COL2X(col);
835
    unsigned int x = vport->x + COL2X(col);
780
    unsigned int y = vport->y + ROW2Y(row);
836
    unsigned int y = vport->y + ROW2Y(row);
781
 
-
 
782
    uint8_t glyph;
-
 
783
    uint32_t fg_color;
-
 
784
    uint32_t bg_color;
-
 
785
   
837
   
786
    glyph = vport->backbuf[BB_POS(vport, col, row)].glyph;
838
    uint32_t glyph = vport->backbuf[BB_POS(vport, col, row)].glyph;
787
    fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color;
839
    uint32_t fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color;
788
    bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color;
840
    uint32_t bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color;
789
 
841
   
790
    (*vport->dglyph)(x, y, cursor, vport->glyphs, glyph,
842
    (*vport->dglyph)(x, y, cursor, screen.glyphs, glyph,
791
        fg_color, bg_color);
843
        fg_color, bg_color);
792
}
844
}
793
 
845
 
794
/** Hide cursor if it is shown
846
/** Hide cursor if it is shown
795
 *
847
 *
Line 834... Line 886...
834
 * @param c      Character to draw
886
 * @param c      Character to draw
835
 * @param col    Screen position relative to viewport
887
 * @param col    Screen position relative to viewport
836
 * @param row    Screen position relative to viewport
888
 * @param row    Screen position relative to viewport
837
 *
889
 *
838
 */
890
 */
839
static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row)
891
static void draw_char(viewport_t *vport, wchar_t c, unsigned int col, unsigned int row)
840
{
892
{
841
    bb_cell_t *bbp;
893
    bb_cell_t *bbp;
842
 
894
   
843
    /* Do not hide cursor if we are going to overwrite it */
895
    /* Do not hide cursor if we are going to overwrite it */
844
    if ((vport->cursor_active) && (vport->cursor_shown) &&
896
    if ((vport->cursor_active) && (vport->cursor_shown) &&
845
        ((vport->cur_col != col) || (vport->cur_row != row)))
897
        ((vport->cur_col != col) || (vport->cur_row != row)))
846
        cursor_hide(vport);
898
        cursor_hide(vport);
847
 
899
   
848
    bbp = &vport->backbuf[BB_POS(vport, col, row)];
900
    bbp = &vport->backbuf[BB_POS(vport, col, row)];
849
    bbp->glyph = c;
901
    bbp->glyph = fb_font_glyph(c);
850
    bbp->fg_color = vport->attr.fg_color;
902
    bbp->fg_color = vport->attr.fg_color;
851
    bbp->bg_color = vport->attr.bg_color;
903
    bbp->bg_color = vport->attr.bg_color;
852
 
904
   
853
    draw_vp_glyph(vport, false, col, row);
905
    draw_vp_glyph(vport, false, col, row);
854
   
906
   
855
    vport->cur_col = col;
907
    vport->cur_col = col;
856
    vport->cur_row = row;
908
    vport->cur_row = row;
857
   
909
   
Line 868... Line 920...
868
 
920
 
869
/** Draw text data to viewport.
921
/** Draw text data to viewport.
870
 *
922
 *
871
 * @param vport Viewport id
923
 * @param vport Viewport id
872
 * @param data  Text data.
924
 * @param data  Text data.
873
 * @param x Leftmost column of the area.
925
 * @param x     Leftmost column of the area.
874
 * @param y Topmost row of the area.
926
 * @param y     Topmost row of the area.
875
 * @param w Number of rows.
927
 * @param w     Number of rows.
876
 * @param h Number of columns.
928
 * @param h     Number of columns.
-
 
929
 *
877
 */
930
 */
878
static void draw_text_data(viewport_t *vport, keyfield_t *data, unsigned int x,
931
static void draw_text_data(viewport_t *vport, keyfield_t *data, unsigned int x,
879
    unsigned int y, unsigned int w, unsigned int h)
932
    unsigned int y, unsigned int w, unsigned int h)
880
{
933
{
-
 
934
    unsigned int i;
881
    unsigned int i, j;
935
    unsigned int j;
882
    bb_cell_t *bbp;
936
    bb_cell_t *bbp;
883
    attrs_t *a;
937
    attrs_t *a;
884
    attr_rgb_t rgb;
938
    attr_rgb_t rgb;
885
 
939
   
886
    for (j = 0; j < h; j++) {
940
    for (j = 0; j < h; j++) {
887
        for (i = 0; i < w; i++) {
941
        for (i = 0; i < w; i++) {
888
            unsigned int col = x + i;
942
            unsigned int col = x + i;
889
            unsigned int row = y + j;
943
            unsigned int row = y + j;
890
 
944
           
891
            bbp = &vport->backbuf[BB_POS(vport, col, row)];
945
            bbp = &vport->backbuf[BB_POS(vport, col, row)];
892
            uint8_t glyph = bbp->glyph;
-
 
893
 
946
           
894
            a = &data[j * w + i].attrs;
947
            a = &data[j * w + i].attrs;
895
            rgb_from_attr(&rgb, a);
948
            rgb_from_attr(&rgb, a);
896
 
949
           
897
            bbp->glyph = data[j * w + i].character;
950
            bbp->glyph = fb_font_glyph(data[j * w + i].character);
898
            bbp->fg_color = rgb.fg_color;
951
            bbp->fg_color = rgb.fg_color;
899
            bbp->bg_color = rgb.bg_color;
952
            bbp->bg_color = rgb.bg_color;
900
 
953
           
901
            draw_vp_glyph(vport, false, col, row);
954
            draw_vp_glyph(vport, false, col, row);
902
        }
955
        }
903
    }
956
    }
904
    cursor_show(vport);
957
    cursor_show(vport);
905
}
958
}
Line 1191... Line 1244...
1191
   
1244
   
1192
    /* Limit redrawing */
1245
    /* Limit redrawing */
1193
    counts = (counts + 1) % 8;
1246
    counts = (counts + 1) % 8;
1194
    if (counts)
1247
    if (counts)
1195
        return;
1248
        return;
1196
 
1249
   
1197
    for (i = 0; i < MAX_ANIMATIONS; i++) {
1250
    for (i = 0; i < MAX_ANIMATIONS; i++) {
1198
        if ((!animations[i].animlen) || (!animations[i].initialized) ||
1251
        if ((!animations[i].animlen) || (!animations[i].initialized) ||
1199
            (!animations[i].enabled))
1252
            (!animations[i].enabled))
1200
            continue;
1253
            continue;
1201
       
1254
       
Line 1508... Line 1561...
1508
        ipc_callid_t callid;
1561
        ipc_callid_t callid;
1509
        ipc_call_t call;
1562
        ipc_call_t call;
1510
        int retval;
1563
        int retval;
1511
        unsigned int i;
1564
        unsigned int i;
1512
        int scroll;
1565
        int scroll;
1513
        uint8_t glyph;
1566
        wchar_t ch;
1514
        unsigned int row, col;
1567
        unsigned int row, col;
1515
       
1568
       
1516
        if ((vport->cursor_active) || (anims_enabled))
1569
        if ((vport->cursor_active) || (anims_enabled))
1517
            callid = async_get_call_timeout(&call, 250000);
1570
            callid = async_get_call_timeout(&call, 250000);
1518
        else
1571
        else
Line 1545... Line 1598...
1545
           
1598
           
1546
            /* Exit thread */
1599
            /* Exit thread */
1547
            return;
1600
            return;
1548
       
1601
       
1549
        case FB_PUTCHAR:
1602
        case FB_PUTCHAR:
1550
            glyph = IPC_GET_ARG1(call);
1603
            ch = IPC_GET_ARG1(call);
1551
            row = IPC_GET_ARG2(call);
1604
            row = IPC_GET_ARG2(call);
1552
            col = IPC_GET_ARG3(call);
1605
            col = IPC_GET_ARG3(call);
1553
           
1606
           
1554
            if ((col >= vport->cols) || (row >= vport->rows)) {
1607
            if ((col >= vport->cols) || (row >= vport->rows)) {
1555
                retval = EINVAL;
1608
                retval = EINVAL;
1556
                break;
1609
                break;
1557
            }
1610
            }
1558
            ipc_answer_0(callid, EOK);
1611
            ipc_answer_0(callid, EOK);
1559
           
1612
           
1560
            draw_char(vport, glyph, col, row);
1613
            draw_char(vport, ch, col, row);
1561
           
1614
           
1562
            /* Message already answered */
1615
            /* Message already answered */
1563
            continue;
1616
            continue;
1564
        case FB_CLEAR:
1617
        case FB_CLEAR:
1565
            vport_clear(vport);
1618
            vport_clear(vport);
Line 1632... Line 1685...
1632
            if (!viewports[i].initialized) {
1685
            if (!viewports[i].initialized) {
1633
                retval = EADDRNOTAVAIL;
1686
                retval = EADDRNOTAVAIL;
1634
                break;
1687
                break;
1635
            }
1688
            }
1636
            viewports[i].initialized = false;
1689
            viewports[i].initialized = false;
1637
            if (viewports[i].glyphs)
-
 
1638
                free(viewports[i].glyphs);
-
 
1639
            if (viewports[i].bgpixel)
1690
            if (viewports[i].bgpixel)
1640
                free(viewports[i].bgpixel);
1691
                free(viewports[i].bgpixel);
1641
            if (viewports[i].backbuf)
1692
            if (viewports[i].backbuf)
1642
                free(viewports[i].backbuf);
1693
                free(viewports[i].backbuf);
1643
            retval = EOK;
1694
            retval = EOK;
Line 1660... Line 1711...
1660
        case FB_POINTER_MOVE:
1711
        case FB_POINTER_MOVE:
1661
            pointer_enabled = true;
1712
            pointer_enabled = true;
1662
            mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
1713
            mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
1663
            retval = EOK;
1714
            retval = EOK;
1664
            break;
1715
            break;
-
 
1716
        case FB_SCREEN_YIELD:
-
 
1717
        case FB_SCREEN_RECLAIM:
-
 
1718
            retval = EOK;
-
 
1719
            break;
1665
        default:
1720
        default:
1666
            retval = ENOENT;
1721
            retval = ENOENT;
1667
        }
1722
        }
1668
        ipc_answer_0(callid, retval);
1723
        ipc_answer_0(callid, retval);
1669
    }
1724
    }