Subversion Repositories HelenOS

Rev

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

Rev 4337 Rev 4338
Line 49... Line 49...
49
#include <ipc/ipc.h>
49
#include <ipc/ipc.h>
50
#include <ipc/ns.h>
50
#include <ipc/ns.h>
51
#include <ipc/services.h>
51
#include <ipc/services.h>
52
#include <kernel/errno.h>
52
#include <kernel/errno.h>
53
#include <kernel/genarch/fb/visuals.h>
53
#include <kernel/genarch/fb/visuals.h>
-
 
54
#include <console/color.h>
-
 
55
#include <console/style.h>
54
#include <async.h>
56
#include <async.h>
55
#include <bool.h>
57
#include <bool.h>
56
 
58
 
57
#include "font-8x16.h"
59
#include "font-8x16.h"
58
#include "fb.h"
60
#include "fb.h"
Line 69... Line 71...
69
#define MAX_ANIM_LEN     8
71
#define MAX_ANIM_LEN     8
70
#define MAX_ANIMATIONS   4
72
#define MAX_ANIMATIONS   4
71
#define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
73
#define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
72
#define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
74
#define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
73
 
75
 
-
 
76
/** Function to render a pixel from a RGB value. */
74
typedef void (*rgb_conv_t)(void *, uint32_t);
77
typedef void (*rgb_conv_t)(void *, uint32_t);
75
 
78
 
-
 
79
/** Function to draw a glyph. */
-
 
80
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);
-
 
82
 
76
struct {
83
struct {
77
    uint8_t *fb_addr;
84
    uint8_t *fb_addr;
78
   
85
   
79
    unsigned int xres;
86
    unsigned int xres;
80
    unsigned int yres;
87
    unsigned int yres;
Line 86... Line 93...
86
    unsigned int glyphbytes;
93
    unsigned int glyphbytes;
87
   
94
   
88
    rgb_conv_t rgb_conv;
95
    rgb_conv_t rgb_conv;
89
} screen;
96
} screen;
90
 
97
 
-
 
98
/** Backbuffer character cell. */
-
 
99
typedef struct {
-
 
100
    uint8_t glyph;
-
 
101
    uint32_t fg_color;
-
 
102
    uint32_t bg_color;
-
 
103
} bb_cell_t;
-
 
104
 
91
typedef struct {
105
typedef struct {
92
    bool initialized;
106
    bool initialized;
93
    unsigned int x;
107
    unsigned int x;
94
    unsigned int y;
108
    unsigned int y;
95
    unsigned int width;
109
    unsigned int width;
Line 97... Line 111...
97
   
111
   
98
    /* Text support in window */
112
    /* Text support in window */
99
    unsigned int cols;
113
    unsigned int cols;
100
    unsigned int rows;
114
    unsigned int rows;
101
   
115
   
-
 
116
    /*
102
    /* Style and glyphs for text printing */
117
     * Style and glyphs for text printing
-
 
118
     */
-
 
119
 
-
 
120
    /** Current attributes. */
103
    style_t style;
121
    attr_rgb_t attr;
-
 
122
 
-
 
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.*/
104
    uint8_t *glyphs;
126
    uint8_t *glyphs;
-
 
127
 
105
    uint8_t *bgpixel;
128
    uint8_t *bgpixel;
-
 
129
 
-
 
130
    /** Glyph drawing function for this viewport. */
-
 
131
    dg_t dglyph;
106
   
132
   
107
    /* Auto-cursor position */
133
    /* Auto-cursor position */
108
    bool cursor_active;
134
    bool cursor_active;
109
    unsigned int cur_col;
135
    unsigned int cur_col;
110
    unsigned int cur_row;
136
    unsigned int cur_row;
111
    bool cursor_shown;
137
    bool cursor_shown;
112
   
138
   
113
    /* Back buffer */
139
    /* Back buffer */
-
 
140
    bb_cell_t *backbuf;
114
    unsigned int bbsize;
141
    unsigned int bbsize;
115
    uint8_t *backbuf;
-
 
116
} viewport_t;
142
} viewport_t;
117
 
143
 
118
typedef struct {
144
typedef struct {
119
    bool initialized;
145
    bool initialized;
120
    bool enabled;
146
    bool enabled;
Line 137... Line 163...
137
static pixmap_t pixmaps[MAX_PIXMAPS];
163
static pixmap_t pixmaps[MAX_PIXMAPS];
138
static viewport_t viewports[128];
164
static viewport_t viewports[128];
139
 
165
 
140
static bool client_connected = false;  /**< Allow only 1 connection */
166
static bool client_connected = false;  /**< Allow only 1 connection */
141
 
167
 
-
 
168
static uint32_t color_table[16] = {
-
 
169
    [COLOR_BLACK]       = 0x000000,
-
 
170
    [COLOR_BLUE]        = 0x0000f0,
-
 
171
    [COLOR_GREEN]       = 0x00f000,
-
 
172
    [COLOR_CYAN]        = 0x00f0f0,
-
 
173
    [COLOR_RED]     = 0xf00000,
-
 
174
    [COLOR_MAGENTA]     = 0xf000f0,
-
 
175
    [COLOR_YELLOW]      = 0xf0f000,
-
 
176
    [COLOR_WHITE]       = 0xf0f0f0,
-
 
177
 
-
 
178
    [8 + COLOR_BLACK]   = 0x000000,
-
 
179
    [8 + COLOR_BLUE]    = 0x0000ff,
-
 
180
    [8 + COLOR_GREEN]   = 0x00ff00,
-
 
181
    [8 + COLOR_CYAN]    = 0x00ffff,
-
 
182
    [8 + COLOR_RED]     = 0xff0000,
-
 
183
    [8 + COLOR_MAGENTA] = 0xff00ff,
-
 
184
    [8 + COLOR_YELLOW]  = 0xffff00,
-
 
185
    [8 + COLOR_WHITE]   = 0xffffff,
-
 
186
};
-
 
187
 
-
 
188
static int rgb_from_style(attr_rgb_t *rgb, int style);
-
 
189
static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color,
-
 
190
    ipcarg_t bg_color, ipcarg_t flags);
-
 
191
 
-
 
192
static int fb_set_color(viewport_t *vport, ipcarg_t fg_color,
-
 
193
    ipcarg_t bg_color, ipcarg_t attr);
-
 
194
 
142
static void draw_glyph(unsigned int x, unsigned int y, bool cursor,
195
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
-
 
196
    uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color);
-
 
197
static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
143
    uint8_t *glyphs, uint8_t glyph);
198
    uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color);
-
 
199
 
144
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
200
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
145
    unsigned int row);
201
    unsigned int row);
146
 
202
 
147
 
203
 
148
#define RED(x, bits)                 ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
204
#define RED(x, bits)                 ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
Line 277... Line 333...
277
 
333
 
278
    if (COL2X(vport->cols) < vport->width) {
334
    if (COL2X(vport->cols) < vport->width) {
279
        draw_filled_rect(
335
        draw_filled_rect(
280
            vport->x + COL2X(vport->cols), vport->y,
336
            vport->x + COL2X(vport->cols), vport->y,
281
            vport->x + vport->width, vport->y + vport->height,
337
            vport->x + vport->width, vport->y + vport->height,
282
            vport->style.bg_color);
338
            vport->attr.bg_color);
283
    }
339
    }
284
 
340
 
285
    if (ROW2Y(vport->rows) < vport->height) {
341
    if (ROW2Y(vport->rows) < vport->height) {
286
        draw_filled_rect(
342
        draw_filled_rect(
287
            vport->x, vport->y + ROW2Y(vport->rows),
343
            vport->x, vport->y + ROW2Y(vport->rows),
288
            vport->x + vport->width, vport->y + vport->height,
344
            vport->x + vport->width, vport->y + vport->height,
289
            vport->style.bg_color);
345
            vport->attr.bg_color);
290
    }
346
    }
291
}
347
}
292
 
348
 
-
 
349
static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color,
-
 
350
    uint32_t bg_color)
-
 
351
{
-
 
352
    unsigned i;
-
 
353
 
-
 
354
    for (i = 0; i < len; i++) {
-
 
355
        backbuf[i].glyph = 0;
-
 
356
        backbuf[i].fg_color = fg_color;
-
 
357
        backbuf[i].bg_color = bg_color;
-
 
358
    }
-
 
359
}
293
 
360
 
294
/** Clear viewport.
361
/** Clear viewport.
295
 *
362
 *
296
 * @param vport Viewport to clear
363
 * @param vport Viewport to clear
297
 *
364
 *
298
 */
365
 */
299
static void vport_clear(viewport_t *vport)
366
static void vport_clear(viewport_t *vport)
300
{
367
{
301
    memset(vport->backbuf, 0, vport->bbsize);
368
    backbuf_clear(vport->backbuf, vport->cols * vport->rows,
-
 
369
        vport->attr.fg_color, vport->attr.bg_color);
302
    vport_redraw(vport);
370
    vport_redraw(vport);
303
}
371
}
304
 
372
 
305
/** Scroll viewport by the specified number of lines.
373
/** Scroll viewport by the specified number of lines.
306
 *
374
 *
Line 311... Line 379...
311
static void vport_scroll(viewport_t *vport, int lines)
379
static void vport_scroll(viewport_t *vport, int lines)
312
{
380
{
313
    unsigned int row, col;
381
    unsigned int row, col;
314
    unsigned int x, y;
382
    unsigned int x, y;
315
    uint8_t glyph;
383
    uint8_t glyph;
-
 
384
    uint32_t fg_color;
-
 
385
    uint32_t bg_color;
-
 
386
    bb_cell_t *bbp, *xbp;
316
 
387
 
317
    /*
388
    /*
318
     * Redraw.
389
     * Redraw.
319
     */
390
     */
320
 
391
 
321
    y = vport->y;
392
    y = vport->y;
322
    for (row = 0; row < vport->rows; row++) {
393
    for (row = 0; row < vport->rows; row++) {
323
        x = vport->x;
394
        x = vport->x;
324
        for (col = 0; col < vport->cols; col++) {
395
        for (col = 0; col < vport->cols; col++) {
325
            if ((row + lines >= 0) && (row + lines < vport->rows)) {
396
            if ((row + lines >= 0) && (row + lines < vport->rows)) {
326
                glyph = vport->backbuf[BB_POS(vport, col, row + lines)];
397
                xbp = &vport->backbuf[BB_POS(vport, col, row + lines)];
-
 
398
                bbp = &vport->backbuf[BB_POS(vport, col, row)];
327
 
399
 
-
 
400
                glyph = xbp->glyph;
-
 
401
                fg_color = xbp->fg_color;
-
 
402
                bg_color = xbp->bg_color;
-
 
403
 
-
 
404
                if (bbp->glyph == glyph &&
-
 
405
                    bbp->fg_color == xbp->fg_color &&
328
                if (vport->backbuf[BB_POS(vport, col, row)] == glyph) {
406
                    bbp->bg_color == xbp->bg_color) {
329
                    x += FONT_WIDTH;
407
                    x += FONT_WIDTH;
330
                    continue;
408
                    continue;
331
                }
409
                }
332
            } else {
410
            } else {
333
                glyph = 0;
411
                glyph = 0;
-
 
412
                fg_color = vport->attr.fg_color;
-
 
413
                bg_color = vport->attr.bg_color;
334
            }
414
            }
335
 
415
 
336
            draw_glyph(x, y, false, vport->glyphs, glyph);
416
            (*vport->dglyph)(x, y, false, vport->glyphs, glyph,
-
 
417
                fg_color, bg_color);
337
            x += FONT_WIDTH;
418
            x += FONT_WIDTH;
338
        }
419
        }
339
        y += FONT_SCANLINES;
420
        y += FONT_SCANLINES;
340
    }
421
    }
341
 
422
 
Line 343... Line 424...
343
     * Scroll backbuffer.
424
     * Scroll backbuffer.
344
     */
425
     */
345
 
426
 
346
    if (lines > 0) {
427
    if (lines > 0) {
347
        memmove(vport->backbuf, vport->backbuf + vport->cols * lines,
428
        memmove(vport->backbuf, vport->backbuf + vport->cols * lines,
348
            vport->cols * (vport->rows - lines));
429
            vport->cols * (vport->rows - lines) * sizeof(bb_cell_t));
349
        memset(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)],
430
        backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)],
350
            0, vport->cols * lines);
431
            vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color);
351
    } else {
432
    } else {
352
        memmove(vport->backbuf - vport->cols * lines, vport->backbuf,
433
        memmove(vport->backbuf - vport->cols * lines, vport->backbuf,
353
            vport->cols * (vport->rows + lines));
434
            vport->cols * (vport->rows + lines) * sizeof(bb_cell_t));
354
        memset(vport->backbuf, 0, - vport->cols * lines);
435
        backbuf_clear(vport->backbuf, - vport->cols * lines,
-
 
436
            vport->attr.fg_color, vport->attr.bg_color);
355
    }
437
    }
356
}
438
}
357
 
439
 
358
/** Render glyphs
440
/** Render glyphs
359
 *
441
 *
Line 374... Line 456...
374
            unsigned int x;
456
            unsigned int x;
375
           
457
           
376
            for (x = 0; x < FONT_WIDTH; x++) {
458
            for (x = 0; x < FONT_WIDTH; x++) {
377
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
459
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
378
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
460
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
379
                    ? vport->style.fg_color : vport->style.bg_color);
-
 
380
               
-
 
381
                uint32_t curcolor;
461
                    ? 0xffffff : 0x000000);
382
               
462
               
383
                if (y < FONT_SCANLINES - 2)
463
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes],
384
                    curcolor =
-
 
385
                        (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
464
                    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
386
                        ? vport->style.fg_color : vport->style.bg_color;
-
 
387
                else
-
 
388
                    curcolor = vport->style.fg_color;
465
                    ? 0x000000 : 0xffffff);
389
               
-
 
390
                screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], curcolor);
-
 
391
            }
466
            }
392
        }
467
        }
393
    }
468
    }
394
   
469
   
395
    screen.rgb_conv(vport->bgpixel, vport->style.bg_color);
470
    screen.rgb_conv(vport->bgpixel, vport->attr.bg_color);
396
}
471
}
397
 
472
 
398
 
473
 
399
/** Create new viewport
474
/** Create new viewport
400
 *
475
 *
Line 418... Line 493...
418
    if (i == MAX_VIEWPORTS)
493
    if (i == MAX_VIEWPORTS)
419
        return ELIMIT;
494
        return ELIMIT;
420
   
495
   
421
    unsigned int cols = width / FONT_WIDTH;
496
    unsigned int cols = width / FONT_WIDTH;
422
    unsigned int rows = height / FONT_SCANLINES;
497
    unsigned int rows = height / FONT_SCANLINES;
423
    unsigned int bbsize = cols * rows;
498
    unsigned int bbsize = cols * rows * sizeof(bb_cell_t);
424
    unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
499
    unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
-
 
500
    unsigned int word_size = sizeof(unsigned long);
425
   
501
   
426
    uint8_t *backbuf = (uint8_t *) malloc(bbsize);
502
    bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize);
427
    if (!backbuf)
503
    if (!backbuf)
428
        return ENOMEM;
504
        return ENOMEM;
429
   
505
   
430
    uint8_t *glyphs = (uint8_t *) malloc(glyphsize);
506
    uint8_t *glyphs = (uint8_t *) malloc(glyphsize);
431
    if (!glyphs) {
507
    if (!glyphs) {
Line 437... Line 513...
437
    if (!bgpixel) {
513
    if (!bgpixel) {
438
        free(glyphs);
514
        free(glyphs);
439
        free(backbuf);
515
        free(backbuf);
440
        return ENOMEM;
516
        return ENOMEM;
441
    }
517
    }
442
   
518
 
443
    memset(backbuf, 0, bbsize);
519
    backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR);
444
    memset(glyphs, 0, glyphsize);
520
    memset(glyphs, 0, glyphsize);
445
    memset(bgpixel, 0, screen.pixelbytes);
521
    memset(bgpixel, 0, screen.pixelbytes);
446
   
522
   
447
    viewports[i].x = x;
523
    viewports[i].x = x;
448
    viewports[i].y = y;
524
    viewports[i].y = y;
Line 450... Line 526...
450
    viewports[i].height = height;
526
    viewports[i].height = height;
451
   
527
   
452
    viewports[i].cols = cols;
528
    viewports[i].cols = cols;
453
    viewports[i].rows = rows;
529
    viewports[i].rows = rows;
454
   
530
   
455
    viewports[i].style.bg_color = DEFAULT_BGCOLOR;
531
    viewports[i].attr.bg_color = DEFAULT_BGCOLOR;
456
    viewports[i].style.fg_color = DEFAULT_FGCOLOR;
532
    viewports[i].attr.fg_color = DEFAULT_FGCOLOR;
457
   
533
   
458
    viewports[i].glyphs = glyphs;
534
    viewports[i].glyphs = glyphs;
459
    viewports[i].bgpixel = bgpixel;
535
    viewports[i].bgpixel = bgpixel;
-
 
536
 
-
 
537
    /*
-
 
538
     * Conditions necessary  to select aligned version:
-
 
539
     *
-
 
540
     *   - word size is divisible by pixelbytes
-
 
541
     *   - cell scanline size is divisible by word size
-
 
542
     *   - cell scanlines are word-aligned
-
 
543
     */
-
 
544
    if ((word_size % screen.pixelbytes) == 0 &&
-
 
545
        (FONT_WIDTH * screen.pixelbytes) % word_size == 0 &&
-
 
546
        (x * screen.pixelbytes) % word_size == 0 &&
-
 
547
        screen.scanline % word_size == 0) {
-
 
548
 
-
 
549
        viewports[i].dglyph = draw_glyph_aligned;
-
 
550
    } else {
-
 
551
        viewports[i].dglyph = draw_glyph_fallback;
460
   
552
    }
-
 
553
 
461
    viewports[i].cur_col = 0;
554
    viewports[i].cur_col = 0;
462
    viewports[i].cur_row = 0;
555
    viewports[i].cur_row = 0;
463
    viewports[i].cursor_active = false;
556
    viewports[i].cursor_active = false;
464
    viewports[i].cursor_shown = false;
557
    viewports[i].cursor_shown = false;
465
   
558
   
Line 532... Line 625...
532
   
625
   
533
    return true;
626
    return true;
534
}
627
}
535
 
628
 
536
 
629
 
537
/** Draw a glyph.
630
/** Draw a glyph, takes advantage of alignment.
538
 *
631
 *
539
 * @param x  x coordinate of top-left corner on screen.
-
 
540
 * @param y  y coordinate of top-left corner on screen.
632
 * This version can only be used if the following conditions are met:
541
 * @param cursor Draw glyph with cursor
-
 
542
 * @param glyphs Pointer to font bitmap.
-
 
543
 * @param glyph  Code of the glyph to draw.
-
 
544
 *
633
 *
-
 
634
 *   - word size is divisible by pixelbytes
-
 
635
 *   - cell scanline size is divisible by word size
-
 
636
 *   - cell scanlines are word-aligned
-
 
637
 *
-
 
638
 * It makes use of the pre-rendered mask to process (possibly) several
-
 
639
 * pixels at once (word size / pixelbytes pixels at a time are processed)
-
 
640
 * making it very fast. Most notably this version is not applicable at 24 bits
-
 
641
 * per pixel.
-
 
642
 *
-
 
643
 * @param x     x coordinate of top-left corner on screen.
-
 
644
 * @param y     y coordinate of top-left corner on screen.
-
 
645
 * @param cursor    Draw glyph with cursor
-
 
646
 * @param glyphs    Pointer to font bitmap.
-
 
647
 * @param glyph     Code of the glyph to draw.
-
 
648
 * @param fg_color  Foreground color.
-
 
649
 * @param bg_color  Backgroudn color.
-
 
650
 */
-
 
651
static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,
-
 
652
    uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color)
-
 
653
{
-
 
654
    unsigned int i, yd;
-
 
655
    unsigned long fg_buf, bg_buf;
-
 
656
    unsigned long *maskp, *dp;
-
 
657
    unsigned long mask;
-
 
658
    unsigned int ww, d_add;
-
 
659
 
-
 
660
    /*
-
 
661
     * Prepare a pair of words, one filled with foreground-color
-
 
662
     * pattern and the other filled with background-color pattern.
-
 
663
     */
-
 
664
    for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) {
-
 
665
        screen.rgb_conv(&((uint8_t *)&fg_buf)[i * screen.pixelbytes],
-
 
666
            fg_color);
-
 
667
        screen.rgb_conv(&((uint8_t *)&bg_buf)[i * screen.pixelbytes],
-
 
668
            bg_color);
-
 
669
    }
-
 
670
 
-
 
671
 
-
 
672
    /* Pointer to the current position in the mask. */
-
 
673
    maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)];
-
 
674
 
-
 
675
    /* Pointer to the current position on the screen. */
-
 
676
    dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)];
-
 
677
 
-
 
678
    /* Width of the character cell in words. */
-
 
679
    ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long);
-
 
680
 
-
 
681
    /* Offset to add when moving to another screen scanline. */
-
 
682
    d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
-
 
683
 
-
 
684
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
-
 
685
        /*
-
 
686
         * Now process the cell scanline, combining foreground
-
 
687
         * and background color patters using the pre-rendered mask.
-
 
688
         */
-
 
689
        for (i = 0; i < ww; i++) {
-
 
690
            mask = *maskp++;
-
 
691
            *dp++ = (fg_buf & mask) | (bg_buf & ~mask);
-
 
692
        }
-
 
693
 
-
 
694
        /* Move to the beginning of the next scanline of the cell. */
-
 
695
        dp = (unsigned long *) ((uint8_t *) dp + d_add);
-
 
696
    }
-
 
697
}
-
 
698
 
-
 
699
/** Draw a glyph, fallback version.
-
 
700
 *
-
 
701
 * This version does not make use of the pre-rendered mask, it uses
-
 
702
 * the font bitmap directly. It works always, but it is slower.
-
 
703
 *
-
 
704
 * @param x     x coordinate of top-left corner on screen.
-
 
705
 * @param y     y coordinate of top-left corner on screen.
-
 
706
 * @param cursor    Draw glyph with cursor
-
 
707
 * @param glyphs    Pointer to font bitmap.
-
 
708
 * @param glyph     Code of the glyph to draw.
-
 
709
 * @param fg_color  Foreground color.
-
 
710
 * @param bg_color  Backgroudn color.
545
 */
711
 */
546
static void draw_glyph(unsigned int x, unsigned int y, bool cursor,
712
void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,
547
    uint8_t *glyphs, uint8_t glyph)
713
    uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color)
548
{
714
{
-
 
715
    unsigned int i, j, yd;
-
 
716
    uint8_t fg_buf[4], bg_buf[4];
-
 
717
    uint8_t *dp, *sp;
549
    unsigned int yd;
718
    unsigned int d_add;
-
 
719
    uint8_t b;
-
 
720
 
-
 
721
    /* Pre-render 1x the foreground and background color pixels. */
-
 
722
    if (cursor) {
-
 
723
        screen.rgb_conv(fg_buf, bg_color);
-
 
724
        screen.rgb_conv(bg_buf, fg_color);
-
 
725
    } else {
-
 
726
        screen.rgb_conv(fg_buf, fg_color);
-
 
727
        screen.rgb_conv(bg_buf, bg_color);
550
   
728
    }
-
 
729
 
-
 
730
    /* Pointer to the current position on the screen. */
-
 
731
    dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)];
-
 
732
 
-
 
733
    /* Offset to add when moving to another screen scanline. */
-
 
734
    d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;
-
 
735
 
551
    for (yd = 0; yd < FONT_SCANLINES; yd++)
736
    for (yd = 0; yd < FONT_SCANLINES; yd++) {
-
 
737
        /* Byte containing bits of the glyph scanline. */
552
        memcpy(&screen.fb_addr[FB_POS(x, y + yd)],
738
        b = fb_font[glyph * FONT_SCANLINES + yd];
-
 
739
 
-
 
740
        for (i = 0; i < FONT_WIDTH; i++) {
-
 
741
            /* Choose color based on the current bit. */
-
 
742
            sp = (b & 0x80) ? fg_buf : bg_buf;
-
 
743
 
-
 
744
            /* Copy the pixel. */
-
 
745
            for (j = 0; j < screen.pixelbytes; j++) {
-
 
746
                *dp++ = *sp++;
-
 
747
            }
-
 
748
 
-
 
749
            /* Move to the next bit. */
-
 
750
            b = b << 1;
-
 
751
        }
-
 
752
       
553
            &glyphs[GLYPH_POS(glyph, yd, cursor)], screen.glyphscanline);
753
        /* Move to the beginning of the next scanline of the cell. */
-
 
754
        dp += d_add;
-
 
755
    }
554
}
756
}
555
 
757
 
556
/** Draw glyph at specified position in viewport.
758
/** Draw glyph at specified position in viewport.
557
 *
759
 *
558
 * @param vport  Viewport identification
760
 * @param vport  Viewport identification
Line 564... Line 766...
564
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
766
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
565
    unsigned int row)
767
    unsigned int row)
566
{
768
{
567
    unsigned int x = vport->x + COL2X(col);
769
    unsigned int x = vport->x + COL2X(col);
568
    unsigned int y = vport->y + ROW2Y(row);
770
    unsigned int y = vport->y + ROW2Y(row);
-
 
771
 
569
    uint8_t glyph;
772
    uint8_t glyph;
-
 
773
    uint32_t fg_color;
-
 
774
    uint32_t bg_color;
570
   
775
   
571
    glyph = vport->backbuf[BB_POS(vport, col, row)];
776
    glyph = vport->backbuf[BB_POS(vport, col, row)].glyph;
572
    draw_glyph(x, y, cursor, vport->glyphs, glyph);
777
    fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color;
573
}
-
 
-
 
778
    bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color;
574
 
779
 
-
 
780
    (*vport->dglyph)(x, y, cursor, vport->glyphs, glyph,
-
 
781
        fg_color, bg_color);
-
 
782
}
575
 
783
 
576
/** Hide cursor if it is shown
784
/** Hide cursor if it is shown
577
 *
785
 *
578
 */
786
 */
579
static void cursor_hide(viewport_t *vport)
787
static void cursor_hide(viewport_t *vport)
Line 618... Line 826...
618
 * @param row    Screen position relative to viewport
826
 * @param row    Screen position relative to viewport
619
 *
827
 *
620
 */
828
 */
621
static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row)
829
static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row)
622
{
830
{
-
 
831
    bb_cell_t *bbp;
-
 
832
 
623
    /* Do not hide cursor if we are going to overwrite it */
833
    /* Do not hide cursor if we are going to overwrite it */
624
    if ((vport->cursor_active) && (vport->cursor_shown) &&
834
    if ((vport->cursor_active) && (vport->cursor_shown) &&
625
        ((vport->cur_col != col) || (vport->cur_row != row)))
835
        ((vport->cur_col != col) || (vport->cur_row != row)))
626
        cursor_hide(vport);
836
        cursor_hide(vport);
627
   
837
 
628
    vport->backbuf[BB_POS(vport, col, row)] = c;
838
    bbp = &vport->backbuf[BB_POS(vport, col, row)];
-
 
839
    bbp->glyph = c;
-
 
840
    bbp->fg_color = vport->attr.fg_color;
-
 
841
    bbp->bg_color = vport->attr.bg_color;
-
 
842
 
629
    draw_vp_glyph(vport, false, col, row);
843
    draw_vp_glyph(vport, false, col, row);
630
   
844
   
631
    vport->cur_col = col;
845
    vport->cur_col = col;
632
    vport->cur_row = row;
846
    vport->cur_row = row;
633
   
847
   
Line 650... Line 864...
650
 *
864
 *
651
 */
865
 */
652
static void draw_text_data(viewport_t *vport, keyfield_t *data)
866
static void draw_text_data(viewport_t *vport, keyfield_t *data)
653
{
867
{
654
    unsigned int i;
868
    unsigned int i;
-
 
869
    bb_cell_t *bbp;
-
 
870
    attrs_t *a;
-
 
871
    attr_rgb_t rgb;
655
   
872
   
656
    for (i = 0; i < vport->cols * vport->rows; i++) {
873
    for (i = 0; i < vport->cols * vport->rows; i++) {
657
        unsigned int col = i % vport->cols;
874
        unsigned int col = i % vport->cols;
658
        unsigned int row = i / vport->cols;
875
        unsigned int row = i / vport->cols;
659
       
876
       
660
        uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)];
877
        bbp = &vport->backbuf[BB_POS(vport, col, row)];
661
       
-
 
662
        // TODO: use data[i].style
878
        uint8_t glyph = bbp->glyph;
663
       
879
 
664
        if (glyph != data[i].character) {
880
        if (glyph != data[i].character) {
665
            vport->backbuf[BB_POS(vport, col, row)] = data[i].character;
881
            bbp->glyph = data[i].character;
-
 
882
            a = &data[i].attrs;
-
 
883
 
-
 
884
            switch (a->t) {
-
 
885
            case at_style:
-
 
886
                rgb_from_style(&rgb, a->a.s.style);
-
 
887
                break;
-
 
888
            case at_idx:
-
 
889
                rgb_from_idx(&rgb, a->a.i.fg_color,
-
 
890
                    a->a.i.bg_color, a->a.i.flags);
-
 
891
                break;
-
 
892
            case at_rgb:
-
 
893
                rgb = a->a.r;
-
 
894
                break;
-
 
895
            }
-
 
896
 
-
 
897
            bbp->fg_color = rgb.fg_color;
-
 
898
            bbp->bg_color = rgb.bg_color;
-
 
899
 
666
            draw_vp_glyph(vport, false, col, row);
900
            draw_vp_glyph(vport, false, col, row);
667
        }
901
        }
668
    }
902
    }
669
    cursor_show(vport);
903
    cursor_show(vport);
670
}
904
}
Line 1178... Line 1412...
1178
        ipc_answer_0(callid, retval);
1412
        ipc_answer_0(callid, retval);
1179
    return handled;
1413
    return handled;
1180
   
1414
   
1181
}
1415
}
1182
 
1416
 
-
 
1417
static int rgb_from_style(attr_rgb_t *rgb, int style)
-
 
1418
{
-
 
1419
    switch (style) {
-
 
1420
    case STYLE_NORMAL:
-
 
1421
        rgb->fg_color = color_table[COLOR_BLACK];
-
 
1422
        rgb->bg_color = color_table[COLOR_WHITE];
-
 
1423
        break;
-
 
1424
    case STYLE_EMPHASIS:
-
 
1425
        rgb->fg_color = color_table[COLOR_RED];
-
 
1426
        rgb->bg_color = color_table[COLOR_WHITE];
-
 
1427
        break;
-
 
1428
    default:
-
 
1429
        return EINVAL;
-
 
1430
    }
-
 
1431
 
-
 
1432
    return EOK;
-
 
1433
}
-
 
1434
 
-
 
1435
static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color,
-
 
1436
    ipcarg_t bg_color, ipcarg_t flags)
-
 
1437
{
-
 
1438
    fg_color = (fg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0);
-
 
1439
    bg_color = (bg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0);
-
 
1440
 
-
 
1441
    rgb->fg_color = color_table[fg_color];
-
 
1442
    rgb->bg_color = color_table[bg_color];
-
 
1443
 
-
 
1444
    return EOK;
-
 
1445
}
-
 
1446
 
-
 
1447
static int fb_set_style(viewport_t *vport, ipcarg_t style)
-
 
1448
{
-
 
1449
    return rgb_from_style(&vport->attr, (int) style);
-
 
1450
}
-
 
1451
 
-
 
1452
static int fb_set_color(viewport_t *vport, ipcarg_t fg_color,
-
 
1453
    ipcarg_t bg_color, ipcarg_t flags)
-
 
1454
{
-
 
1455
    return rgb_from_idx(&vport->attr, fg_color, bg_color, flags);
-
 
1456
}
-
 
1457
 
1183
/** Function for handling connections to FB
1458
/** Function for handling connections to FB
1184
 *
1459
 *
1185
 */
1460
 */
1186
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
1461
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
1187
{
1462
{
Line 1334... Line 1609...
1334
            if (viewports[i].backbuf)
1609
            if (viewports[i].backbuf)
1335
                free(viewports[i].backbuf);
1610
                free(viewports[i].backbuf);
1336
            retval = EOK;
1611
            retval = EOK;
1337
            break;
1612
            break;
1338
        case FB_SET_STYLE:
1613
        case FB_SET_STYLE:
-
 
1614
            retval = fb_set_style(vport, IPC_GET_ARG1(call));
-
 
1615
            break;
-
 
1616
        case FB_SET_COLOR:
1339
            vport->style.fg_color = IPC_GET_ARG1(call);
1617
            retval = fb_set_color(vport, IPC_GET_ARG1(call),
-
 
1618
                IPC_GET_ARG2(call), IPC_GET_ARG3(call));
-
 
1619
            break;
-
 
1620
        case FB_SET_RGB_COLOR:
1340
            vport->style.bg_color = IPC_GET_ARG2(call);
1621
            vport->attr.fg_color = IPC_GET_ARG1(call);
1341
            render_glyphs(vport);
1622
            vport->attr.bg_color = IPC_GET_ARG2(call);
1342
            retval = EOK;
1623
            retval = EOK;
1343
            break;
1624
            break;
1344
        case FB_GET_RESOLUTION:
1625
        case FB_GET_RESOLUTION:
1345
            ipc_answer_2(callid, EOK, screen.xres, screen.yres);
1626
            ipc_answer_2(callid, EOK, screen.xres, screen.yres);
1346
            continue;
1627
            continue;