diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c index ee7e3923d..7b28c55bc 100644 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c @@ -97,6 +97,11 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) { even if you do async flips. */ uint32_t flip_flags = DRM_MODE_PAGE_FLIP_EVENT; + /* Recreate the GBM / EGL surfaces if the display mode has changed */ + if (windata->egl_surface_dirty) { + KMSDRM_CreateSurfaces(_this, window); + } + /* Wait for confirmation that the next front buffer has been flipped, at which point the previous front buffer can be released */ if (!KMSDRM_WaitPageflip(_this, windata)) { diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 9704d0e4f..3f9de064e 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -953,6 +953,8 @@ KMSDRM_CreateSurfaces(_THIS, SDL_Window * window) egl_context = (EGLContext)SDL_GL_GetCurrentContext(); ret = SDL_EGL_MakeCurrent(_this, windata->egl_surface, egl_context); + windata->egl_surface_dirty = SDL_FALSE; + cleanup: if (ret) { @@ -1075,10 +1077,11 @@ KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) for (i = 0; i < viddata->num_windows; i++) { SDL_Window *window = viddata->windows[i]; + SDL_WindowData *windata = (SDL_WindowData *)window->driverdata; - if (KMSDRM_CreateSurfaces(_this, window)) { - return -1; - } + /* Can't recreate EGL surfaces right now, need to wait until SwapWindow + so the correct thread-local surface and context state are available */ + windata->egl_surface_dirty = SDL_TRUE; /* Tell app about the window resize */ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, mode->w, mode->h); diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h index 89b238186..18e90abc2 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.h +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h @@ -99,7 +99,7 @@ typedef struct SDL_WindowData SDL_bool double_buffer; EGLSurface egl_surface; - + SDL_bool egl_surface_dirty; } SDL_WindowData; typedef struct KMSDRM_FBInfo