Commit e3872314 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Remove the SMILTime(double) constructor

This eliminates implicit conversions to SMILTime.

Adds FromSecondsD and FromMicroseconds to SMILTime. This is otherwise
mostly s/0/SMILTime()/ and adding From{SecondsD,Microseconds} where
needed.

Bug: 1003338
Change-Id: I164c644a3b6161e9546af0049de9563d2c7beae2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1803313
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696744}
parent 3a0b072b
...@@ -44,7 +44,6 @@ class SMILTime { ...@@ -44,7 +44,6 @@ class SMILTime {
public: public:
constexpr SMILTime() : time_(0) {} constexpr SMILTime() : time_(0) {}
constexpr SMILTime(double time) : time_(time) {}
static constexpr SMILTime Unresolved() { static constexpr SMILTime Unresolved() {
return std::numeric_limits<double>::quiet_NaN(); return std::numeric_limits<double>::quiet_NaN();
...@@ -55,6 +54,13 @@ class SMILTime { ...@@ -55,6 +54,13 @@ class SMILTime {
static constexpr SMILTime Earliest() { static constexpr SMILTime Earliest() {
return -std::numeric_limits<double>::infinity(); return -std::numeric_limits<double>::infinity();
} }
static constexpr SMILTime FromSecondsD(double seconds) {
return SMILTime(seconds);
}
static constexpr SMILTime FromMicroseconds(int64_t us) {
return SMILTime(static_cast<double>(us) /
base::Time::kMicrosecondsPerSecond);
}
// Used for computing progress. Don't use for anything else. // Used for computing progress. Don't use for anything else.
double InternalValueAsDouble() const { return time_; } double InternalValueAsDouble() const { return time_; }
...@@ -107,6 +113,8 @@ class SMILTime { ...@@ -107,6 +113,8 @@ class SMILTime {
friend bool operator!=(const SMILInterval& a, const SMILInterval& b); friend bool operator!=(const SMILInterval& a, const SMILInterval& b);
friend struct SMILTimeHash; friend struct SMILTimeHash;
constexpr SMILTime(double time) : time_(time) {}
double time_; double time_;
}; };
......
...@@ -44,9 +44,7 @@ static constexpr base::TimeDelta kAnimationPolicyOnceDuration = ...@@ -44,9 +44,7 @@ static constexpr base::TimeDelta kAnimationPolicyOnceDuration =
base::TimeDelta::FromSeconds(3); base::TimeDelta::FromSeconds(3);
SMILTimeContainer::SMILTimeContainer(SVGSVGElement& owner) SMILTimeContainer::SMILTimeContainer(SVGSVGElement& owner)
: presentation_time_(0), : frame_scheduling_state_(kIdle),
latest_update_time_(0),
frame_scheduling_state_(kIdle),
started_(false), started_(false),
paused_(false), paused_(false),
document_order_indexes_dirty_(false), document_order_indexes_dirty_(false),
...@@ -150,7 +148,7 @@ void SMILTimeContainer::NotifyIntervalsChanged() { ...@@ -150,7 +148,7 @@ void SMILTimeContainer::NotifyIntervalsChanged() {
SMILTime SMILTimeContainer::Elapsed() const { SMILTime SMILTimeContainer::Elapsed() const {
if (!IsStarted()) if (!IsStarted())
return 0; return SMILTime();
if (IsPaused()) if (IsPaused())
return presentation_time_; return presentation_time_;
...@@ -160,8 +158,9 @@ SMILTime SMILTimeContainer::Elapsed() const { ...@@ -160,8 +158,9 @@ SMILTime SMILTimeContainer::Elapsed() const {
base::TimeDelta()) - base::TimeDelta()) -
reference_time_; reference_time_;
DCHECK_GE(time_offset, base::TimeDelta()); DCHECK_GE(time_offset, base::TimeDelta());
SMILTime elapsed = presentation_time_ + time_offset.InSecondsF(); SMILTime elapsed = presentation_time_ +
DCHECK_GE(elapsed, 0.0); SMILTime::FromMicroseconds(time_offset.InMicroseconds());
DCHECK_GE(elapsed, SMILTime());
return elapsed; return elapsed;
} }
...@@ -271,7 +270,7 @@ void SMILTimeContainer::SetElapsed(SMILTime elapsed) { ...@@ -271,7 +270,7 @@ void SMILTimeContainer::SetElapsed(SMILTime elapsed) {
prevent_scheduled_animations_changes_ = false; prevent_scheduled_animations_changes_ = false;
#endif #endif
intervals_dirty_ = true; intervals_dirty_ = true;
latest_update_time_ = 0; latest_update_time_ = SMILTime();
UpdateAnimationsAndScheduleFrameIfNeeded(elapsed); UpdateAnimationsAndScheduleFrameIfNeeded(elapsed);
} }
...@@ -437,7 +436,7 @@ void SMILTimeContainer::UpdateAnimationsAndScheduleFrameIfNeeded( ...@@ -437,7 +436,7 @@ void SMILTimeContainer::UpdateAnimationsAndScheduleFrameIfNeeded(
// A helper function to fetch the next interesting time after document_time // A helper function to fetch the next interesting time after document_time
SMILTime SMILTimeContainer::NextInterestingTime( SMILTime SMILTimeContainer::NextInterestingTime(
SMILTime presentation_time) const { SMILTime presentation_time) const {
DCHECK_GE(presentation_time, 0); DCHECK_GE(presentation_time, SMILTime());
SMILTime next_interesting_time = SMILTime::Indefinite(); SMILTime next_interesting_time = SMILTime::Indefinite();
for (const auto& sandwich : scheduled_animations_) { for (const auto& sandwich : scheduled_animations_) {
next_interesting_time = next_interesting_time =
...@@ -461,7 +460,7 @@ void SMILTimeContainer::RemoveUnusedKeys() { ...@@ -461,7 +460,7 @@ void SMILTimeContainer::RemoveUnusedKeys() {
void SMILTimeContainer::UpdateIntervals(SMILTime document_time) { void SMILTimeContainer::UpdateIntervals(SMILTime document_time) {
DCHECK(document_time.IsFinite()); DCHECK(document_time.IsFinite());
DCHECK(document_time >= 0.0); DCHECK_GE(document_time, SMILTime());
do { do {
intervals_dirty_ = false; intervals_dirty_ = false;
...@@ -549,7 +548,7 @@ void SMILTimeContainer::ApplyAnimationValues(SMILTime elapsed) { ...@@ -549,7 +548,7 @@ void SMILTimeContainer::ApplyAnimationValues(SMILTime elapsed) {
} }
void SMILTimeContainer::AdvanceFrameForTesting() { void SMILTimeContainer::AdvanceFrameForTesting() {
const SMILTime kFrameDuration = 0.025; const SMILTime kFrameDuration = SMILTime::FromSecondsD(0.025);
SetElapsed(Elapsed() + kFrameDuration); SetElapsed(Elapsed() + kFrameDuration);
} }
......
...@@ -359,9 +359,12 @@ SMILTime SVGSMILElement::ParseOffsetValue(const String& data) { ...@@ -359,9 +359,12 @@ SMILTime SVGSMILElement::ParseOffsetValue(const String& data) {
result = parse.Left(parse.length() - 1).ToDouble(&ok); result = parse.Left(parse.length() - 1).ToDouble(&ok);
else else
result = parse.ToDouble(&ok); result = parse.ToDouble(&ok);
if (!ok || !SMILTime(result).IsFinite()) if (!ok)
return SMILTime::Unresolved(); return SMILTime::Unresolved();
return result; SMILTime offset_value = SMILTime::FromSecondsD(result);
if (!offset_value.IsFinite())
return SMILTime::Unresolved();
return offset_value;
} }
SMILTime SVGSMILElement::ParseClockValue(const String& data) { SMILTime SVGSMILElement::ParseClockValue(const String& data) {
...@@ -392,12 +395,16 @@ SMILTime SVGSMILElement::ParseClockValue(const String& data) { ...@@ -392,12 +395,16 @@ SMILTime SVGSMILElement::ParseClockValue(const String& data) {
if (!ok) if (!ok)
return SMILTime::Unresolved(); return SMILTime::Unresolved();
result += parse.Substring(3).ToDouble(&ok); result += parse.Substring(3).ToDouble(&ok);
} else } else {
return ParseOffsetValue(parse); return ParseOffsetValue(parse);
}
if (!ok || !SMILTime(result).IsFinite()) if (!ok)
return SMILTime::Unresolved(); return SMILTime::Unresolved();
return result; SMILTime clock_value = SMILTime::FromSecondsD(result);
if (!clock_value.IsFinite())
return SMILTime::Unresolved();
return clock_value;
} }
bool SVGSMILElement::ParseCondition(const String& value, bool SVGSMILElement::ParseCondition(const String& value,
...@@ -629,7 +636,7 @@ void SVGSMILElement::SetTargetElement(SVGElement* target) { ...@@ -629,7 +636,7 @@ void SVGSMILElement::SetTargetElement(SVGElement* target) {
} }
SMILTime SVGSMILElement::Elapsed() const { SMILTime SVGSMILElement::Elapsed() const {
return time_container_ ? time_container_->Elapsed() : 0; return time_container_ ? time_container_->Elapsed() : SMILTime();
} }
SMILTime SVGSMILElement::BeginTimeForPrioritization( SMILTime SVGSMILElement::BeginTimeForPrioritization(
...@@ -646,7 +653,8 @@ SMILTime SVGSMILElement::Dur() const { ...@@ -646,7 +653,8 @@ SMILTime SVGSMILElement::Dur() const {
return cached_dur_; return cached_dur_;
const AtomicString& value = FastGetAttribute(svg_names::kDurAttr); const AtomicString& value = FastGetAttribute(svg_names::kDurAttr);
SMILTime clock_value = ParseClockValue(value); SMILTime clock_value = ParseClockValue(value);
return cached_dur_ = clock_value <= 0 ? SMILTime::Unresolved() : clock_value; return cached_dur_ =
clock_value <= SMILTime() ? SMILTime::Unresolved() : clock_value;
} }
SMILTime SVGSMILElement::RepeatDur() const { SMILTime SVGSMILElement::RepeatDur() const {
...@@ -654,7 +662,8 @@ SMILTime SVGSMILElement::RepeatDur() const { ...@@ -654,7 +662,8 @@ SMILTime SVGSMILElement::RepeatDur() const {
return cached_repeat_dur_; return cached_repeat_dur_;
const AtomicString& value = FastGetAttribute(svg_names::kRepeatDurAttr); const AtomicString& value = FastGetAttribute(svg_names::kRepeatDurAttr);
SMILTime clock_value = ParseClockValue(value); SMILTime clock_value = ParseClockValue(value);
cached_repeat_dur_ = clock_value <= 0 ? SMILTime::Unresolved() : clock_value; cached_repeat_dur_ =
clock_value <= SMILTime() ? SMILTime::Unresolved() : clock_value;
return cached_repeat_dur_; return cached_repeat_dur_;
} }
...@@ -684,7 +693,7 @@ SMILTime SVGSMILElement::MaxValue() const { ...@@ -684,7 +693,7 @@ SMILTime SVGSMILElement::MaxValue() const {
return cached_max_; return cached_max_;
const AtomicString& value = FastGetAttribute(svg_names::kMaxAttr); const AtomicString& value = FastGetAttribute(svg_names::kMaxAttr);
SMILTime result = ParseClockValue(value); SMILTime result = ParseClockValue(value);
return cached_max_ = (result.IsUnresolved() || result <= 0) return cached_max_ = (result.IsUnresolved() || result <= SMILTime())
? SMILTime::Indefinite() ? SMILTime::Indefinite()
: result; : result;
} }
...@@ -694,7 +703,9 @@ SMILTime SVGSMILElement::MinValue() const { ...@@ -694,7 +703,9 @@ SMILTime SVGSMILElement::MinValue() const {
return cached_min_; return cached_min_;
const AtomicString& value = FastGetAttribute(svg_names::kMinAttr); const AtomicString& value = FastGetAttribute(svg_names::kMinAttr);
SMILTime result = ParseClockValue(value); SMILTime result = ParseClockValue(value);
return cached_min_ = (result.IsUnresolved() || result < 0) ? 0 : result; return cached_min_ = (result.IsUnresolved() || result < SMILTime())
? SMILTime()
: result;
} }
SMILTime SVGSMILElement::SimpleDuration() const { SMILTime SVGSMILElement::SimpleDuration() const {
...@@ -720,7 +731,7 @@ void SVGSMILElement::AddInstanceTime(BeginOrEnd begin_or_end, ...@@ -720,7 +731,7 @@ void SVGSMILElement::AddInstanceTime(BeginOrEnd begin_or_end,
SMILTime time, SMILTime time,
SMILTimeWithOrigin::Origin origin) { SMILTimeWithOrigin::Origin origin) {
SMILTime current_presentation_time = SMILTime current_presentation_time =
time_container_ ? time_container_->CurrentDocumentTime() : 0; time_container_ ? time_container_->CurrentDocumentTime() : SMILTime();
DCHECK(!current_presentation_time.IsUnresolved()); DCHECK(!current_presentation_time.IsUnresolved());
SMILTimeWithOrigin time_with_origin(time, origin); SMILTimeWithOrigin time_with_origin(time, origin);
// Ignore new instance times for 'end' if the element is not active // Ignore new instance times for 'end' if the element is not active
...@@ -802,7 +813,7 @@ SMILTime SVGSMILElement::ResolveActiveEnd(SMILTime resolved_begin, ...@@ -802,7 +813,7 @@ SMILTime SVGSMILElement::ResolveActiveEnd(SMILTime resolved_begin,
if (min_value > max_value) { if (min_value > max_value) {
// Ignore both. // Ignore both.
// http://www.w3.org/TR/2001/REC-smil-animation-20010904/#MinMax // http://www.w3.org/TR/2001/REC-smil-animation-20010904/#MinMax
min_value = 0; min_value = SMILTime();
max_value = SMILTime::Indefinite(); max_value = SMILTime::Indefinite();
} }
return resolved_begin + return resolved_begin +
...@@ -836,7 +847,7 @@ SMILInterval SVGSMILElement::ResolveInterval( ...@@ -836,7 +847,7 @@ SMILInterval SVGSMILElement::ResolveInterval(
} }
temp_end = ResolveActiveEnd(temp_begin, temp_end); temp_end = ResolveActiveEnd(temp_begin, temp_end);
} }
if (!first || (temp_end > 0 || (!temp_begin && !temp_end))) if (!first || (temp_end > SMILTime() || (!temp_begin && !temp_end)))
return SMILInterval(temp_begin, temp_end); return SMILInterval(temp_begin, temp_end);
begin_after = temp_end; begin_after = temp_end;
...@@ -871,7 +882,7 @@ base::Optional<SMILInterval> SVGSMILElement::ResolveNextInterval() { ...@@ -871,7 +882,7 @@ base::Optional<SMILInterval> SVGSMILElement::ResolveNextInterval() {
} }
SMILTime SVGSMILElement::NextInterestingTime(SMILTime presentation_time) const { SMILTime SVGSMILElement::NextInterestingTime(SMILTime presentation_time) const {
DCHECK_GE(presentation_time, 0); DCHECK_GE(presentation_time, SMILTime());
SMILTime next_interesting_interval_time = SMILTime::Indefinite(); SMILTime next_interesting_interval_time = SMILTime::Indefinite();
if (interval_.BeginsAfter(presentation_time)) { if (interval_.BeginsAfter(presentation_time)) {
next_interesting_interval_time = interval_.begin; next_interesting_interval_time = interval_.begin;
...@@ -902,7 +913,7 @@ SMILTime SVGSMILElement::NextInterestingTime(SMILTime presentation_time) const { ...@@ -902,7 +913,7 @@ SMILTime SVGSMILElement::NextInterestingTime(SMILTime presentation_time) const {
// These break because the updates land ON THE SAME TIMES as the // These break because the updates land ON THE SAME TIMES as the
// instance times. And the animation cannot then get a new interval // instance times. And the animation cannot then get a new interval
// from that instance time. // from that instance time.
const float half_ms = 0.0005; const SMILTime half_ms = SMILTime::FromSecondsD(0.0005);
const SMILTime instance_time = const SMILTime instance_time =
FindInstanceTime(kBegin, presentation_time, false) - half_ms; FindInstanceTime(kBegin, presentation_time, false) - half_ms;
if (presentation_time < instance_time) if (presentation_time < instance_time)
...@@ -1208,8 +1219,9 @@ void SVGSMILElement::CreateInstanceTimesFromSyncBase( ...@@ -1208,8 +1219,9 @@ void SVGSMILElement::CreateInstanceTimesFromSyncBase(
// If the STAPIT algorithm works, the current document // If the STAPIT algorithm works, the current document
// time will be accurate. So this event should be sent // time will be accurate. So this event should be sent
// correctly. // correctly.
SMILTime base_time = SMILTime base_time = time_container_
time_container_ ? time_container_->CurrentDocumentTime() : 0; ? time_container_->CurrentDocumentTime()
: SMILTime();
time = base_time + condition->Offset(); time = base_time + condition->Offset();
} }
} }
......
...@@ -144,8 +144,8 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { ...@@ -144,8 +144,8 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
enum BeginOrEnd { kBegin, kEnd }; enum BeginOrEnd { kBegin, kEnd };
void IntervalIsDirty() { void IntervalIsDirty() {
interval_.begin = 0.0; interval_.begin = SMILTime();
interval_.end = 0.0; interval_.end = SMILTime();
} }
void AddInstanceTime( void AddInstanceTime(
......
...@@ -261,13 +261,14 @@ float SVGAnimationElement::getSimpleDuration( ...@@ -261,13 +261,14 @@ float SVGAnimationElement::getSimpleDuration(
void SVGAnimationElement::beginElementAt(float offset) { void SVGAnimationElement::beginElementAt(float offset) {
DCHECK(std::isfinite(offset)); DCHECK(std::isfinite(offset));
AddInstanceTime(kBegin, Elapsed() + offset, AddInstanceTime(kBegin, Elapsed() + SMILTime::FromSecondsD(offset),
SMILTimeWithOrigin::kScriptOrigin); SMILTimeWithOrigin::kScriptOrigin);
} }
void SVGAnimationElement::endElementAt(float offset) { void SVGAnimationElement::endElementAt(float offset) {
DCHECK(std::isfinite(offset)); DCHECK(std::isfinite(offset));
AddInstanceTime(kEnd, Elapsed() + offset, SMILTimeWithOrigin::kScriptOrigin); AddInstanceTime(kEnd, Elapsed() + SMILTime::FromSecondsD(offset),
SMILTimeWithOrigin::kScriptOrigin);
} }
void SVGAnimationElement::UpdateAnimationMode() { void SVGAnimationElement::UpdateAnimationMode() {
...@@ -400,7 +401,7 @@ float SVGAnimationElement::CalculatePercentForSpline( ...@@ -400,7 +401,7 @@ float SVGAnimationElement::CalculatePercentForSpline(
gfx::CubicBezier bezier = key_splines_[spline_index]; gfx::CubicBezier bezier = key_splines_[spline_index];
SMILTime duration = SimpleDuration(); SMILTime duration = SimpleDuration();
if (!duration.IsFinite()) if (!duration.IsFinite())
duration = 100.0; duration = SMILTime::FromSecondsD(100.0);
return clampTo<float>( return clampTo<float>(
bezier.SolveWithEpsilon(percent, SolveEpsilon(duration.InSecondsF()))); bezier.SolveWithEpsilon(percent, SolveEpsilon(duration.InSecondsF())));
} }
......
...@@ -564,8 +564,7 @@ float SVGSVGElement::getCurrentTime() const { ...@@ -564,8 +564,7 @@ float SVGSVGElement::getCurrentTime() const {
void SVGSVGElement::setCurrentTime(float seconds) { void SVGSVGElement::setCurrentTime(float seconds) {
DCHECK(std::isfinite(seconds)); DCHECK(std::isfinite(seconds));
seconds = max(seconds, 0.0f); time_container_->SetElapsed(SMILTime::FromSecondsD(std::max(seconds, 0.0f)));
time_container_->SetElapsed(seconds);
} }
bool SVGSVGElement::SelfHasRelativeLengths() const { bool SVGSVGElement::SelfHasRelativeLengths() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment