kmsdrm: fix SetDisplayMode binding the the wrong surface / context

SetDisplayMode needs to recreate the EGL surfaces, which then need to be
bound along with the correct context in each rendering thread

commit 3a1d7d9c9a removed this behavior which
has broken using SetDisplayMode when rendering with multiple contexts

the commit message was rather vague, but if the surfaces do need to be
created immediately, this process probably needs to be split such that
surface is created immediately, but the binding is deferred
This commit is contained in:
Anthony Pesch 2021-05-23 16:09:27 -04:00 committed by Sam Lantinga
parent 0219928dd5
commit 4c965b7a8d
3 changed files with 12 additions and 4 deletions

View File

@ -97,6 +97,11 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) {
even if you do async flips. */ even if you do async flips. */
uint32_t flip_flags = DRM_MODE_PAGE_FLIP_EVENT; 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 /* Wait for confirmation that the next front buffer has been flipped, at which
point the previous front buffer can be released */ point the previous front buffer can be released */
if (!KMSDRM_WaitPageflip(_this, windata)) { if (!KMSDRM_WaitPageflip(_this, windata)) {

View File

@ -953,6 +953,8 @@ KMSDRM_CreateSurfaces(_THIS, SDL_Window * window)
egl_context = (EGLContext)SDL_GL_GetCurrentContext(); egl_context = (EGLContext)SDL_GL_GetCurrentContext();
ret = SDL_EGL_MakeCurrent(_this, windata->egl_surface, egl_context); ret = SDL_EGL_MakeCurrent(_this, windata->egl_surface, egl_context);
windata->egl_surface_dirty = SDL_FALSE;
cleanup: cleanup:
if (ret) { if (ret) {
@ -1075,10 +1077,11 @@ KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
for (i = 0; i < viddata->num_windows; i++) { for (i = 0; i < viddata->num_windows; i++) {
SDL_Window *window = viddata->windows[i]; SDL_Window *window = viddata->windows[i];
SDL_WindowData *windata = (SDL_WindowData *)window->driverdata;
if (KMSDRM_CreateSurfaces(_this, window)) { /* Can't recreate EGL surfaces right now, need to wait until SwapWindow
return -1; so the correct thread-local surface and context state are available */
} windata->egl_surface_dirty = SDL_TRUE;
/* Tell app about the window resize */ /* Tell app about the window resize */
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, mode->w, mode->h); SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, mode->w, mode->h);

View File

@ -99,7 +99,7 @@ typedef struct SDL_WindowData
SDL_bool double_buffer; SDL_bool double_buffer;
EGLSurface egl_surface; EGLSurface egl_surface;
SDL_bool egl_surface_dirty;
} SDL_WindowData; } SDL_WindowData;
typedef struct KMSDRM_FBInfo typedef struct KMSDRM_FBInfo