Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS animations in SVG do not repaint when SVG is zoomed #4727

Closed
wants to merge 1 commit into from

Conversation

Ahmad-S792
Copy link
Contributor

@Ahmad-S792 Ahmad-S792 commented Sep 26, 2022

CSS animations in SVG do not repaint when SVG is zoomed

https://bugs.webkit.org/show_bug.cgi?id=199364

Reviewed by NOBODY (OOPS!).

Merge - https://src.chromium.org/viewvc/blink?view=revision&revision=174874

This patch changes the coordinate system used by RenderSVGImage for invalidation rects to account for zoom. When an SVG image issues invalidations to its ImageResource clients, the invalidation rect does not contain zoom. This is due to how SVG images work internally:
images are laid out without zoom so that relative sizes are resolved
correctly; as a result the invalidation rects do not include zoom. This patch simply removes the zoom from the image size in RenderSVGImage::repaintOrMarkForLayout and clarifies the comment.

This change should not affect bitmap image invalidation because bitmaps (even animated gifs) do not use invalidation rects.

* Source/WebCore/rendering/svg/RenderSVGImage.cpp:
(RenderSVGImage::repaintOrMarkForLayout): Update Comment and simplify logic to remove for 'zoom' factor
* LayoutTests/svg/repaint/resources/animate-center.svg: Added Resource for Testcase
* LayoutTests/svg/repaint/image-animation-with-zoom.html: Added Test Case
* LayoutTests/svg/repaint/image-animation-with-zoom-expected.txt: Added Test Case Expectations

d17f0b0

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe ❌ πŸ›  πŸ§ͺ win
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-debug βœ… πŸ›  gtk βœ… πŸ›  wincairo
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-wk1
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2
βœ… πŸ›  watch βœ… πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  watch-sim βœ… πŸ§ͺ mac-wk2-stress

@Ahmad-S792 Ahmad-S792 self-assigned this Sep 26, 2022
@Ahmad-S792 Ahmad-S792 added SVG For bugs in the SVG implementation. WebKit Nightly Build labels Sep 26, 2022
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 26, 2022
@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Sep 26, 2022
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 26, 2022
@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Sep 27, 2022
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 27, 2022
CSS animations in SVG do not repaint when SVG is zoomed

https://bugs.webkit.org/show_bug.cgi?id=199364

Reviewed by NOBODY (OOPS!).

Merge - https://src.chromium.org/viewvc/blink?view=revision&revision=174874

This patch changes the coordinate system used by RenderSVGImage for invalidation rects to account for zoom. When an SVG image issues invalidations to its ImageResource clients, the invalidation rect does not contain zoom. This is due to how SVG images work internally:
images are laid out without zoom so that relative sizes are resolved
correctly; as a result the invalidation rects do not include zoom. This patch simply removes the zoom from the image size in RenderSVGImage::repaintOrMarkForLayout and clarifies the comment.

This change should not affect bitmap image invalidation because bitmaps (even animated gifs) do not use invalidation rects.

* Source/WebCore/rendering/svg/RenderSVGImage.cpp:
(RenderSVGImage::repaintOrMarkForLayout): Update Comment and simplify logic to remove for 'zoom' factor
* LayoutTests/svg/repaint/resources/animate-center.svg: Added Resource for Testcase
* LayoutTests/svg/repaint/image-animation-with-zoom.html: Added Test Case
* LayoutTests/svg/repaint/image-animation-with-zoom-expected.txt: Added Test Case Expectations
// so map from the bounds of the image to the contentsBox.
repaintRect.intersect(enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint(), imageResource().imageSize(1.0f)), repaintRect)));
const LayoutSize imageSizeWithoutZoom = m_imageResource->imageSize(1 / style().effectiveZoom());
repaintRect.intersect(enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint(), imageSizeWithoutZoom), repaintRect)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RenderSVGImage is only used for LBSE. Is your plan not to fix it for LegacyRenderSVGImage? Also RenderSVGImage and LegacyRenderSVGImage are created for SVG <image> element https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image. Your test case does not include any SVG <image> element. Instead it includes the HTML <img> element which is rendered through SVGImage::draw().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - I will add similar to LegacyRenderSVGImage. As for the test case, I am doing merge from Blink patch and it is more repaint / style invalidation fix when CSS animations are applied to SVG image in <img> rather than <image> element while zoomed. If you want me to add <image> case then I can try but I just started dwelling in Webkit Codebase and still novice so I might not be able to do it for sure but worth giving it a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had a look into LegacyRenderSVGImage and I think it does not have same codepath as the above and in some point from Legacy to LBSE, we moved this part to LBSE use and I think this Blink merge would be limited to this path. If I am missing anything, happy to be guided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reported test case in Bugzilla https://jstsch.com/misc/2019/7/safari-svg-zoom.html is not fixed with this change. This happens with LBSE on or off.

Also when opening the test case you added in this PR in mini-browser, it is not displayed correctly with this change. A pink rectangle is drawn with smaller green rectangle at its top-left corner. When refreshing the page only a green rectangle is displayed. This happens with LBSE on and off.

So I am not sure what this PR is fixing. I think you need to investigate these two cases and understand the problem more. Feel free to ask questions on slack. Also make sure the added layout test exercises the modified code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing PR to investigate and documenting stuff on bug as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LBSE + zooming is currently broken anyhow -- a general fix is underways for LBSE that will fix zooming/panning for absolute/relative sized documents with/without viewBox, within subtrees, SVGImages, etc..
-> A huge interop benefit, as Safari currently deviates (impossible to enlarge SVGs with relative sized width/height that have a viewBox set) from all other browsers [funny thought that I. made it like this also to restore inter-op in 2012, where Opera/FF followed these rules).

setTimeout(function() {
if (window.testRunner)
finishRepaintTest();
}, 220);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using setTimeout(..., 220) here is a little bit fragile. I do not think there I a guarantee that the CSS animation in the SVG image resource will finish in 200ms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I increase it? I looked into this test case from Chromium source and it is using 'rAf' but we don't have infrastructure in TestRunner to use "paintUnderInvalidationCheckingEnabled" and those bits so it wouldn't be possible to port latest Chromium test case code here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is guaranteed to lead to flakey tests -- the timing cannot be guaranteed like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merging-blocked Applied to prevent a change from being merged SVG For bugs in the SVG implementation.
Projects
None yet
5 participants