wayland: Don't delay pending surface resize handling on Vulkan.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 14 Feb 2020 00:58:36 -0500
changeset 13518963f11dbf153
parent 13517 fbcc6e833d3c
child 13519 f22dd67ec07b
wayland: Don't delay pending surface resize handling on Vulkan.

OpenGL apparently needs to not do any drawing between wl_egl_window_resize
and eglSwapBuffers, but Vulkan apps don't use SDL to present, so they
never call into an equivalent of SDL_GL_SwapWindow where our Wayland code
was handling pending resize work.

Fixes Bugzilla #4722.
src/video/wayland/SDL_waylandopengles.c
src/video/wayland/SDL_waylandwindow.c
src/video/wayland/SDL_waylandwindow.h
     1.1 --- a/src/video/wayland/SDL_waylandopengles.c	Fri Feb 14 01:08:21 2020 -0500
     1.2 +++ b/src/video/wayland/SDL_waylandopengles.c	Fri Feb 14 00:58:36 2020 -0500
     1.3 @@ -63,41 +63,13 @@
     1.4  Wayland_GLES_SwapWindow(_THIS, SDL_Window *window)
     1.5  {
     1.6      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     1.7 -    struct wl_region *region;
     1.8  
     1.9      if (SDL_EGL_SwapBuffers(_this, data->egl_surface) < 0) {
    1.10          return -1;
    1.11      }
    1.12  
    1.13      // Wayland-EGL forbids drawing calls in-between SwapBuffers and wl_egl_window_resize
    1.14 -    if (data->resize.pending) {
    1.15 -        if (data->scale_factor != data->resize.scale_factor) {
    1.16 -            window->w = 0;
    1.17 -            window->h = 0;
    1.18 -        }
    1.19 -        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, data->resize.width, data->resize.height);
    1.20 -        window->w = data->resize.width;
    1.21 -        window->h = data->resize.height;
    1.22 -        data->scale_factor = data->resize.scale_factor;
    1.23 -        wl_surface_set_buffer_scale(data->surface, data->scale_factor);
    1.24 -        WAYLAND_wl_egl_window_resize(data->egl_window, window->w * data->scale_factor, window->h * data->scale_factor, 0, 0);
    1.25 -
    1.26 -        if (data->resize.configure) {
    1.27 -           if (data->waylandData->shell.xdg) {
    1.28 -              xdg_surface_ack_configure(data->shell_surface.xdg.surface, data->resize.serial);
    1.29 -           } else if (data->waylandData->shell.zxdg) {
    1.30 -              zxdg_surface_v6_ack_configure(data->shell_surface.zxdg.surface, data->resize.serial);
    1.31 -           }
    1.32 -           data->resize.configure = SDL_FALSE;
    1.33 -        }
    1.34 -
    1.35 -        region = wl_compositor_create_region(data->waylandData->compositor);
    1.36 -        wl_region_add(region, 0, 0, window->w, window->h);
    1.37 -        wl_surface_set_opaque_region(data->surface, region);
    1.38 -        wl_region_destroy(region);
    1.39 -
    1.40 -        data->resize.pending = SDL_FALSE;
    1.41 -    }
    1.42 +    Wayland_HandlePendingResize(window);
    1.43  
    1.44      WAYLAND_wl_display_flush( data->waylandData->display );
    1.45  
     2.1 --- a/src/video/wayland/SDL_waylandwindow.c	Fri Feb 14 01:08:21 2020 -0500
     2.2 +++ b/src/video/wayland/SDL_waylandwindow.c	Fri Feb 14 00:58:36 2020 -0500
     2.3 @@ -87,6 +87,10 @@
     2.4      wind->resize.width = width;
     2.5      wind->resize.height = height;
     2.6      wind->resize.pending = SDL_TRUE;
     2.7 +
     2.8 +    if (!(window->flags & SDL_WINDOW_OPENGL)) {
     2.9 +        Wayland_HandlePendingResize(window);  /* OpenGL windows handle this in SwapWindow */
    2.10 +    }
    2.11  }
    2.12  
    2.13  static void
    2.14 @@ -134,6 +138,9 @@
    2.15          wind->resize.pending = SDL_TRUE;
    2.16          wind->resize.configure = SDL_TRUE;
    2.17          wind->resize.serial = serial;
    2.18 +        if (!(window->flags & SDL_WINDOW_OPENGL)) {
    2.19 +            Wayland_HandlePendingResize(window);  /* OpenGL windows handle this in SwapWindow */
    2.20 +        }
    2.21      }
    2.22  }
    2.23  
    2.24 @@ -241,6 +248,9 @@
    2.25          wind->resize.pending = SDL_TRUE;
    2.26          wind->resize.configure = SDL_TRUE;
    2.27          wind->resize.serial = serial;
    2.28 +        if (!(window->flags & SDL_WINDOW_OPENGL)) {
    2.29 +            Wayland_HandlePendingResize(window);  /* OpenGL windows handle this in SwapWindow */
    2.30 +        }
    2.31      }
    2.32  }
    2.33  
    2.34 @@ -376,6 +386,9 @@
    2.35         window->resize.height = window->sdlwindow->h;
    2.36         window->resize.scale_factor = new_factor;
    2.37         window->resize.pending = SDL_TRUE;
    2.38 +       if (!(window->sdlwindow->flags & SDL_WINDOW_OPENGL)) {
    2.39 +           Wayland_HandlePendingResize(window->sdlwindow);  /* OpenGL windows handle this in SwapWindow */
    2.40 +       }
    2.41     }
    2.42  }
    2.43  
    2.44 @@ -782,6 +795,45 @@
    2.45      return 0;
    2.46  }
    2.47  
    2.48 +
    2.49 +void
    2.50 +Wayland_HandlePendingResize(SDL_Window *window)
    2.51 +{
    2.52 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.53 +
    2.54 +    if (data->resize.pending) {
    2.55 +        struct wl_region *region;
    2.56 +        if (data->scale_factor != data->resize.scale_factor) {
    2.57 +            window->w = 0;
    2.58 +            window->h = 0;
    2.59 +        }
    2.60 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, data->resize.width, data->resize.height);
    2.61 +        window->w = data->resize.width;
    2.62 +        window->h = data->resize.height;
    2.63 +        data->scale_factor = data->resize.scale_factor;
    2.64 +        wl_surface_set_buffer_scale(data->surface, data->scale_factor);
    2.65 +        if (data->egl_window) {
    2.66 +            WAYLAND_wl_egl_window_resize(data->egl_window, window->w * data->scale_factor, window->h * data->scale_factor, 0, 0);
    2.67 +        }
    2.68 +
    2.69 +        if (data->resize.configure) {
    2.70 +           if (data->waylandData->shell.xdg) {
    2.71 +              xdg_surface_ack_configure(data->shell_surface.xdg.surface, data->resize.serial);
    2.72 +           } else if (data->waylandData->shell.zxdg) {
    2.73 +              zxdg_surface_v6_ack_configure(data->shell_surface.zxdg.surface, data->resize.serial);
    2.74 +           }
    2.75 +           data->resize.configure = SDL_FALSE;
    2.76 +        }
    2.77 +
    2.78 +        region = wl_compositor_create_region(data->waylandData->compositor);
    2.79 +        wl_region_add(region, 0, 0, window->w, window->h);
    2.80 +        wl_surface_set_opaque_region(data->surface, region);
    2.81 +        wl_region_destroy(region);
    2.82 +
    2.83 +        data->resize.pending = SDL_FALSE;
    2.84 +    }
    2.85 +}
    2.86 +
    2.87  void Wayland_SetWindowSize(_THIS, SDL_Window * window)
    2.88  {
    2.89      SDL_VideoData *data = _this->driverdata;
     3.1 --- a/src/video/wayland/SDL_waylandwindow.h	Fri Feb 14 01:08:21 2020 -0500
     3.2 +++ b/src/video/wayland/SDL_waylandwindow.h	Fri Feb 14 00:58:36 2020 -0500
     3.3 @@ -99,6 +99,8 @@
     3.4  Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
     3.5  extern int Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
     3.6  
     3.7 +extern void Wayland_HandlePendingResize(SDL_Window *window);
     3.8 +
     3.9  #endif /* SDL_waylandwindow_h_ */
    3.10  
    3.11  /* vi: set ts=4 sw=4 expandtab: */