All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] video: Avoid #ifdef to increase build coverage
@ 2019-12-21  1:10 Simon Glass
  2019-12-21  1:10 ` [PATCH 1/5] video: x86: Enable 32-bit graphics by default Simon Glass
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Simon Glass @ 2019-12-21  1:10 UTC (permalink / raw)
  To: u-boot

A recent change to the video subsystem added more #ifdefs to the code but
these are not necessary. In fact we can often rely on the compiler to drop
dead code. Using the IS_ENABLED() macros with if() can produce the same
result while reducing the number of build combinations in the code.

This series removes most #ifdefs from the core video code. Code size for
wandaboard (for example) does not change.

It also includes a patch to enable 32bpp video on x86, since video is
currently broken.


Simon Glass (5):
  video: x86: Enable 32-bit graphics by default
  video: Avoid using #ifdef in video blitting code
  video: Avoid using #ifdef in console_rotate.c
  video: Avoid using #ifdef in vidconsole-uclass.c
  video: Avoid using #ifdef in video-uclass.c

 drivers/video/Kconfig             |   5 +-
 drivers/video/console_normal.c    | 125 ++++++------
 drivers/video/console_rotate.c    | 325 +++++++++++++++---------------
 drivers/video/vidconsole-uclass.c |  22 +-
 drivers/video/video-uclass.c      |  54 +++--
 5 files changed, 256 insertions(+), 275 deletions(-)

-- 
2.24.1.735.g03f4e72817-goog

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

* [PATCH 1/5] video: x86: Enable 32-bit graphics by default
  2019-12-21  1:10 [PATCH 0/5] video: Avoid #ifdef to increase build coverage Simon Glass
@ 2019-12-21  1:10 ` Simon Glass
       [not found]   ` <20200102153306.59fd28f9@crub>
  2019-12-21  1:10 ` [PATCH 2/5] video: Avoid using #ifdef in video blitting code Simon Glass
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Simon Glass @ 2019-12-21  1:10 UTC (permalink / raw)
  To: u-boot

Most x86 boards that use video make use of 32bpp graphics. Enable this by
default. This fixes missing graphics output on some x86 boards.

Also remove the unnecessary 'default n' while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/Kconfig | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 4cde0acbf6..50ab3650ee 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -38,7 +38,6 @@ config BACKLIGHT_GPIO
 config VIDEO_BPP8
 	bool "Support 8-bit-per-pixel displays"
 	depends on DM_VIDEO
-	default n
 	help
 	  Support drawing text and bitmaps onto a 8-bit-per-pixel display.
 	  Enabling this will include code to support this display. Without
@@ -48,7 +47,6 @@ config VIDEO_BPP8
 config VIDEO_BPP16
 	bool "Support 16-bit-per-pixel displays"
 	depends on DM_VIDEO
-	default n
 	help
 	  Support drawing text and bitmaps onto a 16-bit-per-pixel display.
 	  Enabling this will include code to support this display. Without
@@ -58,7 +56,7 @@ config VIDEO_BPP16
 config VIDEO_BPP32
 	bool "Support 32-bit-per-pixel displays"
 	depends on DM_VIDEO
-	default n
+	default y if X86
 	help
 	  Support drawing text and bitmaps onto a 32-bit-per-pixel display.
 	  Enabling this will include code to support this display. Without
@@ -68,7 +66,6 @@ config VIDEO_BPP32
 config VIDEO_ANSI
 	bool "Support ANSI escape sequences in video console"
 	depends on DM_VIDEO
-	default n
 	help
 	  Enable ANSI escape sequence decoding for a more fully functional
 	  console.
-- 
2.24.1.735.g03f4e72817-goog

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

* [PATCH 2/5] video: Avoid using #ifdef in video blitting code
  2019-12-21  1:10 [PATCH 0/5] video: Avoid #ifdef to increase build coverage Simon Glass
  2019-12-21  1:10 ` [PATCH 1/5] video: x86: Enable 32-bit graphics by default Simon Glass
@ 2019-12-21  1:10 ` Simon Glass
  2019-12-21  1:10 ` [PATCH 3/5] video: Avoid using #ifdef in console_rotate.c Simon Glass
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Simon Glass @ 2019-12-21  1:10 UTC (permalink / raw)
  To: u-boot

This code does not really need to use #ifdef. We can use if() instead and
gain build coverage without impacting code size.

Change the #ifdefs to use IS_ENABLED() instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/console_normal.c | 125 ++++++++++++++++-----------------
 1 file changed, 61 insertions(+), 64 deletions(-)

diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 2f25af7332..c3f7ef8add 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -16,39 +16,36 @@
 static int console_normal_set_row(struct udevice *dev, uint row, int clr)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
-	void * __maybe_unused line;
-	int __maybe_unused pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
-	int __maybe_unused i;
+	void *line;
+	int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
+	int i;
 
 	line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
 	switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
-	case VIDEO_BPP8: {
-		uint8_t *dst = line;
+	case VIDEO_BPP8:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+			uint8_t *dst = line;
 
-		for (i = 0; i < pixels; i++)
-			*dst++ = clr;
-		break;
-	}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
-	case VIDEO_BPP16: {
-		uint16_t *dst = line;
-
-		for (i = 0; i < pixels; i++)
-			*dst++ = clr;
-		break;
-	}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
-	case VIDEO_BPP32: {
-		uint32_t *dst = line;
-
-		for (i = 0; i < pixels; i++)
-			*dst++ = clr;
-		break;
-	}
-#endif
+			for (i = 0; i < pixels; i++)
+				*dst++ = clr;
+			break;
+		}
+	case VIDEO_BPP16:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+			uint16_t *dst = line;
+
+			for (i = 0; i < pixels; i++)
+				*dst++ = clr;
+			break;
+		}
+	case VIDEO_BPP32:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+			uint32_t *dst = line;
+
+			for (i = 0; i < pixels; i++)
+				*dst++ = clr;
+			break;
+		}
 	default:
 		return -ENOSYS;
 	}
@@ -76,7 +73,7 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
 	struct udevice *vid = dev->parent;
 	struct video_priv *vid_priv = dev_get_uclass_priv(vid);
-	int __maybe_unused i, row;
+	int i, row;
 	void *line = vid_priv->fb + y * vid_priv->line_length +
 		VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
 
@@ -85,45 +82,45 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 
 	for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
 		unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
-		uchar __maybe_unused bits = video_fontdata[idx];
+		uchar bits = video_fontdata[idx];
 
 		switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
-		case VIDEO_BPP8: {
-			uint8_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-				*dst++ = (bits & 0x80) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
-				bits <<= 1;
+		case VIDEO_BPP8:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+				uint8_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
+					*dst++ = (bits & 0x80) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+					bits <<= 1;
+				}
+				break;
 			}
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
-		case VIDEO_BPP16: {
-			uint16_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-				*dst++ = (bits & 0x80) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
-				bits <<= 1;
+		case VIDEO_BPP16:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+				uint16_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
+					*dst++ = (bits & 0x80) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+					bits <<= 1;
+				}
+				break;
 			}
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
-		case VIDEO_BPP32: {
-			uint32_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-				*dst++ = (bits & 0x80) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
-				bits <<= 1;
+		case VIDEO_BPP32:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+				uint32_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
+					*dst++ = (bits & 0x80) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+					bits <<= 1;
+				}
+				break;
 			}
-			break;
-		}
-#endif
 		default:
 			return -ENOSYS;
 		}
-- 
2.24.1.735.g03f4e72817-goog

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

* [PATCH 3/5] video: Avoid using #ifdef in console_rotate.c
  2019-12-21  1:10 [PATCH 0/5] video: Avoid #ifdef to increase build coverage Simon Glass
  2019-12-21  1:10 ` [PATCH 1/5] video: x86: Enable 32-bit graphics by default Simon Glass
  2019-12-21  1:10 ` [PATCH 2/5] video: Avoid using #ifdef in video blitting code Simon Glass
@ 2019-12-21  1:10 ` Simon Glass
  2019-12-21  1:10 ` [PATCH 4/5] video: Avoid using #ifdef in vidconsole-uclass.c Simon Glass
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Simon Glass @ 2019-12-21  1:10 UTC (permalink / raw)
  To: u-boot

This code does not really need to use #ifdef. We can use if() instead and
gain build coverage without impacting code size.

Change the #ifdefs to use IS_ENABLED() instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/console_rotate.c | 325 ++++++++++++++++-----------------
 1 file changed, 158 insertions(+), 167 deletions(-)

diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
index 71a5c5efba..b485255598 100644
--- a/drivers/video/console_rotate.c
+++ b/drivers/video/console_rotate.c
@@ -22,33 +22,30 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
 		(row + 1) * VIDEO_FONT_HEIGHT * pbytes;
 	for (j = 0; j < vid_priv->ysize; j++) {
 		switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
-		case VIDEO_BPP8: {
-			uint8_t *dst = line;
+		case VIDEO_BPP8:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+				uint8_t *dst = line;
 
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-				*dst++ = clr;
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
-		case VIDEO_BPP16: {
-			uint16_t *dst = line;
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+					*dst++ = clr;
+				break;
+			}
+		case VIDEO_BPP16:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+				uint16_t *dst = line;
 
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-				*dst++ = clr;
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
-		case VIDEO_BPP32: {
-			uint32_t *dst = line;
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+					*dst++ = clr;
+				break;
+			}
+		case VIDEO_BPP32:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+				uint32_t *dst = line;
 
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-				*dst++ = clr;
-			break;
-		}
-#endif
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+					*dst++ = clr;
+				break;
+			}
 		default:
 			return -ENOSYS;
 		}
@@ -99,39 +96,39 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
 
 	for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
 		switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
-		case VIDEO_BPP8: {
-			uint8_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-				*dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
+		case VIDEO_BPP8:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+				uint8_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
+					*dst-- = (pfont[i] & mask) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+				}
+				break;
 			}
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
-		case VIDEO_BPP16: {
-			uint16_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-				*dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
+		case VIDEO_BPP16:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+				uint16_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
+					*dst-- = (pfont[i] & mask) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+				}
+				break;
 			}
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
-		case VIDEO_BPP32: {
-			uint32_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-				*dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
+		case VIDEO_BPP32:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+				uint32_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
+					*dst-- = (pfont[i] & mask) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+				}
+				break;
 			}
-			break;
-		}
-#endif
 		default:
 			return -ENOSYS;
 		}
@@ -153,33 +150,30 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
 	line = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
 		(row + 1) * VIDEO_FONT_HEIGHT * vid_priv->line_length;
 	switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
-	case VIDEO_BPP8: {
-		uint8_t *dst = line;
+	case VIDEO_BPP8:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+			uint8_t *dst = line;
 
-		for (i = 0; i < pixels; i++)
-			*dst++ = clr;
-		break;
-	}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
-	case VIDEO_BPP16: {
-		uint16_t *dst = line;
-
-		for (i = 0; i < pixels; i++)
-			*dst++ = clr;
-		break;
-	}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
-	case VIDEO_BPP32: {
-		uint32_t *dst = line;
-
-		for (i = 0; i < pixels; i++)
-			*dst++ = clr;
-		break;
-	}
-#endif
+			for (i = 0; i < pixels; i++)
+				*dst++ = clr;
+			break;
+		}
+	case VIDEO_BPP16:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+			uint16_t *dst = line;
+
+			for (i = 0; i < pixels; i++)
+				*dst++ = clr;
+			break;
+		}
+	case VIDEO_BPP32:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+			uint32_t *dst = line;
+
+			for (i = 0; i < pixels; i++)
+				*dst++ = clr;
+			break;
+		}
 	default:
 		return -ENOSYS;
 	}
@@ -226,42 +220,42 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
 		uchar bits = video_fontdata[idx];
 
 		switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
-		case VIDEO_BPP8: {
-			uint8_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-				*dst-- = (bits & 0x80) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
-				bits <<= 1;
+		case VIDEO_BPP8:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+				uint8_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
+					*dst-- = (bits & 0x80) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+					bits <<= 1;
+				}
+				break;
 			}
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
-		case VIDEO_BPP16: {
-			uint16_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-				*dst-- = (bits & 0x80) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
-				bits <<= 1;
+		case VIDEO_BPP16:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+				uint16_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
+					*dst-- = (bits & 0x80) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+					bits <<= 1;
+				}
+				break;
 			}
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
-		case VIDEO_BPP32: {
-			uint32_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
-				*dst-- = (bits & 0x80) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
-				bits <<= 1;
+		case VIDEO_BPP32:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+				uint32_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
+					*dst-- = (bits & 0x80) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+					bits <<= 1;
+				}
+				break;
 			}
-			break;
-		}
-#endif
 		default:
 			return -ENOSYS;
 		}
@@ -281,33 +275,30 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
 	line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
 	for (j = 0; j < vid_priv->ysize; j++) {
 		switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
-		case VIDEO_BPP8: {
-			uint8_t *dst = line;
+		case VIDEO_BPP8:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+				uint8_t *dst = line;
 
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-				*dst++ = clr;
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
-		case VIDEO_BPP16: {
-			uint16_t *dst = line;
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+					*dst++ = clr;
+				break;
+			}
+		case VIDEO_BPP16:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+				uint16_t *dst = line;
 
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-				*dst++ = clr;
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
-		case VIDEO_BPP32: {
-			uint32_t *dst = line;
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+					*dst++ = clr;
+				break;
+			}
+		case VIDEO_BPP32:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+				uint32_t *dst = line;
 
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
-				*dst++ = clr;
-			break;
-		}
-#endif
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+					*dst++ = clr;
+				break;
+			}
 		default:
 			return -ENOSYS;
 		}
@@ -356,39 +347,39 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
 
 	for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
 		switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
-		case VIDEO_BPP8: {
-			uint8_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-				*dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
+		case VIDEO_BPP8:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+				uint8_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
+					*dst++ = (pfont[i] & mask) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+				}
+				break;
 			}
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
-		case VIDEO_BPP16: {
-			uint16_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-				*dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
+		case VIDEO_BPP16:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+				uint16_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
+					*dst++ = (pfont[i] & mask) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+				}
+				break;
 			}
-			break;
-		}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
-		case VIDEO_BPP32: {
-			uint32_t *dst = line;
-
-			for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
-				*dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
-					: vid_priv->colour_bg;
+		case VIDEO_BPP32:
+			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+				uint32_t *dst = line;
+
+				for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
+					*dst++ = (pfont[i] & mask) ?
+						vid_priv->colour_fg :
+						vid_priv->colour_bg;
+				}
+				break;
 			}
-			break;
-		}
-#endif
 		default:
 			return -ENOSYS;
 		}
-- 
2.24.1.735.g03f4e72817-goog

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

* [PATCH 4/5] video: Avoid using #ifdef in vidconsole-uclass.c
  2019-12-21  1:10 [PATCH 0/5] video: Avoid #ifdef to increase build coverage Simon Glass
                   ` (2 preceding siblings ...)
  2019-12-21  1:10 ` [PATCH 3/5] video: Avoid using #ifdef in console_rotate.c Simon Glass
@ 2019-12-21  1:10 ` Simon Glass
  2019-12-21  1:10 ` [PATCH 5/5] video: Avoid using #ifdef in video-uclass.c Simon Glass
  2020-01-04 10:45 ` [PATCH 0/5] video: Avoid #ifdef to increase build coverage Anatolij Gustschin
  5 siblings, 0 replies; 12+ messages in thread
From: Simon Glass @ 2019-12-21  1:10 UTC (permalink / raw)
  To: u-boot

This code does not really need to use #ifdef. We can use if() instead and
gain build coverage without impacting code size.

Change the #ifdefs to use CONFIG_IS_ENABLED() instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/vidconsole-uclass.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index c690eceeaa..75c7e25095 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -116,7 +116,6 @@ static void vidconsole_newline(struct udevice *dev)
 	video_sync(dev->parent, false);
 }
 
-#if CONFIG_IS_ENABLED(VIDEO_BPP16) || CONFIG_IS_ENABLED(VIDEO_BPP32)
 static const struct vid_rgb colors[VID_COLOR_COUNT] = {
 	{ 0x00, 0x00, 0x00 },  /* black */
 	{ 0xc0, 0x00, 0x00 },  /* red */
@@ -135,23 +134,22 @@ static const struct vid_rgb colors[VID_COLOR_COUNT] = {
 	{ 0x00, 0xff, 0xff },  /* bright cyan */
 	{ 0xff, 0xff, 0xff },  /* white */
 };
-#endif
 
 u32 vid_console_color(struct video_priv *priv, unsigned int idx)
 {
 	switch (priv->bpix) {
-#if CONFIG_IS_ENABLED(VIDEO_BPP16)
 	case VIDEO_BPP16:
-		return ((colors[idx].r >> 3) << 11) |
-		       ((colors[idx].g >> 2) <<  5) |
-		       ((colors[idx].b >> 3) <<  0);
-#endif
-#if CONFIG_IS_ENABLED(VIDEO_BPP32)
+		if (CONFIG_IS_ENABLED(VIDEO_BPP16)) {
+			return ((colors[idx].r >> 3) << 11) |
+			       ((colors[idx].g >> 2) <<  5) |
+			       ((colors[idx].b >> 3) <<  0);
+		}
 	case VIDEO_BPP32:
-		return (colors[idx].r << 16) |
-		       (colors[idx].g <<  8) |
-		       (colors[idx].b <<  0);
-#endif
+		if (CONFIG_IS_ENABLED(VIDEO_BPP32)) {
+			return (colors[idx].r << 16) |
+			       (colors[idx].g <<  8) |
+			       (colors[idx].b <<  0);
+		}
 	default:
 		/*
 		 * For unknown bit arrangements just support
-- 
2.24.1.735.g03f4e72817-goog

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

* [PATCH 5/5] video: Avoid using #ifdef in video-uclass.c
  2019-12-21  1:10 [PATCH 0/5] video: Avoid #ifdef to increase build coverage Simon Glass
                   ` (3 preceding siblings ...)
  2019-12-21  1:10 ` [PATCH 4/5] video: Avoid using #ifdef in vidconsole-uclass.c Simon Glass
@ 2019-12-21  1:10 ` Simon Glass
  2020-01-04 10:45 ` [PATCH 0/5] video: Avoid #ifdef to increase build coverage Anatolij Gustschin
  5 siblings, 0 replies; 12+ messages in thread
From: Simon Glass @ 2019-12-21  1:10 UTC (permalink / raw)
  To: u-boot

This code does not really need to use #ifdef. We can use if() instead and
gain build coverage without impacting code size.

Change the #ifdefs to use IS_ENABLED(), etc., instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/video-uclass.c | 54 +++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 28 deletions(-)

diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 5ea7568fa4..12057c8a5b 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -92,26 +92,24 @@ int video_clear(struct udevice *dev)
 	struct video_priv *priv = dev_get_uclass_priv(dev);
 
 	switch (priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP16
-	case VIDEO_BPP16: {
-		u16 *ppix = priv->fb;
-		u16 *end = priv->fb + priv->fb_size;
-
-		while (ppix < end)
-			*ppix++ = priv->colour_bg;
-		break;
-	}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
-	case VIDEO_BPP32: {
-		u32 *ppix = priv->fb;
-		u32 *end = priv->fb + priv->fb_size;
-
-		while (ppix < end)
-			*ppix++ = priv->colour_bg;
-		break;
-	}
-#endif
+	case VIDEO_BPP16:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+			u16 *ppix = priv->fb;
+			u16 *end = priv->fb + priv->fb_size;
+
+			while (ppix < end)
+				*ppix++ = priv->colour_bg;
+			break;
+		}
+	case VIDEO_BPP32:
+		if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+			u32 *ppix = priv->fb;
+			u32 *end = priv->fb + priv->fb_size;
+
+			while (ppix < end)
+				*ppix++ = priv->colour_bg;
+			break;
+		}
 	default:
 		memset(priv->fb, priv->colour_bg, priv->fb_size);
 		break;
@@ -125,14 +123,14 @@ void video_set_default_colors(struct udevice *dev, bool invert)
 	struct video_priv *priv = dev_get_uclass_priv(dev);
 	int fore, back;
 
-#ifdef CONFIG_SYS_WHITE_ON_BLACK
-	/* White is used when switching to bold, use light gray here */
-	fore = VID_LIGHT_GRAY;
-	back = VID_BLACK;
-#else
-	fore = VID_BLACK;
-	back = VID_WHITE;
-#endif
+	if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) {
+		/* White is used when switching to bold, use light gray here */
+		fore = VID_LIGHT_GRAY;
+		back = VID_BLACK;
+	} else {
+		fore = VID_BLACK;
+		back = VID_WHITE;
+	}
 	if (invert) {
 		int temp;
 
-- 
2.24.1.735.g03f4e72817-goog

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

* [PATCH 1/5] video: x86: Enable 32-bit graphics by default
       [not found]   ` <20200102153306.59fd28f9@crub>
@ 2020-01-03  2:29     ` Simon Glass
  2020-01-03  2:41       ` Bin Meng
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Glass @ 2020-01-03  2:29 UTC (permalink / raw)
  To: u-boot

Hi Anatolij,

On Thu, 2 Jan 2020 at 07:34, Anatolij Gustschin <agust@denx.de> wrote:
>
> Hi Simon,
>
> On Fri, 20 Dec 2019 18:10:33 -0700
> Simon Glass sjg at chromium.org wrote:
>
> > Most x86 boards that use video make use of 32bpp graphics. Enable this by
> > default. This fixes missing graphics output on some x86 boards.
>
> Must this patch be applied for v2010.01 release?

I think so since these boards don't work for me at present.

What do you think, Bin?

Regards,
SImon

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

* [PATCH 1/5] video: x86: Enable 32-bit graphics by default
  2020-01-03  2:29     ` Simon Glass
@ 2020-01-03  2:41       ` Bin Meng
  2020-01-03  3:24         ` Simon Glass
  0 siblings, 1 reply; 12+ messages in thread
From: Bin Meng @ 2020-01-03  2:41 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Fri, Jan 3, 2020 at 10:30 AM Simon Glass <sjg@chromium.org> wrote:
>
> Hi Anatolij,
>
> On Thu, 2 Jan 2020 at 07:34, Anatolij Gustschin <agust@denx.de> wrote:
> >
> > Hi Simon,
> >
> > On Fri, 20 Dec 2019 18:10:33 -0700
> > Simon Glass sjg at chromium.org wrote:
> >
> > > Most x86 boards that use video make use of 32bpp graphics. Enable this by
> > > default. This fixes missing graphics output on some x86 boards.
> >
> > Must this patch be applied for v2010.01 release?
>
> I think so since these boards don't work for me at present.
>
> What do you think, Bin?
>

Which board is currently broken due to missing this config? Should it
be safer to move this to board defconfig?

Regards,
Bin

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

* [PATCH 1/5] video: x86: Enable 32-bit graphics by default
  2020-01-03  2:41       ` Bin Meng
@ 2020-01-03  3:24         ` Simon Glass
  2020-01-03 15:41           ` Bin Meng
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Glass @ 2020-01-03  3:24 UTC (permalink / raw)
  To: u-boot

Hi Bin,

On Thu, 2 Jan 2020 at 19:41, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Simon,
>
> On Fri, Jan 3, 2020 at 10:30 AM Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi Anatolij,
> >
> > On Thu, 2 Jan 2020 at 07:34, Anatolij Gustschin <agust@denx.de> wrote:
> > >
> > > Hi Simon,
> > >
> > > On Fri, 20 Dec 2019 18:10:33 -0700
> > > Simon Glass sjg at chromium.org wrote:
> > >
> > > > Most x86 boards that use video make use of 32bpp graphics. Enable this by
> > > > default. This fixes missing graphics output on some x86 boards.
> > >
> > > Must this patch be applied for v2010.01 release?
> >
> > I think so since these boards don't work for me at present.
> >
> > What do you think, Bin?
> >
>
> Which board is currently broken due to missing this config? Should it
> be safer to move this to board defconfig?

I think any x86 board with graphics would need this. Those that don't
enable VIDEO won't get the change anyway.

Regards,
Simon

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

* [PATCH 1/5] video: x86: Enable 32-bit graphics by default
  2020-01-03  3:24         ` Simon Glass
@ 2020-01-03 15:41           ` Bin Meng
  2020-01-03 16:16             ` Anatolij Gustschin
  0 siblings, 1 reply; 12+ messages in thread
From: Bin Meng @ 2020-01-03 15:41 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Fri, Jan 3, 2020 at 11:24 AM Simon Glass <sjg@chromium.org> wrote:
>
> Hi Bin,
>
> On Thu, 2 Jan 2020 at 19:41, Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > Hi Simon,
> >
> > On Fri, Jan 3, 2020 at 10:30 AM Simon Glass <sjg@chromium.org> wrote:
> > >
> > > Hi Anatolij,
> > >
> > > On Thu, 2 Jan 2020 at 07:34, Anatolij Gustschin <agust@denx.de> wrote:
> > > >
> > > > Hi Simon,
> > > >
> > > > On Fri, 20 Dec 2019 18:10:33 -0700
> > > > Simon Glass sjg at chromium.org wrote:
> > > >
> > > > > Most x86 boards that use video make use of 32bpp graphics. Enable this by
> > > > > default. This fixes missing graphics output on some x86 boards.
> > > >
> > > > Must this patch be applied for v2010.01 release?
> > >
> > > I think so since these boards don't work for me at present.
> > >
> > > What do you think, Bin?
> > >
> >
> > Which board is currently broken due to missing this config? Should it
> > be safer to move this to board defconfig?
>
> I think any x86 board with graphics would need this. Those that don't
> enable VIDEO won't get the change anyway.

OK, thanks. I had a test with QEMU x86 and looks good.

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

Regards,
Bin

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

* [PATCH 1/5] video: x86: Enable 32-bit graphics by default
  2020-01-03 15:41           ` Bin Meng
@ 2020-01-03 16:16             ` Anatolij Gustschin
  0 siblings, 0 replies; 12+ messages in thread
From: Anatolij Gustschin @ 2020-01-03 16:16 UTC (permalink / raw)
  To: u-boot

Hi all,

On Fri, 3 Jan 2020 23:41:49 +0800
Bin Meng bmeng.cn at gmail.com wrote:

> Hi Simon,
> 
> On Fri, Jan 3, 2020 at 11:24 AM Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi Bin,
> >
> > On Thu, 2 Jan 2020 at 19:41, Bin Meng <bmeng.cn@gmail.com> wrote:  
> > >
> > > Hi Simon,
> > >
> > > On Fri, Jan 3, 2020 at 10:30 AM Simon Glass <sjg@chromium.org> wrote:  
> > > >
> > > > Hi Anatolij,
> > > >
> > > > On Thu, 2 Jan 2020 at 07:34, Anatolij Gustschin <agust@denx.de> wrote:  
> > > > >
> > > > > Hi Simon,
> > > > >
> > > > > On Fri, 20 Dec 2019 18:10:33 -0700
> > > > > Simon Glass sjg at chromium.org wrote:
> > > > >  
> > > > > > Most x86 boards that use video make use of 32bpp graphics. Enable this by
> > > > > > default. This fixes missing graphics output on some x86 boards.  
> > > > >
> > > > > Must this patch be applied for v2010.01 release?  
> > > >
> > > > I think so since these boards don't work for me at present.
> > > >
> > > > What do you think, Bin?
> > > >  
> > >
> > > Which board is currently broken due to missing this config? Should it
> > > be safer to move this to board defconfig?  
> >
> > I think any x86 board with graphics would need this. Those that don't
> > enable VIDEO won't get the change anyway.  
> 
> OK, thanks. I had a test with QEMU x86 and looks good.
> 
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> Tested-by: Bin Meng <bmeng.cn@gmail.com>

Thanks for testing. I've submitted a pull request for this series
and Tom already merged the patches in master.

--
Anatolij

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

* [PATCH 0/5] video: Avoid #ifdef to increase build coverage
  2019-12-21  1:10 [PATCH 0/5] video: Avoid #ifdef to increase build coverage Simon Glass
                   ` (4 preceding siblings ...)
  2019-12-21  1:10 ` [PATCH 5/5] video: Avoid using #ifdef in video-uclass.c Simon Glass
@ 2020-01-04 10:45 ` Anatolij Gustschin
  5 siblings, 0 replies; 12+ messages in thread
From: Anatolij Gustschin @ 2020-01-04 10:45 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Fri, 20 Dec 2019 18:10:32 -0700
Simon Glass sjg at chromium.org wrote:
...
> Simon Glass (5):
>   video: x86: Enable 32-bit graphics by default
>   video: Avoid using #ifdef in video blitting code
>   video: Avoid using #ifdef in console_rotate.c
>   video: Avoid using #ifdef in vidconsole-uclass.c
>   video: Avoid using #ifdef in video-uclass.c
> 
>  drivers/video/Kconfig             |   5 +-
>  drivers/video/console_normal.c    | 125 ++++++------
>  drivers/video/console_rotate.c    | 325 +++++++++++++++---------------
>  drivers/video/vidconsole-uclass.c |  22 +-
>  drivers/video/video-uclass.c      |  54 +++--
>  5 files changed, 256 insertions(+), 275 deletions(-)

Series applied to u-boot-video/master, thanks!

--
Anatolij

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

end of thread, other threads:[~2020-01-04 10:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-21  1:10 [PATCH 0/5] video: Avoid #ifdef to increase build coverage Simon Glass
2019-12-21  1:10 ` [PATCH 1/5] video: x86: Enable 32-bit graphics by default Simon Glass
     [not found]   ` <20200102153306.59fd28f9@crub>
2020-01-03  2:29     ` Simon Glass
2020-01-03  2:41       ` Bin Meng
2020-01-03  3:24         ` Simon Glass
2020-01-03 15:41           ` Bin Meng
2020-01-03 16:16             ` Anatolij Gustschin
2019-12-21  1:10 ` [PATCH 2/5] video: Avoid using #ifdef in video blitting code Simon Glass
2019-12-21  1:10 ` [PATCH 3/5] video: Avoid using #ifdef in console_rotate.c Simon Glass
2019-12-21  1:10 ` [PATCH 4/5] video: Avoid using #ifdef in vidconsole-uclass.c Simon Glass
2019-12-21  1:10 ` [PATCH 5/5] video: Avoid using #ifdef in video-uclass.c Simon Glass
2020-01-04 10:45 ` [PATCH 0/5] video: Avoid #ifdef to increase build coverage Anatolij Gustschin

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.