Subject: Re: bug#63187: 30.0.50; Tail of longer lines painted after end of nearby lines on macOS

From: Aaron Jensen <[email-masked]>
Date: Thu, 20 Jul 2023 22:02:53 -0400

On Wed, Jun 28, 2023 at 3:53 PM Alan Third <[email-masked]> wrote:
>
> On Mon, Jun 26, 2023 at 03:27:41PM +0800, Kai Ma wrote:
> >
> >
> > > On Jun 25, 2023, at 20:46, Alan Third <[email-masked]> wrote:
> > >
> > >>>
> > >>> 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.
> > >>
> > >> OK, I'm adding this to my current build.
> > >>
> > >> Is this in line with the type of issue I'm seeing where scrolling
> > >> works but the ghosting either replicates (or scrolls with it?) In
> > >> other words, what would you expect to see in this scenario? Would it
> > >> just stop painting entirely?
> > >
> > >
> > > Kai, it might be worth trying just that change above, while keeping
> > > the call to performSelectorInMainThread and see if it fixes anything
> > > for you.
> >
> > Unfortunately, the problem persists (as in the YouTube video) if performSelectorInMainThread is present.
>
> OK. Thanks for trying it.

I've been using this for about a month now and have seen no artifacts:

diff --git a/src/nsterm.m b/src/nsterm.m
index 78089906752..d23fb650ab8 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2708,9 +2708,6 @@ Hide the window (X11 semantics)
     EmacsView *view = FRAME_NS_VIEW (f);

     [view copyRect:srcRect to:dest];
-#ifdef NS_IMPL_COCOA
-    [view setNeedsDisplayInRect:destRect];
-#endif
   }

   unblock_input ();
@@ -10435,7 +10432,7 @@ @implementation EmacsLayer
    cache.  If no free surfaces are found in the cache then a new one
    is created.  */

-#define CACHE_MAX_SIZE 2
+#define CACHE_MAX_SIZE 1

 - (id) initWithColorSpace: (CGColorSpaceRef)cs
 {
@@ -10621,7 +10618,7 @@ - (void) display
 {
   NSTRACE_WHEN (NSTRACE_GROUP_FOCUS, "[EmacsLayer display]");

-  if (context)
+  if (context && context != [NSGraphicsContext currentContext])
     {
       [self releaseContext];

I'm not sure what the ramifications are for CACHE_MAX_SIZE 1 on slower
machines, but I don't notice any performance issues on my M1.

Alan, what do you think we should do? Is there anything else you think
I should test for the next bit of time?

Thanks,

Aaron