[Spice-devel] [spice-common v2 09/15] quic: Wrap declaration/call of quic method in macros

Christophe Fergeau cfergeau at redhat.com
Tue Jul 10 09:02:16 UTC 2018


This allows to pass an additional 'channel' argument when needed, and
should eventually let us unify quic_tmpl.c and quic_rgb_tmpl.c

Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
---
 common/quic_rgb_tmpl.c | 122 ++++++++++++++++++++-------------------
 common/quic_tmpl.c     | 126 +++++++++++++++++++++--------------------
 2 files changed, 128 insertions(+), 120 deletions(-)

diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c
index 5dbc873..3af1d2e 100644
--- a/common/quic_rgb_tmpl.c
+++ b/common/quic_rgb_tmpl.c
@@ -19,6 +19,9 @@
 #include <config.h>
 #endif
 
+#define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
+#define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
+
 #ifdef QUIC_RGB32
 #undef QUIC_RGB32
 #define PIXEL rgb32_pixel_t
@@ -103,6 +106,9 @@
 #define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0)
 #endif
 
+#define FNAME_DECL(name) FNAME(name) FARGS_DECL
+#define FNAME_CALL(name) FNAME(name) FARGS_CALL
+
 #define SAME_PIXEL(p1, p2)                                 \
     (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) &&   \
      GET_b(p1) == GET_b(p2))
@@ -159,12 +165,12 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {
 
 #ifdef COMPRESS_IMP
 
-static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
-                                     const PIXEL * const cur_row,
-                                     const int end,
-                                     const unsigned int waitmask,
-                                     SPICE_GNUC_UNUSED const unsigned int bpc,
-                                     const unsigned int bpc_mask)
+static void FNAME_DECL(compress_row0_seg)(int i,
+                                          const PIXEL * const cur_row,
+                                          const int end,
+                                          const unsigned int waitmask,
+                                          SPICE_GNUC_UNUSED const unsigned int bpc,
+                                          const unsigned int bpc_mask)
 {
     CommonState *state = &encoder->rgb_state;
     Channel * const channel_r = encoder->channels;
@@ -207,8 +213,7 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i,
     state->waitcnt = stopidx - end;
 }
 
-static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
-                                 unsigned int width)
+static void FNAME_DECL(compress_row0)(const PIXEL *cur_row, unsigned int width)
 {
     CommonState *state = &encoder->rgb_state;
     const unsigned int bpc = BPC;
@@ -217,8 +222,8 @@ static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(compress_row0_seg)(encoder, pos, cur_row, pos + state->wmileft,
-                                     bppmask[state->wmidx], bpc, bpc_mask);
+            FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + state->wmileft,
+                                          bppmask[state->wmidx], bpc, bpc_mask);
             width -= state->wmileft;
             pos += state->wmileft;
         }
@@ -229,8 +234,8 @@ static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
     }
 
     if (width) {
-        FNAME(compress_row0_seg)(encoder, pos, cur_row, pos + width,
-                                 bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + width,
+                                      bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -253,13 +258,13 @@ static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row,
     golomb_coding(encoder, correlate_row_##channel[index],                                      \
                  find_bucket(channel_##channel, correlate_row_##channel[index - 1])->bestcode)
 
-static void FNAME(compress_row_seg)(Encoder *encoder, int i,
-                                    const PIXEL * const prev_row,
-                                    const PIXEL * const cur_row,
-                                    const int end,
-                                    const unsigned int waitmask,
-                                    SPICE_GNUC_UNUSED const unsigned int bpc,
-                                    const unsigned int bpc_mask)
+static void FNAME_DECL(compress_row_seg)(int i,
+                                         const PIXEL * const prev_row,
+                                         const PIXEL * const cur_row,
+                                         const int end,
+                                         const unsigned int waitmask,
+                                         SPICE_GNUC_UNUSED const unsigned int bpc,
+                                         const unsigned int bpc_mask)
 {
     CommonState *state = &encoder->rgb_state;
     Channel * const channel_r = encoder->channels;
@@ -324,10 +329,9 @@ do_run:
     }
 }
 
-static void FNAME(compress_row)(Encoder *encoder,
-                                const PIXEL * const prev_row,
-                                const PIXEL * const cur_row,
-                                unsigned int width)
+static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
+                                     const PIXEL * const cur_row,
+                                     unsigned int width)
 
 {
     CommonState *state = &encoder->rgb_state;
@@ -337,10 +341,9 @@ static void FNAME(compress_row)(Encoder *encoder,
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(compress_row_seg)(encoder, pos, prev_row, cur_row,
-                                    pos + state->wmileft,
-                                    bppmask[state->wmidx],
-                                    bpc, bpc_mask);
+            FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row,
+                                         pos + state->wmileft, bppmask[state->wmidx],
+                                         bpc, bpc_mask);
             width -= state->wmileft;
             pos += state->wmileft;
         }
@@ -351,8 +354,8 @@ static void FNAME(compress_row)(Encoder *encoder,
     }
 
     if (width) {
-        FNAME(compress_row_seg)(encoder, pos, prev_row, cur_row, pos + width,
-                                bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row, pos + width,
+                                     bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -381,12 +384,12 @@ static void FNAME(compress_row)(Encoder *encoder,
                   bpc_mask));                                                                     \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
-                                       PIXEL * const cur_row,
-                                       const int end,
-                                       const unsigned int waitmask,
-                                       SPICE_GNUC_UNUSED const unsigned int bpc,
-                                       const unsigned int bpc_mask)
+static void FNAME_DECL(uncompress_row0_seg)(int i,
+                                            PIXEL * const cur_row,
+                                            const int end,
+                                            const unsigned int waitmask,
+                                            SPICE_GNUC_UNUSED const unsigned int bpc,
+                                            const unsigned int bpc_mask)
 {
     CommonState *state = &encoder->rgb_state;
     Channel * const channel_r = encoder->channels;
@@ -437,9 +440,8 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, int i,
     state->waitcnt = stopidx - end;
 }
 
-static void FNAME(uncompress_row0)(Encoder *encoder,
-                                   PIXEL * const cur_row,
-                                   unsigned int width)
+static void FNAME_DECL(uncompress_row0)(PIXEL * const cur_row,
+                                        unsigned int width)
 
 {
     CommonState *state = &encoder->rgb_state;
@@ -449,10 +451,10 @@ static void FNAME(uncompress_row0)(Encoder *encoder,
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(uncompress_row0_seg)(encoder, pos, cur_row,
-                                       pos + state->wmileft,
-                                       bppmask[state->wmidx],
-                                       bpc, bpc_mask);
+            FNAME_CALL(uncompress_row0_seg)(pos, cur_row,
+                                            pos + state->wmileft,
+                                            bppmask[state->wmidx],
+                                            bpc, bpc_mask);
             pos += state->wmileft;
             width -= state->wmileft;
         }
@@ -463,8 +465,8 @@ static void FNAME(uncompress_row0)(Encoder *encoder,
     }
 
     if (width) {
-        FNAME(uncompress_row0_seg)(encoder, pos, cur_row, pos + width,
-                                   bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(uncompress_row0_seg)(pos, cur_row, pos + width,
+                                        bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -492,13 +494,12 @@ static void FNAME(uncompress_row0)(Encoder *encoder,
              &cur_row[i]);                                                                        \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row_seg)(Encoder *encoder,
-                                      const PIXEL * const prev_row,
-                                      PIXEL * const cur_row,
-                                      int i,
-                                      const int end,
-                                      SPICE_GNUC_UNUSED const unsigned int bpc,
-                                      const unsigned int bpc_mask)
+static void FNAME_DECL(uncompress_row_seg)(const PIXEL * const prev_row,
+                                           PIXEL * const cur_row,
+                                           int i,
+                                           const int end,
+                                           SPICE_GNUC_UNUSED const unsigned int bpc,
+                                           const unsigned int bpc_mask)
 {
     CommonState *state = &encoder->rgb_state;
     Channel * const channel_r = encoder->channels;
@@ -576,10 +577,9 @@ do_run:
     }
 }
 
-static void FNAME(uncompress_row)(Encoder *encoder,
-                                  const PIXEL * const prev_row,
-                                  PIXEL * const cur_row,
-                                  unsigned int width)
+static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
+                                       PIXEL * const cur_row,
+                                       unsigned int width)
 
 {
     CommonState *state = &encoder->rgb_state;
@@ -589,8 +589,8 @@ static void FNAME(uncompress_row)(Encoder *encoder,
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(uncompress_row_seg)(encoder, prev_row, cur_row, pos,
-                                      pos + state->wmileft, bpc, bpc_mask);
+            FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
+                                           pos + state->wmileft, bpc, bpc_mask);
             pos += state->wmileft;
             width -= state->wmileft;
         }
@@ -601,8 +601,8 @@ static void FNAME(uncompress_row)(Encoder *encoder,
     }
 
     if (width) {
-        FNAME(uncompress_row_seg)(encoder, prev_row, cur_row, pos,
-                                  pos + width, bpc, bpc_mask);
+        FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
+                                       pos + width, bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -614,7 +614,11 @@ static void FNAME(uncompress_row)(Encoder *encoder,
 }
 
 #undef PIXEL
+#undef FARGS_CALL
+#undef FARGS_DECL
 #undef FNAME
+#undef FNAME_CALL
+#undef FNAME_DECL
 #undef _PIXEL_A
 #undef _PIXEL_B
 #undef SAME_PIXEL
diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c
index 7a009f9..a7be9af 100644
--- a/common/quic_tmpl.c
+++ b/common/quic_tmpl.c
@@ -31,6 +31,11 @@
 #define PIXEL four_bytes_t
 #endif
 
+#define FARGS_DECL(...) (Encoder *encoder, Channel *channel_a, ##__VA_ARGS__)
+#define FARGS_CALL(...) (encoder, channel_a, ##__VA_ARGS__)
+#define FNAME_DECL(name) FNAME(name) FARGS_DECL
+#define FNAME_CALL(name) FNAME(name) FARGS_CALL
+
 #define golomb_coding golomb_coding_8bpc
 #define golomb_decoding golomb_decoding_8bpc
 #define update_model update_model_8bpc
@@ -95,12 +100,12 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {
 #define APPLY_ALL_COMP(macro, ...) \
     macro(a, ## __VA_ARGS__)
 
-static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i,
-                                     const PIXEL * const cur_row,
-                                     const int end,
-                                     const unsigned int waitmask,
-                                     SPICE_GNUC_UNUSED const unsigned int bpc,
-                                     const unsigned int bpc_mask)
+static void FNAME_DECL(compress_row0_seg)(int i,
+                                          const PIXEL * const cur_row,
+                                          const int end,
+                                          const unsigned int waitmask,
+                                          SPICE_GNUC_UNUSED const unsigned int bpc,
+                                          const unsigned int bpc_mask)
 {
     CommonState *state = &channel_a->state;
     BYTE * const correlate_row_a = channel_a->correlate_row;
@@ -140,18 +145,17 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel_a, int i
 #undef COMPRESS_ONE_ROW0_0
 #undef COMPRESS_ONE_ROW0
 
-static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL *cur_row,
-                                 unsigned int width)
+static void FNAME_DECL(compress_row0)(const PIXEL *cur_row, unsigned int width)
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     int pos = 0;
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(compress_row0_seg)(encoder, channel, pos, cur_row, pos + state->wmileft,
-                                     bppmask[state->wmidx], bpc, bpc_mask);
+            FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + state->wmileft,
+                                          bppmask[state->wmidx], bpc, bpc_mask);
             width -= state->wmileft;
             pos += state->wmileft;
         }
@@ -162,8 +166,8 @@ static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL
     }
 
     if (width) {
-        FNAME(compress_row0_seg)(encoder, channel, pos, cur_row, pos + width,
-                                 bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(compress_row0_seg)(pos, cur_row, pos + width,
+                                      bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -185,13 +189,13 @@ static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL
      golomb_coding(encoder, correlate_row_##channel[index],                                            \
                    find_bucket(channel_##channel, correlate_row_##channel[index - 1])->bestcode)
 
-static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel_a, int i,
-                                    const PIXEL * const prev_row,
-                                    const PIXEL * const cur_row,
-                                    const int end,
-                                    const unsigned int waitmask,
-                                    SPICE_GNUC_UNUSED const unsigned int bpc,
-                                    const unsigned int bpc_mask)
+static void FNAME_DECL(compress_row_seg)(int i,
+                                         const PIXEL * const prev_row,
+                                         const PIXEL * const cur_row,
+                                         const int end,
+                                         const unsigned int waitmask,
+                                         SPICE_GNUC_UNUSED const unsigned int bpc,
+                                         const unsigned int bpc_mask)
 {
     CommonState *state = &channel_a->state;
     BYTE * const correlate_row_a = channel_a->correlate_row;
@@ -250,22 +254,21 @@ do_run:
     }
 }
 
-static void FNAME(compress_row)(Encoder *encoder, Channel *channel,
-                                const PIXEL * const prev_row,
-                                const PIXEL * const cur_row,
-                                unsigned int width)
+static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
+                                     const PIXEL * const cur_row,
+                                     unsigned int width)
 
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(compress_row_seg)(encoder, channel, pos, prev_row, cur_row,
-                                    pos + state->wmileft, bppmask[state->wmidx],
-                                    bpc, bpc_mask);
+            FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row,
+                                         pos + state->wmileft, bppmask[state->wmidx],
+                                         bpc, bpc_mask);
             width -= state->wmileft;
             pos += state->wmileft;
         }
@@ -276,8 +279,8 @@ static void FNAME(compress_row)(Encoder *encoder, Channel *channel,
     }
 
     if (width) {
-        FNAME(compress_row_seg)(encoder, channel, pos, prev_row, cur_row, pos + width,
-                                bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(compress_row_seg)(pos, prev_row, cur_row, pos + width,
+                                     bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -305,12 +308,12 @@ static void FNAME(compress_row)(Encoder *encoder, Channel *channel,
                   bpc_mask));                                                                                  \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel_a, int i,
-                                       PIXEL * const cur_row,
-                                       const int end,
-                                       const unsigned int waitmask,
-                                       SPICE_GNUC_UNUSED const unsigned int bpc,
-                                       const unsigned int bpc_mask)
+static void FNAME_DECL(uncompress_row0_seg)(int i,
+                                            PIXEL * const cur_row,
+                                            const int end,
+                                            const unsigned int waitmask,
+                                            SPICE_GNUC_UNUSED const unsigned int bpc,
+                                            const unsigned int bpc_mask)
 {
     CommonState *state = &channel_a->state;
     BYTE * const correlate_row_a = channel_a->correlate_row;
@@ -355,21 +358,20 @@ static void FNAME(uncompress_row0_seg)(Encoder *encoder, Channel *channel_a, int
     state->waitcnt = stopidx - end;
 }
 
-static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
-                                   PIXEL * const cur_row,
-                                   unsigned int width)
+static void FNAME_DECL(uncompress_row0)(PIXEL * const cur_row, unsigned int width)
 
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(uncompress_row0_seg)(encoder, channel, pos, cur_row,
-                                       pos + state->wmileft, bppmask[state->wmidx],
-                                       bpc, bpc_mask);
+            FNAME_CALL(uncompress_row0_seg)(pos, cur_row,
+                                            pos + state->wmileft,
+                                            bppmask[state->wmidx],
+                                            bpc, bpc_mask);
             pos += state->wmileft;
             width -= state->wmileft;
         }
@@ -380,8 +382,8 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
     }
 
     if (width) {
-        FNAME(uncompress_row0_seg)(encoder, channel, pos, cur_row, pos + width,
-                                   bppmask[state->wmidx], bpc, bpc_mask);
+        FNAME_CALL(uncompress_row0_seg)(pos, cur_row, pos + width,
+                                        bppmask[state->wmidx], bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -408,13 +410,12 @@ static void FNAME(uncompress_row0)(Encoder *encoder, Channel *channel,
               &cur_row[i]);                                                                                   \
     decode_eatbits(encoder, codewordlen);
 
-static void FNAME(uncompress_row_seg)(Encoder *encoder, Channel *channel_a,
-                                      const PIXEL * const prev_row,
-                                      PIXEL * const cur_row,
-                                      int i,
-                                      const int end,
-                                      SPICE_GNUC_UNUSED const unsigned int bpc,
-                                      const unsigned int bpc_mask)
+static void FNAME_DECL(uncompress_row_seg)(const PIXEL * const prev_row,
+                                           PIXEL * const cur_row,
+                                           int i,
+                                           const int end,
+                                           SPICE_GNUC_UNUSED const unsigned int bpc,
+                                           const unsigned int bpc_mask)
 {
     CommonState *state = &channel_a->state;
     BYTE * const correlate_row_a = channel_a->correlate_row;
@@ -484,21 +485,20 @@ do_run:
     }
 }
 
-static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
-                                  const PIXEL * const prev_row,
-                                  PIXEL * const cur_row,
-                                  unsigned int width)
+static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
+                                       PIXEL * const cur_row,
+                                       unsigned int width)
 
 {
-    CommonState *state = &channel->state;
+    CommonState *state = &channel_a->state;
     const unsigned int bpc = BPC;
     const unsigned int bpc_mask = BPC_MASK;
     unsigned int pos = 0;
 
     while ((DEFwmimax > (int)state->wmidx) && (state->wmileft <= width)) {
         if (state->wmileft) {
-            FNAME(uncompress_row_seg)(encoder, channel, prev_row, cur_row, pos,
-                                      pos + state->wmileft, bpc, bpc_mask);
+            FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
+                                           pos + state->wmileft, bpc, bpc_mask);
             pos += state->wmileft;
             width -= state->wmileft;
         }
@@ -509,8 +509,8 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
     }
 
     if (width) {
-        FNAME(uncompress_row_seg)(encoder, channel, prev_row, cur_row, pos,
-                                  pos + width, bpc, bpc_mask);
+        FNAME_CALL(uncompress_row_seg)(prev_row, cur_row, pos,
+                                       pos + width, bpc, bpc_mask);
         if (DEFwmimax > (int)state->wmidx) {
             state->wmileft -= width;
         }
@@ -522,7 +522,11 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel,
 }
 
 #undef PIXEL
+#undef FARGS_CALL
+#undef FARGS_DECL
 #undef FNAME
+#undef FNAME_CALL
+#undef FNAME_DECL
 #undef _PIXEL_A
 #undef _PIXEL_B
 #undef SAME_PIXEL
-- 
2.17.1



More information about the Spice-devel mailing list