Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mzaBF-0002KZ-UI for mharc-qemu-trivial@gnu.org; Tue, 21 Dec 2021 03:07:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzaBD-0002G7-Ro; Tue, 21 Dec 2021 03:07:27 -0500 Received: from [2607:f8b0:4864:20::735] (port=35675 helo=mail-qk1-x735.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzaBB-0000wM-Rz; Tue, 21 Dec 2021 03:07:27 -0500 Received: by mail-qk1-x735.google.com with SMTP id 131so568501qkk.2; Tue, 21 Dec 2021 00:07:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:cc:from:in-reply-to; bh=2jPXSqaFwzJUBSSA0pQONTemy4xZ9SutK5ZkL12xfXg=; b=J0XTpYddtsP7Ool+XLUhZBQtz3SnMU/5+Gm5vFi5KL2Tzq7bpu3brjVOj/eufYIsEi MzOdBxkJJ4oxN2Akd/d9jDAaW3iNdkw2Y5Gv0m2CJ781PgOngZHfVOK7Ga8ecCDpx9vR lvaZNmyFzBV5bo1okoOeCqBRXuj7GOtdVJ/rbJrJyjT10YxWYBU1vbX05FKtF3at62ru BDaCV2bFgZa2iUaSkZjifVTz3lI4/N0Gqr6gOjpD3+Q/wQKE/fAdV7F48nx8setj560v 5Fac3J78hPRaUeyRKVZwU5Jp2l8J2ReTF1rC02LysxiKqHgHHp7QXk1i7HpcimvtyXKb MdbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:cc:from:in-reply-to; bh=2jPXSqaFwzJUBSSA0pQONTemy4xZ9SutK5ZkL12xfXg=; b=uSbbgXA+2LLYBoEctYFUYcG79+QrCD0ppdpxv6bMHK006UxZtFB+6rI/qtZo/PzPtU mIZf3fWiM5UBH/Gs84BjaodxjKmdm+6aUMfb/aOR/u8nujYTofPJL97ZkRguF4jf8aTJ uT39ldSWOcnIsrIZHiVHXeyOYtaZCSxfYqHBOJeSodbmckVWgADB2e7U3N5HgNRr95gK WhrKt/V2Ybxy44tbqXVkqAGZq2Y5gcdOzPVvz3V6HAHQQBTGGY/6Fc8nS7v8the2gwEd YYA9EJp7kdlb7uYUu+R9enh2F9opTOvYPZ7J1Ugiv/mdHG5zIyxQcP0913GdEvaQpm3x paQQ== X-Gm-Message-State: AOAM531mQ/OtfsmbByOOcQzH4u5fOmGc8+QCNuPt2ox9WwLrIA2R1KQ2 Jz/8LaOq9Ut3U3WN8PEs4xiKAXhXDuhTPw== X-Google-Smtp-Source: ABdhPJznvJlY7Tcank6+/Z627s2jkcu+NGMmzoq0VxNUQjhDdhs3/zIc8TGZzN1RdZL3Wc71rrSWqA== X-Received: by 2002:a37:c94:: with SMTP id 142mr1192346qkm.470.1640074044214; Tue, 21 Dec 2021 00:07:24 -0800 (PST) Received: from [192.168.1.10] (cpebc4dfb42ca53-cmbc4dfb42ca50.cpe.net.cable.rogers.com. [99.251.122.96]) by smtp.gmail.com with ESMTPSA id o10sm16943971qtx.33.2021.12.21.00.07.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Dec 2021 00:07:23 -0800 (PST) Content-Type: multipart/alternative; boundary="------------LkG0sPvLTikHrcoEDTtiRzqQ" Message-ID: <3fc718a1-5e5d-ab97-9300-2e912fcf14db@gmail.com> Date: Tue, 21 Dec 2021 03:07:22 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window Content-Language: en-US To: =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= References: <20211219023006.124530-1-orzechowski.alexander@gmail.com> <20211219023006.124530-5-orzechowski.alexander@gmail.com> Cc: QEMU , qemu trivial From: Alexander Orzechowski In-Reply-To: X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::735 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=orzechowski.alexander@gmail.com; helo=mail-qk1-x735.google.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, NICE_REPLY_A=-2.012, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-trivial@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Dec 2021 08:07:28 -0000 This is a multi-part message in MIME format. --------------LkG0sPvLTikHrcoEDTtiRzqQ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/21/21 02:48, Marc-André Lureau wrote: > Hi > > On Sun, Dec 19, 2021 at 6:32 AM Alexander Orzechowski > wrote: > > gtk/gl was incorrectly always rendering as if the 'Zoom to Fit' was > always checked even if it wasn't. This is now using logic closer > to what is being used for the existing cairo code paths. > > Signed-off-by: Alexander Orzechowski > > > This doesn't work as expected, the display is not being centered > correctly. > > --- >  ui/gtk-gl-area.c | 34 +++++++++++++++++++++++++++++----- >  1 file changed, 29 insertions(+), 5 deletions(-) > > diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c > index 01e4e74ee3..ea72f1817b 100644 > --- a/ui/gtk-gl-area.c > +++ b/ui/gtk-gl-area.c > @@ -41,16 +41,40 @@ void gd_gl_area_draw(VirtualConsole *vc) >  #ifdef CONFIG_GBM >      QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf; >  #endif > +    GtkDisplayState *s = vc->s; >      int ww, wh, ws, y1, y2; > +    int mx, my; > +    int fbh, fbw; > >      if (!vc->gfx.gls) { >          return; >      } > >  gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); > + > +    fbw = surface_width(vc->gfx.ds); > +    fbh = surface_height(vc->gfx.ds); > + >      ws = > gdk_window_get_scale_factor(gtk_widget_get_window(vc->gfx.drawing_area)); > -    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area) * ws; > -    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area) * ws; > +    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area); > +    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area); > + > +    if (s->full_screen) { > +        vc->gfx.scale_x = (double)ww / fbw; > +        vc->gfx.scale_y = (double)wh / fbh; > +    } else if (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); > +    } > + > +    fbw *= vc->gfx.scale_x * ws; > +    fbh *= vc->gfx.scale_y * ws; > +    mx = (ww * ws - fbw) / 2; > +    my = (wh * ws - fbh) / 2; > >      if (vc->gfx.scanout_mode) { >          if (!vc->gfx.guest_fb.framebuffer) { > @@ -70,11 +94,11 @@ void gd_gl_area_draw(VirtualConsole *vc) >          glBindFramebuffer(GL_READ_FRAMEBUFFER, > vc->gfx.guest_fb.framebuffer); >          /* GtkGLArea sets GL_DRAW_FRAMEBUFFER for us */ > > -        glViewport(0, 0, ww, wh); > +        glViewport(mx, my, fbw, fbh); >          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, ww, wh, > +                          mx, my, fbw, fbh, >                            GL_COLOR_BUFFER_BIT, GL_NEAREST); >  #ifdef CONFIG_GBM >          if (dmabuf) { > @@ -98,7 +122,7 @@ void gd_gl_area_draw(VirtualConsole *vc) >          } >  gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); > > -        surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, ww, wh); > +        glViewport(mx, my, fbw, fbh); >          surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds); >      } > > -- > 2.34.1 > > > > > -- > Marc-André Lureau It seems glBlitFramebuffer takes two coordinates instead of a width and height. I have corrected this locally and I will have v2 up tomorrow. Thanks for the thorough testing! -- Alexander Orzechowski --------------LkG0sPvLTikHrcoEDTtiRzqQ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

On 12/21/21 02:48, Marc-André Lureau wrote:

Hi

On Sun, Dec 19, 2021 at 6:32 AM Alexander Orzechowski <orzechowski.alexander@gmail.com> wrote:
gtk/gl was incorrectly always rendering as if the 'Zoom to Fit' was
always checked even if it wasn't. This is now using logic closer
to what is being used for the existing cairo code paths.

Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>

This doesn't work as expected, the display is not being centered correctly.

---
 ui/gtk-gl-area.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index 01e4e74ee3..ea72f1817b 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -41,16 +41,40 @@ void gd_gl_area_draw(VirtualConsole *vc)
 #ifdef CONFIG_GBM
     QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
 #endif
+    GtkDisplayState *s = vc->s;
     int ww, wh, ws, y1, y2;
+    int mx, my;
+    int fbh, fbw;

     if (!vc->gfx.gls) {
         return;
     }

     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
+
+    fbw = surface_width(vc->gfx.ds);
+    fbh = surface_height(vc->gfx.ds);
+
     ws = gdk_window_get_scale_factor(gtk_widget_get_window(vc->gfx.drawing_area));
-    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area) * ws;
-    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area) * ws;
+    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
+    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
+
+    if (s->full_screen) {
+        vc->gfx.scale_x = (double)ww / fbw;
+        vc->gfx.scale_y = (double)wh / fbh;
+    } else if (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);
+    }
+
+    fbw *= vc->gfx.scale_x * ws;
+    fbh *= vc->gfx.scale_y * ws;
+    mx = (ww * ws - fbw) / 2;
+    my = (wh * ws - fbh) / 2;

     if (vc->gfx.scanout_mode) {
         if (!vc->gfx.guest_fb.framebuffer) {
@@ -70,11 +94,11 @@ void gd_gl_area_draw(VirtualConsole *vc)
         glBindFramebuffer(GL_READ_FRAMEBUFFER, vc->gfx.guest_fb.framebuffer);
         /* GtkGLArea sets GL_DRAW_FRAMEBUFFER for us */

-        glViewport(0, 0, ww, wh);
+        glViewport(mx, my, fbw, fbh);
         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, ww, wh,
+                          mx, my, fbw, fbh,
                           GL_COLOR_BUFFER_BIT, GL_NEAREST);
 #ifdef CONFIG_GBM
         if (dmabuf) {
@@ -98,7 +122,7 @@ void gd_gl_area_draw(VirtualConsole *vc)
         }
         gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));

-        surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, ww, wh);
+        glViewport(mx, my, fbw, fbh);
         surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds);
     }

--
2.34.1




--
Marc-André Lureau

It seems glBlitFramebuffer takes two coordinates instead of a width and height. I have corrected this locally and I will have v2 up tomorrow. Thanks for the thorough testing!

--

Alexander Orzechowski

--------------LkG0sPvLTikHrcoEDTtiRzqQ--