From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#32932: 27.0.50; render bugs on macOS Mojave Date: Sun, 2 Feb 2020 22:30:52 +0000 Message-ID: <20200202223052.GA53567@breton.holly.idiocy.org> References: <2F867D49-6B1C-4CB5-A298-2A0E1BF45462@acm.org> <20200202134628.GB53430@breton.holly.idiocy.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="opJtzjQTFsWo+cga" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="46954"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Robert Pluim , 32932@debbugs.gnu.org To: Aaron Jensen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 02 23:32:14 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iyNmo-000C4A-5R for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 02 Feb 2020 23:32:14 +0100 Original-Received: from localhost ([::1]:60140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyNmm-0005Xj-VN for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 02 Feb 2020 17:32:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37481) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyNme-0005XQ-F6 for bug-gnu-emacs@gnu.org; Sun, 02 Feb 2020 17:32:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyNmc-0000xh-Lw for bug-gnu-emacs@gnu.org; Sun, 02 Feb 2020 17:32:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34718) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iyNmc-0000wm-EK for bug-gnu-emacs@gnu.org; Sun, 02 Feb 2020 17:32:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iyNmc-0006mJ-Bg for bug-gnu-emacs@gnu.org; Sun, 02 Feb 2020 17:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 02 Feb 2020 22:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32932 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 32932-submit@debbugs.gnu.org id=B32932.158068266825991 (code B ref 32932); Sun, 02 Feb 2020 22:32:02 +0000 Original-Received: (at 32932) by debbugs.gnu.org; 2 Feb 2020 22:31:08 +0000 Original-Received: from localhost ([127.0.0.1]:40691 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iyNlj-0006l8-GS for submit@debbugs.gnu.org; Sun, 02 Feb 2020 17:31:07 -0500 Original-Received: from mail-wr1-f46.google.com ([209.85.221.46]:35869) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iyNle-0006kZ-Lo for 32932@debbugs.gnu.org; Sun, 02 Feb 2020 17:31:04 -0500 Original-Received: by mail-wr1-f46.google.com with SMTP id z3so15612551wru.3 for <32932@debbugs.gnu.org>; Sun, 02 Feb 2020 14:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=SM30AKcop6vcEQslz3IcmrbajNAVTuYsyBamiFNYPOM=; b=DDVskGPLXZuvndO3VSz+g2eEQugPuroFjXEp+Xi0urKlrFEEEAldUN4ZeHMrGBhkc8 /X7LZTj28027uckKO3M07JJGoPaG3hIDyqymoD/WyKPNgsEKWRGyWgSB4KfGNM6qd6lY 6A0prAL6gVEbgKU/K80FR0tbkqmSyrgnF21wNQx/6yEt2vI2uaJtQUv2+aAOgwE73Od0 pdCtR1HG2RhAyT4j53KNjPHGDciQFl2qafnqA25EoqstXpLYluW7arle19xug7uZ4ulv +nxvYOujdS4KsGaKtLyz0FjhPXOOTm38NgwDqxIHNyG+dpqJ1gWIuBr+2AhpRQRhX0ao 5z8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=SM30AKcop6vcEQslz3IcmrbajNAVTuYsyBamiFNYPOM=; b=PIFFb9eSzpD6KriYKgxHw1+UnTZ+UaGy0s0rrI4fs7zNPzp+R0RFior+4//590F5H+ z9FZhXkW3a+9SyeSzIW2q9w8uHnG3fu2l/YY+ka7bWF4Brl+afSmDKUqcwyub1bNQIa6 PKikrkvA0tTqL6KpXVfFJ3VFK7fmRrqZhg/4Z4AYEUfdLubxLP+Ekr5u725uB5gn9DH+ 26CjkXWzyTDPValt4X+o/rHf6Rg5UMJ63Tk8DSTS3c1dOPkIbtS+VMglx8qqnEdM4hiC CynJQa3O5XGya3+DjBUbYYJ7VrLRsZuOefi+RoXGUSo2rPcDYgVSeDPt4mTOowPyO8LN lYJQ== X-Gm-Message-State: APjAAAXXr2jsI4M6/KZT/7Ot6zdmi4rd5uL61wxmK5PRHPXRuy+TB1uh RbG98p0mL9jAnSG66kGqBgc= X-Google-Smtp-Source: APXvYqxdX33PR2F8x6SdC4cOtm9VGQDG0BZR/bJAkhU5k8gLCpZmqoLHCdlBDJm+EGH8mcq8+VKwsw== X-Received: by 2002:adf:a50b:: with SMTP id i11mr10677746wrb.362.1580682655521; Sun, 02 Feb 2020 14:30:55 -0800 (PST) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-a08b-b269-65be-dd6a.holly.idiocy.org. [2001:8b0:3f8:8129:a08b:b269:65be:dd6a]) by smtp.gmail.com with ESMTPSA id z25sm20647285wmf.14.2020.02.02.14.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2020 14:30:54 -0800 (PST) Content-Disposition: inline In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:175617 Archived-At: --opJtzjQTFsWo+cga Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sun, Feb 02, 2020 at 08:49:44AM -0800, Aaron Jensen wrote: > On Sun, Feb 2, 2020 at 5:42 AM Alan Third wrote: > > > > Out of interest, is the mac port fast under the same conditions? Here > > their performance seems to be almost identical with the mac port only > > fractionally faster, and their performance scales similarly with frame > > size. > > For scrolling/full repaints the mac port is significantly faster, > similar to repaint speed of cursor moves. With the patch, Emacs 28's > full repaint when taking about 3/5s of my screen takes about 400ms > whereas it's about 16.7ms (60fps) with mac port. Emacs 27 seems to > paint even faster than that. Amazingly the attached patch is faster than the mac port on my machine (13" retina macbook pro) in the scroll test. I can’t see that holding for your screen, though. > On Sun, Feb 2, 2020 at 5:46 AM Alan Third wrote: > > > > > Cures the speed problems for me, but the text became fuzzy (MacBook Pro Retina). > > > Two Emacs instances, without and with the patch: > > > > Thanks for testing it. I think the fuzzyness is just the pre‐mojave > > anti‐aliasing coming back. I don’t know why. > > Ah, good eye. Mine is blurry too. Could it be creating a layer that is > the size of hidpi scaled window but not the actual pixel size of the > window? That would explain the blur if it was then drawn to a larger > pixel-wise window. So turns out you need to do some fancy‐pants manoeuvres to scale CGLayers correctly. They also appear to draw faster when correctly scaled, presumably because it’s not having to scale everything while drawing to the screen. > > I think that second URL is wrong, but I’ve read that quote before. > > Normal double buffering is simply drawing like we do on Emacs 27. > > There are plenty of places in the documentation that push you towards > > just drawing when you want to recreate part of the screen, however as > > we know Emacs redisplay isn’t really amenable to that approach. > > Do you know the cause of the glitching? Or is that still unclear? I > wonder if we could take some time to walk through it together, maybe > something will stand out? I know exactly what’s causing the glitching, but I’ll come back to this tomorrow. -- Alan Third --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Use-CGLayer-instead-of-NSBitmapImageRep-bug-32932.patch" >From 90e329cb6956bd40e927d74576ca8b5f48e5a72e Mon Sep 17 00:00:00 2001 From: Alan Third Date: Sat, 1 Feb 2020 21:17:29 +0000 Subject: [PATCH v2] Use CGLayer instead of NSBitmapImageRep (bug#32932) --- src/nsterm.h | 4 +-- src/nsterm.m | 89 +++++++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/nsterm.h b/src/nsterm.h index 980ca534cf..eefa4d706d 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -418,7 +418,7 @@ #define NSTRACE_UNSILENCE() NSWindow *nonfs_window; BOOL fs_is_native; #ifdef NS_IMPL_COCOA - NSBitmapImageRep *drawingBuffer; + CGLayerRef drawingBuffer; #endif @public struct frame *emacsframe; @@ -464,7 +464,7 @@ #define NSTRACE_UNSILENCE() - (void)focusOnDrawingBuffer; #endif - (void)copyRect:(NSRect)srcRect to:(NSRect)dstRect; -- (void)createDrawingBufferWithRect:(NSRect)rect; +- (void)createDrawingBuffer; /* Non-notification versions of NSView methods. Used for direct calls. */ - (void)windowWillEnterFullScreen; diff --git a/src/nsterm.m b/src/nsterm.m index 9d427b9b38..3576b851a5 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1141,7 +1141,6 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen) #ifdef NS_IMPL_COCOA [NSGraphicsContext setCurrentContext:nil]; - [view display]; #else block_input (); @@ -2853,7 +2852,9 @@ so some key presses (TAB) are swallowed by the system. */ ns_unfocus (f); /* as of 2006/11 or so this is now needed */ - ns_redraw_scroll_bars (f); + /* FIXME: I don't see any reason for this and removing it makes no + difference here. Do we need it for GNUstep? */ + //ns_redraw_scroll_bars (f); unblock_input (); } @@ -3169,18 +3170,6 @@ so some key presses (TAB) are swallowed by the system. */ NSTRACE_RECT ("fromRect", fromRect); - /* Because we're drawing into an offscreen buffer which isn't - flipped, the images come out upside down. To work around it - we need to do some fancy transforms. */ - { - NSAffineTransform *transform = [NSAffineTransform transform]; - [transform translateXBy:0 yBy:NSMaxY(imageRect)]; - [transform scaleXBy:1 yBy:-1]; - [transform concat]; - - imageRect.origin.y = 0; - } - [img drawInRect: imageRect fromRect: fromRect operation: NSCompositingOperationSourceOver @@ -3938,11 +3927,6 @@ Function modeled after x_draw_glyph_string_box (). NSAffineTransform *doTransform = [NSAffineTransform transform]; - /* We have to flip the image around the X axis as the offscreen - bitmap we're drawing to is flipped. */ - [doTransform scaleXBy:1 yBy:-1]; - [doTransform translateXBy:0 yBy:-[img size].height]; - /* ImageMagick images don't have transforms. */ if (img->transform) [doTransform appendTransform:img->transform]; @@ -4838,7 +4822,7 @@ in certain situations (rapid incoming events). if (NILP (window->vertical_scroll_bar)) { if (width > 0 && height > 0) - ns_clear_frame_area (f, left, top, width, height); + ns_clear_frame_area (f, left, top, width, height); bar = [[EmacsScroller alloc] initFrame: r window: win]; wset_vertical_scroll_bar (window, make_mint_ptr (bar)); @@ -7104,7 +7088,7 @@ - (void) updateFrameSize: (BOOL) delay from non-native fullscreen, in other circumstances it appears to be a noop. (bug#28872) */ wr = NSMakeRect (0, 0, neww, newh); - [self createDrawingBufferWithRect:wr]; + [self createDrawingBuffer]; [view setFrame: wr]; // To do: consider using [NSNotificationCenter postNotificationName:]. @@ -7444,7 +7428,7 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f maximizing_resize = NO; #endif - [self createDrawingBufferWithRect:r]; + [self createDrawingBuffer]; win = [[EmacsWindow alloc] initWithContentRect: r @@ -8229,7 +8213,7 @@ - (instancetype)toggleToolbar: (id)sender } -- (void)createDrawingBufferWithRect:(NSRect)rect +- (void)createDrawingBuffer /* Create and store a new NSBitmapImageRep for Emacs to draw into. @@ -8239,10 +8223,24 @@ - (void)createDrawingBufferWithRect:(NSRect)rect retain the old method of drawing direct to the EmacsView. */ { #ifdef NS_IMPL_COCOA + NSGraphicsContext *screen; + CGFloat scale = [[self window] backingScaleFactor]; + NSRect frame = [self frame]; + NSSize size = frame.size; + if (drawingBuffer != nil) - [drawingBuffer release]; + CGLayerRelease (drawingBuffer); + + size.width *= scale; + size.height *= scale; + + screen = [NSGraphicsContext graphicsContextWithBitmapImageRep: + [self bitmapImageRepForCachingDisplayInRect:frame]]; + + drawingBuffer = CGLayerCreateWithContext ([screen CGContext], size, nil); + CGContextRef cgctx = CGLayerGetContext (drawingBuffer); + CGContextScaleCTM(cgctx, scale, scale); - drawingBuffer = [[self bitmapImageRepForCachingDisplayInRect:rect] retain]; #endif } @@ -8250,11 +8248,15 @@ - (void)createDrawingBufferWithRect:(NSRect)rect #ifdef NS_IMPL_COCOA - (void)focusOnDrawingBuffer { - /* Creating the graphics context each time is very slow, but it - doesn't seem possible to cache and reuse it. */ - [NSGraphicsContext - setCurrentContext: - [NSGraphicsContext graphicsContextWithBitmapImageRep:drawingBuffer]]; + NSGraphicsContext *buf; + CGContextRef cgctx = CGLayerGetContext (drawingBuffer); + CGFloat scale = [[self window] backingScaleFactor]; + + buf = + [NSGraphicsContext + graphicsContextWithCGContext:cgctx flipped:YES]; + + [NSGraphicsContext setCurrentContext:buf]; } @@ -8269,7 +8271,7 @@ - (void)windowDidChangeBackingProperties:(NSNotification *)notification if (old != new) { NSRect frame = [self frame]; - [self createDrawingBufferWithRect:frame]; + [self createDrawingBuffer]; ns_clear_frame (emacsframe); expose_frame (emacsframe, 0, 0, NSWidth (frame), NSHeight (frame)); } @@ -8284,13 +8286,18 @@ - (void)copyRect:(NSRect)srcRect to:(NSRect)dstRect NSTRACE_RECT ("Destination", dstRect); #ifdef NS_IMPL_COCOA - [drawingBuffer drawInRect:dstRect - fromRect:srcRect - operation:NSCompositingOperationCopy - fraction:1.0 - respectFlipped:NO - hints:nil]; + CGRect offsetRect = CGRectMake (NSMinX (dstRect) - NSMinX (srcRect), + NSMinY (dstRect) - NSMinY (srcRect), + NSWidth ([self frame]), + NSHeight ([self frame])); + [[NSGraphicsContext currentContext] saveGraphicsState]; + + NSRectClip (dstRect); + CGContextDrawLayerInRect ([[NSGraphicsContext currentContext] CGContext], + offsetRect, drawingBuffer); + + [[NSGraphicsContext currentContext] restoreGraphicsState]; [self setNeedsDisplayInRect:dstRect]; #else hide_bell(); // Ensure the bell image isn't scrolled. @@ -8313,12 +8320,8 @@ - (void)drawRect: (NSRect)rect return; #ifdef NS_IMPL_COCOA - [drawingBuffer drawInRect:rect - fromRect:rect - operation:NSCompositingOperationSourceOver - fraction:1 - respectFlipped:NO - hints:nil]; + CGContextRef ctx = [[NSGraphicsContext currentContext] CGContext]; + CGContextDrawLayerInRect (ctx, [self frame], drawingBuffer); #else int x = NSMinX (rect), y = NSMinY (rect); int width = NSWidth (rect), height = NSHeight (rect); -- 2.24.0 --opJtzjQTFsWo+cga--