Skip to content

Cull simple non-empty canvas text drawing outside of the clip#61305

Open
squelart wants to merge 1 commit intoWebKit:mainfrom
squelart:eng/cull-simple-non-empty-canvas-text-drawing-outside-clip
Open

Cull simple non-empty canvas text drawing outside of the clip#61305
squelart wants to merge 1 commit intoWebKit:mainfrom
squelart:eng/cull-simple-non-empty-canvas-text-drawing-outside-clip

Conversation

@squelart
Copy link
Contributor

@squelart squelart commented Mar 25, 2026

a37ac2d

Cull simple non-empty canvas text drawing outside of the clip
https://bugs.webkit.org/show_bug.cgi?id=306394
rdar://172308695

Reviewed by NOBODY (OOPS!).

In simple cases where no-frills text would be drawn on top of a canvas,
it's easy and fast to check if the text does NOT intersect with the
current clip, in which case the whole operation can safely be skipped.

As an exception, if the textRect is computed to be empty (zero width or
height), it is assumed to be of unknown but actually-non-empty size, so
the optimization is just skipped. This may be used by some websites to
obscure privacy-sensitive texts.

* LayoutTests/fast/canvas/fillText-edge-clip-expected.html: Added.
* LayoutTests/fast/canvas/fillText-edge-clip-shadow-expected.html: Added.
* LayoutTests/fast/canvas/fillText-edge-clip-shadow.html: Added.
* LayoutTests/fast/canvas/fillText-edge-clip.html: Added.
* LayoutTests/fast/canvas/fillText-edge-expected.html: Added.
* LayoutTests/fast/canvas/fillText-edge-shadow-expected.html: Added.
* LayoutTests/fast/canvas/fillText-edge-shadow.html: Added.
* LayoutTests/fast/canvas/fillText-edge.html: Added.
* LayoutTests/fast/canvas/fillText-empty-clip-expected.html: Added.
* LayoutTests/fast/canvas/fillText-empty-clip.html: Added.
* LayoutTests/platform/win/TestExpectations:
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::drawTextUnchecked):

a37ac2d

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win loading 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests loading 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe loading 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

https://bugs.webkit.org/show_bug.cgi?id=306394
rdar://172308695

Reviewed by NOBODY (OOPS!).

In simple cases where no-frills text would be drawn on top of a canvas,
it's easy and fast to check if the text does NOT intersect with the
current clip, in which case the whole operation can safely be skipped.

As an exception, if the textRect is computed to be empty (zero width or
height), it is assumed to be of unknown but actually-non-empty size, so
the optimization is just skipped. This may be used by some websites to
obscure privacy-sensitive texts.

* LayoutTests/fast/canvas/fillText-edge-clip-expected.html: Added.
* LayoutTests/fast/canvas/fillText-edge-clip-shadow-expected.html: Added.
* LayoutTests/fast/canvas/fillText-edge-clip-shadow.html: Added.
* LayoutTests/fast/canvas/fillText-edge-clip.html: Added.
* LayoutTests/fast/canvas/fillText-edge-expected.html: Added.
* LayoutTests/fast/canvas/fillText-edge-shadow-expected.html: Added.
* LayoutTests/fast/canvas/fillText-edge-shadow.html: Added.
* LayoutTests/fast/canvas/fillText-edge.html: Added.
* LayoutTests/fast/canvas/fillText-empty-clip-expected.html: Added.
* LayoutTests/fast/canvas/fillText-empty-clip.html: Added.
* LayoutTests/platform/win/TestExpectations:
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::drawTextUnchecked):
@squelart squelart requested review from cdumez and rniwa as code owners March 25, 2026 04:27
@squelart squelart self-assigned this Mar 25, 2026
@squelart squelart added the Layout and Rendering For bugs with layout and rendering of Web pages. label Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Layout and Rendering For bugs with layout and rendering of Web pages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants