Browse Source

[fbcon] Move margin calculations to fbcon.c

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 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
 	physaddr_t start;
83
 	physaddr_t start;
84
 	/** Pixel geometry */
84
 	/** Pixel geometry */
85
 	struct fbcon_geometry pixel;
85
 	struct fbcon_geometry pixel;
86
-	/** Margin */
87
-	struct fbcon_margin margin;
88
 	/** Colour mapping */
86
 	/** Colour mapping */
89
 	struct fbcon_colour_map map;
87
 	struct fbcon_colour_map map;
90
 	/** Font definition */
88
 	/** Font definition */
419
 static int vesafb_init ( struct console_configuration *config ) {
417
 static int vesafb_init ( struct console_configuration *config ) {
420
 	uint32_t discard_b;
418
 	uint32_t discard_b;
421
 	uint16_t *mode_numbers;
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
 	int mode_number;
420
 	int mode_number;
429
 	int rc;
421
 	int rc;
430
 
422
 
450
 	if ( ( rc = vesafb_set_mode ( mode_number ) ) != 0 )
442
 	if ( ( rc = vesafb_set_mode ( mode_number ) ) != 0 )
451
 		goto err_set_mode;
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
 	/* Get font data */
445
 	/* Get font data */
472
 	vesafb_font();
446
 	vesafb_font();
473
 
447
 
474
 	/* Initialise frame buffer console */
448
 	/* Initialise frame buffer console */
475
 	if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_user ( vesafb.start ),
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
 		goto err_fbcon_init;
452
 		goto err_fbcon_init;
479
 
453
 
480
 	free ( mode_numbers );
454
 	free ( mode_numbers );

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

575
  * @v fbcon		Frame buffer console
575
  * @v fbcon		Frame buffer console
576
  * @v start		Start address
576
  * @v start		Start address
577
  * @v pixel		Pixel geometry
577
  * @v pixel		Pixel geometry
578
- * @v margin		Minimum margin
579
  * @v map		Colour mapping
578
  * @v map		Colour mapping
580
  * @v font		Font definition
579
  * @v font		Font definition
581
- * @v pixbuf		Background picture (if any)
580
+ * @v config		Console configuration
582
  * @ret rc		Return status code
581
  * @ret rc		Return status code
583
  */
582
  */
584
 int fbcon_init ( struct fbcon *fbcon, userptr_t start,
583
 int fbcon_init ( struct fbcon *fbcon, userptr_t start,
585
 		 struct fbcon_geometry *pixel,
584
 		 struct fbcon_geometry *pixel,
586
-		 struct fbcon_margin *margin,
587
 		 struct fbcon_colour_map *map,
585
 		 struct fbcon_colour_map *map,
588
 		 struct fbcon_font *font,
586
 		 struct fbcon_font *font,
589
-		 struct pixel_buffer *pixbuf ) {
587
+		 struct console_configuration *config ) {
590
 	int width;
588
 	int width;
591
 	int height;
589
 	int height;
592
 	unsigned int xgap;
590
 	unsigned int xgap;
593
 	unsigned int ygap;
591
 	unsigned int ygap;
592
+	unsigned int left;
593
+	unsigned int right;
594
+	unsigned int top;
595
+	unsigned int bottom;
594
 	int rc;
596
 	int rc;
595
 
597
 
596
 	/* Initialise data structure */
598
 	/* Initialise data structure */
609
 	       user_to_phys ( fbcon->start, 0 ),
611
 	       user_to_phys ( fbcon->start, 0 ),
610
 	       user_to_phys ( fbcon->start, fbcon->len ) );
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
 	/* Expand margin to accommodate whole characters */
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
 	if ( ( width < FBCON_CHAR_WIDTH ) ||
635
 	if ( ( width < FBCON_CHAR_WIDTH ) ||
616
 	     ( height < ( ( int ) font->height ) ) ) {
636
 	     ( height < ( ( int ) font->height ) ) ) {
617
 		DBGC ( fbcon, "FBCON %p has unusable character area "
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
 		rc = -EINVAL;
642
 		rc = -EINVAL;
622
 		goto err_margin;
643
 		goto err_margin;
623
 	}
644
 	}
624
 	xgap = ( width % FBCON_CHAR_WIDTH );
645
 	xgap = ( width % FBCON_CHAR_WIDTH );
625
 	ygap = ( height % font->height );
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
 	fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
651
 	fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
631
 			  ( fbcon->margin.left * pixel->len ) );
652
 			  ( fbcon->margin.left * pixel->len ) );
632
 
653
 
661
 	memset_user ( fbcon->start, 0, 0, fbcon->len );
682
 	memset_user ( fbcon->start, 0, 0, fbcon->len );
662
 
683
 
663
 	/* Generate pixel buffer from background image, if applicable */
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
 		goto err_picture;
687
 		goto err_picture;
666
 
688
 
667
 	/* Draw background picture (including margins), if applicable */
689
 	/* Draw background picture (including margins), if applicable */

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

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

Loading…
Cancel
Save