Subversion Repositories HelenOS

Rev

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

Rev 4669 Rev 4676
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
static void rgb_8880(void *dst, uint32_t rgb)
122
static void rgb_8880(void *dst, uint32_t rgb)
120
{
123
{
121
    *((uint32_t *) dst)
124
    *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) |
122
       = (RED(rgb, 8) << 24) | (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8);
125
        (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0);
123
 
-
 
124
}
126
}
125
 
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
}
126
 
133
 
127
/** RGB 8:8:8 conversion
-
 
128
 *
-
 
129
 */
-
 
130
static void rgb_888(void *dst, uint32_t rgb)
134
static void rgb_888(void *dst, uint32_t rgb)
131
{
135
{
132
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
136
    ((uint8_t *) dst)[0] = RED(rgb, 8);
133
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
137
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
134
    ((uint8_t *) dst)[2] = RED(rgb, 8);
138
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
135
}
139
}
136
 
140
 
137
 
-
 
138
/** BGR 8:8:8 conversion
-
 
139
 *
-
 
140
 */
-
 
141
static void bgr_888(void *dst, uint32_t rgb)
141
static void bgr_888(void *dst, uint32_t rgb)
142
{
142
{
143
    ((uint8_t *) dst)[0] = RED(rgb, 8);
143
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
144
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
144
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
145
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
145
    ((uint8_t *) dst)[2] = RED(rgb, 8);
146
}
146
}
147
 
147
 
148
 
-
 
149
/** RGB 5:5:5 conversion
-
 
150
 *
-
 
151
 */
-
 
152
static void rgb_555(void *dst, uint32_t rgb)
148
static void bgr_555(void *dst, uint32_t rgb)
153
{
149
{
154
    *((uint16_t *) dst)
150
    uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 5) << 5)) & 0xff;
155
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
151
    uint8_t lo = (GREEN(rgb, 5) >> 3) | (RED(rgb, 5) << 2);
-
 
152
    *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
156
}
153
}
157
 
154
 
158
 
-
 
159
/** RGB 5:6:5 conversion
-
 
160
 *
-
 
161
 */
-
 
162
static void rgb_565(void *dst, uint32_t rgb)
155
static void bgr_565(void *dst, uint32_t rgb)
163
{
156
{
164
    *((uint16_t *) dst)
157
    uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 6) << 5)) & 0xff;
165
        = (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);
166
}
160
}
167
 
161
 
168
 
162
 
169
/** RGB 3:2:3
163
/** BGR 3:2:3
170
 *
164
 *
171
 * 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
172
 * will most likely use a color palette. The color appearance
166
 * will most likely use a color palette. The color appearance
173
 * will be pretty random and depend on the default installed
167
 * will be pretty random and depend on the default installed
174
 * palette. This could be fixed by supporting custom palette
168
 * palette. This could be fixed by supporting custom palette
Line 181... Line 175...
181
 * 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)
182
 * 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
183
 * 0 and 255 to other colors.
177
 * 0 and 255 to other colors.
184
 *
178
 *
185
 */
179
 */
186
static void rgb_323(void *dst, uint32_t rgb)
180
static void bgr_323(void *dst, uint32_t rgb)
187
{
181
{
188
    *((uint8_t *) dst)
182
    *((uint8_t *) dst)
189
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
183
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
190
}
184
}
191
 
185
 
Line 455... Line 449...
455
 */
449
 */
456
void fb_init(fb_properties_t *props)
450
void fb_init(fb_properties_t *props)
457
{
451
{
458
    switch (props->visual) {
452
    switch (props->visual) {
459
    case VISUAL_INDIRECT_8:
453
    case VISUAL_INDIRECT_8:
460
        rgb_conv = rgb_323;
454
        rgb_conv = bgr_323;
461
        pixelbytes = 1;
455
        pixelbytes = 1;
462
        break;
456
        break;
463
    case VISUAL_RGB_5_5_5:
457
    case VISUAL_BGR_5_5_5:
464
        rgb_conv = rgb_555;
458
        rgb_conv = bgr_555;
465
        pixelbytes = 2;
459
        pixelbytes = 2;
466
        break;
460
        break;
467
    case VISUAL_RGB_5_6_5:
461
    case VISUAL_BGR_5_6_5:
468
        rgb_conv = rgb_565;
462
        rgb_conv = bgr_565;
469
        pixelbytes = 2;
463
        pixelbytes = 2;
470
        break;
464
        break;
471
    case VISUAL_RGB_8_8_8:
465
    case VISUAL_RGB_8_8_8:
472
        rgb_conv = rgb_888;
466
        rgb_conv = rgb_888;
473
        pixelbytes = 3;
467
        pixelbytes = 3;
Line 486... Line 480...
486
        break;
480
        break;
487
    case VISUAL_BGR_0_8_8_8:
481
    case VISUAL_BGR_0_8_8_8:
488
        rgb_conv = bgr_0888;
482
        rgb_conv = bgr_0888;
489
        pixelbytes = 4;
483
        pixelbytes = 4;
490
        break;
484
        break;
-
 
485
    case VISUAL_BGR_8_8_8_0:
-
 
486
        rgb_conv = bgr_8880;
-
 
487
        pixelbytes = 4;
-
 
488
        break;
491
    default:
489
    default:
492
        panic("Unsupported visual.");
490
        panic("Unsupported visual.");
493
    }
491
    }
494
   
492
   
495
    xres = props->x;
493
    xres = props->x;