iPXE
Data Structures | Defines | Functions | Variables
fbcon.h File Reference

Frame buffer console. More...

#include <stdint.h>
#include <ipxe/ansiesc.h>
#include <ipxe/uaccess.h>
#include <ipxe/console.h>

Go to the source code of this file.

Data Structures

struct  fbcon_font_glyph
 A font glyph. More...
struct  fbcon_font
 A font definition. More...
struct  fbcon_geometry
 A frame buffer geometry. More...
struct  fbcon_margin
 A frame buffer margin. More...
struct  fbcon_colour_map
 A frame buffer colour mapping. More...
struct  fbcon_text_cell
 A frame buffer text cell. More...
struct  fbcon_text
 A frame buffer text array. More...
struct  fbcon_picture
 A frame buffer background picture. More...
struct  fbcon
 A frame buffer console. More...

Defines

#define FBCON_CHAR_WIDTH   9
 Character width, in pixels.
#define FBCON_BOLD   0x555555
 Bold colour modifier (RGB value)
#define FBCON_TRANSPARENT   0xffffffff
 Transparent background magic colour (raw colour value)

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int fbcon_init (struct fbcon *fbcon, userptr_t start, struct fbcon_geometry *pixel, struct fbcon_colour_map *map, struct fbcon_font *font, struct console_configuration *config)
 Initialise frame buffer console.
void fbcon_fini (struct fbcon *fbcon)
 Finalise frame buffer console.
void fbcon_putchar (struct fbcon *fbcon, int character)
 Print a character to current cursor position.

Variables

struct fbcon_font_glyph __attribute__

Detailed Description

Frame buffer console.

Definition in file fbcon.h.


Define Documentation

#define FBCON_CHAR_WIDTH   9

Character width, in pixels.

Definition at line 18 of file fbcon.h.

Referenced by fbcon_draw(), and fbcon_init().

#define FBCON_BOLD   0x555555

Bold colour modifier (RGB value)

Definition at line 21 of file fbcon.h.

Referenced by fbcon_handle_sgr().

#define FBCON_TRANSPARENT   0xffffffff

Transparent background magic colour (raw colour value)

Definition at line 24 of file fbcon.h.

Referenced by fbcon_draw(), fbcon_draw_cursor(), and fbcon_set_default_background().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int fbcon_init ( struct fbcon fbcon,
userptr_t  start,
struct fbcon_geometry pixel,
struct fbcon_colour_map map,
struct fbcon_font font,
struct console_configuration config 
)

Initialise frame buffer console.

Parameters:
fbconFrame buffer console
startStart address
pixelPixel geometry
mapColour mapping
fontFont definition
configConsole configuration
Return values:
rcReturn status code

Definition at line 583 of file fbcon.c.

References assert, console_configuration::bottom, bottom, fbcon_margin::bottom, fbcon::character, console_set_size(), fbcon::ctx, DBGC, EINVAL, ENOMEM, fbcon_ansiesc_handlers, FBCON_CHAR_WIDTH, fbcon_clear(), fbcon_picture_init(), fbcon_set_default_background(), fbcon_set_default_foreground(), fbcon::font, ansiesc_context::handlers, console_configuration::height, fbcon_font::height, fbcon_geometry::height, fbcon::indent, console_configuration::left, fbcon_margin::left, fbcon_geometry::len, fbcon::len, fbcon::map, fbcon::margin, memcpy_user(), memset(), memset_user(), fbcon::picture, console_configuration::pixbuf, fbcon::pixel, rc, console_configuration::right, fbcon_margin::right, fbcon::show_cursor, fbcon_text::start, fbcon_picture::start, fbcon::start, start, fbcon_geometry::stride, fbcon::text, console_configuration::top, top, fbcon_margin::top, ufree(), umalloc(), user_to_phys(), console_configuration::width, and fbcon_geometry::width.

Referenced by efifb_init(), and vesafb_init().

                                                        {
        int width;
        int height;
        unsigned int xgap;
        unsigned int ygap;
        unsigned int left;
        unsigned int right;
        unsigned int top;
        unsigned int bottom;
        int rc;

        /* Initialise data structure */
        memset ( fbcon, 0, sizeof ( *fbcon ) );
        fbcon->start = start;
        fbcon->pixel = pixel;
        assert ( pixel->len <= sizeof ( uint32_t ) );
        fbcon->map = map;
        fbcon->font = font;
        fbcon->ctx.handlers = fbcon_ansiesc_handlers;
        fbcon->show_cursor = 1;

        /* Derive overall length */
        fbcon->len = ( pixel->height * pixel->stride );
        DBGC ( fbcon, "FBCON %p at [%08lx,%08lx)\n", fbcon,
               user_to_phys ( fbcon->start, 0 ),
               user_to_phys ( fbcon->start, fbcon->len ) );

        /* Calculate margin.  If the actual screen size is larger than
         * the requested screen size, then update the margins so that
         * the margin remains relative to the requested screen size.
         * (As an exception, if a zero margin was specified then treat
         * this as meaning "expand to edge of actual screen".)
         */
        xgap = ( pixel->width - config->width );
        ygap = ( pixel->height - config->height );
        left = ( xgap / 2 );
        right = ( xgap - left );
        top = ( ygap / 2 );
        bottom = ( ygap - top );
        fbcon->margin.left = ( config->left + ( config->left ? left : 0 ) );
        fbcon->margin.right = ( config->right + ( config->right ? right : 0 ) );
        fbcon->margin.top = ( config->top + ( config->top ? top : 0 ) );
        fbcon->margin.bottom =
                ( config->bottom + ( config->bottom ? bottom : 0 ) );

        /* Expand margin to accommodate whole characters */
        width = ( pixel->width - fbcon->margin.left - fbcon->margin.right );
        height = ( pixel->height - fbcon->margin.top - fbcon->margin.bottom );
        if ( ( width < FBCON_CHAR_WIDTH ) ||
             ( height < ( ( int ) font->height ) ) ) {
                DBGC ( fbcon, "FBCON %p has unusable character area "
                       "[%d-%d),[%d-%d)\n", fbcon, fbcon->margin.left,
                       ( pixel->width - fbcon->margin.right ),
                       fbcon->margin.top,
                       ( pixel->height - fbcon->margin.bottom ) );
                rc = -EINVAL;
                goto err_margin;
        }
        xgap = ( width % FBCON_CHAR_WIDTH );
        ygap = ( height % font->height );
        fbcon->margin.left += ( xgap / 2 );
        fbcon->margin.top += ( ygap / 2 );
        fbcon->margin.right += ( xgap - ( xgap / 2 ) );
        fbcon->margin.bottom += ( ygap - ( ygap / 2 ) );
        fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
                          ( fbcon->margin.left * pixel->len ) );

        /* Derive character geometry from pixel geometry */
        fbcon->character.width = ( width / FBCON_CHAR_WIDTH );
        fbcon->character.height = ( height / font->height );
        fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH );
        fbcon->character.stride = ( pixel->stride * font->height );
        DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at "
               "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width,
               fbcon->pixel->height, fbcon->character.width,
               fbcon->character.height, fbcon->margin.left,
               ( fbcon->pixel->width - fbcon->margin.right ),
               fbcon->margin.top,
               ( fbcon->pixel->height - fbcon->margin.bottom ) );

        /* Set default colours */
        fbcon_set_default_foreground ( fbcon );
        fbcon_set_default_background ( fbcon );

        /* Allocate and initialise stored character array */
        fbcon->text.start = umalloc ( fbcon->character.width *
                                      fbcon->character.height *
                                      sizeof ( struct fbcon_text_cell ) );
        if ( ! fbcon->text.start ) {
                rc = -ENOMEM;
                goto err_text;
        }
        fbcon_clear ( fbcon, 0 );

        /* Set framebuffer to all black (including margins) */
        memset_user ( fbcon->start, 0, 0, fbcon->len );

        /* Generate pixel buffer from background image, if applicable */
        if ( config->pixbuf &&
             ( ( rc = fbcon_picture_init ( fbcon, config->pixbuf ) ) != 0 ) )
                goto err_picture;

        /* Draw background picture (including margins), if applicable */
        if ( fbcon->picture.start ) {
                memcpy_user ( fbcon->start, 0, fbcon->picture.start, 0,
                              fbcon->len );
        }

        /* Update console width and height */
        console_set_size ( fbcon->character.width, fbcon->character.height );

        return 0;

        ufree ( fbcon->picture.start );
 err_picture:
        ufree ( fbcon->text.start );
 err_text:
 err_margin:
        return rc;
}
void fbcon_fini ( struct fbcon fbcon)

Finalise frame buffer console.

Parameters:
fbconFrame buffer console

Definition at line 713 of file fbcon.c.

References fbcon::picture, fbcon_text::start, fbcon_picture::start, fbcon::text, and ufree().

Referenced by efifb_fini(), efifb_init(), vesafb_fini(), and vesafb_init().

                                        {

        ufree ( fbcon->text.start );
        ufree ( fbcon->picture.start );
}
void fbcon_putchar ( struct fbcon fbcon,
int  character 
)

Print a character to current cursor position.

Parameters:
fbconFrame buffer console
characterCharacter

Definition at line 441 of file fbcon.c.

References ansiesc_process(), fbcon_text_cell::background, fbcon::background, fbcon::bold, fbcon_text_cell::character, fbcon::character, fbcon::ctx, fbcon_draw(), fbcon_draw_cursor(), fbcon_scroll(), fbcon_store(), fbcon_text_cell::foreground, fbcon::foreground, fbcon_geometry::height, fbcon::show_cursor, fbcon_geometry::width, fbcon::xpos, and fbcon::ypos.

Referenced by efifb_putchar(), and vesafb_putchar().

                                                          {
        struct fbcon_text_cell cell;

        /* Intercept ANSI escape sequences */
        character = ansiesc_process ( &fbcon->ctx, character );
        if ( character < 0 )
                return;

        /* Handle control characters */
        switch ( character ) {
        case '\r':
                fbcon_draw_cursor ( fbcon, 0 );
                fbcon->xpos = 0;
                break;
        case '\n':
                fbcon_draw_cursor ( fbcon, 0 );
                fbcon->xpos = 0;
                fbcon->ypos++;
                break;
        case '\b':
                fbcon_draw_cursor ( fbcon, 0 );
                if ( fbcon->xpos ) {
                        fbcon->xpos--;
                } else if ( fbcon->ypos ) {
                        fbcon->xpos = ( fbcon->character.width - 1 );
                        fbcon->ypos--;
                }
                break;
        default:
                /* Print character at current cursor position */
                cell.foreground = ( fbcon->foreground | fbcon->bold );
                cell.background = fbcon->background;
                cell.character = character;
                fbcon_store ( fbcon, &cell, fbcon->xpos, fbcon->ypos );
                fbcon_draw ( fbcon, &cell, fbcon->xpos, fbcon->ypos );

                /* Advance cursor */
                fbcon->xpos++;
                if ( fbcon->xpos >= fbcon->character.width ) {
                        fbcon->xpos = 0;
                        fbcon->ypos++;
                }
                break;
        }

        /* Scroll screen if necessary */
        if ( fbcon->ypos >= fbcon->character.height )
                fbcon_scroll ( fbcon );

        /* Show cursor */
        fbcon_draw_cursor ( fbcon, fbcon->show_cursor );
}

Variable Documentation