Tk Source Code

View Ticket
Login
2026-10-29
15:33 • Ticket [4af5ca19] XCopyArea is very (very) slow on macOS with version 9 status still Open with 3 other changes artifact: e1cbc4ab user: chrstphrchvz
2026-10-17
10:12 • Ticket [de6ef827] imageName configure -gamma - has no effect on macOS status still Open with 3 other changes artifact: c7e29925 user: chrstphrchvz
2026-10-10
02:35 • Closed ticket [f215a9fd]: Revisiting [df4b603950] plus 8 other changes artifact: bd4b770e user: marc_culler
02:28
Fix [f215a9fdaa]: scaling issues in CreateCGImageFromDrawableRect: patch from Christopher Chavez. check-in: 8a466319 user: culler tags: trunk, main
02:14
Fix [f215a9fdaa]: scaling issues in CreateCGImageFromDrawableRect: patch from Christopher Chavez. check-in: b9aba340 user: culler tags: core-9-0-branch
2026-10-08
20:48 • Ticket [f215a9fd] Revisiting [df4b603950] status still Open with 3 other changes artifact: 4df37816 user: chrstphrchvz
14:11 • Ticket [685ac307] Aqua: XCopyArea() broken for non-pixmap source (as used by Tktable) status still Pending with 3 other changes artifact: d89b5b84 user: chrstphrchvz
2025-08-16
01:42 • Ticket [f215a9fd] Revisiting [df4b603950] status still Open with 3 other changes artifact: f9c6786b user: chrstphrchvz
01:33
Alternative fix for CreateCGImageFromDrawableRect() returning smaller image than requested. See [f215a9fdaa]. check-in: 84c2ba4f user: chrstphrchvz tags: bug-df4b603950-alt
2025-08-15
21:10 • Ticket [f215a9fd] Revisiting [df4b603950] status still Open with 4 other changes artifact: bd1c817b user: marc_culler
2025-08-11
17:38 • Ticket [f215a9fd]: 3 changes artifact: 06dbcc4f user: chrstphrchvz
2025-08-08
23:05 • Ticket [f215a9fd]: 3 changes artifact: 99c4221c user: chrstphrchvz
18:00 • Ticket [4af5ca19] XCopyArea is very (very) slow on macOS with version 9 status still Open with 3 other changes artifact: 2b935008 user: chrstphrchvz
17:43 • Ticket [df4b6039] aqua: artifacts when scrolling a Text widget which is larger than its toplevel status still Closed with 5 other changes artifact: b12e09ad user: chrstphrchvz
17:40 • New ticket [f215a9fd] Revisiting [df4b603950]. artifact: 2e6b0a69 user: chrstphrchvz

Ticket UUID: f215a9fdaad50b6a2963258464cfd2f50f4d64
Title: Revisiting [df4b603950]
Type: Patch Version: core-9-0-branch
Submitter: chrstphrchvz Created on: 2025-08-08 17:40:50
Subsystem: 82. X11 Emulation Assigned To: marc_culler
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-10 02:35:11
Resolution: Accepted Closed By: marc_culler
    Closed on: 2026-10-10 02:35:11
Description:

To me, [df4b603950] seems like a combination of 2 issues. The primary issue was that TkScrollWindow() did not compute damage correctly when a widget was outside the visible portion of a toplevel, causing artifacts to appear. I think Marc's changes to TkScrollWindow() have fixed this.

I find the distortion in those artifacts to be a secondary issue, because if only the changes to TkScrollWindow() were made, then there would have been no more artifacts to notice.

I think there still exists a problem with CreateCGImageFromDrawableRect() where it can unexpectedly return a smaller image than requested. That led to the distorted scaling artifacts, but currently it can also lead to a buffer overread in XGetImage(). I want to say that the cause is that I neglected how CGImageCreateWithImageInRect() understandably does not “pad” the output image when specifying a rectangle extending outside of the input image. What I think CreateCGImageFromDrawableRect() should do instead is just always create a new bitmap context with the requested width and height, draw the image of the source drawable (pixmap or toplevel) at the correct offset into the new bitmap context (i.e. no need to obtain a subimage with CGImageCreateWithImageInRect()), then return the image from the new bitmap context. With this approach, there is nothing in XCopyArea() specifically to change from before; it continues to work with pixmaps and remains unaware of things like a toplevel's NSView. Here is the approach based on [b1b79d9302] (i.e. main branch from 5 months ago): https://github.com/chrstphrchvz/tk/commit/0bbbbc3c7e If there is interest in this, I can create a branch on Fossil.

User Comments: marc_culler (claiming to be Marc Culler) added on 2026-10-10 02:35:11:
Hi Christopher, I apologize for losing track of this issue.  I reviewd it
again - it still looks good - and I merged your branch into 9.0 and 9.1.

I guess I can close the ticket.

chrstphrchvz added on 2026-10-08 20:48:14:

A year ago, I responded to Andrew Clarke on tcl-core to help get his TkHtml fork to retrieve a pixmap's CGContext, draw into it using Cairo, and then copy the pixmap into a widget. For that to work with Tk 9.0+, XCopyArea() needs to support pixmaps again. He successfully tried the change proposed here, and is wondering when this will be resolved. Marc, do you know when you could have a look at this? Thanks


chrstphrchvz added on 2025-08-16 01:42:49:

Please see Fossil branch bug-df4b603950-alt


marc_culler (claiming to be Marc Culler) added on 2025-08-15 21:10:06:
Hi Christopher.  I think this sounds very good.

> If there is interest in this, I can create a branch on Fossil.

Would you please be so kind as to do that?  Thanks.

chrstphrchvz added on 2025-08-11 17:38:59:

The approach here also allows [de6ef8276c] to be fixed; I verified this by no longer defining TK_CAN_RENDER_RGBA in tkMacOSXPort.h.


chrstphrchvz added on 2025-08-08 23:05:10:

Example script using TkImg to trigger a buffer overread in XGetImage() on a non-Retina display:

package require Tk
package require Img
. configure -width 200 -height 100 -background red ttk::button .b -text "Capture this button " -command {do_capture .b} place .b -x 20 -y 30
proc {do_capture} {w} { set capture_photo [image create photo -format window -data $w] toplevel .t$capture_photo pack [label .t$capture_photo.l -image $capture_photo] }

The overread occurs on the line:

pixel32 pixel = *((pixel32 *)(bitmap + m));
because XGetImage() is using a width (e.g. 223 pixels) which is wider than the image from CreateCGImageFromDrawableRect() (e.g. 180 pixels).