From 9953f7ead17011ccc4f747291ef48de8d2ed7184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 8 Feb 2024 22:07:11 +0100 Subject: [PATCH] Wayland: Cache framebuffer size The calculation of framebuffer size is about to get more complicated with the introduction of fractional-scale-v1, so only do it in one place. This is also a tiny preparation for eventually behaving better towards wl_egl_window_resize. --- src/wl_platform.h | 1 + src/wl_window.c | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/wl_platform.h b/src/wl_platform.h index d54d394a..b1303d9f 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -348,6 +348,7 @@ typedef struct _GLFWscaleWayland typedef struct _GLFWwindowWayland { int width, height; + int fbWidth, fbHeight; GLFWbool visible; GLFWbool maximized; GLFWbool activated; diff --git a/src/wl_window.c b/src/wl_window.c index 71be06b7..13879a12 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -312,17 +312,21 @@ static void setContentAreaOpaque(_GLFWwindow* window) static void resizeFramebuffer(_GLFWwindow* window) { - int32_t scale = window->wl.bufferScale; - int scaledWidth = window->wl.width * scale; - int scaledHeight = window->wl.height * scale; + window->wl.fbWidth = window->wl.width * window->wl.bufferScale; + window->wl.fbHeight = window->wl.height * window->wl.bufferScale; if (window->wl.egl.window) - wl_egl_window_resize(window->wl.egl.window, scaledWidth, scaledHeight, 0, 0); + { + wl_egl_window_resize(window->wl.egl.window, + window->wl.fbWidth, + window->wl.fbHeight, + 0, 0); + } if (!window->wl.transparent) setContentAreaOpaque(window); - _glfwInputFramebufferSize(window, scaledWidth, scaledHeight); + _glfwInputFramebufferSize(window, window->wl.fbWidth, window->wl.fbHeight); } static void resizeWindow(_GLFWwindow* window) @@ -971,6 +975,8 @@ static GLFWbool createNativeSurface(_GLFWwindow* window, window->wl.width = wndconfig->width; window->wl.height = wndconfig->height; + window->wl.fbWidth = wndconfig->width; + window->wl.fbHeight = wndconfig->height; window->wl.bufferScale = 1; window->wl.title = _glfw_strdup(wndconfig->title); window->wl.appId = _glfw_strdup(wndconfig->wl.appId); @@ -2044,8 +2050,8 @@ GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window, ctxconfig->source == GLFW_NATIVE_CONTEXT_API) { window->wl.egl.window = wl_egl_window_create(window->wl.surface, - wndconfig->width, - wndconfig->height); + window->wl.fbWidth, + window->wl.fbHeight); if (!window->wl.egl.window) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -2278,11 +2284,10 @@ void _glfwSetWindowAspectRatioWayland(_GLFWwindow* window, int numer, int denom) void _glfwGetFramebufferSizeWayland(_GLFWwindow* window, int* width, int* height) { - _glfwGetWindowSizeWayland(window, width, height); if (width) - *width *= window->wl.bufferScale; + *width = window->wl.fbWidth; if (height) - *height *= window->wl.bufferScale; + *height = window->wl.fbHeight; } void _glfwGetWindowFrameSizeWayland(_GLFWwindow* window,