mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-02-16 02:30:52 +00:00
Move heavy SystemProperties loads to an opt-in model
This avoids heavyweight operations when we're not actually running config checks.
This commit is contained in:
@@ -98,51 +98,16 @@ SystemProperties::SystemProperties()
|
||||
hasDiscordIntegration = false;
|
||||
#endif
|
||||
|
||||
unmappedGamepads = SdlInputHandler::getUnmappedGamepads();
|
||||
|
||||
// These will be queried asynchronously to avoid blocking the UI
|
||||
hasHardwareAcceleration = true;
|
||||
rendererAlwaysFullScreen = false;
|
||||
supportsHdr = true;
|
||||
maximumResolution = QSize(0, 0);
|
||||
|
||||
// We initialize the video subsystem and test window on the main thread
|
||||
// because some platforms (macOS) do not support window creation on
|
||||
// non-main threads.
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
|
||||
SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
// Update display related attributes (max FPS, native resolution, etc).
|
||||
refreshDisplays();
|
||||
|
||||
testWindow = SDL_CreateWindow("", 0, 0, 1280, 720,
|
||||
SDL_WINDOW_HIDDEN | StreamUtils::getPlatformWindowFlags());
|
||||
if (!testWindow) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Failed to create test window with platform flags: %s",
|
||||
SDL_GetError());
|
||||
|
||||
testWindow = SDL_CreateWindow("", 0, 0, 1280, 720, SDL_WINDOW_HIDDEN);
|
||||
if (!testWindow) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Failed to create window for hardware decode test: %s",
|
||||
SDL_GetError());
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
systemPropertyQueryThread = new SystemPropertyQueryThread(this);
|
||||
systemPropertyQueryThread->start();
|
||||
}
|
||||
|
||||
SystemProperties::~SystemProperties()
|
||||
{
|
||||
systemPropertyQueryThread->wait();
|
||||
waitForAsyncLoad();
|
||||
}
|
||||
|
||||
void SystemProperties::updateDecoderProperties(bool hasHardwareAcceleration, bool rendererAlwaysFullScreen, QSize maximumResolution, bool supportsHdr)
|
||||
@@ -177,7 +142,6 @@ void SystemProperties::updateDecoderProperties(bool hasHardwareAcceleration, boo
|
||||
QRect SystemProperties::getNativeResolution(int displayIndex)
|
||||
{
|
||||
// Returns default constructed QRect if out of bounds
|
||||
systemPropertyQueryThread->wait();
|
||||
Q_ASSERT(!monitorNativeResolutions.isEmpty());
|
||||
return monitorNativeResolutions.value(displayIndex);
|
||||
}
|
||||
@@ -185,7 +149,6 @@ QRect SystemProperties::getNativeResolution(int displayIndex)
|
||||
QRect SystemProperties::getSafeAreaResolution(int displayIndex)
|
||||
{
|
||||
// Returns default constructed QRect if out of bounds
|
||||
systemPropertyQueryThread->wait();
|
||||
Q_ASSERT(!monitorSafeAreaResolutions.isEmpty());
|
||||
return monitorSafeAreaResolutions.value(displayIndex);
|
||||
}
|
||||
@@ -193,11 +156,66 @@ QRect SystemProperties::getSafeAreaResolution(int displayIndex)
|
||||
int SystemProperties::getRefreshRate(int displayIndex)
|
||||
{
|
||||
// Returns 0 if out of bounds
|
||||
systemPropertyQueryThread->wait();
|
||||
Q_ASSERT(!monitorRefreshRates.isEmpty());
|
||||
return monitorRefreshRates.value(displayIndex);
|
||||
}
|
||||
|
||||
void SystemProperties::startAsyncLoad()
|
||||
{
|
||||
if (systemPropertyQueryThread) {
|
||||
// Already started/completed
|
||||
return;
|
||||
}
|
||||
|
||||
// This isn't actually asynchronous (due to the need to synchronize with
|
||||
// SdlGamepadKeyNavigation), but we don't query it in the constructor
|
||||
// because it's expensive.
|
||||
unmappedGamepads = SdlInputHandler::getUnmappedGamepads();
|
||||
if (!unmappedGamepads.isEmpty()) {
|
||||
emit unmappedGamepadsChanged();
|
||||
}
|
||||
|
||||
// We initialize the video subsystem and test window on the main thread
|
||||
// because some platforms (macOS) do not support window creation on
|
||||
// non-main threads.
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
|
||||
SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
// Update display related attributes (max FPS, native resolution, etc).
|
||||
refreshDisplays();
|
||||
|
||||
testWindow = SDL_CreateWindow("", 0, 0, 1280, 720,
|
||||
SDL_WINDOW_HIDDEN | StreamUtils::getPlatformWindowFlags());
|
||||
if (!testWindow) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Failed to create test window with platform flags: %s",
|
||||
SDL_GetError());
|
||||
|
||||
testWindow = SDL_CreateWindow("", 0, 0, 1280, 720, SDL_WINDOW_HIDDEN);
|
||||
if (!testWindow) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Failed to create window for hardware decode test: %s",
|
||||
SDL_GetError());
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
systemPropertyQueryThread = new SystemPropertyQueryThread(this);
|
||||
systemPropertyQueryThread->start();
|
||||
}
|
||||
|
||||
void SystemProperties::waitForAsyncLoad()
|
||||
{
|
||||
if (systemPropertyQueryThread) {
|
||||
systemPropertyQueryThread->wait();
|
||||
}
|
||||
}
|
||||
|
||||
void SystemProperties::refreshDisplays()
|
||||
{
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
|
||||
|
||||
Reference in New Issue
Block a user