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 55... Line 55...
55
#include <io/style.h>
55
#include <io/style.h>
56
#include <async.h>
56
#include <async.h>
57
#include <fibril.h>
57
#include <fibril.h>
58
#include <bool.h>
58
#include <bool.h>
59
#include <stdio.h>
59
#include <stdio.h>
-
 
60
#include <byteorder.h>
60
 
61
 
61
#include "font-8x16.h"
62
#include "font-8x16.h"
62
#include "fb.h"
63
#include "fb.h"
63
#include "main.h"
64
#include "main.h"
64
#include "../console/screenbuffer.h"
65
#include "../console/screenbuffer.h"
Line 210... Line 211...
210
 
211
 
211
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
212
static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,
212
    unsigned int row);
213
    unsigned int row);
213
 
214
 
214
 
215
 
215
#define RED(x, bits)                 ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
216
#define RED(x, bits)                 (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1))
216
#define GREEN(x, bits)               ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
217
#define GREEN(x, bits)               (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1))
217
#define BLUE(x, bits)                ((x >> (8 - bits)) & ((1 << bits) - 1))
218
#define BLUE(x, bits)                (((x) >> (8 - (bits))) & ((1 << (bits)) - 1))
218
 
219
 
219
#define COL2X(col)                   ((col) * FONT_WIDTH)
220
#define COL2X(col)                   ((col) * FONT_WIDTH)
220
#define ROW2Y(row)                   ((row) * FONT_SCANLINES)
221
#define ROW2Y(row)                   ((row) * FONT_SCANLINES)
221
 
222
 
222
#define X2COL(x)                     ((x) / FONT_WIDTH)
223
#define X2COL(x)                     ((x) / FONT_WIDTH)
Line 224... Line 225...
224
 
225
 
225
#define FB_POS(x, y)                 ((y) * screen.scanline + (x) * screen.pixelbytes)
226
#define FB_POS(x, y)                 ((y) * screen.scanline + (x) * screen.pixelbytes)
226
#define BB_POS(vport, col, row)      ((row) * vport->cols + (col))
227
#define BB_POS(vport, col, row)      ((row) * vport->cols + (col))
227
#define GLYPH_POS(glyph, y, cursor)  (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline)
228
#define GLYPH_POS(glyph, y, cursor)  (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline)
228
 
229
 
229
 
230
/*
230
/** ARGB 8:8:8:8 conversion
231
 * RGB conversion and mask functions.
231
 *
232
 *
-
 
233
 * These functions write an RGB value to some memory in some predefined format.
-
 
234
 * The naming convention corresponds to the format created by these functions.
-
 
235
 * The functions use the so called network order (i.e. big endian) with respect
-
 
236
 * to their names.
232
 */
237
 */
-
 
238
 
233
static void rgb_0888(void *dst, uint32_t rgb)
239
static void rgb_0888(void *dst, uint32_t rgb)
234
{
240
{
235
    *((uint32_t *) dst) = rgb & 0x00ffffff;
241
    *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
-
 
242
        (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8)));
236
}
243
}
237
 
244
 
238
static void mask_0888(void *dst, bool mask)
245
static void bgr_0888(void *dst, uint32_t rgb)
239
{
246
{
240
    *((uint32_t *) dst) = (mask ? 0x00ffffff : 0);
247
    *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
-
 
248
        (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8)));
241
}
249
}
242
 
250
 
243
 
-
 
244
/** ABGR 8:8:8:8 conversion
-
 
245
 *
-
 
246
 */
-
 
247
static void bgr_0888(void *dst, uint32_t rgb)
251
static void mask_0888(void *dst, bool mask)
248
{
252
{
249
    *((uint32_t *) dst)
-
 
250
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
253
    bgr_0888(dst, mask ? 0xffffff : 0);
251
}
254
}
252
 
255
 
253
static void rgb_8880(void *dst, uint32_t rgb)
256
static void rgb_8880(void *dst, uint32_t rgb)
254
{
257
{
255
    *((uint32_t *) dst)
258
    *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) |
256
        = (RED(rgb, 8) << 24) | (GREEN(rgb, 8) << 16) | BLUE(rgb, 8) << 8;
259
        (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0);
257
}
260
}
258
 
261
 
259
static void mask_8880(void *dst, bool mask)
262
static void bgr_8880(void *dst, uint32_t rgb)
260
{
263
{
261
    *((uint32_t *) dst) = (mask ? 0xffffff00 : 0);
264
    *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) |
-
 
265
        (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0);
262
}
266
}
263
 
267
 
264
/** RGB 8:8:8 conversion
-
 
265
 *
-
 
266
 */
-
 
267
static void rgb_888(void *dst, uint32_t rgb)
268
static void mask_8880(void *dst, bool mask)
268
{
269
{
269
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
-
 
270
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
270
    bgr_8880(dst, mask ? 0xffffff : 0);
271
    ((uint8_t *) dst)[2] = RED(rgb, 8);
-
 
272
}
271
}
273
 
272
 
274
static void mask_888(void *dst, bool mask)
273
static void rgb_888(void *dst, uint32_t rgb)
275
{
274
{
276
    if (mask) {
-
 
277
        ((uint8_t *) dst)[0] = 0xff;
275
    ((uint8_t *) dst)[0] = RED(rgb, 8);
278
        ((uint8_t *) dst)[1] = 0xff;
276
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
279
        ((uint8_t *) dst)[2] = 0xff;
277
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
280
    } else {
-
 
281
        ((uint8_t *) dst)[0] = 0;
-
 
282
        ((uint8_t *) dst)[1] = 0;
-
 
283
        ((uint8_t *) dst)[2] = 0;
-
 
284
    }
-
 
285
}
278
}
286
 
279
 
287
 
-
 
288
/** BGR 8:8:8 conversion
-
 
289
 *
-
 
290
 */
-
 
291
static void bgr_888(void *dst, uint32_t rgb)
280
static void bgr_888(void *dst, uint32_t rgb)
292
{
281
{
293
    ((uint8_t *) dst)[0] = RED(rgb, 8);
282
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
294
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
283
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
295
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
284
    ((uint8_t *) dst)[2] = RED(rgb, 8);
296
}
285
}
297
 
286
 
-
 
287
static void mask_888(void *dst, bool mask)
-
 
288
{
-
 
289
    bgr_888(dst, mask ? 0xffffff : 0);
-
 
290
}
298
 
291
 
299
/** RGB 5:5:5 conversion
-
 
300
 *
-
 
301
 */
-
 
302
static void rgb_555(void *dst, uint32_t rgb)
292
static void bgr_555(void *dst, uint32_t rgb)
303
{
293
{
304
    *((uint16_t *) dst)
294
    uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 5) << 5)) & 0xff;
305
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
295
    uint8_t lo = (GREEN(rgb, 5) >> 3) | (RED(rgb, 5) << 2);
-
 
296
    *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
306
}
297
}
307
 
298
 
308
static void mask_555(void *dst, bool mask)
299
static void mask_555(void *dst, bool mask)
309
{
300
{
310
    *((uint16_t *) dst) = (mask ? 0x7fff : 0);
301
    bgr_555(dst, mask ? 0xffffff : 0);
311
}
302
}
312
 
303
 
313
 
-
 
314
/** RGB 5:6:5 conversion
-
 
315
 *
-
 
316
 */
-
 
317
static void rgb_565(void *dst, uint32_t rgb)
304
static void bgr_565(void *dst, uint32_t rgb)
318
{
305
{
319
    *((uint16_t *) dst)
306
    uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 6) << 5)) & 0xff;
320
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
307
    uint8_t lo = (GREEN(rgb, 6) >> 3) | (RED(rgb, 5) << 3);
-
 
308
    *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
321
}
309
}
322
 
310
 
323
static void mask_565(void *dst, bool mask)
311
static void mask_565(void *dst, bool mask)
324
{
312
{
325
    *((uint16_t *) dst) = (mask ? 0xffff : 0);
313
    bgr_565(dst, mask ? 0xffffff : 0);
326
}
314
}
327
 
315
 
328
 
-
 
329
/** RGB 3:2:3
-
 
330
 *
-
 
331
 */
-
 
332
static void rgb_323(void *dst, uint32_t rgb)
316
static void bgr_323(void *dst, uint32_t rgb)
333
{
317
{
334
    *((uint8_t *) dst)
318
    *((uint8_t *) dst)
335
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
319
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
336
}
320
}
337
 
321
 
338
static void mask_323(void *dst, bool mask)
322
static void mask_323(void *dst, bool mask)
339
{
323
{
340
    *((uint8_t *) dst) = (mask ? 0xff : 0);
324
    bgr_323(dst, mask ? 0x0 : ~0x0);
341
}
325
}
342
 
326
 
343
/** Draw a filled rectangle.
327
/** Draw a filled rectangle.
344
 *
328
 *
345
 * @note Need real implementation that does not access VRAM twice.
329
 * @note Need real implementation that does not access VRAM twice.
Line 629... Line 613...
629
 *
613
 *
630
 */
614
 */
631
static bool screen_init(void *addr, unsigned int xres, unsigned int yres,
615
static bool screen_init(void *addr, unsigned int xres, unsigned int yres,
632
    unsigned int scan, unsigned int visual)
616
    unsigned int scan, unsigned int visual)
633
{
617
{
634
   
-
 
635
   
-
 
636
    switch (visual) {
618
    switch (visual) {
637
    case VISUAL_INDIRECT_8:
619
    case VISUAL_INDIRECT_8:
638
        screen.rgb_conv = rgb_323;
620
        screen.rgb_conv = bgr_323;
639
        screen.mask_conv = mask_323;
621
        screen.mask_conv = mask_323;
640
        screen.pixelbytes = 1;
622
        screen.pixelbytes = 1;
641
        break;
623
        break;
642
    case VISUAL_RGB_5_5_5:
624
    case VISUAL_BGR_5_5_5:
643
        screen.rgb_conv = rgb_555;
625
        screen.rgb_conv = bgr_555;
644
        screen.mask_conv = mask_555;
626
        screen.mask_conv = mask_555;
645
        screen.pixelbytes = 2;
627
        screen.pixelbytes = 2;
646
        break;
628
        break;
647
    case VISUAL_RGB_5_6_5:
629
    case VISUAL_BGR_5_6_5:
648
        screen.rgb_conv = rgb_565;
630
        screen.rgb_conv = bgr_565;
649
        screen.mask_conv = mask_565;
631
        screen.mask_conv = mask_565;
650
        screen.pixelbytes = 2;
632
        screen.pixelbytes = 2;
651
        break;
633
        break;
652
    case VISUAL_RGB_8_8_8:
634
    case VISUAL_RGB_8_8_8:
653
        screen.rgb_conv = rgb_888;
635
        screen.rgb_conv = rgb_888;
Line 672... Line 654...
672
    case VISUAL_BGR_0_8_8_8:
654
    case VISUAL_BGR_0_8_8_8:
673
        screen.rgb_conv = bgr_0888;
655
        screen.rgb_conv = bgr_0888;
674
        screen.mask_conv = mask_0888;
656
        screen.mask_conv = mask_0888;
675
        screen.pixelbytes = 4;
657
        screen.pixelbytes = 4;
676
        break;
658
        break;
-
 
659
    case VISUAL_BGR_8_8_8_0:
-
 
660
        screen.rgb_conv = bgr_8880;
-
 
661
        screen.mask_conv = mask_8880;
-
 
662
        screen.pixelbytes = 4;
-
 
663
        break;
677
    default:
664
    default:
678
        return false;
665
        return false;
679
    }
666
    }
680
   
667
   
681
    screen.fb_addr = (unsigned char *) addr;
668
    screen.fb_addr = (unsigned char *) addr;