All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] UI fixups
@ 2021-12-19  2:30 Alexander Orzechowski
  2021-12-19  2:30 ` [PATCH 1/4] ui: Use allocated size instead of window size Alexander Orzechowski
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Alexander Orzechowski @ 2021-12-19  2:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gerd Hoffmann, Alexander Orzechowski

Some UI fixups including one revert.

I have some things that I want to have a discussion about. Fullscreen mode
will always distort the virtual console. Is this behavior we really want? If we
get rid of this, we can combine scale_x and scale_y into a single variable
and simplify things a little bit.

Also just from looking around a little bit in ui/gtk-egl.c the code
seems super broken regarding the virtual console rendering in the correct place.
I'm unable to test those code paths so I haven't touched it for now.

Alexander Orzechowski (4):
  ui: Use allocated size instead of window size
  ui: Remove unnecessary checks
  ui: Revert: "fix incorrect pointer position on highdpi with gtk"
  ui: Fix gtk/gl when the scaled virtual console does not fit the window

 ui/gtk-gl-area.c | 34 ++++++++++++++++++++++++-----
 ui/gtk.c         | 57 +++++++++++++++---------------------------------
 2 files changed, 46 insertions(+), 45 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] ui: Use allocated size instead of window size
  2021-12-19  2:30 [PATCH 0/4] UI fixups Alexander Orzechowski
@ 2021-12-19  2:30 ` Alexander Orzechowski
  2021-12-21  7:27   ` Marc-André Lureau
  2021-12-19  2:30 ` [PATCH 2/4] ui: Remove unnecessary checks Alexander Orzechowski
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Alexander Orzechowski @ 2021-12-19  2:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gerd Hoffmann, Alexander Orzechowski

In these cases, we only care about the size of the virtual console
itself. Previously, these calculations were made using the size of
the entire window, which would include the size of the virtual console
plus all the ui elements around it.

Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
---
 ui/gtk.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 428f02f2df..824334ff3d 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -340,8 +340,8 @@ static void gd_update_full_redraw(VirtualConsole *vc)
 {
     GtkWidget *area = vc->gfx.drawing_area;
     int ww, wh;
-    ww = gdk_window_get_width(gtk_widget_get_window(area));
-    wh = gdk_window_get_height(gtk_widget_get_window(area));
+    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
+    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
 #if defined(CONFIG_OPENGL)
     if (vc->gfx.gls && gtk_use_gl_area) {
         gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
@@ -387,7 +387,6 @@ static void gd_update(DisplayChangeListener *dcl,
                       int x, int y, int w, int h)
 {
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
-    GdkWindow *win;
     int x1, x2, y1, y2;
     int mx, my;
     int fbw, fbh;
@@ -414,12 +413,8 @@ static void gd_update(DisplayChangeListener *dcl,
     fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
     fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
 
-    win = gtk_widget_get_window(vc->gfx.drawing_area);
-    if (!win) {
-        return;
-    }
-    ww = gdk_window_get_width(win);
-    wh = gdk_window_get_height(win);
+    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
+    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
 
     mx = my = 0;
     if (ww > fbw) {
@@ -788,8 +783,8 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
     fbw = surface_width(vc->gfx.ds);
     fbh = surface_height(vc->gfx.ds);
 
-    ww = gdk_window_get_width(gtk_widget_get_window(widget));
-    wh = gdk_window_get_height(gtk_widget_get_window(widget));
+    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;
@@ -838,7 +833,6 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
 {
     VirtualConsole *vc = opaque;
     GtkDisplayState *s = vc->s;
-    GdkWindow *window;
     int x, y;
     int mx, my;
     int fbh, fbw;
@@ -851,10 +845,10 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
     fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
     fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
 
-    window = gtk_widget_get_window(vc->gfx.drawing_area);
-    ww = gdk_window_get_width(window);
-    wh = gdk_window_get_height(window);
-    ws = gdk_window_get_scale_factor(window);
+    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
+    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
+    ws = gdk_window_get_scale_factor(
+            gtk_widget_get_window(vc->gfx.drawing_area));
 
     mx = my = 0;
     if (ww > fbw) {
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] ui: Remove unnecessary checks
  2021-12-19  2:30 [PATCH 0/4] UI fixups Alexander Orzechowski
  2021-12-19  2:30 ` [PATCH 1/4] ui: Use allocated size instead of window size Alexander Orzechowski
@ 2021-12-19  2:30 ` Alexander Orzechowski
  2021-12-21  7:40   ` Marc-André Lureau
  2021-12-19  2:30 ` [PATCH 3/4] ui: Revert: "fix incorrect pointer position on highdpi with gtk" Alexander Orzechowski
  2021-12-19  2:30 ` [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window Alexander Orzechowski
  3 siblings, 1 reply; 10+ messages in thread
From: Alexander Orzechowski @ 2021-12-19  2:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gerd Hoffmann, Alexander Orzechowski

These conditionals should never be false as scale_x and scale_y should
scale the fbw and fbh variables such that the ww and wh variables always
have a greater magnitude.

Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
---
 ui/gtk.c | 27 ++++++---------------------
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 824334ff3d..f2d74b253d 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -416,13 +416,8 @@ static void gd_update(DisplayChangeListener *dcl,
     ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
     wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
 
-    mx = my = 0;
-    if (ww > fbw) {
-        mx = (ww - fbw) / 2;
-    }
-    if (wh > fbh) {
-        my = (wh - fbh) / 2;
-    }
+    mx = (ww - fbw) / 2;
+    my = (wh - fbh) / 2;
 
     gtk_widget_queue_draw_area(vc->gfx.drawing_area,
                                mx + x1, my + y1, (x2 - x1), (y2 - y1));
@@ -801,13 +796,8 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
     fbw *= vc->gfx.scale_x;
     fbh *= vc->gfx.scale_y;
 
-    mx = my = 0;
-    if (ww > fbw) {
-        mx = (ww - fbw) / 2;
-    }
-    if (wh > fbh) {
-        my = (wh - fbh) / 2;
-    }
+    mx = (ww - fbw) / 2;
+    my = (wh - fbh) / 2;
 
     cairo_rectangle(cr, 0, 0, ww, wh);
 
@@ -850,13 +840,8 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
     ws = gdk_window_get_scale_factor(
             gtk_widget_get_window(vc->gfx.drawing_area));
 
-    mx = my = 0;
-    if (ww > fbw) {
-        mx = (ww - fbw) / 2;
-    }
-    if (wh > fbh) {
-        my = (wh - fbh) / 2;
-    }
+    mx = (ww - fbw) / 2;
+    my = (wh - fbh) / 2;
 
     x = (motion->x - mx) / vc->gfx.scale_x * ws;
     y = (motion->y - my) / vc->gfx.scale_y * ws;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] ui: Revert: "fix incorrect pointer position on highdpi with gtk"
  2021-12-19  2:30 [PATCH 0/4] UI fixups Alexander Orzechowski
  2021-12-19  2:30 ` [PATCH 1/4] ui: Use allocated size instead of window size Alexander Orzechowski
  2021-12-19  2:30 ` [PATCH 2/4] ui: Remove unnecessary checks Alexander Orzechowski
@ 2021-12-19  2:30 ` Alexander Orzechowski
  2021-12-19  2:30 ` [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window Alexander Orzechowski
  3 siblings, 0 replies; 10+ messages in thread
From: Alexander Orzechowski @ 2021-12-19  2:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gerd Hoffmann, Alexander Orzechowski

This reverts commit f14aab420c58b57e07189d6d9e6d3fbfab4761a6.

This commit was originally tested on gtk/gl which corrected behavior
there. Turns out, the OpenGL texture representing the virtual console
was being rendered in the incorrect place and not that the cursor
was incorrectly being handled.

Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
---
 ui/gtk.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index f2d74b253d..c41601f24d 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -826,7 +826,7 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
     int x, y;
     int mx, my;
     int fbh, fbw;
-    int ww, wh, ws;
+    int ww, wh;
 
     if (!vc->gfx.ds) {
         return TRUE;
@@ -837,14 +837,12 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
 
     ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
     wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
-    ws = gdk_window_get_scale_factor(
-            gtk_widget_get_window(vc->gfx.drawing_area));
 
     mx = (ww - fbw) / 2;
     my = (wh - fbh) / 2;
 
-    x = (motion->x - mx) / vc->gfx.scale_x * ws;
-    y = (motion->y - my) / vc->gfx.scale_y * ws;
+    x = (motion->x - mx) / vc->gfx.scale_x;
+    y = (motion->y - my) / vc->gfx.scale_y;
 
     if (qemu_input_is_absolute()) {
         if (x < 0 || y < 0 ||
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window
  2021-12-19  2:30 [PATCH 0/4] UI fixups Alexander Orzechowski
                   ` (2 preceding siblings ...)
  2021-12-19  2:30 ` [PATCH 3/4] ui: Revert: "fix incorrect pointer position on highdpi with gtk" Alexander Orzechowski
@ 2021-12-19  2:30 ` Alexander Orzechowski
  2021-12-21  7:48   ` Marc-André Lureau
  3 siblings, 1 reply; 10+ messages in thread
From: Alexander Orzechowski @ 2021-12-19  2:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gerd Hoffmann, Alexander Orzechowski

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>
---
 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



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] ui: Use allocated size instead of window size
  2021-12-19  2:30 ` [PATCH 1/4] ui: Use allocated size instead of window size Alexander Orzechowski
@ 2021-12-21  7:27   ` Marc-André Lureau
  0 siblings, 0 replies; 10+ messages in thread
From: Marc-André Lureau @ 2021-12-21  7:27 UTC (permalink / raw)
  To: Alexander Orzechowski; +Cc: qemu trival, QEMU, Gerd Hoffmann

[-- Attachment #1: Type: text/plain, Size: 3858 bytes --]

Hi

On Sun, Dec 19, 2021 at 6:33 AM Alexander Orzechowski <
orzechowski.alexander@gmail.com> wrote:

> In these cases, we only care about the size of the virtual console
> itself. Previously, these calculations were made using the size of
> the entire window, which would include the size of the virtual console
> plus all the ui elements around it.
>
> Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
>

It's not obvious to me that the drawing area doesn't have its own window.

Nonetheless, it is better to use the allocated size.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
>  ui/gtk.c | 26 ++++++++++----------------
>  1 file changed, 10 insertions(+), 16 deletions(-)
>
> diff --git a/ui/gtk.c b/ui/gtk.c
> index 428f02f2df..824334ff3d 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -340,8 +340,8 @@ static void gd_update_full_redraw(VirtualConsole *vc)
>  {
>      GtkWidget *area = vc->gfx.drawing_area;
>      int ww, wh;
> -    ww = gdk_window_get_width(gtk_widget_get_window(area));
> -    wh = gdk_window_get_height(gtk_widget_get_window(area));
> +    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
> +    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
>  #if defined(CONFIG_OPENGL)
>      if (vc->gfx.gls && gtk_use_gl_area) {
>          gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
> @@ -387,7 +387,6 @@ static void gd_update(DisplayChangeListener *dcl,
>                        int x, int y, int w, int h)
>  {
>      VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
> -    GdkWindow *win;
>      int x1, x2, y1, y2;
>      int mx, my;
>      int fbw, fbh;
> @@ -414,12 +413,8 @@ static void gd_update(DisplayChangeListener *dcl,
>      fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
>      fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
>
> -    win = gtk_widget_get_window(vc->gfx.drawing_area);
> -    if (!win) {
> -        return;
> -    }
> -    ww = gdk_window_get_width(win);
> -    wh = gdk_window_get_height(win);
> +    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
> +    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
>
>      mx = my = 0;
>      if (ww > fbw) {
> @@ -788,8 +783,8 @@ static gboolean gd_draw_event(GtkWidget *widget,
> cairo_t *cr, void *opaque)
>      fbw = surface_width(vc->gfx.ds);
>      fbh = surface_height(vc->gfx.ds);
>
> -    ww = gdk_window_get_width(gtk_widget_get_window(widget));
> -    wh = gdk_window_get_height(gtk_widget_get_window(widget));
> +    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;
> @@ -838,7 +833,6 @@ static gboolean gd_motion_event(GtkWidget *widget,
> GdkEventMotion *motion,
>  {
>      VirtualConsole *vc = opaque;
>      GtkDisplayState *s = vc->s;
> -    GdkWindow *window;
>      int x, y;
>      int mx, my;
>      int fbh, fbw;
> @@ -851,10 +845,10 @@ static gboolean gd_motion_event(GtkWidget *widget,
> GdkEventMotion *motion,
>      fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
>      fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
>
> -    window = gtk_widget_get_window(vc->gfx.drawing_area);
> -    ww = gdk_window_get_width(window);
> -    wh = gdk_window_get_height(window);
> -    ws = gdk_window_get_scale_factor(window);
> +    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
> +    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
> +    ws = gdk_window_get_scale_factor(
> +            gtk_widget_get_window(vc->gfx.drawing_area));
>
>      mx = my = 0;
>      if (ww > fbw) {
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 5007 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/4] ui: Remove unnecessary checks
  2021-12-19  2:30 ` [PATCH 2/4] ui: Remove unnecessary checks Alexander Orzechowski
@ 2021-12-21  7:40   ` Marc-André Lureau
  2021-12-21  8:26     ` Alexander Orzechowski
  0 siblings, 1 reply; 10+ messages in thread
From: Marc-André Lureau @ 2021-12-21  7:40 UTC (permalink / raw)
  To: Alexander Orzechowski; +Cc: qemu trival, QEMU, Gerd Hoffmann

[-- Attachment #1: Type: text/plain, Size: 2394 bytes --]

Hi

On Sun, Dec 19, 2021 at 6:32 AM Alexander Orzechowski <
orzechowski.alexander@gmail.com> wrote:

> These conditionals should never be false as scale_x and scale_y should
> scale the fbw and fbh variables such that the ww and wh variables always
> have a greater magnitude.
>
> Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
>

I don't understand how you reached that conclusion.

scale_x/scale_y can have various values, from 0.25 manually, or pretty much
anything in freescale.

Just adding a breakpoint/debug there and you can see they can be false.

---
>  ui/gtk.c | 27 ++++++---------------------
>  1 file changed, 6 insertions(+), 21 deletions(-)
>
> diff --git a/ui/gtk.c b/ui/gtk.c
> index 824334ff3d..f2d74b253d 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -416,13 +416,8 @@ static void gd_update(DisplayChangeListener *dcl,
>      ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
>      wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
>
> -    mx = my = 0;
> -    if (ww > fbw) {
> -        mx = (ww - fbw) / 2;
> -    }
> -    if (wh > fbh) {
> -        my = (wh - fbh) / 2;
> -    }
> +    mx = (ww - fbw) / 2;
> +    my = (wh - fbh) / 2;
>
>      gtk_widget_queue_draw_area(vc->gfx.drawing_area,
>                                 mx + x1, my + y1, (x2 - x1), (y2 - y1));
> @@ -801,13 +796,8 @@ static gboolean gd_draw_event(GtkWidget *widget,
> cairo_t *cr, void *opaque)
>      fbw *= vc->gfx.scale_x;
>      fbh *= vc->gfx.scale_y;
>
> -    mx = my = 0;
> -    if (ww > fbw) {
> -        mx = (ww - fbw) / 2;
> -    }
> -    if (wh > fbh) {
> -        my = (wh - fbh) / 2;
> -    }
> +    mx = (ww - fbw) / 2;
> +    my = (wh - fbh) / 2;
>
>      cairo_rectangle(cr, 0, 0, ww, wh);
>
> @@ -850,13 +840,8 @@ static gboolean gd_motion_event(GtkWidget *widget,
> GdkEventMotion *motion,
>      ws = gdk_window_get_scale_factor(
>              gtk_widget_get_window(vc->gfx.drawing_area));
>
> -    mx = my = 0;
> -    if (ww > fbw) {
> -        mx = (ww - fbw) / 2;
> -    }
> -    if (wh > fbh) {
> -        my = (wh - fbh) / 2;
> -    }
> +    mx = (ww - fbw) / 2;
> +    my = (wh - fbh) / 2;
>
>      x = (motion->x - mx) / vc->gfx.scale_x * ws;
>      y = (motion->y - my) / vc->gfx.scale_y * ws;
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 3360 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window
  2021-12-19  2:30 ` [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window Alexander Orzechowski
@ 2021-12-21  7:48   ` Marc-André Lureau
  2021-12-21  8:07     ` Alexander Orzechowski
  0 siblings, 1 reply; 10+ messages in thread
From: Marc-André Lureau @ 2021-12-21  7:48 UTC (permalink / raw)
  To: Alexander Orzechowski; +Cc: qemu trival, QEMU, Gerd Hoffmann

[-- Attachment #1: Type: text/plain, Size: 3210 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 4307 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window
  2021-12-21  7:48   ` Marc-André Lureau
@ 2021-12-21  8:07     ` Alexander Orzechowski
  0 siblings, 0 replies; 10+ messages in thread
From: Alexander Orzechowski @ 2021-12-21  8:07 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu trivial, QEMU

[-- Attachment #1: Type: text/plain, Size: 3864 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 6484 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/4] ui: Remove unnecessary checks
  2021-12-21  7:40   ` Marc-André Lureau
@ 2021-12-21  8:26     ` Alexander Orzechowski
  0 siblings, 0 replies; 10+ messages in thread
From: Alexander Orzechowski @ 2021-12-21  8:26 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu trivial, QEMU

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

> Hi
>
> On Sun, Dec 19, 2021 at 6:32 AM Alexander Orzechowski 
> <orzechowski.alexander@gmail.com> wrote:
>
>     These conditionals should never be false as scale_x and scale_y should
>     scale the fbw and fbh variables such that the ww and wh variables
>     always
>     have a greater magnitude.
>
>     Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
>
>
> I don't understand how you reached that conclusion.
>
> scale_x/scale_y can have various values, from 0.25 manually, or pretty 
> much anything in freescale.
>
> Just adding a breakpoint/debug there and you can see they can be false.
>
>     ---
>      ui/gtk.c | 27 ++++++---------------------
>      1 file changed, 6 insertions(+), 21 deletions(-)
>
>     diff --git a/ui/gtk.c b/ui/gtk.c
>     index 824334ff3d..f2d74b253d 100644
>     --- a/ui/gtk.c
>     +++ b/ui/gtk.c
>     @@ -416,13 +416,8 @@ static void gd_update(DisplayChangeListener *dcl,
>          ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
>          wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
>
>     -    mx = my = 0;
>     -    if (ww > fbw) {
>     -        mx = (ww - fbw) / 2;
>     -    }
>     -    if (wh > fbh) {
>     -        my = (wh - fbh) / 2;
>     -    }
>     +    mx = (ww - fbw) / 2;
>     +    my = (wh - fbh) / 2;
>
>          gtk_widget_queue_draw_area(vc->gfx.drawing_area,
>                                     mx + x1, my + y1, (x2 - x1), (y2 -
>     y1));
>     @@ -801,13 +796,8 @@ static gboolean gd_draw_event(GtkWidget
>     *widget, cairo_t *cr, void *opaque)
>          fbw *= vc->gfx.scale_x;
>          fbh *= vc->gfx.scale_y;
>
>     -    mx = my = 0;
>     -    if (ww > fbw) {
>     -        mx = (ww - fbw) / 2;
>     -    }
>     -    if (wh > fbh) {
>     -        my = (wh - fbh) / 2;
>     -    }
>     +    mx = (ww - fbw) / 2;
>     +    my = (wh - fbh) / 2;
>
>          cairo_rectangle(cr, 0, 0, ww, wh);
>
>     @@ -850,13 +840,8 @@ static gboolean gd_motion_event(GtkWidget
>     *widget, GdkEventMotion *motion,
>          ws = gdk_window_get_scale_factor(
>      gtk_widget_get_window(vc->gfx.drawing_area));
>
>     -    mx = my = 0;
>     -    if (ww > fbw) {
>     -        mx = (ww - fbw) / 2;
>     -    }
>     -    if (wh > fbh) {
>     -        my = (wh - fbh) / 2;
>     -    }
>     +    mx = (ww - fbw) / 2;
>     +    my = (wh - fbh) / 2;
>
>          x = (motion->x - mx) / vc->gfx.scale_x * ws;
>          y = (motion->y - my) / vc->gfx.scale_y * ws;
>     -- 
>     2.34.1
>
>
>
>
> -- 
> Marc-André Lureau

Thanks for the thorough review. I didn't realize you could set the scale 
manually, but

it was under my impression that qemu would set the GDK_HINT_MIN_SIZE 
property[1]

to try to disallow the user from resizing the window any smaller than 
the size of the

virtual console. Qemu provides no mechanism to change the translation of 
the virtual

console within the window in this case where the window is smaller than 
the virtual

console would normally allow, I consider this invalid state. The mx and 
my variables

are only used to translate the virtual console within its render 
surface. Thus, if qemu

were to enter this "invalid" state as I've called it, the view would 
show the middle of

the virtual console and obscure the edges. Without this patch it would 
show the top

left, obscuring the bottom right. I am happy to drop this patch for v2. 
Please let me

know your thoughts.


[1]: See ui/gtk.c line 279 with the patches applied.

--

Alexander Orzechowski



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-12-21  8:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-19  2:30 [PATCH 0/4] UI fixups Alexander Orzechowski
2021-12-19  2:30 ` [PATCH 1/4] ui: Use allocated size instead of window size Alexander Orzechowski
2021-12-21  7:27   ` Marc-André Lureau
2021-12-19  2:30 ` [PATCH 2/4] ui: Remove unnecessary checks Alexander Orzechowski
2021-12-21  7:40   ` Marc-André Lureau
2021-12-21  8:26     ` Alexander Orzechowski
2021-12-19  2:30 ` [PATCH 3/4] ui: Revert: "fix incorrect pointer position on highdpi with gtk" Alexander Orzechowski
2021-12-19  2:30 ` [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window Alexander Orzechowski
2021-12-21  7:48   ` Marc-André Lureau
2021-12-21  8:07     ` Alexander Orzechowski

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.