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

Unify SMIL interval resolution

This removes the ResolveFirstInterval() function, in favor of just
passing the appropriate arguments to ResolveInterval().
The |is_waiting_for_first_interval_| is cleared in the
StartedActiveInterval() callback (when the first interval starts), and
SVGSMILElement::CurrentIntervalIsActive() is simplified to only check if
|next_interval_time_| has been reached. Because of this, the initial
value of that member field is changed to Earliest().

Bug: 998526
Change-Id: I56103218fd210fbcd11076f20757b06319f5a054
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1848692Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#704526}
parent d4bd5085
...@@ -70,7 +70,7 @@ void SMILAnimationSandwich::UpdateTiming(SMILTime elapsed) { ...@@ -70,7 +70,7 @@ void SMILAnimationSandwich::UpdateTiming(SMILTime elapsed) {
for (const auto& animation : sandwich_) { for (const auto& animation : sandwich_) {
DCHECK(animation->HasValidTarget()); DCHECK(animation->HasValidTarget());
if (!animation->CurrentIntervalIsActive(elapsed)) if (!animation->NeedsIntervalUpdate(elapsed))
continue; continue;
animation->UpdateInterval(elapsed); animation->UpdateInterval(elapsed);
} }
......
...@@ -188,7 +188,7 @@ SVGSMILElement::SVGSMILElement(const QualifiedName& tag_name, Document& doc) ...@@ -188,7 +188,7 @@ SVGSMILElement::SVGSMILElement(const QualifiedName& tag_name, Document& doc)
is_scheduled_(false), is_scheduled_(false),
interval_{SMILTime::Unresolved(), SMILTime::Unresolved()}, interval_{SMILTime::Unresolved(), SMILTime::Unresolved()},
previous_interval_{SMILTime::Unresolved(), SMILTime::Unresolved()}, previous_interval_{SMILTime::Unresolved(), SMILTime::Unresolved()},
next_interval_time_(SMILTime::Unresolved()), next_interval_time_(SMILTime::Earliest()),
active_state_(kInactive), active_state_(kInactive),
restart_(kRestartAlways), restart_(kRestartAlways),
fill_(kFillRemove), fill_(kFillRemove),
...@@ -257,9 +257,8 @@ void SVGSMILElement::Reset() { ...@@ -257,9 +257,8 @@ void SVGSMILElement::Reset() {
is_waiting_for_first_interval_ = true; is_waiting_for_first_interval_ = true;
interval_ = {SMILTime::Unresolved(), SMILTime::Unresolved()}; interval_ = {SMILTime::Unresolved(), SMILTime::Unresolved()};
previous_interval_ = {SMILTime::Unresolved(), SMILTime::Unresolved()}; previous_interval_ = {SMILTime::Unresolved(), SMILTime::Unresolved()};
next_interval_time_ = SMILTime::Unresolved(); next_interval_time_ = SMILTime::Earliest();
last_progress_ = {0.0f, 0}; last_progress_ = {0.0f, 0};
ResolveFirstInterval(SMILTime());
} }
Node::InsertionNotificationRequest SVGSMILElement::InsertedInto( Node::InsertionNotificationRequest SVGSMILElement::InsertedInto(
...@@ -819,15 +818,6 @@ SMILInterval SVGSMILElement::ResolveInterval(SMILTime begin_after, ...@@ -819,15 +818,6 @@ SMILInterval SVGSMILElement::ResolveInterval(SMILTime begin_after,
return SMILInterval(SMILTime::Unresolved(), SMILTime::Unresolved()); return SMILInterval(SMILTime::Unresolved(), SMILTime::Unresolved());
} }
bool SVGSMILElement::ResolveFirstInterval(SMILTime presentation_time) {
SMILInterval first_interval =
ResolveInterval(SMILTime::Earliest(), presentation_time);
if (!first_interval.IsResolved() || first_interval == interval_)
return false;
SetNewInterval(first_interval, presentation_time);
return true;
}
void SVGSMILElement::SetNewInterval(const SMILInterval& interval, void SVGSMILElement::SetNewInterval(const SMILInterval& interval,
SMILTime presentation_time) { SMILTime presentation_time) {
interval_ = interval; interval_ = interval;
...@@ -873,14 +863,8 @@ void SVGSMILElement::InstanceListChanged() { ...@@ -873,14 +863,8 @@ void SVGSMILElement::InstanceListChanged() {
SMILTime current_presentation_time = SMILTime current_presentation_time =
time_container_ ? time_container_->CurrentDocumentTime() : SMILTime(); time_container_ ? time_container_->CurrentDocumentTime() : SMILTime();
DCHECK(!current_presentation_time.IsUnresolved()); DCHECK(!current_presentation_time.IsUnresolved());
if (is_waiting_for_first_interval_) {
instance_lists_have_changed_ = false;
ResolveFirstInterval(current_presentation_time);
return;
}
SMILInterval old_interval = interval_;
UpdateInterval(current_presentation_time); UpdateInterval(current_presentation_time);
if (interval_ != old_interval) { if (interval_has_changed_) {
if (GetActiveState() == kActive && if (GetActiveState() == kActive &&
interval_.BeginsAfter(current_presentation_time)) { interval_.BeginsAfter(current_presentation_time)) {
active_state_ = DetermineActiveState(current_presentation_time); active_state_ = DetermineActiveState(current_presentation_time);
...@@ -914,7 +898,7 @@ void SVGSMILElement::DiscardOrRevalidateCurrentInterval( ...@@ -914,7 +898,7 @@ void SVGSMILElement::DiscardOrRevalidateCurrentInterval(
bool SVGSMILElement::HandleIntervalRestart(SMILTime presentation_time) { bool SVGSMILElement::HandleIntervalRestart(SMILTime presentation_time) {
Restart restart = GetRestart(); Restart restart = GetRestart();
if (restart == kRestartNever) if (!is_waiting_for_first_interval_ && restart == kRestartNever)
return false; return false;
if (!interval_.IsResolved() || interval_.EndsBefore(presentation_time)) if (!interval_.IsResolved() || interval_.EndsBefore(presentation_time))
return true; return true;
...@@ -929,7 +913,6 @@ bool SVGSMILElement::HandleIntervalRestart(SMILTime presentation_time) { ...@@ -929,7 +913,6 @@ bool SVGSMILElement::HandleIntervalRestart(SMILTime presentation_time) {
} }
void SVGSMILElement::UpdateInterval(SMILTime presentation_time) { void SVGSMILElement::UpdateInterval(SMILTime presentation_time) {
DCHECK(!is_waiting_for_first_interval_);
if (instance_lists_have_changed_) { if (instance_lists_have_changed_) {
instance_lists_have_changed_ = false; instance_lists_have_changed_ = false;
DiscardOrRevalidateCurrentInterval(presentation_time); DiscardOrRevalidateCurrentInterval(presentation_time);
...@@ -937,7 +920,9 @@ void SVGSMILElement::UpdateInterval(SMILTime presentation_time) { ...@@ -937,7 +920,9 @@ void SVGSMILElement::UpdateInterval(SMILTime presentation_time) {
if (!HandleIntervalRestart(presentation_time)) if (!HandleIntervalRestart(presentation_time))
return; return;
SMILTime begin_after = SMILTime begin_after =
interval_.IsResolved() ? interval_.end : SMILTime::Earliest(); !is_waiting_for_first_interval_ && interval_.IsResolved()
? interval_.end
: SMILTime::Earliest();
SMILInterval next_interval = ResolveInterval(begin_after, presentation_time); SMILInterval next_interval = ResolveInterval(begin_after, presentation_time);
if (!next_interval.IsResolved() || next_interval == interval_) if (!next_interval.IsResolved() || next_interval == interval_)
return; return;
...@@ -950,8 +935,7 @@ void SVGSMILElement::UpdateInterval(SMILTime presentation_time) { ...@@ -950,8 +935,7 @@ void SVGSMILElement::UpdateInterval(SMILTime presentation_time) {
void SVGSMILElement::AddedToTimeContainer() { void SVGSMILElement::AddedToTimeContainer() {
DCHECK(time_container_); DCHECK(time_container_);
SMILTime current_presentation_time = time_container_->CurrentDocumentTime(); SMILTime current_presentation_time = time_container_->CurrentDocumentTime();
if (is_waiting_for_first_interval_) UpdateInterval(current_presentation_time);
ResolveFirstInterval(current_presentation_time);
if (IntervalBegin() <= current_presentation_time || if (IntervalBegin() <= current_presentation_time ||
NextProgressTime(current_presentation_time).IsFinite()) { NextProgressTime(current_presentation_time).IsFinite()) {
...@@ -1069,36 +1053,12 @@ bool SVGSMILElement::IsContributing(SMILTime elapsed) const { ...@@ -1069,36 +1053,12 @@ bool SVGSMILElement::IsContributing(SMILTime elapsed) const {
GetActiveState() == kFrozen; GetActiveState() == kFrozen;
} }
bool SVGSMILElement::CurrentIntervalIsActive(SMILTime elapsed) { bool SVGSMILElement::NeedsIntervalUpdate(SMILTime elapsed) const {
// Check we're connected to something and that our conditions have been // Check we're connected to something and that our conditions have been
// "connected". // "connected".
DCHECK(time_container_); DCHECK(time_container_);
DCHECK(conditions_connected_); DCHECK(conditions_connected_);
// If |is_waiting_for_first_interval_| is true, |interval_| can either be the return elapsed >= next_interval_time_;
// actual interval that has been resolved, or unresolved if there are no
// begin times yet.
DCHECK(is_waiting_for_first_interval_ || interval_.IsResolved());
// No interval has been resolved yet, we're waiting for an event of some
// sort.
if (!interval_.IsResolved()) {
DCHECK_EQ(GetActiveState(), kInactive);
return false;
}
// We have a current interval, but it has not started yet.
if (interval_.BeginsAfter(elapsed)) {
DCHECK_NE(GetActiveState(), kActive);
return false;
}
if (is_waiting_for_first_interval_) {
// The current internal must be the first, and has started, so clear the flag and (re)resolve.
is_waiting_for_first_interval_ = false;
if (ResolveFirstInterval(elapsed))
time_container_->MarkIntervalsDirty();
}
return true;
} }
void SVGSMILElement::UpdateActiveState(SMILTime elapsed) { void SVGSMILElement::UpdateActiveState(SMILTime elapsed) {
...@@ -1247,6 +1207,10 @@ void SVGSMILElement::BeginByLinkActivation() { ...@@ -1247,6 +1207,10 @@ void SVGSMILElement::BeginByLinkActivation() {
AddInstanceTimeAndUpdate(kBegin, Elapsed(), SMILTimeOrigin::kLinkActivation); AddInstanceTimeAndUpdate(kBegin, Elapsed(), SMILTimeOrigin::kLinkActivation);
} }
void SVGSMILElement::StartedActiveInterval() {
is_waiting_for_first_interval_ = false;
}
void SVGSMILElement::EndedActiveInterval() { void SVGSMILElement::EndedActiveInterval() {
RemoveInstanceTimesWithOrigin(begin_times_, SMILTimeOrigin::kScript); RemoveInstanceTimesWithOrigin(begin_times_, SMILTimeOrigin::kScript);
RemoveInstanceTimesWithOrigin(end_times_, SMILTimeOrigin::kScript); RemoveInstanceTimesWithOrigin(end_times_, SMILTimeOrigin::kScript);
......
...@@ -84,7 +84,7 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { ...@@ -84,7 +84,7 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
SMILTime IntervalBegin() const { return interval_.begin; } SMILTime IntervalBegin() const { return interval_.begin; }
SMILTime SimpleDuration() const; SMILTime SimpleDuration() const;
bool CurrentIntervalIsActive(SMILTime elapsed); bool NeedsIntervalUpdate(SMILTime elapsed) const;
void UpdateInterval(SMILTime presentation_time); void UpdateInterval(SMILTime presentation_time);
void UpdateActiveState(SMILTime elapsed); void UpdateActiveState(SMILTime elapsed);
void UpdateProgressState(SMILTime presentation_time); void UpdateProgressState(SMILTime presentation_time);
...@@ -141,6 +141,8 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { ...@@ -141,6 +141,8 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
virtual void WillChangeAnimationTarget(); virtual void WillChangeAnimationTarget();
virtual void DidChangeAnimationTarget(); virtual void DidChangeAnimationTarget();
virtual void StartedActiveInterval();
QualifiedName attribute_name_; QualifiedName attribute_name_;
private: private:
...@@ -148,7 +150,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { ...@@ -148,7 +150,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
void ClearResourceAndEventBaseReferences(); void ClearResourceAndEventBaseReferences();
void ClearConditions(); void ClearConditions();
virtual void StartedActiveInterval() = 0;
void EndedActiveInterval(); void EndedActiveInterval();
virtual void UpdateAnimation(float percent, virtual void UpdateAnimation(float percent,
unsigned repeat, unsigned repeat,
......
...@@ -529,6 +529,8 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation( ...@@ -529,6 +529,8 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation(
} }
void SVGAnimationElement::StartedActiveInterval() { void SVGAnimationElement::StartedActiveInterval() {
SVGSMILElement::StartedActiveInterval();
animation_valid_ = false; animation_valid_ = false;
if (!IsValid() || !HasValidTarget()) if (!IsValid() || !HasValidTarget())
......
...@@ -51,7 +51,6 @@ class SVGDiscardElement final : public SVGSMILElement { ...@@ -51,7 +51,6 @@ class SVGDiscardElement final : public SVGSMILElement {
bool OverwritesUnderlyingAnimationValue() const override { return false; } bool OverwritesUnderlyingAnimationValue() const override { return false; }
void StartedActiveInterval() override {}
void UpdateAnimation(float percent, void UpdateAnimation(float percent,
unsigned repeat, unsigned repeat,
SVGSMILElement* result_element) override {} SVGSMILElement* result_element) override {}
......
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