All of lore.kernel.org
 help / color / mirror / Atom feed
From: Weifeng Liu <weifeng.liu.z@gmail.com>
To: "Kim, Dongwon" <dongwon.kim@intel.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [PATCH 3/9] gtk/ui: Introduce helper gd_update_scale
Date: Tue, 13 May 2025 10:08:54 +0800	[thread overview]
Message-ID: <c70f48302d69f447e306ca2ced2abe9f3d1b7631.camel@gmail.com> (raw)
In-Reply-To: <PH8PR11MB6879A5858D3F4EA9F4EDB149FA96A@PH8PR11MB6879.namprd11.prod.outlook.com>

Hi Dongwon,

On Tue, 2025-05-13 at 01:26 +0000, Kim, Dongwon wrote:
> Hi,
> 
> > Subject: [PATCH 3/9] gtk/ui: Introduce helper gd_update_scale
> > 
> > The code snippet updating scale_x/scale_y is general and will be
> > used in next
> > patch. Make it a function.
> > 
> > Signed-off-by: Weifeng Liu <weifeng.liu.z@gmail.com>
> > ---
> >  include/ui/gtk.h |  2 ++
> >  ui/gtk.c         | 30 +++++++++++++++++++-----------
> >  2 files changed, 21 insertions(+), 11 deletions(-)
> > 
> > diff --git a/include/ui/gtk.h b/include/ui/gtk.h index
> > aa3d637029..d3944046db 100644
> > --- a/include/ui/gtk.h
> > +++ b/include/ui/gtk.h
> > @@ -224,4 +224,6 @@ int gd_gl_area_make_current(DisplayGLCtx *dgc,
> >  /* gtk-clipboard.c */
> >  void gd_clipboard_init(GtkDisplayState *gd);
> > 
> > +void gd_update_scale(VirtualConsole *vc, int ww, int wh, int fbw,
> > int
> > +fbh);
> > +
> >  #endif /* UI_GTK_H */
> > diff --git a/ui/gtk.c b/ui/gtk.c
> > index 8f5bb4b62e..47af49e387 100644
> > --- a/ui/gtk.c
> > +++ b/ui/gtk.c
> > @@ -801,6 +801,24 @@ void
> > gd_update_monitor_refresh_rate(VirtualConsole *vc, GtkWidget
> > *widget)
> > #endif  }
> > 
> > +void gd_update_scale(VirtualConsole *vc, int ww, int wh, int fbw,
> > int
> > +fbh) {
> > +    if (!vc) {
> > +        return;
> > +    }
> > +
> > +    if (vc->s->full_screen) {
> > +        vc->gfx.scale_x = (double)ww / fbw;
> > +        vc->gfx.scale_y = (double)wh / fbh;
> > +    } else if (vc->s->free_scale) {
> > +        double sx, sy;
> > +
> > +        sx = (double)ww / fbw;
> > +        sy = (double)wh / fbh;
> > +
> > +        vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
>  
> I assume you are trying to keep the w/h ratio same here in case free-
> scale == true.
> Why would we do that? We can easily stretch the host window to any
> direction then the scale-x and scale-y
> could be different any time.
> 
Currently, the code doesn’t clarify how we should handle aspect ratios.
However, I noticed that in the gd_draw_event function, when free-
scale=true, it preserves a fixed aspect ratio. I believe this is a
reasonable approach (in my humble opinion, it's unlikely that people
want to see distorted images), so I’ve decided to retain this behavior
for now and align other parts to follow the same logic, ensuring a
consistent experience for users.

Best regards,
Weifeng

> > +    }
> > +}
> >  /**
> >   * DOC: Coordinate handling.
> >   *
> > @@ -908,17 +926,7 @@ static gboolean gd_draw_event(GtkWidget
> > *widget,
> > cairo_t *cr, void *opaque)
> >      ww_widget =
> > gdk_window_get_width(gtk_widget_get_window(widget));
> >      wh_widget =
> > gdk_window_get_height(gtk_widget_get_window(widget));
> > 
> > -    if (s->full_screen) {
> > -        vc->gfx.scale_x = (double)ww_widget / fbw;
> > -        vc->gfx.scale_y = (double)wh_widget / fbh;
> > -    } else if (s->free_scale) {
> > -        double sx, sy;
> > -
> > -        sx = (double)ww_widget / fbw;
> > -        sy = (double)wh_widget / fbh;
> > -
> > -        vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
> > -    }
> > +    gd_update_scale(vc, ww_widget, wh_widget, fbw, fbh);
> > 
> >      ww_surface = fbw * vc->gfx.scale_x;
> >      wh_surface = fbh * vc->gfx.scale_y;
> > --
> > 2.49.0
> > 


  reply	other threads:[~2025-05-13  2:10 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
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 [this message]
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=c70f48302d69f447e306ca2ced2abe9f3d1b7631.camel@gmail.com \
    --to=weifeng.liu.z@gmail.com \
    --cc=dongwon.kim@intel.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.