[PATCH spice-gtk] egl: Adjust to window scaling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When GDK_SCALE is != 1 and egl is used, the presented image does not
fit to the window (scale of 2 is often used with hidpi monitors).
Usually this is not a problem since all components are adjusted by
gdk/gtk but with egl, pixel-based data is not being scaled. In this
case window's scale value can be used in order to determine whether
to use a pixel resource with higher resolution data.
---

In order to reproduce the problem set spice with virgl/Intel-vGPU
and run spice-gtk with GDK_SCALE=2

This patch is kind of RFC, it fixes the issue, but it's a bit hacky
and specific. I didn't come across other scale issues but it is likely
that more of these exist and better and generic fix is needed.

---
 src/spice-widget-egl.c  | 15 +++++++++++++--
 src/spice-widget-priv.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/spice-widget-egl.c b/src/spice-widget-egl.c
index 43fccd7..814a580 100644
--- a/src/spice-widget-egl.c
+++ b/src/spice-widget-egl.c
@@ -326,6 +326,8 @@ static gboolean spice_widget_init_egl_win(SpiceDisplay *display, GdkWindow *win,
     if (d->egl.surface)
         return TRUE;
 
+    d->egl.scale = gdk_window_get_scale_factor(win);
+
 #ifdef GDK_WINDOWING_X11
     if (GDK_IS_X11_WINDOW(win)) {
         native = (EGLNativeWindowType)GDK_WINDOW_XID(win);
@@ -431,15 +433,17 @@ void spice_egl_resize_display(SpiceDisplay *display, int w, int h)
 {
     SpiceDisplayPrivate *d = display->priv;
     int prog;
+    gint ws;
 
     if (!gl_make_current(display, NULL))
         return;
 
+    ws = d->egl.scale;
     glGetIntegerv(GL_CURRENT_PROGRAM, &prog);
 
     glUseProgram(d->egl.prog);
-    apply_ortho(d->egl.mproj, 0, w, 0, h, -1, 1);
-    glViewport(0, 0, w, h);
+    apply_ortho(d->egl.mproj, 0, w * ws , 0, h * ws, -1, 1);
+    glViewport(0, 0, w * ws, h * ws);
 
     if (d->ready)
         spice_egl_update_display(display);
@@ -559,6 +563,13 @@ void spice_egl_update_display(SpiceDisplay *display)
 
     spice_display_get_scaling(display, &s, &x, &y, &w, &h);
 
+    // Adjust to gdk scale
+    s *= d->egl.scale;
+    x *= d->egl.scale;
+    y *= d->egl.scale;
+    w *= d->egl.scale;
+    h *= d->egl.scale;
+
     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     glClear(GL_COLOR_BUFFER_BIT);
 
diff --git a/src/spice-widget-priv.h b/src/spice-widget-priv.h
index 65eb404..8f110ac 100644
--- a/src/spice-widget-priv.h
+++ b/src/spice-widget-priv.h
@@ -149,6 +149,7 @@ struct _SpiceDisplayPrivate {
         EGLImageKHR         image;
         gboolean            call_draw_done;
         SpiceGlScanout      scanout;
+        gint                scale;
     } egl;
 #endif // HAVE_EGL
     double scroll_delta_y;
-- 
2.19.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]