Skip to content

Commit

Permalink
CSS animations in SVG do not repaint when SVG is zoomed
Browse files Browse the repository at this point in the history
CSS animations in SVG do not repaint when SVG is zoomed
https://bugs.webkit.org/show_bug.cgi?id=199364
rdar://problem/52459928

Reviewed by NOBODY (OOPS!).

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

This patch changes the coordinate system used by RenderImage 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 RenderImage::repaintOrMarkForLayout and clarifies the comment.

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

From local build testing, I have verified that this does indeed fix an issue
described on test case from the bug.

* Source/WebCore/rendering/RenderImage.cpp:
(RenderImage::repaintOrMarkForLayout): Update Comment and simplify logic
to remove for 'zoom' factor
* LayoutTests/svg/repaint/resources/animate-center.svg: Add Test Case Resource
* LayoutTests/svg/repaint/image-animation-with-zoom.html: Add Test Case
* LayoutTests/svg/repaint/image-animation-with-zoom-expected.txt: Add Test Case Expectation
  • Loading branch information
Ahmad-S792 committed Jan 30, 2023
1 parent 8c0586d commit 84bc61d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


28 changes: 28 additions & 0 deletions LayoutTests/svg/repaint/image-animation-with-zoom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<script src="../../fast/repaint/resources/text-based-repaint.js"></script>
<style>
html {
zoom: 2.2
}
* {
margin: 0;
padding: 0;
}
img {
width: 50px;
height: 50px;
}
</style>
<body onload="runRepaintTest()">
<img src="resources/animate-center.svg" width="200px" height="200px"></img>
<script>
function repaintTest() {
if (window.testRunner)
testRunner.waitUntilDone();
setTimeout(function() {
if (window.testRunner)
testRunner.notifyDone();
}, 100);
};
</script>
</body>
17 changes: 17 additions & 0 deletions LayoutTests/svg/repaint/resources/animate-center.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions Source/WebCore/rendering/RenderImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* (C) 2000 Dirk Mueller (mueller@kde.org)
* (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com)
* (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2003-2021 Apple Inc. All rights reserved.
* Copyright (C) 2010 Google Inc. All rights reserved.
* Copyright (C) 2003-2023 Apple Inc. All rights reserved.
* Copyright (C) 2010-2014 Google Inc. All rights reserved.
* Copyright (C) Research In Motion Limited 2011-2012. All rights reserved.
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -379,9 +379,10 @@ void RenderImage::repaintOrMarkForLayout(ImageSizeChangeType imageSizeChange, co

LayoutRect repaintRect = contentBoxRect();
if (rect) {
// The image changed rect is in source image coordinates (pre-zooming),
// The image changed rect is in source image coordinates (without zoom),
// 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)));
}

repaintRectangle(repaintRect);
Expand Down

0 comments on commit 84bc61d

Please sign in to comment.