<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 6/10/19 3:45 PM, Victor Toso wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:20190610124533.iensfzeie6kna43v@toolbox">
      <pre class="moz-quote-pre" wrap="">Hi,

On Mon, Jun 10, 2019 at 12:15:27PM +0000, Victor Toso wrote:
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">From: Snir Sheriber <a class="moz-txt-link-rfc2396E" href="mailto:ssheribe@redhat.com"><ssheribe@redhat.com></a>

When GDK_SCALE is != 1 and egl is used, the image presented 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 issue was also reported at freedesktop gitlab repo:
<a class="moz-txt-link-freetext" href="https://gitlab.freedesktop.org/spice/spice-gtk/issues/99">https://gitlab.freedesktop.org/spice/spice-gtk/issues/99</a>
---
 src/spice-widget-egl.c |  8 ++++----
 src/spice-widget.c     | 31 +++++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/src/spice-widget-egl.c b/src/spice-widget-egl.c
index 43fccd7..4c2a58e 100644
--- a/src/spice-widget-egl.c
+++ b/src/spice-widget-egl.c
@@ -360,9 +360,9 @@ gboolean spice_egl_realize_display(SpiceDisplay *display, GdkWindow *win, GError
     DISPLAY_DEBUG(display, "egl realize");
     if (!spice_widget_init_egl_win(display, win, err))
         return FALSE;
-
-    spice_egl_resize_display(display, gdk_window_get_width(win),
-                             gdk_window_get_height(win));
+    gint scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(display));
+    spice_egl_resize_display(display, gdk_window_get_width(win) * scale_factor,
+                             gdk_window_get_height(win) * scale_factor);
 
     return TRUE;
 }
@@ -427,7 +427,7 @@ void spice_egl_unrealize_display(SpiceDisplay *display)
 }
 
 G_GNUC_INTERNAL
-void spice_egl_resize_display(SpiceDisplay *display, int w, int h)
+void spice_egl_resize_display(SpiceDisplay *display, int w, int h) // w and h should be adjusted to gdk scaling
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
Why not a comment before the function declaration?

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap=""> {
     SpiceDisplayPrivate *d = display->priv;
     int prog;
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 1f2a154..a2651ff 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -1382,7 +1382,8 @@ static void set_egl_enabled(SpiceDisplay *display, bool enabled)
     }
 
     if (enabled && d->egl.context_ready) {
-        spice_egl_resize_display(display, d->ww, d->wh);
+        gint scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(display));
+        spice_egl_resize_display(display, d->ww * scale_factor, d->wh * scale_factor);
     }
 
     d->egl.enabled = enabled;
@@ -1978,11 +1979,16 @@ static void transform_input(SpiceDisplay *display,
     SpiceDisplayPrivate *d = display->priv;
     int display_x, display_y, display_w, display_h;
     double is;
+    gint scale_factor = 1;
 
     spice_display_get_scaling(display, NULL,
                               &display_x, &display_y,
                               &display_w, &display_h);
-
+#if HAVE_EGL
+        if (egl_enabled(d)) {
+            scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(display));
+        }
+#endif
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
I don't think this #if HAVE_EGL is needed because that's in
egl_enabled() too, in case egl is disabled it should always
return false which I hope compiler can optimize...

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">     /* For input we need a different scaling factor in order to
        be able to reach the full width of a display. For instance, consider
        a display of 100 pixels showing in a window 10 pixels wide. The normal
@@ -1998,7 +2004,7 @@ static void transform_input(SpiceDisplay *display,
        coordinates in the inverse direction (window -> display) as the fb size
        (display -> window).
     */
-    is = (double)(d->area.width-1) / (double)(display_w-1);
+    is = ((double)(d->area.width-1) / (double)(display_w-1)) * scale_factor;
 
     window_x -= display_x;
     window_y -= display_y;
@@ -2183,8 +2189,10 @@ static void size_allocate(GtkWidget *widget, GtkAllocation *conf, gpointer data)
         d->wh = conf->height;
         recalc_geometry(widget);
 #if HAVE_EGL
-        if (egl_enabled(d))
-            spice_egl_resize_display(display, conf->width, conf->height);
+        if (egl_enabled(d)) {
+            gint scale_factor = gtk_widget_get_scale_factor(widget);
+            spice_egl_resize_display(display, conf->width * scale_factor, conf->height * scale_factor);
+        }
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
Indentation is wrong</pre>
    </blockquote>
    <p><br>
    </p>
    <p>Will be fixed.</p>
    <p><br>
    </p>
    <blockquote type="cite"
      cite="mid:20190610124533.iensfzeie6kna43v@toolbox">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap=""> #endif
     }
 
@@ -2942,10 +2950,16 @@ void spice_display_get_scaling(SpiceDisplay *display,
     int ww, wh;
     int x, y, w, h;
     double s;
+    gint scale_factor = 1;
 
     if (gtk_widget_get_realized (GTK_WIDGET(display))) {
-        ww = gtk_widget_get_allocated_width(GTK_WIDGET(display));
-        wh = gtk_widget_get_allocated_height(GTK_WIDGET(display));
+#if HAVE_EGL
+        if (egl_enabled(d)) {
+            scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(display));
+        }
+#endif
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
.. same here but I haven't tested this version nor checked the
assembly code so, take this as suggestion only :)</pre>
    </blockquote>
    <p><br>
    </p>
    <p>This is indeed not necessary.</p>
    <p>Will be removed, Thanks!</p>
    <p><br>
    </p>
    <blockquote type="cite"
      cite="mid:20190610124533.iensfzeie6kna43v@toolbox">
      <pre class="moz-quote-pre" wrap="">

Acked-by: Victor Toso <a class="moz-txt-link-rfc2396E" href="mailto:victortoso@redhat.com"><victortoso@redhat.com></a>

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+        ww = gtk_widget_get_allocated_width(GTK_WIDGET(display)) * scale_factor;
+        wh = gtk_widget_get_allocated_height(GTK_WIDGET(display)) * scale_factor;
     } else {
         ww = fbw;
         wh = fbh;
@@ -3091,7 +3105,8 @@ void spice_display_widget_gl_scanout(SpiceDisplay *display)
             g_clear_error(&err);
         }
 
-        spice_egl_resize_display(display, d->ww, d->wh);
+        gint scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(display));
+        spice_egl_resize_display(display, d->ww * scale_factor, d->wh * scale_factor);
     }
 #endif
 
-- 
2.20.1

_______________________________________________
Spice-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/spice-devel">https://lists.freedesktop.org/mailman/listinfo/spice-devel</a>
</pre>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <pre class="moz-quote-pre" wrap="">_______________________________________________
Spice-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/spice-devel">https://lists.freedesktop.org/mailman/listinfo/spice-devel</a></pre>
      </blockquote>
    </blockquote>
  </body>
</html>