david/ipxe
Archived
1
0

[fbcon] Allow for an arbitrary margin around the text area

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2014-01-22 13:57:07 +00:00
parent 7fc380e950
commit 608d6cac9e
4 changed files with 41 additions and 15 deletions

View File

@ -76,6 +76,8 @@ struct vesafb {
physaddr_t start; physaddr_t start;
/** Pixel geometry */ /** Pixel geometry */
struct fbcon_geometry pixel; struct fbcon_geometry pixel;
/** Margin */
struct fbcon_margin margin;
/** Colour mapping */ /** Colour mapping */
struct fbcon_colour_map map; struct fbcon_colour_map map;
/** Font definition */ /** Font definition */
@ -428,8 +430,8 @@ static int vesafb_init ( unsigned int min_width, unsigned int min_height,
/* Initialise frame buffer console */ /* Initialise frame buffer console */
if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_user ( vesafb.start ), if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_user ( vesafb.start ),
&vesafb.pixel, &vesafb.map, &vesafb.font, &vesafb.pixel, &vesafb.margin, &vesafb.map,
pixbuf ) ) != 0 ) &vesafb.font, pixbuf ) ) != 0 )
goto err_fbcon_init; goto err_fbcon_init;
free ( mode_numbers ); free ( mode_numbers );

View File

@ -573,6 +573,7 @@ static int fbcon_picture_init ( struct fbcon *fbcon,
* @v fbcon Frame buffer console * @v fbcon Frame buffer console
* @v start Start address * @v start Start address
* @v pixel Pixel geometry * @v pixel Pixel geometry
* @v margin Minimum margin
* @v map Colour mapping * @v map Colour mapping
* @v font Font definition * @v font Font definition
* @v pixbuf Background picture (if any) * @v pixbuf Background picture (if any)
@ -580,9 +581,12 @@ static int fbcon_picture_init ( struct fbcon *fbcon,
*/ */
int fbcon_init ( struct fbcon *fbcon, userptr_t start, int fbcon_init ( struct fbcon *fbcon, userptr_t start,
struct fbcon_geometry *pixel, struct fbcon_geometry *pixel,
struct fbcon_margin *margin,
struct fbcon_colour_map *map, struct fbcon_colour_map *map,
struct fbcon_font *font, struct fbcon_font *font,
struct pixel_buffer *pixbuf ) { struct pixel_buffer *pixbuf ) {
int width;
int height;
unsigned int xgap; unsigned int xgap;
unsigned int ygap; unsigned int ygap;
int rc; int rc;
@ -603,21 +607,31 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start,
user_to_phys ( fbcon->start, 0 ), user_to_phys ( fbcon->start, 0 ),
user_to_phys ( fbcon->start, fbcon->len ) ); user_to_phys ( fbcon->start, fbcon->len ) );
/* Derive character geometry from pixel geometry */ /* Expand margin to accommodate whole characters */
fbcon->character.width = ( pixel->width / FBCON_CHAR_WIDTH ); width = ( pixel->width - margin->left - margin->right );
fbcon->character.height = ( pixel->height / FBCON_CHAR_HEIGHT ); height = ( pixel->height - margin->top - margin->bottom );
fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH ); if ( ( width < FBCON_CHAR_WIDTH ) || ( height < FBCON_CHAR_HEIGHT ) ) {
fbcon->character.stride = ( pixel->stride * FBCON_CHAR_HEIGHT ); DBGC ( fbcon, "FBCON %p has unusable character area "
"[%d-%d),[%d-%d)\n", fbcon,
/* Calculate margin */ margin->left, ( pixel->width - margin->right ),
xgap = ( pixel->width % FBCON_CHAR_WIDTH ); margin->top, ( pixel->height - margin->bottom ) );
ygap = ( pixel->height % FBCON_CHAR_HEIGHT ); rc = -EINVAL;
fbcon->margin.left = ( xgap / 2 ); goto err_margin;
fbcon->margin.top = ( ygap / 2 ); }
fbcon->margin.right = ( xgap - fbcon->margin.left ); xgap = ( width % FBCON_CHAR_WIDTH );
fbcon->margin.bottom = ( ygap - fbcon->margin.top ); ygap = ( height % FBCON_CHAR_HEIGHT );
fbcon->margin.left = ( margin->left + ( xgap / 2 ) );
fbcon->margin.top = ( margin->top + ( ygap / 2 ) );
fbcon->margin.right = ( margin->right + ( xgap - ( xgap / 2 ) ) );
fbcon->margin.bottom = ( margin->bottom + ( ygap - ( ygap / 2 ) ) );
fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) + fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
( fbcon->margin.left * pixel->len ) ); ( fbcon->margin.left * pixel->len ) );
/* Derive character geometry from pixel geometry */
fbcon->character.width = ( width / FBCON_CHAR_WIDTH );
fbcon->character.height = ( height / FBCON_CHAR_HEIGHT );
fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH );
fbcon->character.stride = ( pixel->stride * FBCON_CHAR_HEIGHT );
DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at " DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at "
"[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width, "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width,
fbcon->pixel->height, fbcon->character.width, fbcon->pixel->height, fbcon->character.width,
@ -662,6 +676,7 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start,
err_picture: err_picture:
ufree ( fbcon->text.start ); ufree ( fbcon->text.start );
err_text: err_text:
err_margin:
return rc; return rc;
} }

View File

@ -28,6 +28,14 @@ struct console_configuration {
unsigned int height; unsigned int height;
/** Colour depth */ /** Colour depth */
unsigned int bpp; unsigned int bpp;
/** Left margin */
unsigned int left;
/** Right margin */
unsigned int right;
/** Top margin */
unsigned int top;
/** Bottom margin */
unsigned int bottom;
/** Background picture, if any */ /** Background picture, if any */
struct pixel_buffer *pixbuf; struct pixel_buffer *pixbuf;
}; };

View File

@ -145,6 +145,7 @@ struct fbcon {
extern int fbcon_init ( struct fbcon *fbcon, userptr_t start, extern int fbcon_init ( struct fbcon *fbcon, userptr_t start,
struct fbcon_geometry *pixel, struct fbcon_geometry *pixel,
struct fbcon_margin *margin,
struct fbcon_colour_map *map, struct fbcon_colour_map *map,
struct fbcon_font *font, struct fbcon_font *font,
struct pixel_buffer *pixbuf ); struct pixel_buffer *pixbuf );