[Intel-gfx] [PATCH xf86-video-intel 06/21] sna: Add sna_br13_color_depth()
Ville Syrjala
ville.syrjala at linux.intel.com
Thu Sep 19 16:30:58 UTC 2019
From: Ville Syrjälä <ville.syrjala at 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 at 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
More information about the Intel-gfx
mailing list