Browse Source

[fbcon] Move margin calculations to fbcon.c

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
79afe60b09
3 changed files with 40 additions and 46 deletions
  1. 2
    28
      src/arch/i386/interface/pcbios/vesafb.c
  2. 36
    14
      src/core/fbcon.c
  3. 2
    4
      src/include/ipxe/fbcon.h

+ 2
- 28
src/arch/i386/interface/pcbios/vesafb.c View File

@@ -83,8 +83,6 @@ struct vesafb {
83 83
 	physaddr_t start;
84 84
 	/** Pixel geometry */
85 85
 	struct fbcon_geometry pixel;
86
-	/** Margin */
87
-	struct fbcon_margin margin;
88 86
 	/** Colour mapping */
89 87
 	struct fbcon_colour_map map;
90 88
 	/** Font definition */
@@ -419,12 +417,6 @@ static void vesafb_restore ( void ) {
419 417
 static int vesafb_init ( struct console_configuration *config ) {
420 418
 	uint32_t discard_b;
421 419
 	uint16_t *mode_numbers;
422
-	unsigned int xgap;
423
-	unsigned int ygap;
424
-	unsigned int left;
425
-	unsigned int right;
426
-	unsigned int top;
427
-	unsigned int bottom;
428 420
 	int mode_number;
429 421
 	int rc;
430 422
 
@@ -450,31 +442,13 @@ static int vesafb_init ( struct console_configuration *config ) {
450 442
 	if ( ( rc = vesafb_set_mode ( mode_number ) ) != 0 )
451 443
 		goto err_set_mode;
452 444
 
453
-	/* Calculate margin.  If the actual screen size is larger than
454
-	 * the requested screen size, then update the margins so that
455
-	 * the margin remains relative to the requested screen size.
456
-	 * (As an exception, if a zero margin was specified then treat
457
-	 * this as meaning "expand to edge of actual screen".)
458
-	 */
459
-	xgap = ( vesafb.pixel.width - config->width );
460
-	ygap = ( vesafb.pixel.height - config->height );
461
-	left = ( xgap / 2 );
462
-	right = ( xgap - left );
463
-	top = ( ygap / 2 );
464
-	bottom = ( ygap - top );
465
-	vesafb.margin.left = ( config->left + ( config->left ? left : 0 ) );
466
-	vesafb.margin.right = ( config->right + ( config->right ? right : 0 ) );
467
-	vesafb.margin.top = ( config->top + ( config->top ? top : 0 ) );
468
-	vesafb.margin.bottom =
469
-		( config->bottom + ( config->bottom ? bottom : 0 ) );
470
-
471 445
 	/* Get font data */
472 446
 	vesafb_font();
473 447
 
474 448
 	/* Initialise frame buffer console */
475 449
 	if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_user ( vesafb.start ),
476
-				 &vesafb.pixel, &vesafb.margin, &vesafb.map,
477
-				 &vesafb.font, config->pixbuf ) ) != 0 )
450
+				 &vesafb.pixel, &vesafb.map, &vesafb.font,
451
+				 config ) ) != 0 )
478 452
 		goto err_fbcon_init;
479 453
 
480 454
 	free ( mode_numbers );

+ 36
- 14
src/core/fbcon.c View File

@@ -575,22 +575,24 @@ static int fbcon_picture_init ( struct fbcon *fbcon,
575 575
  * @v fbcon		Frame buffer console
576 576
  * @v start		Start address
577 577
  * @v pixel		Pixel geometry
578
- * @v margin		Minimum margin
579 578
  * @v map		Colour mapping
580 579
  * @v font		Font definition
581
- * @v pixbuf		Background picture (if any)
580
+ * @v config		Console configuration
582 581
  * @ret rc		Return status code
583 582
  */
584 583
 int fbcon_init ( struct fbcon *fbcon, userptr_t start,
585 584
 		 struct fbcon_geometry *pixel,
586
-		 struct fbcon_margin *margin,
587 585
 		 struct fbcon_colour_map *map,
588 586
 		 struct fbcon_font *font,
589
-		 struct pixel_buffer *pixbuf ) {
587
+		 struct console_configuration *config ) {
590 588
 	int width;
591 589
 	int height;
592 590
 	unsigned int xgap;
593 591
 	unsigned int ygap;
592
+	unsigned int left;
593
+	unsigned int right;
594
+	unsigned int top;
595
+	unsigned int bottom;
594 596
 	int rc;
595 597
 
596 598
 	/* Initialise data structure */
@@ -609,24 +611,43 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start,
609 611
 	       user_to_phys ( fbcon->start, 0 ),
610 612
 	       user_to_phys ( fbcon->start, fbcon->len ) );
611 613
 
614
+	/* Calculate margin.  If the actual screen size is larger than
615
+	 * the requested screen size, then update the margins so that
616
+	 * the margin remains relative to the requested screen size.
617
+	 * (As an exception, if a zero margin was specified then treat
618
+	 * this as meaning "expand to edge of actual screen".)
619
+	 */
620
+	xgap = ( pixel->width - config->width );
621
+	ygap = ( pixel->height - config->height );
622
+	left = ( xgap / 2 );
623
+	right = ( xgap - left );
624
+	top = ( ygap / 2 );
625
+	bottom = ( ygap - top );
626
+	fbcon->margin.left = ( config->left + ( config->left ? left : 0 ) );
627
+	fbcon->margin.right = ( config->right + ( config->right ? right : 0 ) );
628
+	fbcon->margin.top = ( config->top + ( config->top ? top : 0 ) );
629
+	fbcon->margin.bottom =
630
+		( config->bottom + ( config->bottom ? bottom : 0 ) );
631
+
612 632
 	/* Expand margin to accommodate whole characters */
613
-	width = ( pixel->width - margin->left - margin->right );
614
-	height = ( pixel->height - margin->top - margin->bottom );
633
+	width = ( pixel->width - fbcon->margin.left - fbcon->margin.right );
634
+	height = ( pixel->height - fbcon->margin.top - fbcon->margin.bottom );
615 635
 	if ( ( width < FBCON_CHAR_WIDTH ) ||
616 636
 	     ( height < ( ( int ) font->height ) ) ) {
617 637
 		DBGC ( fbcon, "FBCON %p has unusable character area "
618
-		       "[%d-%d),[%d-%d)\n", fbcon,
619
-		       margin->left, ( pixel->width - margin->right ),
620
-		       margin->top, ( pixel->height - margin->bottom ) );
638
+		       "[%d-%d),[%d-%d)\n", fbcon, fbcon->margin.left,
639
+		       ( pixel->width - fbcon->margin.right ),
640
+		       fbcon->margin.top,
641
+		       ( pixel->height - fbcon->margin.bottom ) );
621 642
 		rc = -EINVAL;
622 643
 		goto err_margin;
623 644
 	}
624 645
 	xgap = ( width % FBCON_CHAR_WIDTH );
625 646
 	ygap = ( height % font->height );
626
-	fbcon->margin.left = ( margin->left + ( xgap / 2 ) );
627
-	fbcon->margin.top = ( margin->top + ( ygap / 2 ) );
628
-	fbcon->margin.right = ( margin->right + ( xgap - ( xgap / 2 ) ) );
629
-	fbcon->margin.bottom = ( margin->bottom + ( ygap - ( ygap / 2 ) ) );
647
+	fbcon->margin.left += ( xgap / 2 );
648
+	fbcon->margin.top += ( ygap / 2 );
649
+	fbcon->margin.right += ( xgap - ( xgap / 2 ) );
650
+	fbcon->margin.bottom += ( ygap - ( ygap / 2 ) );
630 651
 	fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
631 652
 			  ( fbcon->margin.left * pixel->len ) );
632 653
 
@@ -661,7 +682,8 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start,
661 682
 	memset_user ( fbcon->start, 0, 0, fbcon->len );
662 683
 
663 684
 	/* Generate pixel buffer from background image, if applicable */
664
-	if ( pixbuf && ( ( rc = fbcon_picture_init ( fbcon, pixbuf ) ) != 0 ) )
685
+	if ( config->pixbuf &&
686
+	     ( ( rc = fbcon_picture_init ( fbcon, config->pixbuf ) ) != 0 ) )
665 687
 		goto err_picture;
666 688
 
667 689
 	/* Draw background picture (including margins), if applicable */

+ 2
- 4
src/include/ipxe/fbcon.h View File

@@ -12,8 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 12
 #include <stdint.h>
13 13
 #include <ipxe/ansiesc.h>
14 14
 #include <ipxe/uaccess.h>
15
-
16
-struct pixel_buffer;
15
+#include <ipxe/console.h>
17 16
 
18 17
 /** Character width, in pixels */
19 18
 #define FBCON_CHAR_WIDTH 9
@@ -149,10 +148,9 @@ struct fbcon {
149 148
 
150 149
 extern int fbcon_init ( struct fbcon *fbcon, userptr_t start,
151 150
 			struct fbcon_geometry *pixel,
152
-			struct fbcon_margin *margin,
153 151
 			struct fbcon_colour_map *map,
154 152
 			struct fbcon_font *font,
155
-			struct pixel_buffer *pixbuf );
153
+			struct console_configuration *config );
156 154
 extern void fbcon_fini ( struct fbcon *fbcon );
157 155
 extern void fbcon_putchar ( struct fbcon *fbcon, int character );
158 156
 

Loading…
Cancel
Save