[Spice-commits] 4 commits - gtk/channel-base.c gtk/decode-glz.c gtk/spice-channel.c gtk/spice-widget.c

Marc-André Lureau elmarco at kemper.freedesktop.org
Sun Jan 15 10:31:52 PST 2012


 gtk/channel-base.c  |    6 +++---
 gtk/decode-glz.c    |   36 ++++++++++++++++++++++++------------
 gtk/spice-channel.c |    2 +-
 gtk/spice-widget.c  |   14 +++++++++-----
 4 files changed, 37 insertions(+), 21 deletions(-)

New commits:
commit d8246e2b7c0a5c6fd1558922b8568f0b6744b883
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Sun Jan 15 17:20:50 2012 +0100

    Fix compilation on mingw/windows

diff --git a/gtk/channel-base.c b/gtk/channel-base.c
index b01be23..cc4d242 100644
--- a/gtk/channel-base.c
+++ b/gtk/channel-base.c
@@ -129,11 +129,11 @@ void spice_channel_handle_wait_for_channels(SpiceChannel *channel, SpiceMsgIn *i
             .channel = channel
         };
 
-        SPICE_DEBUG("waiting for serial %lu (%d/%d)", data.wait->message_serial, i + 1, wfc->wait_count);
+        SPICE_DEBUG("waiting for serial %" PRIu64 " (%d/%d)", data.wait->message_serial, i + 1, wfc->wait_count);
         if (g_coroutine_condition_wait(&c->coroutine, wait_for_channel, &data))
-            SPICE_DEBUG("waiting for serial %lu, done", data.wait->message_serial);
+            SPICE_DEBUG("waiting for serial %"  PRIu64 ", done", data.wait->message_serial);
         else
-            SPICE_DEBUG("waiting for serial %lu, cancelled", data.wait->message_serial);
+            SPICE_DEBUG("waiting for serial %" PRIu64 ", cancelled", data.wait->message_serial);
     }
 }
 
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index ed0ca8b..83cd344 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -2170,7 +2170,7 @@ ssl_reconnect:
 
 connected:
     rc = setsockopt(g_socket_get_fd(c->sock), IPPROTO_TCP, TCP_NODELAY,
-                    &delay_val, sizeof(delay_val));
+                    (const char*)&delay_val, sizeof(delay_val));
     if (rc != 0) {
         g_warning("%s: could not set sockopt TCP_NODELAY: %s", c->name,
                   strerror(errno));
commit f905850dc4657a146f7ba090247777d718c6aa2e
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Sun Jan 15 16:56:25 2012 +0100

    Warn if windows keyboard hook failed

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 362f313..a3ca4fc 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -488,8 +488,10 @@ static void try_keyboard_grab(SpiceDisplay *display)
     gtk_widget_grab_focus(widget);
 
 #ifdef WIN32
-    d->keyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_hook_cb,
-                                        GetModuleHandle(NULL), 0);
+    if (d->keyboard_hook == NULL)
+        d->keyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_hook_cb,
+                                            GetModuleHandle(NULL), 0);
+    g_warn_if_fail(d->keyboard_hook != NULL);
 #endif
     status = gdk_keyboard_grab(gtk_widget_get_window(widget), FALSE,
                                GDK_CURRENT_TIME);
@@ -513,8 +515,10 @@ static void try_keyboard_ungrab(SpiceDisplay *display)
     SPICE_DEBUG("ungrab keyboard");
     gdk_keyboard_ungrab(GDK_CURRENT_TIME);
 #ifdef WIN32
-    UnhookWindowsHookEx(d->keyboard_hook);
-    d->keyboard_hook = 0;
+    if (d->keyboard_hook != NULL) {
+        UnhookWindowsHookEx(d->keyboard_hook);
+        d->keyboard_hook = NULL;
+    }
 #endif
     d->keyboard_grab_active = false;
     g_signal_emit(widget, signals[SPICE_DISPLAY_KEYBOARD_GRAB], 0, false);
commit edee7467bf9d0d8ed09a4477f0372d8f3981d8f1
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Sat Jan 14 18:53:02 2012 +0100

    Don't release images after the tail gap
    
    This fix a hang on an image lookup that has already been remved.  It
    only happens in multihead, when stressing a bit the displays.
    
    The decoder assumed that the last added images is the tail of the
    window. However, there are "gaps" in the window that will be filled by
    other channels. Instead of taking the last added image as the current
    up to date tail, let's take the reference to the last image before the
    first gap as the up to date tail, and release from there.
    
    The spicec code does things differently, perhaps it needs slightly
    less memory at the cost of added complexity by maintaining list of
    missing images and much more conditions/synchronization.

diff --git a/gtk/decode-glz.c b/gtk/decode-glz.c
index 3b7c34b..fb6ecc9 100644
--- a/gtk/decode-glz.c
+++ b/gtk/decode-glz.c
@@ -83,6 +83,7 @@ struct SpiceGlzDecoderWindow {
     struct glz_image        **images;
     uint32_t                nimages;
     uint64_t                oldest;
+    uint64_t                tail_gap;
 };
 
 static void glz_decoder_window_resize(SpiceGlzDecoderWindow *w)
@@ -123,6 +124,10 @@ static void glz_decoder_window_add(SpiceGlzDecoderWindow *w,
     }
 
     w->images[slot] = img;
+
+    /* close the gap */
+    while (w->tail_gap <= img->hdr.id && w->images[w->tail_gap % w->nimages] != NULL)
+        w->tail_gap++;
 }
 
 struct wait_for_image_data {
@@ -145,20 +150,17 @@ static gboolean wait_for_image(gpointer data)
 static void *glz_decoder_window_bits(SpiceGlzDecoderWindow *w, uint64_t id,
                                      uint32_t dist, uint32_t offset)
 {
-    int slot = (id - dist) % w->nimages;
-
-    if (!w->images[slot] || w->images[slot]->hdr.id != id - dist) {
-        struct wait_for_image_data data = {
-            .window = w,
-            .id = id - dist,
-        };
+    struct wait_for_image_data data = {
+        .window = w,
+        .id = id - dist,
+    };
 
-        if (!g_coroutine_condition_wait(g_coroutine_self(), wait_for_image, &data))
-            SPICE_DEBUG("wait for image cancelled");
+    if (!g_coroutine_condition_wait(g_coroutine_self(), wait_for_image, &data))
+        SPICE_DEBUG("wait for image cancelled");
 
-        slot = (id - dist) % w->nimages;
-    }
+    int slot = (id - dist) % w->nimages;
 
+    g_return_val_if_fail(w->images[slot] != NULL, NULL);
     g_return_val_if_fail(w->images[slot]->hdr.id == id - dist, NULL);
     g_return_val_if_fail(w->images[slot]->hdr.gross_pixels >= offset, NULL);
 
@@ -406,8 +408,17 @@ static void decode(SpiceGlzDecoder *decoder,
                              d->image.gross_pixels, d->image.id, palette);
     }
 
-    glz_decoder_window_release(d->window, d->image.id - d->image.win_head_dist);
     glz_decoder_window_add(d->window, decoded_image);
+
+    { /* release old images from last tail_gap, only if the gap is closed  */
+        uint64_t oldest;
+        struct glz_image *image = d->window->images[(d->window->tail_gap - 1) % d->window->nimages];
+
+        g_return_if_fail(image != NULL);
+
+        oldest = image->hdr.id - image->hdr.win_head_dist;
+        glz_decoder_window_release(d->window, oldest);
+    }
 }
 
 /* ------------------------------------------------------------------ */
@@ -431,6 +442,7 @@ void glz_decoder_window_clear(SpiceGlzDecoderWindow *w)
     w->nimages = 16;
     g_free(w->images);
     w->images = spice_new0(struct glz_image*, w->nimages);
+    w->tail_gap = 0;
 }
 
 SpiceGlzDecoderWindow *glz_decoder_window_new(void)
commit 382958c972030f6c3bef9e046a110cd7dd51db9a
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Fri Jan 13 22:25:18 2012 +0100

    Grab focus before grabing keyboard
    
    Make sure the display has the focus before grabing the keyboard for
    the application.

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 1dd06f1..362f313 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -483,9 +483,9 @@ static void try_keyboard_grab(SpiceDisplay *display)
         return;
 
     g_return_if_fail(gtk_widget_is_focus(widget));
-    g_return_if_fail(gtk_widget_has_focus(widget));
 
     SPICE_DEBUG("grab keyboard");
+    gtk_widget_grab_focus(widget);
 
 #ifdef WIN32
     d->keyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_hook_cb,


More information about the Spice-commits mailing list