[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-10.0.3 03/39] ui/gtk: Document scale and coordinate handling
From: |
Michael Tokarev |
Subject: |
[Stable-10.0.3 03/39] ui/gtk: Document scale and coordinate handling |
Date: |
Fri, 11 Jul 2025 11:15:59 +0300 |
From: Weifeng Liu <weifeng.liu.z@gmail.com>
The existence of multiple scaling factors forces us to deal with various
coordinate systems and this would be confusing. It would be beneficial
to define the concepts clearly and use consistent representation for
variables in different coordinates.
Signed-off-by: Weifeng Liu <weifeng.liu.z@gmail.com>
Message-ID: <20250511073337.876650-2-weifeng.liu.z@gmail.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
(cherry picked from commit 9498e2f7e1a247557cfa0f830a86c398a23c6809)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/ui/gtk.c b/ui/gtk.c
index 59bda83da6..582841e031 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -800,6 +800,71 @@ void gd_update_monitor_refresh_rate(VirtualConsole *vc,
GtkWidget *widget)
#endif
}
+/**
+ * DOC: Coordinate handling.
+ *
+ * We are coping with sizes and positions in various coordinates and the
+ * handling of these coordinates is somewhat confusing. It would benefit us
+ * all if we define these coordinates explicitly and clearly. Besides, it's
+ * also helpful to follow the same naming convention for variables
+ * representing values in different coordinates.
+ *
+ * I. Definitions
+ *
+ * - (guest) buffer coordinate: this is the coordinates that the guest will
+ * see. The x/y offsets and width/height specified in commands sent by
+ * guest is basically in buffer coordinate.
+ *
+ * - (host) pixel coordinate: this is the coordinate in pixel level on the
+ * host destop. A window/widget of width 300 in pixel coordinate means it
+ * occupies 300 pixels horizontally.
+ *
+ * - (host) logical window coordinate: the existence of global scaling
+ * factor in desktop level makes this kind of coordinate play a role. It
+ * always holds that (logical window size) * (global scale factor) =
+ * (pixel size).
+ *
+ * - global scale factor: this is specified in desktop level and is
+ * typically invariant during the life cycle of the process. Users with
+ * high-DPI monitors might set this scale, for example, to 2, in order to
+ * make the UI look larger.
+ *
+ * - zooming scale: this can be freely controlled by the QEMU user to zoom
+ * in/out the guest content.
+ *
+ * II. Representation
+ *
+ * We'd like to use consistent representation for variables in different
+ * coordinates:
+ * - buffer coordinate: prefix fb
+ * - pixel coordinate: prefix p
+ * - logical window coordinate: prefix w
+ *
+ * For scales:
+ * - global scale factor: prefix gs
+ * - zooming scale: prefix scale/s
+ *
+ * Example: fbw, pw, ww for width in different coordinates
+ *
+ * III. Equation
+ *
+ * - fbw * gs * scale_x = pw
+ * - pw = gs * ww
+ *
+ * Consequently we have
+ *
+ * - fbw * scale_x = ww
+ *
+ * Example: assuming we are running QEMU on a 3840x2160 screen and have set
+ * global scaling factor to 2, if the guest buffer size is 1920x1080 and the
+ * zooming scale is 0.5, then we have:
+ * - fbw = 1920, fbh = 1080
+ * - pw = 1920, ph = 1080
+ * - ww = 960, wh = 540
+ * A bonus of this configuration is that we can achieve pixel to pixel
+ * presentation of the guest content.
+ */
+
static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
{
VirtualConsole *vc = opaque;
--
2.47.2
- [Stable-10.0.3 00/39] Patch Round-up for stable 10.0.3, freeze on 2025-07-21, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 01/39] hw/misc/aspeed_hace: Ensure HASH_IRQ is always set to prevent firmware hang, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 02/39] hw/arm/aspeed_ast27x0: Fix RAM size detection failure on BE hosts, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 05/39] gtk/ui: Introduce helper gd_update_scale, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 04/39] ui/gtk: Use consistent naming for variables in different coordinates, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 03/39] ui/gtk: Document scale and coordinate handling,
Michael Tokarev <=
- [Stable-10.0.3 06/39] ui/gtk: Update scales in fixed-scale mode when rendering GL area, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 07/39] ui/sdl: Consider scaling in mouse event handling, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 08/39] ui/vnc.c: replace big endian flag with byte order value, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 09/39] ui/vnc: take account of client byte order in pixman format, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 10/39] ui/vnc: fix tight palette pixel encoding for 8/16-bpp formats, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 11/39] hw/arm: Add missing psci_conduit to NPCM8XX SoC boot info, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 13/39] hw/i386/pc_piix: Fix RTC ISA IRQ wiring of isapc machine, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 12/39] vhost: Don't set vring call if guest notifier is unused, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 15/39] hw/i386/amd_iommu: Fix xtsup when vcpus < 255, Michael Tokarev, 2025/07/11
- [Stable-10.0.3 16/39] audio: fix SIGSEGV in AUD_get_buffer_size_out(), Michael Tokarev, 2025/07/11