All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ville Syrjala <ville.syrjala@linux.intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH xf86-video-intel 06/21] sna: Add sna_br13_color_depth()
Date: Thu, 19 Sep 2019 19:30:58 +0300	[thread overview]
Message-ID: <20190919163113.17402-7-ville.syrjala@linux.intel.com> (raw)
In-Reply-To: <20190919163113.17402-1-ville.syrjala@linux.intel.com>

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Refactor the BR13 color depth setup to common helper. This
eliminates a bunch of implicit fall through warns.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 src/sna/kgem.c    | 10 +++------
 src/sna/sna.h     | 19 ++++++++++++++++
 src/sna/sna_blt.c | 56 ++++++++++-------------------------------------
 src/sna/sna_io.c  | 30 ++++++++-----------------
 4 files changed, 43 insertions(+), 72 deletions(-)

diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index d396f1b40dbc..9c0708a635fb 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -8148,13 +8148,9 @@ kgem_replace_bo(struct kgem *kgem,
 	}
 
 	br13 |= 0xcc << 16;
-	switch (bpp) {
-	default:
-	case 32: br00 |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-		 br13 |= 1 << 25; /* RGB8888 */
-	case 16: br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	br13 |= sna_br13_color_depth(bpp);
+	if (bpp == 32)
+		br00 |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
 
 	b = kgem->batch + kgem->nbatch;
 	if (kgem->gen >= 0100) {
diff --git a/src/sna/sna.h b/src/sna/sna.h
index cf2a7a519f29..f2bc189624a5 100644
--- a/src/sna/sna.h
+++ b/src/sna/sna.h
@@ -1397,4 +1397,23 @@ static inline void add_shm_flush(struct sna *sna, struct sna_pixmap *priv)
 	sna->needs_shm_flush = true;
 }
 
+static inline uint32_t sna_br13_color_depth(int bpp)
+{
+	uint32_t br13 = 0;
+
+	switch (bpp) {
+	default:
+		assert(0);
+		/* fall through */
+	case 32:
+		br13 |= 1 << 25; /* RGB8888 */
+		/* fall through */
+	case 16:
+		br13 |= 1 << 24; /* RGB565 */
+		/* fall through */
+	case 8:
+		return br13;
+	}
+}
+
 #endif /* _SNA_H */
diff --git a/src/sna/sna_blt.c b/src/sna/sna_blt.c
index 61e2b0feaf35..005224363b9c 100644
--- a/src/sna/sna_blt.c
+++ b/src/sna/sna_blt.c
@@ -154,12 +154,7 @@ static bool sna_blt_fill_init(struct sna *sna,
 	}
 
 	blt->br13 |= 1<<31 | (fill_ROP[alu] << 16);
-	switch (bpp) {
-	default: assert(0);
-	case 32: blt->br13 |= 1 << 25; /* RGB8888 */
-	case 16: blt->br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	blt->br13 |= sna_br13_color_depth(bpp);
 
 	blt->pixel = pixel;
 	blt->bpp = bpp;
@@ -372,12 +367,7 @@ static bool sna_blt_copy_init(struct sna *sna,
 
 	blt->overwrites = alu == GXcopy || alu == GXclear || alu == GXset;
 	blt->br13 = (copy_ROP[alu] << 16) | blt->pitch[1];
-	switch (bpp) {
-	default: assert(0);
-	case 32: blt->br13 |= 1 << 25; /* RGB8888 */
-	case 16: blt->br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	blt->br13 |= sna_br13_color_depth(bpp);
 
 	kgem_set_mode(kgem, KGEM_BLT, dst);
 	if (!kgem_check_many_bo_fenced(kgem, src, dst, NULL)) {
@@ -425,13 +415,10 @@ static bool sna_blt_alpha_fixup_init(struct sna *sna,
 
 	blt->overwrites = 1;
 	blt->br13 = (0xfc << 16) | blt->pitch[1];
-	switch (bpp) {
-	default: assert(0);
-	case 32: blt->cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-		 blt->br13 |= 1 << 25; /* RGB8888 */
-	case 16: blt->br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	blt->br13 |= sna_br13_color_depth(bpp);
+	if (bpp == 32)
+		blt->cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+
 	blt->pixel = alpha;
 
 	kgem_set_mode(kgem, KGEM_BLT, dst);
@@ -3356,13 +3343,9 @@ static bool sna_blt_fill_box(struct sna *sna, uint8_t alu,
 	assert(br13 <= MAXSHORT);
 
 	br13 |= fill_ROP[alu] << 16;
-	switch (bpp) {
-	default: assert(0);
-	case 32: cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-		 br13 |= 1 << 25; /* RGB8888 */
-	case 16: br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	br13 |= sna_br13_color_depth(bpp);
+	if (bpp == 32)
+		cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
 
 	/* All too frequently one blt completely overwrites the previous */
 	overwrites = alu == GXcopy || alu == GXclear || alu == GXset;
@@ -3517,12 +3500,7 @@ bool sna_blt_fill_boxes(struct sna *sna, uint8_t alu,
 	assert(br13 <= MAXSHORT);
 
 	br13 |= 1<<31 | fill_ROP[alu] << 16;
-	switch (bpp) {
-	default: assert(0);
-	case 32: br13 |= 1 << 25; /* RGB8888 */
-	case 16: br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	br13 |= sna_br13_color_depth(bpp);
 
 	kgem_set_mode(kgem, KGEM_BLT, bo);
 	if (!kgem_check_batch(kgem, 14) ||
@@ -3739,12 +3717,7 @@ bool sna_blt_copy_boxes(struct sna *sna, uint8_t alu,
 	assert(br13 <= MAXSHORT);
 
 	br13 |= copy_ROP[alu] << 16;
-	switch (bpp) {
-	default: assert(0);
-	case 32: br13 |= 1 << 25; /* RGB8888 */
-	case 16: br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	br13 |= sna_br13_color_depth(bpp);
 
 	/* Compare first box against a previous fill */
 	if ((alu == GXcopy || alu == GXclear || alu == GXset) &&
@@ -4086,12 +4059,7 @@ bool sna_blt_copy_boxes__with_alpha(struct sna *sna, uint8_t alu,
 	assert(br13 <= MAXSHORT);
 
 	br13 |= copy_ROP[alu] << 16;
-	switch (bpp) {
-	default: assert(0);
-	case 32: br13 |= 1 << 25; /* RGB8888 */
-	case 16: br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	br13 |= sna_br13_color_depth(bpp);
 
 	kgem_set_mode(kgem, KGEM_BLT, dst_bo);
 	if (!kgem_check_many_bo_fenced(kgem, dst_bo, src_bo, NULL)) {
diff --git a/src/sna/sna_io.c b/src/sna/sna_io.c
index d32bd583fc42..d03280edb7a7 100644
--- a/src/sna/sna_io.c
+++ b/src/sna/sna_io.c
@@ -465,13 +465,9 @@ fallback:
 	}
 
 	br13 = 0xcc << 16;
-	switch (cpp) {
-	default:
-	case 4: cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-		br13 |= 1 << 25; /* RGB8888 */
-	case 2: br13 |= 1 << 24; /* RGB565 */
-	case 1: break;
-	}
+	br13 |= sna_br13_color_depth(cpp * 4);
+	if (cpp == 4)
+		cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
 
 	kgem_set_mode(kgem, KGEM_BLT, dst_bo);
 	if (!kgem_check_batch(kgem, 10) ||
@@ -1042,13 +1038,9 @@ tile:
 		br13 >>= 2;
 	}
 	br13 |= 0xcc << 16;
-	switch (dst->drawable.bitsPerPixel) {
-	default:
-	case 32: cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-		 br13 |= 1 << 25; /* RGB8888 */
-	case 16: br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	br13 |= sna_br13_color_depth(dst->drawable.bitsPerPixel);
+	if (dst->drawable.bitsPerPixel == 32)
+		cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
 
 	kgem_set_mode(kgem, KGEM_BLT, dst_bo);
 	if (!kgem_check_batch(kgem, 10) ||
@@ -1548,13 +1540,9 @@ tile:
 		br13 >>= 2;
 	}
 	br13 |= 0xcc << 16;
-	switch (dst->drawable.bitsPerPixel) {
-	default:
-	case 32: cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-		 br13 |= 1 << 25; /* RGB8888 */
-	case 16: br13 |= 1 << 24; /* RGB565 */
-	case 8: break;
-	}
+	br13 |= sna_br13_color_depth(dst->drawable.bitsPerPixel);
+	if (dst->drawable.bitsPerPixel == 32)
+		cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
 
 	kgem_set_mode(kgem, KGEM_BLT, dst_bo);
 	if (!kgem_check_batch(kgem, 10) ||
-- 
2.21.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-09-19 16:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19 16:30 [PATCH xf86-video-intel 00/21] Compiler warn elimination Ville Syrjala
2019-09-19 16:30 ` [PATCH xf86-video-intel 01/21] sna: Use -Wno-clobbered Ville Syrjala
2019-09-19 16:30 ` [PATCH xf86-video-intel 02/21] sna: Shut up more compiler warns Ville Syrjala
2019-09-19 16:30 ` [PATCH xf86-video-intel 03/21] sna: undef FontSetPrivate() before redefining it Ville Syrjala
2019-09-19 16:30 ` [PATCH xf86-video-intel 04/21] sna: Replace fall through comments with standard form Ville Syrjala
2019-09-19 16:30 ` [PATCH xf86-video-intel 05/21] sna: Annotate more fall throughs Ville Syrjala
2019-09-19 16:30 ` Ville Syrjala [this message]
2019-09-19 16:30 ` [PATCH xf86-video-intel 07/21] sna/fb: Eliminate implicit fallthrough Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 08/21] uxa: Use named initializers Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 09/21] Avoid missing initializer warning Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 10/21] sna: Use named initializers Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 11/21] sna: Increase the size of the path name buffer a bit Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 12/21] sna: Use memcmp() to avoid strict aliasing warns Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 13/21] sna: Avoid strict aliasing violations with glyphinfo Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 14/21] sna/fb: Use memcpy() to avoid strict aliasing violations Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 15/21] xvmc: Eliminate " Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 16/21] sna/fb: Initialize xoff/yoff Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 17/21] sna: Use -Wno-maybe-uninitialized Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 18/21] sna: Get rid of -Wno-shift-negative-value Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 19/21] uxa: " Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 20/21] tools: Get rid of -Wno-sign-compare Ville Syrjala
2019-09-19 16:31 ` [PATCH xf86-video-intel 21/21] sna: Fix compiler warnings due to DrawablePtr vs. PixmapPtr Ville Syrjala
2019-09-27 19:41 ` [PATCH xf86-video-intel 00/21] Compiler warn elimination Chris Wilson

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=20190919163113.17402-7-ville.syrjala@linux.intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /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.