Tk Source Code

View Ticket
Login
Ticket UUID: fa1a4cfa2aa6206fccfee5a40923dca39b1a1aed
Title: Aqua: revisiting idle drawing issues
Type: Bug Version: core-8-6-branch
Submitter: chrstphrchvz Created on: 2020-12-11 04:53:54
Subsystem: 02. Appearance Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2021-01-21 09:54:34
Resolution: None Closed By: nobody
    Closed on:
Description:

Using Nicolas' 100 canvases demo ([2a61eca3a8]) with recent core-8-6-branch on my old MacBook running 10.15 Catalina, I observe that drawRect: is not always called strictly from within TkMacOSXDrawAllViews(), and that TkMacOSXDrawAllViews(NULL) is sometimes called while in drawRect:.

User Comments: chrstphrchvz added on 2021-01-21 09:54:34:

I think I should have specifically said that the Tk Aqua code was merely not doing what I believed the comments for TkMacOSXDrawAllViews() claimed. Since I still don't have an explanation for something happening when I confidently agree shouldn't, and I still have not observed first-hand that this leads to drawing issues, maybe all that should be done is minor adjustment to those comments to mention what can currently happen instead. Something like "Reportedly not always the case; see [fa1a4cfa2a]" could suffice.

For drawing issues others still observe, I struggle to think of something less drastic than for Tcl to support idle event "filtering" and allow drawRect: to ignore already-queued idle events. I'm actually no longer confident that would totally work and not lead to other issues caused by Tk's longstanding assumptions of how idle events work (i.e. the lack filtering capability). Another idea would be to use a separate idle event queue while in drawRect:, but I don't think that would work if idle events queued outside of drawRect: need to be cancelable. Also, none of this would help with [f79ed9db4a] if my explanation from 2020-12-19 19:19:16 is correct, unless scrollRect:by: usage is eliminated.

As a diagnostic for determining whether a drawing issue is due to drawing operation code (e.g. text, shapes, images) or is specific to drawing directly to an NSView, there might still be the approach of drawing to an NSImage→CALayer rather than directly to an NSView, which should be closer to letting Tk draw whenever it wants to (see [685ac30727] 2020-08-09 18:50:23). Unless its poor performance impacts timing too much to be useful for many issues.

Or try bugging the folks at cocoa-dev, which I have not done.


marc_culler (claiming to be Marc Culler) added on 2020-12-14 15:53:07:
One other comment about this.  We should distinguish between timer tasks and
idle tasks.  These are handled differently in the event loop.

marc_culler (claiming to be Marc Culler) added on 2020-12-14 13:40:51:
My experiments involved tracing calls to XFillRectangles while running
Nicolas' script.  In cases where a rectangle was not being filled I found
that XFillRectangle *was* being called for the rectangle which was skipped,
meaning that CGContextFillRect was being called for that rectangle, and I
also verified that CGContextFillRect was being called from drawRect while
the NSView was the focusView, so the fill *should* have happened.

If you think I did something wrong, which is certainly possible, then I
invite you to do your own tracing and report what you find.

Can you say what context leads to TkMacOSXDrawAllViews being called while
in drawRect?

I do not know of any way to force drawRect to only get called from within
TkMacOSXDrawAllViews and I did not attempt to do that.  The best that I
could do was to provide an opportunity for the Apple window manager to
call drawRect within TkMacOSXDrawAllViews.  That opportunity is provided
by calling [NSApp nextEventMatchingMask:].  Of course there is no documentation
indicating that calling that method will allow, or force, drawRect to be
called.  However, reverse engineering, thanks to you, indicated that
that method blocks and that while it is blocking it calls drawRect for all
or some views that are marked as needing display.

I think this issue is well worth revisiting, so I am glad you are looking at it.

chrstphrchvz added on 2020-12-11 04:54:58:

Maybe this wasn't the case at the time [2a61eca3a8] was closed, when Marc concluded that there is a bug in Core Graphics and not somewhere else like event handling. But I remain skeptical of that being the case, especially given evidence of idle events already queued when entering drawRect: and setNeedsDisplay: called while in drawRect: (despite attempts to prevent this).

I hesitate to revisit this whole issue, as I don't feel I have any constructive suggestions to offer.