[fbcon] Move margin calculations to fbcon.c

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2015-10-14 22:01:29 +01:00
parent bc69777a40
commit 79afe60b09
3 changed files with 40 additions and 46 deletions

View File

@@ -83,8 +83,6 @@ 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 */
@@ -419,12 +417,6 @@ static void vesafb_restore ( void ) {
static int vesafb_init ( struct console_configuration *config ) { static int vesafb_init ( struct console_configuration *config ) {
uint32_t discard_b; uint32_t discard_b;
uint16_t *mode_numbers; uint16_t *mode_numbers;
unsigned int xgap;
unsigned int ygap;
unsigned int left;
unsigned int right;
unsigned int top;
unsigned int bottom;
int mode_number; int mode_number;
int rc; int rc;
@@ -450,31 +442,13 @@ static int vesafb_init ( struct console_configuration *config ) {
if ( ( rc = vesafb_set_mode ( mode_number ) ) != 0 ) if ( ( rc = vesafb_set_mode ( mode_number ) ) != 0 )
goto err_set_mode; goto err_set_mode;
/* 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 = ( vesafb.pixel.width - config->width );
ygap = ( vesafb.pixel.height - config->height );
left = ( xgap / 2 );
right = ( xgap - left );
top = ( ygap / 2 );
bottom = ( ygap - top );
vesafb.margin.left = ( config->left + ( config->left ? left : 0 ) );
vesafb.margin.right = ( config->right + ( config->right ? right : 0 ) );
vesafb.margin.top = ( config->top + ( config->top ? top : 0 ) );
vesafb.margin.bottom =
( config->bottom + ( config->bottom ? bottom : 0 ) );
/* Get font data */ /* Get font data */
vesafb_font(); vesafb_font();
/* 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.margin, &vesafb.map, &vesafb.pixel, &vesafb.map, &vesafb.font,
&vesafb.font, config->pixbuf ) ) != 0 ) config ) ) != 0 )
goto err_fbcon_init; goto err_fbcon_init;
free ( mode_numbers ); free ( mode_numbers );

View File

@@ -575,22 +575,24 @@ 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 config Console configuration
* @ret rc Return status code * @ret rc Return status code
*/ */
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 console_configuration *config ) {
int width; int width;
int height; int height;
unsigned int xgap; unsigned int xgap;
unsigned int ygap; unsigned int ygap;
unsigned int left;
unsigned int right;
unsigned int top;
unsigned int bottom;
int rc; int rc;
/* Initialise data structure */ /* Initialise data structure */
@@ -609,24 +611,43 @@ 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 ) );
/* 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 */ /* Expand margin to accommodate whole characters */
width = ( pixel->width - margin->left - margin->right ); width = ( pixel->width - fbcon->margin.left - fbcon->margin.right );
height = ( pixel->height - margin->top - margin->bottom ); height = ( pixel->height - fbcon->margin.top - fbcon->margin.bottom );
if ( ( width < FBCON_CHAR_WIDTH ) || if ( ( width < FBCON_CHAR_WIDTH ) ||
( height < ( ( int ) font->height ) ) ) { ( height < ( ( int ) font->height ) ) ) {
DBGC ( fbcon, "FBCON %p has unusable character area " DBGC ( fbcon, "FBCON %p has unusable character area "
"[%d-%d),[%d-%d)\n", fbcon, "[%d-%d),[%d-%d)\n", fbcon, fbcon->margin.left,
margin->left, ( pixel->width - margin->right ), ( pixel->width - fbcon->margin.right ),
margin->top, ( pixel->height - margin->bottom ) ); fbcon->margin.top,
( pixel->height - fbcon->margin.bottom ) );
rc = -EINVAL; rc = -EINVAL;
goto err_margin; goto err_margin;
} }
xgap = ( width % FBCON_CHAR_WIDTH ); xgap = ( width % FBCON_CHAR_WIDTH );
ygap = ( height % font->height ); ygap = ( height % font->height );
fbcon->margin.left = ( margin->left + ( xgap / 2 ) ); fbcon->margin.left += ( xgap / 2 );
fbcon->margin.top = ( margin->top + ( ygap / 2 ) ); fbcon->margin.top += ( ygap / 2 );
fbcon->margin.right = ( margin->right + ( xgap - ( xgap / 2 ) ) ); fbcon->margin.right += ( xgap - ( xgap / 2 ) );
fbcon->margin.bottom = ( margin->bottom + ( ygap - ( ygap / 2 ) ) ); fbcon->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 ) );
@@ -661,7 +682,8 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start,
memset_user ( fbcon->start, 0, 0, fbcon->len ); memset_user ( fbcon->start, 0, 0, fbcon->len );
/* Generate pixel buffer from background image, if applicable */ /* Generate pixel buffer from background image, if applicable */
if ( pixbuf && ( ( rc = fbcon_picture_init ( fbcon, pixbuf ) ) != 0 ) ) if ( config->pixbuf &&
( ( rc = fbcon_picture_init ( fbcon, config->pixbuf ) ) != 0 ) )
goto err_picture; goto err_picture;
/* Draw background picture (including margins), if applicable */ /* Draw background picture (including margins), if applicable */

View File

@@ -12,8 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h> #include <stdint.h>
#include <ipxe/ansiesc.h> #include <ipxe/ansiesc.h>
#include <ipxe/uaccess.h> #include <ipxe/uaccess.h>
#include <ipxe/console.h>
struct pixel_buffer;
/** Character width, in pixels */ /** Character width, in pixels */
#define FBCON_CHAR_WIDTH 9 #define FBCON_CHAR_WIDTH 9
@@ -149,10 +148,9 @@ 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 console_configuration *config );
extern void fbcon_fini ( struct fbcon *fbcon ); extern void fbcon_fini ( struct fbcon *fbcon );
extern void fbcon_putchar ( struct fbcon *fbcon, int character ); extern void fbcon_putchar ( struct fbcon *fbcon, int character );