Closed Bug 2091406 Opened 7 days ago Closed

[wpt-sync] Sync PR 64498 - WebKit export of https://bugs.webkit.org/show_bug.cgi?id=322160

Categories

(Core :: Graphics: Canvas2D, task, P4)

task

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Sync web-platform-tests PR 64498 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/64498
Details from upstream follow.

Ahmad Saleem <ahmad.saleem792+github@gmail.com> wrote:

WebKit export of https://bugs.webkit.org/show_bug.cgi?id=322160

WebKit export from bug: Canvas 2D hit testing and transform mutations should not require the canvas bitmap

<pre>
Canvas 2D hit testing and transform mutations should not require the canvas bitmap

isPointInPath(), isPointInStroke(), drawFocusIfNeeded() and all six CTM
mutators opened with if (!effectiveDrawingContext()) return;. That runs
buffer() -> allocateImageBuffer(), so a pure geometry query on a fresh
canvas committed width * height * 4 bytes plus an IOSurface. Neither
hit-testing helper uses the context it fetched: Path::contains() is a CG
path query, and PathCG::strokeContains() builds its own GraphicsContext
over the 1x1 scratchContext().

It is also a correctness bug. validateArea() returns false when the area
is zero, so a canvas with a zero width or height has no bitmap at all.
Hit tests therefore returned false for points genuinely inside the path,
and every CTM mutation was silently dropped.

The spec does not permit this. Per the canvas state [1]: "The rendering
context's bitmaps are not part of the drawing state, as they depend on
whether and how the rendering context is bound to a canvas element." The
same section lists "The current transformation matrix." as the first
component of the drawing state. Nor is the CTM merely a painting input:
"The current transformation matrix is applied to coordinates when
creating the current default path, and when painting text, shapes, and
Path2D objects" [2]. Dropping a mutation therefore corrupts the path as
it is built -- which is what we do, by folding the inverse into m_path --
so the damage does not depend on there being a bitmap to paint into.

Both hit-testing algorithms are likewise pure geometry once the
non-finite check has run [3][4], over inputs that all exist without a
backing store: the current default path, of which "There is only one
current default path, it is not part of the drawing state" [5], the CTM,
and for isPointInStroke() the line styles of the CanvasPathDrawingStyles
mixin. Firefox already behaves this way; Chrome matches our old behavior.

Drop the check outright in the two hit-testing helpers, move the fetch to
the point of use behind if (auto* c = effectiveDrawingContext()) in the
mutators so the state update happens either way, and hoist the cheap
early-outs above the fetch in drawFocusIfNeededInternal() so the common
unfocused case no longer allocates.

Reordering cannot let state().transform drift from the context CTM:
m_hasCreatedImageBuffer is only cleared by didUpdateCanvasSizeProperties()
on a size change, which also resets the state stack and clears the path.

[1] <a href="https://html.spec.whatwg.org/multipage/canvas.html#the-canvas-state">https://html.spec.whatwg.org/multipage/canvas.html#the-canvas-state</a>
[2] <a href="https://html.spec.whatwg.org/multipage/canvas.html#transformations">https://html.spec.whatwg.org/multipage/canvas.html#transformations</a>
[3] <a href="https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinpath">https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinpath</a>
[4] <a href="https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinstroke">https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinstroke</a>
[5] <a href="https://html.spec.whatwg.org/multipage/canvas.html#current-default-path">https://html.spec.whatwg.org/multipage/canvas.html#current-default-path</a>

Those live under html/canvas/{element,offscreen}/path-objects/ and are
generated by /html/canvas/tools/gentest.py from tools/yaml/path-objects.yaml,
so the seven new YAML entries emit the HTMLCanvasElement, OffscreenCanvas and
worker flavor of each. All 21 baselines are a FAIL before this change.

Add the YAML these tests were generated from to path-objects.yaml. WebKit has the generated files but not the YAML; gentest.py generates the tests from it byte for byte.

WebKit-Bug: <a href="https://bugs.webkit.org/show_bug.cgi?id=322160">https://bugs.webkit.org/show_bug.cgi?id=322160</a>
WebKit-Canonical-Link: <a href="https://commits.webkit.org/319602@main">https://commits.webkit.org/319602@main</a>
</pre>

Component: web-platform-tests → Graphics: Canvas2D
Product: Testing → Core

CI Results

Ran 4 Firefox configurations based on mozilla-central, and Firefox, Chrome, and Safari on GitHub CI

Total 632 tests and 1 subtests

Status Summary

Firefox

OK : 21[GitHub] 626[Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt] 631[Gecko-linux2404-64-debug] 632[Gecko-linux2404-64-opt]
PASS: 21[GitHub] 614[Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt] 620[Gecko-linux2404-64-debug, Gecko-linux2404-64-opt]
FAIL: 12

Chrome

OK : 21
FAIL: 21

Safari

OK : 21
PASS: 21

Links

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Details

New Tests That Don't Pass

Tests Disabled in Gecko Infrastructure

Status: NEW → RESOLVED
Closed: 4 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
You need to log in before you can comment on or make changes to this bug.