[Spice-devel] [PATCH RFC 13/14] Change validate_surface to return surface pointer
Frediano Ziglio
fziglio at redhat.com
Thu Sep 29 08:44:12 UTC 2016
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/dcc-send.c | 8 ++++----
server/display-channel.c | 19 +++++++++++--------
server/display-channel.h | 2 +-
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/server/dcc-send.c b/server/dcc-send.c
index 1e31584..d5ed97e 100644
--- a/server/dcc-send.c
+++ b/server/dcc-send.c
@@ -94,9 +94,9 @@ static int 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) {
@@ -401,13 +401,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;
diff --git a/server/display-channel.c b/server/display-channel.c
index d0b4a25..cf019fe 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -2073,19 +2073,20 @@ int display_channel_get_stream_id(DisplayChannel *display, Stream *stream)
return (int)(stream - display->priv->streams_buf);
}
-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 NULL;
}
- 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)\n",
&(display->priv->surfaces[surface_id].context.canvas), surface_id);
spice_warning("failed on %d", surface_id);
- return FALSE;
+ return NULL;
}
- return TRUE;
+ return surface;
}
void display_channel_update_monitors_config(DisplayChannel *display,
@@ -2102,14 +2103,16 @@ 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, };
+ 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;
if (display->priv->monitors_config)
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, 1);
diff --git a/server/display-channel.h b/server/display-channel.h
index bd386a7..2b04bb6 100644
--- a/server/display-channel.h
+++ b/server/display-channel.h
@@ -295,7 +295,7 @@ void display_channel_update_monitors_config(DisplayChannel *display, QXLMonitors
uint16_t count, uint16_t max_allowed);
void display_channel_set_monitors_config_to_primary(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);
--
2.7.4
More information about the Spice-devel
mailing list