wayland: Add dedupe logic to window geometry configuration Adds deduplication logic to ConfigureWindowGeometry() to avoid setting redundant backbuffer, viewport and surface opaque region dimensions. State is now only set when the window and/or backbuffer dimensions change. This repurposes the viewport rect to always hold the actual size of the window, which can differ from the SDL size if things are being scaled. The SDL_Rect was removed in favor of two ints, as the x/y members of the struct were never used, so they just wasted space. Since the internal variables always have the true window size, the width/height getter functions are no longer required and can be removed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 4f015b0..2abb2d5 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -164,21 +164,6 @@ NeedViewport(SDL_Window *window)
return SDL_FALSE;
}
-/* If a viewport is active, use the width and height for the window dimensions. */
-SDL_FORCE_INLINE int
-GetWindowWidth(SDL_Window *window)
-{
- SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
- return SDL_RectEmpty(&data->viewport_rect) ? window->w : data->viewport_rect.w;
-}
-
-SDL_FORCE_INLINE int
-GetWindowHeight(SDL_Window *window)
-{
- SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
- return SDL_RectEmpty(&data->viewport_rect) ? window->h : data->viewport_rect.h;
-}
-
static void
GetBufferSize(SDL_Window *window, int *width, int *height)
{
@@ -247,11 +232,16 @@ ConfigureWindowGeometry(SDL_Window *window)
SDL_VideoData *viddata = data->waylandData;
SDL_WaylandOutputData *output = (SDL_WaylandOutputData *)SDL_GetDisplayForWindow(window)->driverdata;
struct wl_region *region;
+ const int old_dw = data->drawable_width;
+ const int old_dh = data->drawable_height;
+ SDL_bool window_size_changed;
+ SDL_bool drawable_size_changed;
/* Set the drawable backbuffer size. */
GetBufferSize(window, &data->drawable_width, &data->drawable_height);
+ drawable_size_changed = data->drawable_width != old_dw || data->drawable_height != old_dh;
- if (data->egl_window) {
+ if (data->egl_window && drawable_size_changed) {
WAYLAND_wl_egl_window_resize(data->egl_window,
data->drawable_width,
data->drawable_height,
@@ -260,58 +250,63 @@ ConfigureWindowGeometry(SDL_Window *window)
if (FullscreenModeEmulation(window) && NeedViewport(window)) {
int fs_width, fs_height;
- int src_width, src_height;
const int output_width = data->fs_output_width ? data->fs_output_width : output->width;
const int output_height = data->fs_output_height ? data->fs_output_height : output->height;
- GetFullScreenDimensions(window, &fs_width, &fs_height, &src_width, &src_height);
+ window_size_changed = data->window_width != output_width || data->window_height != output_height;
- /* Set the buffer scale to 1 since a viewport will be used. */
- wl_surface_set_buffer_scale(data->surface, 1);
- SetDrawSurfaceViewport(window, src_width, src_height, output_width, output_height);
+ if (window_size_changed || drawable_size_changed) {
+ GetFullScreenDimensions(window, &fs_width, &fs_height, NULL, NULL);
- data->viewport_rect.x = 0;
- data->viewport_rect.y = 0;
- data->viewport_rect.w = output_width;
- data->viewport_rect.h = output_height;
+ /* Set the buffer scale to 1 since a viewport will be used. */
+ wl_surface_set_buffer_scale(data->surface, 1);
+ SetDrawSurfaceViewport(window, data->drawable_width, data->drawable_height,
+ output_width, output_height);
- data->pointer_scale_x = (float)fs_width / (float)output_width;
- data->pointer_scale_y = (float)fs_height / (float)output_height;
+ data->window_width = output_width;
+ data->window_height = output_height;
- if (!EGLTransparencyEnabled()) {
- region = wl_compositor_create_region(viddata->compositor);
- wl_region_add(region, data->viewport_rect.x, data->viewport_rect.y,
- data->viewport_rect.w, data->viewport_rect.h);
- wl_surface_set_opaque_region(data->surface, region);
- wl_region_destroy(region);
+ data->pointer_scale_x = (float) fs_width / (float) output_width;
+ data->pointer_scale_y = (float) fs_height / (float) output_height;
}
} else {
- if (NeedViewport(window)) {
- wl_surface_set_buffer_scale(data->surface, 1);
- SetDrawSurfaceViewport(window, data->drawable_width, data->drawable_height, window->w, window->h);
- } else {
- UnsetDrawSurfaceViewport(window);
+ window_size_changed = data->window_width != window->w || data->window_height != window->h;
- /* Round to the next integer in case of a fractional value. */
- wl_surface_set_buffer_scale(data->surface, (int32_t)SDL_ceilf(data->scale_factor));
- }
+ if (window_size_changed || drawable_size_changed) {
+ if (NeedViewport(window)) {
+ wl_surface_set_buffer_scale(data->surface, 1);
+ SetDrawSurfaceViewport(window, data->drawable_width, data->drawable_height, window->w, window->h);
+ } else {
+ UnsetDrawSurfaceViewport(window);
+
+ /* Round to the next integer in case of a fractional value. */
+ wl_surface_set_buffer_scale(data->surface, (int32_t) SDL_ceilf(data->scale_factor));
+ }
- SDL_zero(data->viewport_rect);
+ data->window_width = window->w;
+ data->window_height = window->h;
- data->pointer_scale_x = 1.0f;
- data->pointer_scale_y = 1.0f;
+ data->pointer_scale_x = 1.0f;
+ data->pointer_scale_y = 1.0f;
+ }
+ }
+ /*
+ * The opaque and pointer confinement regions only need to be recalculated
+ * if the output size has changed.
+ */
+ if (window_size_changed) {
if (!EGLTransparencyEnabled()) {
region = wl_compositor_create_region(viddata->compositor);
- wl_region_add(region, 0, 0, window->w, window->h);
+ wl_region_add(region, 0, 0,
+ data->window_width, data->window_height);
wl_surface_set_opaque_region(data->surface, region);
wl_region_destroy(region);
}
- }
- /* Recreate the pointer confinement region when the window geometry changes. */
- if (data->confined_pointer) {
- Wayland_input_confine_pointer(viddata->input, window);
+ if (data->confined_pointer) {
+ Wayland_input_confine_pointer(viddata->input, window);
+ }
}
}
@@ -361,7 +356,7 @@ SetMinMaxDimensions(SDL_Window *window, SDL_bool commit)
max_height);
if (commit) {
- struct libdecor_state *state = libdecor_state_new(GetWindowWidth(window), GetWindowHeight(window));
+ struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height);
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
wl_surface_commit(wind->surface);
@@ -415,7 +410,7 @@ SetFullscreen(SDL_Window *window, struct wl_output *output)
libdecor_frame_set_capabilities(wind->shell_surface.libdecor.frame, LIBDECOR_ACTION_RESIZE);
wl_surface_commit(wind->surface);
} else {
- struct libdecor_state *state = libdecor_state_new(GetWindowWidth(window), GetWindowHeight(window));
+ struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height);
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
wl_surface_commit(wind->surface);
@@ -430,7 +425,7 @@ SetFullscreen(SDL_Window *window, struct wl_output *output)
libdecor_frame_unset_capabilities(wind->shell_surface.libdecor.frame, LIBDECOR_ACTION_RESIZE);
wl_surface_commit(wind->surface);
} else {
- struct libdecor_state *state = libdecor_state_new(GetWindowWidth(window), GetWindowHeight(window));
+ struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height);
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
wl_surface_commit(wind->surface);
@@ -509,14 +504,14 @@ CommitWindowGeometry(SDL_Window *window)
#ifdef HAVE_LIBDECOR_H
if (WINDOW_IS_LIBDECOR(data, window) && wind->shell_surface.libdecor.frame) {
- struct libdecor_state *state = libdecor_state_new(GetWindowWidth(window), GetWindowHeight(window));
+ struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height);
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
} else
#endif
if (viddata->shell.xdg && wind->shell_surface.xdg.surface) {
xdg_surface_set_window_geometry(wind->shell_surface.xdg.surface, 0, 0,
- GetWindowWidth(window), GetWindowHeight(window));
+ wind->window_width, wind->window_height);
}
}
@@ -527,11 +522,9 @@ surface_damage_frame_done(void *data, struct wl_callback *cb, uint32_t time)
{
SDL_WindowData *wind = (SDL_WindowData *)data;
- /* Manually set the damage region when using a viewport. */
- if (!SDL_RectEmpty(&wind->viewport_rect)) {
- wl_surface_damage(wind->surface, wind->viewport_rect.x, wind->viewport_rect.y,
- wind->viewport_rect.w, wind->viewport_rect.h);
- }
+ /* Set the damage region. */
+ wl_surface_damage(wind->surface, 0, 0,
+ wind->window_width, wind->window_height);
wl_callback_destroy(cb);
wind->surface_damage_frame_callback = wl_surface_frame(wind->surface);
@@ -933,7 +926,7 @@ decoration_frame_configure(struct libdecor_frame *frame,
wind->shell_surface.libdecor.initial_configure_seen = SDL_TRUE;
/* ... then commit the changes on the libdecor side. */
- state = libdecor_state_new(GetWindowWidth(window), GetWindowHeight(window));
+ state = libdecor_state_new(wind->window_width, wind->window_height);
libdecor_frame_commit(frame, state, configuration);
libdecor_state_free(state);
@@ -1971,7 +1964,6 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
{
SDL_WindowData *data;
SDL_VideoData *c;
- struct wl_region *region;
data = SDL_calloc(1, sizeof *data);
if (data == NULL)
@@ -1998,8 +1990,6 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
data->sdlwindow = window;
data->scale_factor = 1.0f;
- data->pointer_scale_x = 1.0f;
- data->pointer_scale_y = 1.0f;
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
int i;
@@ -2021,6 +2011,9 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
SDL_WAYLAND_register_surface(data->surface);
+ /* Must be called before EGL configuration to set the drawable backbuffer size. */
+ ConfigureWindowGeometry(window);
+
/* Fire a callback when the compositor wants a new frame rendered.
* Right now this only matters for OpenGL; we use this callback to add a
* wait timeout that avoids getting deadlocked by the compositor when the
@@ -2048,9 +2041,6 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
}
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
- 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);
@@ -2072,13 +2062,6 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
}
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
- if (!EGLTransparencyEnabled()) {
- region = wl_compositor_create_region(c->compositor);
- wl_region_add(region, 0, 0, window->w, window->h);
- wl_surface_set_opaque_region(data->surface, region);
- wl_region_destroy(region);
- }
-
if (c->relative_mouse_mode) {
Wayland_input_lock_pointer(c->input);
}
@@ -2149,7 +2132,7 @@ Wayland_HandleResize(SDL_Window *window, int width, int height, float scale)
viddata->shell.xdg &&
data->shell_surface.xdg.surface) {
xdg_surface_set_window_geometry(data->shell_surface.xdg.surface, 0, 0,
- GetWindowWidth(window), GetWindowHeight(window));
+ data->window_width, data->window_height);
}
}
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
index 0a37a27..a14ba13 100644
--- a/src/video/wayland/SDL_waylandwindow.h
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -105,7 +105,7 @@ typedef struct {
float pointer_scale_y;
int drawable_width, drawable_height;
int fs_output_width, fs_output_height;
- SDL_Rect viewport_rect;
+ int window_width, window_height;
SDL_bool needs_resize_event;
SDL_bool floating_resize_pending;
SDL_bool is_fullscreen;