Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(672)

Side by Side Diff: third_party/WebKit/Source/core/svg/animation/SVGSMILElement.cpp

Issue 2592103002: Improve separation between "SMIL times" and timestamps (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/svg/animation/SVGSMILElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 } 975 }
976 } 976 }
977 } 977 }
978 m_nextProgressTime = elapsed; 978 m_nextProgressTime = elapsed;
979 979
980 if (m_timeContainer) 980 if (m_timeContainer)
981 m_timeContainer->notifyIntervalsChanged(); 981 m_timeContainer->notifyIntervalsChanged();
982 } 982 }
983 983
984 SVGSMILElement::RestartedInterval SVGSMILElement::maybeRestartInterval( 984 SVGSMILElement::RestartedInterval SVGSMILElement::maybeRestartInterval(
985 SMILTime elapsed) { 985 double elapsed) {
986 ASSERT(!m_isWaitingForFirstInterval); 986 DCHECK(!m_isWaitingForFirstInterval);
987 ASSERT(elapsed >= m_interval.begin); 987 DCHECK(elapsed >= m_interval.begin);
988 988
989 Restart restart = this->getRestart(); 989 Restart restart = this->getRestart();
990 if (restart == RestartNever) 990 if (restart == RestartNever)
991 return DidNotRestartInterval; 991 return DidNotRestartInterval;
992 992
993 if (elapsed < m_interval.end) { 993 if (elapsed < m_interval.end) {
994 if (restart != RestartAlways) 994 if (restart != RestartAlways)
995 return DidNotRestartInterval; 995 return DidNotRestartInterval;
996 SMILTime nextBegin = findInstanceTime(Begin, m_interval.begin, false); 996 SMILTime nextBegin = findInstanceTime(Begin, m_interval.begin, false);
997 if (nextBegin < m_interval.end) { 997 if (nextBegin < m_interval.end) {
998 m_interval.end = nextBegin; 998 m_interval.end = nextBegin;
999 notifyDependentsIntervalChanged(); 999 notifyDependentsIntervalChanged();
1000 } 1000 }
1001 } 1001 }
1002 1002
1003 if (elapsed >= m_interval.end) { 1003 if (elapsed >= m_interval.end) {
1004 if (resolveNextInterval() && elapsed >= m_interval.begin) 1004 if (resolveNextInterval() && elapsed >= m_interval.begin)
1005 return DidRestartInterval; 1005 return DidRestartInterval;
1006 } 1006 }
1007 return DidNotRestartInterval; 1007 return DidNotRestartInterval;
1008 } 1008 }
1009 1009
1010 void SVGSMILElement::seekToIntervalCorrespondingToTime(SMILTime elapsed) { 1010 void SVGSMILElement::seekToIntervalCorrespondingToTime(double elapsed) {
1011 ASSERT(!m_isWaitingForFirstInterval); 1011 DCHECK(!m_isWaitingForFirstInterval);
1012 ASSERT(elapsed >= m_interval.begin); 1012 DCHECK(elapsed >= m_interval.begin);
1013 1013
1014 // Manually seek from interval to interval, just as if the animation would run 1014 // Manually seek from interval to interval, just as if the animation would run
1015 // regulary. 1015 // regulary.
1016 while (true) { 1016 while (true) {
1017 // Figure out the next value in the begin time list after the current 1017 // Figure out the next value in the begin time list after the current
1018 // interval begin. 1018 // interval begin.
1019 SMILTime nextBegin = findInstanceTime(Begin, m_interval.begin, false); 1019 SMILTime nextBegin = findInstanceTime(Begin, m_interval.begin, false);
1020 1020
1021 // If the 'nextBegin' time is unresolved (eg. just one defined interval), 1021 // If the 'nextBegin' time is unresolved (eg. just one defined interval),
1022 // we're done seeking. 1022 // we're done seeking.
(...skipping 18 matching lines...) Expand all
1041 if (!resolveNextInterval()) 1041 if (!resolveNextInterval())
1042 break; 1042 break;
1043 continue; 1043 continue;
1044 } 1044 }
1045 1045
1046 return; 1046 return;
1047 } 1047 }
1048 } 1048 }
1049 1049
1050 float SVGSMILElement::calculateAnimationPercentAndRepeat( 1050 float SVGSMILElement::calculateAnimationPercentAndRepeat(
1051 SMILTime elapsed, 1051 double elapsed,
1052 unsigned& repeat) const { 1052 unsigned& repeat) const {
1053 SMILTime simpleDuration = this->simpleDuration(); 1053 SMILTime simpleDuration = this->simpleDuration();
1054 repeat = 0; 1054 repeat = 0;
1055 if (simpleDuration.isIndefinite()) { 1055 if (simpleDuration.isIndefinite()) {
1056 repeat = 0; 1056 repeat = 0;
1057 return 0.f; 1057 return 0.f;
1058 } 1058 }
1059 if (!simpleDuration) { 1059 if (!simpleDuration) {
1060 repeat = 0; 1060 repeat = 0;
1061 return 1.f; 1061 return 1.f;
1062 } 1062 }
1063 ASSERT(m_interval.begin.isFinite()); 1063 DCHECK(m_interval.begin.isFinite());
1064 ASSERT(simpleDuration.isFinite()); 1064 DCHECK(simpleDuration.isFinite());
1065 SMILTime activeTime = elapsed - m_interval.begin; 1065 double activeTime = elapsed - m_interval.begin.value();
1066 SMILTime repeatingDuration = this->repeatingDuration(); 1066 SMILTime repeatingDuration = this->repeatingDuration();
1067 if (elapsed >= m_interval.end || activeTime > repeatingDuration) { 1067 if (elapsed >= m_interval.end || activeTime > repeatingDuration) {
1068 repeat = static_cast<unsigned>(repeatingDuration.value() / 1068 repeat = static_cast<unsigned>(repeatingDuration.value() /
1069 simpleDuration.value()); 1069 simpleDuration.value());
1070 if (!fmod(repeatingDuration.value(), simpleDuration.value())) 1070 if (!fmod(repeatingDuration.value(), simpleDuration.value()))
1071 repeat--; 1071 repeat--;
1072 1072
1073 double percent = (m_interval.end.value() - m_interval.begin.value()) / 1073 double percent = (m_interval.end.value() - m_interval.begin.value()) /
1074 simpleDuration.value(); 1074 simpleDuration.value();
1075 percent = percent - floor(percent); 1075 percent = percent - floor(percent);
1076 if (percent < std::numeric_limits<float>::epsilon() || 1076 if (percent < std::numeric_limits<float>::epsilon() ||
1077 1 - percent < std::numeric_limits<float>::epsilon()) 1077 1 - percent < std::numeric_limits<float>::epsilon())
1078 return 1.0f; 1078 return 1.0f;
1079 return clampTo<float>(percent); 1079 return clampTo<float>(percent);
1080 } 1080 }
1081 repeat = static_cast<unsigned>(activeTime.value() / simpleDuration.value()); 1081 repeat = static_cast<unsigned>(activeTime / simpleDuration.value());
1082 SMILTime simpleTime = fmod(activeTime.value(), simpleDuration.value()); 1082 double simpleTime = fmod(activeTime, simpleDuration.value());
1083 return clampTo<float>(simpleTime.value() / simpleDuration.value()); 1083 return clampTo<float>(simpleTime / simpleDuration.value());
1084 } 1084 }
1085 1085
1086 SMILTime SVGSMILElement::calculateNextProgressTime(SMILTime elapsed) const { 1086 SMILTime SVGSMILElement::calculateNextProgressTime(double elapsed) const {
1087 if (m_activeState == Active) { 1087 if (m_activeState == Active) {
1088 // If duration is indefinite the value does not actually change over time. 1088 // If duration is indefinite the value does not actually change over time.
1089 // Same is true for <set>. 1089 // Same is true for <set>.
1090 SMILTime simpleDuration = this->simpleDuration(); 1090 SMILTime simpleDuration = this->simpleDuration();
1091 if (simpleDuration.isIndefinite() || isSVGSetElement(*this)) { 1091 if (simpleDuration.isIndefinite() || isSVGSetElement(*this)) {
1092 SMILTime repeatingDurationEnd = m_interval.begin + repeatingDuration(); 1092 SMILTime repeatingDurationEnd = m_interval.begin + repeatingDuration();
1093 // We are supposed to do freeze semantics when repeating ends, even if the 1093 // We are supposed to do freeze semantics when repeating ends, even if the
1094 // element is still active. 1094 // element is still active.
1095 // Take care that we get a timer callback at that point. 1095 // Take care that we get a timer callback at that point.
1096 if (elapsed < repeatingDurationEnd && 1096 if (elapsed < repeatingDurationEnd &&
1097 repeatingDurationEnd < m_interval.end && 1097 repeatingDurationEnd < m_interval.end &&
1098 repeatingDurationEnd.isFinite()) 1098 repeatingDurationEnd.isFinite())
1099 return repeatingDurationEnd; 1099 return repeatingDurationEnd;
1100 return m_interval.end; 1100 return m_interval.end;
1101 } 1101 }
1102 return elapsed + 0.025; 1102 return elapsed + 0.025;
1103 } 1103 }
1104 return m_interval.begin >= elapsed ? m_interval.begin 1104 return m_interval.begin >= elapsed ? m_interval.begin
1105 : SMILTime::unresolved(); 1105 : SMILTime::unresolved();
1106 } 1106 }
1107 1107
1108 SVGSMILElement::ActiveState SVGSMILElement::determineActiveState( 1108 SVGSMILElement::ActiveState SVGSMILElement::determineActiveState(
1109 SMILTime elapsed) const { 1109 SMILTime elapsed) const {
1110 if (elapsed >= m_interval.begin && elapsed < m_interval.end) 1110 if (elapsed >= m_interval.begin && elapsed < m_interval.end)
1111 return Active; 1111 return Active;
1112 1112
1113 return fill() == FillFreeze ? Frozen : Inactive; 1113 return fill() == FillFreeze ? Frozen : Inactive;
1114 } 1114 }
1115 1115
1116 bool SVGSMILElement::isContributing(SMILTime elapsed) const { 1116 bool SVGSMILElement::isContributing(double elapsed) const {
1117 // Animation does not contribute during the active time if it is past its 1117 // Animation does not contribute during the active time if it is past its
1118 // repeating duration and has fill=remove. 1118 // repeating duration and has fill=remove.
1119 return (m_activeState == Active && 1119 return (m_activeState == Active &&
1120 (fill() == FillFreeze || 1120 (fill() == FillFreeze ||
1121 elapsed <= m_interval.begin + repeatingDuration())) || 1121 elapsed <= m_interval.begin + repeatingDuration())) ||
1122 m_activeState == Frozen; 1122 m_activeState == Frozen;
1123 } 1123 }
1124 1124
1125 bool SVGSMILElement::progress(SMILTime elapsed, bool seekToTime) { 1125 bool SVGSMILElement::progress(double elapsed, bool seekToTime) {
1126 ASSERT(m_timeContainer); 1126 ASSERT(m_timeContainer);
1127 ASSERT(m_isWaitingForFirstInterval || m_interval.begin.isFinite()); 1127 ASSERT(m_isWaitingForFirstInterval || m_interval.begin.isFinite());
1128 1128
1129 if (!m_syncBaseConditionsConnected) 1129 if (!m_syncBaseConditionsConnected)
1130 connectSyncBaseConditions(); 1130 connectSyncBaseConditions();
1131 1131
1132 if (!m_interval.begin.isFinite()) { 1132 if (!m_interval.begin.isFinite()) {
1133 ASSERT(m_activeState == Inactive); 1133 ASSERT(m_activeState == Inactive);
1134 m_nextProgressTime = SMILTime::unresolved(); 1134 m_nextProgressTime = SMILTime::unresolved();
1135 return false; 1135 return false;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 DEFINE_TRACE(SVGSMILElement) { 1352 DEFINE_TRACE(SVGSMILElement) {
1353 visitor->trace(m_targetElement); 1353 visitor->trace(m_targetElement);
1354 visitor->trace(m_timeContainer); 1354 visitor->trace(m_timeContainer);
1355 visitor->trace(m_conditions); 1355 visitor->trace(m_conditions);
1356 visitor->trace(m_syncBaseDependents); 1356 visitor->trace(m_syncBaseDependents);
1357 SVGElement::trace(visitor); 1357 SVGElement::trace(visitor);
1358 SVGTests::trace(visitor); 1358 SVGTests::trace(visitor);
1359 } 1359 }
1360 1360
1361 } // namespace blink 1361 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/animation/SVGSMILElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698