OSX 具有自定义分辨率的全屏(Kiosk)应用程序

OSX Fullscreen (Kiosk) Application with Custom Resolution

我有一个 OS X Metal 应用程序,我想 运行 在非本地分辨率下全屏显示,例如我的原始分辨率是 1920x1080,我想以 1024x768 全屏呈现应用程序。 (我不认为使用 Metal 来绘制东西会影响这个问题,除了我无法使用 OpenGL 特定的 NSView 函数。)

我的渲染器使用硬编码大小为 1024x768 的后台缓冲区。

当我用 bounds = 1024x768 创建我的 window 时,我得到了全屏 window,但我的内容是居中绘制的,它不会拉伸以填满整个屏幕。

当我用 bounds = 1920x1080 创建 window 时,我得到了全屏 window,但是我的内容绘制在左上角并且缩放不正确(因为比例不匹配在两个决议之间)。

使用[NSView - enterFullScreenMode:withOptions:] 产生了相同的结果。设置 [NSView autoresizingMask] 也没有任何改变。

理想情况下,我希望 window 与屏幕大小相同,并拉伸低分辨率后台缓冲区以填满整个 window。我错过了什么能让我做到这一点?

来自我的相关应用初始化 NSResponder <NSApplicationDelegate>:

// Create the window
self.Window = [NSWindow alloc];
[self.Window initWithContentRect:bounds
                       styleMask:NSBorderlessWindowMask
                         backing:NSBackingStoreBuffered
                           defer:YES];

// Create the view
self.View = [NSView alloc];
[self.View initWithFrame:bounds];
[self.View setWantsLayer:YES];    // The generated layer is CAMetalLayer

// Associate the view with the window
[self.Window setContentView:self.View];

// Misc
[self.Window makeKeyAndOrderFront:self.Window];
[self.Window setAcceptsMouseMovedEvents:YES];
[self.Window setHidesOnDeactivate:YES];

// Fullscreen
[self.Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
[self.Window toggleFullScreen:nil];
[self.Window makeFirstResponder:self.View];

谢谢。

支持视图的图层被限制为使其框架等于该视图的边界。默认情况下,CAMetalLayerdrawableSize 等于其边界乘以其内容比例。但是,您可以通过显式设置图层的 drawableSize.

将其设置为您想要的任何大小