Revise shapePhoto()
to not use TkPhotoGetValidRegion()
#8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
shapePhoto()
currently works by obtaining a region fromTkPhotoGetValidRegion()
and passing it toShape_CombineRegion()
(and in turnXShapeCombineRegion()
on X11). However,TkPhotoGetValidRegion()
is not a public Tk C API. And as discussed at https://core.tcl-lang.org/tk/info/919066 it takes a very long time to compute the region for some images, and I am not aware of an instance in core Tk or an extension where using this region is strictly necessary. Tk could draw photo image instances using a clip mask rather than a region (as attempted in chrstphrchvz/tk#4). I propose thatshapePhoto()
follow a similar approach: use the public APITk_PhotoGetImage()
to access alpha channel data and create a bitmap (pixmap with depth of 1) for use a clip mask to be passed toShape_CombineBitmap()
(and in turnXShapeCombineMask()
on X11).Note that this would leave
Shape_CombineRegion()
unused within the shape extension.If Tk 8.3 or later can be required, then this approach allows photo shape source support to be enabled unconditionally. That should also make it okay for demos to use a photo shape source. As an example, I propose revising the dragger.tcl demo: instead of using doc-mask.xbm as a bitmap shape source, make doc-img.gif have a transparent background and use it as a photo shape source; the demo should look the same as before.
I have tested this using recent Tk core-8-6-branch on XQuartz (macOS), after applying demo and build fixes/workarounds (some from #7, some not reported). Some build fixes are currently included in this pull request, but can be moved to another pull request if desirable.