Skip to content

Commit

Permalink
Dynamically checking display depth for Mac client
Browse files Browse the repository at this point in the history
  • Loading branch information
colincornaby committed Dec 11, 2023
1 parent 6491a18 commit 4e5f1d5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 35 additions & 1 deletion Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
@interface PLSView ()

@property NSTrackingArea* mouseTrackingArea;
@property id windowDidChangeObserver;

#if PLASMA_PIPELINE_METAL
@property(weak) CAMetalLayer* metalLayer;
#endif
Expand All @@ -79,13 +81,21 @@ - (id)initWithFrame:(NSRect)frameRect
CAMetalLayer* layer = [CAMetalLayer layer];
layer.contentsScale = [[NSScreen mainScreen] backingScaleFactor];
layer.maximumDrawableCount = 3;
layer.pixelFormat = MTLPixelFormatBGR10A2Unorm;
self.layer = self.metalLayer = layer;
#endif
self.layer.backgroundColor = NSColor.blackColor.CGColor;
[self configureLayerColorDepth];
self.windowDidChangeObserver = [NSNotificationCenter.defaultCenter addObserverForName:NSWindowDidChangeScreenNotification object:self.window queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull notification) {
[self configureLayerColorDepth];
}];
return self;
}

-(void)dealloc
{
[NSNotificationCenter.defaultCenter removeObserver:self.windowDidChangeObserver];
}

- (BOOL)acceptsFirstResponder
{
return YES;
Expand Down Expand Up @@ -283,4 +293,28 @@ - (void)resizeDrawable:(CGFloat)scaleFactor
scale:scaleFactor];
}

-(void)configureLayerColorDepth
{
NSWindow *window = self.window;
if (window)
{
NSDictionary<NSDeviceDescriptionKey, id> *windowProperties = [window deviceDescription];
NSUInteger bitsPerPixel = [windowProperties[NSDeviceBitsPerSample] unsignedIntValue];
#if PLASMA_PIPELINE_METAL
if (bitsPerPixel <=8)
{
if (self.metalLayer.pixelFormat != MTLPixelFormatBGRA8Unorm)
{
self.metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
}
} else {
if (self.metalLayer.pixelFormat != MTLPixelFormatBGR10A2Unorm)
{
self.metalLayer.pixelFormat = MTLPixelFormatBGR10A2Unorm;
}
}
#endif
}
}

@end
2 changes: 2 additions & 0 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ - (id)init
styleMask:windowStyle
backing:NSBackingStoreBuffered
defer:NO];
[window setDynamicDepthLimit:YES];
window.depthLimit = NSWindowDepthSixtyfourBitRGB;
window.backgroundColor = NSColor.blackColor;

PLSView* view = [[PLSView alloc] init];
Expand Down

0 comments on commit 4e5f1d5

Please sign in to comment.