Browse Source

Get rid of the flickering that occurs on Mojave as a result of changes in the way AppKit handles view layers.

Donny Lawrence 7 years ago
parent
commit
8a0f438156
1 changed files with 15 additions and 0 deletions
  1. 15 0
      panda/src/cocoadisplay/cocoaPandaView.mm

+ 15 - 0
panda/src/cocoadisplay/cocoaPandaView.mm

@@ -26,6 +26,10 @@
   [self setCanDrawConcurrently:YES];
   [self setCanDrawConcurrently:YES];
 #endif
 #endif
 
 
+  // If a layer ends up becoming attached to the view, tell AppKit we'll manage
+  // the redrawing since we're doing things our own way.
+  self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawNever;
+
   cocoadisplay_cat.debug()
   cocoadisplay_cat.debug()
     << "Created CocoaPandaView " << self << " for GraphicsWindow " << window << "\n";
     << "Created CocoaPandaView " << self << " for GraphicsWindow " << window << "\n";
   _graphicsWindow = window;
   _graphicsWindow = window;
@@ -167,4 +171,15 @@
 - (BOOL) isOpaque {
 - (BOOL) isOpaque {
   return YES;
   return YES;
 }
 }
+
+-(void)setLayer:(CALayer*)layer
+{
+    [super setLayer:layer];
+
+    // Starting in macOS 10.14, a CALayer will still be attached to a view even
+    // if `wantsLayer` is false. If we don't update the context now, only a
+    // black screen will be rendered until the context is updated some other
+    // way (like through a window resize event).
+    [_context update];
+}
 @end
 @end