changeset 1954:85229fe9ae5a

Mac: 10.14 doesn't like too many needsDisplays so instead we keep a list of dirty drawables, and only set needsDisplay when dw_flush() is called. We remove the drawable from the dirty list when it is actually drawn.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 12 Jul 2019 17:41:13 +0000
parents 77d156c3f01c
children 91541efcea10
files mac/dw.m
diffstat 1 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Fri Jul 12 02:03:09 2019 +0000
+++ b/mac/dw.m	Fri Jul 12 17:41:13 2019 +0000
@@ -615,7 +615,9 @@
 #if !defined(GARBAGE_COLLECT)
 NSAutoreleasePool *pool;
 #endif
-#ifndef BUILDING_FOR_MOJAVE
+#ifdef BUILDING_FOR_MOJAVE
+NSMutableArray *_DWDirtyDrawables;
+#else
 HWND _DWLastDrawable;
 #endif
 HMTX DWRunMutex;
@@ -892,7 +894,9 @@
         cachedDrawingRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
         [cachedDrawingRep retain];
     }
-    self.needsDisplay = YES;
+    /* Mark this render dirty if something is requesting it to draw */
+    if(![_DWDirtyDrawables containsObject:self])
+        [_DWDirtyDrawables addObject:self];
     return cachedDrawingRep;
 }
 #endif
@@ -911,7 +915,10 @@
     _event_handler(self, nil, 7);
 #ifdef BUILDING_FOR_MOJAVE
     if (cachedDrawingRep)
+    {
         [cachedDrawingRep drawInRect:self.bounds];
+        [_DWDirtyDrawables removeObject:self];
+    }
 #endif
 }
 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); }
@@ -923,6 +930,7 @@
     dw_signal_disconnect_by_window(self);
 #ifdef BUILDING_FOR_MOJAVE
     [cachedDrawingRep release];
+    [_DWDirtyDrawables removeObject:self];
 #endif
     [super dealloc];
 }
@@ -1045,12 +1053,20 @@
 }
 -(void)doFlush:(id)param
 {
-#ifndef BUILDING_FOR_MOJAVE
+#ifdef BUILDING_FOR_MOJAVE
+    NSEnumerator *enumerator = [_DWDirtyDrawables objectEnumerator];
+    DWRender *rend;
+    
+    while (rend = [enumerator nextObject])
+        rend.needsDisplay = YES;
+    [_DWDirtyDrawables removeAllObjects];
+#else
     if(_DWLastDrawable)
     {
         id object = _DWLastDrawable;
         NSWindow *window = [object window];
         [window flushWindow];
+        _DWLastDrawable = nil;
     }
 #endif
 }
@@ -11406,6 +11422,9 @@
     DWRunMutex = dw_mutex_new();
     DWThreadMutex = dw_mutex_new();
     DWThreadMutex2 = dw_mutex_new();
+#ifdef BUILDING_FOR_MOJAVE
+    _DWDirtyDrawables = [[NSMutableArray alloc] init];
+#endif
     /* Use NSThread to start a dummy thread to initialize the threading subsystem */
     NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil];
     [thread start];