Change validate_surface to return surface pointer

Instead of computing the value inside the function to then
compute also in the caller return it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
This commit is contained in:
Frediano Ziglio 2016-09-16 22:09:03 +01:00 committed by Frediano Ziglio
parent 1d123192e7
commit 4434c6fb96
3 changed files with 28 additions and 27 deletions

View File

@ -92,9 +92,9 @@ static bool is_surface_area_lossy(DisplayChannelClient *dcc, uint32_t surface_id
QRegion lossy_region;
DisplayChannel *display = DCC_TO_DC(dcc);
spice_return_val_if_fail(display_channel_validate_surface(display, surface_id), FALSE);
surface = display_channel_validate_surface(display, surface_id);
spice_return_val_if_fail(surface, false);
surface = &display->priv->surfaces[surface_id];
surface_lossy_region = &dcc->priv->surface_client_lossy_region[surface_id];
if (!area) {
@ -398,13 +398,13 @@ static FillBitsType fill_bits(DisplayChannelClient *dcc, SpiceMarshaller *m,
RedSurface *surface;
surface_id = simage->u.surface.surface_id;
if (!display_channel_validate_surface(display, surface_id)) {
surface = display_channel_validate_surface(display, surface_id);
if (!surface) {
spice_warning("Invalid surface in SPICE_IMAGE_TYPE_SURFACE");
pthread_mutex_unlock(&dcc->priv->pixmap_cache->lock);
return FILL_BITS_TYPE_SURFACE;
}
surface = &display->priv->surfaces[surface_id];
image.descriptor.type = SPICE_IMAGE_TYPE_SURFACE;
image.descriptor.flags = 0;
image.descriptor.width = surface->context.width;

View File

@ -1241,15 +1241,15 @@ static void draw_depend_on_me(DisplayChannel *display, RedSurface *surface)
static bool validate_drawable_bbox(DisplayChannel *display, RedDrawable *drawable)
{
DrawContext *context;
uint32_t surface_id = drawable->surface_id;
/* surface_id must be validated before calling into
* validate_drawable_bbox
*/
if (!display_channel_validate_surface(display, drawable->surface_id)) {
RedSurface *surface = display_channel_validate_surface(display, drawable->surface_id);
if (!surface) {
return FALSE;
}
context = &display->priv->surfaces[surface_id].context;
context = &surface->context;
if (drawable->bbox.top < 0)
return FALSE;
@ -1955,16 +1955,15 @@ void display_channel_update(DisplayChannel *display,
QXLRect **qxl_dirty_rects, uint32_t *num_dirty_rects)
{
SpiceRect rect;
RedSurface *surface;
// Check that the request is valid, the surface_id comes directly from the guest
if (!display_channel_validate_surface(display, surface_id)) {
RedSurface *surface = display_channel_validate_surface(display, surface_id);
if (!surface) {
// just return, display_channel_validate_surface already logged a warning
return;
}
red_get_rect_ptr(&rect, area);
surface = &display->priv->surfaces[surface_id];
display_channel_surface_draw(display, surface, &rect);
if (*qxl_dirty_rects == nullptr) {
@ -2003,11 +2002,10 @@ static void display_channel_destroy_surface(DisplayChannel *display, RedSurface
void display_channel_destroy_surface_wait(DisplayChannel *display, uint32_t surface_id)
{
if (!display_channel_validate_surface(display, surface_id))
return;
RedSurface *surface = &display->priv->surfaces[surface_id];
if (!surface->context.canvas)
RedSurface *surface = display_channel_validate_surface(display, surface_id);
if (!surface) {
return;
}
draw_depend_on_me(display, surface);
/* note that draw_depend_on_me must be called before current_remove_all.
@ -2152,9 +2150,9 @@ static SpiceCanvas *image_surfaces_get(SpiceImageSurfaces *surfaces, uint32_t su
DisplayChannelPrivate *p = SPICE_CONTAINEROF(surfaces, DisplayChannelPrivate, image_surfaces);
DisplayChannel *display = p->pub;
spice_return_val_if_fail(display_channel_validate_surface(display, surface_id), NULL);
auto surface = display_channel_validate_surface(display, surface_id);
return p->surfaces[surface_id].context.canvas;
return surface ? surface->context.canvas : nullptr;
}
red::shared_ptr<DisplayChannel>
@ -2340,19 +2338,20 @@ VideoStream *display_channel_get_nth_video_stream(DisplayChannel *display, gint
return &display->priv->streams_buf[i];
}
gboolean display_channel_validate_surface(DisplayChannel *display, uint32_t surface_id)
RedSurface *display_channel_validate_surface(DisplayChannel *display, uint32_t surface_id)
{
if SPICE_UNLIKELY(surface_id >= display->priv->n_surfaces) {
spice_warning("invalid surface_id %u", surface_id);
return FALSE;
return nullptr;
}
if (!display->priv->surfaces[surface_id].context.canvas) {
RedSurface *surface = &display->priv->surfaces[surface_id];
if (!surface->context.canvas) {
spice_warning("canvas address is %p for %d (and is NULL)",
&(display->priv->surfaces[surface_id].context.canvas), surface_id);
&(surface->context.canvas), surface_id);
spice_warning("failed on %d", surface_id);
return FALSE;
return nullptr;
}
return TRUE;
return surface;
}
void display_channel_push_monitors_config(DisplayChannel *display)
@ -2380,17 +2379,19 @@ void display_channel_update_monitors_config(DisplayChannel *display,
void display_channel_set_monitors_config_to_primary(DisplayChannel *display)
{
DrawContext *context = &display->priv->surfaces[0].context;
QXLHead head = { 0, };
uint16_t old_max = 1;
RedSurface *surface = display_channel_validate_surface(display, 0);
spice_return_if_fail(display->priv->surfaces[0].context.canvas);
spice_return_if_fail(surface);
DrawContext *context = &surface->context;
uint16_t old_max = 1;
if (display->priv->monitors_config) {
old_max = display->priv->monitors_config->max_allowed;
monitors_config_unref(display->priv->monitors_config);
}
QXLHead head = { 0, };
head.width = context->width;
head.height = context->height;
display->priv->monitors_config = monitors_config_new(&head, 1, old_max);

View File

@ -139,7 +139,7 @@ void display_channel_update_monitors_config(DisplayChannel *display, const QXLMo
void display_channel_set_monitors_config_to_primary(DisplayChannel *display);
void display_channel_push_monitors_config(DisplayChannel *display);
gboolean display_channel_validate_surface(DisplayChannel *display, uint32_t surface_id);
RedSurface *display_channel_validate_surface(DisplayChannel *display, uint32_t surface_id);
gboolean display_channel_surface_has_canvas(DisplayChannel *display, uint32_t surface_id);
void display_channel_reset_image_cache(DisplayChannel *self);