Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically checking display depth for Mac client #1542

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Comment on lines +299 to +318
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct brace newline style?


@end
1 change: 1 addition & 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,7 @@ - (id)init
styleMask:windowStyle
backing:NSBackingStoreBuffered
defer:NO];
window.depthLimit = NSWindowDepthSixtyfourBitRGB;
window.backgroundColor = NSColor.blackColor;

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