Subversion Repositories HelenOS

Rev

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

Rev 4348 Rev 4691
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
 
-
 
122
static void rgb_8880(void *dst, uint32_t rgb)
-
 
123
{
-
 
124
    *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) |
-
 
125
        (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0);
-
 
126
}
-
 
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
}
119
 
133
 
120
/** RGB 8:8:8 conversion
-
 
121
 *
-
 
122
 */
-
 
123
static void rgb_888(void *dst, uint32_t rgb)
134
static void rgb_888(void *dst, uint32_t rgb)
124
{
135
{
125
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
136
    ((uint8_t *) dst)[0] = RED(rgb, 8);
126
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
137
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
127
    ((uint8_t *) dst)[2] = RED(rgb, 8);
138
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
128
}
139
}
129
 
140
 
130
 
-
 
131
/** BGR 8:8:8 conversion
-
 
132
 *
-
 
133
 */
-
 
134
static void bgr_888(void *dst, uint32_t rgb)
141
static void bgr_888(void *dst, uint32_t rgb)
135
{
142
{
136
    ((uint8_t *) dst)[0] = RED(rgb, 8);
143
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
137
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
144
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
138
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
145
    ((uint8_t *) dst)[2] = RED(rgb, 8);
139
}
146
}
140
 
147
 
-
 
148
static void rgb_555_be(void *dst, uint32_t rgb)
-
 
149
{
-
 
150
    *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 10 |
-
 
151
        GREEN(rgb, 5) << 5 | BLUE(rgb, 5));
-
 
152
}
141
 
153
 
142
/** RGB 5:5:5 conversion
-
 
143
 *
-
 
144
 */
-
 
145
static void rgb_555(void *dst, uint32_t rgb)
154
static void rgb_555_le(void *dst, uint32_t rgb)
146
{
155
{
147
    *((uint16_t *) dst)
156
    *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 10 |
148
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
157
        GREEN(rgb, 5) << 5 | BLUE(rgb, 5));
149
}
158
}
150
 
159
 
-
 
160
static void rgb_565_be(void *dst, uint32_t rgb)
-
 
161
{
-
 
162
    *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 11 |
-
 
163
        GREEN(rgb, 6) << 5 | BLUE(rgb, 5));
-
 
164
}
151
 
165
 
152
/** RGB 5:6:5 conversion
-
 
153
 *
-
 
154
 */
-
 
155
static void rgb_565(void *dst, uint32_t rgb)
166
static void rgb_565_le(void *dst, uint32_t rgb)
156
{
167
{
157
    *((uint16_t *) dst)
168
    *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 11 |
158
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
169
        GREEN(rgb, 6) << 5 | BLUE(rgb, 5));
159
}
170
}
160
 
171
 
161
 
172
 
162
/** RGB 3:2:3
173
/** BGR 3:2:3
163
 *
174
 *
164
 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
175
 * 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
176
 * will most likely use a color palette. The color appearance
166
 * will be pretty random and depend on the default installed
177
 * will be pretty random and depend on the default installed
167
 * palette. This could be fixed by supporting custom palette
178
 * palette. This could be fixed by supporting custom palette
Line 174... Line 185...
174
 * is 0 and the black color code is 255, as some machines (Sun Blade 1500)
185
 * 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
186
 * use these codes for black and white and prevent to set codes
176
 * 0 and 255 to other colors.
187
 * 0 and 255 to other colors.
177
 *
188
 *
178
 */
189
 */
179
static void rgb_323(void *dst, uint32_t rgb)
190
static void bgr_323(void *dst, uint32_t rgb)
180
{
191
{
181
    *((uint8_t *) dst)
192
    *((uint8_t *) dst)
182
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
193
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
183
}
194
}
184
 
195
 
Line 448... Line 459...
448
 */
459
 */
449
void fb_init(fb_properties_t *props)
460
void fb_init(fb_properties_t *props)
450
{
461
{
451
    switch (props->visual) {
462
    switch (props->visual) {
452
    case VISUAL_INDIRECT_8:
463
    case VISUAL_INDIRECT_8:
453
        rgb_conv = rgb_323;
464
        rgb_conv = bgr_323;
454
        pixelbytes = 1;
465
        pixelbytes = 1;
455
        break;
466
        break;
456
    case VISUAL_RGB_5_5_5:
467
    case VISUAL_RGB_5_5_5_LE:
457
        rgb_conv = rgb_555;
468
        rgb_conv = rgb_555_le;
458
        pixelbytes = 2;
469
        pixelbytes = 2;
459
        break;
470
        break;
-
 
471
    case VISUAL_RGB_5_5_5_BE:
-
 
472
        rgb_conv = rgb_555_be;
-
 
473
        pixelbytes = 2;
-
 
474
        break;
460
    case VISUAL_RGB_5_6_5:
475
    case VISUAL_RGB_5_6_5_LE:
-
 
476
        rgb_conv = rgb_565_le;
-
 
477
        pixelbytes = 2;
-
 
478
        break;
-
 
479
    case VISUAL_RGB_5_6_5_BE:
461
        rgb_conv = rgb_565;
480
        rgb_conv = rgb_565_be;
462
        pixelbytes = 2;
481
        pixelbytes = 2;
463
        break;
482
        break;
464
    case VISUAL_RGB_8_8_8:
483
    case VISUAL_RGB_8_8_8:
465
        rgb_conv = rgb_888;
484
        rgb_conv = rgb_888;
466
        pixelbytes = 3;
485
        pixelbytes = 3;
Line 468... Line 487...
468
    case VISUAL_BGR_8_8_8:
487
    case VISUAL_BGR_8_8_8:
469
        rgb_conv = bgr_888;
488
        rgb_conv = bgr_888;
470
        pixelbytes = 3;
489
        pixelbytes = 3;
471
        break;
490
        break;
472
    case VISUAL_RGB_8_8_8_0:
491
    case VISUAL_RGB_8_8_8_0:
473
        rgb_conv = rgb_888;
492
        rgb_conv = rgb_8880;
474
        pixelbytes = 4;
493
        pixelbytes = 4;
475
        break;
494
        break;
476
    case VISUAL_RGB_0_8_8_8:
495
    case VISUAL_RGB_0_8_8_8:
477
        rgb_conv = rgb_0888;
496
        rgb_conv = rgb_0888;
478
        pixelbytes = 4;
497
        pixelbytes = 4;
479
        break;
498
        break;
480
    case VISUAL_BGR_0_8_8_8:
499
    case VISUAL_BGR_0_8_8_8:
481
        rgb_conv = bgr_0888;
500
        rgb_conv = bgr_0888;
482
        pixelbytes = 4;
501
        pixelbytes = 4;
483
        break;
502
        break;
-
 
503
    case VISUAL_BGR_8_8_8_0:
-
 
504
        rgb_conv = bgr_8880;
-
 
505
        pixelbytes = 4;
-
 
506
        break;
484
    default:
507
    default:
485
        panic("Unsupported visual.");
508
        panic("Unsupported visual.");
486
    }
509
    }
487
   
510
   
488
    xres = props->x;
511
    xres = props->x;