From d88ef4ff31fde87759f6648ebe9473a00d998fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 9 Jan 2012 18:11:33 +0100 Subject: [PATCH spice-gtk] wait for cached images that haven't been added to the cache yet https://bugs.freedesktop.org/show_bug.cgi?id=44570 --- gtk/channel-display.c | 66 ++++++++++++++++++++++++++++++++---------------- 1 files changed, 44 insertions(+), 22 deletions(-) diff --git a/gtk/channel-display.c b/gtk/channel-display.c index d5061da..ec42829 100644 --- a/gtk/channel-display.c +++ b/gtk/channel-display.c @@ -404,18 +404,44 @@ static void image_put(SpiceImageCache *cache, uint64_t id, pixman_image_t *image item->ptr = pixman_image_ref(image); } -static pixman_image_t *image_get(SpiceImageCache *cache, uint64_t id) +typedef struct _WaitImageData +{ + gboolean lossy; + SpiceImageCache *cache; + uint64_t id; + pixman_image_t *image; +} WaitImageData; + +static gboolean wait_image(gpointer data) { - SpiceDisplayChannelPrivate *c = - SPICE_CONTAINEROF(cache, SpiceDisplayChannelPrivate, image_cache); display_cache_item *item; + WaitImageData *wait = data; + SpiceDisplayChannelPrivate *c = + SPICE_CONTAINEROF(wait->cache, SpiceDisplayChannelPrivate, image_cache); - item = cache_find(c->images, id); - if (item) { - cache_used(c->images, item); - return pixman_image_ref(item->ptr); - } - return NULL; + item = cache_find(c->images, wait->id); + if (item == NULL || + (item->lossy && !wait->lossy)) + return FALSE; + + cache_used(c->images, item); + wait->image = pixman_image_ref(item->ptr); + + return TRUE; +} + +static pixman_image_t *image_get(SpiceImageCache *cache, uint64_t id) +{ + WaitImageData wait = { + .lossy = TRUE, + .cache = cache, + .id = id, + .image = NULL + }; + if (!g_coroutine_condition_wait(g_coroutine_self(), wait_image, &wait)) + SPICE_DEBUG("wait image got cancelled"); + + return wait.image; } static void image_remove(SpiceImageCache *cache, uint64_t id) @@ -511,20 +537,16 @@ static void image_replace_lossy(SpiceImageCache *cache, uint64_t id, static pixman_image_t* image_get_lossless(SpiceImageCache *cache, uint64_t id) { - SpiceDisplayChannelPrivate *c = - SPICE_CONTAINEROF(cache, SpiceDisplayChannelPrivate, image_cache); - display_cache_item *item; - - item = cache_find(c->images, id); - if (!item) - return NULL; - - /* TODO: shared_cache.hpp does wait until it is lossless..., is - that necessary? */ - g_warn_if_fail(item->lossy == FALSE); + WaitImageData wait = { + .lossy = FALSE, + .cache = cache, + .id = id, + .image = NULL + }; + if (!g_coroutine_condition_wait(g_coroutine_self(), wait_image, &wait)) + SPICE_DEBUG("wait lossless got cancelled"); - cache_used(c->images, item); - return pixman_image_ref(item->ptr); + return wait.image; } #endif -- 1.7.7.5