Store display in Drawable struct

If the Drawable keeps a pointer to the Display channel that it is
associated with, we can unref it directly and not need to pass the
'display' parameter separately to the unref function

Acked-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
Jonathon Jongsma 2016-04-21 10:45:15 -05:00
parent c6b1fc3551
commit 50a2c2fce2
3 changed files with 21 additions and 18 deletions

View File

@ -277,13 +277,11 @@ static void add_drawable_surface_images(DisplayChannelClient *dcc, Drawable *dra
void drawable_pipe_item_free(PipeItem *item)
{
DrawablePipeItem *dpi = SPICE_CONTAINEROF(item, DrawablePipeItem, dpi_pipe_item);
DisplayChannel *display = DCC_TO_DC(dpi->dcc);
spice_assert(item->refcount == 0);
spice_warn_if_fail(!ring_item_is_linked(&item->link));
spice_warn_if_fail(!ring_item_is_linked(&dpi->base));
display_channel_drawable_unref(display, dpi->drawable);
drawable_unref(dpi->drawable);
free(dpi);
}
@ -1591,20 +1589,18 @@ int dcc_handle_migrate_data(DisplayChannelClient *dcc, uint32_t size, void *mess
return TRUE;
}
static void upgrade_item_unref(DisplayChannel *display, UpgradeItem *item)
static void upgrade_item_unref(UpgradeItem *item)
{
if (--item->refs != 0)
return;
display_channel_drawable_unref(display, item->drawable);
drawable_unref(item->drawable);
free(item->rects);
free(item);
}
static void release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
static void release_item_after_push(PipeItem *item)
{
DisplayChannel *display = DCC_TO_DC(dcc);
switch (item->type) {
case PIPE_ITEM_TYPE_DRAW:
case PIPE_ITEM_TYPE_IMAGE:
@ -1613,7 +1609,7 @@ static void release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
pipe_item_unref(item);
break;
case PIPE_ITEM_TYPE_UPGRADE:
upgrade_item_unref(display, (UpgradeItem *)item);
upgrade_item_unref((UpgradeItem *)item);
break;
case PIPE_ITEM_TYPE_GL_SCANOUT:
case PIPE_ITEM_TYPE_GL_DRAW:
@ -1651,7 +1647,7 @@ static void release_item_before_push(DisplayChannelClient *dcc, PipeItem *item)
}
case PIPE_ITEM_TYPE_STREAM_CLIP:
case PIPE_ITEM_TYPE_UPGRADE:
upgrade_item_unref(display, (UpgradeItem *)item);
upgrade_item_unref((UpgradeItem *)item);
break;
case PIPE_ITEM_TYPE_IMAGE:
case PIPE_ITEM_TYPE_MONITORS_CONFIG:
@ -1688,7 +1684,7 @@ static void release_item_before_push(DisplayChannelClient *dcc, PipeItem *item)
void dcc_release_item(DisplayChannelClient *dcc, PipeItem *item, int item_pushed)
{
if (item_pushed)
release_item_after_push(dcc, item);
release_item_after_push(item);
else
release_item_before_push(dcc, item);
}

View File

@ -390,7 +390,7 @@ static void current_remove_drawable(DisplayChannel *display, Drawable *item)
ring_remove(&item->tree_item.base.siblings_link);
ring_remove(&item->list_link);
ring_remove(&item->surface_list_link);
display_channel_drawable_unref(display, item);
drawable_unref(item);
display->current_size--;
}
@ -488,7 +488,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem *
pipes_add_drawable(display, drawable);
}
drawable_remove_from_pipes(other_drawable);
display_channel_drawable_unref(display, other_drawable);
drawable_unref(other_drawable);
return TRUE;
}
@ -531,7 +531,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem *
/* not sending other_drawable where possible */
drawable_remove_from_pipes(other_drawable);
display_channel_drawable_unref(display, other_drawable);
drawable_unref(other_drawable);
return TRUE;
}
break;
@ -1185,7 +1185,7 @@ void display_channel_process_draw(DisplayChannel *display, RedDrawable *red_draw
display_channel_add_drawable(display, drawable);
display_channel_drawable_unref(display, drawable);
drawable_unref(drawable);
}
int display_channel_wait_for_migrate_data(DisplayChannel *display)
@ -1373,6 +1373,10 @@ Drawable *display_channel_drawable_try_new(DisplayChannel *display,
}
bzero(drawable, sizeof(Drawable));
/* Pointer to the display from which the drawable is allocated. This
* pointer is safe to be retained as DisplayChannel lifespan is bigger than
* all drawables. */
drawable->display = display;
drawable->refs = 1;
drawable->creation_time = drawable->first_frame_time = spice_get_monotonic_time_ns();
ring_item_init(&drawable->list_link);
@ -1423,8 +1427,9 @@ static void drawable_unref_surface_deps(DisplayChannel *display, Drawable *drawa
}
}
void display_channel_drawable_unref(DisplayChannel *display, Drawable *drawable)
void drawable_unref(Drawable *drawable)
{
DisplayChannel *display = drawable->display;
RingItem *item, *next;
if (--drawable->refs != 0)
@ -1646,7 +1651,7 @@ static void draw_until(DisplayChannel *display, RedSurface *surface, Drawable *l
that display_channel_draw is called for, Otherwise, 'now' would have already been rendered.
See the call for red_handle_depends_on_target_surface in red_process_draw */
drawable_draw(display, now);
display_channel_drawable_unref(display, now);
drawable_unref(now);
} while (now != last);
}

View File

@ -79,8 +79,11 @@ struct Drawable {
int surface_deps[3];
uint32_t process_commands_generation;
DisplayChannel *display;
};
void drawable_unref (Drawable *drawable);
#define LINK_TO_DPI(ptr) SPICE_CONTAINEROF((ptr), DrawablePipeItem, base)
#define DRAWABLE_FOREACH_DPI_SAFE(drawable, link, next, dpi) \
SAFE_FOREACH(link, next, drawable, &(drawable)->pipes, dpi, LINK_TO_DPI(link))
@ -280,7 +283,6 @@ void display_channel_compress_stats_print (const Disp
void display_channel_compress_stats_reset (DisplayChannel *display);
Drawable * display_channel_drawable_try_new (DisplayChannel *display,
int process_commands_generation);
void display_channel_drawable_unref (DisplayChannel *display, Drawable *drawable);
void display_channel_surface_unref (DisplayChannel *display,
uint32_t surface_id);
void display_channel_current_flush (DisplayChannel *display,