[Spice-devel] [PATCH 19/30] Encapsulate some data in dcc-encoders
Frediano Ziglio
fziglio at redhat.com
Tue Jun 7 10:17:57 UTC 2016
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/dcc-encoders.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++--
server/dcc-encoders.h | 33 ++------------------------
server/display-channel.c | 13 +++--------
server/display-channel.h | 5 ----
4 files changed, 63 insertions(+), 48 deletions(-)
diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index c0b9714..f583857 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -26,8 +26,45 @@
#define ZLIB_DEFAULT_COMPRESSION_LEVEL 3
+#define MAX_GLZ_DRAWABLE_INSTANCES 2
+
+typedef struct GlzDrawableInstanceItem GlzDrawableInstanceItem;
+
+/* for each qxl drawable, there may be several instances of lz drawables */
+/* TODO - reuse this stuff for the top level. I just added a second level of multiplicity
+ * at the Drawable by keeping a ring, so:
+ * Drawable -> (ring of) RedGlzDrawable -> (up to 2) GlzDrawableInstanceItem
+ * and it should probably (but need to be sure...) be
+ * Drawable -> ring of GlzDrawableInstanceItem.
+ */
+struct GlzDrawableInstanceItem {
+ RingItem glz_link;
+ RingItem free_link;
+ GlzEncDictImageContext *context;
+ RedGlzDrawable *glz_drawable;
+};
+
+struct RedGlzDrawable {
+ RingItem link; // ordered by the time it was encoded
+ RingItem drawable_link;
+ RedDrawable *red_drawable;
+ struct Drawable *drawable;
+ GlzDrawableInstanceItem instances_pool[MAX_GLZ_DRAWABLE_INSTANCES];
+ Ring instances;
+ uint8_t instances_count;
+ EncodersData *encoders;
+};
+
+#define LINK_TO_GLZ(ptr) SPICE_CONTAINEROF((ptr), RedGlzDrawable, \
+ drawable_link)
+#define DRAWABLE_FOREACH_GLZ_SAFE(drawable, link, next, glz) \
+ SAFE_FOREACH(link, next, drawable, &(drawable)->glz_ring, glz, LINK_TO_GLZ(link))
+
static void dcc_free_glz_drawable_instance(EncodersData *enc,
GlzDrawableInstanceItem *item);
+static void encoder_data_init(EncoderData *data);
+static void encoder_data_reset(EncoderData *data);
+
static SPICE_GNUC_NORETURN SPICE_GNUC_PRINTF(2, 3) void
quic_usr_error(QuicUsrContext *usr, const char *fmt, ...)
@@ -139,14 +176,14 @@ static void glz_usr_free(GlzEncoderUsrContext *usr, void *ptr)
free(ptr);
}
-void encoder_data_init(EncoderData *data)
+static void encoder_data_init(EncoderData *data)
{
data->bufs_tail = g_new(RedCompressBuf, 1);
data->bufs_head = data->bufs_tail;
data->bufs_head->send_next = NULL;
}
-void encoder_data_reset(EncoderData *data)
+static void encoder_data_reset(EncoderData *data)
{
RedCompressBuf *buf = data->bufs_head;
while (buf) {
@@ -572,6 +609,25 @@ void dcc_free_glz_drawables(EncodersData *enc)
pthread_rwlock_unlock(&glz_dict->encode_lock);
}
+void dcc_glz_free_from_drawable(struct Drawable *drawable)
+{
+ RingItem *glz_item, *next_item;
+ RedGlzDrawable *glz;
+ DRAWABLE_FOREACH_GLZ_SAFE(drawable, glz_item, next_item, glz) {
+ dcc_free_glz_drawable(glz->encoders, glz);
+ }
+}
+
+void dcc_glz_detach_from_drawable(struct Drawable *drawable)
+{
+ RingItem *item, *next;
+
+ RING_FOREACH_SAFE(item, next, &drawable->glz_ring) {
+ SPICE_CONTAINEROF(item, RedGlzDrawable, drawable_link)->drawable = NULL;
+ ring_remove(item);
+ }
+}
+
void dcc_freeze_glz(EncodersData *enc)
{
pthread_rwlock_wrlock(&enc->glz_dict->encode_lock);
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index f98eac0..26d8d27 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -32,7 +32,6 @@
#include "zlib-encoder.h"
typedef struct RedCompressBuf RedCompressBuf;
-typedef struct GlzDrawableInstanceItem GlzDrawableInstanceItem;
typedef struct RedGlzDrawable RedGlzDrawable;
typedef struct EncodersData EncodersData;
@@ -45,6 +44,8 @@ void dcc_free_glz_drawables_to_free(EncodersData* enc);
gboolean dcc_glz_encoder_create(EncodersData *enc, uint8_t id);
void dcc_freeze_glz(EncodersData *enc);
void dcc_release_glz(EncodersData *enc);
+void dcc_glz_free_from_drawable(struct Drawable *drawable);
+void dcc_glz_detach_from_drawable(struct Drawable *drawable);
#define RED_COMPRESS_BUF_SIZE (1024 * 64)
struct RedCompressBuf {
@@ -101,9 +102,6 @@ typedef struct {
char message_buf[512];
} EncoderData;
-void encoder_data_init(EncoderData *data);
-void encoder_data_reset(EncoderData *data);
-
typedef struct {
QuicUsrContext usr;
EncoderData data;
@@ -136,33 +134,6 @@ typedef struct {
EncoderData data;
} GlzData;
-#define MAX_GLZ_DRAWABLE_INSTANCES 2
-
-/* for each qxl drawable, there may be several instances of lz drawables */
-/* TODO - reuse this stuff for the top level. I just added a second level of multiplicity
- * at the Drawable by keeping a ring, so:
- * Drawable -> (ring of) RedGlzDrawable -> (up to 2) GlzDrawableInstanceItem
- * and it should probably (but need to be sure...) be
- * Drawable -> ring of GlzDrawableInstanceItem.
- */
-struct GlzDrawableInstanceItem {
- RingItem glz_link;
- RingItem free_link;
- GlzEncDictImageContext *context;
- RedGlzDrawable *glz_drawable;
-};
-
-struct RedGlzDrawable {
- RingItem link; // ordered by the time it was encoded
- RingItem drawable_link;
- RedDrawable *red_drawable;
- Drawable *drawable;
- GlzDrawableInstanceItem instances_pool[MAX_GLZ_DRAWABLE_INSTANCES];
- Ring instances;
- uint8_t instances_count;
- EncodersData *encoders;
-};
-
struct EncodersData {
QuicData quic_data;
QuicContext *quic;
diff --git a/server/display-channel.c b/server/display-channel.c
index 6b6b542..60337b1 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -1230,11 +1230,7 @@ static bool free_one_drawable(DisplayChannel *display, int force_glz_free)
drawable = SPICE_CONTAINEROF(ring_item, Drawable, list_link);
if (force_glz_free) {
- RingItem *glz_item, *next_item;
- RedGlzDrawable *glz;
- DRAWABLE_FOREACH_GLZ_SAFE(drawable, glz_item, next_item, glz) {
- dcc_free_glz_drawable(glz->encoders, glz);
- }
+ dcc_glz_free_from_drawable(drawable);
}
drawable_draw(display, drawable);
container = drawable->tree_item.base.container;
@@ -1386,7 +1382,6 @@ static void drawable_unref_surface_deps(DisplayChannel *display, Drawable *drawa
void drawable_unref(Drawable *drawable)
{
DisplayChannel *display = drawable->display;
- RingItem *item, *next;
if (--drawable->refs != 0)
return;
@@ -1403,10 +1398,8 @@ void drawable_unref(Drawable *drawable)
drawable_unref_surface_deps(display, drawable);
display_channel_surface_unref(display, drawable->surface_id);
- RING_FOREACH_SAFE(item, next, &drawable->glz_ring) {
- SPICE_CONTAINEROF(item, RedGlzDrawable, drawable_link)->drawable = NULL;
- ring_remove(item);
- }
+ dcc_glz_detach_from_drawable(drawable);
+
if (drawable->red_drawable) {
red_drawable_unref(drawable->red_drawable);
}
diff --git a/server/display-channel.h b/server/display-channel.h
index 45032cb..a2e0473 100644
--- a/server/display-channel.h
+++ b/server/display-channel.h
@@ -88,11 +88,6 @@ void drawable_unref (Drawable *drawable);
#define DRAWABLE_FOREACH_DPI_SAFE(drawable, link, next, dpi) \
SAFE_FOREACH(link, next, drawable, &(drawable)->pipes, dpi, LINK_TO_DPI(link))
-#define LINK_TO_GLZ(ptr) SPICE_CONTAINEROF((ptr), RedGlzDrawable, \
- drawable_link)
-#define DRAWABLE_FOREACH_GLZ_SAFE(drawable, link, next, glz) \
- SAFE_FOREACH(link, next, drawable, &(drawable)->glz_ring, glz, LINK_TO_GLZ(link))
-
enum {
RED_PIPE_ITEM_TYPE_DRAW = RED_PIPE_ITEM_TYPE_COMMON_LAST,
RED_PIPE_ITEM_TYPE_IMAGE,
--
2.7.4
More information about the Spice-devel
mailing list