From 83ca1ad8a682251b84d04fd87247d068784588f8 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Wed, 2 Nov 2022 23:06:36 -0500 Subject: [PATCH] VideoBackends:Metal: Headless render support --- Source/Core/VideoBackends/Metal/MTLMain.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoBackends/Metal/MTLMain.mm b/Source/Core/VideoBackends/Metal/MTLMain.mm index 15cce280b0..ad646b9bf0 100644 --- a/Source/Core/VideoBackends/Metal/MTLMain.mm +++ b/Source/Core/VideoBackends/Metal/MTLMain.mm @@ -54,6 +54,7 @@ static bool WindowSystemTypeSupportsMetal(WindowSystemType type) switch (type) { case WindowSystemType::MacOS: + case WindowSystemType::Headless: return true; default: return false; @@ -64,7 +65,8 @@ bool Metal::VideoBackend::Initialize(const WindowSystemInfo& wsi) { @autoreleasepool { - if (!WindowSystemTypeSupportsMetal(wsi.type) || !wsi.render_surface) + const bool surface_ok = wsi.type == WindowSystemType::Headless || wsi.render_surface; + if (!WindowSystemTypeSupportsMetal(wsi.type) || !surface_ok) { PanicAlertFmt("Bad WindowSystemInfo for Metal renderer."); return false; @@ -100,6 +102,8 @@ bool Metal::VideoBackend::Initialize(const WindowSystemInfo& wsi) [layer setPixelFormat:MTLPixelFormatBGRA8Unorm]; CGSize size = [layer bounds].size; float scale = [layer contentsScale]; + if (!layer) // headless + scale = 1.0; ObjectCache::Initialize(std::move(adapter)); g_state_tracker = std::make_unique();