Browse Source

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

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
608d6cac9e
4 changed files with 40 additions and 14 deletions
  1. 4
    2
      src/arch/i386/interface/pcbios/vesafb.c
  2. 27
    12
      src/core/fbcon.c
  3. 8
    0
      src/include/ipxe/console.h
  4. 1
    0
      src/include/ipxe/fbcon.h

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

@@ -76,6 +76,8 @@ struct vesafb {
76 76
 	physaddr_t start;
77 77
 	/** Pixel geometry */
78 78
 	struct fbcon_geometry pixel;
79
+	/** Margin */
80
+	struct fbcon_margin margin;
79 81
 	/** Colour mapping */
80 82
 	struct fbcon_colour_map map;
81 83
 	/** Font definition */
@@ -428,8 +430,8 @@ static int vesafb_init ( unsigned int min_width, unsigned int min_height,
428 430
 
429 431
 	/* Initialise frame buffer console */
430 432
 	if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_user ( vesafb.start ),
431
-				 &vesafb.pixel, &vesafb.map, &vesafb.font,
432
-				 pixbuf ) ) != 0 )
433
+				 &vesafb.pixel, &vesafb.margin, &vesafb.map,
434
+				 &vesafb.font, pixbuf ) ) != 0 )
433 435
 		goto err_fbcon_init;
434 436
 
435 437
 	free ( mode_numbers );

+ 27
- 12
src/core/fbcon.c View File

@@ -573,6 +573,7 @@ static int fbcon_picture_init ( struct fbcon *fbcon,
573 573
  * @v fbcon		Frame buffer console
574 574
  * @v start		Start address
575 575
  * @v pixel		Pixel geometry
576
+ * @v margin		Minimum margin
576 577
  * @v map		Colour mapping
577 578
  * @v font		Font definition
578 579
  * @v pixbuf		Background picture (if any)
@@ -580,9 +581,12 @@ static int fbcon_picture_init ( struct fbcon *fbcon,
580 581
  */
581 582
 int fbcon_init ( struct fbcon *fbcon, userptr_t start,
582 583
 		 struct fbcon_geometry *pixel,
584
+		 struct fbcon_margin *margin,
583 585
 		 struct fbcon_colour_map *map,
584 586
 		 struct fbcon_font *font,
585 587
 		 struct pixel_buffer *pixbuf ) {
588
+	int width;
589
+	int height;
586 590
 	unsigned int xgap;
587 591
 	unsigned int ygap;
588 592
 	int rc;
@@ -603,21 +607,31 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start,
603 607
 	       user_to_phys ( fbcon->start, 0 ),
604 608
 	       user_to_phys ( fbcon->start, fbcon->len ) );
605 609
 
610
+	/* Expand margin to accommodate whole characters */
611
+	width = ( pixel->width - margin->left - margin->right );
612
+	height = ( pixel->height - margin->top - margin->bottom );
613
+	if ( ( width < FBCON_CHAR_WIDTH ) || ( height < FBCON_CHAR_HEIGHT ) ) {
614
+		DBGC ( fbcon, "FBCON %p has unusable character area "
615
+		       "[%d-%d),[%d-%d)\n", fbcon,
616
+		       margin->left, ( pixel->width - margin->right ),
617
+		       margin->top, ( pixel->height - margin->bottom ) );
618
+		rc = -EINVAL;
619
+		goto err_margin;
620
+	}
621
+	xgap = ( width % FBCON_CHAR_WIDTH );
622
+	ygap = ( height % FBCON_CHAR_HEIGHT );
623
+	fbcon->margin.left = ( margin->left + ( xgap / 2 ) );
624
+	fbcon->margin.top = ( margin->top + ( ygap / 2 ) );
625
+	fbcon->margin.right = ( margin->right + ( xgap - ( xgap / 2 ) ) );
626
+	fbcon->margin.bottom = ( margin->bottom + ( ygap - ( ygap / 2 ) ) );
627
+	fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
628
+			  ( fbcon->margin.left * pixel->len ) );
629
+
606 630
 	/* Derive character geometry from pixel geometry */
607
-	fbcon->character.width = ( pixel->width / FBCON_CHAR_WIDTH );
608
-	fbcon->character.height = ( pixel->height / FBCON_CHAR_HEIGHT );
631
+	fbcon->character.width = ( width / FBCON_CHAR_WIDTH );
632
+	fbcon->character.height = ( height / FBCON_CHAR_HEIGHT );
609 633
 	fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH );
610 634
 	fbcon->character.stride = ( pixel->stride * FBCON_CHAR_HEIGHT );
611
-
612
-	/* Calculate margin */
613
-	xgap = ( pixel->width % FBCON_CHAR_WIDTH );
614
-	ygap = ( pixel->height % FBCON_CHAR_HEIGHT );
615
-	fbcon->margin.left = ( xgap / 2 );
616
-	fbcon->margin.top = ( ygap / 2 );
617
-	fbcon->margin.right = ( xgap - fbcon->margin.left );
618
-	fbcon->margin.bottom = ( ygap - fbcon->margin.top );
619
-	fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
620
-			  ( fbcon->margin.left * pixel->len ) );
621 635
 	DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at "
622 636
 	       "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width,
623 637
 	       fbcon->pixel->height, fbcon->character.width,
@@ -662,6 +676,7 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start,
662 676
  err_picture:
663 677
 	ufree ( fbcon->text.start );
664 678
  err_text:
679
+ err_margin:
665 680
 	return rc;
666 681
 }
667 682
 

+ 8
- 0
src/include/ipxe/console.h View File

@@ -28,6 +28,14 @@ struct console_configuration {
28 28
 	unsigned int height;
29 29
 	/** Colour depth */
30 30
 	unsigned int bpp;
31
+	/** Left margin */
32
+	unsigned int left;
33
+	/** Right margin */
34
+	unsigned int right;
35
+	/** Top margin */
36
+	unsigned int top;
37
+	/** Bottom margin */
38
+	unsigned int bottom;
31 39
 	/** Background picture, if any */
32 40
 	struct pixel_buffer *pixbuf;
33 41
 };

+ 1
- 0
src/include/ipxe/fbcon.h View File

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

Loading…
Cancel
Save