All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dzmitry Sankouski <dsankouski@gmail.com>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Dzmitry Sankouski <dsankouski@gmail.com>,
	Simon Glass <sjg@chromium.org>,
	Anatolij Gustschin <agust@denx.de>
Subject: [PATCH v8 05/10] video console: move vidconsole_get_font_size() logic to driver ops
Date: Tue,  7 Mar 2023 13:21:15 +0300	[thread overview]
Message-ID: <20230307102121.1925581-6-dsankouski@gmail.com> (raw)
In-Reply-To: <20230307102121.1925581-1-dsankouski@gmail.com>

Since multiple vidconsole drivers exists, vidconsole_get_font_size()
implementation cannot longer live in vidconsole_uclass.c file.

Move current vidconsole_get_font_size logic to truetype driver ops.

Signed-off-by: Dzmitry Sankouski <dsankouski@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

Changes in v8:
none

Changes in v7:
N/A

Changes in v6:
N/A

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v3:
N/A

Changes in v2:
N/A

 cmd/font.c                        |  6 +++++-
 drivers/video/console_truetype.c  |  3 ++-
 drivers/video/vidconsole-uclass.c | 11 +++++++++++
 include/video_console.h           | 14 ++++++++++++--
 test/cmd/font.c                   | 13 +++++++------
 5 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/cmd/font.c b/cmd/font.c
index 7b4347f32b..fe2d65caaf 100644
--- a/cmd/font.c
+++ b/cmd/font.c
@@ -61,7 +61,11 @@ static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
 		return CMD_RET_FAILURE;
-	font_name = vidconsole_get_font_size(dev, &size);
+	ret = vidconsole_get_font_size(dev, &font_name, &size);
+	if (ret) {
+		printf("Failed (error %d)\n", ret);
+		return CMD_RET_FAILURE;
+	}
 
 	size = dectoul(argv[1], NULL);
 
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 9cac9a6de4..6b5390136a 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -724,7 +724,7 @@ static int truetype_select_font(struct udevice *dev, const char *name,
 	return 0;
 }
 
-const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep)
+const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep)
 {
 	struct console_tt_priv *priv = dev_get_priv(dev);
 	struct console_tt_metrics *met = priv->cur_met;
@@ -773,6 +773,7 @@ struct vidconsole_ops console_truetype_ops = {
 	.backspace	= console_truetype_backspace,
 	.entry_start	= console_truetype_entry_start,
 	.get_font	= console_truetype_get_font,
+	.get_font_size	= console_truetype_get_font_size,
 	.select_font	= truetype_select_font,
 };
 
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 72a13d3052..a5f2350ca1 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -575,6 +575,17 @@ int vidconsole_get_font(struct udevice *dev, int seq,
 	return ops->get_font(dev, seq, info);
 }
 
+int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep)
+{
+	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+	if (!ops->get_font_size)
+		return -ENOSYS;
+
+	*name = ops->get_font_size(dev, sizep);
+	return 0;
+}
+
 int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
 {
 	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
diff --git a/include/video_console.h b/include/video_console.h
index 3e1e00c23f..770103284b 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -160,6 +160,15 @@ struct vidconsole_ops {
 	int (*get_font)(struct udevice *dev, int seq,
 			struct vidfont_info *info);
 
+	/**
+	 * get_font_size() - get the current font name and size
+	 *
+	 * @dev: vidconsole device
+	 * @sizep: Place to put the font size (nominal height in pixels)
+	 * Returns: Current font name
+	 */
+	const char *(*get_font_size)(struct udevice *dev, uint *sizep);
+
 	/**
 	 * select_font() - Select a particular font by name / size
 	 *
@@ -303,9 +312,10 @@ void vidconsole_list_fonts(struct udevice *dev);
  *
  * @dev: vidconsole device
  * @sizep: Place to put the font size (nominal height in pixels)
- * Returns: Current font name
+ * @name: pointer to font name, a placeholder for result
+ * Return: 0 if OK, -ENOSYS if not implemented in driver
  */
-const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep);
+int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep);
 
 #ifdef CONFIG_VIDEO_COPY
 /**
diff --git a/test/cmd/font.c b/test/cmd/font.c
index adb353965a..40682e5ce4 100644
--- a/test/cmd/font.c
+++ b/test/cmd/font.c
@@ -19,6 +19,7 @@
 static int font_test_base(struct unit_test_state *uts)
 {
 	struct udevice *dev;
+	const char *name;
 	int max_metrics;
 	uint size;
 	int ret;
@@ -32,8 +33,8 @@ static int font_test_base(struct unit_test_state *uts)
 	ut_assert_nextline("cantoraone_regular");
 	ut_assertok(ut_check_console_end(uts));
 
-	ut_asserteq_str("nimbus_sans_l_regular",
-			vidconsole_get_font_size(dev, &size));
+	ut_assertok(vidconsole_get_font_size(dev, &name, &size));
+	ut_asserteq_str("nimbus_sans_l_regular", name);
 	ut_asserteq(18, size);
 
 	max_metrics = 1;
@@ -52,15 +53,15 @@ static int font_test_base(struct unit_test_state *uts)
 	ut_assertok(ret);
 	ut_assertok(ut_check_console_end(uts));
 
-	ut_asserteq_str("cantoraone_regular",
-			vidconsole_get_font_size(dev, &size));
+	ut_assertok(vidconsole_get_font_size(dev, &name, &size));
+	ut_asserteq_str("cantoraone_regular", name);
 	ut_asserteq(40, size);
 
 	ut_assertok(run_command("font size 30", 0));
 	ut_assertok(ut_check_console_end(uts));
 
-	ut_asserteq_str("cantoraone_regular",
-			vidconsole_get_font_size(dev, &size));
+	ut_assertok(vidconsole_get_font_size(dev, &name, &size));
+	ut_asserteq_str("cantoraone_regular", name);
 	ut_asserteq(30, size);
 
 	return 0;
-- 
2.30.2


  parent reply	other threads:[~2023-03-07 10:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 10:21 [PATCH v8 00/10] vidconsole: refactoring and support for wider fonts Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 01/10] video console: refactoring and optimization Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 02/10] video console: add support for fonts wider than 1 byte Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 03/10] video console: move 8x16 font data in named header Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 04/10] video console: implement multiple fonts configuration Dzmitry Sankouski
2023-03-07 15:22   ` Anatolij Gustschin
2023-03-10  8:35     ` Dzmitry Sankouski
2023-03-10  9:24       ` Anatolij Gustschin
2023-03-07 10:21 ` Dzmitry Sankouski [this message]
2023-03-07 10:21 ` [PATCH v8 06/10] video console: allow font size configuration at runtime Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 07/10] video console: add 12x22 Sun font from linux Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 08/10] video console: add 16x32 Terminus " Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 09/10] video console: sandbox: add 12x22 font defconfigs Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 10/10] video console: add 12x22 console simple font test Dzmitry Sankouski
2023-03-10  9:26 ` [PATCH v8 00/10] vidconsole: refactoring and support for wider fonts Anatolij Gustschin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230307102121.1925581-6-dsankouski@gmail.com \
    --to=dsankouski@gmail.com \
    --cc=agust@denx.de \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.