Merge pull request #11247 from tellowkrinkle/MetalHeadless

VideoBackends:Metal: Headless render support
This commit is contained in:
Admiral H. Curtiss 2022-11-04 23:10:39 +01:00 committed by GitHub
commit c2e6d85ba7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -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<StateTracker>();