[Spice-devel] [PATCH 02/14] UpgradeItem: use base PipeItem for refcounting
Jonathon Jongsma
jjongsma at redhat.com
Thu Apr 21 21:43:48 UTC 2016
No need to re-implement refcounting in this subclass.
---
Changes since last version:
- remove the dcc/display parameter from the struct since the previous patch
was added that stored a display pointer in the Drawable struct.
server/dcc.c | 16 +---------------
server/display-channel.c | 4 +---
server/display-channel.h | 1 -
server/stream.c | 14 ++++++++++++--
4 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/server/dcc.c b/server/dcc.c
index 4f3f227..09a1fca 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -1589,16 +1589,6 @@ int dcc_handle_migrate_data(DisplayChannelClient *dcc, uint32_t size, void *mess
return TRUE;
}
-static void upgrade_item_unref(UpgradeItem *item)
-{
- if (--item->refs != 0)
- return;
-
- drawable_unref(item->drawable);
- free(item->rects);
- free(item);
-}
-
static void release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
{
switch (item->type) {
@@ -1606,10 +1596,8 @@ static void release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
case PIPE_ITEM_TYPE_IMAGE:
case PIPE_ITEM_TYPE_STREAM_CLIP:
case PIPE_ITEM_TYPE_MONITORS_CONFIG:
- pipe_item_unref(item);
- break;
case PIPE_ITEM_TYPE_UPGRADE:
- upgrade_item_unref((UpgradeItem *)item);
+ pipe_item_unref(item);
break;
case PIPE_ITEM_TYPE_GL_SCANOUT:
case PIPE_ITEM_TYPE_GL_DRAW:
@@ -1647,8 +1635,6 @@ static void release_item_before_push(DisplayChannelClient *dcc, PipeItem *item)
}
case PIPE_ITEM_TYPE_STREAM_CLIP:
case PIPE_ITEM_TYPE_UPGRADE:
- upgrade_item_unref((UpgradeItem *)item);
- break;
case PIPE_ITEM_TYPE_IMAGE:
case PIPE_ITEM_TYPE_MONITORS_CONFIG:
pipe_item_unref(item);
diff --git a/server/display-channel.c b/server/display-channel.c
index f2bdc1d..99a490d 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -1978,10 +1978,8 @@ static void hold_item(RedChannelClient *rcc, PipeItem *item)
case PIPE_ITEM_TYPE_DRAW:
case PIPE_ITEM_TYPE_IMAGE:
case PIPE_ITEM_TYPE_STREAM_CLIP:
- pipe_item_ref(item);
- break;
case PIPE_ITEM_TYPE_UPGRADE:
- ((UpgradeItem *)item)->refs++;
+ pipe_item_ref(item);
break;
default:
spice_warn_if_reached();
diff --git a/server/display-channel.h b/server/display-channel.h
index c4a3b19..c10cfe2 100644
--- a/server/display-channel.h
+++ b/server/display-channel.h
@@ -247,7 +247,6 @@ typedef struct SurfaceDestroyItem {
typedef struct UpgradeItem {
PipeItem base;
- int refs;
Drawable *drawable;
SpiceClipRects *rects;
} UpgradeItem;
diff --git a/server/stream.c b/server/stream.c
index ae37a62..22e1004 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -758,6 +758,16 @@ void stream_agent_stop(StreamAgent *agent)
}
}
+static void upgrade_item_free(UpgradeItem *item)
+{
+ g_return_if_fail(item != NULL);
+ g_return_if_fail(item->base.refcount != 0);
+
+ drawable_unref(item->drawable);
+ free(item->rects);
+ free(item);
+}
+
/*
* after dcc_detach_stream_gracefully is called for all the display channel clients,
* detach_stream should be called. See comment (1).
@@ -798,8 +808,8 @@ static void dcc_detach_stream_gracefully(DisplayChannelClient *dcc,
rect_debug(&stream->current->red_drawable->bbox);
rcc = RED_CHANNEL_CLIENT(dcc);
upgrade_item = spice_new(UpgradeItem, 1);
- upgrade_item->refs = 1;
- pipe_item_init(&upgrade_item->base, PIPE_ITEM_TYPE_UPGRADE);
+ pipe_item_init_full(&upgrade_item->base, PIPE_ITEM_TYPE_UPGRADE,
+ (GDestroyNotify)upgrade_item_free);
upgrade_item->drawable = stream->current;
upgrade_item->drawable->refs++;
n_rects = pixman_region32_n_rects(&upgrade_item->drawable->tree_item.base.rgn);
--
2.4.11
More information about the Spice-devel
mailing list