@@ -593,18 +593,22 @@ - (void)drawRect:(NSRect)rect
593593
594594 [drawData removeAllObjects ];
595595
596- CGLayerRef l = [self getLayer ];
597-
598- /* during a live resize, we will have around a stale layer until the
599- * refresh messages travel back from the vim process. we push the old
600- * layer in at an offset to get rid of jitter due to lines changing position. */
601-
602- CGSize layerSize = CGLayerGetSize (l);
603- CGSize frameSize = [self frame ].size ;
604- NSRect drawRect = NSMakeRect (0 , frameSize.height - layerSize.height , layerSize.width , layerSize.height );
605-
606- CGContextDrawLayerInRect ([context graphicsPort ], drawRect, l);
607-
596+ if (cgLayerEnabled) {
597+ // during a live resize, we will have around a stale layer until the
598+ // refresh messages travel back from the vim process. We push the old
599+ // layer in at an offset to get rid of jitter due to lines changing
600+ // position.
601+ CGLayerRef l = [self getCGLayer ];
602+ CGSize cgLayerSize = CGLayerGetSize (l);
603+ CGSize frameSize = [self frame ].size ;
604+ NSRect drawRect = NSMakeRect (
605+ 0 ,
606+ frameSize.height - cgLayerSize.height ,
607+ cgLayerSize.width ,
608+ cgLayerSize.height );
609+
610+ CGContextDrawLayerInRect ([context graphicsPort ], drawRect, l);
611+ }
608612}
609613
610614- (void )performBatchDrawWithData : (NSData *)data
@@ -618,30 +622,44 @@ - (void)performBatchDrawWithData:(NSData *)data
618622 [self display ];
619623}
620624
621- - (void )releaseLayer
625+ - (void )setCGLayerEnabled : (BOOL )enabled
626+ {
627+ cgLayerEnabled = enabled;
628+
629+ if (!cgLayerEnabled)
630+ [self releaseCGLayer ];
631+ }
632+
633+ - (void )releaseCGLayer
622634{
623- if (layer ) {
624- CGLayerRelease (layer );
625- layer = nil ;
626- layerContext = nil ;
627- }
635+ if (cgLayer ) {
636+ CGLayerRelease (cgLayer );
637+ cgLayer = nil ;
638+ cgLayerContext = nil ;
639+ }
628640}
629- - (CGLayerRef)getLayer
641+
642+ - (CGLayerRef)getCGLayer
630643{
631- if (!layer) {
644+ NSParameterAssert (cgLayerEnabled);
645+ if (!cgLayer) {
632646 NSGraphicsContext *context = [NSGraphicsContext currentContext ];
633647 NSRect frame = [self frame ];
634- layer = CGLayerCreateWithContext ([context graphicsPort ], frame.size , NULL );
648+ cgLayer = CGLayerCreateWithContext (
649+ [context graphicsPort ], frame.size , NULL );
635650 }
636- return layer ;
651+ return cgLayer ;
637652}
638653
639- - (CGContextRef)getLayerContext
654+ - (CGContextRef)getCGContext
640655{
641- if (!layerContext)
642- layerContext = CGLayerGetContext ([self getLayer ]);
643-
644- return layerContext;
656+ if (cgLayerEnabled) {
657+ if (!cgLayerContext)
658+ cgLayerContext = CGLayerGetContext ([self getCGLayer ]);
659+ return cgLayerContext;
660+ } else {
661+ return [[NSGraphicsContext currentContext ] graphicsPort ];
662+ }
645663}
646664
647665
@@ -948,13 +966,18 @@ - (void)batchDrawData:(NSData *)data
948966 column: col
949967 numRows: height
950968 numColumns: width];
951-
952- CGContextRef context = [self getLayerContext ];
953- CGImageRef cgImage = [signImg CGImageForProposedRect: &r
954- context: nil
955- hints: nil ];
956-
957- CGContextDrawImage (context, r, cgImage);
969+ if (cgLayerEnabled) {
970+ CGContextRef context = [self getCGContext ];
971+ CGImageRef cgImage = [signImg CGImageForProposedRect: &r
972+ context: nil
973+ hints: nil ];
974+ CGContextDrawImage (context, r, cgImage);
975+ } else {
976+ [signImg drawInRect: r
977+ fromRect: NSZeroRect
978+ operation: NSCompositingOperationSourceOver
979+ fraction: 1.0 ];
980+ }
958981 } else if (DrawStringDrawType == type) {
959982 int bg = *((int *)bytes); bytes += sizeof (int );
960983 int fg = *((int *)bytes); bytes += sizeof (int );
@@ -1060,7 +1083,7 @@ - (void)batchDrawData:(NSData *)data
10601083#endif
10611084}
10621085
1063- static CTFontRef
1086+ static CTFontRef
10641087lookupFont (NSMutableArray *fontCache, const unichar *chars, UniCharCount count,
10651088 CTFontRef currFontRef)
10661089{
@@ -1337,7 +1360,7 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
13371360 withFlags : (int )flags foregroundColor : (int )fg
13381361 backgroundColor : (int )bg specialColor : (int )sp
13391362{
1340- CGContextRef context = [self getLayerContext ];
1363+ CGContextRef context = [self getCGContext ];
13411364 NSRect frame = [self bounds ];
13421365 float x = col*cellSize.width + insetSize.width ;
13431366 float y = frame.size .height - insetSize.height - (1 +row)*cellSize.height ;
@@ -1455,16 +1478,22 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
14551478
14561479- (void )scrollRect : (NSRect )rect lineCount : (int )count
14571480{
1458- CGContextRef context = [self getLayerContext ];
1459- int yOffset = count * cellSize.height ;
1460- NSRect clipRect = rect;
1461- clipRect.origin .y -= yOffset;
1462-
1463- /* draw self on top of self, offset so as to "scroll" lines vertically. */
1464- CGContextSaveGState (context);
1465- CGContextClipToRect (context, clipRect);
1466- CGContextDrawLayerAtPoint (context, CGPointMake (0 , -yOffset), [self getLayer ]);
1467- CGContextRestoreGState (context);
1481+ if (cgLayerEnabled) {
1482+ CGContextRef context = [self getCGContext ];
1483+ int yOffset = count * cellSize.height ;
1484+ NSRect clipRect = rect;
1485+ clipRect.origin .y -= yOffset;
1486+
1487+ // draw self on top of self, offset so as to "scroll" lines vertically
1488+ CGContextSaveGState (context);
1489+ CGContextClipToRect (context, clipRect);
1490+ CGContextDrawLayerAtPoint (
1491+ context, CGPointMake (0 , -yOffset), [self getCGLayer ]);
1492+ CGContextRestoreGState (context);
1493+ } else {
1494+ NSSize delta={0 , -count * cellSize.height };
1495+ [self scrollRect: rect by: delta];
1496+ }
14681497}
14691498
14701499- (void )deleteLinesFromRow : (int )row lineCount : (int )count
@@ -1506,7 +1535,7 @@ - (void)insertLinesAtRow:(int)row lineCount:(int)count
15061535- (void )clearBlockFromRow : (int )row1 column : (int )col1 toRow : (int )row2
15071536 column : (int )col2 color : (int )color
15081537{
1509- CGContextRef context = [self getLayerContext ];
1538+ CGContextRef context = [self getCGContext ];
15101539 NSRect rect = [self rectFromRow: row1 column: col1 toRow: row2 column: col2];
15111540
15121541 CGContextSetRGBFillColor (context, RED (color), GREEN (color), BLUE (color),
@@ -1519,8 +1548,8 @@ - (void)clearBlockFromRow:(int)row1 column:(int)col1 toRow:(int)row2
15191548
15201549- (void )clearAll
15211550{
1522- [self releaseLayer ];
1523- CGContextRef context = [self getLayerContext ];
1551+ [self releaseCGLayer ];
1552+ CGContextRef context = [self getCGContext ];
15241553 NSRect rect = [self bounds ];
15251554 float r = [defaultBackgroundColor redComponent ];
15261555 float g = [defaultBackgroundColor greenComponent ];
@@ -1536,7 +1565,7 @@ - (void)clearAll
15361565- (void )drawInsertionPointAtRow : (int )row column : (int )col shape : (int )shape
15371566 fraction : (int )percent color : (int )color
15381567{
1539- CGContextRef context = [self getLayerContext ];
1568+ CGContextRef context = [self getCGContext ];
15401569 NSRect rect = [self rectForRow: row column: col numRows: 1 numColumns: 1 ];
15411570
15421571 CGContextSaveGState (context);
@@ -1585,7 +1614,7 @@ - (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows
15851614 numColumns : (int )ncols
15861615{
15871616 // TODO: THIS CODE HAS NOT BEEN TESTED!
1588- CGContextRef cgctx = [self getLayerContext ];
1617+ CGContextRef cgctx = [self getCGContext ];
15891618 CGContextSaveGState (cgctx);
15901619 CGContextSetBlendMode (cgctx, kCGBlendModeDifference );
15911620 CGContextSetRGBFillColor (cgctx, 1.0 , 1.0 , 1.0 , 1.0 );
0 commit comments