[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/ns/performance ee74dc5 2/6: Improve performance of scrolling on
From: |
Alan Third |
Subject: |
scratch/ns/performance ee74dc5 2/6: Improve performance of scrolling on NS |
Date: |
Thu, 31 Dec 2020 10:45:19 -0500 (EST) |
branch: scratch/ns/performance
commit ee74dc593b02f4fe8ee234c9ce80b389d682089c
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 9949664..9fea83d 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -8421,32 +8421,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
- branch scratch/ns/performance created (now 6312a8e), Alan Third, 2020/12/31
- scratch/ns/performance 9be0f08 1/6: Improve drawing performance on macOS, Alan Third, 2020/12/31
- scratch/ns/performance 690bb68 3/6: Fix problems with reusing IOSurfaces, Alan Third, 2020/12/31
- scratch/ns/performance 77a07a2 4/6: Fix GNUstep warnings, Alan Third, 2020/12/31
- scratch/ns/performance 6312a8e 6/6: Change pixel format, Alan Third, 2020/12/31
- scratch/ns/performance aeb2475 5/6: Fix EmacsSurface definitions, Alan Third, 2020/12/31
- scratch/ns/performance ee74dc5 2/6: Improve performance of scrolling on NS,
Alan Third <=