mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-30 17:49:02 +00:00
RedChannel: Add FOREACH_CLIENT and use it to iterate
Remove the custom FOREACH_DCC macro and use the more generic FOREACH_CLIENT macro and use it for all channels.
This commit is contained in:
parent
4028fb1c79
commit
a31efd7e75
@ -245,7 +245,7 @@ void display_channel_surface_unref(DisplayChannel *display, uint32_t surface_id)
|
||||
|
||||
region_destroy(&surface->draw_dirty_region);
|
||||
surface->context.canvas = NULL;
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
dcc_destroy_surface(dcc, surface_id);
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ static void streams_update_visible_region(DisplayChannel *display, Drawable *dra
|
||||
continue;
|
||||
}
|
||||
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
agent = &dcc->stream_agents[get_stream_id(display, stream)];
|
||||
|
||||
if (region_intersects(&agent->vis_region, &drawable->tree_item.base.rgn)) {
|
||||
@ -298,7 +298,7 @@ static void pipes_add_drawable(DisplayChannel *display, Drawable *drawable)
|
||||
GList *link, *next;
|
||||
|
||||
spice_warn_if_fail(ring_is_empty(&drawable->pipes));
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
dcc_prepend_drawable(dcc, drawable);
|
||||
}
|
||||
}
|
||||
@ -322,7 +322,7 @@ static void pipes_add_drawable_after(DisplayChannel *display,
|
||||
if (num_other_linked != display->common.base.clients_num) {
|
||||
GList *link, *next;
|
||||
spice_debug("TODO: not O(n^2)");
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
int sent = 0;
|
||||
DRAWABLE_FOREACH_DPI_SAFE(pos_after, dpi_link, dpi_next, dpi_pos_after) {
|
||||
if (dpi_pos_after->dcc == dcc) {
|
||||
@ -1213,7 +1213,7 @@ void display_channel_free_glz_drawables_to_free(DisplayChannel *display)
|
||||
|
||||
spice_return_if_fail(display);
|
||||
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
dcc_free_glz_drawables_to_free(dcc);
|
||||
}
|
||||
}
|
||||
@ -1225,7 +1225,7 @@ void display_channel_free_glz_drawables(DisplayChannel *display)
|
||||
|
||||
spice_return_if_fail(display);
|
||||
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
dcc_free_glz_drawables(dcc);
|
||||
}
|
||||
}
|
||||
@ -1272,7 +1272,7 @@ void display_channel_free_some(DisplayChannel *display)
|
||||
|
||||
spice_debug("#draw=%d, #glz_draw=%d", display->drawable_count,
|
||||
display->glz_drawable_count);
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
GlzSharedDictionary *glz_dict = dcc ? dcc->glz_dict : NULL;
|
||||
|
||||
if (glz_dict) {
|
||||
@ -1287,7 +1287,7 @@ void display_channel_free_some(DisplayChannel *display)
|
||||
free_one_drawable(display, TRUE);
|
||||
}
|
||||
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
GlzSharedDictionary *glz_dict = dcc ? dcc->glz_dict : NULL;
|
||||
|
||||
if (glz_dict) {
|
||||
@ -1762,7 +1762,7 @@ static void clear_surface_drawables_from_pipes(DisplayChannel *display, int surf
|
||||
GList *link, *next;
|
||||
DisplayChannelClient *dcc;
|
||||
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
if (!dcc_clear_surface_drawables_from_pipe(dcc, surface_id, wait_if_used)) {
|
||||
red_channel_client_disconnect(RED_CHANNEL_CLIENT(dcc));
|
||||
}
|
||||
@ -1828,7 +1828,7 @@ static void send_create_surface(DisplayChannel *display, int surface_id, int ima
|
||||
DisplayChannelClient *dcc;
|
||||
GList *link, *next;
|
||||
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
dcc_create_surface(dcc, surface_id);
|
||||
if (image_ready)
|
||||
dcc_push_surface_image(dcc, surface_id);
|
||||
|
||||
@ -226,15 +226,6 @@ struct DisplayChannel {
|
||||
stat_info_t lz4_stat;
|
||||
};
|
||||
|
||||
#define FOREACH_DCC(channel, _link, _next, _data) \
|
||||
for (_link = (channel ? RED_CHANNEL(channel)->clients : NULL), \
|
||||
_next = (_link ? _link->next : NULL), \
|
||||
_data = (_link ? _link->data : NULL); \
|
||||
_link; \
|
||||
_link = _next, \
|
||||
_next = (_link ? _link->next : NULL), \
|
||||
_data = (_link ? _link->data : NULL))
|
||||
|
||||
static inline int get_stream_id(DisplayChannel *display, Stream *stream)
|
||||
{
|
||||
return (int)(stream - display->streams_buf);
|
||||
|
||||
@ -42,13 +42,11 @@ static void main_channel_client_on_disconnect(RedChannelClient *rcc)
|
||||
|
||||
RedClient *main_channel_get_client_by_link_id(MainChannel *main_chan, uint32_t connection_id)
|
||||
{
|
||||
GList *link;
|
||||
MainChannelClient *mcc;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
|
||||
for (link = main_chan->base.clients; link != NULL; link = link->next) {
|
||||
rcc = link->data;
|
||||
mcc = (MainChannelClient*) rcc;
|
||||
FOREACH_CLIENT(main_chan, link, next, rcc) {
|
||||
MainChannelClient *mcc = (MainChannelClient*) rcc;
|
||||
if (main_channel_client_get_connection_id(mcc) == connection_id) {
|
||||
return rcc->client;
|
||||
}
|
||||
@ -328,10 +326,10 @@ MainChannel* main_channel_new(RedsState *reds)
|
||||
|
||||
static int main_channel_connect_semi_seamless(MainChannel *main_channel)
|
||||
{
|
||||
GList *link;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
|
||||
for (link = main_channel->base.clients; link != NULL; link = link->next) {
|
||||
RedChannelClient *rcc = link->data;
|
||||
FOREACH_CLIENT(main_channel, link, next, rcc) {
|
||||
MainChannelClient *mcc = (MainChannelClient*)rcc;
|
||||
if (main_channel_client_connect_semi_seamless(mcc))
|
||||
main_channel->num_clients_mig_wait++;
|
||||
@ -341,12 +339,12 @@ static int main_channel_connect_semi_seamless(MainChannel *main_channel)
|
||||
|
||||
static int main_channel_connect_seamless(MainChannel *main_channel)
|
||||
{
|
||||
GList *link;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
|
||||
spice_assert(g_list_length(main_channel->base.clients) == 1);
|
||||
|
||||
for (link = main_channel->base.clients; link != NULL; link = link->next) {
|
||||
RedChannelClient *rcc = link->data;
|
||||
FOREACH_CLIENT(main_channel, link, next, rcc) {
|
||||
MainChannelClient *mcc = (MainChannelClient*)rcc;
|
||||
main_channel_client_connect_seamless(mcc);
|
||||
main_channel->num_clients_mig_wait++;
|
||||
@ -383,10 +381,10 @@ int main_channel_migrate_connect(MainChannel *main_channel, RedsMigSpice *mig_ta
|
||||
|
||||
void main_channel_migrate_cancel_wait(MainChannel *main_chan)
|
||||
{
|
||||
GList *link;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
|
||||
for (link = main_chan->base.clients; link != NULL; link = link->next) {
|
||||
RedChannelClient *rcc = link->data;
|
||||
FOREACH_CLIENT(main_chan, link, next, rcc) {
|
||||
MainChannelClient *mcc = (MainChannelClient*)rcc;
|
||||
main_channel_client_migrate_cancel_wait(mcc);
|
||||
}
|
||||
@ -395,8 +393,9 @@ void main_channel_migrate_cancel_wait(MainChannel *main_chan)
|
||||
|
||||
int main_channel_migrate_src_complete(MainChannel *main_chan, int success)
|
||||
{
|
||||
GList *link;
|
||||
GList *link, *next;
|
||||
int semi_seamless_count = 0;
|
||||
RedChannelClient *rcc;
|
||||
|
||||
spice_printerr("");
|
||||
|
||||
@ -405,8 +404,7 @@ int main_channel_migrate_src_complete(MainChannel *main_chan, int success)
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (link = main_chan->base.clients; link != NULL; link = link->next) {
|
||||
RedChannelClient *rcc = link->data;
|
||||
FOREACH_CLIENT(main_chan, link, next, rcc) {
|
||||
MainChannelClient *mcc = (MainChannelClient*)rcc;
|
||||
if (main_channel_client_migrate_src_complete(mcc, success))
|
||||
semi_seamless_count++;
|
||||
|
||||
@ -675,11 +675,10 @@ int red_channel_client_test_remote_cap(RedChannelClient *rcc, uint32_t cap)
|
||||
|
||||
int red_channel_test_remote_common_cap(RedChannel *channel, uint32_t cap)
|
||||
{
|
||||
GList *link;
|
||||
|
||||
for (link = channel->clients; link != NULL; link = link->next) {
|
||||
RedChannelClient *rcc = link->data;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
|
||||
FOREACH_CLIENT(channel, link, next, rcc) {
|
||||
if (!red_channel_client_test_remote_common_cap(rcc, cap)) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -689,11 +688,10 @@ int red_channel_test_remote_common_cap(RedChannel *channel, uint32_t cap)
|
||||
|
||||
int red_channel_test_remote_cap(RedChannel *channel, uint32_t cap)
|
||||
{
|
||||
GList *link;
|
||||
|
||||
for (link = channel->clients; link != NULL; link = link->next) {
|
||||
RedChannelClient *rcc = link->data;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
|
||||
FOREACH_CLIENT(channel, link, next, rcc) {
|
||||
if (!red_channel_client_test_remote_cap(rcc, cap)) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -1920,11 +1918,10 @@ int red_channel_all_blocked(RedChannel *channel)
|
||||
|
||||
int red_channel_any_blocked(RedChannel *channel)
|
||||
{
|
||||
GList *link;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
|
||||
for (link = channel->clients; link != NULL; link = link->next) {
|
||||
rcc = link->data;
|
||||
FOREACH_CLIENT(channel, link, next, rcc) {
|
||||
if (rcc->send_data.blocked) {
|
||||
return TRUE;
|
||||
}
|
||||
@ -1979,11 +1976,10 @@ int red_channel_get_first_socket(RedChannel *channel)
|
||||
|
||||
int red_channel_no_item_being_sent(RedChannel *channel)
|
||||
{
|
||||
GList *link;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
|
||||
for (link = channel->clients; link != NULL; link = link->next) {
|
||||
rcc = link->data;
|
||||
FOREACH_CLIENT(channel, link, next, rcc) {
|
||||
if (!red_channel_client_no_item_being_sent(rcc)) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -2228,16 +2224,12 @@ static int red_channel_pipes_create_batch(RedChannel *channel,
|
||||
spice_assert(creator != NULL);
|
||||
spice_assert(pipe_add != NULL);
|
||||
|
||||
link = channel->clients;
|
||||
while (link != NULL) {
|
||||
next = link->next;
|
||||
rcc = link->data;
|
||||
FOREACH_CLIENT(channel, link, next, rcc) {
|
||||
item = (*creator)(rcc, data, num++);
|
||||
if (item) {
|
||||
(*pipe_add)(rcc, item);
|
||||
n++;
|
||||
}
|
||||
link = next;
|
||||
}
|
||||
|
||||
return n;
|
||||
@ -2280,12 +2272,11 @@ uint32_t red_channel_max_pipe_size(RedChannel *channel)
|
||||
|
||||
uint32_t red_channel_min_pipe_size(RedChannel *channel)
|
||||
{
|
||||
GList *link;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
uint32_t pipe_size = ~0;
|
||||
|
||||
for (link = channel->clients; link != NULL; link = link->next) {
|
||||
rcc = link->data;
|
||||
FOREACH_CLIENT(channel, link, next, rcc) {
|
||||
pipe_size = MIN(pipe_size, rcc->pipe_size);
|
||||
}
|
||||
return pipe_size == ~0 ? 0 : pipe_size;
|
||||
@ -2293,12 +2284,11 @@ uint32_t red_channel_min_pipe_size(RedChannel *channel)
|
||||
|
||||
uint32_t red_channel_sum_pipes_size(RedChannel *channel)
|
||||
{
|
||||
GList *link;
|
||||
GList *link, *next;
|
||||
RedChannelClient *rcc;
|
||||
uint32_t sum = 0;
|
||||
|
||||
for (link = channel->clients; link != NULL; link = link->next) {
|
||||
rcc = link->data;
|
||||
FOREACH_CLIENT(channel, link, next, rcc) {
|
||||
sum += rcc->pipe_size;
|
||||
}
|
||||
return sum;
|
||||
|
||||
@ -330,6 +330,16 @@ struct RedChannel {
|
||||
#endif
|
||||
};
|
||||
|
||||
#define FOREACH_CLIENT(channel, _link, _next, _data) \
|
||||
for (_link = (channel ? RED_CHANNEL(channel)->clients : NULL), \
|
||||
_next = (_link ? _link->next : NULL), \
|
||||
_data = (_link ? _link->data : NULL); \
|
||||
_link; \
|
||||
_link = _next, \
|
||||
_next = (_link ? _link->next : NULL), \
|
||||
_data = (_link ? _link->data : NULL))
|
||||
|
||||
|
||||
#define RED_CHANNEL(Channel) ((RedChannel *)(Channel))
|
||||
|
||||
/*
|
||||
|
||||
@ -533,7 +533,7 @@ static void guest_set_client_capabilities(RedWorker *worker)
|
||||
for (i = 0 ; i < sizeof(caps_available) / sizeof(caps_available[0]); ++i) {
|
||||
SET_CAP(caps, caps_available[i]);
|
||||
}
|
||||
FOREACH_DCC(worker->display_channel, link, next, dcc) {
|
||||
FOREACH_CLIENT(worker->display_channel, link, next, dcc) {
|
||||
rcc = (RedChannelClient *)dcc;
|
||||
for (i = 0 ; i < sizeof(caps_available) / sizeof(caps_available[0]); ++i) {
|
||||
if (!red_channel_client_test_remote_cap(rcc, caps_available[i]))
|
||||
@ -648,7 +648,7 @@ static void red_worker_push_monitors_config(RedWorker *worker)
|
||||
DisplayChannelClient *dcc;
|
||||
GList *item, *next;
|
||||
|
||||
FOREACH_DCC(worker->display_channel, item, next, dcc) {
|
||||
FOREACH_CLIENT(worker->display_channel, item, next, dcc) {
|
||||
dcc_push_monitors_config(dcc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ void stream_stop(DisplayChannel *display, Stream *stream)
|
||||
spice_return_if_fail(!stream->current);
|
||||
|
||||
spice_debug("stream %d", get_stream_id(display, stream));
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
StreamAgent *stream_agent;
|
||||
|
||||
stream_agent = &dcc->stream_agents[get_stream_id(display, stream)];
|
||||
@ -308,7 +308,7 @@ static void attach_stream(DisplayChannel *display, Drawable *drawable, Stream *s
|
||||
stream->num_input_frames++;
|
||||
}
|
||||
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
StreamAgent *agent;
|
||||
QRegion clip_in_draw_dest;
|
||||
|
||||
@ -386,7 +386,7 @@ static void before_reattach_stream(DisplayChannel *display,
|
||||
}
|
||||
|
||||
|
||||
FOREACH_DCC(display, link, link_next, dcc) {
|
||||
FOREACH_CLIENT(display, link, link_next, dcc) {
|
||||
double drop_factor;
|
||||
|
||||
agent = &dcc->stream_agents[index];
|
||||
@ -468,7 +468,7 @@ static void display_channel_create_stream(DisplayChannel *display, Drawable *dra
|
||||
stream->input_fps_start_time = drawable->creation_time;
|
||||
display->streams_size_total += stream->width * stream->height;
|
||||
display->stream_count++;
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
dcc_create_stream(dcc, stream);
|
||||
}
|
||||
spice_debug("stream %d %dx%d (%d, %d) (%d, %d) %u fps",
|
||||
@ -874,7 +874,7 @@ static void detach_stream_gracefully(DisplayChannel *display, Stream *stream,
|
||||
GList *link, *next;
|
||||
DisplayChannelClient *dcc;
|
||||
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
dcc_detach_stream_gracefully(dcc, stream, update_area_limit);
|
||||
}
|
||||
if (stream->current) {
|
||||
@ -905,7 +905,7 @@ void stream_detach_behind(DisplayChannel *display, QRegion *region, Drawable *dr
|
||||
int detach = 0;
|
||||
item = ring_next(ring, item);
|
||||
|
||||
FOREACH_DCC(display, link, next, dcc) {
|
||||
FOREACH_CLIENT(display, link, next, dcc) {
|
||||
StreamAgent *agent = &dcc->stream_agents[get_stream_id(display, stream)];
|
||||
|
||||
if (region_intersects(&agent->vis_region, region)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user