aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/nsterm.m27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/nsterm.m b/src/nsterm.m
index e5917f902f9..6b6ad0c016c 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -9716,6 +9716,7 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
9716 probably be some sort of pruning job that removes excess 9716 probably be some sort of pruning job that removes excess
9717 surfaces. */ 9717 surfaces. */
9718 9718
9719#define CACHE_MAX_SIZE 2
9719 9720
9720- (id) initWithSize: (NSSize)s 9721- (id) initWithSize: (NSSize)s
9721 ColorSpace: (CGColorSpaceRef)cs 9722 ColorSpace: (CGColorSpaceRef)cs
@@ -9725,7 +9726,7 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
9725 9726
9726 [super init]; 9727 [super init];
9727 9728
9728 cache = [[NSMutableArray arrayWithCapacity:3] retain]; 9729 cache = [[NSMutableArray arrayWithCapacity:CACHE_MAX_SIZE] retain];
9729 size = s; 9730 size = s;
9730 colorSpace = cs; 9731 colorSpace = cs;
9731 scale = scl; 9732 scale = scl;
@@ -9741,8 +9742,6 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
9741 9742
9742 if (currentSurface) 9743 if (currentSurface)
9743 CFRelease (currentSurface); 9744 CFRelease (currentSurface);
9744 if (lastSurface)
9745 CFRelease (lastSurface);
9746 9745
9747 for (id object in cache) 9746 for (id object in cache)
9748 CFRelease ((IOSurfaceRef)object); 9747 CFRelease ((IOSurfaceRef)object);
@@ -9765,7 +9764,7 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
9765 calls cannot be nested. */ 9764 calls cannot be nested. */
9766- (CGContextRef) getContext 9765- (CGContextRef) getContext
9767{ 9766{
9768 NSTRACE ("[EmacsSurface getContextWithSize:]"); 9767 NSTRACE ("[EmacsSurface getContext]");
9769 9768
9770 if (!context) 9769 if (!context)
9771 { 9770 {
@@ -9783,7 +9782,15 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
9783 } 9782 }
9784 } 9783 }
9785 9784
9786 if (!surface) 9785 if (!surface && [cache count] >= CACHE_MAX_SIZE)
9786 {
9787 /* Just grab the first one off the cache. This may result
9788 in tearing effects. The alternative is to wait for one
9789 of the surfaces to become free. */
9790 surface = (IOSurfaceRef)[cache firstObject];
9791 [cache removeObject:(id)surface];
9792 }
9793 else if (!surface)
9787 { 9794 {
9788 int bytesPerRow = IOSurfaceAlignProperty (kIOSurfaceBytesPerRow, 9795 int bytesPerRow = IOSurfaceAlignProperty (kIOSurfaceBytesPerRow,
9789 size.width * 4); 9796 size.width * 4);
@@ -9837,11 +9844,8 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
9837 if (lockStatus != kIOReturnSuccess) 9844 if (lockStatus != kIOReturnSuccess)
9838 NSLog (@"Failed to unlock surface: %x", lockStatus); 9845 NSLog (@"Failed to unlock surface: %x", lockStatus);
9839 9846
9840 /* Put lastSurface back on the end of the cache. It may not have 9847 /* Put currentSurface back on the end of the cache. */
9841 been displayed on the screen yet, but we probably want the new 9848 [cache addObject:(id)currentSurface];
9842 data and not some stale data anyway. */
9843 if (lastSurface)
9844 [cache addObject:(id)lastSurface];
9845 lastSurface = currentSurface; 9849 lastSurface = currentSurface;
9846 currentSurface = NULL; 9850 currentSurface = NULL;
9847} 9851}
@@ -9866,7 +9870,7 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
9866 9870
9867 NSTRACE ("[EmacsSurface copyContentsTo:]"); 9871 NSTRACE ("[EmacsSurface copyContentsTo:]");
9868 9872
9869 if (! lastSurface) 9873 if (!lastSurface || lastSurface == destination)
9870 return; 9874 return;
9871 9875
9872 lockStatus = IOSurfaceLock (lastSurface, kIOSurfaceLockReadOnly, nil); 9876 lockStatus = IOSurfaceLock (lastSurface, kIOSurfaceLockReadOnly, nil);
@@ -9886,6 +9890,7 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c)
9886 NSLog (@"Failed to unlock source surface: %x", lockStatus); 9890 NSLog (@"Failed to unlock source surface: %x", lockStatus);
9887} 9891}
9888 9892
9893#undef CACHE_MAX_SIZE
9889 9894
9890@end /* EmacsSurface */ 9895@end /* EmacsSurface */
9891 9896