From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#63187: 30.0.50; Tail of longer lines painted after end of nearby lines on macOS Date: Sat, 24 Jun 2023 22:29:54 +0100 Message-ID: References: <335C856F-41F7-48B8-AF42-B2406065C7A9@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18925"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Po Lu , Kai Ma , Eli Zaretskii , 63187@debbugs.gnu.org To: Aaron Jensen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 24 23:31:24 2023 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 1qDAqq-0004jd-5F for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 24 Jun 2023 23:31:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qDAqZ-0002Gn-DA; Sat, 24 Jun 2023 17:31:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qDAqU-0002Ge-M3 for bug-gnu-emacs@gnu.org; Sat, 24 Jun 2023 17:31:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qDAqU-0002rx-Dk for bug-gnu-emacs@gnu.org; Sat, 24 Jun 2023 17:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qDAqU-0007BU-96 for bug-gnu-emacs@gnu.org; Sat, 24 Jun 2023 17:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 24 Jun 2023 21:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63187 X-GNU-PR-Package: emacs Original-Received: via spool by 63187-submit@debbugs.gnu.org id=B63187.168764220427437 (code B ref 63187); Sat, 24 Jun 2023 21:31:02 +0000 Original-Received: (at 63187) by debbugs.gnu.org; 24 Jun 2023 21:30:04 +0000 Original-Received: from localhost ([127.0.0.1]:41594 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qDApX-00078P-TA for submit@debbugs.gnu.org; Sat, 24 Jun 2023 17:30:04 -0400 Original-Received: from dane.soverin.net ([185.233.34.150]:52103) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qDApW-00077P-FY for 63187@debbugs.gnu.org; Sat, 24 Jun 2023 17:30:03 -0400 Original-Received: from smtp.soverin.net (c04smtp-lb01.int.sover.in [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dane.soverin.net (Postfix) with ESMTPS id 4QpS1c34Mcz7H; Sat, 24 Jun 2023 21:29:56 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.99]) by soverin.net (Postfix) with ESMTPSA id 4QpS1b57NqzHg; Sat, 24 Jun 2023 21:29:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1687642196; bh=f9qFRW6AYp/jMCF/5yk44gSxAundVWJL3lnEMoZ1bLY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Imd2Mk6Gg0j0HWZEnYvuTRxDkZG31C0tqAb5Ywcz2BS9vO/GXNtrCXMh05vG9KjcN qygTEzcYeFVqTDizsGLjjtQtNKlWky8GIm4P/ApqttiGCIeoOCPL2E7WD5sAG8aMw6 +ylTUXLobgXLxk8Cicqv1HN6JcggnQAZ3sdwhgN3nqDZNuHvC4oGe/uyK9B/8ydFCU U+7dgaK0KPCuYW/No+kbZoCi0EQwAsnV22+1Y2c5MH4e432yzmntU/eykKVyavS3T4 2le3Y0wNlsFSOxSzYM7kETwN4K9E7aJ7szoLcAJOaOoMttfn4STYFRMKyja4cdOzbR uH56xOnhPz6tQ== Original-Received: from alan by faroe.holly.idiocy.org with local (Exim 4.95) (envelope-from ) id 1qDApO-000Y63-DM; Sat, 24 Jun 2023 22:29:54 +0100 X-Soverin-Authenticated: true Mail-Followup-To: Alan Third , Aaron Jensen , Kai Ma , 63187@debbugs.gnu.org, Eli Zaretskii , Po Lu Content-Disposition: inline In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:264016 Archived-At: On Sat, Jun 24, 2023 at 12:05:45PM -0400, Aaron Jensen wrote: > > But if that's the case, why would removing the asynchronous call to > > getContext fix so many problems? > > It's possible we have two very different problems that only appear related: > 1. The one i'm seeing, which is sort of ghosting of other lines into > the whitespace of nearby lines. The getContext call removal did not > fix this for me, I saw it happen once. > 2. The one Kai is seeing, that is exacerbated by decreasing the > polling interval, but seems to be helped by removing the getContext > call. Yes, it might be two different things. > > Something perhaps worth trying... Since removing the asynchronous call > > to getContext fixes the problems, perhaps we need to think about the > > "lazy" way we get the next buffer when the current one is displayed. > > At the moment it just forgets about it until we want to draw to the > > screen, at which point we call getContext and it creates the buffer if > > necessary and copies the old one to the new one. > > > > Maybe we should get the new buffer and do the copy when we set the > > current buffer for display... > > > > IIRC I avoided that because there isn't always time for the buffer to > > have been sent to VRAM and unlocked before the *next* call to display, > > so I wanted to leave it as long as possible between display and > > getting the next buffer, but maybe this is just the wrong way to do > > it. > > > > So I suppose putting a call to getContext right after "currentSurface > > == NULL" in display might be a quick and dirty way to test that. > > My problem is that at this point it happens so infrequently and I have > no idea if that's because of the patches I'm trying or some other > environmental thing or just luck. I'm going to try running without the > async getContext and without the setNeedsDisplay for a while and see > if it happens. Perhaps the setNeedsDisplay is somehow causing an issue > and that's why changing it from source to dest seemed to help but it > didn't alleviate it. OK > If I see it again, I'll add the sync getContext call in, though I'll > admit I do not understand your paragraph above starting with IIRC. Are > you suspecting a potential problem with reading from the surface that > is in the process of being copied to vram? Maybe... I'm really not sure what might be going on. My suspicion is that if we try to swap between the buffers too fast, something is going wrong between the process of flushing the drawing to the pixel buffer and copying the pixel buffer to the next one. So, we have two buffers, A and B. We draw to A, but before we're done the system calls display. We send off the incomplete buffer A to VRAM, and then take a copy of that incomplete buffer for B. At some point the system decides to flush the graphics context to the buffer, but it's flushing to A, and we've *already* copied A to B. This would possibly explain why Kai lowering the polling interval induces the issue, as it may increase the frequency at which the screen is updated beyond the point where we're able to keep up. To be honest though, I feel it should all be pretty linear and this idea implies things are happening out-of-order. So I'm not convinced I'm right. Who knows. Maybe all we need to do is make sure we don't try to draw to the screen while emacs is drawing to the buffer... Something like this: modified src/nsterm.m @@ -10622,7 +10622,7 @@ - (void) display { NSTRACE_WHEN (NSTRACE_GROUP_FOCUS, "[EmacsLayer display]"); - if (context) + if (context && context != [NSGraphicsContext currentContext]) { [self releaseContext]; ... Actually... That change should probably be made anyway. If the NS run loop kicks in between an ns_focus call and an ns_unfocus call, it could call display and our display function will happily destroy the existing context without creating a new one, so any *subsequent* drawing operations, up until ns_unfocus, will be lost. I'm not sure if that's a legitimate concern... 😕 I've got too many ideas about how to fix it and no way to actually try them out, never mind the difficulty of inducing the issue if I did. -- Alan Third