diff mbox series

[v2,27/32] sandbox: sdl: Add an option to double the screen size

Message ID 20200203073614.v2.27.I48cb07fb0d542000360e9f2585be5e895a73d586@changeid
State Superseded
Headers show
Series sandbox: Move to SDL2 | expand

Commit Message

Simon Glass Feb. 3, 2020, 2:36 p.m. UTC
On high-DPI displays U-Boot's LCD window can look very small. Add a
-K flag to expand it to make things easier to read, while still using
the existing resolution internally.

Signed-off-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Anatolij Gustschin <agust at denx.de>
---

Changes in v2: None

 arch/sandbox/cpu/sdl.c           | 17 +++++++++++++++--
 arch/sandbox/cpu/start.c         | 10 ++++++++++
 arch/sandbox/include/asm/sdl.h   |  9 ++++++---
 arch/sandbox/include/asm/state.h |  1 +
 drivers/video/sandbox_sdl.c      |  5 ++++-
 5 files changed, 36 insertions(+), 6 deletions(-)

Comments

Simon Glass Feb. 6, 2020, 2:31 a.m. UTC | #1
On high-DPI displays U-Boot's LCD window can look very small. Add a
-K flag to expand it to make things easier to read, while still using
the existing resolution internally.

Signed-off-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Anatolij Gustschin <agust at denx.de>
---

Changes in v2: None

 arch/sandbox/cpu/sdl.c           | 17 +++++++++++++++--
 arch/sandbox/cpu/start.c         | 10 ++++++++++
 arch/sandbox/include/asm/sdl.h   |  9 ++++++---
 arch/sandbox/include/asm/state.h |  1 +
 drivers/video/sandbox_sdl.c      |  5 ++++-
 5 files changed, 36 insertions(+), 6 deletions(-)

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index 58a9cc8168..6416cab96c 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -30,6 +30,8 @@  struct buf_info {
  *
  * @width: Width of simulated LCD display
  * @height: Height of simulated LCD display
+ * @vis_width: Visible width (may be larger to allow for scaling up)
+ * @vis_height: Visible height (may be larger to allow for scaling up)
  * @depth: Depth of the display in bits per pixel (16 or 32)
  * @pitch: Number of bytes per line of the display
  * @sample_rate: Current sample rate for audio
@@ -46,6 +48,8 @@  struct buf_info {
 static struct sdl_info {
 	int width;
 	int height;
+	int vis_width;
+	int vis_height;
 	int depth;
 	int pitch;
 	uint sample_rate;
@@ -94,7 +98,8 @@  static int sandbox_sdl_ensure_init(void)
 	return 0;
 }
 
-int sandbox_sdl_init_display(int width, int height, int log2_bpp)
+int sandbox_sdl_init_display(int width, int height, int log2_bpp,
+			     bool double_size)
 {
 	struct sandbox_state *state = state_get_current();
 	int err;
@@ -110,11 +115,19 @@  int sandbox_sdl_init_display(int width, int height, int log2_bpp)
 	}
 	sdl.width = width;
 	sdl.height = height;
+	if (double_size) {
+		sdl.vis_width = sdl.width * 2;
+		sdl.vis_height = sdl.height * 2;
+	} else {
+		sdl.vis_width = sdl.width;
+		sdl.vis_height = sdl.height;
+	}
+
 	sdl.depth = 1 << log2_bpp;
 	sdl.pitch = sdl.width * sdl.depth / 8;
 	SDL_Window *screen = SDL_CreateWindow("U-Boot", SDL_WINDOWPOS_UNDEFINED,
 					      SDL_WINDOWPOS_UNDEFINED,
-					      sdl.width, sdl.height, 0);
+					      sdl.vis_width, sdl.vis_height, 0);
 	if (!screen) {
 		printf("Unable to initialise SDL screen: %s\n",
 		       SDL_GetError());
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index fa53428436..3655ebf157 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -308,6 +308,16 @@  static int sandbox_cmdline_cb_show_lcd(struct sandbox_state *state,
 SANDBOX_CMDLINE_OPT_SHORT(show_lcd, 'l', 0,
 			  "Show the sandbox LCD display");
 
+static int sandbox_cmdline_cb_double_lcd(struct sandbox_state *state,
+					 const char *arg)
+{
+	state->double_lcd = true;
+
+	return 0;
+}
+SANDBOX_CMDLINE_OPT_SHORT(double_lcd, 'K', 0,
+			  "Double the LCD display size in each direction");
+
 static const char *term_args[STATE_TERM_COUNT] = {
 	"raw-with-sigs",
 	"raw",
diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h
index c45dbddd70..47fc4889d2 100644
--- a/arch/sandbox/include/asm/sdl.h
+++ b/arch/sandbox/include/asm/sdl.h
@@ -17,10 +17,13 @@ 
  * @height	Window height in pixels
  * @log2_bpp:	Log to base 2 of the number of bits per pixel. So a 32bpp
  *		display will pass 5, since 2*5 = 32
+ * @double_size: true to double the visible size in each direction for high-DPI
+ *		displays
  * @return 0 if OK, -ENODEV if no device, -EIO if SDL failed to initialize
  *		and -EPERM if the video failed to come up.
  */
-int sandbox_sdl_init_display(int width, int height, int log2_bpp);
+int sandbox_sdl_init_display(int width, int height, int log2_bpp,
+			     bool double_size);
 
 /**
  * sandbox_sdl_sync() - Sync current U-Boot LCD frame buffer to SDL
@@ -78,8 +81,8 @@  int sandbox_sdl_sound_stop(void);
 int sandbox_sdl_sound_init(int rate, int channels);
 
 #else
-static inline int sandbox_sdl_init_display(int width, int height,
-					    int log2_bpp)
+static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp,
+					   bool double_size)
 {
 	return -ENODEV;
 }
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index ad3e94beb9..705645d714 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -83,6 +83,7 @@  struct sandbox_state {
 	bool write_state;		/* Write sandbox state on exit */
 	bool ignore_missing_state_on_read;	/* No error if state missing */
 	bool show_lcd;			/* Show LCD on start-up */
+	bool double_lcd;		/* Double display size for high-DPI */
 	enum sysreset_t last_sysreset;	/* Last system reset type */
 	bool sysreset_allowed[SYSRESET_COUNT];	/* Allowed system reset types */
 	enum state_terminal_raw term_raw;	/* Terminal raw/cooked */
diff --git a/drivers/video/sandbox_sdl.c b/drivers/video/sandbox_sdl.c
index 913651c565..d1272d0918 100644
--- a/drivers/video/sandbox_sdl.c
+++ b/drivers/video/sandbox_sdl.c
@@ -8,6 +8,7 @@ 
 #include <fdtdec.h>
 #include <video.h>
 #include <asm/sdl.h>
+#include <asm/state.h>
 #include <asm/u-boot-sandbox.h>
 #include <dm/test.h>
 
@@ -23,9 +24,11 @@  static int sandbox_sdl_probe(struct udevice *dev)
 {
 	struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct sandbox_state *state = state_get_current();
 	int ret;
 
-	ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix);
+	ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
+				       state->double_lcd);
 	if (ret) {
 		puts("LCD init failed\n");
 		return ret;