mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] 2d-primitives: Introduce gu_draw_text()
@ 2018-02-05 17:29 Andrey Smirnov
  2018-02-05 17:29 ` [PATCH 2/4] gui: graphic_utils: Stub out fb_* functions Andrey Smirnov
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andrey Smirnov @ 2018-02-05 17:29 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov, Nikita Yushchenko

Add code to draw characters/string on a display.

Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 include/gui/2d-primitives.h | 12 ++++++++
 lib/gui/2d-primitives.c     | 67 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/include/gui/2d-primitives.h b/include/gui/2d-primitives.h
index 06216bb03..f97c5eb61 100644
--- a/include/gui/2d-primitives.h
+++ b/include/gui/2d-primitives.h
@@ -2,6 +2,7 @@
 #define __2D_PRIMITIVES__
 
 #include <fb.h>
+#include <linux/font.h>
 
 void gu_draw_line(struct screen *sc,
 		  int x1, int y1, int x2, int y2,
@@ -12,4 +13,15 @@ void gu_draw_circle(struct screen *sc,
 		    int x0, int y0, int radius,
 		    u8 r, u8 g, u8 b, u8 a);
 
+#ifdef CONFIG_FONTS
+void gu_draw_text(struct screen *sc, const struct font_desc *font,
+                 int x, int y, const char *text,
+                 u8 fr, u8 fg, u8 fb, u8 fa,
+                 u8 br, u8 bg, u8 bb, u8 ba);
+#else
+static inline void gu_draw_text(struct screen *sc, const struct font_desc *font,
+				int x, int y, const char *text,
+				u8 fr, u8 fg, u8 fb, u8 fa,
+				u8 br, u8 bg, u8 bb, u8 ba) {}
+#endif
 #endif
diff --git a/lib/gui/2d-primitives.c b/lib/gui/2d-primitives.c
index 82e59d9a6..8cb316b4d 100644
--- a/lib/gui/2d-primitives.c
+++ b/lib/gui/2d-primitives.c
@@ -6,6 +6,8 @@
 #include <errno.h>
 #include <fs.h>
 #include <malloc.h>
+#include <linux/font.h>
+#include <linux/ctype.h>
 
 static void __illuminate(struct fb_info *info,
 			 int x, int y,
@@ -200,3 +202,68 @@ void gu_draw_circle(struct screen *sc,
 		 }
 	}
 }
+
+#ifdef CONFIG_FONTS
+static void gu_draw_char(struct screen *sc, const struct font_desc *font,
+			 int ch, int x0, int y0,
+			 u8 fr, u8 fg, u8 fb, u8 fa,
+			 u8 br, u8 bg, u8 bb, u8 ba)
+{
+       const u8 *bitmap = font->data + find_font_index(font, ch);
+       int x, y;
+
+       for (y = 0; y < font->height; y++) {
+               for (x = 0; x < font->width; x++) {
+		       const unsigned index  = y * font->width + x;
+		       const unsigned byte   = index / 8;
+		       const unsigned bit    = 8 - (index % 8);
+		       const bool foreground = bitmap[byte] & BIT(bit);
+
+		       const u8 r = (foreground) ? fr : br;
+		       const u8 g = (foreground) ? fg : bg;
+		       const u8 b = (foreground) ? fb : bb;
+		       const u8 a = (foreground) ? fa : ba;
+
+		       __illuminate(sc->info, x0 + x, y0 + y, r, g, b, a);
+               }
+       }
+}
+
+/**
+ * gu_draw_text - display text at (x0, y0)
+ *
+ * @sc: screen to draw on
+ * @font: font used to render the text
+ * @x0, @y0: coordinates of top left corner of the text "box"
+ * @text: text to render
+ * @fr, @fg, @fb, @fa: foreground color information
+ * @fr, @fg, @fb, @fa: background color information
+ *
+ * gu_draw_text() implements basic algorithm capable of rendering
+ * textual information to a frambuffer. Resulting text is produced to
+ * be a single line and no attempt to do wrapping/text layout is made.
+ */
+void gu_draw_text(struct screen *sc, const struct font_desc *font,
+		  int x0, int y0, const char *text,
+		  u8 fr, u8 fg, u8 fb, u8 fa,
+		  u8 br, u8 bg, u8 bb, u8 ba)
+{
+	char c;
+	int x = x0;
+	int y = y0;
+
+	BUG_ON(x0 < 0 || y0 < 0);
+
+	while ((c = *text++)) {
+		/*
+		 * Just skip all non-printable characters
+		 */
+		if (isprint(c)) {
+			gu_draw_char(sc, font, c, x, y,
+				     fr, fg, fb, fa, br, bg, bb, ba);
+			x += font->width;
+		}
+	}
+}
+#endif
+
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] gui: graphic_utils: Stub out fb_* functions
  2018-02-05 17:29 [PATCH 1/4] 2d-primitives: Introduce gu_draw_text() Andrey Smirnov
@ 2018-02-05 17:29 ` Andrey Smirnov
  2018-02-05 17:29 ` [PATCH 3/4] linux/font.h: Stub out font functions Andrey Smirnov
  2018-02-05 17:29 ` [PATCH 4/4] commands: version: Add framebuffer output support Andrey Smirnov
  2 siblings, 0 replies; 6+ messages in thread
From: Andrey Smirnov @ 2018-02-05 17:29 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Stub out fb_* functions so as to avoid having to #ifdef the code using
them.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 include/gui/graphic_utils.h | 47 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/include/gui/graphic_utils.h b/include/gui/graphic_utils.h
index 279fdf91d..d4bac6394 100644
--- a/include/gui/graphic_utils.h
+++ b/include/gui/graphic_utils.h
@@ -11,6 +11,8 @@
 #include <gui/image.h>
 #include <gui/gui.h>
 
+#ifdef CONFIG_IMAGE_RENDERER
+
 u32 gu_hex_to_pixel(struct fb_info *info, u32 color);
 u32 gu_rgb_to_pixel(struct fb_info *info, u8 r, u8 g, u8 b, u8 t);
 void gu_rgba_blend(struct fb_info *info, struct image *img, void* dest, int height,
@@ -31,4 +33,49 @@ void gu_screen_blit_area(struct screen *sc, int startx, int starty, int width,
 void gu_fill_rectangle(struct screen *sc,
 		       int x1, int y1, int x2, int y2,
 		       u8 r, u8 g, u8 b, u8 a);
+#else
+
+static inline u32 gu_hex_to_pixel(struct fb_info *info, u32 color)
+{
+	return 0;
+}
+static inline u32 gu_rgb_to_pixel(struct fb_info *info, u8 r,
+				  u8 g, u8 b, u8 t)
+{
+	return 0;
+}
+static inline void gu_rgba_blend(struct fb_info *info, struct image *img,
+				 void* dest,int height,
+				 int width, int startx,
+				 int starty, bool is_rgba) {}
+static inline void gu_set_pixel(struct fb_info *info, void *adr, u32 px) {}
+static inline void gu_set_rgb_pixel(struct fb_info *info, void *adr,
+				    u8 r, u8 g, u8 b) {}
+static inline void gu_set_rgba_pixel(struct fb_info *info, void *adr,
+				     u8 r, u8 g, u8 b, u8 a) {}
+static inline void gu_memset_pixel(struct fb_info *info, void* buf,
+				   u32 color, size_t size) {}
+static inline struct screen *fb_create_screen(struct fb_info *info)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
+static inline struct screen *fb_open(const char *fbdev)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
+static inline void fb_close(struct screen *sc) {}
+static inline void gu_screen_blit(struct screen *sc) {}
+static inline void gu_invert_area(struct fb_info *info, void *buf, int startx,
+				  int starty, int width, int height) {}
+static inline void gu_screen_blit_area(struct screen *sc, int startx,
+				       int starty, int width,
+				       int height) {}
+static inline void gu_fill_rectangle(struct screen *sc, int x1, int y1,
+				     int x2, int y2, u8 r, u8 g, u8 b, u8 a) {}
+
+#endif
+
+
 #endif /* __GRAPHIC_UTILS_H__ */
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] linux/font.h: Stub out font functions
  2018-02-05 17:29 [PATCH 1/4] 2d-primitives: Introduce gu_draw_text() Andrey Smirnov
  2018-02-05 17:29 ` [PATCH 2/4] gui: graphic_utils: Stub out fb_* functions Andrey Smirnov
@ 2018-02-05 17:29 ` Andrey Smirnov
  2018-02-05 17:29 ` [PATCH 4/4] commands: version: Add framebuffer output support Andrey Smirnov
  2 siblings, 0 replies; 6+ messages in thread
From: Andrey Smirnov @ 2018-02-05 17:29 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Stub out font-related funtions functions so as to avoid having to
ifdef the code using them.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 include/linux/font.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/include/linux/font.h b/include/linux/font.h
index feeab9719..9b3699ba8 100644
--- a/include/linux/font.h
+++ b/include/linux/font.h
@@ -30,6 +30,8 @@ struct font_desc {
 /* Max. length for the name of a predefined font */
 #define MAX_FONT_NAME	32
 
+#ifdef CONFIG_FONTS
+
 extern int find_font_index(const struct font_desc *font, int ch);
 extern const struct font_desc *find_font_enum(int n);
 extern struct param_d *add_param_font(struct device_d *dev,
@@ -39,4 +41,32 @@ extern struct param_d *add_param_font(struct device_d *dev,
 
 int font_register(struct font_desc *font);
 
+#else
+
+static inline int find_font_index(const struct font_desc *font, int ch)
+{
+	return -ENOTSUPP;
+}
+
+static inline const struct font_desc *find_font_enum(int n)
+{
+	return NULL;
+}
+
+static inline 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)
+{
+	return NULL;
+}
+
+static inline int font_register(struct font_desc *font)
+{
+	return -ENOTSUPP;
+}
+
+#endif
+
 #endif /* _VIDEO_FONT_H */
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] commands: version: Add framebuffer output support
  2018-02-05 17:29 [PATCH 1/4] 2d-primitives: Introduce gu_draw_text() Andrey Smirnov
  2018-02-05 17:29 ` [PATCH 2/4] gui: graphic_utils: Stub out fb_* functions Andrey Smirnov
  2018-02-05 17:29 ` [PATCH 3/4] linux/font.h: Stub out font functions Andrey Smirnov
@ 2018-02-05 17:29 ` Andrey Smirnov
  2018-02-09  7:29   ` Sascha Hauer
  2 siblings, 1 reply; 6+ messages in thread
From: Andrey Smirnov @ 2018-02-05 17:29 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Extend "version" command to be capable of rendeing version information
on framebuffer devices.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 commands/Kconfig   |   8 +++
 commands/version.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 204 insertions(+), 2 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index 095536849..1cad5d608 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -238,6 +238,14 @@ config CMD_VERSION
 
 	  barebox 2014.05.0-00142-gb289373 #177 Mon May 12 20:35:55 CEST 2014
 
+config CMD_VERSION_OUTPUT_TO_FRAMEBUFFER
+       bool
+       depends on CMD_VERSION
+       prompt "support displaying version via framebuffer"
+       help
+         Selecting this option will enable version command to output
+         version information onto display backed by a frambuffer
+
 config CMD_MMC_EXTCSD
 	tristate
 	prompt "read/write eMMC ext. CSD register"
diff --git a/commands/version.c b/commands/version.c
index 090f2dd13..ba74a993c 100644
--- a/commands/version.c
+++ b/commands/version.c
@@ -20,16 +20,210 @@
 #include <common.h>
 #include <command.h>
 #include <complete.h>
+#include <getopt.h>
+#include <fb.h>
+#include <gui/graphic_utils.h>
+#include <gui/2d-primitives.h>
+
+#define FRAME_SIZE	8
+
+struct placement {
+	int x, y;
+};
+
+typedef struct placement placement_function_t (struct screen *, int, int);
+
+struct placement
+placement_center(struct screen *sc, int text_width, int text_height)
+{
+	struct placement p;
+
+	p.x = (sc->info->xres - text_width) / 2;
+	p.y = (sc->info->yres - text_height) / 2;
+
+	return p;
+}
+
+struct placement
+placement_upper_left(struct screen *sc, int text_width, int text_height)
+{
+	struct placement p;
+
+	p.x = FRAME_SIZE;
+	p.y = FRAME_SIZE;
+
+	return p;
+}
+
+struct placement
+placement_upper_right(struct screen *sc, int text_width, int text_height)
+{
+	struct placement p;
+
+	p.x = sc->info->xres - 1 - text_width - FRAME_SIZE;
+	p.y = FRAME_SIZE;
+
+	return p;
+}
+
+struct placement
+placement_lower_left(struct screen *sc, int text_width, int text_height)
+{
+	struct placement p;
+
+	p.x = FRAME_SIZE;
+	p.y = sc->info->yres - 1 - text_height - FRAME_SIZE;
+
+	return p;
+}
+
+struct placement
+placement_lower_right(struct screen *sc, int text_width, int text_height)
+{
+	struct placement p;
+
+	p.x = sc->info->xres - 1 - text_width  - FRAME_SIZE;
+	p.y = sc->info->yres - 1 - text_height - FRAME_SIZE;
+
+	return p;
+}
 
 static int do_version(int argc, char *argv[])
 {
-	printf ("\n%s\n", version_string);
+	const struct font_desc *font;
+	const char *fbdev = NULL;
+	struct screen *sc;
+	u8 fg[3], bg[3];
+	int text_width;
+	int text_height;
+
+	placement_function_t *place;
+	struct placement placement;
+
+	if (IS_ENABLED(CONFIG_CMD_VERSION_OUTPUT_TO_FRAMEBUFFER)) {
+		const struct {
+			const char *name;
+			placement_function_t *func;
+		} placements[] = {
+			{ "center",      placement_center      },
+			{ "upper-left",  placement_upper_left  },
+			{ "lower-left",  placement_lower_left  },
+			{ "upper-right", placement_upper_right },
+			{ "lower-right", placement_lower_right  },
+		};
+		u32 color;
+		size_t i;
+		int opt;
+		u8 *c;
+
+		place = placement_center;
+
+		memset(fg, 0xff, sizeof(fg)); /* default to white */
+		memset(bg, 0x00, sizeof(bg)); /* default to black */
+
+		while((opt = getopt(argc, argv, "d:f:b:p:")) > 0) {
+			switch(opt) {
+			case 'd':
+				fbdev = optarg;
+				break;
+			case 'f':
+				/* FALLTHROUGH */
+			case 'b':
+				c     = (opt == 'f') ? fg : bg;
+				color = simple_strtoul(optarg, NULL, 16);
+
+				c[0] = color >> 16;
+				c[1] = color >>  8;
+				c[2] = color >>  0;
+				break;
+			case 'p':
+				place = NULL;
+				for (i = 0; i < ARRAY_SIZE(placements); i++)
+					if (!strcmp(optarg, placements[i].name))
+						place = placements[i].func;
+
+				if (!place) {
+					pr_err("Unknown placement: %s\n",
+					       optarg);
+					return -EINVAL;
+				}
+				break;
+			default:
+				return COMMAND_ERROR_USAGE;
+			}
+		}
+	}
+
+	/*
+	 * If no framebuffer device was passed to us, or in case if
+	 * CONFIG_CMD_VERSION_OUTPUT_TO_FRAMEBUFFER is not enabled we
+	 * resort to commands old behaviour.
+	 */
+	if (!fbdev) {
+		printf ("\n%s\n", version_string);
+		return 0;
+	}
+
+	font = find_font_enum(0);
+	if (!font) {
+		pr_err("Couldn't find any suitable fonts to use\n");
+		return -ENOENT;
+	}
+
+	sc = fb_open(fbdev);
+	if (IS_ERR(sc)) {
+		perror("unable to open framebuffer device");
+		return PTR_ERR(sc);
+	}
+
+	text_width  = strlen(version_string) * font->width;
+	text_height = font->height;
+
+	placement = place(sc, text_width, text_height);
+	/*
+	 * Draw a small frame around the version text
+	 */
+	gu_fill_rectangle(sc,
+			  placement.x - FRAME_SIZE,
+			  placement.y - FRAME_SIZE,
+			  placement.x + text_width  + FRAME_SIZE,
+			  placement.y + text_height + FRAME_SIZE,
+			  bg[0], bg[1], bg[2], 0xff);
+	/*
+	 * Then render the version string on the screen
+	 */
+	gu_draw_text(sc, font,
+		     placement.x, placement.y, version_string,
+		     fg[0], fg[1], fg[2], 0xff, bg[0], bg[1], bg[2], 0xff);
+
+	gu_screen_blit(sc);
+	fb_close(sc);
+
 	return 0;
 }
 
+BAREBOX_CMD_HELP_START(version)
+BAREBOX_CMD_HELP_TEXT("This command renders version information to a "
+		      "console/framebuffer")
+#ifdef CONFIG_CMD_VERSION_OUTPUT_TO_FRAMEBUFFER
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-d <fbdev>\t", "framebuffer device (if omitted, version "
+		      "is sent to active console(s))")
+BAREBOX_CMD_HELP_OPT ("-f color\t", "foreground color, in hex RRGGBB format")
+BAREBOX_CMD_HELP_OPT ("-b color\t", "background color, in hex RRGGBB format")
+BAREBOX_CMD_HELP_OPT ("-p placement\t",
+		      "version info placement (center, upper-left, lower-left, "
+		      "upper-right, lower-right)")
+#endif
+BAREBOX_CMD_HELP_END
+
 BAREBOX_CMD_START(version)
 	.cmd		= do_version,
 	BAREBOX_CMD_DESC("print barebox version")
+#ifdef CONFIG_CMD_VERSION_OUTPUT_TO_FRAMEBUFFER
+	BAREBOX_CMD_OPTS("[-dcp]")
+#endif
 	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
-	BAREBOX_CMD_COMPLETE(empty_complete)
+	BAREBOX_CMD_HELP(cmd_version_help)
 BAREBOX_CMD_END
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 4/4] commands: version: Add framebuffer output support
  2018-02-05 17:29 ` [PATCH 4/4] commands: version: Add framebuffer output support Andrey Smirnov
@ 2018-02-09  7:29   ` Sascha Hauer
  2018-02-16 13:39     ` Andrey Smirnov
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2018-02-09  7:29 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

Hi Andrey,

On Mon, Feb 05, 2018 at 09:29:35AM -0800, Andrey Smirnov wrote:
> Extend "version" command to be capable of rendeing version information
> on framebuffer devices.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  commands/Kconfig   |   8 +++
>  commands/version.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 204 insertions(+), 2 deletions(-)
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index 095536849..1cad5d608 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -238,6 +238,14 @@ config CMD_VERSION
>  
>  	  barebox 2014.05.0-00142-gb289373 #177 Mon May 12 20:35:55 CEST 2014
>  
> +config CMD_VERSION_OUTPUT_TO_FRAMEBUFFER
> +       bool
> +       depends on CMD_VERSION
> +       prompt "support displaying version via framebuffer"
> +       help
> +         Selecting this option will enable version command to output
> +         version information onto display backed by a frambuffer
> +
>  config CMD_MMC_EXTCSD
>  	tristate
>  	prompt "read/write eMMC ext. CSD register"
> diff --git a/commands/version.c b/commands/version.c
> index 090f2dd13..ba74a993c 100644
> --- a/commands/version.c
> +++ b/commands/version.c
> @@ -20,16 +20,210 @@
>  #include <common.h>
>  #include <command.h>
>  #include <complete.h>
> +#include <getopt.h>
> +#include <fb.h>
> +#include <gui/graphic_utils.h>
> +#include <gui/2d-primitives.h>
> +
> +#define FRAME_SIZE	8
> +
> +struct placement {
> +	int x, y;
> +};
> +
> +typedef struct placement placement_function_t (struct screen *, int, int);
> +
> +struct placement
> +placement_center(struct screen *sc, int text_width, int text_height)
> +{
> +	struct placement p;
> +
> +	p.x = (sc->info->xres - text_width) / 2;
> +	p.y = (sc->info->yres - text_height) / 2;
> +
> +	return p;
> +}
> +
> +struct placement
> +placement_upper_left(struct screen *sc, int text_width, int text_height)
> +{
> +	struct placement p;
> +
> +	p.x = FRAME_SIZE;
> +	p.y = FRAME_SIZE;
> +
> +	return p;
> +}
> +
> +struct placement
> +placement_upper_right(struct screen *sc, int text_width, int text_height)
> +{
> +	struct placement p;
> +
> +	p.x = sc->info->xres - 1 - text_width - FRAME_SIZE;
> +	p.y = FRAME_SIZE;
> +
> +	return p;
> +}
> +
> +struct placement
> +placement_lower_left(struct screen *sc, int text_width, int text_height)
> +{
> +	struct placement p;
> +
> +	p.x = FRAME_SIZE;
> +	p.y = sc->info->yres - 1 - text_height - FRAME_SIZE;
> +
> +	return p;
> +}
> +
> +struct placement
> +placement_lower_right(struct screen *sc, int text_width, int text_height)
> +{
> +	struct placement p;
> +
> +	p.x = sc->info->xres - 1 - text_width  - FRAME_SIZE;
> +	p.y = sc->info->yres - 1 - text_height - FRAME_SIZE;
> +
> +	return p;
> +}
>  
>  static int do_version(int argc, char *argv[])
>  {
> -	printf ("\n%s\n", version_string);
> +	const struct font_desc *font;
> +	const char *fbdev = NULL;
> +	struct screen *sc;
> +	u8 fg[3], bg[3];
> +	int text_width;
> +	int text_height;
> +
> +	placement_function_t *place;
> +	struct placement placement;
> +
> +	if (IS_ENABLED(CONFIG_CMD_VERSION_OUTPUT_TO_FRAMEBUFFER)) {

This is quite much code added to the version command, given that the
command previously only was a one-liner. I think this should rather be a
separate command. This could depend on framebuffer and other needed
stuff which would make the first two patches unnecessary. I think
stubbing away graphics functions when the user is graphics-only code is
a bit over the top.

The placement functions look as if they should be moved to some font
handling generic code.

Also it's always nice to have a C API for anything we also have as
command. It has proven to be useful so many times.

> +BAREBOX_CMD_HELP_OPT ("-f color\t", "foreground color, in hex RRGGBB format")
> +BAREBOX_CMD_HELP_OPT ("-b color\t", "background color, in hex RRGGBB format")

I'm not sure how useful these are as parameters to a command. How about
a nv variable? This could be used by the framebuffer console aswell.

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 4/4] commands: version: Add framebuffer output support
  2018-02-09  7:29   ` Sascha Hauer
@ 2018-02-16 13:39     ` Andrey Smirnov
  0 siblings, 0 replies; 6+ messages in thread
From: Andrey Smirnov @ 2018-02-16 13:39 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Thu, Feb 8, 2018 at 11:29 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> Hi Andrey,
>
> On Mon, Feb 05, 2018 at 09:29:35AM -0800, Andrey Smirnov wrote:
>> Extend "version" command to be capable of rendeing version information
>> on framebuffer devices.
>>
>> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
>> ---
>>  commands/Kconfig   |   8 +++
>>  commands/version.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>>  2 files changed, 204 insertions(+), 2 deletions(-)
>>
>> diff --git a/commands/Kconfig b/commands/Kconfig
>> index 095536849..1cad5d608 100644
>> --- a/commands/Kconfig
>> +++ b/commands/Kconfig
>> @@ -238,6 +238,14 @@ config CMD_VERSION
>>
>>         barebox 2014.05.0-00142-gb289373 #177 Mon May 12 20:35:55 CEST 2014
>>
>> +config CMD_VERSION_OUTPUT_TO_FRAMEBUFFER
>> +       bool
>> +       depends on CMD_VERSION
>> +       prompt "support displaying version via framebuffer"
>> +       help
>> +         Selecting this option will enable version command to output
>> +         version information onto display backed by a frambuffer
>> +
>>  config CMD_MMC_EXTCSD
>>       tristate
>>       prompt "read/write eMMC ext. CSD register"
>> diff --git a/commands/version.c b/commands/version.c
>> index 090f2dd13..ba74a993c 100644
>> --- a/commands/version.c
>> +++ b/commands/version.c
>> @@ -20,16 +20,210 @@
>>  #include <common.h>
>>  #include <command.h>
>>  #include <complete.h>
>> +#include <getopt.h>
>> +#include <fb.h>
>> +#include <gui/graphic_utils.h>
>> +#include <gui/2d-primitives.h>
>> +
>> +#define FRAME_SIZE   8
>> +
>> +struct placement {
>> +     int x, y;
>> +};
>> +
>> +typedef struct placement placement_function_t (struct screen *, int, int);
>> +
>> +struct placement
>> +placement_center(struct screen *sc, int text_width, int text_height)
>> +{
>> +     struct placement p;
>> +
>> +     p.x = (sc->info->xres - text_width) / 2;
>> +     p.y = (sc->info->yres - text_height) / 2;
>> +
>> +     return p;
>> +}
>> +
>> +struct placement
>> +placement_upper_left(struct screen *sc, int text_width, int text_height)
>> +{
>> +     struct placement p;
>> +
>> +     p.x = FRAME_SIZE;
>> +     p.y = FRAME_SIZE;
>> +
>> +     return p;
>> +}
>> +
>> +struct placement
>> +placement_upper_right(struct screen *sc, int text_width, int text_height)
>> +{
>> +     struct placement p;
>> +
>> +     p.x = sc->info->xres - 1 - text_width - FRAME_SIZE;
>> +     p.y = FRAME_SIZE;
>> +
>> +     return p;
>> +}
>> +
>> +struct placement
>> +placement_lower_left(struct screen *sc, int text_width, int text_height)
>> +{
>> +     struct placement p;
>> +
>> +     p.x = FRAME_SIZE;
>> +     p.y = sc->info->yres - 1 - text_height - FRAME_SIZE;
>> +
>> +     return p;
>> +}
>> +
>> +struct placement
>> +placement_lower_right(struct screen *sc, int text_width, int text_height)
>> +{
>> +     struct placement p;
>> +
>> +     p.x = sc->info->xres - 1 - text_width  - FRAME_SIZE;
>> +     p.y = sc->info->yres - 1 - text_height - FRAME_SIZE;
>> +
>> +     return p;
>> +}
>>
>>  static int do_version(int argc, char *argv[])
>>  {
>> -     printf ("\n%s\n", version_string);
>> +     const struct font_desc *font;
>> +     const char *fbdev = NULL;
>> +     struct screen *sc;
>> +     u8 fg[3], bg[3];
>> +     int text_width;
>> +     int text_height;
>> +
>> +     placement_function_t *place;
>> +     struct placement placement;
>> +
>> +     if (IS_ENABLED(CONFIG_CMD_VERSION_OUTPUT_TO_FRAMEBUFFER)) {
>
> This is quite much code added to the version command, given that the
> command previously only was a one-liner. I think this should rather be a
> separate command. This could depend on framebuffer and other needed
> stuff which would make the first two patches unnecessary. I think
> stubbing away graphics functions when the user is graphics-only code is
> a bit over the top.
>

OK, will change in v2.

> The placement functions look as if they should be moved to some font
> handling generic code.

OK, will do.

>
> Also it's always nice to have a C API for anything we also have as
> command. It has proven to be useful so many times.
>

Sure, will do.

>> +BAREBOX_CMD_HELP_OPT ("-f color\t", "foreground color, in hex RRGGBB format")
>> +BAREBOX_CMD_HELP_OPT ("-b color\t", "background color, in hex RRGGBB format")
>
> I'm not sure how useful these are as parameters to a command. How about
> a nv variable? This could be used by the framebuffer console aswell.
>

Sure, sounds reasonable.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-02-16 13:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-05 17:29 [PATCH 1/4] 2d-primitives: Introduce gu_draw_text() Andrey Smirnov
2018-02-05 17:29 ` [PATCH 2/4] gui: graphic_utils: Stub out fb_* functions Andrey Smirnov
2018-02-05 17:29 ` [PATCH 3/4] linux/font.h: Stub out font functions Andrey Smirnov
2018-02-05 17:29 ` [PATCH 4/4] commands: version: Add framebuffer output support Andrey Smirnov
2018-02-09  7:29   ` Sascha Hauer
2018-02-16 13:39     ` Andrey Smirnov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox