From fa58dd9256cfe5775718a311e1785ca3df46bddc Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 1 Apr 2023 22:52:13 -0400 Subject: Use fractional scale for the GL renderer 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 | 16 +++++++++------- gdk/wayland/gdksurface-wayland.c | 9 +++++---- gsk/gl/gskglrenderer.c | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c index 5f6047378b..b8972e57f8 100644 --- a/gdk/gdkglcontext.c +++ b/gdk/gdkglcontext.c @@ -94,6 +94,8 @@ #include #endif +#include + #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); diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c index 76112b8256..f51f081a43 100644 --- a/gdk/wayland/gdksurface-wayland.c +++ b/gdk/wayland/gdksurface-wayland.c @@ -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); } } diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c index ffd3a0f27b..eb3c77c72f 100644 --- a/gsk/gl/gskglrenderer.c +++ b/gsk/gl/gskglrenderer.c @@ -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; -- cgit v1.2.1