[Spice-devel] [PATCH 1/2] fixup! Convert RedChannelClient hierarchy to GObject

Jonathon Jongsma jjongsma at redhat.com
Wed Oct 5 16:34:08 UTC 2016


Allocate DisplayChannelClientPrivate manually to avoid changing all
arrays to dynamically allocated.
---
 server/dcc-private.h |  6 +++---
 server/dcc.c         | 17 +++++------------
 2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/server/dcc-private.h b/server/dcc-private.h
index 0901045..de6ea92 100644
--- a/server/dcc-private.h
+++ b/server/dcc-private.h
@@ -51,10 +51,10 @@ struct DisplayChannelClientPrivate
         int num_pixmap_cache_items;
     } send_data;
 
-    uint8_t *surface_client_created;
-    QRegion *surface_client_lossy_region;
+    uint8_t surface_client_created[NUM_SURFACES];
+    QRegion surface_client_lossy_region[NUM_SURFACES];
 
-    StreamAgent *stream_agents;
+    StreamAgent stream_agents[NUM_STREAMS];
     int use_video_encoder_rate_control;
     uint32_t streams_max_latency;
     uint64_t streams_max_bit_rate;
diff --git a/server/dcc.c b/server/dcc.c
index 08866c9..64a6f5e 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -26,8 +26,6 @@
 
 G_DEFINE_TYPE(DisplayChannelClient, display_channel_client, RED_TYPE_CHANNEL_CLIENT)
 
-#define DISPLAY_CHANNEL_CLIENT_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_DISPLAY_CHANNEL_CLIENT, DisplayChannelClientPrivate))
-
 #define DISPLAY_CLIENT_SHORT_TIMEOUT 15000000000ULL //nano
 #define DISPLAY_FREE_LIST_DEFAULT_SIZE 128
 
@@ -99,18 +97,13 @@ display_channel_client_constructed(GObject *object)
     dcc_init_stream_agents(self);
 
     image_encoders_init(&self->priv->encoders, &DCC_TO_DC(self)->priv->encoder_shared_data);
-
-    self->priv->surface_client_created = g_new0(uint8_t, NUM_SURFACES);
-    self->priv->surface_client_lossy_region = g_new0(QRegion, NUM_SURFACES);
 }
 
 static void
 display_channel_client_finalize(GObject *object)
 {
     DisplayChannelClient *self = DISPLAY_CHANNEL_CLIENT(object);
-    g_free(self->priv->stream_agents);
-    g_free(self->priv->surface_client_created);
-    g_free(self->priv->surface_client_lossy_region);
+    g_free(self->priv);
 
     G_OBJECT_CLASS(display_channel_client_parent_class)->finalize(object);
 }
@@ -120,8 +113,6 @@ display_channel_client_class_init(DisplayChannelClientClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
 
-    g_type_class_add_private(klass, sizeof(DisplayChannelClientPrivate));
-
     object_class->get_property = display_channel_client_get_property;
     object_class->set_property = display_channel_client_set_property;
     object_class->constructed = display_channel_client_constructed;
@@ -160,7 +151,10 @@ display_channel_client_class_init(DisplayChannelClientClass *klass)
 
 static void display_channel_client_init(DisplayChannelClient *self)
 {
-    self->priv = DISPLAY_CHANNEL_CLIENT_PRIVATE(self);
+    /* we need to allocate the private data manually here since
+     * g_type_class_add_private() doesn't support private structs larger than
+     * 64k */
+    self->priv = g_new0(DisplayChannelClientPrivate, 1);
 
     ring_init(&self->priv->palette_cache_lru);
     self->priv->palette_cache_available = CLIENT_PALETTE_CACHE_SIZE;
@@ -474,7 +468,6 @@ static void dcc_init_stream_agents(DisplayChannelClient *dcc)
     int i;
     DisplayChannel *display = DCC_TO_DC(dcc);
 
-    dcc->priv->stream_agents = g_new0(StreamAgent, NUM_STREAMS);
     for (i = 0; i < NUM_STREAMS; i++) {
         StreamAgent *agent = &dcc->priv->stream_agents[i];
         agent->stream = &display->priv->streams_buf[i];
-- 
2.7.4



More information about the Spice-devel mailing list