All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	qemu-ppc@nongnu.org, "Gerd Hoffmann" <kraxel@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [PULL 3/9] edid: use physical dimensions if available
Date: Tue, 29 Sep 2020 11:57:11 +0200	[thread overview]
Message-ID: <20200929095717.26745-4-kraxel@redhat.com> (raw)
In-Reply-To: <20200929095717.26745-1-kraxel@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Replace dpi with width_mm/height_mm in qemu_edid_info.

Use it when set (non-zero) to compute the DPI and generate the EDID.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-id: 20200927145751.365446-3-marcandre.lureau@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/hw/display/edid.h  |  5 ++++-
 hw/display/edid-generate.c | 36 +++++++++++++++++++++++++-----------
 qemu-edid.c                | 11 +++++++++--
 3 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/include/hw/display/edid.h b/include/hw/display/edid.h
index 5b1de57f24f9..1f8fc9b37500 100644
--- a/include/hw/display/edid.h
+++ b/include/hw/display/edid.h
@@ -5,7 +5,8 @@ typedef struct qemu_edid_info {
     const char *vendor; /* http://www.uefi.org/pnp_id_list */
     const char *name;
     const char *serial;
-    uint32_t    dpi;
+    uint16_t    width_mm;
+    uint16_t    height_mm;
     uint32_t    prefx;
     uint32_t    prefy;
     uint32_t    maxx;
@@ -18,6 +19,8 @@ size_t qemu_edid_size(uint8_t *edid);
 void qemu_edid_region_io(MemoryRegion *region, Object *owner,
                          uint8_t *edid, size_t size);
 
+uint32_t qemu_edid_dpi_to_mm(uint32_t dpi, uint32_t res);
+
 #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),    \
diff --git a/hw/display/edid-generate.c b/hw/display/edid-generate.c
index 618c74e1df39..1665b7cbb29a 100644
--- a/hw/display/edid-generate.c
+++ b/hw/display/edid-generate.c
@@ -205,12 +205,8 @@ static void edid_desc_dummy(uint8_t *desc)
 
 static void edid_desc_timing(uint8_t *desc,
                              uint32_t xres, uint32_t yres,
-                             uint32_t dpi)
+                             uint32_t xmm, uint32_t ymm)
 {
-    /* physical display size */
-    uint32_t xmm = xres * 254 / 10 / dpi;
-    uint32_t ymm = yres * 254 / 10 / dpi;
-
     /* pull some realistic looking timings out of thin air */
     uint32_t xfront = xres * 25 / 100;
     uint32_t xsync  = xres *  3 / 100;
@@ -290,12 +286,24 @@ static void edid_colorspace(uint8_t *edid,
     edid[34] = white_y >> 2;
 }
 
+static uint32_t qemu_edid_dpi_from_mm(uint32_t mm, uint32_t res)
+{
+    return res * 254 / 10 / mm;
+}
+
+uint32_t qemu_edid_dpi_to_mm(uint32_t dpi, uint32_t res)
+{
+    return res * 254 / 10 / dpi;
+}
+
 void qemu_edid_generate(uint8_t *edid, size_t size,
                         qemu_edid_info *info)
 {
     uint32_t desc = 54;
     uint8_t *xtra3 = NULL;
     uint8_t *dta = NULL;
+    uint32_t width_mm, height_mm;
+    uint32_t dpi = 100; /* if no width_mm/height_mm */
 
     /* =============== set defaults  =============== */
 
@@ -305,15 +313,20 @@ void qemu_edid_generate(uint8_t *edid, size_t size,
     if (!info->name) {
         info->name = "QEMU Monitor";
     }
-    if (!info->dpi) {
-        info->dpi = 100;
-    }
     if (!info->prefx) {
         info->prefx = 1024;
     }
     if (!info->prefy) {
         info->prefy = 768;
     }
+    if (info->width_mm && info->height_mm) {
+        width_mm = info->width_mm;
+        height_mm = info->height_mm;
+        dpi = qemu_edid_dpi_from_mm(width_mm, info->prefx);
+    } else {
+        width_mm = qemu_edid_dpi_to_mm(dpi, info->prefx);
+        height_mm = qemu_edid_dpi_to_mm(dpi, info->prefy);
+    }
 
     /* =============== extensions  =============== */
 
@@ -360,8 +373,8 @@ void qemu_edid_generate(uint8_t *edid, size_t size,
     edid[20] = 0xa5;
 
     /* screen size: undefined */
-    edid[21] = info->prefx * 254 / 100 / info->dpi;
-    edid[22] = info->prefy * 254 / 100 / info->dpi;
+    edid[21] = width_mm / 10;
+    edid[22] = height_mm / 10;
 
     /* display gamma: 2.2 */
     edid[23] = 220 - 100;
@@ -387,7 +400,8 @@ void qemu_edid_generate(uint8_t *edid, size_t size,
 
     /* =============== descriptor blocks =============== */
 
-    edid_desc_timing(edid + desc, info->prefx, info->prefy, info->dpi);
+    edid_desc_timing(edid + desc, info->prefx, info->prefy,
+                     width_mm, height_mm);
     desc += 18;
 
     edid_desc_ranges(edid + desc);
diff --git a/qemu-edid.c b/qemu-edid.c
index 46eef7049803..1db3372b982c 100644
--- a/qemu-edid.c
+++ b/qemu-edid.c
@@ -9,7 +9,10 @@
 #include "qemu/cutils.h"
 #include "hw/display/edid.h"
 
-static qemu_edid_info info;
+static qemu_edid_info info = (qemu_edid_info) {
+    .prefx = 1024,
+    .prefy = 768,
+};
 
 static void usage(FILE *out)
 {
@@ -39,6 +42,7 @@ int main(int argc, char *argv[])
 {
     FILE *outfile = NULL;
     uint8_t blob[256];
+    uint32_t dpi = 100;
     int rc;
 
     for (;;) {
@@ -83,7 +87,7 @@ int main(int argc, char *argv[])
             }
             break;
         case 'd':
-            if (qemu_strtoui(optarg, NULL, 10, &info.dpi) < 0) {
+            if (qemu_strtoui(optarg, NULL, 10, &dpi) < 0) {
                 fprintf(stderr, "not a number: %s\n", optarg);
                 exit(1);
             }
@@ -110,6 +114,9 @@ int main(int argc, char *argv[])
         outfile = stdout;
     }
 
+    info.width_mm = qemu_edid_dpi_to_mm(dpi, info.prefx);
+    info.height_mm = qemu_edid_dpi_to_mm(dpi, info.prefy);
+
     memset(blob, 0, sizeof(blob));
     qemu_edid_generate(blob, sizeof(blob), &info);
     fwrite(blob, sizeof(blob), 1, outfile);
-- 
2.27.0



  parent reply	other threads:[~2020-09-29 10:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29  9:57 [PULL 0/9] Vga 20200929 patches Gerd Hoffmann
2020-09-29  9:57 ` [PULL 1/9] virtio-gpu-3d: fix abnormal display after a warm reboot Gerd Hoffmann
2020-09-29  9:57 ` [PULL 2/9] edid: fix physical display size computation Gerd Hoffmann
2020-09-29  9:57 ` Gerd Hoffmann [this message]
2020-09-29  9:57 ` [PULL 4/9] ui: add getter for UIInfo Gerd Hoffmann
2020-09-29  9:57 ` [PULL 5/9] spice: remove the single monitor config logic Gerd Hoffmann
2020-09-29  9:57 ` [PULL 6/9] spice: get monitors physical dimension Gerd Hoffmann
2020-09-29  9:57 ` [PULL 7/9] virtio-gpu: set physical dimensions for EDID Gerd Hoffmann
2020-09-29  9:57 ` [PULL 8/9] virtio-vga: implement big-endian-framebuffer property Gerd Hoffmann
2020-09-29  9:57 ` [PULL 9/9] ppc/pseries: enable big-endian-framebuffer quirk for bochs-display and virtio-vga Gerd Hoffmann
2020-09-29 12:18 ` [PULL 0/9] Vga 20200929 patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200929095717.26745-4-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=marcandre.lureau@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.