The content view's layer can have internal sublayers from Cocoa, so assuming anything about the hierarchy is dangerous and can result in us removing backing layers for visible content.
---
Fixes solid grey fullscreen windows in some games. It's not clear to me why the content view layer only sometimes has sublayers; it may be a macOS version difference or something, but either way we should not assume anything about what's going on in there.
From: Tim Clem tclem@codeweavers.com
The content view's layer can have internal sublayers from Cocoa, so assuming anything about the hierarchy is dangerous and can result in us removing backing layers for visible content. --- dlls/winemac.drv/cocoa_window.m | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m index 2dd7d180c24..abfd3e3919c 100644 --- a/dlls/winemac.drv/cocoa_window.m +++ b/dlls/winemac.drv/cocoa_window.m @@ -414,6 +414,8 @@ @interface WineWindow ()
@property (readonly, copy, nonatomic) NSArray* childWineWindows;
+@property (retain, nonatomic) CAShapeLayer* contentViewMaskLayer; + - (void) setShape:(CGPathRef)newShape;
- (void) updateForGLSubviews; @@ -1013,6 +1015,7 @@ @implementation WineWindow @synthesize shapeChangedSinceLastDraw; @synthesize usePerPixelAlpha; @synthesize himc, commandDone; + @synthesize contentViewMaskLayer;
+ (WineWindow*) createWindowWithFeatures:(const struct macdrv_window_features*)wf windowFrame:(NSRect)window_frame @@ -1106,6 +1109,7 @@ - (void) dealloc [queue release]; [latentChildWindows release]; [latentParentWindow release]; + [contentViewMaskLayer release]; [super dealloc]; }
@@ -2780,12 +2784,15 @@ - (void) setMask:(CGRect)rect /* Draw black bars to cover every part of the window except for 'rect'. * Intended for use on a window covering the full screen. */ - if (CGRectIsEmpty(rect)) + if (self.contentViewMaskLayer) { - [[[self.contentView.layer sublayers] firstObject] removeFromSuperlayer]; - return; + [self.contentViewMaskLayer removeFromSuperlayer]; + self.contentViewMaskLayer = nil; }
+ if (CGRectIsEmpty(rect)) + return; + CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.bounds = self.contentView.layer.bounds; shapeLayer.position = self.contentView.layer.position; @@ -2815,11 +2822,8 @@ - (void) setMask:(CGRect)rect shapeLayer.path = path; CGPathRelease(path);
- if ([[self.contentView.layer sublayers] firstObject]) - [self.contentView.layer replaceSublayer:[[self.contentView.layer sublayers] firstObject] - with:shapeLayer]; - else - [self.contentView.layer addSublayer:shapeLayer]; + [self.contentView.layer addSublayer:shapeLayer]; + self.contentViewMaskLayer = shapeLayer; }
This merge request was approved by Brendan Shanks.