[PATCH 07/20] StreamClipItem: use base class refcounting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PipeItem already implements refcounting. Use it.
---
 server/dcc.c             | 10 +++-------
 server/display-channel.c |  4 +---
 server/stream.c          | 30 +++++++++++++++---------------
 server/stream.h          |  6 +-----
 4 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/server/dcc.c b/server/dcc.c
index fcef02d..9ada7f1 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -497,7 +497,7 @@ void dcc_stop(DisplayChannelClient *dcc)
 
 void dcc_stream_agent_clip(DisplayChannelClient* dcc, StreamAgent *agent)
 {
-    StreamClipItem *item = stream_clip_item_new(dcc, agent);
+    StreamClipItem *item = stream_clip_item_new(agent);
     int n_rects;
 
     item->clip_type = SPICE_CLIP_TYPE_RECTS;
@@ -1601,10 +1601,8 @@ static void release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
     switch (item->type) {
     case PIPE_ITEM_TYPE_DRAW:
     case PIPE_ITEM_TYPE_IMAGE:
-        pipe_item_unref(item);
-        break;
     case PIPE_ITEM_TYPE_STREAM_CLIP:
-        stream_clip_item_unref(dcc, (StreamClipItem *)item);
+        pipe_item_unref(item);
         break;
     case PIPE_ITEM_TYPE_UPGRADE:
         upgrade_item_unref(display, (UpgradeItem *)item);
@@ -1645,14 +1643,12 @@ static void release_item_before_push(DisplayChannelClient *dcc, PipeItem *item)
         stream_agent_unref(display, agent);
         break;
     }
-    case PIPE_ITEM_TYPE_STREAM_CLIP:
-        stream_clip_item_unref(dcc, (StreamClipItem *)item);
-        break;
     case PIPE_ITEM_TYPE_STREAM_DESTROY: {
         StreamAgent *agent = SPICE_CONTAINEROF(item, StreamAgent, destroy_item);
         stream_agent_unref(display, agent);
         break;
     }
+    case PIPE_ITEM_TYPE_STREAM_CLIP:
     case PIPE_ITEM_TYPE_UPGRADE:
         upgrade_item_unref(display, (UpgradeItem *)item);
         break;
diff --git a/server/display-channel.c b/server/display-channel.c
index 4d339f5..88dbc74 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -1972,10 +1972,8 @@ static void hold_item(RedChannelClient *rcc, PipeItem *item)
     switch (item->type) {
     case PIPE_ITEM_TYPE_DRAW:
     case PIPE_ITEM_TYPE_IMAGE:
-        pipe_item_ref(item);
-        break;
     case PIPE_ITEM_TYPE_STREAM_CLIP:
-        ((StreamClipItem *)item)->refs++;
+        pipe_item_ref(item);
         break;
     case PIPE_ITEM_TYPE_UPGRADE:
         ((UpgradeItem *)item)->refs++;
diff --git a/server/stream.c b/server/stream.c
index 548c4c7..ae37a62 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -133,29 +133,29 @@ void stream_agent_unref(DisplayChannel *display, StreamAgent *agent)
     stream_unref(display, agent->stream);
 }
 
-StreamClipItem *stream_clip_item_new(DisplayChannelClient* dcc, StreamAgent *agent)
+void stream_clip_item_free(StreamClipItem *item)
 {
-    StreamClipItem *item = spice_new(StreamClipItem, 1);
-    pipe_item_init((PipeItem *)item, PIPE_ITEM_TYPE_STREAM_CLIP);
-
-    item->stream_agent = agent;
-    agent->stream->refs++;
-    item->refs = 1;
-    return item;
-}
-
-void stream_clip_item_unref(DisplayChannelClient *dcc, StreamClipItem *item)
-{
-    DisplayChannel *display = DCC_TO_DC(dcc);
+    g_return_if_fail(item != NULL);
+    DisplayChannel *display = DCC_TO_DC(item->stream_agent->dcc);
 
-    if (--item->refs != 0)
-        return;
+    g_return_if_fail(item->base.refcount == 0);
 
     stream_agent_unref(display, item->stream_agent);
     free(item->rects);
     free(item);
 }
 
+StreamClipItem *stream_clip_item_new(StreamAgent *agent)
+{
+    StreamClipItem *item = spice_new(StreamClipItem, 1);
+    pipe_item_init_full((PipeItem *)item, PIPE_ITEM_TYPE_STREAM_CLIP,
+                        (GDestroyNotify)stream_clip_item_free);
+
+    item->stream_agent = agent;
+    agent->stream->refs++;
+    return item;
+}
+
 static int is_stream_start(Drawable *drawable)
 {
     return ((drawable->frames_count >= RED_STREAM_FRAMES_START_CONDITION) &&
diff --git a/server/stream.h b/server/stream.h
index a3e84ed..c83e3b5 100644
--- a/server/stream.h
+++ b/server/stream.h
@@ -101,16 +101,12 @@ typedef struct StreamAgent {
 
 typedef struct StreamClipItem {
     PipeItem base;
-    int refs;
     StreamAgent *stream_agent;
     int clip_type;
     SpiceClipRects *rects;
 } StreamClipItem;
 
-StreamClipItem *      stream_clip_item_new                          (DisplayChannelClient* dcc,
-                                                                     StreamAgent *agent);
-void                  stream_clip_item_unref                        (DisplayChannelClient *dcc,
-                                                                     StreamClipItem *item);
+StreamClipItem *      stream_clip_item_new                          (StreamAgent *agent);
 
 typedef struct ItemTrace {
     red_time_t time;
-- 
2.4.11

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]