Skip to content

Commit dba6293

Browse files
committed
Make the Core Text renderer faster
This change reworks `MMCoreTextView` to keep track of the state of the screen instead of drawing to the screen or to an image. This lets `drawRect:` draw any part of the view at any time, as needed. This change came about when the old strategy stopped working: The old strategy calls `drawRect:` for the entire view to handle any draw command from the backend, but drew only the changes on top of the old content of the view. This did not work in new versions of macOS that use layers, because `drawRect:` is now expected to fill the entire rect with new content. If it doesn't, the rest of the view will just contain garbage. bbad3ed worked around this issue by adding an intermediate CGImage which was preserved between draws. This fixed the problem but made rendering slower. With the change, the intermediate image is no longer needed and rendering is much faster overall, which resolves macvim-dev#796. As part of this change, font substitution is now handled by Core Text, which changes which fallback fonts are used in some cases but matches other macOS apps.
1 parent 96a68b5 commit dba6293

14 files changed

+430
-1218
lines changed

src/MacVim/MMAppController.m

-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,6 @@ + (void)initialize
248248
[NSNumber numberWithBool:NO], MMSuppressTerminationAlertKey,
249249
[NSNumber numberWithBool:YES], MMNativeFullScreenKey,
250250
[NSNumber numberWithDouble:0.25], MMFullScreenFadeTimeKey,
251-
[NSNumber numberWithBool:NO], MMUseCGLayerAlwaysKey,
252-
@(shouldUseBufferedDrawing()), MMBufferedDrawingKey,
253251
[NSNumber numberWithBool:YES], MMShareFindPboardKey,
254252
nil];
255253

src/MacVim/MMCoreTextView.h

+3-35
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,13 @@
3131
BOOL antialias;
3232
BOOL ligatures;
3333
BOOL thinStrokes;
34-
BOOL drawPending;
35-
NSMutableArray *drawData;
3634

3735
MMTextViewHelper *helper;
3836

39-
unsigned maxlen;
40-
CGGlyph *glyphs;
41-
CGPoint *positions;
42-
NSMutableArray *fontCache;
43-
44-
// Issue draws onto an CGImage that caches the drawn results instead of
45-
// directly in drawRect:. This is the default behavior in cases where simply
46-
// drawing incrementally in drawRect: doesn't work. Those cases are:
47-
// 1. Non-native fullscreen
48-
// 2. 10.14+ (views are always layer-backed which means the view buffer will
49-
// be cleared and we can't incrementally draw in drawRect:)
50-
//
51-
// This can be configured by setting MMBufferedDrawingKey in user defaults.
52-
BOOL cgBufferDrawEnabled;
53-
BOOL cgBufferDrawNeedsUpdateContext;
54-
CGContextRef cgContext;
37+
NSMutableDictionary<NSNumber *, NSFont *> *fontVariants;
38+
NSMutableSet<NSString *> *characterStrings;
39+
NSMutableDictionary<NSNumber *,NSCache<NSString *,id> *> *characterLines;
5540

56-
// *Deprecated*
57-
// Draw onto a CGLayer instead of lazily updating the view's buffer in
58-
// drawRect: which is error-prone and relying on undocumented behaviors
59-
// (that the OS will preserve the old buffer).
60-
//
61-
// This is deprecated. Use cgBufferDrawEnabled instead which is more
62-
// efficient.
63-
//
64-
// This can be configured by setting MMUseCGLayerAlwaysKey in user defaults.
65-
BOOL cgLayerEnabled;
66-
CGLayerRef cgLayer;
67-
CGContextRef cgLayerContext;
68-
NSLock *cgLayerLock;
69-
7041
// These are used in MMCoreTextView+ToolTip.m
7142
id trackingRectOwner_; // (not retained)
7243
void *trackingRectUserData_;
@@ -113,13 +84,10 @@
11384
- (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column;
11485
- (NSRect)rectForRow:(int)row column:(int)column numRows:(int)nr
11586
numColumns:(int)nc;
116-
- (void)setCGLayerEnabled:(BOOL)enabled;
117-
- (BOOL)getCGLayerEnabled;
11887

11988
//
12089
// NSTextView methods
12190
//
122-
- (void)setFrameSize:(NSSize)newSize;
12391
- (void)keyDown:(NSEvent *)event;
12492
- (void)insertText:(id)string;
12593
- (void)doCommandBySelector:(SEL)selector;

0 commit comments

Comments
 (0)