emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/ns/performance d39b5ff 2/4: Improve performance of scrolling on


From: Alan Third
Subject: scratch/ns/performance d39b5ff 2/4: Improve performance of scrolling on NS
Date: Sun, 20 Dec 2020 05:47:51 -0500 (EST)

branch: scratch/ns/performance
commit d39b5ffcad5f02a33f49f921f4bcc6bafcda03f2
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 d48cf2e..04595bb 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -8523,32 +8523,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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]