comparison mac/dw.m @ 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
comparison
equal deleted inserted replaced
1953:77d156c3f01c 1954:85229fe9ae5a
613 NSFont *DWDefaultFont; 613 NSFont *DWDefaultFont;
614 DWTimerHandler *DWHandler; 614 DWTimerHandler *DWHandler;
615 #if !defined(GARBAGE_COLLECT) 615 #if !defined(GARBAGE_COLLECT)
616 NSAutoreleasePool *pool; 616 NSAutoreleasePool *pool;
617 #endif 617 #endif
618 #ifndef BUILDING_FOR_MOJAVE 618 #ifdef BUILDING_FOR_MOJAVE
619 NSMutableArray *_DWDirtyDrawables;
620 #else
619 HWND _DWLastDrawable; 621 HWND _DWLastDrawable;
620 #endif 622 #endif
621 HMTX DWRunMutex; 623 HMTX DWRunMutex;
622 HMTX DWThreadMutex; 624 HMTX DWThreadMutex;
623 HMTX DWThreadMutex2; 625 HMTX DWThreadMutex2;
890 if(!cachedDrawingRep) 892 if(!cachedDrawingRep)
891 { 893 {
892 cachedDrawingRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds]; 894 cachedDrawingRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
893 [cachedDrawingRep retain]; 895 [cachedDrawingRep retain];
894 } 896 }
895 self.needsDisplay = YES; 897 /* Mark this render dirty if something is requesting it to draw */
898 if(![_DWDirtyDrawables containsObject:self])
899 [_DWDirtyDrawables addObject:self];
896 return cachedDrawingRep; 900 return cachedDrawingRep;
897 } 901 }
898 #endif 902 #endif
899 -(void)mouseDown:(NSEvent *)theEvent 903 -(void)mouseDown:(NSEvent *)theEvent
900 { 904 {
909 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } 913 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); }
910 -(void)drawRect:(NSRect)rect { 914 -(void)drawRect:(NSRect)rect {
911 _event_handler(self, nil, 7); 915 _event_handler(self, nil, 7);
912 #ifdef BUILDING_FOR_MOJAVE 916 #ifdef BUILDING_FOR_MOJAVE
913 if (cachedDrawingRep) 917 if (cachedDrawingRep)
918 {
914 [cachedDrawingRep drawInRect:self.bounds]; 919 [cachedDrawingRep drawInRect:self.bounds];
920 [_DWDirtyDrawables removeObject:self];
921 }
915 #endif 922 #endif
916 } 923 }
917 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } 924 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); }
918 -(BOOL)isFlipped { return YES; } 925 -(BOOL)isFlipped { return YES; }
919 -(void)dealloc { 926 -(void)dealloc {
921 _remove_userdata(&root, NULL, TRUE); 928 _remove_userdata(&root, NULL, TRUE);
922 [font release]; 929 [font release];
923 dw_signal_disconnect_by_window(self); 930 dw_signal_disconnect_by_window(self);
924 #ifdef BUILDING_FOR_MOJAVE 931 #ifdef BUILDING_FOR_MOJAVE
925 [cachedDrawingRep release]; 932 [cachedDrawingRep release];
933 [_DWDirtyDrawables removeObject:self];
926 #endif 934 #endif
927 [super dealloc]; 935 [super dealloc];
928 } 936 }
929 -(BOOL)acceptsFirstResponder { return YES; } 937 -(BOOL)acceptsFirstResponder { return YES; }
930 @end 938 @end
1043 #endif 1051 #endif
1044 free(bltinfo); 1052 free(bltinfo);
1045 } 1053 }
1046 -(void)doFlush:(id)param 1054 -(void)doFlush:(id)param
1047 { 1055 {
1048 #ifndef BUILDING_FOR_MOJAVE 1056 #ifdef BUILDING_FOR_MOJAVE
1057 NSEnumerator *enumerator = [_DWDirtyDrawables objectEnumerator];
1058 DWRender *rend;
1059
1060 while (rend = [enumerator nextObject])
1061 rend.needsDisplay = YES;
1062 [_DWDirtyDrawables removeAllObjects];
1063 #else
1049 if(_DWLastDrawable) 1064 if(_DWLastDrawable)
1050 { 1065 {
1051 id object = _DWLastDrawable; 1066 id object = _DWLastDrawable;
1052 NSWindow *window = [object window]; 1067 NSWindow *window = [object window];
1053 [window flushWindow]; 1068 [window flushWindow];
1069 _DWLastDrawable = nil;
1054 } 1070 }
1055 #endif 1071 #endif
1056 } 1072 }
1057 -(void)doWindowFunc:(id)param 1073 -(void)doWindowFunc:(id)param
1058 { 1074 {
11404 DWDefaultFont = nil; 11420 DWDefaultFont = nil;
11405 /* Create mutexes for thread safety */ 11421 /* Create mutexes for thread safety */
11406 DWRunMutex = dw_mutex_new(); 11422 DWRunMutex = dw_mutex_new();
11407 DWThreadMutex = dw_mutex_new(); 11423 DWThreadMutex = dw_mutex_new();
11408 DWThreadMutex2 = dw_mutex_new(); 11424 DWThreadMutex2 = dw_mutex_new();
11425 #ifdef BUILDING_FOR_MOJAVE
11426 _DWDirtyDrawables = [[NSMutableArray alloc] init];
11427 #endif
11409 /* Use NSThread to start a dummy thread to initialize the threading subsystem */ 11428 /* Use NSThread to start a dummy thread to initialize the threading subsystem */
11410 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil]; 11429 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil];
11411 [thread start]; 11430 [thread start];
11412 [thread release]; 11431 [thread release];
11413 [NSTextField setCellClass:[DWTextFieldCell class]]; 11432 [NSTextField setCellClass:[DWTextFieldCell class]];