From nobody Tue Dec 16 08:52:30 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1535986547410963.5338082289431; Mon, 3 Sep 2018 07:55:47 -0700 (PDT) Received: from localhost ([::1]:45583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwqGY-0004qm-AZ for importer@patchew.org; Mon, 03 Sep 2018 10:55:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwqFg-0004Od-1Y for qemu-devel@nongnu.org; Mon, 03 Sep 2018 10:54:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fwqFe-0002ZS-Op for qemu-devel@nongnu.org; Mon, 03 Sep 2018 10:54:51 -0400 Received: from mail.lekensteyn.nl ([2a02:2308::360:1:25]:56663) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fwqFe-0002W4-Dr for qemu-devel@nongnu.org; Mon, 03 Sep 2018 10:54:50 -0400 Received: by lekensteyn.nl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1fwqFa-0006bB-4z; Mon, 03 Sep 2018 16:54:47 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2015-q1; h=Message-Id:Date:Subject:Cc:To:From; bh=dW0tC+rPlzQ8DGxcALpxQiwYuITAR6UmRq1oUhUX3y4=; b=YuLrB2VsSVuObqcJJQck3Dk+qFTI6H7QqKnyoYTdijk0edWDrtqsFai9B4V9ko46NY+wjwWPeD3BsjF1nrdvNTcHkCAg9H6W5YWBS8uWWiM2F4+npBjTixpDtL6lz/uneot9jUJSGWsL3vKLiv1DOyROHKHXHIJjOa9Tq3+adfrN4o8hWF0TfI8iorAfk3NfPYlL9Q4Zkzu3DHB1t0/g/I5QHWDmfXQS8EdHsJOCGNTLftUseaclh/JuQy3v3PHuMSwy9Pjtzuqwp31cz3gF8P6LXzf/iqzVGlxQIvNIPxOMFDoQ12aM9hSIxoxRvGDVPwQgtliwEPjqsmRBDLb8yg==; From: Peter Wu To: qemu-devel@nongnu.org Date: Mon, 3 Sep 2018 16:54:47 +0200 Message-Id: <20180903145447.17142-1-peter@lekensteyn.nl> X-Mailer: git-send-email 2.18.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a02:2308::360:1:25 Subject: [Qemu-devel] [PATCH] qxl: support mono cursors with inverted colors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Monochrome cursors are still used by Windows guests with the QXL-WDDM-DOD driver. Such cursor types have one odd feature, inversion of colors. GDK does not seem to support it, so implement an alternative solution: fill the inverted pixels and add an outline to make the cursor more visible. Tested with the text cursor in Notepad and Windows 10. cursor_set_mono is also used by the vmware GPU, so add a special check to avoid breaking its 32bpp format (tested with Kubuntu 14.04.4). I was unable to find a guest which supports the 1bpp format with a vmware GPU. The old implementation was buggy and removed in v2.10.0-108-g79c5a10cdd ("qxl: drop mono cursor support"), this version improves upon that by adding bounds validation, clarifying the semantics of the two masks and adds a workaround for inverted colors support. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1611984 Signed-off-by: Peter Wu --- hw/display/qxl-render.c | 16 ++++++++++++++++ ui/cursor.c | 42 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c index c62b9a5e75..b82501ea9a 100644 --- a/hw/display/qxl-render.c +++ b/hw/display/qxl-render.c @@ -234,12 +234,28 @@ static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLC= ursor *cursor, uint32_t group_id) { QEMUCursor *c; + uint8_t *and_mask, *xor_mask; size_t size; =20 c =3D cursor_alloc(cursor->header.width, cursor->header.height); c->hot_x =3D cursor->header.hot_spot_x; c->hot_y =3D cursor->header.hot_spot_y; switch (cursor->header.type) { + case SPICE_CURSOR_TYPE_MONO: + /* Assume that the full cursor is available in a single chunk. */ + size =3D 2 * cursor_get_mono_bpl(c) * c->height; + if (size !=3D cursor->data_size) { + fprintf(stderr, "%s: bad monochrome cursor %ux%u with size %u\= n", + __func__, c->width, c->height, cursor->data_size); + goto fail; + } + and_mask =3D cursor->chunk.data; + xor_mask =3D and_mask + cursor_get_mono_bpl(c) * c->height; + cursor_set_mono(c, 0xffffff, 0x000000, xor_mask, 1, and_mask); + if (qxl->debug > 2) { + cursor_print_ascii_art(c, "qxl/mono"); + } + break; case SPICE_CURSOR_TYPE_ALPHA: size =3D sizeof(uint32_t) * cursor->header.width * cursor->header.= height; qxl_unpack_chunks(c->data, size, qxl, &cursor->chunk, group_id); diff --git a/ui/cursor.c b/ui/cursor.c index f3da0cee79..836bfb847f 100644 --- a/ui/cursor.c +++ b/ui/cursor.c @@ -128,13 +128,25 @@ void cursor_set_mono(QEMUCursor *c, uint32_t *data =3D c->data; uint8_t bit; int x,y,bpl; - + bool expand_bitmap_only =3D image =3D=3D mask; + bool has_inverted_colors =3D false; + const uint32_t inverted =3D 0x80000000; + + /* + * Converts a monochrome bitmap with XOR mask 'image' and AND mask 'ma= sk': + * https://docs.microsoft.com/en-us/windows-hardware/drivers/display/d= rawing-monochrome-pointers + */ bpl =3D cursor_get_mono_bpl(c); for (y =3D 0; y < c->height; y++) { bit =3D 0x80; for (x =3D 0; x < c->width; x++, data++) { if (transparent && mask[x/8] & bit) { - *data =3D 0x00000000; + if (!expand_bitmap_only && image[x/8] & bit) { + *data =3D inverted; + has_inverted_colors =3D true; + } else { + *data =3D 0x00000000; + } } else if (!transparent && !(mask[x/8] & bit)) { *data =3D 0x00000000; } else if (image[x/8] & bit) { @@ -150,6 +162,32 @@ void cursor_set_mono(QEMUCursor *c, mask +=3D bpl; image +=3D bpl; } + + /* + * If there are any pixels with inverted colors, create an outline (fi= ll + * transparent neighbors with the background color) and use the foregr= ound + * color as "inverted" color. + */ + if (has_inverted_colors) { + data =3D c->data; + for (y =3D 0; y < c->height; y++) { + for (x =3D 0; x < c->width; x++, data++) { + if (*data =3D=3D 0 /* transparent */ && + ((x > 0 && data[-1] =3D=3D inverted) || + (x + 1 < c->width && data[1] =3D=3D inverted) || + (y > 0 && data[-c->width] =3D=3D inverted) || + (y + 1 < c->height && data[c->width] =3D=3D inver= ted))) { + *data =3D 0xff000000 | background; + } + } + } + data =3D c->data; + for (x =3D 0; x < c->width * c->height; x++, data++) { + if (*data =3D=3D inverted) { + *data =3D 0xff000000 | foreground; + } + } + } } =20 void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *image) --=20 2.18.0