Subversion Repositories HelenOS

Rev

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

Rev 1954 Rev 1993
Line 47... Line 47...
47
#include <ipc/fb.h>
47
#include <ipc/fb.h>
48
#include <ipc/ipc.h>
48
#include <ipc/ipc.h>
49
#include <ipc/ns.h>
49
#include <ipc/ns.h>
50
#include <ipc/services.h>
50
#include <ipc/services.h>
51
#include <kernel/errno.h>
51
#include <kernel/errno.h>
-
 
52
#include <kernel/genarch/fb/visuals.h>
52
#include <async.h>
53
#include <async.h>
-
 
54
#include <bool.h>
53
 
55
 
54
#include "font-8x16.h"
56
#include "font-8x16.h"
55
#include "fb.h"
57
#include "fb.h"
56
#include "main.h"
58
#include "main.h"
57
#include "../console/screenbuffer.h"
59
#include "../console/screenbuffer.h"
Line 145... Line 147...
145
{
147
{
146
    return screen.invert_colors ? ~color : color;
148
    return screen.invert_colors ? ~color : color;
147
}
149
}
148
 
150
 
149
/* Conversion routines between different color representations */
151
/* Conversion routines between different color representations */
150
static void rgb_4byte(void *dst, int rgb)
152
static void rgb_byte0888(void *dst, int rgb)
151
{
153
{
152
    *(int *)dst = rgb;
154
    *(int *)dst = rgb;
153
}
155
}
154
 
156
 
155
static int byte4_rgb(void *src)
157
static int byte0888_rgb(void *src)
156
{
158
{
157
    return (*(int *)src) & 0xffffff;
159
    return (*(int *)src) & 0xffffff;
158
}
160
}
159
 
161
 
160
static void rgb_3byte(void *dst, int rgb)
162
static void rgb_byte888(void *dst, int rgb)
161
{
163
{
162
    uint8_t *scr = dst;
164
    uint8_t *scr = dst;
163
#if defined(FB_INVERT_ENDIAN)
165
#if defined(FB_INVERT_ENDIAN)
164
    scr[0] = RED(rgb, 8);
166
    scr[0] = RED(rgb, 8);
165
    scr[1] = GREEN(rgb, 8);
167
    scr[1] = GREEN(rgb, 8);
Line 169... Line 171...
169
    scr[1] = GREEN(rgb, 8);
171
    scr[1] = GREEN(rgb, 8);
170
    scr[0] = BLUE(rgb, 8);
172
    scr[0] = BLUE(rgb, 8);
171
#endif
173
#endif
172
}
174
}
173
 
175
 
174
static int byte3_rgb(void *src)
176
static int byte888_rgb(void *src)
175
{
177
{
176
    uint8_t *scr = src;
178
    uint8_t *scr = src;
177
#if defined(FB_INVERT_ENDIAN)
179
#if defined(FB_INVERT_ENDIAN)
178
    return scr[0] << 16 | scr[1] << 8 | scr[2];
180
    return scr[0] << 16 | scr[1] << 8 | scr[2];
179
#else
181
#else
180
    return scr[2] << 16 | scr[1] << 8 | scr[0];
182
    return scr[2] << 16 | scr[1] << 8 | scr[0];
181
#endif  
183
#endif  
182
}
184
}
183
 
185
 
-
 
186
/**  16-bit depth (5:5:5) */
-
 
187
static void rgb_byte555(void *dst, int rgb)
-
 
188
{
-
 
189
    /* 5-bit, 5-bits, 5-bits */
-
 
190
    *((uint16_t *)(dst)) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5);
-
 
191
}
-
 
192
 
-
 
193
/** 16-bit depth (5:5:5) */
-
 
194
static int byte555_rgb(void *src)
-
 
195
{
-
 
196
    int color = *(uint16_t *)(src);
-
 
197
    return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3);
-
 
198
}
-
 
199
 
184
/**  16-bit depth (5:6:5) */
200
/**  16-bit depth (5:6:5) */
185
static void rgb_2byte(void *dst, int rgb)
201
static void rgb_byte565(void *dst, int rgb)
186
{
202
{
187
    /* 5-bit, 6-bits, 5-bits */
203
    /* 5-bit, 6-bits, 5-bits */
188
    *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
204
    *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
189
}
205
}
190
 
206
 
191
/** 16-bit depth (5:6:5) */
207
/** 16-bit depth (5:6:5) */
192
static int byte2_rgb(void *src)
208
static int byte565_rgb(void *src)
193
{
209
{
194
    int color = *(uint16_t *)(src);
210
    int color = *(uint16_t *)(src);
195
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
211
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
196
}
212
}
197
 
213
 
198
/** Put pixel - 8-bit depth (3:2:3) */
214
/** Put pixel - 8-bit depth (3:2:3) */
199
static void rgb_1byte(void *dst, int rgb)
215
static void rgb_byte8(void *dst, int rgb)
200
{
216
{
201
    *(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
217
    *(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
202
}
218
}
203
 
219
 
204
/** Return pixel color - 8-bit depth (3:2:3) */
220
/** Return pixel color - 8-bit depth (3:2:3) */
205
static int byte1_rgb(void *src)
221
static int byte8_rgb(void *src)
206
{
222
{
207
    int color = *(uint8_t *)src;
223
    int color = *(uint8_t *)src;
208
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
224
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
209
}
225
}
210
 
226
 
Line 450... Line 466...
450
}
466
}
451
 
467
 
452
 
468
 
453
/** Initialize framebuffer as a chardev output device
469
/** Initialize framebuffer as a chardev output device
454
 *
470
 *
455
 * @param addr Address of theframebuffer
471
 * @param addr          Address of theframebuffer
456
 * @param xres Screen width in pixels
472
 * @param xres          Screen width in pixels
457
 * @param yres Screen height in pixels
473
 * @param yres          Screen height in pixels
458
 * @param bpp  Bits per pixel (8, 16, 24, 32)
474
 * @param visual        Bits per pixel (8, 16, 24, 32)
459
 * @param scan Bytes per one scanline
475
 * @param scan          Bytes per one scanline
460
 * @param align Alignment for 24bpp mode.
-
 
461
 * @param invert_colors Inverted colors.
476
 * @param invert_colors Inverted colors.
462
 *
477
 *
463
 */
478
 */
464
static void
-
 
465
screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan,
479
static bool screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int scan, unsigned int visual, bool invert_colors)
466
    int align, int invert_colors)
-
 
467
{
480
{
468
    switch (bpp) {
481
    switch (visual) {
469
    case 8:
482
    case VISUAL_INDIRECT_8:
470
        screen.rgb2scr = rgb_1byte;
483
        screen.rgb2scr = rgb_byte8;
471
        screen.scr2rgb = byte1_rgb;
484
        screen.scr2rgb = byte8_rgb;
472
        screen.pixelbytes = 1;
485
        screen.pixelbytes = 1;
473
        break;
486
        break;
474
    case 16:
487
    case VISUAL_RGB_5_5_5:
475
        screen.rgb2scr = rgb_2byte;
488
        screen.rgb2scr = rgb_byte555;
476
        screen.scr2rgb = byte2_rgb;
489
        screen.scr2rgb = byte555_rgb;
477
        screen.pixelbytes = 2;
490
        screen.pixelbytes = 2;
478
        break;
491
        break;
479
    case 24:
492
    case VISUAL_RGB_5_6_5:
480
        screen.rgb2scr = rgb_3byte;
493
        screen.rgb2scr = rgb_byte565;
481
        screen.scr2rgb = byte3_rgb;
494
        screen.scr2rgb = byte565_rgb;
482
        if (!align)
-
 
483
            screen.pixelbytes = 3;
495
        screen.pixelbytes = 2;
484
        else
496
        break;
-
 
497
    case VISUAL_RGB_8_8_8:
-
 
498
        screen.rgb2scr = rgb_byte888;
-
 
499
        screen.scr2rgb = byte888_rgb;
485
            screen.pixelbytes = 4;
500
        screen.pixelbytes = 3;
486
        break;
501
        break;
487
    case 32:
502
    case VISUAL_RGB_8_8_8_0:
488
        screen.rgb2scr = rgb_4byte;
503
        screen.rgb2scr = rgb_byte888;
489
        screen.scr2rgb = byte4_rgb;
504
        screen.scr2rgb = byte888_rgb;
490
        screen.pixelbytes = 4;
505
        screen.pixelbytes = 4;
491
        break;
506
        break;
-
 
507
    case VISUAL_RGB_0_8_8_8:
-
 
508
        screen.rgb2scr = rgb_byte0888;
-
 
509
        screen.scr2rgb = byte0888_rgb;
-
 
510
        screen.pixelbytes = 4;
-
 
511
        break;
-
 
512
    default:
-
 
513
        return false;
492
    }
514
    }
493
 
515
 
494
    screen.fbaddress = (unsigned char *) addr;
516
    screen.fbaddress = (unsigned char *) addr;
495
    screen.xres = xres;
517
    screen.xres = xres;
496
    screen.yres = yres;
518
    screen.yres = yres;
497
    screen.scanline = scan;
519
    screen.scanline = scan;
498
    screen.invert_colors = invert_colors;
520
    screen.invert_colors = invert_colors;
499
   
521
   
500
    /* Create first viewport */
522
    /* Create first viewport */
501
    viewport_create(0,0,xres,yres);
523
    viewport_create(0, 0, xres, yres);
-
 
524
   
-
 
525
    return true;
502
}
526
}
503
 
527
 
504
/** Hide cursor if it is shown */
528
/** Hide cursor if it is shown */
505
static void cursor_hide(viewport_t *vport)
529
static void cursor_hide(viewport_t *vport)
506
{
530
{
Line 1224... Line 1248...
1224
int fb_init(void)
1248
int fb_init(void)
1225
{
1249
{
1226
    void *fb_ph_addr;
1250
    void *fb_ph_addr;
1227
    unsigned int fb_width;
1251
    unsigned int fb_width;
1228
    unsigned int fb_height;
1252
    unsigned int fb_height;
1229
    unsigned int fb_bpp;
-
 
1230
    unsigned int fb_bpp_align;
-
 
1231
    unsigned int fb_scanline;
1253
    unsigned int fb_scanline;
1232
    unsigned int fb_invert_colors;
1254
    unsigned int fb_visual;
-
 
1255
    bool fb_invert_colors;
1233
    void *fb_addr;
1256
    void *fb_addr;
1234
    size_t asz;
1257
    size_t asz;
1235
 
1258
 
1236
    async_set_client_connection(fb_client_connection);
1259
    async_set_client_connection(fb_client_connection);
1237
 
1260
 
1238
    fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
1261
    fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
1239
    fb_width = sysinfo_value("fb.width");
1262
    fb_width = sysinfo_value("fb.width");
1240
    fb_height = sysinfo_value("fb.height");
1263
    fb_height = sysinfo_value("fb.height");
1241
    fb_bpp = sysinfo_value("fb.bpp");
-
 
1242
    fb_bpp_align = sysinfo_value("fb.bpp-align");
-
 
1243
    fb_scanline = sysinfo_value("fb.scanline");
1264
    fb_scanline = sysinfo_value("fb.scanline");
-
 
1265
    fb_visual = sysinfo_value("fb.visual");
1244
    fb_invert_colors = sysinfo_value("fb.invert-colors");
1266
    fb_invert_colors = sysinfo_value("fb.invert-colors");
1245
 
1267
 
1246
    asz = fb_scanline*fb_height;
1268
    asz = fb_scanline * fb_height;
1247
    fb_addr = as_get_mappable_page(asz);
1269
    fb_addr = as_get_mappable_page(asz);
1248
   
1270
   
1249
    map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >> PAGE_WIDTH,
1271
    map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >> PAGE_WIDTH,
1250
            AS_AREA_READ | AS_AREA_WRITE);
1272
            AS_AREA_READ | AS_AREA_WRITE);
1251
 
1273
 
1252
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline, fb_bpp_align, fb_invert_colors);
1274
    if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual, fb_invert_colors))
1253
    return 0;
1275
        return 0;
-
 
1276
   
-
 
1277
    return -1;
1254
}
1278
}
1255
 
1279
 
1256
/**
1280
/**
1257
 * @}
1281
 * @}
1258
 */
1282
 */