[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/ns/performance a1b42b4 2/5: Improve performance of scrolling on
From: |
Alan Third |
Subject: |
scratch/ns/performance a1b42b4 2/5: Improve performance of scrolling on NS |
Date: |
Sun, 27 Dec 2020 12:20:24 -0500 (EST) |
branch: scratch/ns/performance
commit a1b42b43e2eac1602b0e995552c5a6ce602a0f0a
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>
Improve performance of scrolling on NS
* src/nsterm.m ([EmacsView copyRect:to:]): Use memcpy to copy bits
around instead of using NS image functions.
---
src/nsterm.m | 44 +++++++++++++++++++-------------------------
1 file changed, 19 insertions(+), 25 deletions(-)
diff --git a/src/nsterm.m b/src/nsterm.m
index 4b32531..dbae137 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -8420,32 +8420,26 @@ not_in_argv (NSString *arg)
if ([self wantsUpdateLayer])
{
#endif
- CGImageRef copy;
- NSRect frame = [self frame];
- NSAffineTransform *setOrigin = [NSAffineTransform transform];
-
- [[NSGraphicsContext currentContext] saveGraphicsState];
-
- /* Set the clipping before messing with the buffer's
- orientation. */
- NSRectClip (dstRect);
-
- /* Unflip the buffer as the copied image will be unflipped, and
- offset the top left so when we draw back into the buffer the
- correct part of the image is drawn. */
- CGContextScaleCTM(drawingBuffer, 1, -1);
- CGContextTranslateCTM(drawingBuffer,
- NSMinX (dstRect) - NSMinX (srcRect),
- -NSHeight (frame) - (NSMinY (dstRect) - NSMinY
(srcRect)));
-
- /* Take a copy of the buffer and then draw it back to the buffer,
- limited by the clipping rectangle. */
- copy = CGBitmapContextCreateImage (drawingBuffer);
- CGContextDrawImage (drawingBuffer, frame, copy);
-
- CGImageRelease (copy);
+ double scale = [[self window] backingScaleFactor];
+ int bpe = IOSurfaceGetBytesPerElement (surface);
+ void *pixels = IOSurfaceGetBaseAddress (surface);
+ int rowSize = IOSurfaceGetBytesPerRow (surface);
+ int srcRowSize = NSWidth (srcRect) * scale * bpe;
+ void *srcPixels = pixels + (int)(NSMinY (srcRect) * scale * rowSize +
NSMinX (srcRect) * scale * bpe);
+ void *dstPixels = pixels + (int)(NSMinY (dstRect) * scale * rowSize +
NSMinX (dstRect) * scale * bpe);
+
+ if (NSIntersectsRect (srcRect, dstRect)
+ && NSMinY (srcRect) < NSMinY (dstRect))
+ for (int y = NSHeight (srcRect) * scale - 1 ; y >= 0 ; y--)
+ memmove (dstPixels + y * rowSize,
+ srcPixels + y * rowSize,
+ srcRowSize);
+ else
+ for (int y = 0 ; y < NSHeight (srcRect) * scale ; y++)
+ memmove (dstPixels + y * rowSize,
+ srcPixels + y * rowSize,
+ srcRowSize);
- [[NSGraphicsContext currentContext] restoreGraphicsState];
[self setNeedsDisplayInRect:dstRect];
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101400