From nobody Mon Apr 29 15:19:25 2024 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15380325314753.814621841527128; Thu, 27 Sep 2018 00:15:31 -0700 (PDT) Received: from localhost ([::1]:34054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QWI-0000HW-58 for importer@patchew.org; Thu, 27 Sep 2018 03:15:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QTw-0007Tn-MM for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5QTt-0004Mc-6k for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56130) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5QTr-0004Kv-3l for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:00 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A885E811A7 for ; Thu, 27 Sep 2018 07:12:54 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC9A0600C7; Thu, 27 Sep 2018 07:12:48 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 735693EB9D; Thu, 27 Sep 2018 09:12:47 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 27 Sep 2018 09:12:41 +0200 Message-Id: <20180927071247.25725-2-kraxel@redhat.com> In-Reply-To: <20180927071247.25725-1-kraxel@redhat.com> References: <20180927071247.25725-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 27 Sep 2018 07:12:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/7] display/edid: add edid generator to qemu. 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 , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" EDID is a metadata format to describe monitors. On physical hardware the monitor has an eeprom with that data block which can be read over i2c bus. On a linux system you can usually find the EDID data block in /sys/class/drm/$card/$connector/edid. xorg ships a edid-decode utility which you can use to turn the blob into readable form. I think it would be a good idea to use EDID for virtual displays too. Needs changes in both qemu and guest kms drivers. This patch is the first step, it adds an generator for EDID blobs to qemu. Comes with a qemu-edid test tool included. With EDID we can pass more information to the guest. Names and serial numbers, so the guests display configuration has no boring "Unknown Monitor". List of video modes. Display resolution, pretty important in case we want add HiDPI support some day. Signed-off-by: Gerd Hoffmann Message-id: 20180925075646.25114-2-kraxel@redhat.com --- configure | 2 +- Makefile | 2 + include/hw/display/edid.h | 18 ++ hw/display/edid-generate.c | 425 +++++++++++++++++++++++++++++++++++++++++= ++++ qemu-edid.c | 120 +++++++++++++ MAINTAINERS | 7 + hw/display/Makefile.objs | 2 + 7 files changed, 575 insertions(+), 1 deletion(-) create mode 100644 include/hw/display/edid.h create mode 100644 hw/display/edid-generate.c create mode 100644 qemu-edid.c diff --git a/configure b/configure index 7fd989aee1..18006f0865 100755 --- a/configure +++ b/configure @@ -5714,7 +5714,7 @@ fi =20 tools=3D"" if test "$want_tools" =3D "yes" ; then - tools=3D"qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools" + tools=3D"qemu-img\$(EXESUF) qemu-io\$(EXESUF) qemu-edid\$(EXESUF) $tools" if [ "$linux" =3D "yes" -o "$bsd" =3D "yes" -o "$solaris" =3D "yes" ] ; = then tools=3D"qemu-nbd\$(EXESUF) $tools" fi diff --git a/Makefile b/Makefile index fe623e4634..7bb6675f4a 100644 --- a/Makefile +++ b/Makefile @@ -543,6 +543,8 @@ qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COM= MON_LDADDS) =20 qemu-keymap$(EXESUF): qemu-keymap.o ui/input-keymap.o $(COMMON_LDADDS) =20 +qemu-edid$(EXESUF): qemu-edid.o hw/display/edid-generate.o $(COMMON_LDADDS) + fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-m= arshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): LIBS +=3D -lcap =20 diff --git a/include/hw/display/edid.h b/include/hw/display/edid.h new file mode 100644 index 0000000000..63b60015c3 --- /dev/null +++ b/include/hw/display/edid.h @@ -0,0 +1,18 @@ +#ifndef EDID_H +#define EDID_H + +typedef struct qemu_edid_info { + const char *vendor; + const char *name; + const char *serial; + uint32_t dpi; + uint32_t prefx; + uint32_t prefy; + uint32_t maxx; + uint32_t maxy; +} qemu_edid_info; + +void qemu_edid_generate(uint8_t *edid, size_t size, + qemu_edid_info *info); + +#endif /* EDID_H */ diff --git a/hw/display/edid-generate.c b/hw/display/edid-generate.c new file mode 100644 index 0000000000..b3e493da19 --- /dev/null +++ b/hw/display/edid-generate.c @@ -0,0 +1,425 @@ +/* + * QEMU EDID generator. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/bswap.h" +#include "hw/display/edid.h" + +static const struct edid_mode { + uint32_t xres; + uint32_t yres; + uint32_t byte; + uint32_t xtra3; + uint32_t bit; + uint32_t dta; +} modes[] =3D { + /* dea/dta extension timings (all @ 50 Hz) */ + { .xres =3D 5120, .yres =3D 2160, .dta =3D 125 }, + { .xres =3D 4096, .yres =3D 2160, .dta =3D 101 }, + { .xres =3D 3840, .yres =3D 2160, .dta =3D 96 }, + { .xres =3D 2560, .yres =3D 1080, .dta =3D 89 }, + { .xres =3D 2048, .yres =3D 1152 }, + { .xres =3D 1920, .yres =3D 1080, .dta =3D 31 }, + + /* additional standard timings 3 (all @ 60Hz) */ + { .xres =3D 1920, .yres =3D 1440, .xtra3 =3D 11, .bit =3D 5 }, + { .xres =3D 1920, .yres =3D 1200, .xtra3 =3D 10, .bit =3D 0 }, + { .xres =3D 1856, .yres =3D 1392, .xtra3 =3D 10, .bit =3D 3 }, + { .xres =3D 1792, .yres =3D 1344, .xtra3 =3D 10, .bit =3D 5 }, + { .xres =3D 1600, .yres =3D 1200, .xtra3 =3D 9, .bit =3D 2 }, + { .xres =3D 1680, .yres =3D 1050, .xtra3 =3D 9, .bit =3D 5 }, + { .xres =3D 1440, .yres =3D 1050, .xtra3 =3D 8, .bit =3D 1 }, + { .xres =3D 1440, .yres =3D 900, .xtra3 =3D 8, .bit =3D 5 }, + { .xres =3D 1360, .yres =3D 768, .xtra3 =3D 8, .bit =3D 7 }, + { .xres =3D 1280, .yres =3D 1024, .xtra3 =3D 7, .bit =3D 1 }, + { .xres =3D 1280, .yres =3D 960, .xtra3 =3D 7, .bit =3D 3 }, + { .xres =3D 1280, .yres =3D 768, .xtra3 =3D 7, .bit =3D 6 }, + + /* established timings (all @ 60Hz) */ + { .xres =3D 1024, .yres =3D 768, .byte =3D 36, .bit =3D 3 }, + { .xres =3D 800, .yres =3D 600, .byte =3D 35, .bit =3D 0 }, + { .xres =3D 640, .yres =3D 480, .byte =3D 35, .bit =3D 5 }, +}; + +static void edid_ext_dta(uint8_t *dta) +{ + dta[0] =3D 0x02; + dta[1] =3D 0x03; + dta[2] =3D 0x05; + dta[3] =3D 0x00; + + /* video data block */ + dta[4] =3D 0x40; +} + +static void edid_ext_dta_mode(uint8_t *dta, uint8_t nr) +{ + dta[dta[2]] =3D nr; + dta[2]++; + dta[4]++; +} + +static int edid_std_mode(uint8_t *mode, uint32_t xres, uint32_t yres) +{ + uint32_t aspect; + + if (xres =3D=3D 0 || yres =3D=3D 0) { + mode[0] =3D 0x01; + mode[1] =3D 0x01; + return 0; + + } else if (xres * 10 =3D=3D yres * 16) { + aspect =3D 0; + } else if (xres * 3 =3D=3D yres * 4) { + aspect =3D 1; + } else if (xres * 4 =3D=3D yres * 5) { + aspect =3D 2; + } else if (xres * 9 =3D=3D yres * 16) { + aspect =3D 3; + } else { + return -1; + } + + if ((xres / 8) - 31 > 255) { + return -1; + } + + mode[0] =3D (xres / 8) - 31; + mode[1] =3D ((aspect << 6) | (60 - 60)); + return 0; +} + +static void edid_fill_modes(uint8_t *edid, uint8_t *xtra3, uint8_t *dta, + uint32_t maxx, uint32_t maxy) +{ + const struct edid_mode *mode; + int std =3D 38; + int rc, i; + + for (i =3D 0; i < ARRAY_SIZE(modes); i++) { + mode =3D modes + i; + + if ((maxx && mode->xres > maxx) || + (maxy && mode->yres > maxy)) { + continue; + } + + if (mode->byte) { + edid[mode->byte] |=3D (1 << mode->bit); + } else if (mode->xtra3 && xtra3) { + xtra3[mode->xtra3] |=3D (1 << mode->bit); + } else if (std < 54) { + rc =3D edid_std_mode(edid + std, mode->xres, mode->yres); + if (rc =3D=3D 0) { + std +=3D 2; + } + } + + if (dta && mode->dta) { + edid_ext_dta_mode(dta, mode->dta); + } + } + + while (std < 54) { + edid_std_mode(edid + std, 0, 0); + std +=3D 2; + } +} + +static void edid_checksum(uint8_t *edid) +{ + uint32_t sum =3D 0; + int i; + + for (i =3D 0; i < 127; i++) { + sum +=3D edid[i]; + } + sum &=3D 0xff; + if (sum) { + edid[127] =3D 0x100 - sum; + } +} + +static void edid_desc_type(uint8_t *desc, uint8_t type) +{ + desc[0] =3D 0; + desc[1] =3D 0; + desc[2] =3D 0; + desc[3] =3D type; + desc[4] =3D 0; +} + +static void edid_desc_text(uint8_t *desc, uint8_t type, + const char *text) +{ + size_t len; + + edid_desc_type(desc, type); + memset(desc + 5, ' ', 13); + + len =3D strlen(text); + if (len > 12) { + len =3D 12; + } + strncpy((char *)(desc + 5), text, len); + desc[5 + len] =3D '\n'; +} + +static void edid_desc_ranges(uint8_t *desc) +{ + edid_desc_type(desc, 0xfd); + + /* vertical (50 -> 125 Hz) */ + desc[5] =3D 50; + desc[6] =3D 125; + + /* horizontal (30 -> 160 kHz) */ + desc[7] =3D 30; + desc[8] =3D 160; + + /* max dot clock (1200 MHz) */ + desc[9] =3D 1200 / 10; + + /* no extended timing information */ + desc[10] =3D 0x01; + + /* padding */ + desc[11] =3D '\n'; + memset(desc + 12, ' ', 6); +} + +/* additional standard timings 3 */ +static void edid_desc_xtra3_std(uint8_t *desc) +{ + edid_desc_type(desc, 0xf7); + desc[5] =3D 10; +} + +static void edid_desc_dummy(uint8_t *desc) +{ + edid_desc_type(desc, 0x10); +} + +static void edid_desc_timing(uint8_t *desc, + uint32_t xres, uint32_t yres, + uint32_t dpi) +{ + /* physical display size */ + uint32_t xmm =3D xres * dpi / 254; + uint32_t ymm =3D yres * dpi / 254; + + /* pull some realistic looking timings out of thin air */ + uint32_t xfront =3D xres * 25 / 100; + uint32_t xsync =3D xres * 3 / 100; + uint32_t xblank =3D xres * 35 / 100; + + uint32_t yfront =3D yres * 5 / 1000; + uint32_t ysync =3D yres * 5 / 1000; + uint32_t yblank =3D yres * 35 / 1000; + + uint32_t clock =3D 75 * (xres + xblank) * (yres + yblank); + + *(uint32_t *)(desc) =3D cpu_to_le32(clock / 10000); + + desc[2] =3D xres & 0xff; + desc[3] =3D xblank & 0xff; + desc[4] =3D (((xres & 0xf00) >> 4) | + ((xblank & 0xf00) >> 8)); + + desc[5] =3D yres & 0xff; + desc[6] =3D yblank & 0xff; + desc[7] =3D (((yres & 0xf00) >> 4) | + ((yblank & 0xf00) >> 8)); + + desc[8] =3D xfront & 0xff; + desc[9] =3D xsync & 0xff; + + desc[10] =3D (((yfront & 0x00f) << 4) | + ((ysync & 0x00f) << 0)); + desc[11] =3D (((xfront & 0x300) >> 2) | + ((xsync & 0x300) >> 4) | + ((yfront & 0x030) >> 2) | + ((ysync & 0x030) >> 4)); + + desc[12] =3D xmm & 0xff; + desc[13] =3D ymm & 0xff; + desc[14] =3D (((xmm & 0xf00) >> 4) | + ((ymm & 0xf00) >> 8)); + + desc[17] =3D 0x18; +} + +static uint32_t edid_to_10bit(float value) +{ + return (uint32_t)(value * 1024 + 0.5); +} + +static void edid_colorspace(uint8_t *edid, + float rx, float ry, + float gx, float gy, + float bx, float by, + float wx, float wy) +{ + uint32_t red_x =3D edid_to_10bit(rx); + uint32_t red_y =3D edid_to_10bit(ry); + uint32_t green_x =3D edid_to_10bit(gx); + uint32_t green_y =3D edid_to_10bit(gy); + uint32_t blue_x =3D edid_to_10bit(bx); + uint32_t blue_y =3D edid_to_10bit(by); + uint32_t white_x =3D edid_to_10bit(wx); + uint32_t white_y =3D edid_to_10bit(wy); + + edid[25] =3D (((red_x & 0x03) << 6) | + ((red_y & 0x03) << 4) | + ((green_x & 0x03) << 2) | + ((green_y & 0x03) << 0)); + edid[26] =3D (((blue_x & 0x03) << 6) | + ((blue_y & 0x03) << 4) | + ((white_x & 0x03) << 2) | + ((white_y & 0x03) << 0)); + edid[27] =3D red_x >> 2; + edid[28] =3D red_y >> 2; + edid[29] =3D green_x >> 2; + edid[30] =3D green_y >> 2; + edid[31] =3D blue_x >> 2; + edid[32] =3D blue_y >> 2; + edid[33] =3D white_x >> 2; + edid[34] =3D white_y >> 2; +} + +void qemu_edid_generate(uint8_t *edid, size_t size, + qemu_edid_info *info) +{ + uint32_t desc =3D 54; + uint8_t *xtra3 =3D NULL; + uint8_t *dta =3D NULL; + + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D set defaults =3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + + if (!info->vendor || strlen(info->vendor) !=3D 3) { + info->vendor =3D "EMU"; + } + if (!info->name) { + info->name =3D "QEMU Monitor"; + } + if (!info->dpi) { + info->dpi =3D 100; + } + if (!info->prefx) { + info->prefx =3D 1024; + } + if (!info->prefy) { + info->prefy =3D 768; + } + + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D extensions =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + + if (size >=3D 256) { + dta =3D edid + 128; + edid[126]++; + edid_ext_dta(dta); + } + + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D header information = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + + /* fixed */ + edid[0] =3D 0x00; + edid[1] =3D 0xff; + edid[2] =3D 0xff; + edid[3] =3D 0xff; + edid[4] =3D 0xff; + edid[5] =3D 0xff; + edid[6] =3D 0xff; + edid[7] =3D 0x00; + + /* manufacturer id, product code, serial number */ + uint16_t vendor_id =3D ((((info->vendor[0] - '@') & 0x1f) << 10) | + (((info->vendor[1] - '@') & 0x1f) << 5) | + (((info->vendor[2] - '@') & 0x1f) << 0)); + uint16_t model_nr =3D 0x1234; + uint32_t serial_nr =3D info->serial ? atoi(info->serial) : 0; + *(uint16_t *)(edid + 8) =3D cpu_to_be16(vendor_id); + *(uint16_t *)(edid + 10) =3D cpu_to_le16(model_nr); + *(uint32_t *)(edid + 12) =3D cpu_to_le32(serial_nr); + + /* manufacture week and year */ + edid[16] =3D 42; + edid[17] =3D 2014 - 1990; + + /* edid version */ + edid[18] =3D 1; + edid[19] =3D 4; + + + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D basic display paramet= ers =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + + /* video input: digital, 8bpc, displayport */ + edid[20] =3D 0xa5; + + /* screen size: undefined */ + edid[21] =3D info->prefx * info->dpi / 2540; + edid[22] =3D info->prefy * info->dpi / 2540; + + /* display gamma: 2.2 */ + edid[23] =3D 220 - 100; + + /* supported features bitmap: std sRGB, preferred timing */ + edid[24] =3D 0x06; + + + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D chromaticity coordina= tes =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + + /* standard sRGB colorspace */ + edid_colorspace(edid, + 0.6400, 0.3300, /* red */ + 0.3000, 0.6000, /* green */ + 0.1500, 0.0600, /* blue */ + 0.3127, 0.3290); /* white point */ + + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D established timing bi= tmap =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D standard timing infor= mation =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + + /* both filled by edid_fill_modes() */ + + + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D descriptor blocks =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + + edid_desc_timing(edid + desc, info->prefx, info->prefy, info->dpi); + desc +=3D 18; + + edid_desc_ranges(edid + desc); + desc +=3D 18; + + if (info->name) { + edid_desc_text(edid + desc, 0xfc, info->name); + desc +=3D 18; + } + + if (info->serial) { + edid_desc_text(edid + desc, 0xff, info->serial); + desc +=3D 18; + } + + if (desc < 126) { + xtra3 =3D edid + desc; + edid_desc_xtra3_std(xtra3); + desc +=3D 18; + } + + while (desc < 126) { + edid_desc_dummy(edid + desc); + desc +=3D 18; + } + + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D finish up =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + + edid_fill_modes(edid, xtra3, dta, info->maxx, info->maxy); + edid_checksum(edid); + if (dta) { + edid_checksum(dta); + } +} diff --git a/qemu-edid.c b/qemu-edid.c new file mode 100644 index 0000000000..ae8b8a6d9b --- /dev/null +++ b/qemu-edid.c @@ -0,0 +1,120 @@ +/* + * QEMU EDID test tool. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/bswap.h" +#include "qemu/cutils.h" +#include "hw/display/edid.h" + +static qemu_edid_info info; + +static void usage(FILE *out) +{ + fprintf(out, + "\n" + "This is a test tool for the qemu edid generator.\n" + "\n" + "Typically you'll pipe the output into edid-decode\n" + "to check if the generator works correctly.\n" + "\n" + "usage: qemu-edid \n" + "options:\n" + " -h print this text\n" + " -o set output file (stdout by default)\n" + " -v set monitor vendor (three letters)\n" + " -n set monitor name\n" + " -s set monitor serial\n" + " -d set display resolution\n" + " -x set preferred width\n" + " -y set preferred height\n" + " -X set maximum width\n" + " -Y set maximum height\n" + "\n"); +} + +int main(int argc, char *argv[]) +{ + FILE *outfile =3D NULL; + uint8_t blob[256]; + int rc; + + for (;;) { + rc =3D getopt(argc, argv, "ho:x:y:X:Y:d:v:n:s:"); + if (rc =3D=3D -1) { + break; + } + switch (rc) { + case 'o': + if (outfile) { + fprintf(stderr, "outfile specified twice\n"); + exit(1); + } + outfile =3D fopen(optarg, "w"); + if (outfile =3D=3D NULL) { + fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); + exit(1); + } + break; + case 'x': + if (qemu_strtoui(optarg, NULL, 10, &info.prefx) < 0) { + fprintf(stderr, "not a number: %s\n", optarg); + exit(1); + } + break; + case 'y': + if (qemu_strtoui(optarg, NULL, 10, &info.prefy) < 0) { + fprintf(stderr, "not a number: %s\n", optarg); + exit(1); + } + break; + case 'X': + if (qemu_strtoui(optarg, NULL, 10, &info.maxx) < 0) { + fprintf(stderr, "not a number: %s\n", optarg); + exit(1); + } + break; + case 'Y': + if (qemu_strtoui(optarg, NULL, 10, &info.maxy) < 0) { + fprintf(stderr, "not a number: %s\n", optarg); + exit(1); + } + break; + case 'd': + if (qemu_strtoui(optarg, NULL, 10, &info.dpi) < 0) { + fprintf(stderr, "not a number: %s\n", optarg); + exit(1); + } + break; + case 'v': + info.vendor =3D optarg; + break; + case 'n': + info.name =3D optarg; + break; + case 's': + info.serial =3D optarg; + break; + case 'h': + usage(stdout); + exit(0); + default: + usage(stderr); + exit(1); + } + } + + if (outfile =3D=3D NULL) { + outfile =3D stdout; + } + + memset(blob, 0, sizeof(blob)); + qemu_edid_generate(blob, sizeof(blob), &info); + fwrite(blob, sizeof(blob), 1, outfile); + fflush(outfile); + + exit(0); +} diff --git a/MAINTAINERS b/MAINTAINERS index ce7c351afa..15503f41d8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1403,6 +1403,13 @@ S: Odd Fixes W: https://www.kraxel.org/blog/2014/10/qemu-using-cirrus-considered-harmfu= l/ F: hw/display/cirrus* =20 +EDID Generator +M: Gerd Hoffmann +S: Maintained +F: hw/display/edid* +F: include/hw/display/edid.h +F: qemu-edid.c + Subsystems ---------- Audio diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs index a606fb7404..492404c09e 100644 --- a/hw/display/Makefile.objs +++ b/hw/display/Makefile.objs @@ -1,3 +1,5 @@ +common-obj-y +=3D edid-generate.o + common-obj-$(CONFIG_FW_CFG_DMA) +=3D ramfb.o common-obj-$(CONFIG_FW_CFG_DMA) +=3D ramfb-standalone.o =20 --=20 2.9.3 From nobody Mon Apr 29 15:19:25 2024 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 153803252890788.6207937964981; Thu, 27 Sep 2018 00:15:28 -0700 (PDT) Received: from localhost ([::1]:34051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QW7-0000AS-3L for importer@patchew.org; Thu, 27 Sep 2018 03:15:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QTv-0007Tg-VA for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5QTq-0004Lg-U5 for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38098) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5QTn-0004Kg-8z for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:12:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47303308A96F for ; Thu, 27 Sep 2018 07:12:53 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCDDA5D9D6; Thu, 27 Sep 2018 07:12:48 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 7CE1A3EBB6; Thu, 27 Sep 2018 09:12:47 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 27 Sep 2018 09:12:42 +0200 Message-Id: <20180927071247.25725-3-kraxel@redhat.com> In-Reply-To: <20180927071247.25725-1-kraxel@redhat.com> References: <20180927071247.25725-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 27 Sep 2018 07:12:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/7] display/edid: add qemu_edid_size() 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 , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Helper function to figure the size of a edid blob, by checking how many extensions are present. Both the base edid blob and the extensions are 128 bytes in size. Signed-off-by: Gerd Hoffmann Message-id: 20180925075646.25114-3-kraxel@redhat.com --- include/hw/display/edid.h | 1 + hw/display/edid-generate.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/hw/display/edid.h b/include/hw/display/edid.h index 63b60015c3..96910ada0f 100644 --- a/include/hw/display/edid.h +++ b/include/hw/display/edid.h @@ -14,5 +14,6 @@ typedef struct qemu_edid_info { =20 void qemu_edid_generate(uint8_t *edid, size_t size, qemu_edid_info *info); +size_t qemu_edid_size(uint8_t *edid); =20 #endif /* EDID_H */ diff --git a/hw/display/edid-generate.c b/hw/display/edid-generate.c index b3e493da19..c80397ea96 100644 --- a/hw/display/edid-generate.c +++ b/hw/display/edid-generate.c @@ -423,3 +423,17 @@ void qemu_edid_generate(uint8_t *edid, size_t size, edid_checksum(dta); } } + +size_t qemu_edid_size(uint8_t *edid) +{ + uint32_t exts; + + if (edid[0] !=3D 0x00 || + edid[1] !=3D 0xff) { + /* doesn't look like a valid edid block */ + return 0; + } + + exts =3D edid[126]; + return 128 * (exts + 1); +} --=20 2.9.3 From nobody Mon Apr 29 15:19:25 2024 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538032528206727.0414640004592; Thu, 27 Sep 2018 00:15:28 -0700 (PDT) Received: from localhost ([::1]:34053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QW8-0000Cl-SS for importer@patchew.org; Thu, 27 Sep 2018 03:15:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QTv-0007Ti-VK for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5QTt-0004Mw-Ia for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20066) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5QTt-0004LD-89 for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:01 -0400 Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B49C792C0 for ; Thu, 27 Sep 2018 07:12:55 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCB66BF9A2; Thu, 27 Sep 2018 07:12:48 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8719F3EC00; Thu, 27 Sep 2018 09:12:47 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 27 Sep 2018 09:12:43 +0200 Message-Id: <20180927071247.25725-4-kraxel@redhat.com> In-Reply-To: <20180927071247.25725-1-kraxel@redhat.com> References: <20180927071247.25725-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 27 Sep 2018 07:12:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/7] display/edid: add region helper. 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 , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create a io region for an EDID data block. Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20180925075646.25114-4-kraxel@redhat.com --- include/hw/display/edid.h | 4 ++++ hw/display/edid-region.c | 33 +++++++++++++++++++++++++++++++++ hw/display/Makefile.objs | 1 + 3 files changed, 38 insertions(+) create mode 100644 hw/display/edid-region.c diff --git a/include/hw/display/edid.h b/include/hw/display/edid.h index 96910ada0f..b7fe56a958 100644 --- a/include/hw/display/edid.h +++ b/include/hw/display/edid.h @@ -1,6 +1,8 @@ #ifndef EDID_H #define EDID_H =20 +#include "hw/hw.h" + typedef struct qemu_edid_info { const char *vendor; const char *name; @@ -15,5 +17,7 @@ typedef struct qemu_edid_info { void qemu_edid_generate(uint8_t *edid, size_t size, qemu_edid_info *info); size_t qemu_edid_size(uint8_t *edid); +void qemu_edid_region_io(MemoryRegion *region, Object *owner, + uint8_t *edid, size_t size); =20 #endif /* EDID_H */ diff --git a/hw/display/edid-region.c b/hw/display/edid-region.c new file mode 100644 index 0000000000..9a15734d3a --- /dev/null +++ b/hw/display/edid-region.c @@ -0,0 +1,33 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "hw/display/edid.h" + +static uint64_t edid_region_read(void *ptr, hwaddr addr, unsigned size) +{ + uint8_t *edid =3D ptr; + + return edid[addr]; +} + +static void edid_region_write(void *ptr, hwaddr addr, + uint64_t val, unsigned size) +{ + /* read only */ +} + +static const MemoryRegionOps edid_region_ops =3D { + .read =3D edid_region_read, + .write =3D edid_region_write, + .valid.min_access_size =3D 1, + .valid.max_access_size =3D 4, + .impl.min_access_size =3D 1, + .impl.max_access_size =3D 1, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + +void qemu_edid_region_io(MemoryRegion *region, Object *owner, + uint8_t *edid, size_t size) +{ + memory_region_init_io(region, owner, &edid_region_ops, + edid, "edid", size); +} diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs index 492404c09e..780a76b9f0 100644 --- a/hw/display/Makefile.objs +++ b/hw/display/Makefile.objs @@ -15,6 +15,7 @@ common-obj-$(CONFIG_XEN) +=3D xenfb.o =20 common-obj-$(CONFIG_VGA_PCI) +=3D vga-pci.o common-obj-$(CONFIG_VGA_PCI) +=3D bochs-display.o +common-obj-$(CONFIG_VGA_PCI) +=3D edid-region.o common-obj-$(CONFIG_VGA_ISA) +=3D vga-isa.o common-obj-$(CONFIG_VGA_ISA_MM) +=3D vga-isa-mm.o common-obj-$(CONFIG_VMWARE_VGA) +=3D vmware_vga.o --=20 2.9.3 From nobody Mon Apr 29 15:19:25 2024 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538032528029804.9304720758801; Thu, 27 Sep 2018 00:15:28 -0700 (PDT) Received: from localhost ([::1]:34052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QW6-0000BY-2s for importer@patchew.org; Thu, 27 Sep 2018 03:15:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QTv-0007Te-V4 for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5QTt-0004N8-N1 for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5QTt-0004L9-BW for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:01 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4210530832CD for ; Thu, 27 Sep 2018 07:12:55 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCD586109B; Thu, 27 Sep 2018 07:12:48 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8F0293EC09; Thu, 27 Sep 2018 09:12:47 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 27 Sep 2018 09:12:44 +0200 Message-Id: <20180927071247.25725-5-kraxel@redhat.com> In-Reply-To: <20180927071247.25725-1-kraxel@redhat.com> References: <20180927071247.25725-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 27 Sep 2018 07:12:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/7] display/edid: add DEFINE_EDID_PROPERTIES 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 , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a define for edid monitor properties. Signed-off-by: Gerd Hoffmann Message-id: 20180925075646.25114-5-kraxel@redhat.com --- include/hw/display/edid.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/hw/display/edid.h b/include/hw/display/edid.h index b7fe56a958..bd51d26916 100644 --- a/include/hw/display/edid.h +++ b/include/hw/display/edid.h @@ -20,4 +20,8 @@ size_t qemu_edid_size(uint8_t *edid); void qemu_edid_region_io(MemoryRegion *region, Object *owner, uint8_t *edid, size_t size); =20 +#define DEFINE_EDID_PROPERTIES(_state, _edid_info) \ + DEFINE_PROP_UINT32("xres", _state, _edid_info.prefx, 0), \ + DEFINE_PROP_UINT32("yres", _state, _edid_info.prefy, 0) + #endif /* EDID_H */ --=20 2.9.3 From nobody Mon Apr 29 15:19:25 2024 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538032673484828.6239782435214; Thu, 27 Sep 2018 00:17:53 -0700 (PDT) Received: from localhost ([::1]:34067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QYa-0003M9-7R for importer@patchew.org; Thu, 27 Sep 2018 03:17:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QU2-0007W7-Hh for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5QTt-0004NK-P2 for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47666) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5QTt-0004Kx-Cx for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:01 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C03593001706 for ; Thu, 27 Sep 2018 07:12:54 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10B2F600CD; Thu, 27 Sep 2018 07:12:54 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 9A93B3EC0A; Thu, 27 Sep 2018 09:12:47 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 27 Sep 2018 09:12:45 +0200 Message-Id: <20180927071247.25725-6-kraxel@redhat.com> In-Reply-To: <20180927071247.25725-1-kraxel@redhat.com> References: <20180927071247.25725-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 27 Sep 2018 07:12:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/7] display/stdvga: add edid support. 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 , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds edid support to the qemu stdvga. It is turned off by default and can be enabled with the new edid property. The patch also adds xres and yres properties to specify the video mode you want the guest use. Works only with edid enabled and updated guest driver. The mmio bar of the stdvga has some unused address space at the start. It was reserved just in case it'll be needed for virtio, but it turned out to not be needed for that. So let's use that region to place the EDID data block there. Signed-off-by: Gerd Hoffmann Message-id: 20180925075646.25114-6-kraxel@redhat.com --- docs/specs/standard-vga.txt | 2 +- hw/display/vga_int.h | 2 +- hw/display/vga-pci.c | 35 +++++++++++++++++++++++++++++++---- hw/display/virtio-vga.c | 2 +- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/docs/specs/standard-vga.txt b/docs/specs/standard-vga.txt index 19d2a74509..18f75f1b30 100644 --- a/docs/specs/standard-vga.txt +++ b/docs/specs/standard-vga.txt @@ -61,7 +61,7 @@ MMIO area spec =20 Likewise applies to the pci variant only for obvious reasons. =20 -0000 - 03ff : reserved, for possible virtio extension. +0000 - 03ff : edid data blob. 0400 - 041f : vga ioports (0x3c0 -> 0x3df), remapped 1:1. word access is supported, bytes are written in little endia order (aka index port first), diff --git a/hw/display/vga_int.h b/hw/display/vga_int.h index 339661bc01..6e4fa48a79 100644 --- a/hw/display/vga_int.h +++ b/hw/display/vga_int.h @@ -197,6 +197,6 @@ void pci_std_vga_mmio_region_init(VGACommonState *s, Object *owner, MemoryRegion *parent, MemoryRegion *subs, - bool qext); + bool qext, bool edid); =20 #endif diff --git a/hw/display/vga-pci.c b/hw/display/vga-pci.c index e9e62eac70..24ca1b3e1f 100644 --- a/hw/display/vga-pci.c +++ b/hw/display/vga-pci.c @@ -30,18 +30,22 @@ #include "ui/pixel_ops.h" #include "qemu/timer.h" #include "hw/loader.h" +#include "hw/display/edid.h" =20 enum vga_pci_flags { PCI_VGA_FLAG_ENABLE_MMIO =3D 1, PCI_VGA_FLAG_ENABLE_QEXT =3D 2, + PCI_VGA_FLAG_ENABLE_EDID =3D 3, }; =20 typedef struct PCIVGAState { PCIDevice dev; VGACommonState vga; uint32_t flags; + qemu_edid_info edid_info; MemoryRegion mmio; - MemoryRegion mrs[3]; + MemoryRegion mrs[4]; + uint8_t edid[256]; } PCIVGAState; =20 #define TYPE_PCI_VGA "pci-vga" @@ -195,8 +199,10 @@ void pci_std_vga_mmio_region_init(VGACommonState *s, Object *owner, MemoryRegion *parent, MemoryRegion *subs, - bool qext) + bool qext, bool edid) { + PCIVGAState *d =3D container_of(s, PCIVGAState, vga); + memory_region_init_io(&subs[0], owner, &pci_vga_ioport_ops, s, "vga ioports remapped", PCI_VGA_IOPORT_SIZE); memory_region_add_subregion(parent, PCI_VGA_IOPORT_OFFSET, @@ -213,6 +219,12 @@ void pci_std_vga_mmio_region_init(VGACommonState *s, memory_region_add_subregion(parent, PCI_VGA_QEXT_OFFSET, &subs[2]); } + + if (edid) { + qemu_edid_generate(d->edid, sizeof(d->edid), &d->edid_info); + qemu_edid_region_io(&subs[3], owner, d->edid, sizeof(d->edid)); + memory_region_add_subregion(parent, 0, &subs[3]); + } } =20 static void pci_std_vga_realize(PCIDevice *dev, Error **errp) @@ -220,6 +232,7 @@ static void pci_std_vga_realize(PCIDevice *dev, Error *= *errp) PCIVGAState *d =3D PCI_VGA(dev); VGACommonState *s =3D &d->vga; bool qext =3D false; + bool edid =3D false; =20 /* vga + console init */ vga_common_init(s, OBJECT(dev)); @@ -240,7 +253,11 @@ static void pci_std_vga_realize(PCIDevice *dev, Error = **errp) qext =3D true; pci_set_byte(&d->dev.config[PCI_REVISION_ID], 2); } - pci_std_vga_mmio_region_init(s, OBJECT(dev), &d->mmio, d->mrs, qex= t); + if (d->flags & (1 << PCI_VGA_FLAG_ENABLE_EDID)) { + edid =3D true; + } + pci_std_vga_mmio_region_init(s, OBJECT(dev), &d->mmio, d->mrs, + qext, edid); =20 pci_register_bar(&d->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mm= io); } @@ -263,6 +280,7 @@ static void pci_secondary_vga_realize(PCIDevice *dev, E= rror **errp) PCIVGAState *d =3D PCI_VGA(dev); VGACommonState *s =3D &d->vga; bool qext =3D false; + bool edid =3D false; =20 /* vga + console init */ vga_common_init(s, OBJECT(dev)); @@ -276,7 +294,10 @@ static void pci_secondary_vga_realize(PCIDevice *dev, = Error **errp) qext =3D true; pci_set_byte(&d->dev.config[PCI_REVISION_ID], 2); } - pci_std_vga_mmio_region_init(s, OBJECT(dev), &d->mmio, d->mrs, qext); + if (d->flags & (1 << PCI_VGA_FLAG_ENABLE_EDID)) { + edid =3D true; + } + pci_std_vga_mmio_region_init(s, OBJECT(dev), &d->mmio, d->mrs, qext, e= did); =20 pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram); pci_register_bar(&d->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio); @@ -308,6 +329,9 @@ static Property vga_pci_properties[] =3D { DEFINE_PROP_BIT("mmio", PCIVGAState, flags, PCI_VGA_FLAG_ENABLE_MMIO, = true), DEFINE_PROP_BIT("qemu-extended-regs", PCIVGAState, flags, PCI_VGA_FLAG_ENABLE_QEXT, true), + DEFINE_PROP_BIT("edid", + PCIVGAState, flags, PCI_VGA_FLAG_ENABLE_EDID, false), + DEFINE_EDID_PROPERTIES(PCIVGAState, edid_info), DEFINE_PROP_BOOL("global-vmstate", PCIVGAState, vga.global_vmstate, fa= lse), DEFINE_PROP_END_OF_LIST(), }; @@ -316,6 +340,9 @@ static Property secondary_pci_properties[] =3D { DEFINE_PROP_UINT32("vgamem_mb", PCIVGAState, vga.vram_size_mb, 16), DEFINE_PROP_BIT("qemu-extended-regs", PCIVGAState, flags, PCI_VGA_FLAG_ENABLE_QEXT, true), + DEFINE_PROP_BIT("edid", + PCIVGAState, flags, PCI_VGA_FLAG_ENABLE_EDID, false), + DEFINE_EDID_PROPERTIES(PCIVGAState, edid_info), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c index 1e601c1a3b..ab2e369b28 100644 --- a/hw/display/virtio-vga.c +++ b/hw/display/virtio-vga.c @@ -153,7 +153,7 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev= , Error **errp) =20 /* add stdvga mmio regions */ pci_std_vga_mmio_region_init(vga, OBJECT(vvga), &vpci_dev->modern_bar, - vvga->vga_mrs, true); + vvga->vga_mrs, true, false); =20 vga->con =3D g->scanout[0].con; graphic_console_set_hwops(vga->con, &virtio_vga_ops, vvga); --=20 2.9.3 From nobody Mon Apr 29 15:19:25 2024 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538032773671218.24314746552318; Thu, 27 Sep 2018 00:19:33 -0700 (PDT) Received: from localhost ([::1]:34079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QaC-00059w-I7 for importer@patchew.org; Thu, 27 Sep 2018 03:19:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QTw-0007To-NE for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5QTt-0004Ml-9L for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5QTs-0004Kt-VY for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:01 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB6D130820DD for ; Thu, 27 Sep 2018 07:12:54 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F678600CC; Thu, 27 Sep 2018 07:12:54 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A53353EC31; Thu, 27 Sep 2018 09:12:47 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 27 Sep 2018 09:12:46 +0200 Message-Id: <20180927071247.25725-7-kraxel@redhat.com> In-Reply-To: <20180927071247.25725-1-kraxel@redhat.com> References: <20180927071247.25725-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 27 Sep 2018 07:12:54 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/7] qxl: use guest_monitor_config for local renderer. 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 , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When processing monitor config from guest store head0 width and height for single-head configurations. Use these when creating the DisplaySurface in the local renderer. This fixes a rendering issue with wayland. Wayland rounds up the framebuffer width and height to a multiple of 64, so with odd resolutions (800x600 for example) the framebuffer is larger than the actual screen. The monitor config has the actual screen size though. This fixes guest display for anything using the local renderer (non-spice UI, screendump monitor command). Signed-off-by: Gerd Hoffmann Reviewed-by: Marc-Andr=C3=A9 Lureau Message-id: 20180919103057.9666-1-kraxel@redhat.com --- hw/display/qxl.h | 2 ++ hw/display/qxl-render.c | 18 ++++++++++-------- hw/display/qxl.c | 12 ++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/hw/display/qxl.h b/hw/display/qxl.h index 6eacba080d..dd9c0522b7 100644 --- a/hw/display/qxl.h +++ b/hw/display/qxl.h @@ -78,6 +78,8 @@ typedef struct PCIQXLDevice { QXLPHYSICAL guest_cursor; =20 QXLPHYSICAL guest_monitors_config; + uint32_t guest_head0_width; + uint32_t guest_head0_height; =20 QemuMutex track_lock; =20 diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c index c62b9a5e75..6debe8fc11 100644 --- a/hw/display/qxl-render.c +++ b/hw/display/qxl-render.c @@ -98,6 +98,8 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice = *qxl) { VGACommonState *vga =3D &qxl->vga; DisplaySurface *surface; + int width =3D qxl->guest_head0_width ?: qxl->guest_primary.surface.wid= th; + int height =3D qxl->guest_head0_height ?: qxl->guest_primary.surface.h= eight; int i; =20 if (qxl->guest_primary.resized) { @@ -111,8 +113,8 @@ static void qxl_render_update_area_unlocked(PCIQXLDevic= e *qxl) qxl_set_rect_to_surface(qxl, &qxl->dirty[0]); qxl->num_dirty_rects =3D 1; trace_qxl_render_guest_primary_resized( - qxl->guest_primary.surface.width, - qxl->guest_primary.surface.height, + width, + height, qxl->guest_primary.qxl_stride, qxl->guest_primary.bytes_pp, qxl->guest_primary.bits_pp); @@ -120,15 +122,15 @@ static void qxl_render_update_area_unlocked(PCIQXLDev= ice *qxl) pixman_format_code_t format =3D qemu_default_pixman_format(qxl->guest_primary.bits_pp, tru= e); surface =3D qemu_create_displaysurface_from - (qxl->guest_primary.surface.width, - qxl->guest_primary.surface.height, + (width, + height, format, qxl->guest_primary.abs_stride, qxl->guest_primary.data); } else { surface =3D qemu_create_displaysurface - (qxl->guest_primary.surface.width, - qxl->guest_primary.surface.height); + (width, + height); } dpy_gfx_replace_surface(vga->con, surface); } @@ -144,8 +146,8 @@ static void qxl_render_update_area_unlocked(PCIQXLDevic= e *qxl) qxl->dirty[i].top < 0 || qxl->dirty[i].left > qxl->dirty[i].right || qxl->dirty[i].top > qxl->dirty[i].bottom || - qxl->dirty[i].right > qxl->guest_primary.surface.width || - qxl->dirty[i].bottom > qxl->guest_primary.surface.height) { + qxl->dirty[i].right > width || + qxl->dirty[i].bottom > height) { continue; } qxl_blit(qxl, qxl->dirty+i); diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 8e9135d9c6..747986478f 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -259,6 +259,8 @@ static void qxl_spice_destroy_surfaces(PCIQXLDevice *qx= l, qxl_async_io async) =20 static void qxl_spice_monitors_config_async(PCIQXLDevice *qxl, int replay) { + QXLMonitorsConfig *cfg; + trace_qxl_spice_monitors_config(qxl->id); if (replay) { /* @@ -286,6 +288,16 @@ static void qxl_spice_monitors_config_async(PCIQXLDevi= ce *qxl, int replay) (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO, QXL_IO_MONITORS_CONFIG_ASYNC)); } + + cfg =3D qxl_phys2virt(qxl, qxl->guest_monitors_config, MEMSLOT_GROUP_G= UEST); + if (cfg->count =3D=3D 1) { + qxl->guest_primary.resized =3D 1; + qxl->guest_head0_width =3D cfg->heads[0].width; + qxl->guest_head0_height =3D cfg->heads[0].height; + } else { + qxl->guest_head0_width =3D 0; + qxl->guest_head0_height =3D 0; + } } =20 void qxl_spice_reset_image_cache(PCIQXLDevice *qxl) --=20 2.9.3 From nobody Mon Apr 29 15:19:25 2024 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538032673636585.5220818616381; Thu, 27 Sep 2018 00:17:53 -0700 (PDT) Received: from localhost ([::1]:34068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QYa-0003Mp-C4 for importer@patchew.org; Thu, 27 Sep 2018 03:17:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5QTv-0007Tf-V5 for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5QTt-0004NE-MZ for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5QTt-0004M9-A1 for qemu-devel@nongnu.org; Thu, 27 Sep 2018 03:13:01 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCD7830820D1; Thu, 27 Sep 2018 07:12:59 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73C0C106A792; Thu, 27 Sep 2018 07:12:55 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id AEE593F10D; Thu, 27 Sep 2018 09:12:47 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 27 Sep 2018 09:12:47 +0200 Message-Id: <20180927071247.25725-8-kraxel@redhat.com> In-Reply-To: <20180927071247.25725-1-kraxel@redhat.com> References: <20180927071247.25725-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 27 Sep 2018 07:12:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/7] 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: Peter Wu , Gerd Hoffmann , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Wu 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 Message-id: 20180903145447.17142-1-peter@lekensteyn.nl [ kraxel: minor codestyle fix ] Signed-off-by: Gerd Hoffmann --- hw/display/qxl-render.c | 16 ++++++++++++++++ ui/cursor.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c index 6debe8fc11..14ad2b352d 100644 --- a/hw/display/qxl-render.c +++ b/hw/display/qxl-render.c @@ -236,12 +236,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..26ce69fe5e 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; =20 + /* + * 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.9.3