Pause SVG image animations when there are no clients / no clients in the visual viewport |
|||||
Issue descriptionWebKit just landed an interesting patch to pause SVG image animations when the SVG image is not used or is not in the viewport: https://bugs.webkit.org/show_bug.cgi?id=170155. They said this affects Yahoo.com.
,
Mar 28 2017
I think we can apply the same thing already done for LayoutBox and background-image
of LayoutBox that works for animated GIFs.
Animated GIF throttling works like this:
1. A timer fires from the image saying that the image has a new frame to draw
2. LayoutImage (or LayoutBox) hears that and invalidates paint on itself.
3. In the next document lifecycle, the Layout{Image,Box} paints itself. As part of
this it asks the image to paint itself into the display list.
4. When painting itself, BitmapImage::draw() will paint itself, then call
BitmapImpage::startAnimation() on itself. This sets off a timer to go back to step 1.
Our code short-circuits this cycle for animated GIFs by issuing a "delayed" paint
invalidation at step 2 when we notice that the GIF is not visible (by calling
LayoutBox::intersectsVisibleViewport). If that returns true, we upgrade to a non-delayed
invalidation for that frame, and otherwise issue an invalidation to be checked again
for paint invalidation in the next frame.
It appears that SVGImage uses the same pattern as BitmapImage, so therefore we can do the
same for SVG images. In fact, I'm not sure why it doesn't work already. Is the ImageResource not
returning maybeAnimated in invalidation in LayoutImage?
fs@ would you like to take a look?
,
Mar 28 2017
Adding to backlog.
,
Mar 29 2017
Looks like Image::maybeAnimated() isn't even overridden for SVGImage. Doing that should be easy enough since we already have essentially the same predicate already (from an old version of the same method even I think...)
,
Mar 29 2017
,
Mar 30 2017
,
Mar 31 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/bb03bc3127de97898e62323b12cd2997267cfd5a commit bb03bc3127de97898e62323b12cd2997267cfd5a Author: fs <fs@opera.com> Date: Fri Mar 31 10:38:13 2017 Implement Image::maybeAnimated for SVGImage This CL renames SVGImage::hasAnimations to maybeAnimated, overriding the implementation from the base class (Image.) The old method matches the new one in certainty of the reply, and allows SVGImages to be paused when being scrolled out of view etc. BUG= 706152 Review-Url: https://codereview.chromium.org/2783133002 Cr-Commit-Position: refs/heads/master@{#461094} [add] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/LayoutTests/paint/invalidation/svg/animated-svg-as-image-background-offscreen-expected.txt [add] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/LayoutTests/paint/invalidation/svg/animated-svg-as-image-background-offscreen.html [add] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/LayoutTests/paint/invalidation/svg/animated-svg-as-image-offscreen-expected.txt [add] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/LayoutTests/paint/invalidation/svg/animated-svg-as-image-offscreen.html [add] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/LayoutTests/paint/invalidation/svg/animated-svg-as-image-transformed-offscreen-expected.txt [add] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/LayoutTests/paint/invalidation/svg/animated-svg-as-image-transformed-offscreen.html [modify] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp [modify] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/Source/core/svg/graphics/SVGImage.h [modify] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/Source/core/svg/graphics/SVGImageChromeClient.cpp [modify] https://crrev.com/bb03bc3127de97898e62323b12cd2997267cfd5a/third_party/WebKit/Source/core/svg/graphics/SVGImageTest.cpp
,
Apr 3 2017
I think all components should be there now. |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by f...@opera.com
, Mar 28 2017