Skip to contentSkip to conversation

WIP: fbconsole: very dirty font selection via param_enum

RFC Superseded Antony Pavlov 2 participants 5 messages Jul 13, 2015 – Jul 14, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC 1/1 WIP: fbconsole: very dirty font selection via param_enum

Alas I can't find any tab-complition for param_enum, so addition 'fonts' command is introduced.

Usage example:
==============

barebox@barebox sandbox:/ fonts
VGA8x16
MINI4x6
barebox@barebox sandbox:/ fbconsole0.font=MINI4x6 barebox@barebox sandbox:/ fbconsole0.active=o
fb0: framebuffer console 160x80 activated barebox@barebox sandbox:/ fbconsole0.font=VGA8x16

---
 drivers/video/fbconsole.c | 55 +++++++++++++++++++++++++++++++++++++++++------
 include/linux/font.h      |  8 +++++++
 lib/fonts/fonts.c         | 44 +++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 7 deletions(-)
drivers/video/fbconsole.c +48 -7
index 36fd138..43a73d9 100644
@@ -20,6 +20,10 @@ struct fbc_priv {
 	struct fb_info *fb;
 
 	struct screen *sc;
+
+	struct param_d *par_font;
+	int par_font_val;
+
 /* FIXME */
 #define VIDEO_FONT_CHARS 256
 	struct image *chars[VIDEO_FONT_CHARS];
@@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
 	return 0;
 }
 
+static void cls(struct fbc_priv *priv)
+{
+	void *buf = gui_screen_render_buffer(priv->sc);
+
+	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
+
+	priv->x = 0;
+	priv->y = 0;
+}
+
 static void drawchar(struct fbc_priv *priv, int x, int y, char c)
 {
 	void *buf;
@@ -173,12 +187,7 @@ static void fbc_parse_csi(struct fbc_priv *priv)
 	}
 
 	if (*end == 'J' && a == 2 && b == -1) {
-		void *buf = gui_screen_render_buffer(priv->sc);
-
-		memset(buf, 0, priv->fb->line_length * priv->fb->yres);
-
-		priv->x = 0;
-		priv->y = 0;
+		cls(priv);
 		video_invertchar(priv, priv->x, priv->y);
 	}
 
@@ -270,7 +279,7 @@ static int fbc_set_active(struct console_device *cdev, unsigned flags)
 	struct fb_info *fb = priv->fb;
 	const struct font_desc *font;
 
-	font = find_font("MINI4x6");
+	font = find_font(font_by_param_value(priv->par_font_val));
 	if (!font) {
 		return -ENOENT;
 	}
@@ -296,6 +305,33 @@ static int fbc_set_active(struct console_device *cdev, unsigned flags)
 	return 0;
 }
 
+static int set_font(struct param_d *p, void *vpriv)
+{
+	struct fbc_priv *priv = vpriv;
+	struct console_device *cdev = &priv->cdev;
+
+	if (cdev->f_active & CONSOLE_STDOUT) {
+		struct fb_info *fb = priv->fb;
+		const struct font_desc *font;
+
+		cls(priv);
+
+		font = find_font(font_by_param_value(priv->par_font_val));
+
+		/* FIXME: code duplication */
+		priv->font_width = font->width;
+		priv->font_height = font->height;
+		priv->fontdata = font->data;
+
+		priv->rows = fb->yres / priv->font_height - 1;
+		priv->cols = fb->xres / priv->font_width - 1;
+
+		priv->state = LIT;
+	}
+
+	return 0;
+}
+
 int register_fbconsole(struct fb_info *fb)
 {
 	struct fbc_priv *priv;
@@ -325,6 +361,11 @@ int register_fbconsole(struct fb_info *fb)
 		return ret;
 	}
 
+	priv->par_font_val = 0;
+	priv->par_font = add_param_font(&cdev->class_dev,
+			set_font, NULL,
+			&priv->par_font_val, priv);
+
 	pr_info("registered as %s%d\n", cdev->class_dev.name, cdev->class_dev.id);
 
 	return 0;
include/linux/font.h +8 -0
index 24d6355..4171c5c 100644
@@ -11,6 +11,8 @@
 #ifndef _VIDEO_FONT_H
 #define _VIDEO_FONT_H
 
+#include <param.h>
+
 struct font_desc {
 	const char *name;
 	int width, height;
@@ -26,4 +28,10 @@ extern const struct font_desc *find_font(const char *name);
 /* Max. length for the name of a predefined font */
 #define MAX_FONT_NAME	32
 
+extern struct param_d *add_param_font(struct device_d *dev,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		int *value, void *priv);
+extern char *font_by_param_value(int value);
+
 #endif /* _VIDEO_FONT_H */
lib/fonts/fonts.c +44 -0

50 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 2 lines · Antony Pavlov

Alas I can't find any tab-complition for param_enum, so addition 'fonts' command is introduced.

There is no tab completion, but 'devinfo fbconsole0' will show the different possibilities for the enum. Is that sufficient?

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
In reply to Antony Pavlov
Quoted 68 lines · Antony Pavlov

Alas I can't find any tab-complition for param_enum, so addition 'fonts' command is introduced.

Usage example:
==============

barebox@barebox sandbox:/ fonts
VGA8x16
MINI4x6
barebox@barebox sandbox:/ fbconsole0.font=MINI4x6 barebox@barebox sandbox:/ fbconsole0.active=o
fb0: framebuffer console 160x80 activated barebox@barebox sandbox:/ fbconsole0.font=VGA8x16

---
 drivers/video/fbconsole.c | 55 +++++++++++++++++++++++++++++++++++++++++------
 include/linux/font.h      |  8 +++++++
 lib/fonts/fonts.c         | 44 +++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 7 deletions(-)
drivers/video/fbconsole.c +15 -6
index 36fd138..43a73d9 100644
@@ -20,6 +20,10 @@ struct fbc_priv {
 	struct fb_info *fb;
 
 	struct screen *sc;
+
+	struct param_d *par_font;
+	int par_font_val;
+
 /* FIXME */
 #define VIDEO_FONT_CHARS 256
 	struct image *chars[VIDEO_FONT_CHARS];
@@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
 	return 0;
 }
 
+static void cls(struct fbc_priv *priv)
+{
+	void *buf = gui_screen_render_buffer(priv->sc);
+
+	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
+
+	priv->x = 0;
+	priv->y = 0;
+}
+
 static void drawchar(struct fbc_priv *priv, int x, int y, char c)
 {
 	void *buf;
@@ -173,12 +187,7 @@ static void fbc_parse_csi(struct fbc_priv *priv)
 	}
 
 	if (*end == 'J' && a == 2 && b == -1) {
-		void *buf = gui_screen_render_buffer(priv->sc);
-
-		memset(buf, 0, priv->fb->line_length * priv->fb->yres);
-
-		priv->x = 0;
-		priv->y = 0;
+		cls(priv);
 		video_invertchar(priv, priv->x, priv->y);
 	}
 

drivers/video/fbconsole.c static int fbc_set_active(struct console_device *cdev, unsigned flags) · line 282

Quoted 5 lines
drivers/video/fbconsole.c +1 -1
@@ -270,7 +279,7 @@ static int fbc_set_active(struct console_device *cdev, unsigned flags)
 	struct fb_info *fb = priv->fb;
 	const struct font_desc *font;
 
-	font = find_font("MINI4x6");
+	font = find_font(font_by_param_value(priv->par_font_val));

This find_font(font_by_param_value()) doesn't look very nice. I think there should be a const struct font_desc *find_font_enum(int); or similar which doesn't take the detour via the font name.

drivers/video/fbconsole.c static int fbc_set_active(struct console_device *cdev, unsigned flags) · line 313

Quoted 13 lines
drivers/video/fbconsole.c +6 -0
 	if (!font) {
 		return -ENOENT;
 	}
@@ -296,6 +305,33 @@ static int fbc_set_active(struct console_device *cdev, unsigned flags)
 	return 0;
 }
 
+static int set_font(struct param_d *p, void *vpriv)
+{
+	struct fbc_priv *priv = vpriv;
+	struct console_device *cdev = &priv->cdev;
+
+	if (cdev->f_active & CONSOLE_STDOUT) {

(CONSOLE_STDOUT | CONSOLE_ERR)

Quoted 6 lines
drivers/video/fbconsole.c +6 -0
+		struct fb_info *fb = priv->fb;
+		const struct font_desc *font;
+
+		cls(priv);
+
+		font = find_font(font_by_param_value(priv->par_font_val));

drivers/video/fbconsole.c static int fbc_set_active(struct console_device *cdev, unsigned flags) · line 329

Quoted 10 lines
drivers/video/fbconsole.c +10 -0
+
+		/* FIXME: code duplication */
+		priv->font_width = font->width;
+		priv->font_height = font->height;
+		priv->fontdata = font->data;
+
+		priv->rows = fb->yres / priv->font_height - 1;
+		priv->cols = fb->xres / priv->font_width - 1;
+
+		priv->state = LIT;

Is this correct? If we are in the middle of an escape sequence, why should we leave it here?

Quoted 57 lines
drivers/video/fbconsole.c +10 -0
+	}
+
+	return 0;
+}
+
 int register_fbconsole(struct fb_info *fb)
 {
 	struct fbc_priv *priv;
@@ -325,6 +361,11 @@ int register_fbconsole(struct fb_info *fb)
 		return ret;
 	}
 
+	priv->par_font_val = 0;
+	priv->par_font = add_param_font(&cdev->class_dev,
+			set_font, NULL,
+			&priv->par_font_val, priv);
+
 	pr_info("registered as %s%d\n", cdev->class_dev.name, cdev->class_dev.id);
 
 	return 0;
include/linux/font.h +8 -0
index 24d6355..4171c5c 100644
@@ -11,6 +11,8 @@
 #ifndef _VIDEO_FONT_H
 #define _VIDEO_FONT_H
 
+#include <param.h>
+
 struct font_desc {
 	const char *name;
 	int width, height;
@@ -26,4 +28,10 @@ extern const struct font_desc *find_font(const char *name);
 /* Max. length for the name of a predefined font */
 #define MAX_FONT_NAME	32
 
+extern struct param_d *add_param_font(struct device_d *dev,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		int *value, void *priv);
+extern char *font_by_param_value(int value);
+
 #endif /* _VIDEO_FONT_H */
lib/fonts/fonts.c +5 -0
index dbd1813..528ee3c 100644
@@ -61,6 +61,50 @@ const struct font_desc *find_font(const char *name)
 
 EXPORT_SYMBOL(find_font);
 
+static char *font_names;
+
+char *font_by_param_value(int value)
+{
+	return ((char **)font_names)[value];

lib/fonts/fonts.c const struct font_desc *find_font(const char *name) · line 78

Quoted 10 lines
lib/fonts/fonts.c +10 -0
+}
+
+struct param_d *add_param_font(struct device_d *dev,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		int *value, void *priv)
+{
+	unsigned int i;
+	int t = num_fonts;
+
	if (!font_names) {

lib/fonts/fonts.c const struct font_desc *find_font(const char *name) · line 82

Quoted 4 lines
lib/fonts/fonts.c +4 -0
+	font_names = xmalloc(sizeof(char *) * t);
+
+	for (i = 0; i < num_fonts; i++)
+		((const char **)font_names)[i] = fonts[i]->name;
	}

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
In reply to Sascha Hauer
Quoted 6 lines · On Tue, 14 Jul 2015 06:42:38 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 2 lines · Antony Pavlov

Alas I can't find any tab-complition for param_enum, so addition 'fonts' command is introduced.

There is no tab completion, but 'devinfo fbconsole0' will show the different possibilities for the enum. Is that sufficient?

It's sufficient. I'll drop the font command in the RFCv2 patch.

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw
In reply to Sascha Hauer
Quoted 72 lines · On Tue, 14 Jul 2015 07:27:56 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 71 lines · Antony Pavlov

Alas I can't find any tab-complition for param_enum, so addition 'fonts' command is introduced.

Usage example:
==============

barebox@barebox sandbox:/ fonts
VGA8x16
MINI4x6
barebox@barebox sandbox:/ fbconsole0.font=MINI4x6 barebox@barebox sandbox:/ fbconsole0.active=o
fb0: framebuffer console 160x80 activated barebox@barebox sandbox:/ fbconsole0.font=VGA8x16

---
 drivers/video/fbconsole.c | 55 +++++++++++++++++++++++++++++++++++++++++------
 include/linux/font.h      |  8 +++++++
 lib/fonts/fonts.c         | 44 +++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 7 deletions(-)
drivers/video/fbconsole.c +15 -6
index 36fd138..43a73d9 100644
@@ -20,6 +20,10 @@ struct fbc_priv {
 	struct fb_info *fb;
 
 	struct screen *sc;
+
+	struct param_d *par_font;
+	int par_font_val;
+
 /* FIXME */
 #define VIDEO_FONT_CHARS 256
 	struct image *chars[VIDEO_FONT_CHARS];
@@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
 	return 0;
 }
 
+static void cls(struct fbc_priv *priv)
+{
+	void *buf = gui_screen_render_buffer(priv->sc);
+
+	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
+
+	priv->x = 0;
+	priv->y = 0;
+}
+
 static void drawchar(struct fbc_priv *priv, int x, int y, char c)
 {
 	void *buf;
@@ -173,12 +187,7 @@ static void fbc_parse_csi(struct fbc_priv *priv)
 	}
 
 	if (*end == 'J' && a == 2 && b == -1) {
-		void *buf = gui_screen_render_buffer(priv->sc);
-
-		memset(buf, 0, priv->fb->line_length * priv->fb->yres);
-
-		priv->x = 0;
-		priv->y = 0;
+		cls(priv);
 		video_invertchar(priv, priv->x, priv->y);
 	}
 
@@ -270,7 +279,7 @@ static int fbc_set_active(struct console_device *cdev, unsigned flags)
 	struct fb_info *fb = priv->fb;
 	const struct font_desc *font;
 
Quoted 6 lines

drivers/video/fbconsole.c static int fbc_set_active(struct console_device *cdev, unsigned flags) · line 282

Quoted 2 lines
drivers/video/fbconsole.c +1 -1
-	font = find_font("MINI4x6");
+	font = find_font(font_by_param_value(priv->par_font_val));

This find_font(font_by_param_value()) doesn't look very nice. I think there should be a const struct font_desc *find_font_enum(int); or similar which doesn't take the detour via the font name.

I have fixed this in the RFCv2 patch.
Also I have dropped unused find_font() so some patch splitting&rebasing is necessary.

Quoted 3 lines

drivers/video/fbconsole.c static int fbc_set_active(struct console_device *cdev, unsigned flags) · line 313

Quoted 1 line
drivers/video/fbconsole.c +1 -0
+	if (cdev->f_active & CONSOLE_STDOUT) {

(CONSOLE_STDOUT | CONSOLE_ERR)

fixed in RFCv2.

Quoted 12 lines
Quoted 12 lines
drivers/video/fbconsole.c +11 -0
+		struct fb_info *fb = priv->fb;
+		const struct font_desc *font;
+
+		cls(priv);
+
+		font = find_font(font_by_param_value(priv->par_font_val));
+
+		/* FIXME: code duplication */
+		priv->font_width = font->width;
+		priv->font_height = font->height;
+		priv->fontdata = font->data;
Quoted 8 lines

drivers/video/fbconsole.c static int fbc_set_active(struct console_device *cdev, unsigned flags) · line 329

Quoted 5 lines
drivers/video/fbconsole.c +5 -0
+
+		priv->rows = fb->yres / priv->font_height - 1;
+		priv->cols = fb->xres / priv->font_width - 1;
+
+		priv->state = LIT;

Is this correct? If we are in the middle of an escape sequence, why should we leave it here?

I can't imagine this situation.
I have dropped it in RFCv2 anyway.

Quoted 10 lines

drivers/video/fbconsole.c

Quoted 8 lines
drivers/video/fbconsole.c +8 -0
+struct param_d *add_param_font(struct device_d *dev,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		int *value, void *priv)
+{
+	unsigned int i;
+	int t = num_fonts;
+
	if (!font_names) {
Quoted 5 lines

drivers/video/fbconsole.c

Quoted 4 lines
drivers/video/fbconsole.c +4 -0
+	font_names = xmalloc(sizeof(char *) * t);
+
+	for (i = 0; i < num_fonts; i++)
+		((const char **)font_names)[i] = fonts[i]->name;
	}

I have planned to add separate initcall for font_names initialization, but font_names initialization in add_parm_font() looks better:
* it is simplier;
* it runs "on-demand" only.

I have fixed this in RFCv2 too.

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox