Encapsulate more pipe item initialisation in constructors

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
This commit is contained in:
Frediano Ziglio 2020-06-04 19:18:08 +01:00
parent 20408491fa
commit 10749220dd
5 changed files with 35 additions and 32 deletions

View File

@ -473,7 +473,7 @@ static void dcc_stop(DisplayChannelClient *dcc)
void dcc_video_stream_agent_clip(DisplayChannelClient* dcc, VideoStreamAgent *agent)
{
auto item = video_stream_clip_item_new(agent);
auto item = red::make_shared<VideoStreamClipItem>(agent);
dcc->pipe_add(std::move(item));
}

View File

@ -226,8 +226,9 @@ struct RedDrawablePipeItem: public RedPipeItemNum<RED_PIPE_ITEM_TYPE_DRAW> {
/* This item is used to send a full quality image (lossless) of the area where the stream was.
* This to avoid the artifacts due to the lossy compression. */
struct RedUpgradeItem: public RedPipeItemNum<RED_PIPE_ITEM_TYPE_UPGRADE> {
RedUpgradeItem(Drawable *drawable);
~RedUpgradeItem();
Drawable *drawable;
Drawable *const drawable;
red::glib_unique_ptr<SpiceClipRects> rects;
};

View File

@ -186,6 +186,8 @@ static red::shared_ptr<RedVmcChannel> red_vmc_channel_new(RedsState *reds, uint8
}
struct RedPortInitPipeItem: public RedPipeItemNum<RED_PIPE_ITEM_TYPE_PORT_INIT> {
RedPortInitPipeItem(const char *name, uint8_t opened);
red::glib_unique_ptr<char> name;
uint8_t opened;
};
@ -273,14 +275,18 @@ RedCharDeviceSpiceVmc::read_one_msg_from_device()
return RedPipeItemPtr();
}
RedPortInitPipeItem::RedPortInitPipeItem(const char *init_name, uint8_t init_opened):
name(g_strdup(init_name)),
opened(init_opened)
{
}
static void spicevmc_port_send_init(VmcChannelClient *rcc)
{
RedVmcChannel *channel = rcc->get_channel();
SpiceCharDeviceInstance *sin = channel->chardev_sin;
auto item = red::make_shared<RedPortInitPipeItem>();
auto item = red::make_shared<RedPortInitPipeItem>(sin->portname, channel->port_opened);
item->name.reset(g_strdup(sin->portname));
item->opened = channel->port_opened;
rcc->pipe_add_push(std::move(item));
}

View File

@ -70,24 +70,21 @@ StreamCreateDestroyItem::~StreamCreateDestroyItem()
video_stream_agent_unref(display, agent);
}
static RedPipeItemPtr
video_stream_create_destroy_item_new(VideoStreamAgent *agent, int type)
StreamCreateDestroyItem::StreamCreateDestroyItem(VideoStreamAgent *init_agent, int init_type):
RedPipeItem(init_type),
agent(init_agent)
{
auto item = red::make_shared<StreamCreateDestroyItem>(type);
agent->stream->refs++;
item->agent = agent;
return item;
}
static RedPipeItemPtr video_stream_create_item_new(VideoStreamAgent *agent)
{
return video_stream_create_destroy_item_new(agent, RED_PIPE_ITEM_TYPE_STREAM_CREATE);
return red::make_shared<StreamCreateDestroyItem>(agent, RED_PIPE_ITEM_TYPE_STREAM_CREATE);
}
static RedPipeItemPtr video_stream_destroy_item_new(VideoStreamAgent *agent)
{
return video_stream_create_destroy_item_new(agent, RED_PIPE_ITEM_TYPE_STREAM_DESTROY);
return red::make_shared<StreamCreateDestroyItem>(agent, RED_PIPE_ITEM_TYPE_STREAM_DESTROY);
}
@ -166,22 +163,18 @@ VideoStreamClipItem::~VideoStreamClipItem()
video_stream_agent_unref(display, stream_agent);
}
red::shared_ptr<VideoStreamClipItem> video_stream_clip_item_new(VideoStreamAgent *agent)
VideoStreamClipItem::VideoStreamClipItem(VideoStreamAgent *agent):
RedPipeItem(RED_PIPE_ITEM_TYPE_STREAM_CLIP),
stream_agent(agent),
clip_type(SPICE_CLIP_TYPE_RECTS)
{
auto item = red::make_shared<VideoStreamClipItem>(RED_PIPE_ITEM_TYPE_STREAM_CLIP);
item->stream_agent = agent;
agent->stream->refs++;
item->clip_type = SPICE_CLIP_TYPE_RECTS;
int n_rects = pixman_region32_n_rects(&agent->clip);
item->rects.reset((SpiceClipRects*) g_malloc(sizeof(SpiceClipRects) +
n_rects * sizeof(SpiceRect)));
item->rects->num_rects = n_rects;
region_ret_rects(&agent->clip, item->rects->rects, n_rects);
return item;
rects.reset((SpiceClipRects*) g_malloc(sizeof(SpiceClipRects) +
n_rects * sizeof(SpiceRect)));
rects->num_rects = n_rects;
region_ret_rects(&agent->clip, rects->rects, n_rects);
}
static int is_stream_start(Drawable *drawable)
@ -804,6 +797,12 @@ RedUpgradeItem::~RedUpgradeItem()
drawable_unref(drawable);
}
RedUpgradeItem::RedUpgradeItem(Drawable *init_drawable):
drawable(init_drawable)
{
drawable->refs++;
}
/*
* after dcc_detach_stream_gracefully is called for all the display channel clients,
* video_stream_detach_drawable should be called. See comment (1).
@ -839,9 +838,7 @@ static void dcc_detach_stream_gracefully(DisplayChannelClient *dcc,
}
spice_debug("stream %d: upgrade by drawable. box ==>", stream_id);
rect_debug(&stream->current->red_drawable->bbox);
auto upgrade_item = red::make_shared<RedUpgradeItem>();
upgrade_item->drawable = stream->current;
upgrade_item->drawable->refs++;
auto upgrade_item = red::make_shared<RedUpgradeItem>(stream->current);
n_rects = pixman_region32_n_rects(&upgrade_item->drawable->tree_item.base.rgn);
upgrade_item->rects.reset((SpiceClipRects*) g_malloc(sizeof(SpiceClipRects) +
n_rects * sizeof(SpiceRect)));

View File

@ -82,17 +82,16 @@ typedef struct VideoStreamAgent {
} VideoStreamAgent;
struct VideoStreamClipItem: public RedPipeItem {
using RedPipeItem::RedPipeItem;
VideoStreamClipItem(VideoStreamAgent *agent);
~VideoStreamClipItem();
VideoStreamAgent *stream_agent;
int clip_type;
red::glib_unique_ptr<SpiceClipRects> rects;
};
red::shared_ptr<VideoStreamClipItem> video_stream_clip_item_new(VideoStreamAgent *agent);
struct StreamCreateDestroyItem: public RedPipeItem {
using RedPipeItem::RedPipeItem;
StreamCreateDestroyItem(VideoStreamAgent *agent, int type);
~StreamCreateDestroyItem();
VideoStreamAgent *agent;
};