UI fixups
cover UI fixups
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(-)
Signature · 1 line
2.34.1
PATCH 1/4 ui: Use allocated size instead of window size
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.
--- ui/gtk.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
ui/gtk.c +10 -16
@@ -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) {
Signature · 1 line
2.34.1
Re: [PATCH 1/4] ui: Use allocated size instead of window size
Hi
Quoted 7 lines · 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 <[email protected]>
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.
---
Quoted 83 lines
ui/gtk.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)ui/gtk.c +6
-11@@ -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;ui/gtk.c +0
-1@@ -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;ui/gtk.c +4
-4@@ -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
Signature · 1 line
Marc-André Lureau
PATCH 2/4 ui: Remove unnecessary checks
In reply to Alexander OrzechowskiThese 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.
--- ui/gtk.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-)
ui/gtk.c +6 -21
@@ -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;
Signature · 1 line
2.34.1
Re: [PATCH 2/4] ui: Remove unnecessary checks
Hi
Quoted 6 lines · Alexander Orzechowski
These conditionals should never be false as
scale_xandscale_yshould scale the fbw and fbh variables such that the ww and wh variables always have a greater magnitude.Signed-off-by Alexander Orzechowski <[email protected]>
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.
---
Quoted 62 lines
ui/gtk.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-)ui/gtk.c +6
-21@@ -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
Signature · 1 line
Marc-André Lureau
Re: [PATCH 2/4] ui: Remove unnecessary checks
Quoted 71 lines · Marc-André Lureau
Hi
On Sun, Dec 19, 2021 at 6:32 AM Alexander Orzechowski <[email protected]> wrote:
These conditionals should never be false as
scale_xandscale_yshould scale the fbw and fbh variables such that the ww and wh variables always
have a greater magnitude.Signed-off-by Alexander Orzechowski <[email protected]>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;
Quoted 14 lines
- } + 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.1Signature · 1 line
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
PATCH 3/4 ui: Revert: "fix incorrect pointer position on highdpi with gtk"
In reply to Alexander OrzechowskiThis 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.
--- ui/gtk.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
ui/gtk.c +3 -5
@@ -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 ||
Signature · 1 line
2.34.1
PATCH 4/4 ui: Fix gtk/gl when the scaled virtual console does not fit the window
In reply to Alexander Orzechowskigtk/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.
--- ui/gtk-gl-area.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)
ui/gtk-gl-area.c +29 -5
@@ -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); }
Signature · 1 line
2.34.1
Re: [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window
Hi
Quoted 6 lines · 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 <[email protected]>
This doesn't work as expected, the display is not being centered correctly.
---
Quoted 80 lines
ui/gtk-gl-area.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)ui/gtk-gl-area.c +26
-2@@ -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) {ui/gtk-gl-area.c +2
-2@@ -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) {ui/gtk-gl-area.c +1
-2@@ -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
Signature · 1 line
Marc-André Lureau
Re: [PATCH 4/4] ui: Fix gtk/gl when the scaled virtual console does not fit the window
Quoted 84 lines · Marc-André Lureau
Hi
On Sun, Dec 19, 2021 at 6:32 AM Alexander Orzechowski <[email protected]> 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 <[email protected]>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));
Quoted 13 lines
- 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.1Signature · 1 line
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