Move forced KMSDRM modesetting operation into Session init code

Performing this each time DrmRenderer is initialized leads to long
delays when choosing a decoder on embedded platforms, particularly
those like TH1520/JH7110 which lack accelerated GL drivers.
This commit is contained in:
Cameron Gutman
2024-06-25 21:57:02 -05:00
parent ffdf683597
commit a9d7c8e495
2 changed files with 25 additions and 37 deletions

View File

@@ -1802,6 +1802,31 @@ void Session::execInternal()
FillRect(info.info.win.hdc, &clientRect, blackBrush);
DeleteObject(blackBrush);
}
#else
if (strcmp(SDL_GetCurrentVideoDriver(), "KMSDRM") == 0) {
// Create a dummy renderer to force SDL to complete the modesetting
// operation that the KMSDRM backend keeps pending until the next
// time we swap buffers.
SDL_Renderer* renderer = SDL_CreateRenderer(m_Window, -1, SDL_RENDERER_SOFTWARE);
if (renderer != nullptr) {
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_DestroyRenderer(renderer);
// SDL_CreateRenderer() can end up having to recreate our window (SDL_RecreateWindow())
// to ensure it's compatible with the renderer's OpenGL context. If that happens, we
// can get spurious SDL_WINDOWEVENT events that will cause us to (again) recreate our
// renderer. This can lead to an infinite to renderer recreation, so discard all
// SDL_WINDOWEVENT events after SDL_CreateRenderer().
flushWindowEvents();
}
else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_CreateRenderer() for KMSDRM modesetting failed: %s",
SDL_GetError());
}
}
#endif
}