Subversion Repositories HelenOS

Rev

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

Rev 4296 Rev 4678
Line 48... Line 48...
48
#include <bitops.h>
48
#include <bitops.h>
49
#include <print.h>
49
#include <print.h>
50
#include <string.h>
50
#include <string.h>
51
#include <ddi/ddi.h>
51
#include <ddi/ddi.h>
52
#include <arch/types.h>
52
#include <arch/types.h>
-
 
53
#include <byteorder.h>
53
 
54
 
54
SPINLOCK_INITIALIZE(fb_lock);
55
SPINLOCK_INITIALIZE(fb_lock);
55
 
56
 
56
static uint8_t *fb_addr;
57
static uint8_t *fb_addr;
57
static uint16_t *backbuf;
58
static uint16_t *backbuf;
Line 78... Line 79...
78
 
79
 
79
#define BG_COLOR     0x000080
80
#define BG_COLOR     0x000080
80
#define FG_COLOR     0xffff00
81
#define FG_COLOR     0xffff00
81
#define INV_COLOR    0xaaaaaa
82
#define INV_COLOR    0xaaaaaa
82
 
83
 
83
#define RED(x, bits)         ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
84
#define RED(x, bits)         (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1))
84
#define GREEN(x, bits)       ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
85
#define GREEN(x, bits)       (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1))
85
#define BLUE(x, bits)        ((x >> (8 - bits)) & ((1 << bits) - 1))
86
#define BLUE(x, bits)        (((x) >> (8 - (bits))) & ((1 << (bits)) - 1))
86
 
87
 
87
#define COL2X(col)           ((col) * FONT_WIDTH)
88
#define COL2X(col)           ((col) * FONT_WIDTH)
88
#define ROW2Y(row)           ((row) * FONT_SCANLINES)
89
#define ROW2Y(row)           ((row) * FONT_SCANLINES)
89
 
90
 
90
#define X2COL(x)             ((x) / FONT_WIDTH)
91
#define X2COL(x)             ((x) / FONT_WIDTH)
Line 95... Line 96...
95
#define GLYPH_POS(glyph, y)  ((glyph) * glyphbytes + (y) * glyphscanline)
96
#define GLYPH_POS(glyph, y)  ((glyph) * glyphbytes + (y) * glyphscanline)
96
 
97
 
97
 
98
 
98
static void (*rgb_conv)(void *, uint32_t);
99
static void (*rgb_conv)(void *, uint32_t);
99
 
100
 
100
 
101
/*
101
/** ARGB 8:8:8:8 conversion
102
 * RGB conversion functions.
102
 *
103
 *
-
 
104
 * These functions write an RGB value to some memory in some predefined format.
-
 
105
 * The naming convention corresponds to the format created by these functions.
-
 
106
 * The functions use the so called network order (i.e. big endian) with respect
-
 
107
 * to their names.
103
 */
108
 */
-
 
109
 
104
static void rgb_0888(void *dst, uint32_t rgb)
110
static void rgb_0888(void *dst, uint32_t rgb)
105
{
111
{
106
    *((uint32_t *) dst) = rgb & 0xffffff;
112
    *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
-
 
113
        (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8)));
107
}
114
}
108
 
115
 
109
 
-
 
110
/** ABGR 8:8:8:8 conversion
-
 
111
 *
-
 
112
 */
-
 
113
static void bgr_0888(void *dst, uint32_t rgb)
116
static void bgr_0888(void *dst, uint32_t rgb)
114
{
117
{
115
    *((uint32_t *) dst)
118
    *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
116
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
119
        (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8)));
117
}
120
}
118
 
121
 
119
 
-
 
120
/** RGB 8:8:8 conversion
-
 
121
 *
-
 
122
 */
-
 
123
static void rgb_888(void *dst, uint32_t rgb)
122
static void rgb_8880(void *dst, uint32_t rgb)
124
{
123
{
125
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
124
    *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) |
126
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
125
        (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0);
127
    ((uint8_t *) dst)[2] = RED(rgb, 8);
-
 
128
}
126
}
129
 
127
 
-
 
128
static void bgr_8880(void *dst, uint32_t rgb)
-
 
129
{
-
 
130
    *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) |
-
 
131
        (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0);
-
 
132
}
130
 
133
 
131
/** BGR 8:8:8 conversion
-
 
132
 *
-
 
133
 */
-
 
134
static void bgr_888(void *dst, uint32_t rgb)
134
static void rgb_888(void *dst, uint32_t rgb)
135
{
135
{
136
    ((uint8_t *) dst)[0] = RED(rgb, 8);
136
    ((uint8_t *) dst)[0] = RED(rgb, 8);
137
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
137
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
138
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
138
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
139
}
139
}
140
 
140
 
141
 
-
 
142
/** RGB 5:5:5 conversion
-
 
143
 *
-
 
144
 */
-
 
145
static void rgb_555(void *dst, uint32_t rgb)
141
static void bgr_888(void *dst, uint32_t rgb)
146
{
142
{
147
    *((uint16_t *) dst)
143
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
148
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
144
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
-
 
145
    ((uint8_t *) dst)[2] = RED(rgb, 8);
149
}
146
}
150
 
147
 
-
 
148
static void bgr_555(void *dst, uint32_t rgb)
-
 
149
{
-
 
150
    uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 5) << 5)) & 0xff;
-
 
151
    uint8_t lo = (GREEN(rgb, 5) >> 3) | (RED(rgb, 5) << 2);
-
 
152
    *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
-
 
153
}
151
 
154
 
152
/** RGB 5:6:5 conversion
-
 
153
 *
-
 
154
 */
-
 
155
static void rgb_565(void *dst, uint32_t rgb)
155
static void bgr_565(void *dst, uint32_t rgb)
156
{
156
{
157
    *((uint16_t *) dst)
157
    uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 6) << 5)) & 0xff;
158
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
158
    uint8_t lo = (GREEN(rgb, 6) >> 3) | (RED(rgb, 5) << 3);
-
 
159
    *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
159
}
160
}
160
 
161
 
161
 
162
 
162
/** RGB 3:2:3
163
/** BGR 3:2:3
163
 *
164
 *
164
 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
165
 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
165
 * will most likely use a color palette. The color appearance
166
 * will most likely use a color palette. The color appearance
166
 * will be pretty random and depend on the default installed
167
 * will be pretty random and depend on the default installed
167
 * palette. This could be fixed by supporting custom palette
168
 * palette. This could be fixed by supporting custom palette
Line 174... Line 175...
174
 * is 0 and the black color code is 255, as some machines (Sun Blade 1500)
175
 * is 0 and the black color code is 255, as some machines (Sun Blade 1500)
175
 * use these codes for black and white and prevent to set codes
176
 * use these codes for black and white and prevent to set codes
176
 * 0 and 255 to other colors.
177
 * 0 and 255 to other colors.
177
 *
178
 *
178
 */
179
 */
179
static void rgb_323(void *dst, uint32_t rgb)
180
static void bgr_323(void *dst, uint32_t rgb)
180
{
181
{
181
    *((uint8_t *) dst)
182
    *((uint8_t *) dst)
182
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
183
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
183
}
184
}
184
 
185
 
Line 448... Line 449...
448
 */
449
 */
449
void fb_init(fb_properties_t *props)
450
void fb_init(fb_properties_t *props)
450
{
451
{
451
    switch (props->visual) {
452
    switch (props->visual) {
452
    case VISUAL_INDIRECT_8:
453
    case VISUAL_INDIRECT_8:
453
        rgb_conv = rgb_323;
454
        rgb_conv = bgr_323;
454
        pixelbytes = 1;
455
        pixelbytes = 1;
455
        break;
456
        break;
456
    case VISUAL_RGB_5_5_5:
457
    case VISUAL_BGR_5_5_5:
457
        rgb_conv = rgb_555;
458
        rgb_conv = bgr_555;
458
        pixelbytes = 2;
459
        pixelbytes = 2;
459
        break;
460
        break;
460
    case VISUAL_RGB_5_6_5:
461
    case VISUAL_BGR_5_6_5:
461
        rgb_conv = rgb_565;
462
        rgb_conv = bgr_565;
462
        pixelbytes = 2;
463
        pixelbytes = 2;
463
        break;
464
        break;
464
    case VISUAL_RGB_8_8_8:
465
    case VISUAL_RGB_8_8_8:
465
        rgb_conv = rgb_888;
466
        rgb_conv = rgb_888;
466
        pixelbytes = 3;
467
        pixelbytes = 3;
Line 468... Line 469...
468
    case VISUAL_BGR_8_8_8:
469
    case VISUAL_BGR_8_8_8:
469
        rgb_conv = bgr_888;
470
        rgb_conv = bgr_888;
470
        pixelbytes = 3;
471
        pixelbytes = 3;
471
        break;
472
        break;
472
    case VISUAL_RGB_8_8_8_0:
473
    case VISUAL_RGB_8_8_8_0:
473
        rgb_conv = rgb_888;
474
        rgb_conv = rgb_8880;
474
        pixelbytes = 4;
475
        pixelbytes = 4;
475
        break;
476
        break;
476
    case VISUAL_RGB_0_8_8_8:
477
    case VISUAL_RGB_0_8_8_8:
477
        rgb_conv = rgb_0888;
478
        rgb_conv = rgb_0888;
478
        pixelbytes = 4;
479
        pixelbytes = 4;
479
        break;
480
        break;
480
    case VISUAL_BGR_0_8_8_8:
481
    case VISUAL_BGR_0_8_8_8:
481
        rgb_conv = bgr_0888;
482
        rgb_conv = bgr_0888;
482
        pixelbytes = 4;
483
        pixelbytes = 4;
483
        break;
484
        break;
-
 
485
    case VISUAL_BGR_8_8_8_0:
-
 
486
        rgb_conv = bgr_8880;
-
 
487
        pixelbytes = 4;
-
 
488
        break;
484
    default:
489
    default:
485
        panic("Unsupported visual.");
490
        panic("Unsupported visual.");
486
    }
491
    }
487
   
492
   
488
    xres = props->x;
493
    xres = props->x;