Commit c11bdeeb6975e00ecf7d7be0d13b47669a50abf9

Frank Praznik 2022-06-21T13:28:14

wayland: Round fractional backbuffer sizes halfway away from zero Use SDL_lroundf() to round fractional backbuffer sizes halfway away from zero, as this is the rounding method recommended by the forthcoming Wayland fractional scaling protocol.

diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index cfd835b..8ca0842 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -184,8 +184,9 @@ GetBufferSize(SDL_Window *window, int *width, int *height)
     if (FullscreenModeEmulation(window)) {
         GetFullScreenDimensions(window, NULL, NULL, &buf_width, &buf_height);
     } else if (NeedViewport(window)) {
-        buf_width  = (int)SDL_ceil(window->w * data->scale_factor);
-        buf_height = (int)SDL_ceil(window->h * data->scale_factor);
+        /* Round fractional backbuffer sizes halfway away from zero. */
+        buf_width  = (int)SDL_lroundf(window->w * data->scale_factor);
+        buf_height = (int)SDL_lroundf(window->h * data->scale_factor);
     } else {
         /*
          * Integer scaled windowed or fullscreen with no viewport
@@ -1897,8 +1898,8 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
     }
 #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
 
-    data->drawable_width = SDL_ceilf(window->w * data->scale_factor);
-    data->drawable_height = SDL_ceilf(window->h * data->scale_factor);
+    data->drawable_width = SDL_lroundf(window->w * data->scale_factor);
+    data->drawable_height = SDL_lroundf(window->h * data->scale_factor);
 
     if (window->flags & SDL_WINDOW_OPENGL) {
         data->egl_window = WAYLAND_wl_egl_window_create(data->surface, data->drawable_width, data->drawable_height);