From: Weifeng Liu <weifeng.liu.z@gmail.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@gmail.com>
Subject: Re: [PATCH 1/9] ui/gtk: Document scale and coordinate handling
Date: Wed, 14 May 2025 10:50:55 +0800 [thread overview]
Message-ID: <ce6e4a42353118fe41e59f2e6ef79d6df959692b.camel@gmail.com> (raw)
In-Reply-To: <hyeijrn3pxl5r5ij2zryiaar5xcqpj7oigpzwgdl3bl5wslddu@fdfgzn27uy52>
Hi Gerd,
On Mon, 2025-05-12 at 13:46 +0200, Gerd Hoffmann wrote:
> On Sun, May 11, 2025 at 03:33:11PM +0800, Weifeng Liu wrote:
> > 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>
> > ---
> > ui/gtk.c | 65
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 65 insertions(+)
> >
> > diff --git a/ui/gtk.c b/ui/gtk.c
> > index 982037b2c0..9f3171abc5 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
>
> Well. That is one possible approach (and this is what qemu is doing
> today, for historical reasons, because most code dates back to pre
> high-dpi days).
>
> A possible alternative would be to go for fbw * scale_x = pw, i.e.
> let
> the guest run in pixel coordinates instead of window coordinates.
> The
> guest would do the high-dpi scaling then. That requires setting
> physical display width and height in ui_info, so the guest can figure
> what the display resolution is and go into high-dpi mode if needed.
>
Thanks for your suggestion. Sounds like code could be simplified and be
much easier to understand in this way. I will investigate it on top of
this change.
Best regards,
Weifeng
> We probably also need a non-high-dpi compatibility mode for old
> guests.
> That mode would start with "zooming scale = global scale" instead of
> "zooming scale = 1", and the dpi calculation would have to consider
> that too.
>
> (maybe best done on top of this nice cleanup).
>
> take care,
> Gerd
next prev parent reply other threads:[~2025-05-14 2:51 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-11 7:33 [PATCH 0/9] ui: Improve scale handling Weifeng Liu
2025-05-11 7:33 ` [PATCH 1/9] ui/gtk: Document scale and coordinate handling Weifeng Liu
2025-05-12 11:46 ` Gerd Hoffmann
2025-05-14 2:50 ` Weifeng Liu [this message]
2025-05-14 11:50 ` BALATON Zoltan
2025-05-15 5:55 ` Weifeng Liu
2025-05-11 7:33 ` [PATCH 2/9] ui/gtk: Use consistent naming for variables in different coordinates Weifeng Liu
2025-05-11 7:33 ` [PATCH 3/9] gtk/ui: Introduce helper gd_update_scale Weifeng Liu
2025-05-13 1:26 ` Kim, Dongwon
2025-05-13 2:08 ` Weifeng Liu
2025-05-13 20:01 ` Kim, Dongwon
2025-05-14 2:12 ` Weifeng Liu
2025-05-11 7:33 ` [PATCH 4/9] ui/gtk: Update scales in fixed-scale mode when rendering GL area Weifeng Liu
2025-05-11 7:33 ` [PATCH 5/9] ui/sdl: Consider scaling in mouse event handling Weifeng Liu
2025-05-11 7:33 ` [PATCH 6/9] ui/gtk: Don't update scale in fixed scale mode in gtk-egl.c Weifeng Liu
2025-05-11 7:33 ` [PATCH 7/9] ui/gtk: Consider scaling when propagating ui info Weifeng Liu
2025-05-11 7:33 ` [PATCH 8/9] ui/gtk-gl-area: Render guest content with padding in fixed-scale mode Weifeng Liu
2025-05-13 0:37 ` Kim, Dongwon
2025-05-13 2:28 ` Weifeng Liu
2025-05-13 9:52 ` BALATON Zoltan
2025-05-13 12:44 ` Weifeng Liu
2025-05-13 13:42 ` BALATON Zoltan
2025-05-11 7:33 ` [PATCH 9/9] ui/gtk-egl: " Weifeng Liu
2025-05-12 11:49 ` [PATCH 0/9] ui: Improve scale handling Gerd Hoffmann
2025-05-29 7:23 ` Michael Tokarev
2025-05-30 6:39 ` Weifeng Liu
2025-05-30 10:44 ` Michael Tokarev
2025-05-30 10:56 ` Michael Tokarev
2025-06-01 8:23 ` Weifeng Liu
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=ce6e4a42353118fe41e59f2e6ef79d6df959692b.camel@gmail.com \
--to=weifeng.liu.z@gmail.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@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.