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 8/9] ui/gtk-gl-area: Render guest content with padding in fixed-scale mode
Date: Tue, 13 May 2025 10:28:14 +0800	[thread overview]
Message-ID: <ffa687c30c11429767d48c9d1358c729d1e49e8f.camel@gmail.com> (raw)
In-Reply-To: <PH8PR11MB6879607C14D7E5BB7FCDAAD1FA96A@PH8PR11MB6879.namprd11.prod.outlook.com>

Hi,

On Tue, 2025-05-13 at 00:37 +0000, Kim, Dongwon wrote:
> Hi,
> 
> > Subject: [PATCH 8/9] ui/gtk-gl-area: Render guest content with
> > padding in
> > fixed-scale mode
> > 
> > In fixed-scale mode (zoom-to-fit=false), we expect that scale
> > should not
> > change, meaning that if window size is larger than guest surface,
> > padding is
> 
> # @zoom-to-fit: Zoom guest display to fit into the host window.  When
> #     turned off the host window will be resized instead.  In case
> the
> #     display device can notify the guest on window resizes
> #     (virtio-gpu) this will default to "on", assuming the guest will
> #     resize the display to match the window size then.  Otherwise it
> #     defaults to "off".  (Since 3.1)
> 
> Current definition says the host window should be resized to fit the
> size of the guest surface instead. Wouldn't padding accommodate this?
> 

Yeah, window will be resized to fit the size of guest surface in fixed-
scale mode. However, users are still allowed to resize the window to a
larger size and this is case where padding is required, otherwise the
fixed-scale assumption is broken. In fact, gl=off mode employs padding
to preserve scale already but gl=on mode doesn't follow this behavior,
which, IMO, is a defect that this patch is trying to correct.

Best regards,
Weifeng

> > supposed to be added to preserve the scale. However, in OpenGL mode
> > (gl=on), guest surface is always painted to the whole canvas
> > without any
> > padding. This change tries to fix this bug by adding appropriate
> > padding
> > when drawing surfaces.
> > 
> > Signed-off-by: Weifeng Liu <weifeng.liu.z@gmail.com>
> > ---
> >  ui/gtk-gl-area.c | 33 ++++++++++++++++++++++++++++++++-
> >  1 file changed, 32 insertions(+), 1 deletion(-)
> > 
> > diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index
> > db93cd6204..8151cc413c
> > 100644
> > --- a/ui/gtk-gl-area.c
> > +++ b/ui/gtk-gl-area.c
> > @@ -44,7 +44,9 @@ void gd_gl_area_draw(VirtualConsole *vc)  #endif
> >      int pw, ph, gs, y1, y2;
> >      int ww, wh;
> > +    int ww_surface, wh_surface;
> >      int fbw, fbh;
> > +    int wx_offset, wy_offset;
> > 
> >      if (!vc->gfx.gls) {
> >          return;
> > @@ -61,6 +63,17 @@ void gd_gl_area_draw(VirtualConsole *vc)
> > 
> >      gd_update_scale(vc, ww, wh, fbw, fbh);
> > 
> > +    ww_surface = fbw * vc->gfx.scale_x;
> > +    wh_surface = fbh * vc->gfx.scale_y;
> > +
> > +    wx_offset = wy_offset = 0;
> > +    if (ww > ww_surface) {
> > +        wx_offset = (ww - ww_surface) / 2;
> > +    }
> > +    if (wh > wh_surface) {
> > +        wy_offset = (wh - wh_surface) / 2;
> > +    }
> > +
> >      if (vc->gfx.scanout_mode) {
> >          if (!vc->gfx.guest_fb.framebuffer) {
> >              return;
> > @@ -79,11 +92,29 @@ void gd_gl_area_draw(VirtualConsole *vc)
> >          glBindFramebuffer(GL_READ_FRAMEBUFFER, vc-
> > > gfx.guest_fb.framebuffer);
> >          /* GtkGLArea sets GL_DRAW_FRAMEBUFFER for us */
> > 
> > +        if (wx_offset > 0) {
> > +            glEnable(GL_SCISSOR_TEST);
> > +            glScissor(0, 0, wx_offset * gs, wh * gs);
> > +            glClear(GL_COLOR_BUFFER_BIT);
> > +            glScissor((ww - wx_offset) * gs, 0, wx_offset * gs, wh
> > * gs);
> > +            glClear(GL_COLOR_BUFFER_BIT);
> > +            glDisable(GL_SCISSOR_TEST);
> > +        }
> > +        if (wy_offset > 0) {
> > +            glEnable(GL_SCISSOR_TEST);
> > +            glScissor(0, 0, ww * gs, wy_offset * gs);
> > +            glClear(GL_COLOR_BUFFER_BIT);
> > +            glScissor(0, (wh - wy_offset) * gs, ww * gs, wy_offset
> > * gs);
> > +            glClear(GL_COLOR_BUFFER_BIT);
> > +            glDisable(GL_SCISSOR_TEST);
> > +        }
> > +
> >          glViewport(0, 0, pw, ph);
> >          y1 = vc->gfx.y0_top ? 0 : vc->gfx.h;
> >          y2 = vc->gfx.y0_top ? vc->gfx.h : 0;
> >          glBlitFramebuffer(0, y1, vc->gfx.w, y2,
> > -                          0, 0, pw, ph,
> > +                          wx_offset * gs, wy_offset * gs,
> > +                          (ww - wx_offset) * gs, (wh - wy_offset)
> > * gs,
> >                            GL_COLOR_BUFFER_BIT, GL_NEAREST); 
> > #ifdef CONFIG_GBM
> >          if (dmabuf) {
> > --
> > 2.49.0
> > 
> 
> Thanks

  reply	other threads:[~2025-05-13  2:29 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
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 [this message]
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=ffa687c30c11429767d48c9d1358c729d1e49e8f.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.