[Spice-commits] 3 commits - server/dcc-encoders.c server/dcc-encoders.h server/dcc.c server/dcc.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Thu Jun 9 21:12:12 UTC 2016


 server/dcc-encoders.c |  106 +++++++++++++++++++++++++++++++++++++++++++-------
 server/dcc-encoders.h |    8 +++
 server/dcc.c          |   75 ++---------------------------------
 server/dcc.h          |    2 
 4 files changed, 107 insertions(+), 84 deletions(-)

New commits:
commit cff7950aa34541c946676da5865ac3aa62454a9e
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Jun 3 15:29:43 2016 +0100

    Move image_encoders_compress_lz to dcc-encoders.c
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index 2ccbb66..e795065 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -782,4 +782,84 @@ int image_encoders_compress_quic(ImageEncoders *enc, SpiceImage *dest,
     return TRUE;
 }
 
+static const LzImageType bitmap_fmt_to_lz_image_type[] = {
+    LZ_IMAGE_TYPE_INVALID,
+    LZ_IMAGE_TYPE_PLT1_LE,
+    LZ_IMAGE_TYPE_PLT1_BE,
+    LZ_IMAGE_TYPE_PLT4_LE,
+    LZ_IMAGE_TYPE_PLT4_BE,
+    LZ_IMAGE_TYPE_PLT8,
+    LZ_IMAGE_TYPE_RGB16,
+    LZ_IMAGE_TYPE_RGB24,
+    LZ_IMAGE_TYPE_RGB32,
+    LZ_IMAGE_TYPE_RGBA,
+    LZ_IMAGE_TYPE_A8
+};
+
+int image_encoders_compress_lz(ImageEncoders *enc,
+                               SpiceImage *dest, SpiceBitmap *src,
+                               compress_send_data_t* o_comp_data,
+                               stat_info_t *stats)
+{
+    LzData *lz_data = &enc->lz_data;
+    LzContext *lz = enc->lz;
+    LzImageType type = bitmap_fmt_to_lz_image_type[src->format];
+    int size;            // size of the compressed data
+
+    stat_start_time_t start_time;
+    stat_start_time_init(&start_time, stats);
+
+#ifdef COMPRESS_DEBUG
+    spice_info("LZ LOCAL compress");
+#endif
+
+    encoder_data_init(&lz_data->data);
+
+    if (setjmp(lz_data->data.jmp_env)) {
+        encoder_data_reset(&lz_data->data);
+        return FALSE;
+    }
+
+    lz_data->data.u.lines_data.chunks = src->data;
+    lz_data->data.u.lines_data.stride = src->stride;
+    lz_data->data.u.lines_data.next = 0;
+    lz_data->data.u.lines_data.reverse = 0;
+
+    size = lz_encode(lz, type, src->x, src->y,
+                     !!(src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN),
+                     NULL, 0, src->stride,
+                     lz_data->data.bufs_head->buf.bytes,
+                     sizeof(lz_data->data.bufs_head->buf));
+
+    // the compressed buffer is bigger than the original data
+    if (size > (src->y * src->stride)) {
+        longjmp(lz_data->data.jmp_env, 1);
+    }
+
+    if (bitmap_fmt_is_rgb(src->format)) {
+        dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_RGB;
+        dest->u.lz_rgb.data_size = size;
+
+        o_comp_data->comp_buf = lz_data->data.bufs_head;
+        o_comp_data->comp_buf_size = size;
+    } else {
+        /* masks are 1BIT bitmaps without palettes, but they are not compressed
+         * (see fill_mask) */
+        spice_assert(src->palette);
+        dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_PLT;
+        dest->u.lz_plt.data_size = size;
+        dest->u.lz_plt.flags = src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN;
+        dest->u.lz_plt.palette = src->palette;
+        dest->u.lz_plt.palette_id = src->palette->unique;
+        o_comp_data->comp_buf = lz_data->data.bufs_head;
+        o_comp_data->comp_buf_size = size;
+
+        o_comp_data->lzplt_palette = dest->u.lz_plt.palette;
+    }
+
+    stat_compress_add(stats, start_time, src->stride * src->y,
+                      o_comp_data->comp_buf_size);
+    return TRUE;
+}
+
 
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index 3c1b037..e4e2726 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -179,6 +179,11 @@ typedef struct compress_send_data_t {
 int image_encoders_compress_quic(ImageEncoders *enc, SpiceImage *dest,
                                  SpiceBitmap *src, compress_send_data_t* o_comp_data,
                                  stat_info_t *stats);
+int image_encoders_compress_lz(ImageEncoders *enc,
+                               SpiceImage *dest, SpiceBitmap *src,
+                               compress_send_data_t* o_comp_data,
+                               stat_info_t *stats);
+
 #define RED_RELEASE_BUNCH_SIZE 64
 
 #endif /* DCC_ENCODERS_H_ */
diff --git a/server/dcc.c b/server/dcc.c
index d5e6c6b..2d715d9 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -784,72 +784,6 @@ glz:
     return TRUE;
 }
 
-static int image_encoders_compress_lz(ImageEncoders *enc,
-                                      SpiceImage *dest, SpiceBitmap *src,
-                                      compress_send_data_t* o_comp_data,
-                                      stat_info_t *stats)
-{
-    LzData *lz_data = &enc->lz_data;
-    LzContext *lz = enc->lz;
-    LzImageType type = bitmap_fmt_to_lz_image_type[src->format];
-    int size;            // size of the compressed data
-
-    stat_start_time_t start_time;
-    stat_start_time_init(&start_time, stats);
-
-#ifdef COMPRESS_DEBUG
-    spice_info("LZ LOCAL compress");
-#endif
-
-    encoder_data_init(&lz_data->data);
-
-    if (setjmp(lz_data->data.jmp_env)) {
-        encoder_data_reset(&lz_data->data);
-        return FALSE;
-    }
-
-    lz_data->data.u.lines_data.chunks = src->data;
-    lz_data->data.u.lines_data.stride = src->stride;
-    lz_data->data.u.lines_data.next = 0;
-    lz_data->data.u.lines_data.reverse = 0;
-
-    size = lz_encode(lz, type, src->x, src->y,
-                     !!(src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN),
-                     NULL, 0, src->stride,
-                     lz_data->data.bufs_head->buf.bytes,
-                     sizeof(lz_data->data.bufs_head->buf));
-
-    // the compressed buffer is bigger than the original data
-    if (size > (src->y * src->stride)) {
-        longjmp(lz_data->data.jmp_env, 1);
-    }
-
-    if (bitmap_fmt_is_rgb(src->format)) {
-        dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_RGB;
-        dest->u.lz_rgb.data_size = size;
-
-        o_comp_data->comp_buf = lz_data->data.bufs_head;
-        o_comp_data->comp_buf_size = size;
-    } else {
-        /* masks are 1BIT bitmaps without palettes, but they are not compressed
-         * (see fill_mask) */
-        spice_assert(src->palette);
-        dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_PLT;
-        dest->u.lz_plt.data_size = size;
-        dest->u.lz_plt.flags = src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN;
-        dest->u.lz_plt.palette = src->palette;
-        dest->u.lz_plt.palette_id = src->palette->unique;
-        o_comp_data->comp_buf = lz_data->data.bufs_head;
-        o_comp_data->comp_buf_size = size;
-
-        o_comp_data->lzplt_palette = dest->u.lz_plt.palette;
-    }
-
-    stat_compress_add(stats, start_time, src->stride * src->y,
-                      o_comp_data->comp_buf_size);
-    return TRUE;
-}
-
 static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
                                    SpiceBitmap *src, compress_send_data_t* o_comp_data)
 {
commit c5caf0ddddea9c79859eb302c0a4c9fea3da6827
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jun 9 11:53:57 2016 +0100

    Prepare to move dcc_compress_image_lz to ImageEncoders
    
    Remove all DisplayChannel(Client) dependencies.
    Rename function.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/dcc.c b/server/dcc.c
index 04ef5fb..d5e6c6b 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -784,17 +784,18 @@ glz:
     return TRUE;
 }
 
-static int dcc_compress_image_lz(DisplayChannelClient *dcc,
-                                 SpiceImage *dest, SpiceBitmap *src,
-                                 compress_send_data_t* o_comp_data)
+static int image_encoders_compress_lz(ImageEncoders *enc,
+                                      SpiceImage *dest, SpiceBitmap *src,
+                                      compress_send_data_t* o_comp_data,
+                                      stat_info_t *stats)
 {
-    LzData *lz_data = &dcc->encoders.lz_data;
-    LzContext *lz = dcc->encoders.lz;
+    LzData *lz_data = &enc->lz_data;
+    LzContext *lz = enc->lz;
     LzImageType type = bitmap_fmt_to_lz_image_type[src->format];
     int size;            // size of the compressed data
 
     stat_start_time_t start_time;
-    stat_start_time_init(&start_time, &DCC_TO_DC(dcc)->lz_stat);
+    stat_start_time_init(&start_time, stats);
 
 #ifdef COMPRESS_DEBUG
     spice_info("LZ LOCAL compress");
@@ -841,11 +842,10 @@ static int dcc_compress_image_lz(DisplayChannelClient *dcc,
         o_comp_data->comp_buf = lz_data->data.bufs_head;
         o_comp_data->comp_buf_size = size;
 
-        dcc_palette_cache_palette(dcc, dest->u.lz_plt.palette, &(dest->u.lz_plt.flags));
         o_comp_data->lzplt_palette = dest->u.lz_plt.palette;
     }
 
-    stat_compress_add(&DCC_TO_DC(dcc)->lz_stat, start_time, src->stride * src->y,
+    stat_compress_add(stats, start_time, src->stride * src->y,
                       o_comp_data->comp_buf_size);
     return TRUE;
 }
@@ -1160,7 +1160,10 @@ int dcc_compress_image(DisplayChannelClient *dcc,
 #endif
 lz_compress:
     case SPICE_IMAGE_COMPRESSION_LZ:
-        success = dcc_compress_image_lz(dcc, dest, src, o_comp_data);
+        success = image_encoders_compress_lz(&dcc->encoders, dest, src, o_comp_data, &display_channel->lz_stat);
+        if (success && !bitmap_fmt_is_rgb(src->format)) {
+            dcc_palette_cache_palette(dcc, dest->u.lz_plt.palette, &(dest->u.lz_plt.flags));
+        }
         break;
     default:
         spice_error("invalid image compression type %u", image_compression);
commit a25182f0606a43e3c76dc668aba540cb6a64da3b
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jun 9 11:53:16 2016 +0100

    Encapsulate lz information in ImageEncoders structure
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index a17efe6..2ccbb66 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -308,19 +308,19 @@ static void image_encoders_init_quic(ImageEncoders *enc)
     }
 }
 
-static void dcc_init_lz(DisplayChannelClient *dcc)
+static void image_encoders_init_lz(ImageEncoders *enc)
 {
-    dcc->lz_data.usr.error = lz_usr_error;
-    dcc->lz_data.usr.warn = lz_usr_warn;
-    dcc->lz_data.usr.info = lz_usr_warn;
-    dcc->lz_data.usr.malloc = lz_usr_malloc;
-    dcc->lz_data.usr.free = lz_usr_free;
-    dcc->lz_data.usr.more_space = lz_usr_more_space;
-    dcc->lz_data.usr.more_lines = lz_usr_more_lines;
+    enc->lz_data.usr.error = lz_usr_error;
+    enc->lz_data.usr.warn = lz_usr_warn;
+    enc->lz_data.usr.info = lz_usr_warn;
+    enc->lz_data.usr.malloc = lz_usr_malloc;
+    enc->lz_data.usr.free = lz_usr_free;
+    enc->lz_data.usr.more_space = lz_usr_more_space;
+    enc->lz_data.usr.more_lines = lz_usr_more_lines;
 
-    dcc->lz = lz_create(&dcc->lz_data.usr);
+    enc->lz = lz_create(&enc->lz_data.usr);
 
-    if (!dcc->lz) {
+    if (!enc->lz) {
         spice_critical("create lz failed");
     }
 }
@@ -404,7 +404,7 @@ void dcc_encoders_init(DisplayChannelClient *dcc)
 
     dcc_init_glz_data(dcc);
     image_encoders_init_quic(enc);
-    dcc_init_lz(dcc);
+    image_encoders_init_lz(enc);
     dcc_init_jpeg(dcc);
 #ifdef USE_LZ4
     dcc_init_lz4(dcc);
@@ -420,8 +420,8 @@ void dcc_encoders_free(DisplayChannelClient *dcc)
     ImageEncoders *enc = &dcc->encoders;
     quic_destroy(enc->quic);
     enc->quic = NULL;
-    lz_destroy(dcc->lz);
-    dcc->lz = NULL;
+    lz_destroy(enc->lz);
+    enc->lz = NULL;
     jpeg_encoder_destroy(dcc->jpeg);
     dcc->jpeg = NULL;
 #ifdef USE_LZ4
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index 00191a0..3c1b037 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -164,6 +164,9 @@ struct RedGlzDrawable {
 struct ImageEncoders {
     QuicData quic_data;
     QuicContext *quic;
+
+    LzData lz_data;
+    LzContext  *lz;
 };
 
 typedef struct compress_send_data_t {
diff --git a/server/dcc.c b/server/dcc.c
index 17809d4..04ef5fb 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -788,8 +788,8 @@ static int dcc_compress_image_lz(DisplayChannelClient *dcc,
                                  SpiceImage *dest, SpiceBitmap *src,
                                  compress_send_data_t* o_comp_data)
 {
-    LzData *lz_data = &dcc->lz_data;
-    LzContext *lz = dcc->lz;
+    LzData *lz_data = &dcc->encoders.lz_data;
+    LzContext *lz = dcc->encoders.lz;
     LzImageType type = bitmap_fmt_to_lz_image_type[src->format];
     int size;            // size of the compressed data
 
@@ -854,9 +854,9 @@ static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
                                    SpiceBitmap *src, compress_send_data_t* o_comp_data)
 {
     JpegData *jpeg_data = &dcc->jpeg_data;
-    LzData *lz_data = &dcc->lz_data;
+    LzData *lz_data = &dcc->encoders.lz_data;
     JpegEncoderContext *jpeg = dcc->jpeg;
-    LzContext *lz = dcc->lz;
+    LzContext *lz = dcc->encoders.lz;
     volatile JpegEncoderImageType jpeg_in_type;
     int jpeg_size = 0;
     volatile int has_alpha = FALSE;
diff --git a/server/dcc.h b/server/dcc.h
index 62f1851..d10ba87 100644
--- a/server/dcc.h
+++ b/server/dcc.h
@@ -66,8 +66,6 @@ struct DisplayChannelClient {
 
     int zlib_level;
 
-    LzData lz_data;
-    LzContext  *lz;
     JpegData jpeg_data;
     JpegEncoderContext *jpeg;
 #ifdef USE_LZ4


More information about the Spice-commits mailing list