Changeset 51baa8a in mainline for kernel/genarch/src/fb/fb.c


Ignore:
Timestamp:
2007-01-26T17:04:42Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6f4495f5
Parents:
e71a61d
Message:

Don't write to frame buffer memory, which is past the resolution.
This fixes Ticket #17

Coding style a formatting changes in the frame buffer code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/fb/fb.c

    re71a61d r51baa8a  
    8282#define LOGOCOLOR       0x2020b0
    8383
    84 #define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
     84#define RED(x, bits)    ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
    8585#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
    8686#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
     
    112112static void bgr_byte0888(void *dst, int rgb)
    113113{
    114         *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | RED(rgb,
    115                 8);
     114        *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 |
     115            RED(rgb, 8);
    116116}
    117117
     
    119119{
    120120        int color = *(uint32_t *)(src);
    121         return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | ((color
    122                 >> 16) & 0xff);
     121        return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) |
     122            ((color >> 16) & 0xff);
    123123}
    124124
     
    151151{
    152152        /* 5-bit, 5-bits, 5-bits */
    153         *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | BLUE(rgb,
    154                 5);
     153        *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 |
     154            BLUE(rgb, 5);
    155155}
    156156
     
    159159{
    160160        int color = *(uint16_t *)(src);
    161         return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) <<
    162                 (8 + 3)) | ((color & 0x1f) << 3);
     161        return (((color >> 10) & 0x1f) << (16 + 3)) |
     162            (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3);
    163163}
    164164
     
    167167{
    168168        /* 5-bit, 6-bits, 5-bits */
    169         *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb,                5);
     169        *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 |
     170            BLUE(rgb, 5);
    170171}
    171172
     
    174175{
    175176        int color = *(uint16_t *)(src);
    176         return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) <<
    177                 (8 + 2)) | ((color & 0x1f) << 3);
     177        return (((color >> 11) & 0x1f) << (16 + 3)) |
     178            (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
    178179}
    179180
     
    188189static void rgb_byte8(void *dst, int rgb)
    189190{
    190         *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb,
    191                 3);
     191        *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 |
     192            BLUE(rgb, 3);
    192193}
    193194
     
    199200{
    200201        int color = *(uint8_t *)src;
    201         return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8
    202                 + 6)) | ((color & 0x7) << 5);
     202        return (((color >> 5) & 0x7) << (16 + 5)) |
     203            (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
    203204}
    204205
     
    232233                memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes);
    233234                if (dbbuffer)
    234                         memcpy(&dbbuffer[scanline * y], blankline, xres *
    235                                 pixelbytes);
     235                        memcpy(&dbbuffer[scanline * y], blankline,
     236                            xres * pixelbytes);
    236237        }
    237238}
     
    244245                count_t first;
    245246               
     247                /* Clear the last row */
    246248                memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES);
    247249               
    248250                dboffset = (dboffset + FONT_SCANLINES) % yres;
    249251                first = yres - dboffset;
    250 
    251                 memcpy(fbaddress, &dbbuffer[scanline * dboffset], first *
    252                         scanline);
    253                 memcpy(&fbaddress[first * scanline], dbbuffer, dboffset *
    254                         scanline);
     252               
     253                /* Move all rows one row up */
     254                if (xres * pixelbytes == scanline) {
     255                        memcpy(fbaddress, &dbbuffer[dboffset * scanline],
     256                            first * scanline);
     257                        memcpy(&fbaddress[first * scanline], dbbuffer,
     258                            dboffset * scanline);
     259                } else {
     260                        /*
     261                         * When the scanline is bigger than number of bytes
     262                         * in the X-resolution, chances are that the
     263                         * frame buffer memory past the X-resolution is special
     264                         * in some way. For example, the SUNW,ffb framebuffer
     265                         * wraps this area around the beginning of the same
     266                         * line. To avoid troubles, copy only memory as
     267                         * specified by the resolution.
     268                         */
     269                        int i;
     270
     271                        for (i = 0; i < first; i++)
     272                                memcpy(&fbaddress[i * scanline],
     273                                    &dbbuffer[(dboffset + i) * scanline],
     274                                    xres * pixelbytes);
     275                        for (i = 0; i < dboffset; i++)
     276                                memcpy(&fbaddress[(first + i) * scanline],
     277                                    &dbbuffer[i * scanline], xres * pixelbytes);
     278                }
    255279        } else {
    256280                uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES];
    257281               
    258                 memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES],
    259                         scanline * yres - ROW_BYTES);
    260                 /* Clear last row */
    261                 memcpy((void *) lastline, (void *) blankline, ROW_BYTES);
     282                if (xres * pixelbytes == scanline) {
     283                        /* Move all rows one row up */
     284                        memcpy((void *) fbaddress,
     285                            (void *) &fbaddress[ROW_BYTES],
     286                            scanline * yres - ROW_BYTES);
     287                        /* Clear the last row */
     288                        memcpy((void *) lastline, (void *) blankline,
     289                            ROW_BYTES);
     290                } else {
     291                        /*
     292                         * See the comment in the dbbuffer case.
     293                         */
     294                        int i;
     295
     296                        /* Move all rows one row up */
     297                        for (i = 0; i < yres - FONT_SCANLINES; i++)
     298                                memcpy(&fbaddress[i * scanline],
     299                                    &fbaddress[(i + FONT_SCANLINES) * scanline],
     300                                    xres * pixelbytes);
     301                        /* Clear the last row */
     302                        for (i = 0; i < FONT_SCANLINES; i++)
     303                                memcpy(&lastline[i * scanline],
     304                                    &blankline[i * scanline],
     305                                    xres * pixelbytes);
     306                }
    262307        }
    263308}
     
    291336
    292337        for (y = 0; y < FONT_SCANLINES; y++)
    293                 draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], col *
    294                         COL_WIDTH, row * FONT_SCANLINES + y);
     338                draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y],
     339                    col * COL_WIDTH, row * FONT_SCANLINES + y);
    295340}
    296341
     
    303348        for (x = 0; x < COL_WIDTH; x++)
    304349                for (y = 0; y < FONT_SCANLINES; y++)
    305                         invert_pixel(col * COL_WIDTH + x, row * FONT_SCANLINES +
    306                                 y);
     350                        invert_pixel(col * COL_WIDTH + x,
     351                            row * FONT_SCANLINES + y);
    307352}
    308353
     
    328373                        if (byte & 1)
    329374                                putpixel(startx + x, starty + y,
    330                                         COLOR(LOGOCOLOR));
     375                                    COLOR(LOGOCOLOR));
    331376                }
    332377}
     
    401446 */
    402447void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int scan,
    403         unsigned int visual)
     448    unsigned int visual)
    404449{
    405450        switch (visual) {
     
    468513        sysinfo_set_item_val("fb.visual", NULL, visual);
    469514        sysinfo_set_item_val("fb.address.physical", NULL, addr);
    470         sysinfo_set_item_val("fb.address.color", NULL, PAGE_COLOR((uintptr_t)
    471                 fbaddress));
     515        sysinfo_set_item_val("fb.address.color", NULL,
     516            PAGE_COLOR((uintptr_t) fbaddress));
    472517        sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors);
    473518
Note: See TracChangeset for help on using the changeset viewer.