Subversion Repositories HelenOS

Rev

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

Rev 4668 Rev 4678
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
 
-
 
254
/** RGB 8:8:8 conversion
-
 
255
 *
-
 
256
 */
-
 
257
static void rgb_888(void *dst, uint32_t rgb)
256
static void rgb_8880(void *dst, uint32_t rgb)
258
{
257
{
259
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
258
    *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) |
260
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
259
        (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0);
261
    ((uint8_t *) dst)[2] = RED(rgb, 8);
-
 
262
}
260
}
263
 
261
 
264
static void mask_888(void *dst, bool mask)
262
static void bgr_8880(void *dst, uint32_t rgb)
265
{
263
{
266
    if (mask) {
-
 
267
        ((uint8_t *) dst)[0] = 0xff;
-
 
268
        ((uint8_t *) dst)[1] = 0xff;
-
 
269
        ((uint8_t *) dst)[2] = 0xff;
264
    *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) |
270
    } else {
-
 
271
        ((uint8_t *) dst)[0] = 0;
-
 
272
        ((uint8_t *) dst)[1] = 0;
-
 
273
        ((uint8_t *) dst)[2] = 0;
265
        (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0);
274
    }
-
 
275
}
266
}
276
 
267
 
-
 
268
static void mask_8880(void *dst, bool mask)
-
 
269
{
-
 
270
    bgr_8880(dst, mask ? 0xffffff : 0);
-
 
271
}
277
 
272
 
278
/** BGR 8:8:8 conversion
-
 
279
 *
-
 
280
 */
-
 
281
static void bgr_888(void *dst, uint32_t rgb)
273
static void rgb_888(void *dst, uint32_t rgb)
282
{
274
{
283
    ((uint8_t *) dst)[0] = RED(rgb, 8);
275
    ((uint8_t *) dst)[0] = RED(rgb, 8);
284
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
276
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
285
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
277
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
286
}
278
}
287
 
279
 
-
 
280
static void bgr_888(void *dst, uint32_t rgb)
-
 
281
{
-
 
282
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
-
 
283
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
-
 
284
    ((uint8_t *) dst)[2] = RED(rgb, 8);
-
 
285
}
288
 
286
 
289
/** RGB 5:5:5 conversion
-
 
290
 *
-
 
291
 */
-
 
292
static void rgb_555(void *dst, uint32_t rgb)
287
static void mask_888(void *dst, bool mask)
293
{
288
{
294
    *((uint16_t *) dst)
289
    bgr_888(dst, mask ? 0xffffff : 0);
295
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
-
 
296
}
290
}
297
 
291
 
298
static void mask_555(void *dst, bool mask)
292
static void bgr_555(void *dst, uint32_t rgb)
299
{
293
{
-
 
294
    uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 5) << 5)) & 0xff;
-
 
295
    uint8_t lo = (GREEN(rgb, 5) >> 3) | (RED(rgb, 5) << 2);
300
    *((uint16_t *) dst) = (mask ? 0x7fff : 0);
296
    *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
301
}
297
}
302
 
298
 
-
 
299
static void mask_555(void *dst, bool mask)
-
 
300
{
-
 
301
    bgr_555(dst, mask ? 0xffffff : 0);
-
 
302
}
303
 
303
 
304
/** RGB 5:6:5 conversion
-
 
305
 *
-
 
306
 */
-
 
307
static void rgb_565(void *dst, uint32_t rgb)
304
static void bgr_565(void *dst, uint32_t rgb)
308
{
305
{
309
    *((uint16_t *) dst)
306
    uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 6) << 5)) & 0xff;
310
        = (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);
311
}
309
}
312
 
310
 
313
static void mask_565(void *dst, bool mask)
311
static void mask_565(void *dst, bool mask)
314
{
312
{
315
    *((uint16_t *) dst) = (mask ? 0xffff : 0);
313
    bgr_565(dst, mask ? 0xffffff : 0);
316
}
314
}
317
 
315
 
318
 
-
 
319
/** RGB 3:2:3
-
 
320
 *
-
 
321
 */
-
 
322
static void rgb_323(void *dst, uint32_t rgb)
316
static void bgr_323(void *dst, uint32_t rgb)
323
{
317
{
324
    *((uint8_t *) dst)
318
    *((uint8_t *) dst)
325
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
319
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
326
}
320
}
327
 
321
 
328
static void mask_323(void *dst, bool mask)
322
static void mask_323(void *dst, bool mask)
329
{
323
{
330
    *((uint8_t *) dst) = (mask ? 0xff : 0);
324
    bgr_323(dst, mask ? 0x0 : ~0x0);
331
}
325
}
332
 
326
 
333
/** Draw a filled rectangle.
327
/** Draw a filled rectangle.
334
 *
328
 *
335
 * @note Need real implementation that does not access VRAM twice.
329
 * @note Need real implementation that does not access VRAM twice.
Line 619... Line 613...
619
 *
613
 *
620
 */
614
 */
621
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,
622
    unsigned int scan, unsigned int visual)
616
    unsigned int scan, unsigned int visual)
623
{
617
{
624
   
-
 
625
   
-
 
626
    switch (visual) {
618
    switch (visual) {
627
    case VISUAL_INDIRECT_8:
619
    case VISUAL_INDIRECT_8:
628
        screen.rgb_conv = rgb_323;
620
        screen.rgb_conv = bgr_323;
629
        screen.mask_conv = mask_323;
621
        screen.mask_conv = mask_323;
630
        screen.pixelbytes = 1;
622
        screen.pixelbytes = 1;
631
        break;
623
        break;
632
    case VISUAL_RGB_5_5_5:
624
    case VISUAL_BGR_5_5_5:
633
        screen.rgb_conv = rgb_555;
625
        screen.rgb_conv = bgr_555;
634
        screen.mask_conv = mask_555;
626
        screen.mask_conv = mask_555;
635
        screen.pixelbytes = 2;
627
        screen.pixelbytes = 2;
636
        break;
628
        break;
637
    case VISUAL_RGB_5_6_5:
629
    case VISUAL_BGR_5_6_5:
638
        screen.rgb_conv = rgb_565;
630
        screen.rgb_conv = bgr_565;
639
        screen.mask_conv = mask_565;
631
        screen.mask_conv = mask_565;
640
        screen.pixelbytes = 2;
632
        screen.pixelbytes = 2;
641
        break;
633
        break;
642
    case VISUAL_RGB_8_8_8:
634
    case VISUAL_RGB_8_8_8:
643
        screen.rgb_conv = rgb_888;
635
        screen.rgb_conv = rgb_888;
Line 648... Line 640...
648
        screen.rgb_conv = bgr_888;
640
        screen.rgb_conv = bgr_888;
649
        screen.mask_conv = mask_888;
641
        screen.mask_conv = mask_888;
650
        screen.pixelbytes = 3;
642
        screen.pixelbytes = 3;
651
        break;
643
        break;
652
    case VISUAL_RGB_8_8_8_0:
644
    case VISUAL_RGB_8_8_8_0:
653
        screen.rgb_conv = rgb_888;
645
        screen.rgb_conv = rgb_8880;
654
        screen.mask_conv = mask_888;
646
        screen.mask_conv = mask_8880;
655
        screen.pixelbytes = 4;
647
        screen.pixelbytes = 4;
656
        break;
648
        break;
657
    case VISUAL_RGB_0_8_8_8:
649
    case VISUAL_RGB_0_8_8_8:
658
        screen.rgb_conv = rgb_0888;
650
        screen.rgb_conv = rgb_0888;
659
        screen.mask_conv = mask_0888;
651
        screen.mask_conv = mask_0888;
Line 662... Line 654...
662
    case VISUAL_BGR_0_8_8_8:
654
    case VISUAL_BGR_0_8_8_8:
663
        screen.rgb_conv = bgr_0888;
655
        screen.rgb_conv = bgr_0888;
664
        screen.mask_conv = mask_0888;
656
        screen.mask_conv = mask_0888;
665
        screen.pixelbytes = 4;
657
        screen.pixelbytes = 4;
666
        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;
667
    default:
664
    default:
668
        return false;
665
        return false;
669
    }
666
    }
670
   
667
   
671
    screen.fb_addr = (unsigned char *) addr;
668
    screen.fb_addr = (unsigned char *) addr;
Line 1742... Line 1739...
1742
    unsigned int fb_offset = sysinfo_value("fb.offset");
1739
    unsigned int fb_offset = sysinfo_value("fb.offset");
1743
    unsigned int fb_width = sysinfo_value("fb.width");
1740
    unsigned int fb_width = sysinfo_value("fb.width");
1744
    unsigned int fb_height = sysinfo_value("fb.height");
1741
    unsigned int fb_height = sysinfo_value("fb.height");
1745
    unsigned int fb_scanline = sysinfo_value("fb.scanline");
1742
    unsigned int fb_scanline = sysinfo_value("fb.scanline");
1746
    unsigned int fb_visual = sysinfo_value("fb.visual");
1743
    unsigned int fb_visual = sysinfo_value("fb.visual");
1747
   
1744
 
1748
    unsigned int fbsize = fb_scanline * fb_height;
1745
    unsigned int fbsize = fb_scanline * fb_height;
1749
    void *fb_addr = as_get_mappable_page(fbsize);
1746
    void *fb_addr = as_get_mappable_page(fbsize);
1750
   
1747
 
1751
    if (physmem_map(fb_ph_addr + fb_offset, fb_addr,
1748
    if (physmem_map(fb_ph_addr + fb_offset, fb_addr,
1752
        ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
1749
        ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
1753
        return -1;
1750
        return -1;
1754
   
1751
 
1755
    if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual))
1752
    if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual))
1756
        return 0;
1753
        return 0;
1757
   
1754
 
1758
    return -1;
1755
    return -1;
1759
}
1756
}
1760
 
1757
 
1761
/**
1758
/**
1762
 * @}
1759
 * @}