| Ticket UUID: | 6a33585a3514f14f093e1058876a0e7d372e96f0 | |||
| Title: | Legacy and Revised [text]: textDisp-6.5, -6.6, -7.[1-8] fail on aqua | |||
| Type: | Bug | Version: | core-8-6-branch, revised_text | |
| Submitter: | fvogel | Created on: | 2021-07-24 12:30:05 | |
| Subsystem: | 18. [text] | Assigned To: | marc_culler | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Open | Last Modified: | 2023-07-14 13:59:10 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
On aqua, textDisp-6.5, -6.6, -7.[1-8] all fail because their obtained result is wrong for the tk_textRedraw variable, and for some tests for the tk_textRelayout variable as well.
The rendering on screen is correct, and the test results are repeatable. This looks like a logging bug, specific to aqua. The above observations were made with both the legacy version of the text widget and it's revised variant. | |||
| User Comments: |
fvogel added on 2023-07-14 13:59:10:
Quite some time ago, textDisp-6.5, -6.6, -7.[1-8] were marked as 'knownBug' in core-8-6-branch, trunk and revised_text. fvogel added on 2022-06-07 21:06:41: See also [aad0231f07]. fvogel added on 2021-07-28 11:31:14: Here are a few more investigation results. I'm taking the following code from textDisp-6.5 as an example for the analysis:
package require Tk
set fixedFont {Courier -12}
text .t -width 20 -height 10 -font $fixedFont -bd 2 -highlightthickness 2 -wrap char
pack .t -expand 1 -fill both
.t debug on
frame .f2 -bg red
place .f2 -in .t -relx 0.5 -rely 0.5 -relwidth 0.5 -relheight 0.5
.t insert 1.0 "Line 1 is so long that it wraps around, a couple of times"
foreach i {2 3 4 5 6 7 8 9 10 11 12 13 14 15} {
.t insert end "\nLine $i"
}
update ; # update idletasks on the mac
.t delete 1.6 1.end
update ; # update idletasks on the mac
list $tk_textRelayout $tk_textRedraw
When running Later in the same call to DisplayText(), lines flagged with OLD_Y_INVALID and lines which y position have changed in the preceding layout process get actually redrawn, and are logged in the tk_textRedraw list. There are at least two things making a difference between Windows and macOS in this process:
Regarding 1, on Windows, ScrollWindowEx() (this is a Windows API function) computes a possibly complex damage region. On macOS, the damage region is computed by Tk and is the scroll source rectangle minus the scroll destination rectangle. In the example code above, when running rect.x = 5 rect.y = 50 rect.width = 140 rect.height = 105on Windows, and rect.x = 5 rect.y = 109 rect.width = 140 rect.height = 26on macOS. On macOS the damage region is limited to the two lines at the bottom of the text widget (one line is 13 pixels height here on the mac), whereas on Windows it is from line 3 to line 10 (one line is 15 pixels height on Win). So how come that macOS shows correct rendering of the widget, if the damage region is incorrect? The answer is that there is an extra Expose event triggered (how?) on the mac for the entire text widget (rectangle 0, 0, full width, full height). TextEventProc() then runs TextRedrawRegion() for the entire widget, which calls TextInvalidateRegion() with the entire text widget area as damage region (its clipbox is rect.x = 0 rect.y = 0 rect.width = 150 rect.height = 140), which in turn flags all lines of the widget with OLD_Y_INVALID. Therefore, all lines of the widget get redrawn and the widget looks entirely correct. But then how come that the tk_textRedraw list does not contain all lines? The answer is number 2 above: lines numbers logging does not happen when called from inside the drawRect method. The OK_TO_LOG flag instructing to actually log or not is true only if we're outside drawRect. I think this all explains the difference in content of tk_textRedraw between macOS and Windows (or Linux: tk_textRedraw content on Win and Linux is the same). marc_culler (claiming to be Marc Culler) added on 2021-07-26 21:32:34: Cool! This is very convincing to me. fvogel added on 2021-07-26 21:12:10: All the tests in question use a frame that is [place]d -in the text widget. I believe the answer is already provided in the source code comments. On the mac TkScrollWindow() generates a damage region which is the scroll source rectangle minus the scroll destination rectangle. On Windows, ScrollWindowEx() generates a more complex damage region, and ditto on Linux for XScrollWindow(). So this has nothing to do with timings (btw results are fully repeatable, which confirms this), but with different computations of the damage region when scrolling. fvogel added on 2021-07-26 19:15:13: > It should not declare failure if some
> other stuff gets redrawn as well.
The problem with this theory is that the obtained output is not always the expected output plus some other lines.
For instance take textDisp-6.5:
* expected output of [list $tk_textRelayout $tk_textRedraw] is {{1.0 9.0 10.0} {1.0 4.0 5.0 9.0 10.0}}
* obtained output on the mac is {{1.0 9.0 10.0} {1.0 9.0 10.0}}
In that specific textDisp-6.5 example, lines 4 and 5 really are dirty and shall be redrawn (and it really is the case when looking at the widget).
If your theory was fully right, then the obtained $tk_textRedraw should at least include all items from the expected $tk_textRedraw, which is not the case.
marc_culler (claiming to be Marc Culler) added on 2021-07-24 13:07:54: I suspect this happens because the drawing proc is called twice. First it is called outside of the drawRect method, causing it to be rescheduled. But before the rescheduled redraw takes place something else happens to mark the entire widget as dirty. So the second redraw draws the entire widget, causing the "borders" to be logged. This would explain why it works fine for users, but fails the test. Basically the test is making lots of assumptions about the exact moment when the redraw will take place, and those assumptions are not valid if a drawing operation is rescheduled in order to make it happen in the drawRect method. The drawRect method is called by the system and cannot be called by Tk. Christopher discovered by experiment that it usually gets called during the blocking function which Tk uses to get the next event off of Apple's event queue (nextEventMatchingMask). So we attempt to manage when the call to drawRect will happen by avoiding marking an NSView as needing display until immediately before calling nextEventMatchingMask. But the calls to drawRect are still asynchronous from Tk's point of view, and this means that the test's expectation of when (and where) drawing will take place is not always correct. If the expected result of a test depends on that timing then the test will sometimes fail. Really the test should only be checking whether the dirty part that the test knows about gets redrawn. It should not declare failure if some other stuff gets redrawn as well. As far as a real user is concerned that extra redrawing is not a failure of any sort. It just means that the text widget looks correct. Possibly the extra drawing could be considered to be a performance issue, but the fact is that the performance of the text widget has gotten a lot better (on Aqua) over the last year or so. | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki