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