From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 3/8] vga: Separate LE and BE conversion functions
Date: Mon, 22 Sep 2014 16:44:51 +0200 [thread overview]
Message-ID: <1411397096-31566-4-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1411397096-31566-1-git-send-email-kraxel@redhat.com>
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Provide different functions for converting from an LE vs a BE
framebuffer. We cannot rely on the simple cases always being
shared surfaces since cirrus will need to always shadow for
cursor emulation, so we need the full set of functions to
be able to later handle runtime switching.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>\
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/display/vga.c | 47 +++++++++++++-------
hw/display/vga_template.h | 110 +++++++++++++++++++++++++++++++++++-----------
2 files changed, 114 insertions(+), 43 deletions(-)
diff --git a/hw/display/vga.c b/hw/display/vga.c
index 3d3de9e..8724f04 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -1374,10 +1374,14 @@ enum {
VGA_DRAW_LINE4D2,
VGA_DRAW_LINE8D2,
VGA_DRAW_LINE8,
- VGA_DRAW_LINE15,
- VGA_DRAW_LINE16,
- VGA_DRAW_LINE24,
- VGA_DRAW_LINE32,
+ VGA_DRAW_LINE15_LE,
+ VGA_DRAW_LINE16_LE,
+ VGA_DRAW_LINE24_LE,
+ VGA_DRAW_LINE32_LE,
+ VGA_DRAW_LINE15_BE,
+ VGA_DRAW_LINE16_BE,
+ VGA_DRAW_LINE24_BE,
+ VGA_DRAW_LINE32_BE,
VGA_DRAW_LINE_NB,
};
@@ -1388,10 +1392,14 @@ static vga_draw_line_func * const vga_draw_line_table[VGA_DRAW_LINE_NB] = {
vga_draw_line4d2,
vga_draw_line8d2,
vga_draw_line8,
- vga_draw_line15,
- vga_draw_line16,
- vga_draw_line24,
- vga_draw_line32,
+ vga_draw_line15_le,
+ vga_draw_line16_le,
+ vga_draw_line24_le,
+ vga_draw_line32_le,
+ vga_draw_line15_be,
+ vga_draw_line16_be,
+ vga_draw_line24_be,
+ vga_draw_line32_be,
};
static int vga_get_bpp(VGACommonState *s)
@@ -1464,10 +1472,15 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)
uint8_t *d;
uint32_t v, addr1, addr;
vga_draw_line_func *vga_draw_line;
-#if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
- static const bool byteswap = false;
+#if defined(TARGET_WORDS_BIGENDIAN)
+ static const bool big_endian_fb = true;
#else
- static const bool byteswap = true;
+ static const bool big_endian_fb = false;
+#endif
+#if defined(HOST_WORDS_BIGENDIAN)
+ static const bool byteswap = !big_endian_fb;
+#else
+ static const bool byteswap = big_endian_fb;
#endif
full_update |= update_basic_params(s);
@@ -1572,19 +1585,19 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)
bits = 8;
break;
case 15:
- v = VGA_DRAW_LINE15;
- bits = 16;
+ v = big_endian_fb ? VGA_DRAW_LINE15_BE : VGA_DRAW_LINE15_LE;
+ bits = 15;
break;
case 16:
- v = VGA_DRAW_LINE16;
- bits = 16;
+ v = big_endian_fb ? VGA_DRAW_LINE16_BE : VGA_DRAW_LINE16_LE;
+ bits = 15;
break;
case 24:
- v = VGA_DRAW_LINE24;
+ v = big_endian_fb ? VGA_DRAW_LINE24_BE : VGA_DRAW_LINE24_LE;
bits = 24;
break;
case 32:
- v = VGA_DRAW_LINE32;
+ v = big_endian_fb ? VGA_DRAW_LINE32_BE : VGA_DRAW_LINE32_LE;
bits = 32;
break;
}
diff --git a/hw/display/vga_template.h b/hw/display/vga_template.h
index 41fc764..94f6de2 100644
--- a/hw/display/vga_template.h
+++ b/hw/display/vga_template.h
@@ -278,21 +278,36 @@ static void vga_draw_line8(VGACommonState *s1, uint8_t *d,
}
}
-
-/* XXX: optimize */
-
/*
* 15 bit color
*/
-static void vga_draw_line15(VGACommonState *s1, uint8_t *d,
- const uint8_t *s, int width)
+static void vga_draw_line15_le(VGACommonState *s1, uint8_t *d,
+ const uint8_t *s, int width)
{
int w;
uint32_t v, r, g, b;
w = width;
do {
- v = lduw_p((void *)s);
+ v = lduw_le_p((void *)s);
+ r = (v >> 7) & 0xf8;
+ g = (v >> 2) & 0xf8;
+ b = (v << 3) & 0xf8;
+ ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
+ s += 2;
+ d += 4;
+ } while (--w != 0);
+}
+
+static void vga_draw_line15_be(VGACommonState *s1, uint8_t *d,
+ const uint8_t *s, int width)
+{
+ int w;
+ uint32_t v, r, g, b;
+
+ w = width;
+ do {
+ v = lduw_be_p((void *)s);
r = (v >> 7) & 0xf8;
g = (v >> 2) & 0xf8;
b = (v << 3) & 0xf8;
@@ -305,15 +320,33 @@ static void vga_draw_line15(VGACommonState *s1, uint8_t *d,
/*
* 16 bit color
*/
-static void vga_draw_line16(VGACommonState *s1, uint8_t *d,
- const uint8_t *s, int width)
+static void vga_draw_line16_le(VGACommonState *s1, uint8_t *d,
+ const uint8_t *s, int width)
{
int w;
uint32_t v, r, g, b;
w = width;
do {
- v = lduw_p((void *)s);
+ v = lduw_le_p((void *)s);
+ r = (v >> 8) & 0xf8;
+ g = (v >> 3) & 0xfc;
+ b = (v << 3) & 0xf8;
+ ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
+ s += 2;
+ d += 4;
+ } while (--w != 0);
+}
+
+static void vga_draw_line16_be(VGACommonState *s1, uint8_t *d,
+ const uint8_t *s, int width)
+{
+ int w;
+ uint32_t v, r, g, b;
+
+ w = width;
+ do {
+ v = lduw_be_p((void *)s);
r = (v >> 8) & 0xf8;
g = (v >> 3) & 0xfc;
b = (v << 3) & 0xf8;
@@ -326,23 +359,34 @@ static void vga_draw_line16(VGACommonState *s1, uint8_t *d,
/*
* 24 bit color
*/
-static void vga_draw_line24(VGACommonState *s1, uint8_t *d,
- const uint8_t *s, int width)
+static void vga_draw_line24_le(VGACommonState *s1, uint8_t *d,
+ const uint8_t *s, int width)
{
int w;
uint32_t r, g, b;
w = width;
do {
-#if defined(TARGET_WORDS_BIGENDIAN)
- r = s[0];
- g = s[1];
- b = s[2];
-#else
b = s[0];
g = s[1];
r = s[2];
-#endif
+ ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
+ s += 3;
+ d += 4;
+ } while (--w != 0);
+}
+
+static void vga_draw_line24_be(VGACommonState *s1, uint8_t *d,
+ const uint8_t *s, int width)
+{
+ int w;
+ uint32_t r, g, b;
+
+ w = width;
+ do {
+ r = s[0];
+ g = s[1];
+ b = s[2];
((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
s += 3;
d += 4;
@@ -352,10 +396,10 @@ static void vga_draw_line24(VGACommonState *s1, uint8_t *d,
/*
* 32 bit color
*/
-static void vga_draw_line32(VGACommonState *s1, uint8_t *d,
- const uint8_t *s, int width)
+static void vga_draw_line32_le(VGACommonState *s1, uint8_t *d,
+ const uint8_t *s, int width)
{
-#if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
+#ifndef HOST_WORDS_BIGENDIAN
memcpy(d, s, width * 4);
#else
int w;
@@ -363,15 +407,9 @@ static void vga_draw_line32(VGACommonState *s1, uint8_t *d,
w = width;
do {
-#if defined(TARGET_WORDS_BIGENDIAN)
- r = s[1];
- g = s[2];
- b = s[3];
-#else
b = s[0];
g = s[1];
r = s[2];
-#endif
((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
s += 4;
d += 4;
@@ -379,3 +417,23 @@ static void vga_draw_line32(VGACommonState *s1, uint8_t *d,
#endif
}
+static void vga_draw_line32_be(VGACommonState *s1, uint8_t *d,
+ const uint8_t *s, int width)
+{
+#ifdef HOST_WORDS_BIGENDIAN
+ memcpy(d, s, width * 4);
+#else
+ int w;
+ uint32_t r, g, b;
+
+ w = width;
+ do {
+ r = s[1];
+ g = s[2];
+ b = s[3];
+ ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
+ s += 4;
+ d += 4;
+ } while (--w != 0);
+#endif
+}
--
1.8.3.1
next prev parent reply other threads:[~2014-09-22 14:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-22 14:44 [Qemu-devel] [PATCH 0/8] vga cleanup series Gerd Hoffmann
2014-09-22 14:44 ` [Qemu-devel] [PATCH 1/8] vga: Start cutting out non-32bpp conversion support Gerd Hoffmann
2014-09-26 4:10 ` David Gibson
2014-09-22 14:44 ` [Qemu-devel] [PATCH 2/8] vga: Remove remainder of old conversion cruft Gerd Hoffmann
2014-09-26 4:10 ` David Gibson
2014-09-22 14:44 ` Gerd Hoffmann [this message]
2014-09-26 4:16 ` [Qemu-devel] [PATCH 3/8] vga: Separate LE and BE conversion functions David Gibson
2014-09-26 6:25 ` Gerd Hoffmann
2014-09-22 14:44 ` [Qemu-devel] [PATCH 4/8] vga: Remove rgb_to_pixel indirection Gerd Hoffmann
2014-09-26 4:18 ` David Gibson
2014-09-22 14:44 ` [Qemu-devel] [PATCH 5/8] vga: Simplify vga_draw_blank() a bit Gerd Hoffmann
2014-09-26 4:20 ` David Gibson
2014-09-22 14:44 ` [Qemu-devel] [PATCH 6/8] cirrus: Remove non-32bpp cursor drawing Gerd Hoffmann
2014-09-26 4:21 ` David Gibson
2014-09-22 14:44 ` [Qemu-devel] [PATCH 7/8] vga: Remove some "should be done in BIOS" comments Gerd Hoffmann
2014-09-26 4:22 ` David Gibson
2014-09-22 14:44 ` [Qemu-devel] [PATCH 8/8] vga: Rename vga_template.h to vga-helpers.h Gerd Hoffmann
2014-09-26 4:22 ` David Gibson
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=1411397096-31566-4-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).