Skip to contentSkip to conversation

hw/display/blizzard: remove blizzard_template.h

PATCH In review Peter Maydell 3 participants 7 messages May 4, 2016 – May 9, 2016

lore
Share & tools
lore
#0 lore raw

cover hw/display/blizzard: remove blizzard_template.h

Now that we can rely on the display surface being 32 bits, the whole machinery of blizzard_template.h being included once per supported depth is unnecessary.

This series expands out the DEPTH-dependent macros, and then moves the remaining code into blizzard.c and removes the header file.

It applies on top of Pooja Dhannawat's patch
"blizzard: Remove support for DEPTH != 32" (which you can also find in my target-arm.next branch:
https://git.linaro.org/people/peter.maydell/qemu-arm.git target-arm.next)

thanks
-- PMM

Peter Maydell (2):
hw/display/blizzard: Expand out macros
hw/display/blizzard: Remove blizzard_template.h

 hw/display/blizzard.c          |  79 ++++++++++++++++++++++++++-
 hw/display/blizzard_template.h | 118 -----------------------------------------
 2 files changed, 77 insertions(+), 120 deletions(-)
 delete mode 100644 hw/display/blizzard_template.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 hw/display/blizzard: Expand out macros

Now that we can assume that only depth 32 is possible, there's no need for the COPY_PIXEL1 and PIXEL_TYPE macros, and the SKIP_PIXEL, COPY_PIXEL and SWAP_WORDS macros aren't used at all. Expand out COPY_PIXEL1 and PIXEL_TYPE where they are used, delete the unused macro definitions, and expand out the uses of glue(name_prefix, DEPTH).

---
 hw/display/blizzard_template.h | 55 +++++++++++++-----------------------------
 1 file changed, 17 insertions(+), 38 deletions(-)
hw/display/blizzard_template.h +17 -38
index bc38d7a..ed96092 100644
@@ -18,21 +18,8 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#define SKIP_PIXEL(to)         (to += deststep)
-#if DEPTH == 32
-# define PIXEL_TYPE            uint32_t
-# define COPY_PIXEL(to, from)  do { *to = from; SKIP_PIXEL(to); } while (0)
-# define COPY_PIXEL1(to, from) (*to++ = from)
-#else
-# error unknown bit depth
-#endif
-
-#ifdef HOST_WORDS_BIGENDIAN
-# define SWAP_WORDS	1
-#endif
-
-static void glue(blizzard_draw_line16_, DEPTH)(PIXEL_TYPE *dest,
-                const uint16_t *src, unsigned int width)
+static void blizzard_draw_line16_32(uint32_t *dest,
+                                    const uint16_t *src, unsigned int width)
 {
     uint16_t data;
     unsigned int r, g, b;
@@ -45,12 +32,12 @@ static void glue(blizzard_draw_line16_, DEPTH)(PIXEL_TYPE *dest,
         data >>= 6;
         r = (data & 0x1f) << 3;
         data >>= 5;
-        COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
+        *dest++ = rgb_to_pixel32(r, g, b);
     }
 }
 
-static void glue(blizzard_draw_line24mode1_, DEPTH)(PIXEL_TYPE *dest,
-                const uint8_t *src, unsigned int width)
+static void blizzard_draw_line24mode1_32(uint32_t *dest,
+                                         const uint8_t *src, unsigned int width)
 {
     /* TODO: check if SDL 24-bit planes are not in the same format and
      * if so, use memcpy */
@@ -61,15 +48,15 @@ static void glue(blizzard_draw_line24mode1_, DEPTH)(PIXEL_TYPE *dest,
         r[0] = *src ++;
         r[1] = *src ++;
         b[0] = *src ++;
-        COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r[0], g[0], b[0]));
+        *dest++ = rgb_to_pixel32(r[0], g[0], b[0]);
         b[1] = *src ++;
         g[1] = *src ++;
-        COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r[1], g[1], b[1]));
+        *dest++ = rgb_to_pixel32(r[1], g[1], b[1]);
     }
 }
 
-static void glue(blizzard_draw_line24mode2_, DEPTH)(PIXEL_TYPE *dest,
-                const uint8_t *src, unsigned int width)
+static void blizzard_draw_line24mode2_32(uint32_t *dest,
+                                         const uint8_t *src, unsigned int width)
 {
     unsigned int r, g, b;
     const uint8_t *end = src + width;
@@ -78,24 +65,24 @@ static void glue(blizzard_draw_line24mode2_, DEPTH)(PIXEL_TYPE *dest,
         src ++;
         b = *src ++;
         g = *src ++;
-        COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
+        *dest++ = rgb_to_pixel32(r, g, b);
     }
 }
 
 /* No rotation */
-static blizzard_fn_t glue(blizzard_draw_fn_, DEPTH)[0x10] = {
+static blizzard_fn_t blizzard_draw_fn_32[0x10] = {
     NULL,
     /* RGB 5:6:5*/
-    (blizzard_fn_t) glue(blizzard_draw_line16_, DEPTH),
+    (blizzard_fn_t) blizzard_draw_line16_32,
     /* RGB 6:6:6 mode 1 */
-    (blizzard_fn_t) glue(blizzard_draw_line24mode1_, DEPTH),
+    (blizzard_fn_t) blizzard_draw_line24mode1_32,
     /* RGB 8:8:8 mode 1 */
-    (blizzard_fn_t) glue(blizzard_draw_line24mode1_, DEPTH),
+    (blizzard_fn_t) blizzard_draw_line24mode1_32,
     NULL, NULL,
     /* RGB 6:6:6 mode 2 */
-    (blizzard_fn_t) glue(blizzard_draw_line24mode2_, DEPTH),
+    (blizzard_fn_t) blizzard_draw_line24mode2_32,
     /* RGB 8:8:8 mode 2 */
-    (blizzard_fn_t) glue(blizzard_draw_line24mode2_, DEPTH),
+    (blizzard_fn_t) blizzard_draw_line24mode2_32,
     /* YUV 4:2:2 */
     NULL,
     /* YUV 4:2:0 */
@@ -104,15 +91,7 @@ static blizzard_fn_t glue(blizzard_draw_fn_, DEPTH)[0x10] = {
 };
 
 /* 90deg, 180deg and 270deg rotation */
-static blizzard_fn_t glue(blizzard_draw_fn_r_, DEPTH)[0x10] = {
+static blizzard_fn_t blizzard_draw_fn_r_32[0x10] = {
     /* TODO */
     [0 ... 0xf] = NULL,
 };
-
-#undef DEPTH
-#undef SKIP_PIXEL
-#undef COPY_PIXEL
-#undef COPY_PIXEL1
-#undef PIXEL_TYPE
-
-#undef SWAP_WORDS
Signature · 1 line
1.9.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-arm] [PATCH 1/2] hw/display/blizzard: Expand out macros

Quoted 10 lines · Peter Maydell

Now that we can assume that only depth 32 is possible, there's no need for the COPY_PIXEL1 and PIXEL_TYPE macros, and the SKIP_PIXEL, COPY_PIXEL and SWAP_WORDS macros aren't used at all. Expand out COPY_PIXEL1 and PIXEL_TYPE where they are used, delete the unused macro definitions, and expand out the uses of glue(name_prefix, DEPTH).

---
 hw/display/blizzard_template.h | 55 +++++++++++++-----------------------------
 1 file changed, 17 insertions(+), 38 deletions(-)

I might have broken into more patches, one per macro expansion; but the final patch was still small enough to review when merged, so keep it the way you have it.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

PATCH 2/2 hw/display/blizzard: Remove blizzard_template.h

In reply to Peter Maydell

We no longer need to do the "multiply include this header" trick with blizzard_template.h, and it is only used in a single .c file, so just put its contents inline in blizzard.c.

---
 hw/display/blizzard.c          | 79 +++++++++++++++++++++++++++++++++-
 hw/display/blizzard_template.h | 97 ------------------------------------------
 2 files changed, 77 insertions(+), 99 deletions(-)
 delete mode 100644 hw/display/blizzard_template.h
hw/display/blizzard.c +77 -2
index af0b51e..cbf07d1 100644
@@ -925,8 +925,83 @@ static void blizzard_update_display(void *opaque)
     s->my[1] = 0;
 }
 
-#define DEPTH 32
-#include "blizzard_template.h"
+static void blizzard_draw_line16_32(uint32_t *dest,
+                                    const uint16_t *src, unsigned int width)
+{
+    uint16_t data;
+    unsigned int r, g, b;
+    const uint16_t *end = (const void *) src + width;
+    while (src < end) {
+        data = *src ++;
+        b = (data & 0x1f) << 3;
+        data >>= 5;
+        g = (data & 0x3f) << 2;
+        data >>= 6;
+        r = (data & 0x1f) << 3;
+        data >>= 5;
+        *dest++ = rgb_to_pixel32(r, g, b);
+    }
+}
+
+static void blizzard_draw_line24mode1_32(uint32_t *dest,
+                                         const uint8_t *src, unsigned int width)
+{
+    /* TODO: check if SDL 24-bit planes are not in the same format and
+     * if so, use memcpy */
+    unsigned int r[2], g[2], b[2];
+    const uint8_t *end = src + width;
+    while (src < end) {
+        g[0] = *src ++;
+        r[0] = *src ++;
+        r[1] = *src ++;
+        b[0] = *src ++;
+        *dest++ = rgb_to_pixel32(r[0], g[0], b[0]);
+        b[1] = *src ++;
+        g[1] = *src ++;
+        *dest++ = rgb_to_pixel32(r[1], g[1], b[1]);
+    }
+}
+
+static void blizzard_draw_line24mode2_32(uint32_t *dest,
+                                         const uint8_t *src, unsigned int width)
+{
+    unsigned int r, g, b;
+    const uint8_t *end = src + width;
+    while (src < end) {
+        r = *src ++;
+        src ++;
+        b = *src ++;
+        g = *src ++;
+        *dest++ = rgb_to_pixel32(r, g, b);
+    }
+}
+
+/* No rotation */
+static blizzard_fn_t blizzard_draw_fn_32[0x10] = {
+    NULL,
+    /* RGB 5:6:5*/
+    (blizzard_fn_t) blizzard_draw_line16_32,
+    /* RGB 6:6:6 mode 1 */
+    (blizzard_fn_t) blizzard_draw_line24mode1_32,
+    /* RGB 8:8:8 mode 1 */
+    (blizzard_fn_t) blizzard_draw_line24mode1_32,
+    NULL, NULL,
+    /* RGB 6:6:6 mode 2 */
+    (blizzard_fn_t) blizzard_draw_line24mode2_32,
+    /* RGB 8:8:8 mode 2 */
+    (blizzard_fn_t) blizzard_draw_line24mode2_32,
+    /* YUV 4:2:2 */
+    NULL,
+    /* YUV 4:2:0 */
+    NULL,
+    NULL, NULL, NULL, NULL, NULL, NULL,
+};
+
+/* 90deg, 180deg and 270deg rotation */
+static blizzard_fn_t blizzard_draw_fn_r_32[0x10] = {
+    /* TODO */
+    [0 ... 0xf] = NULL,
+};
 
 static const GraphicHwOps blizzard_ops = {
     .invalidate  = blizzard_invalidate_display,
hw/display/blizzard_template.h deleted +0 -97

97 lines not on this page · raw message

Signature · 1 line
1.9.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [Qemu-arm] [PATCH 2/2] hw/display/blizzard: Remove blizzard_template.h

Quoted 11 lines · Peter Maydell

We no longer need to do the "multiply include this header" trick with blizzard_template.h, and it is only used in a single .c file, so just put its contents inline in blizzard.c.

---
 hw/display/blizzard.c          | 79 +++++++++++++++++++++++++++++++++-
 hw/display/blizzard_template.h | 97 ------------------------------------------
 2 files changed, 77 insertions(+), 99 deletions(-)
 delete mode 100644 hw/display/blizzard_template.h
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on the v1 series
#5 lore raw
In reply to Peter Maydell
Quoted 11 lines · Peter Maydell

Now that we can rely on the display surface being 32 bits, the whole machinery of blizzard_template.h being included once per supported depth is unnecessary.

This series expands out the DEPTH-dependent macros, and then moves the remaining code into blizzard.c and removes the header file.

It applies on top of Pooja Dhannawat's patch
"blizzard: Remove support for DEPTH != 32" (which you can also find in my target-arm.next branch:
https://git.linaro.org/people/peter.maydell/qemu-arm.git target-arm.next)

So you take those two through the arm queue too I guess?

cheers,
Gerd

#6 lore raw
Quoted 8 lines · Gerd Hoffmann
Quoted 7 lines · Peter Maydell

Now that we can rely on the display surface being 32 bits, the whole machinery of blizzard_template.h being included once per supported depth is unnecessary.

This series expands out the DEPTH-dependent macros, and then moves the remaining code into blizzard.c and removes the header file.

Quoted 6 lines
Quoted 4 lines

It applies on top of Pooja Dhannawat's patch
"blizzard: Remove support for DEPTH != 32" (which you can also find in my target-arm.next branch:
https://git.linaro.org/people/peter.maydell/qemu-arm.git target-arm.next)

So you take those two through the arm queue too I guess?

Yes.

Quoted 1 line

Thanks for the review.

-- PMM