summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYonit Halperin <yhalperi@redhat.com>2013-10-10 09:49:52 -0400
committerYonit Halperin <yhalperi@redhat.com>2013-10-23 15:44:11 -0400
commitcd4321560a8578d579516b3fdfdc45a4c28fd3ce (patch)
treee139c3086c3edca19a777577c5661dfbc68a95aa
parent52d9c288dc5af8aec4f2c9ac64075a411dd6a162 (diff)
red_worker/fill_bits: wrap the code that encodes the output SpiceImage in its own routine
-rw-r--r--server/red_worker.c112
1 files changed, 74 insertions, 38 deletions
diff --git a/server/red_worker.c b/server/red_worker.c
index 438113c..9685382 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -6745,65 +6745,101 @@ static void spice_image_set_quic_data(DisplayChannelClient *dcc,
src_image->u.quic.data->num_chunks * sizeof(SpiceChunk));
}
-typedef enum {
- FILL_BITS_TYPE_INVALID,
- FILL_BITS_TYPE_CACHE,
- FILL_BITS_TYPE_SURFACE,
- FILL_BITS_TYPE_COMPRESS_LOSSLESS,
- FILL_BITS_TYPE_COMPRESS_LOSSY,
- FILL_BITS_TYPE_BITMAP,
-} FillBitsType;
-
-/* if the number of times fill_bits can be called per one qxl_drawable increases -
- MAX_LZ_DRAWABLE_INSTANCES must be increased as well */
-static FillBitsType fill_bits(DisplayChannelClient *dcc, SpiceMarshaller *m,
- SpiceImage *simage, Drawable *drawable, int can_lossy)
+static void spice_image_encode(DisplayChannelClient *dcc,
+ SpiceImage *src_image,
+ Drawable *drawable,
+ SpiceImage *dst_image,
+ int can_lossy)
{
- RedChannelClient *rcc = &dcc->common.base;
- DisplayChannel *display_channel = SPICE_CONTAINEROF(rcc->channel, DisplayChannel, common.base);
- SpiceImage image;
- FillBitsType ret = FILL_BITS_TYPE_INVALID;
+ spice_assert(dst_image);
+ spice_assert(drawable);
- if (simage == NULL) {
+ memset(dst_image, 0, sizeof(*dst_image));
+ if (src_image == NULL) {
spice_assert(drawable->red_drawable->self_bitmap_image);
- simage = drawable->red_drawable->self_bitmap_image;
+ src_image = drawable->red_drawable->self_bitmap_image;
}
- image.descriptor = simage->descriptor;
- image.descriptor.flags = 0;
- if (simage->descriptor.flags & SPICE_IMAGE_FLAGS_HIGH_BITS_SET) {
- image.descriptor.flags = SPICE_IMAGE_FLAGS_HIGH_BITS_SET;
+ dst_image->descriptor = src_image->descriptor;
+ dst_image->descriptor.flags = 0;
+ if (src_image->descriptor.flags & SPICE_IMAGE_FLAGS_HIGH_BITS_SET) {
+ dst_image->descriptor.flags = SPICE_IMAGE_FLAGS_HIGH_BITS_SET;
}
- if (spice_image_set_cache_info(dcc, simage, &image, can_lossy)) {
- spice_image_marshall(&image, m, TRUE);
- stat_inc_counter(display_channel->cache_hits_counter, 1);
- return FILL_BITS_TYPE_CACHE;
+ if (spice_image_set_cache_info(dcc, src_image, dst_image, can_lossy)) {
+ return;
}
- switch (simage->descriptor.type) {
+ switch (src_image->descriptor.type) {
case SPICE_IMAGE_TYPE_SURFACE:
- spice_image_set_surface_info(dcc, simage, &image);
- ret = FILL_BITS_TYPE_SURFACE;
+ spice_image_set_surface_info(dcc, src_image, dst_image);
break;
case SPICE_IMAGE_TYPE_BITMAP:
- spice_image_encode_bitmap(dcc, simage, drawable, &image, can_lossy);
- ret = spice_image_is_lossy_compressed(&image) ?
- FILL_BITS_TYPE_COMPRESS_LOSSY :
- FILL_BITS_TYPE_COMPRESS_LOSSLESS;
+ spice_image_encode_bitmap(dcc, src_image, drawable, dst_image, can_lossy);
break;
case SPICE_IMAGE_TYPE_QUIC:
- spice_image_set_quic_data(dcc, simage, &image);
- ret = FILL_BITS_TYPE_COMPRESS_LOSSLESS;
+ spice_image_set_quic_data(dcc, src_image, dst_image);
break;
default:
- spice_error("invalid image type %u", image.descriptor.type);
+ spice_error("invalid image type %u", src_image->descriptor.type);
+ }
+}
+
+typedef enum {
+ FILL_BITS_TYPE_INVALID,
+ FILL_BITS_TYPE_CACHE,
+ FILL_BITS_TYPE_SURFACE,
+ FILL_BITS_TYPE_COMPRESS_LOSSLESS,
+ FILL_BITS_TYPE_COMPRESS_LOSSY,
+ FILL_BITS_TYPE_BITMAP,
+} FillBitsType;
+
+static FillBitsType spice_image_get_compress_type(SpiceImage *image)
+{
+ FillBitsType ret = FILL_BITS_TYPE_INVALID;
+
+ switch (image->descriptor.type) {
+ case SPICE_IMAGE_TYPE_BITMAP:
+ ret = FILL_BITS_TYPE_BITMAP;
+ break;
+ case SPICE_IMAGE_TYPE_SURFACE:
+ ret = FILL_BITS_TYPE_SURFACE;
+ break;
+ case SPICE_IMAGE_TYPE_FROM_CACHE:
+ case SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS:
+ ret = FILL_BITS_TYPE_CACHE;
+ break;
+ case SPICE_IMAGE_TYPE_JPEG:
+ case SPICE_IMAGE_TYPE_JPEG_ALPHA:
+ ret = FILL_BITS_TYPE_COMPRESS_LOSSY;
+ break;
+ case SPICE_IMAGE_TYPE_QUIC:
+ case SPICE_IMAGE_TYPE_GLZ_RGB:
+ case SPICE_IMAGE_TYPE_LZ_RGB:
+ case SPICE_IMAGE_TYPE_ZLIB_GLZ_RGB:
+ case SPICE_IMAGE_TYPE_LZ_PLT:
+ ret = FILL_BITS_TYPE_COMPRESS_LOSSLESS;
+ break;
+ default:
+ spice_error("invalid image type %u", image->descriptor.type);
}
- spice_image_marshall(&image, m, TRUE);
return ret;
}
+/* if the number of times fill_bits can be called per one qxl_drawable increases -
+ MAX_LZ_DRAWABLE_INSTANCES must be increased as well */
+static FillBitsType fill_bits(DisplayChannelClient *dcc, SpiceMarshaller *m,
+ SpiceImage *src_image, Drawable *drawable, int can_lossy)
+{
+ SpiceImage dst_image;
+
+ spice_image_encode(dcc,src_image, drawable, &dst_image, can_lossy);
+ spice_image_marshall(&dst_image, m, TRUE);
+
+ return spice_image_get_compress_type(&dst_image);
+}
+
static void fill_mask(RedChannelClient *rcc, SpiceMarshaller *m,
SpiceImage *mask_bitmap, Drawable *drawable)
{