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: Mon, 10 Feb 2020 07:44:04 +0000 Message-ID: <20200210074404.GA44470@breton.holly.idiocy.org> References: <20200203204408.GA59034@breton.holly.idiocy.org> <20200203213041.GC59034@breton.holly.idiocy.org> <20200207201802.GA7538@breton.holly.idiocy.org> <20200208141335.GA9391@breton.holly.idiocy.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="G4iJoqBmSsgzjUCe" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="13836"; 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 Mon Feb 10 08:45:28 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 1j13l1-0003TM-S9 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 10 Feb 2020 08:45:27 +0100 Original-Received: from localhost ([::1]:57934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j13l0-0006xo-Na for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 10 Feb 2020 02:45:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34143) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j13kf-0006W0-AH for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2020 02:45:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j13kd-0002BT-F0 for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2020 02:45:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47650) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j13kc-00026I-PQ for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2020 02:45:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j13kc-00088Y-E4 for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2020 02:45: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: Mon, 10 Feb 2020 07:45: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.158132065531209 (code B ref 32932); Mon, 10 Feb 2020 07:45:02 +0000 Original-Received: (at 32932) by debbugs.gnu.org; 10 Feb 2020 07:44:15 +0000 Original-Received: from localhost ([127.0.0.1]:53623 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j13jr-00087I-7j for submit@debbugs.gnu.org; Mon, 10 Feb 2020 02:44:15 -0500 Original-Received: from mail-wr1-f49.google.com ([209.85.221.49]:33728) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j13jp-000873-6i for 32932@debbugs.gnu.org; Mon, 10 Feb 2020 02:44:13 -0500 Original-Received: by mail-wr1-f49.google.com with SMTP id u6so6272972wrt.0 for <32932@debbugs.gnu.org>; Sun, 09 Feb 2020 23:44:13 -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=0sf4H41mNv1S+emN3/x0y84jfB+lunNsaxPnngW22Xk=; b=eUlkEiN9i4ocN4n3vfuNCeqbQUdmzVX18aNlYNMiXsZTjfmsUg+zdjC9wTD37IAR2/ BIqaqEqZwXgxDGI9AwPQj+MP18Q+nfKkWTAlhEKoFIlkCqllEoNXKsJwghoLP6exG8pu NoltAOGSDbocMghZdYiTFrhnJqe4Hj1gPXObiKR2KGSXaeCV86oqiV465fdpXxOhkGf4 Dy8Wa0UCzIYnqPnC+/kZvETWUFXJVqJFCSQYq5GvlU7NT+K+zX+sB6cs8NOghbbvH3XO XnqfixBZOnLky/d8dLT0yI+C1vzVkh8z7GPY6oc1MsmOsfCpR3X8m1P/ft1dZpiu9gEj KuhQ== 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=0sf4H41mNv1S+emN3/x0y84jfB+lunNsaxPnngW22Xk=; b=deORACQpYyVpXMsSOKGNpYE24kD0aWqFW6KAgaXy/TwSYDKjyMzBLG1CdK9/DuqrS6 xq63XThvp37FE6CeFTesGNgSWRjttxvoxNSFKW/KOdQK7pwX7kjFIMEyeh+JAcni2GL2 oKChss0Ls3uvZoa+4lewtwOzOs3rNpskNuBORA7p7ofXEIO8LZS9vgnhqr01R569JJVK /x4+n5547jAbpBWaHw7kkwI2kyyvICh0+dsYRaKInfhH7SL/d8Iu4iySQfBKsJKq06aX CoTeveFrPy6F482HbUaZ2GCqqOmJEsxiHOOqJX1GBnhkXRiudPhdUJ3qCjog4B5L4TUB bxAA== X-Gm-Message-State: APjAAAWVd773970lC8VBU09qWyBbq0w3v+Qo5ZH34RRpUlinBSv/Zs5I GnSGYvaeWwu14oePhpntWL4= X-Google-Smtp-Source: APXvYqxuLt+UnP0YkGu1zvf+V1zQHHtZtdIFLJcOMEER97yC4u5IHuK0jrzppH8TQha7LSTCtGFrNw== X-Received: by 2002:adf:dc8d:: with SMTP id r13mr219179wrj.357.1581320647035; Sun, 09 Feb 2020 23:44:07 -0800 (PST) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-d44f-5a06-b616-7005.holly.idiocy.org. [2001:8b0:3f8:8129:d44f:5a06:b616:7005]) by smtp.gmail.com with ESMTPSA id d204sm14055441wmd.30.2020.02.09.23.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Feb 2020 23:44:06 -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:175859 Archived-At: --G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sat, Feb 08, 2020 at 08:45:25AM -0800, Aaron Jensen wrote: > > Yeah, unfortunately. Are you on Catalina? I can try the build on my > work machine as well. It's a 2019 MBP 16", so pretty close to my 2017 > at home, but different. A hardware issue seems unlikely... No, I’m still on Mojave. Anyway, one last thing to try. I was reading up on how MacVim handled this same issue, and while their drawing techniques are quite different, they did find performance problems with CGLayers so switched to using CGImages. I’ve given that a go and I don’t think this patch is quite as fast here as the CGLayer one, but it may be faster for you. -- Alan Third --G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Use-CGImage-instead-of-NSBitmapImageRep-bug-32932.patch" >From 2b514b8dfac196a7e19ccb4718f3b40afd09d8e0 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Sat, 1 Feb 2020 21:17:29 +0000 Subject: [PATCH] Use CGImage instead of NSBitmapImageRep (bug#32932) --- src/nsterm.h | 4 +- src/nsterm.m | 115 +++++++++++++++++++++++++++++---------------------- 2 files changed, 68 insertions(+), 51 deletions(-) diff --git a/src/nsterm.h b/src/nsterm.h index 980ca534cf..7c6197f128 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; + CGContextRef 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..8761f65da9 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,8 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f maximizing_resize = NO; #endif - [self createDrawingBufferWithRect:r]; + [self setCanDrawConcurrently:YES]; + [self createDrawingBuffer]; win = [[EmacsWindow alloc] initWithContentRect: r @@ -8229,20 +8214,28 @@ - (instancetype)toggleToolbar: (id)sender } -- (void)createDrawingBufferWithRect:(NSRect)rect - /* Create and store a new NSBitmapImageRep for Emacs to draw - into. +- (void)createDrawingBuffer + /* Create and store a new CGLayer for Emacs to draw into. - Drawing to an offscreen bitmap doesn't work in GNUstep as there's - a bug in graphicsContextWithBitmapImageRep - (https://savannah.gnu.org/bugs/?38405). So under GNUstep we - retain the old method of drawing direct to the EmacsView. */ + We can't do this in GNUstep as there's no CGLayer or equivalent. + So under GNUstep we 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]; + if (drawingBuffer != nil) - [drawingBuffer release]; + CGContextRelease (drawingBuffer); + + drawingBuffer = CGBitmapContextCreate (nil, NSWidth (frame) * scale, + NSHeight (frame) * scale, + 8, 0, self.window.colorSpace.CGColorSpace, + kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host); - drawingBuffer = [[self bitmapImageRepForCachingDisplayInRect:rect] retain]; + CGContextTranslateCTM(drawingBuffer, 0, NSHeight (frame) * scale); + CGContextScaleCTM(drawingBuffer, scale, -scale); #endif } @@ -8250,11 +8243,11 @@ - (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 = + [NSGraphicsContext + graphicsContextWithCGContext:drawingBuffer flipped:YES]; + + [NSGraphicsContext setCurrentContext:buf]; } @@ -8269,7 +8262,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 +8277,27 @@ - (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]; + CGImageRef copy; + NSAffineTransform *setOrigin = [NSAffineTransform transform]; + NSRect frame = [self frame]; + CGFloat xoffset = NSMinX (dstRect) - NSMinX (srcRect); + CGFloat yoffset = NSMinY (dstRect) - NSMinY (srcRect); + + [[NSGraphicsContext currentContext] saveGraphicsState]; + + NSRectClip (dstRect); + [setOrigin scaleXBy:1 yBy:-1]; + [setOrigin translateXBy:xoffset + yBy:-NSHeight (frame) - yoffset]; + [setOrigin concat]; + + copy = CGBitmapContextCreateImage (drawingBuffer); + CGContextDrawImage (drawingBuffer, frame, copy); + + CGImageRelease (copy); + + [[NSGraphicsContext currentContext] restoreGraphicsState]; [self setNeedsDisplayInRect:dstRect]; #else hide_bell(); // Ensure the bell image isn't scrolled. @@ -8304,6 +8311,20 @@ - (void)copyRect:(NSRect)srcRect to:(NSRect)dstRect } +- (BOOL)wantsUpdateLayer +{ + return YES; +} + + +- (void)updateLayer +{ + CGImageRef contentsImage = CGBitmapContextCreateImage(drawingBuffer); + self.layer.contents = (id)contentsImage; + CGImageRelease(contentsImage); +} + + - (void)drawRect: (NSRect)rect { NSTRACE ("[EmacsView drawRect:" NSTRACE_FMT_RECT "]", @@ -8313,12 +8334,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, NSRectToCGRect ([self frame]), drawingBuffer); #else int x = NSMinX (rect), y = NSMinY (rect); int width = NSWidth (rect), height = NSHeight (rect); -- 2.24.0 --G4iJoqBmSsgzjUCe--