Create windows with SDL_WINDOW_METAL on macOS

This prevents the window from being recreated when initializing a Metal renderer.
This commit is contained in:
Cameron Gutman 2020-09-05 14:06:56 -07:00
parent 62b296cf85
commit 3e9781033a
4 changed files with 62 additions and 21 deletions

View File

@ -120,13 +120,21 @@ void SystemProperties::querySdlVideoInfo()
} }
} }
SDL_Window* testWindow = SDL_CreateWindow("", 0, 0, 1280, 720, SDL_WINDOW_HIDDEN); SDL_Window* testWindow = SDL_CreateWindow("", 0, 0, 1280, 720,
SDL_WINDOW_HIDDEN | StreamUtils::getPlatformWindowFlags());
if (!testWindow) { if (!testWindow) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Failed to create window for hardware decode test: %s", "Failed to create test window with platform flags: %s",
SDL_GetError()); SDL_GetError());
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return; 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;
}
} }
Session::getDecoderInfo(testWindow, hasHardwareAcceleration, rendererAlwaysFullScreen, maximumResolution); Session::getDecoderInfo(testWindow, hasHardwareAcceleration, rendererAlwaysFullScreen, maximumResolution);

View File

@ -372,13 +372,21 @@ bool Session::initialize()
} }
// Create a hidden window to use for decoder initialization tests // Create a hidden window to use for decoder initialization tests
SDL_Window* testWindow = SDL_CreateWindow("", 0, 0, 1280, 720, SDL_WINDOW_HIDDEN); SDL_Window* testWindow = SDL_CreateWindow("", 0, 0, 1280, 720,
SDL_WINDOW_HIDDEN | StreamUtils::getPlatformWindowFlags());
if (!testWindow) { if (!testWindow) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Failed to create window for hardware decode test: %s", "Failed to create test window with platform flags: %s",
SDL_GetError()); SDL_GetError());
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return false; 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 false;
}
} }
qInfo() << "Server GPU:" << m_Computer->gpuModel; qInfo() << "Server GPU:" << m_Computer->gpuModel;
@ -1104,16 +1112,29 @@ void Session::exec(int displayOriginX, int displayOriginY)
y, y,
width, width,
height, height,
SDL_WINDOW_ALLOW_HIGHDPI); SDL_WINDOW_ALLOW_HIGHDPI | StreamUtils::getPlatformWindowFlags());
if (!m_Window) { if (!m_Window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"SDL_CreateWindow() failed: %s", "SDL_CreateWindow() failed with platform flags: %s",
SDL_GetError()); SDL_GetError());
delete m_InputHandler;
m_InputHandler = nullptr; m_Window = SDL_CreateWindow("Moonlight",
SDL_QuitSubSystem(SDL_INIT_VIDEO); x,
QThreadPool::globalInstance()->start(new DeferredSessionCleanupTask(this)); y,
return; width,
height,
SDL_WINDOW_ALLOW_HIGHDPI);
if (!m_Window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_CreateWindow() failed: %s",
SDL_GetError());
delete m_InputHandler;
m_InputHandler = nullptr;
SDL_QuitSubSystem(SDL_INIT_VIDEO);
QThreadPool::globalInstance()->start(new DeferredSessionCleanupTask(this));
return;
}
} }
m_InputHandler->setWindow(m_Window); m_InputHandler->setWindow(m_Window);

View File

@ -6,6 +6,15 @@
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
#endif #endif
Uint32 StreamUtils::getPlatformWindowFlags()
{
#ifdef Q_OS_DARWIN
return SDL_WINDOW_METAL;
#else
return 0;
#endif
}
void StreamUtils::scaleSourceToDestinationSurface(SDL_Rect* src, SDL_Rect* dst) void StreamUtils::scaleSourceToDestinationSurface(SDL_Rect* src, SDL_Rect* dst)
{ {
int dstH = dst->w * src->h / src->w; int dstH = dst->w * src->h / src->w;

View File

@ -5,6 +5,9 @@
class StreamUtils class StreamUtils
{ {
public: public:
static
Uint32 getPlatformWindowFlags();
static static
void scaleSourceToDestinationSurface(SDL_Rect* src, SDL_Rect* dst); void scaleSourceToDestinationSurface(SDL_Rect* src, SDL_Rect* dst);