Use fractional scale for the GL renderer
authorMatthias Clasen <mclasen@redhat.com>
Sun, 2 Apr 2023 02:52:13 +0000 (22:52 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 2 Apr 2023 13:22:56 +0000 (09:22 -0400)
This commit combines changes in the Wayland backend,
the GL context frontend, and the GL renderer to switch
them all to use the fractional scale.

In the Wayland backend, we now use the fractional scale
to size the EGL window.

In the GL frontend code, we use the fractional scale to
scale the damage region and surface in begin/end_frame.

And in the GL renderer, we replace gdk_surface_get_scale_factor()
with gdk_surface_get_scale().

gdk/gdkglcontext.c
gdk/wayland/gdksurface-wayland.c
gsk/gl/gskglrenderer.c

index 5f6047378b8e9166aa8e2a750606f15ce9678465..b8972e57f8a9ffbfd875bf636d93a4281eac22c8 100644 (file)
@@ -94,6 +94,8 @@
 #include <epoxy/egl.h>
 #endif
 
+#include <math.h>
+
 #define DEFAULT_ALLOWED_APIS GDK_GL_API_GL | GDK_GL_API_GLES
 
 typedef struct {
@@ -586,8 +588,8 @@ gdk_gl_context_real_begin_frame (GdkDrawContext *draw_context,
   cairo_region_union (region, damage);
   cairo_region_destroy (damage);
 
-  ww = gdk_surface_get_width (surface) * gdk_surface_get_scale_factor (surface);
-  wh = gdk_surface_get_height (surface) * gdk_surface_get_scale_factor (surface);
+  ww = (int) ceil (gdk_surface_get_width (surface) * gdk_surface_get_scale (surface));
+  wh = (int) ceil (gdk_surface_get_height (surface) * gdk_surface_get_scale (surface));
 
   gdk_gl_context_make_current (context);
 
@@ -631,7 +633,7 @@ gdk_gl_context_real_end_frame (GdkDrawContext *draw_context,
       EGLint *heap_rects = NULL;
       int i, j, n_rects = cairo_region_num_rectangles (painted);
       int surface_height = gdk_surface_get_height (surface);
-      int scale = gdk_surface_get_scale_factor (surface);
+      double scale = gdk_surface_get_scale (surface);
       EGLint *rects;
 
       if (n_rects < G_N_ELEMENTS (stack_rects) / 4)
@@ -644,10 +646,10 @@ gdk_gl_context_real_end_frame (GdkDrawContext *draw_context,
           cairo_rectangle_int_t rect;
 
           cairo_region_get_rectangle (painted, i, &rect);
-          rects[j++] = rect.x * scale;
-          rects[j++] = (surface_height - rect.height - rect.y) * scale;
-          rects[j++] = rect.width * scale;
-          rects[j++] = rect.height * scale;
+          rects[j++] = (int) floor (rect.x * scale);
+          rects[j++] = (int) floor ((surface_height - rect.height - rect.y) * scale);
+          rects[j++] = (int) ceil (rect.width * scale);
+          rects[j++] = (int) ceil (rect.height * scale);
         }
       priv->eglSwapBuffersWithDamage (gdk_display_get_egl_display (display), egl_surface, rects, n_rects);
       g_free (heap_rects);
index 76112b8256975c65ed22dacee8997ae40e76b6fc..f51f081a43db5b6959fc266c7815c7d46b114d2a 100644 (file)
@@ -259,8 +259,9 @@ gdk_wayland_surface_update_size (GdkSurface               *surface,
 
   if (impl->display_server.egl_window)
     wl_egl_window_resize (impl->display_server.egl_window,
-                          width * gdk_fractional_scale_to_int (scale),
-                          height * gdk_fractional_scale_to_int (scale), 0, 0);
+                          gdk_fractional_scale_scale (scale, width),
+                          gdk_fractional_scale_scale (scale, height),
+                          0, 0);
 
   gdk_surface_invalidate_rect (surface, NULL);
 
@@ -1364,8 +1365,8 @@ gdk_wayland_surface_ensure_wl_egl_window (GdkSurface *surface)
     {
       impl->display_server.egl_window =
         wl_egl_window_create (impl->display_server.wl_surface,
-                              surface->width * gdk_fractional_scale_to_int (&impl->scale),
-                              surface->height * gdk_fractional_scale_to_int (&impl->scale));
+                              gdk_fractional_scale_scale (&impl->scale, surface->width),
+                              gdk_fractional_scale_scale (&impl->scale, surface->height));
       gdk_surface_set_egl_native_window (surface, impl->display_server.egl_window);
     }
 }
index ffd3a0f27b381baa4d279ce192607702a39a961c..eb3c77c72f7af33e624f30f51c38ae1dd96e6b4c 100644 (file)
@@ -288,7 +288,7 @@ gsk_gl_renderer_render (GskRenderer          *renderer,
   g_assert (root != NULL);
 
   surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (self->context));
-  scale = gdk_surface_get_scale_factor (surface);
+  scale = gdk_surface_get_scale (surface);
 
   viewport.origin.x = 0;
   viewport.origin.y = 0;