marco1475
marco1475

Reputation: 55

OSX Fullscreen (Kiosk) Application with Custom Resolution

I have an OS X Metal application that I would like to run in fullscreen at a non-native resolution, e.g. my native resolution is 1920x1080 and I would like to render the app in fullscreen at 1024x768. (I don't believe that using Metal to draw things impacts this question other than I am unable to use the OpenGL-specific NSView functions.)

My renderer uses a back buffer with a hard-coded size of 1024x768.

When I create my window with bounds = 1024x768 I get a fullscreen window, but my content is drawn centered and it does not stretch to fill the whole screen.

When I create my window with bounds = 1920x1080 I get a fullscreen window, but my content is drawn in the upper-left corner and incorrectly scaled (because of the ratio mismatch between the two resolutions).

Using [NSView - enterFullScreenMode:withOptions:] yielded the same results. Setting [NSView autoresizingMask] didn't change anything either.

Ideally I want the window to be the size of the screen and have the low-resolution back buffer be stretched to fill the whole window. What am I missing that would allow me to do that?

The relevant app initialization from my 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];

Thanks.

Upvotes: 2

Views: 426

Answers (1)

warrenm
warrenm

Reputation: 31782

The layer that backs a view is constrained to have its frame equal to that view's bounds. By default, the drawableSize of a CAMetalLayer is equal to its bounds times its contents scale. However, you can set it to any size you desire by explicitly setting the layer's drawableSize.

Upvotes: 2

Related Questions