Bug 245032

Summary: Stop applying transforms on root/canvas background-image
Product: WebKit Reporter: Tim Nguyen (:ntim) <ntim>
Component: Layout and RenderingAssignee: Matt Woodrow <mattwoodrow>
Status: NEW ---    
Severity: Normal CC: ahmad.saleem792, bfulgham, karlcow, mattwoodrow, nmouchtaris, simon.fraser, webkit-bug-importer, zalan
Priority: P2 Keywords: BrowserCompat, InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Description Tim Nguyen (:ntim) 2022-09-10 11:42:04 PDT
Affected WPT:

css/css-transforms/transform-root-bg-001.html : https://wpt.live/css/css-transforms/transform-root-bg-001.html
css/css-transforms/transform-root-bg-002.html : https://wpt.live/css/css-transforms/transform-root-bg-002.html
css/css-transforms/transform-root-bg-003.html : https://wpt.live/css/css-transforms/transform-root-bg-003.html
Comment 1 Radar WebKit Bug Importer 2022-09-10 11:57:23 PDT
<rdar://problem/99782177>
Comment 2 Tim Nguyen (:ntim) 2022-09-12 18:26:51 PDT
There are more affected WPT:
css/css-transforms/transform-translate-background-001.html
css/css-transforms/transform-translate-background-002.html
css/css-transforms/transform-background-007.html
css/css-transforms/transform-background-008.html
Comment 3 Matt Woodrow 2022-09-20 19:50:06 PDT
I think these tests are potentially wrong, depending on the outcome of https://github.com/w3c/csswg-drafts/issues/6683.

As dbaron says, the current spec wording expects us to not transform backgrounds on the root element, unless background-attachment is fixed.

If that's the case, then the tests are invalid, since they're testing that the transform does get applied (which is why Gecko also fails the test, since they don't apply the transform).

I think we should consider getting these tests removed from interop, until we have a clear spec resolution, and tests that reflect it.
Comment 4 Matt Woodrow 2022-09-20 19:54:49 PDT
The bug as originally stated (incorrect number of repeated images for transformed repeated backgrounds) is because BackgroundPainter::calculateBackgroundImageGeometry is computing a destination drawing area in coordinates after the transform has been applied.

We then pass that rectangle to GraphicsContext::drawTiledImage, which expects a destination rectangle in pre-transform coordinates.

I think we'd need to transform all the relevant coordinates by the inverse of the transform on the root element (destinationRect, borderBoxRect, positioningAreaSize, left, top etc).

There's a lot of complexity around which coordinate space to use when computing tiling size, pixel snapping, background-repeat: round/space etc. None of that appears to be specified currently, nor are there any tests.
Comment 5 Tim Nguyen (:ntim) 2022-10-05 21:02:04 PDT
So the CSSWG resolution was to stop applying transforms on background-images for the root: https://github.com/w3c/csswg-drafts/issues/6683#issuecomment-1269092125
Comment 6 Tim Nguyen (:ntim) 2022-10-05 21:57:53 PDT
Pull request: https://github.com/WebKit/WebKit/pull/5069
Comment 7 Tim Nguyen (:ntim) 2022-10-06 07:42:21 PDT
Tests were updated here: https://github.com/web-platform-tests/wpt/pull/36306
Comment 8 Ahmad Saleem 2023-05-13 17:42:25 PDT
(In reply to Tim Nguyen (:ntim) from comment #2)
> There are more affected WPT:
> css/css-transforms/transform-translate-background-001.html
> css/css-transforms/transform-translate-background-002.html
> css/css-transforms/transform-background-007.html
> css/css-transforms/transform-background-008.html

Still failing as of STP169.
Comment 9 Matt Woodrow 2023-08-13 21:11:03 PDT
Pull request: https://github.com/WebKit/WebKit/pull/16657
Comment 10 Matt Woodrow 2023-09-03 19:19:19 PDT
Pull request: https://github.com/WebKit/WebKit/pull/17395
Comment 11 Matt Woodrow 2023-09-07 21:03:50 PDT
Pull request: https://github.com/WebKit/WebKit/pull/17570