8000 Compute the keyTimes index correctly for discrete (values) animations · WebKit/WebKit@580e961 · GitHub
[go: up one dir, main page]

Skip to content

Commit 580e961

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
Compute the keyTimes index correctly for discrete (values) animations
Compute the keyTimes index correctly for discrete (values) animations https://bugs.webkit.org/show_bug.cgi?id=250643 Reviewed by Simon Fraser. This patch is to align WebKit with Blink / Chromium and Gecko / Firefox. Merge - https://chromium.googlesource.com/chromium/blink/+/be50d8baacafe25f3a96d22be3e9a96ab882df4a This patch is to modify to ensure that the last value is allowed to be non-one for discrete mode animations (but not for linear and spline mode animations). * Source/WebCore/svg/SVGAnimationElement.cpp: (SVGAnimationElement::calaculateKeyTimesIndex): Update function to exclude 'discrete' mode (SVGAnimationElement::calculatePercentFromKeyPoints): Add ASSERT and move functions after Disrete mode * LayoutTests/imported/w3c/web-platform-tests/svg/animations/animate-elem-18-t-drt-expected.txt: Rebaselined * LayoutTests/imported/w3c/web-platform-tests/svg/animations/animate-elem-14-t-drt-expected.txt: Ditto * LayoutTests/svg/animations/animate-elem-14-t-drt-expected.txt: Ditto * LayoutTests/svg/animations/animate-elem-18-t-drt-expected.txt: Ditto Canonical link: https://commits.webkit.org/258939@main
1 parent 19ed940 commit 580e961

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

LayoutTests/imported/w3c/web-platform-tests/svg/animations/animate-elem-14-t-drt-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ Time (s):
77
6
88
$Revision: 1.6 $
99

10-
FAIL A copy of the corresponding W3C-SVG-1.1 test, which dumps the animation at certain times assert_approx_equals: expected 30 +/- 1 but got 180
10+
PASS A copy of the corresponding W3C-SVG-1.1 test, which dumps the animation at certain times
1111

LayoutTests/imported/w3c/web-platform-tests/svg/animations/animate-elem-18-t-drt-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ Time (s):
77
8
88
$Revision: 1.1 $
99

10-
FAIL A copy of the corresponding W3C-SVG-1.1 test, which dumps the animation at certain times assert_approx_equals: expected 30 +/- 1 but got 180
10+
PASS A copy of the corresponding W3C-SVG-1.1 test, which dumps the animation at certain times
1111

LayoutTests/svg/animations/animate-elem-14-t-drt-expected.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ PASS rect.width.animVal.value is 180
1818
PASS rect.width.baseVal.value is 300
1919
PASS rect.width.animVal.value is 180
2020
PASS rect.width.baseVal.value is 300
21-
FAIL rect.width.animVal.value should be close to 30. Was 180.
21+
PASS rect.width.animVal.value is 30
2222
PASS rect.width.baseVal.value is 300
23-
FAIL rect.width.animVal.value should be close to 30. Was 180.
23+
PASS rect.width.animVal.value is 30
2424
PASS rect.width.baseVal.value is 300
25-
FAIL rect.width.animVal.value should be close to 30. Was 180.
25+
PASS rect.width.animVal.value is 30
2626
PASS rect.width.baseVal.value is 300
27-
FAIL rect.width.animVal.value should be close to 30. Was 180.
27+
PASS rect.width.animVal.value is 30
2828
PASS rect.width.baseVal.value is 300
29-
FAIL rect.width.animVal.value should be close to 30. Was 180.
29+
PASS rect.width.animVal.value is 30
3030
PASS rect.width.baseVal.value is 300
3131
PASS rect.width.animVal.value is 30
3232
PASS rect.width.baseVal.value is 300

LayoutTests/svg/animations/animate-elem-18-t-drt-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ PASS rect.width.animVal.value is 180
1818
PASS rect.width.baseVal.value is 300
1919
PASS rect.width.animVal.value is 180
2020
PASS rect.width.baseVal.value is 300
21-
FAIL rect.width.animVal.value should be close to 30. Was 180.
21+
PASS rect.width.animVal.value is 30
2222
PASS rect.width.baseVal.value is 300
23-
FAIL rect.width.animVal.value should be close to 30. Was 180.
23+
PASS rect.width.animVal.value is 30
2424
PASS rect.width.baseVal.value is 300
2525
PASS rect.width.animVal.value is 30
2626
PASS rect.width.baseVal.value is 300

Source/WebCore/svg/SVGAnimationElement.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
* Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
33
* Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
44
* Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5-
* Copyright (C) 2008-2021 Apple Inc. All rights reserved.
5+
* Copyright (C) 2008-2023 Apple Inc. All rights reserved.
66
* Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
77
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
88
* Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved.
9+
* Copyright (C) 2013 Google Inc. All rights reserved.
910
*
1011
* This library is free software; you can redistribute it and/or
1112
* modify it under the terms of the GNU Library General Public
@@ -403,10 +404,12 @@ unsigned SVGAnimationElement::calculateKeyTimesIndex(float percent) const
403404
const auto& keyTimes = this->keyTimes();
404405
unsigned index;
405406
unsigned keyTimesCount = keyTimes.size();
406-
// Compare index + 1 to keyTimesCount because the last keyTimes entry is
407-
// required to be 1, and percent can never exceed 1; i.e., the second last
408-
// keyTimes entry defines the beginning of the final interval
409-
for (index = 1; index + 1 < keyTimesCount; ++index) {
407+
// For linear and spline animations, the last value must be '1'. In those
408+
// cases we don't need to consider the last value, since |percent| is never
409+
// greater than one.
410+
if (keyTimesCount && calcMode() != CalcMode::Discrete)
411+
--keyTimesCount;
412+
for (index = 1; index < keyTimesCount; ++index) {
410413
if (keyTimes[index] > percent)
411414
break;
412415
}
@@ -437,14 +440,15 @@ float SVGAnimationElement::calculatePercentFromKeyPoints(float percent) const
437440
return m_keyPoints[m_keyPoints.size() - 1];
438441

439442
unsigned index = calculateKeyTimesIndex(percent);
440-
float fromPercent = keyTimes[index];
441-
float toPercent = keyTimes[index + 1];
442443
float fromKeyPoint = m_keyPoints[index];
443-
float toKeyPoint = m_keyPoints[index + 1];
444444

445445
if (calcMode() == CalcMode::Discrete)
446446
return fromKeyPoint;
447447

448+
ASSERT(index + 1 < keyTimes.size());
449+
float fromPercent = keyTimes[index];
450+
float toPercent = keyTimes[index + 1];
451+
float toKeyPoint = m_keyPoints[index + 1];
448452
float keyPointPercent = (percent - fromPercent) / (toPercent - fromPercent);
449453

450454
if (calcMode() == CalcMode::Spline) {

0 commit comments

Comments
 (0)
0