Index: cc/scheduler/begin_frame_source.cc |
diff --git a/cc/scheduler/begin_frame_source.cc b/cc/scheduler/begin_frame_source.cc |
index 42b8f6f1c735db05dfca52c00ed6070bb8b63a36..8eb0155bee7ab05307103c04c439d9a3a54e509b 100644 |
--- a/cc/scheduler/begin_frame_source.cc |
+++ b/cc/scheduler/begin_frame_source.cc |
@@ -33,7 +33,7 @@ BeginFrameObserverMixIn::BeginFrameObserverMixIn() |
: last_begin_frame_args_(), dropped_begin_frame_args_(0) { |
} |
-const BeginFrameArgs BeginFrameObserverMixIn::LastUsedBeginFrameArgs() const { |
+const BeginFrameArgs BeginFrameObserverMixIn::LastUsedBeginFrameArgs() { |
return last_begin_frame_args_; |
} |
void BeginFrameObserverMixIn::OnBeginFrame(const BeginFrameArgs& args) { |
@@ -53,7 +53,7 @@ void BeginFrameObserverMixIn::OnBeginFrame(const BeginFrameArgs& args) { |
} |
void BeginFrameObserverMixIn::AsValueInto( |
- base::trace_event::TracedValue* dict) const { |
+ base::trace_event::TracedValue* dict) { |
dict->BeginDictionary("last_begin_frame_args_"); |
last_begin_frame_args_.AsValueInto(dict); |
dict->EndDictionary(); |
@@ -62,13 +62,15 @@ void BeginFrameObserverMixIn::AsValueInto( |
// BeginFrameSourceMixIn ------------------------------------------------------ |
BeginFrameSourceMixIn::BeginFrameSourceMixIn() |
- : observer_(NULL), |
+ : observer_list_(), |
needs_begin_frames_(false), |
inside_as_value_into_(false) { |
- DCHECK(!observer_); |
DCHECK_EQ(inside_as_value_into_, false); |
} |
+BeginFrameSourceMixIn::~BeginFrameSourceMixIn() { |
+} |
+ |
bool BeginFrameSourceMixIn::NeedsBeginFrames() const { |
return needs_begin_frames_; |
} |
@@ -86,56 +88,51 @@ void BeginFrameSourceMixIn::SetNeedsBeginFrames(bool needs_begin_frames) { |
} |
void BeginFrameSourceMixIn::AddObserver(BeginFrameObserver* obs) { |
- DEBUG_FRAMES("BeginFrameSourceMixIn::AddObserver", |
- "current observer", |
- observer_, |
- "to add observer", |
- obs); |
- DCHECK(!observer_); |
- observer_ = obs; |
+ DEBUG_FRAMES("BeginFrameSourceMixIn::AddObserver", "has observers?", |
+ (observer_list_).might_have_observers(), "to add observer", obs); |
+ DCHECK(obs); |
+ DCHECK(!observer_list_.HasObserver(obs)); |
+ observer_list_.AddObserver(obs); |
} |
void BeginFrameSourceMixIn::RemoveObserver(BeginFrameObserver* obs) { |
- DEBUG_FRAMES("BeginFrameSourceMixIn::RemoveObserver", |
- "current observer", |
- observer_, |
- "to remove observer", |
+ DEBUG_FRAMES("BeginFrameSourceMixIn::RemoveObserver", "has observers?", |
+ (observer_list_).might_have_observers(), "to remove observer", |
obs); |
- DCHECK_EQ(observer_, obs); |
- observer_ = NULL; |
+ DCHECK(obs); |
+ DCHECK(observer_list_.HasObserver(obs)); |
+ observer_list_.RemoveObserver(obs); |
} |
void BeginFrameSourceMixIn::CallOnBeginFrame(const BeginFrameArgs& args) { |
- DEBUG_FRAMES("BeginFrameSourceMixIn::CallOnBeginFrame", |
- "current observer", |
- observer_, |
- "args", |
- args.AsValue()); |
- if (observer_) { |
- return observer_->OnBeginFrame(args); |
- } |
+ DEBUG_FRAMES("BeginFrameSourceMixIn::CallOnBeginFrame", "has observers?", |
+ observer_list_.might_have_observers(), "args", args.AsValue()); |
+ FOR_EACH_OBSERVER(BeginFrameObserver, observer_list_, OnBeginFrame(args)); |
} |
// Tracing support |
-void BeginFrameSourceMixIn::AsValueInto( |
- base::trace_event::TracedValue* dict) const { |
+void BeginFrameSourceMixIn::AsValueInto(base::trace_event::TracedValue* dict) { |
// As the observer might try to trace the source, prevent an infinte loop |
// from occuring. |
if (inside_as_value_into_) { |
dict->SetString("observer", "<loop detected>"); |
return; |
} |
+ base::AutoReset<bool> prevent_loops(const_cast<bool*>(&inside_as_value_into_), |
+ true); |
- if (observer_) { |
- base::AutoReset<bool> prevent_loops( |
- const_cast<bool*>(&inside_as_value_into_), true); |
- dict->BeginDictionary("observer"); |
- observer_->AsValueInto(dict); |
- dict->EndDictionary(); |
- } else { |
- dict->SetString("observer", "NULL"); |
- } |
dict->SetBoolean("needs_begin_frames", NeedsBeginFrames()); |
+ if (observer_list_.might_have_observers()) { |
+ ObserverList<BeginFrameObserver>::Iterator it(&observer_list_); |
+ BeginFrameObserver* obs; |
+ dict->BeginArray("observers"); |
+ while ((obs = it.GetNext()) != NULL) { |
+ dict->BeginDictionary(); |
+ obs->AsValueInto(dict); |
+ dict->EndDictionary(); |
+ } |
+ dict->EndArray(); |
+ } |
} |
// BackToBackBeginFrameSourceMixIn -------------------------------------------- |
@@ -199,7 +196,7 @@ void BackToBackBeginFrameSource::DidFinishFrame(size_t remaining_frames) { |
// Tracing support |
void BackToBackBeginFrameSource::AsValueInto( |
- base::trace_event::TracedValue* dict) const { |
+ base::trace_event::TracedValue* dict) { |
danakj
2015/03/25 18:12:55
What's with all the const changes? AsValueInto can
mithro-old
2015/03/26 00:54:49
The AsValueInto loops over each of the observers.
|
dict->SetString("type", "BackToBackBeginFrameSource"); |
BeginFrameSourceMixIn::AsValueInto(dict); |
dict->SetBoolean("send_begin_frame_posted_", send_begin_frame_posted_); |
@@ -267,7 +264,7 @@ void SyntheticBeginFrameSource::OnNeedsBeginFramesChange( |
// Tracing support |
void SyntheticBeginFrameSource::AsValueInto( |
- base::trace_event::TracedValue* dict) const { |
+ base::trace_event::TracedValue* dict) { |
dict->SetString("type", "SyntheticBeginFrameSource"); |
BeginFrameSourceMixIn::AsValueInto(dict); |
@@ -394,12 +391,19 @@ void BeginFrameSourceMultiplexer::OnBeginFrame(const BeginFrameArgs& args) { |
CallOnBeginFrame(args); |
} |
-const BeginFrameArgs BeginFrameSourceMultiplexer::LastUsedBeginFrameArgs() |
- const { |
- if (observer_) |
- return observer_->LastUsedBeginFrameArgs(); |
- else |
- return BeginFrameArgs(); |
+const BeginFrameArgs BeginFrameSourceMultiplexer::LastUsedBeginFrameArgs() { |
+ BeginFrameArgs last; |
+ |
+ if ((observer_list_).might_have_observers()) { |
+ ObserverList<BeginFrameObserver>::Iterator it(&observer_list_); |
+ BeginFrameObserver* obs; |
+ while ((obs = it.GetNext()) != NULL) { |
+ BeginFrameArgs obs_last = obs->LastUsedBeginFrameArgs(); |
+ if (obs_last.frame_time > last.frame_time) |
+ last = obs_last; |
+ } |
+ } |
+ return last; |
} |
// BeginFrameSource support |
@@ -428,16 +432,11 @@ void BeginFrameSourceMultiplexer::DidFinishFrame(size_t remaining_frames) { |
// Tracing support |
void BeginFrameSourceMultiplexer::AsValueInto( |
- base::trace_event::TracedValue* dict) const { |
+ base::trace_event::TracedValue* dict) { |
dict->SetString("type", "BeginFrameSourceMultiplexer"); |
+ BeginFrameSourceMixIn::AsValueInto(dict); |
dict->SetInteger("minimum_interval_us", minimum_interval_.InMicroseconds()); |
- if (observer_) { |
- dict->BeginDictionary("last_begin_frame_args"); |
- observer_->LastUsedBeginFrameArgs().AsValueInto(dict); |
- dict->EndDictionary(); |
- } |
- |
if (active_source_) { |
dict->BeginDictionary("active_source"); |
active_source_->AsValueInto(dict); |
@@ -464,17 +463,15 @@ bool BeginFrameSourceMultiplexer::HasSource(BeginFrameSource* source) { |
bool BeginFrameSourceMultiplexer::IsIncreasing(const BeginFrameArgs& args) { |
DCHECK(args.IsValid()); |
- if (!observer_) |
- return false; |
// If the last begin frame is invalid, then any new begin frame is valid. |
- if (!observer_->LastUsedBeginFrameArgs().IsValid()) |
+ if (!LastUsedBeginFrameArgs().IsValid()) |
return true; |
// Only allow new args have a *strictly bigger* frame_time value and statisfy |
// minimum interval requirement. |
return (args.frame_time >= |
- observer_->LastUsedBeginFrameArgs().frame_time + minimum_interval_); |
+ LastUsedBeginFrameArgs().frame_time + minimum_interval_); |
} |
} // namespace cc |