[spice-gtk/f19] RHBZ 998529: fix cursor to contrast for mono invert only cursors

Alon Levy alon at fedoraproject.org
Sun Oct 20 22:41:26 UTC 2013


commit 6ed0f2f1286c49838c87b538c6389c0de1e30968
Author: Alon Levy <alevy at redhat.com>
Date:   Mon Oct 21 01:41:14 2013 +0300

    RHBZ 998529: fix cursor to contrast for mono invert only cursors

 ...-increase-contrast-better-looking-putty-c.patch |   42 ++++
 ...nel.c-add-cursor-print-function-for-debug.patch |   63 +++++
 ...nel-cursor-mono-cursors-edge-highlighting.patch |  248 ++++++++++++++++++++
 spice-gtk.spec                                     |   15 ++-
 4 files changed, 367 insertions(+), 1 deletions(-)
---
diff --git a/0009-mono-cursor-increase-contrast-better-looking-putty-c.patch b/0009-mono-cursor-increase-contrast-better-looking-putty-c.patch
new file mode 100644
index 0000000..394f686
--- /dev/null
+++ b/0009-mono-cursor-increase-contrast-better-looking-putty-c.patch
@@ -0,0 +1,42 @@
+From a0a5818fefe75135f383dcc5914ca376b3272418 Mon Sep 17 00:00:00 2001
+From: Alon Levy <alevy at redhat.com>
+Date: Mon, 23 Sep 2013 16:09:32 +0300
+Subject: [PATCH 09/11] mono cursor: increase contrast, better looking putty
+ cursor (rhbz 998529)
+
+Signed-off-by: Alon Levy <alevy at redhat.com>
+---
+ gtk/channel-cursor.c | 16 ++++++++--------
+ 1 file changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/gtk/channel-cursor.c b/gtk/channel-cursor.c
+index e4a996b..7a985a4 100644
+--- a/gtk/channel-cursor.c
++++ b/gtk/channel-cursor.c
+@@ -267,15 +267,15 @@ static void mono_cursor(display_cursor *cursor, const guint8 *data)
+                      * the same contrast.
+                      */
+                     if ((x ^ y) & 1) {
+-                        dest[0] = 0x30;
+-                        dest[1] = 0x30;
+-                        dest[2] = 0x30;
+-                        dest[3] = 0xc0;
++                        dest[0] = 0xff;
++                        dest[1] = 0xff;
++                        dest[2] = 0xff;
++                        dest[3] = 0xff;
+                     } else {
+-                        dest[0] = 0x50;
+-                        dest[1] = 0x50;
+-                        dest[2] = 0x50;
+-                        dest[3] = 0x30;
++                        dest[0] = 0x00;
++                        dest[1] = 0x00;
++                        dest[2] = 0x00;
++                        dest[3] = 0x00;
+                     }
+                 } else {
+                     /* unchanged -> transparent */
+-- 
+1.8.3.1
+
diff --git a/0010-cursor-channel.c-add-cursor-print-function-for-debug.patch b/0010-cursor-channel.c-add-cursor-print-function-for-debug.patch
new file mode 100644
index 0000000..1cb3aa8
--- /dev/null
+++ b/0010-cursor-channel.c-add-cursor-print-function-for-debug.patch
@@ -0,0 +1,63 @@
+From 57c0e9be6e96afd1e5d2887ae374d551dc375b2f Mon Sep 17 00:00:00 2001
+From: Alon Levy <alevy at redhat.com>
+Date: Fri, 18 Oct 2013 14:36:22 +0300
+Subject: [PATCH 10/11] cursor-channel.c: add cursor print function for
+ debugging only (ifdefed)
+
+---
+ gtk/channel-cursor.c | 32 ++++++++++++++++++++++++++++++++
+ 1 file changed, 32 insertions(+)
+
+diff --git a/gtk/channel-cursor.c b/gtk/channel-cursor.c
+index 7a985a4..7407521 100644
+--- a/gtk/channel-cursor.c
++++ b/gtk/channel-cursor.c
+@@ -244,6 +244,35 @@ static void do_emit_main_context(GObject *object, int signum, gpointer params)
+ 
+ /* ------------------------------------------------------------------ */
+ 
++#ifdef DEBUG_CURSOR
++static void print_cursor(display_cursor *cursor, const guint8 *data)
++{
++    int x, y, bpl;
++    const guint8 *xor, *and;
++
++    bpl = (cursor->hdr.width + 7) / 8;
++    and = data;
++    xor = and + bpl * cursor->hdr.height;
++
++    printf("data (%d x %d):\n", cursor->hdr.width, cursor->hdr.height);
++    for (y = 0 ; y < cursor->hdr.height; ++y) {
++        for (x = 0 ; x < cursor->hdr.width / 8; x++) {
++            printf("%02X", and[x]);
++        }
++        and += bpl;
++        printf("\n");
++    }
++    printf("xor:\n");
++    for (y = 0 ; y < cursor->hdr.height; ++y) {
++        for (x = 0 ; x < cursor->hdr.width / 8; ++x) {
++            printf("%02X", xor[x]);
++        }
++        xor += bpl;
++        printf("\n");
++    }
++}
++#endif
++
+ static void mono_cursor(display_cursor *cursor, const guint8 *data)
+ {
+     const guint8 *xor, *and;
+@@ -254,6 +283,9 @@ static void mono_cursor(display_cursor *cursor, const guint8 *data)
+     and = data;
+     xor = and + bpl * cursor->hdr.height;
+     dest  = (uint8_t *)cursor->data;
++#ifdef DEBUG_CURSOR
++    print_cursor(cursor, data);
++#endif
+     for (y = 0; y < cursor->hdr.height; y++) {
+         bit = 0x80;
+         for (x = 0; x < cursor->hdr.width; x++, dest += 4) {
+-- 
+1.8.3.1
+
diff --git a/0011-channel-cursor-mono-cursors-edge-highlighting.patch b/0011-channel-cursor-mono-cursors-edge-highlighting.patch
new file mode 100644
index 0000000..3472865
--- /dev/null
+++ b/0011-channel-cursor-mono-cursors-edge-highlighting.patch
@@ -0,0 +1,248 @@
+From 74909d9b9989b672502b398024c4326fe9364a5e Mon Sep 17 00:00:00 2001
+From: Alon Levy <alevy at redhat.com>
+Date: Fri, 18 Oct 2013 14:51:33 +0300
+Subject: [PATCH] channel-cursor: mono cursors edge highlighting
+
+Fix 998529, mono (invert) cursors not visible on a black background, by doing
+simple edge detection on the cursor (this is done once when the cursor
+is changed and then cached, cursors are 32x32 generally) and thus having
+a cursor with contrast on both dark and light backgrounds.
+
+When (if) GDK gets invert cursor support (wayland?) then we can just use
+the cursor as is. Until then X doesn't provide any way I see of solving
+this otherwise. The end result was tested with the I beam cursor that
+the original bug was referring to (run putty on a windows 7 vm) and
+looks ok to me.
+
+Moving the core function to spice-util for testing.
+---
+ gtk/channel-cursor.c  |  64 ++------------------
+ gtk/spice-util-priv.h |   2 +
+ gtk/spice-util.c      | 113 +++++++++++++++++++++++++++++++++++
+ 3 files changed, 121 insertions(+), 58 deletions(-)
+
+diff --git a/gtk/channel-cursor.c b/gtk/channel-cursor.c
+index 7407521..0e48446 100644
+--- a/gtk/channel-cursor.c
++++ b/gtk/channel-cursor.c
+@@ -275,70 +275,18 @@ static void print_cursor(display_cursor *cursor, const guint8 *data)
+ 
+ static void mono_cursor(display_cursor *cursor, const guint8 *data)
+ {
++    int bpl = (cursor->hdr.width + 7) / 8;
+     const guint8 *xor, *and;
+     guint8 *dest;
+-    int bpl, x, y, bit;
++    dest = (uint8_t *)cursor->data;
+ 
+-    bpl = (cursor->hdr.width + 7) / 8;
+-    and = data;
+-    xor = and + bpl * cursor->hdr.height;
+-    dest  = (uint8_t *)cursor->data;
+ #ifdef DEBUG_CURSOR
+     print_cursor(cursor, data);
+ #endif
+-    for (y = 0; y < cursor->hdr.height; y++) {
+-        bit = 0x80;
+-        for (x = 0; x < cursor->hdr.width; x++, dest += 4) {
+-            if (and[x/8] & bit) {
+-                if (xor[x/8] & bit) {
+-                    /*
+-                     * flip -> unsupported by x11, since XCreatePixmapCursor has
+-                     * no invert functionality, only a mask, shape, background and
+-                     * foreground colors. Use this checkerboard hack to get some
+-                     * contrast for cursors in the guest that relied on invert for
+-                     * the same contrast.
+-                     */
+-                    if ((x ^ y) & 1) {
+-                        dest[0] = 0xff;
+-                        dest[1] = 0xff;
+-                        dest[2] = 0xff;
+-                        dest[3] = 0xff;
+-                    } else {
+-                        dest[0] = 0x00;
+-                        dest[1] = 0x00;
+-                        dest[2] = 0x00;
+-                        dest[3] = 0x00;
+-                    }
+-                } else {
+-                    /* unchanged -> transparent */
+-                    dest[0] = 0x00;
+-                    dest[1] = 0x00;
+-                    dest[2] = 0x00;
+-                    dest[3] = 0x00;
+-                }
+-            } else {
+-                if (xor[x/8] & bit) {
+-                    /* set -> white */
+-                    dest[0] = 0xff;
+-                    dest[1] = 0xff;
+-                    dest[2] = 0xff;
+-                    dest[3] = 0xff;
+-                } else {
+-                    /* clear -> black */
+-                    dest[0] = 0x00;
+-                    dest[1] = 0x00;
+-                    dest[2] = 0x00;
+-                    dest[3] = 0xff;
+-                }
+-            }
+-            bit >>= 1;
+-            if (bit == 0) {
+-                bit = 0x80;
+-            }
+-        }
+-        and += bpl;
+-        xor += bpl;
+-    }
++    and = data;
++    xor = and + bpl * cursor->hdr.height;
++    spice_mono_edge_highlight(cursor->hdr.width, cursor->hdr.height,
++                              and, xor, dest);
+ }
+ 
+ static guint8 get_pix_mask(const guint8 *data, gint offset, gint pix_index)
+diff --git a/gtk/spice-util-priv.h b/gtk/spice-util-priv.h
+index ee5a42d..2fe78a2 100644
+--- a/gtk/spice-util-priv.h
++++ b/gtk/spice-util-priv.h
+@@ -29,6 +29,8 @@ gboolean spice_strv_contains(const GStrv strv, const gchar *str);
+ gchar* spice_uuid_to_string(const guint8 uuid[16]);
+ const gchar* spice_yes_no(gboolean value);
+ guint16 spice_make_scancode(guint scancode, gboolean release);
++void spice_mono_edge_highlight(unsigned width, unsigned hight,
++                               const guint8 *and, const guint8 *xor, guint8 *dest);
+ 
+ #if GLIB_CHECK_VERSION(2,32,0)
+ #define STATIC_MUTEX            GMutex
+diff --git a/gtk/spice-util.c b/gtk/spice-util.c
+index 774a145..61a6597 100644
+--- a/gtk/spice-util.c
++++ b/gtk/spice-util.c
+@@ -19,6 +19,8 @@
+ #ifdef HAVE_CONFIG_H
+ # include "config.h"
+ #endif
++
++#include <stdbool.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <glib-object.h>
+@@ -245,3 +247,114 @@ guint16 spice_make_scancode(guint scancode, gboolean release)
+ 
+     g_return_val_if_reached(0);
+ }
++
++static bool buf_is_ones(unsigned size, const guint8 *data)
++{
++    int i;
++
++    for (i = 0 ; i < size; ++i) {
++        if (data[i] != 0xff) {
++            return false;
++        }
++    }
++    return true;
++}
++
++static bool is_edge_helper(const guint8 *xor, int bpl, int x, int y)
++{
++    return (xor[bpl * y + (x / 8)] & (0x80 >> (x % 8))) > 0;
++}
++
++static bool is_edge(unsigned width, unsigned height, const guint8 *xor, int bpl, int x, int y)
++{
++    if (x == 0 || x == width -1 || y == 0 || y == height - 1) {
++        return 0;
++    }
++#define P(x, y) is_edge_helper(xor, bpl, x, y)
++    return !P(x, y) && (P(x - 1, y + 1) || P(x, y + 1) || P(x + 1, y + 1) ||
++                        P(x - 1, y)     ||                P(x + 1, y)     ||
++                        P(x - 1, y - 1) || P(x, y - 1) || P(x + 1, y - 1));
++#undef P
++}
++
++/* Mono cursors have two places, "and" and "xor". If a bit is 1 in both, it
++ * means invertion of the corresponding pixel in the display. Since X11 (and
++ * gdk) doesn't do invertion, instead we do edge detection and turn the
++ * sorrounding edge pixels black, and the invert-me pixels white. To
++ * illustrate:
++ *
++ *  and   xor      dest RGB (1=0xffffff, 0=0x000000)
++ *
++ *                        dest alpha (1=0xff, 0=0x00)
++ *
++ * 11111 00000     00000  00000
++ * 11111 00000     00000  01110
++ * 11111 00100 =>  00100  01110
++ * 11111 00100     00100  01110
++ * 11111 00000     00000  01110
++ * 11111 00000     00000  00000
++ *
++ * See tests/util.c for more tests
++ *
++ * Notes:
++ *  Assumes width >= 8 (i.e. bytes per line is at least 1)
++ *  Assumes edges are not on the boundary (first/last line/column) for simplicity
++ *
++ */
++G_GNUC_INTERNAL
++void spice_mono_edge_highlight(unsigned width, unsigned height,
++                               const guint8 *and, const guint8 *xor, guint8 *dest)
++{
++    int bpl = (width + 7) / 8;
++    bool and_ones = buf_is_ones(height * bpl, and);
++    int x, y, bit;
++    const guint8 *xor_base = xor;
++
++    for (y = 0; y < height; y++) {
++        bit = 0x80;
++        for (x = 0; x < width; x++, dest += 4) {
++            if (is_edge(width, height, xor_base, bpl, x, y) && and_ones) {
++                dest[0] = 0x00;
++                dest[1] = 0x00;
++                dest[2] = 0x00;
++                dest[3] = 0xff;
++                goto next_bit;
++            }
++            if (and[x/8] & bit) {
++                if (xor[x/8] & bit) {
++                    dest[0] = 0xff;
++                    dest[1] = 0xff;
++                    dest[2] = 0xff;
++                    dest[3] = 0xff;
++                } else {
++                    /* unchanged -> transparent */
++                    dest[0] = 0x00;
++                    dest[1] = 0x00;
++                    dest[2] = 0x00;
++                    dest[3] = 0x00;
++                }
++            } else {
++                if (xor[x/8] & bit) {
++                    /* set -> white */
++                    dest[0] = 0xff;
++                    dest[1] = 0xff;
++                    dest[2] = 0xff;
++                    dest[3] = 0xff;
++                } else {
++                    /* clear -> black */
++                    dest[0] = 0x00;
++                    dest[1] = 0x00;
++                    dest[2] = 0x00;
++                    dest[3] = 0xff;
++                }
++            }
++        next_bit:
++            bit >>= 1;
++            if (bit == 0) {
++                bit = 0x80;
++            }
++        }
++        and += bpl;
++        xor += bpl;
++    }
++}
+-- 
+1.8.3.1
+
diff --git a/spice-gtk.spec b/spice-gtk.spec
index 4d38aa0..c8273de 100644
--- a/spice-gtk.spec
+++ b/spice-gtk.spec
@@ -13,7 +13,7 @@
 
 Name:           spice-gtk
 Version:        0.20
-Release:        6%{?dist}
+Release:        7%{?dist}
 Summary:        A GTK+ widget for SPICE clients
 
 Group:          System Environment/Libraries
@@ -30,6 +30,11 @@ Patch6:         0006-gtk-channel-cursor.c-add-cursor_type_to_string-for-d.patch
 Patch7:         0007-gtk-channel-cursor-copy-spicec-hack-RHBZ-998529.patch
 Patch8:         0008-acl-helper-Use-ruid-of-invoker-rather-than-looking-u.patch
 
+# rhbz#998529
+Patch9:         0009-mono-cursor-increase-contrast-better-looking-putty-c.patch
+Patch10:        0010-cursor-channel.c-add-cursor-print-function-for-debug.patch
+Patch11:        0011-channel-cursor-mono-cursors-edge-highlighting.patch
+
 BuildRequires: intltool
 BuildRequires: gtk2-devel >= 2.14
 BuildRequires: usbredir-devel >= 0.5.2
@@ -163,6 +168,11 @@ pushd spice-gtk-%{version}
 %patch6 -p1
 %patch7 -p1
 %patch8 -p1
+
+# rhbz#998529
+%patch9 -p1
+%patch10 -p1
+%patch11 -p1
 find . -name '*.stamp' | xargs touch
 popd
 
@@ -284,6 +294,9 @@ rm -rf %{buildroot}%{_datadir}/pkgconfig/spice-protocol.pc
 %{_bindir}/spicy-stats
 
 %changelog
+* Mon Oct 21 2013 Alon Levy <alevy at redhat.com> - 0.20-7
+- Fix mono invert only cursor contract. rhbz#998529
+
 * Wed Sep 18 2013 Marc-André Lureau <marcandre.lureau at redhat.com> - 0.20-6
 - Fix CVE-2013-4324 Insecure calling of polkit via
   polkit_unix_process_new() (rhbz#1009540)


More information about the scm-commits mailing list