Tk Source Code

View Ticket
Login
Ticket UUID: aad0231f074cf5c8a6783295cbf40fd6b09d920b
Title: On macOS, DisplayText is called twice (inside and outside of drawRect)
Type: Bug Version: core-8-6-branch, revised_text
Submitter: fvogel Created on: 2022-06-07 20:19:33
Subsystem: 66. Aqua Window Operations Assigned To: marc_culler
Priority: 5 Medium Severity: Severe
Status: Open Last Modified: 2022-08-07 09:01:47
Resolution: None Closed By: nobody
    Closed on:
Description:

In a text widget, when an insert or delete, or any other operation changing the display is run, function DisplayText() is called twice:

1. once outside of drawRect, during which pass (tk_textRelayout and tk_textRedraw) logging happens (since we're outside of drawRect), and the minimal damage region is correctly computed, but NO drawing actually happens (since we're outside of drawRect)

2. a second time from inside drawRect during which pass (tk_textRelayout and tk_textRedraw) logging does not happen, and (because of the expose event mechanism receives the entire text widget area) the damage region is the entire text widget area, and redrawing actually happens (for the entire text widget).

Number 1. makes the text widget tests pass by logging MINIMAL redrawing actions that do NOT actually happen, and number 2. redraws ALL visible lines WITHOUT logging anything.

# Preparation phase
package require Tk
pack [text .t]
update
.t debug true
foreach i {1 2 3 4 5} {
  .t insert end "Line $i\n"
}
update idletasks
set tk_textRelayout "empty"
set tk_textRedraw "empty"

# Tested instruction
.t delete 2.0 3.0

# Look up the results
update idletasks
list $tk_textRelayout $tk_textRedraw

# 2.0 {2.0 eof}  is obtained, which is the correct result
# but NO drawing occurred during the first DisplayText pass.
# Actual drawing occurred during the second DisplayText pass
# but ALL lines were redrawn (and nothing gets logged).
# This can be demonstrated by instrumenting both DisplayText
# and drawRect code (#define TK_MAC_DEBUG_DRAWING).

This is quite a serious performance problem on macOS.

Moreover it nullifies the interest of the test suite on the mac since what gets logged and whats gets drawn are two different things.

User Comments: chrstphrchvz added on 2022-08-07 09:01:47:

…*ANY* display proc can be called twice on macOS, once from outside of drawRect and once inside drawRect. That is how the macOS port works, and no one has managed to come up with an alternative.

Please see [3e9e82bcfe4] for discussion of a potential alternative.


marc_culler (claiming to be Marc Culler) added on 2022-06-12 17:28:01:
Just to be clear about this - *ANY* display proc can be called twice on
macOS, once from outside of drawRect and once inside drawRect.  That is
how the macOS port works, and no one has managed to come up with an
alternative.

The core low-level graphics routine checks whether it is being called from
within drawRect.  If not, the bounding rectangle is marked as dirty and the
routine returns immediately.  The drawing then occurs in the next call to
drawRect, when it redraws the dirty region. Since this happens at the lowest
level, it happens with every display proc. That has been true since the
Mojave release, which removed the ability to draw directly to the frame
buffer.

The place to focus attention to increase the perfomance of the Text widget
is on making it possible for a Text widget to maintain finer grained
information about which subregions of the widget actually need to be updated.
The drawRect mewthod has to call the display proc of the Text widget whenever
the bounding rectangle of the Text widget meets the dirty rectangle because
it doesn't have any more information than that. Performance would be better
it the Text widget could streamline its display proc so as to avoid drawing
subregions that are not actually dirty.

fvogel added on 2022-06-12 12:25:13:

Sorry, I meant: I have tagged textDisp failing tests.

To force these tests to run, and therefore test potential fixes for the prsent bug, use:

make -C ./macosx test TESTFLAGS="-file textDisp.test -constraints knownBug"


fvogel added on 2022-06-12 12:13:38:

To ease the testing, I have just tagged textWind failing tests with a new constraint 'aquaKnownBug'. These tests are now run normally on all platforms with any windowing system, except on aqua where these tests are skipped due to the present known bug.

To force these tests to run, i.e. to test fixes for the present ticket, use:

make -C ./macosx test TESTFLAGS="-file textWind.test -constraints knownBug"

This is available in any of the following three branches: core-8-6-branch, trunk, unstable_tests.


fvogel added on 2022-06-07 21:07:06:

See also [6a33585a35].


fvogel added on 2022-06-07 20:45:00:

An easy way to check whether this issue is fixed or not is to remove the 'notAqua' constraint on textDisp-6.5, -6.6, -7.* and run the textDisp.test file. These tests are currently failing on macOS because of the issue described in the present ticket. See [9428449d3c].