@@ -593,18 +593,22 @@ - (void)drawRect:(NSRect)rect
593
593
594
594
[drawData removeAllObjects ];
595
595
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
+ }
608
612
}
609
613
610
614
- (void )performBatchDrawWithData : (NSData *)data
@@ -618,30 +622,44 @@ - (void)performBatchDrawWithData:(NSData *)data
618
622
[self display ];
619
623
}
620
624
621
- - (void )releaseLayer
625
+ - (void )setCGLayerEnabled : (BOOL )enabled
626
+ {
627
+ cgLayerEnabled = enabled;
628
+
629
+ if (!cgLayerEnabled)
630
+ [self releaseCGLayer ];
631
+ }
632
+
633
+ - (void )releaseCGLayer
622
634
{
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
+ }
628
640
}
629
- - (CGLayerRef )getLayer
641
+
642
+ - (CGLayerRef )getCGLayer
630
643
{
631
- if (!layer) {
644
+ NSParameterAssert (cgLayerEnabled);
645
+ if (!cgLayer) {
632
646
NSGraphicsContext *context = [NSGraphicsContext currentContext ];
633
647
NSRect frame = [self frame ];
634
- layer = CGLayerCreateWithContext ([context graphicsPort ], frame.size , NULL );
648
+ cgLayer = CGLayerCreateWithContext (
649
+ [context graphicsPort ], frame.size , NULL );
635
650
}
636
- return layer ;
651
+ return cgLayer ;
637
652
}
638
653
639
- - (CGContextRef )getLayerContext
654
+ - (CGContextRef )getCGContext
640
655
{
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
+ }
645
663
}
646
664
647
665
@@ -948,13 +966,18 @@ - (void)batchDrawData:(NSData *)data
948
966
column: col
949
967
numRows: height
950
968
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
+ }
958
981
} else if (DrawStringDrawType == type) {
959
982
int bg = *((int *)bytes); bytes += sizeof (int );
960
983
int fg = *((int *)bytes); bytes += sizeof (int );
@@ -1060,7 +1083,7 @@ - (void)batchDrawData:(NSData *)data
1060
1083
#endif
1061
1084
}
1062
1085
1063
- static CTFontRef
1086
+ static CTFontRef
1064
1087
lookupFont (NSMutableArray *fontCache, const unichar *chars, UniCharCount count,
1065
1088
CTFontRef currFontRef)
1066
1089
{
@@ -1337,7 +1360,7 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
1337
1360
withFlags : (int )flags foregroundColor : (int )fg
1338
1361
backgroundColor : (int )bg specialColor : (int )sp
1339
1362
{
1340
- CGContextRef context = [self getLayerContext ];
1363
+ CGContextRef context = [self getCGContext ];
1341
1364
NSRect frame = [self bounds ];
1342
1365
float x = col*cellSize.width + insetSize.width ;
1343
1366
float y = frame.size .height - insetSize.height - (1 +row)*cellSize.height ;
@@ -1455,16 +1478,22 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
1455
1478
1456
1479
- (void )scrollRect : (NSRect )rect lineCount : (int )count
1457
1480
{
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
+ }
1468
1497
}
1469
1498
1470
1499
- (void )deleteLinesFromRow : (int )row lineCount : (int )count
@@ -1506,7 +1535,7 @@ - (void)insertLinesAtRow:(int)row lineCount:(int)count
1506
1535
- (void )clearBlockFromRow : (int )row1 column : (int )col1 toRow : (int )row2
1507
1536
column : (int )col2 color : (int )color
1508
1537
{
1509
- CGContextRef context = [self getLayerContext ];
1538
+ CGContextRef context = [self getCGContext ];
1510
1539
NSRect rect = [self rectFromRow: row1 column: col1 toRow: row2 column: col2];
1511
1540
1512
1541
CGContextSetRGBFillColor (context, RED (color), GREEN (color), BLUE (color),
@@ -1519,8 +1548,8 @@ - (void)clearBlockFromRow:(int)row1 column:(int)col1 toRow:(int)row2
1519
1548
1520
1549
- (void )clearAll
1521
1550
{
1522
- [self releaseLayer ];
1523
- CGContextRef context = [self getLayerContext ];
1551
+ [self releaseCGLayer ];
1552
+ CGContextRef context = [self getCGContext ];
1524
1553
NSRect rect = [self bounds ];
1525
1554
float r = [defaultBackgroundColor redComponent ];
1526
1555
float g = [defaultBackgroundColor greenComponent ];
@@ -1536,7 +1565,7 @@ - (void)clearAll
1536
1565
- (void )drawInsertionPointAtRow : (int )row column : (int )col shape : (int )shape
1537
1566
fraction : (int )percent color : (int )color
1538
1567
{
1539
- CGContextRef context = [self getLayerContext ];
1568
+ CGContextRef context = [self getCGContext ];
1540
1569
NSRect rect = [self rectForRow: row column: col numRows: 1 numColumns: 1 ];
1541
1570
1542
1571
CGContextSaveGState (context);
@@ -1585,7 +1614,7 @@ - (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows
1585
1614
numColumns : (int )ncols
1586
1615
{
1587
1616
// TODO: THIS CODE HAS NOT BEEN TESTED!
1588
- CGContextRef cgctx = [self getLayerContext ];
1617
+ CGContextRef cgctx = [self getCGContext ];
1589
1618
CGContextSaveGState (cgctx);
1590
1619
CGContextSetBlendMode (cgctx, kCGBlendModeDifference );
1591
1620
CGContextSetRGBFillColor (cgctx, 1.0 , 1.0 , 1.0 , 1.0 );
0 commit comments