Changeset 2bc137c2 in mainline for uspace/fb/fb.c


Ignore:
Timestamp:
2006-11-22T12:36:59Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ccb0cbc
Parents:
33dc0ad
Message:

make framebuffer code more generic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/fb/fb.c

    r33dc0ad r2bc137c2  
    5050#include <ipc/services.h>
    5151#include <kernel/errno.h>
     52#include <kernel/genarch/fb/visuals.h>
    5253#include <async.h>
     54#include <bool.h>
    5355
    5456#include "font-8x16.h"
     
    148150
    149151/* Conversion routines between different color representations */
    150 static void rgb_4byte(void *dst, int rgb)
     152static void rgb_byte0888(void *dst, int rgb)
    151153{
    152154        *(int *)dst = rgb;
    153155}
    154156
    155 static int byte4_rgb(void *src)
     157static int byte0888_rgb(void *src)
    156158{
    157159        return (*(int *)src) & 0xffffff;
    158160}
    159161
    160 static void rgb_3byte(void *dst, int rgb)
     162static void rgb_byte888(void *dst, int rgb)
    161163{
    162164        uint8_t *scr = dst;
     
    172174}
    173175
    174 static int byte3_rgb(void *src)
     176static int byte888_rgb(void *src)
    175177{
    176178        uint8_t *scr = src;
     
    182184}
    183185
     186/**  16-bit depth (5:5:5) */
     187static 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) */
     194static 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
    184200/**  16-bit depth (5:6:5) */
    185 static void rgb_2byte(void *dst, int rgb)
     201static void rgb_byte565(void *dst, int rgb)
    186202{
    187203        /* 5-bit, 6-bits, 5-bits */
     
    190206
    191207/** 16-bit depth (5:6:5) */
    192 static int byte2_rgb(void *src)
     208static int byte565_rgb(void *src)
    193209{
    194210        int color = *(uint16_t *)(src);
     
    197213
    198214/** Put pixel - 8-bit depth (3:2:3) */
    199 static void rgb_1byte(void *dst, int rgb)
     215static void rgb_byte8(void *dst, int rgb)
    200216{
    201217        *(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
     
    203219
    204220/** Return pixel color - 8-bit depth (3:2:3) */
    205 static int byte1_rgb(void *src)
     221static int byte8_rgb(void *src)
    206222{
    207223        int color = *(uint8_t *)src;
     
    453469/** Initialize framebuffer as a chardev output device
    454470 *
    455  * @param addr Address of theframebuffer
    456  * @param xres Screen width in pixels
    457  * @param yres Screen height in pixels
    458  * @param bpp  Bits per pixel (8, 16, 24, 32)
    459  * @param scan Bytes per one scanline
    460  * @param align Alignment for 24bpp mode.
     471 * @param addr          Address of theframebuffer
     472 * @param xres          Screen width in pixels
     473 * @param yres          Screen height in pixels
     474 * @param visual        Bits per pixel (8, 16, 24, 32)
     475 * @param scan          Bytes per one scanline
    461476 * @param invert_colors Inverted colors.
    462477 *
    463478 */
    464 static void
    465 screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan,
    466         int align, int invert_colors)
    467 {
    468         switch (bpp) {
    469         case 8:
    470                 screen.rgb2scr = rgb_1byte;
    471                 screen.scr2rgb = byte1_rgb;
     479static bool screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int scan, unsigned int visual, bool invert_colors)
     480{
     481        switch (visual) {
     482        case VISUAL_INDIRECT_8:
     483                screen.rgb2scr = rgb_byte8;
     484                screen.scr2rgb = byte8_rgb;
    472485                screen.pixelbytes = 1;
    473486                break;
    474         case 16:
    475                 screen.rgb2scr = rgb_2byte;
    476                 screen.scr2rgb = byte2_rgb;
     487        case VISUAL_RGB_5_5_5:
     488                screen.rgb2scr = rgb_byte555;
     489                screen.scr2rgb = byte555_rgb;
    477490                screen.pixelbytes = 2;
    478491                break;
    479         case 24:
    480                 screen.rgb2scr = rgb_3byte;
    481                 screen.scr2rgb = byte3_rgb;
    482                 if (!align)
    483                         screen.pixelbytes = 3;
    484                 else
    485                         screen.pixelbytes = 4;
    486                 break;
    487         case 32:
    488                 screen.rgb2scr = rgb_4byte;
    489                 screen.scr2rgb = byte4_rgb;
     492        case VISUAL_RGB_5_6_5:
     493                screen.rgb2scr = rgb_byte565;
     494                screen.scr2rgb = byte565_rgb;
     495                screen.pixelbytes = 2;
     496                break;
     497        case VISUAL_RGB_8_8_8:
     498                screen.rgb2scr = rgb_byte888;
     499                screen.scr2rgb = byte888_rgb;
     500                screen.pixelbytes = 3;
     501                break;
     502        case VISUAL_RGB_8_8_8_0:
     503                screen.rgb2scr = rgb_byte888;
     504                screen.scr2rgb = byte888_rgb;
    490505                screen.pixelbytes = 4;
    491506                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;
    492514        }
    493515
     
    499521       
    500522        /* Create first viewport */
    501         viewport_create(0,0,xres,yres);
     523        viewport_create(0, 0, xres, yres);
     524       
     525        return true;
    502526}
    503527
     
    12271251        unsigned int fb_width;
    12281252        unsigned int fb_height;
    1229         unsigned int fb_bpp;
    1230         unsigned int fb_bpp_align;
    12311253        unsigned int fb_scanline;
    1232         unsigned int fb_invert_colors;
     1254        unsigned int fb_visual;
     1255        bool fb_invert_colors;
    12331256        void *fb_addr;
    12341257        size_t asz;
     
    12391262        fb_width = sysinfo_value("fb.width");
    12401263        fb_height = sysinfo_value("fb.height");
    1241         fb_bpp = sysinfo_value("fb.bpp");
    1242         fb_bpp_align = sysinfo_value("fb.bpp-align");
    12431264        fb_scanline = sysinfo_value("fb.scanline");
     1265        fb_visual = sysinfo_value("fb.visual");
    12441266        fb_invert_colors = sysinfo_value("fb.invert-colors");
    12451267
    1246         asz = fb_scanline*fb_height;
     1268        asz = fb_scanline * fb_height;
    12471269        fb_addr = as_get_mappable_page(asz);
    12481270       
     
    12501272                    AS_AREA_READ | AS_AREA_WRITE);
    12511273
    1252         screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline, fb_bpp_align, fb_invert_colors);
    1253         return 0;
     1274        if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual, fb_invert_colors))
     1275                return 0;
     1276       
     1277        return -1;
    12541278}
    12551279
Note: See TracChangeset for help on using the changeset viewer.