Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/scheduler/begin_frame_source.h" | 5 #include "cc/scheduler/begin_frame_source.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 } | 53 } |
| 54 | 54 |
| 55 void BeginFrameObserverMixIn::AsValueInto( | 55 void BeginFrameObserverMixIn::AsValueInto( |
| 56 base::trace_event::TracedValue* dict) const { | 56 base::trace_event::TracedValue* dict) const { |
| 57 dict->BeginDictionary("last_begin_frame_args_"); | 57 dict->BeginDictionary("last_begin_frame_args_"); |
| 58 last_begin_frame_args_.AsValueInto(dict); | 58 last_begin_frame_args_.AsValueInto(dict); |
| 59 dict->EndDictionary(); | 59 dict->EndDictionary(); |
| 60 dict->SetInteger("dropped_begin_frame_args_", dropped_begin_frame_args_); | 60 dict->SetInteger("dropped_begin_frame_args_", dropped_begin_frame_args_); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // BeginFrameSourceMixIn ------------------------------------------------------ | 63 // BeginFrameObserverMultiplexer ------------------------------------------ |
| 64 BeginFrameObserverMultiplexer::BeginFrameObserverMultiplexer() | |
| 65 : last_callback_state_(false), has_observers_callback_() { | |
| 66 } | |
| 67 | |
| 68 BeginFrameObserverMultiplexer::~BeginFrameObserverMultiplexer() { | |
|
simonhong
2015/03/25 02:03:21
How about checking empty() of observer list?
mithro-old
2015/03/25 02:34:47
Do we (and should we) require a user to remove all
| |
| 69 observer_list_.Clear(); | |
| 70 CallCallbackOnChange(); | |
| 71 } | |
| 72 | |
| 73 scoped_ptr<BeginFrameObserverMultiplexer> | |
| 74 BeginFrameObserverMultiplexer::Create() { | |
| 75 return make_scoped_ptr(new BeginFrameObserverMultiplexer()); | |
| 76 } | |
| 77 | |
| 78 void BeginFrameObserverMultiplexer::AddObserver(BeginFrameObserver* obs) { | |
|
simonhong
2015/03/25 02:03:21
As you can see in my previous landed cl (https://c
mithro-old
2015/03/25 02:34:47
I'm not sure what you are saying here? This code a
| |
| 79 DCHECK(!observer_list_.HasObserver(obs)); | |
| 80 // If have a LastBeginFrameArgs is still effective, send it to the new | |
| 81 // |obs| immediately. | |
| 82 if (last_begin_frame_args_.IsValid() && | |
| 83 obs->LastUsedBeginFrameArgs().frame_time < | |
| 84 last_begin_frame_args_.frame_time) { | |
| 85 BeginFrameArgs missed = last_begin_frame_args_; | |
| 86 missed.type = BeginFrameArgs::MISSED; | |
| 87 obs->OnBeginFrame(missed); | |
| 88 } | |
| 89 observer_list_.AddObserver(obs); | |
| 90 CallCallbackOnChange(); | |
| 91 } | |
| 92 | |
| 93 void BeginFrameObserverMultiplexer::RemoveObserver(BeginFrameObserver* obs) { | |
| 94 DCHECK(observer_list_.HasObserver(obs)); | |
| 95 observer_list_.RemoveObserver(obs); | |
| 96 CallCallbackOnChange(); | |
| 97 } | |
| 98 | |
| 99 bool BeginFrameObserverMultiplexer::HasObservers() { | |
| 100 return observer_list_.might_have_observers(); | |
|
simonhong
2015/03/25 02:03:21
Also in my previous cl, there is some suggestion.
mithro-old
2015/03/25 02:34:47
Looking at the ObserverList implementation, the re
| |
| 101 } | |
| 102 | |
| 103 void BeginFrameObserverMultiplexer::SetHasObserverCallback( | |
| 104 const HasObserversCallback& cb) { | |
| 105 if (last_callback_state_ != false) | |
| 106 CallCallback(false); | |
| 107 has_observers_callback_ = cb; | |
| 108 CallCallback(HasObservers()); | |
| 109 } | |
| 110 | |
| 111 void BeginFrameObserverMultiplexer::AsValueInto( | |
| 112 base::trace_event::TracedValue* dict) const { | |
| 113 BeginFrameObserverMixIn::AsValueInto(dict); | |
| 114 if (observer_list_.might_have_observers()) { | |
| 115 ObserverList<BeginFrameObserver>::Iterator it( | |
| 116 const_cast<ObserverList<BeginFrameObserver>*>(&observer_list_)); | |
| 117 BeginFrameObserver* obs; | |
| 118 dict->BeginArray("observers"); | |
| 119 while ((obs = it.GetNext()) != NULL) { | |
| 120 dict->BeginDictionary(); | |
| 121 obs->AsValueInto(dict); | |
| 122 dict->EndDictionary(); | |
| 123 } | |
| 124 dict->EndArray(); | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 bool BeginFrameObserverMultiplexer::OnBeginFrameMixInDelegate( | |
| 129 const BeginFrameArgs& args) { | |
| 130 FOR_EACH_OBSERVER(BeginFrameObserver, observer_list_, OnBeginFrame(args)); | |
| 131 return true; | |
| 132 } | |
| 133 | |
| 134 void BeginFrameObserverMultiplexer::CallCallbackOnChange() { | |
| 135 if (HasObservers() == last_callback_state_) | |
| 136 return; | |
| 137 CallCallback(HasObservers()); | |
| 138 } | |
| 139 | |
| 140 void BeginFrameObserverMultiplexer::CallCallback(bool has_observers) { | |
| 141 if (!has_observers_callback_.is_null()) { | |
| 142 has_observers_callback_.Run(has_observers); | |
| 143 last_callback_state_ = has_observers; | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 // BeginFrameSourceMixIn -------------------------------------------------- | |
| 64 BeginFrameSourceMixIn::BeginFrameSourceMixIn() | 148 BeginFrameSourceMixIn::BeginFrameSourceMixIn() |
| 65 : observer_(NULL), | 149 : observer_(NULL), |
| 66 needs_begin_frames_(false), | 150 needs_begin_frames_(false), |
| 67 inside_as_value_into_(false) { | 151 inside_as_value_into_(false) { |
| 68 DCHECK(!observer_); | 152 DCHECK(!observer_); |
| 69 DCHECK_EQ(inside_as_value_into_, false); | 153 DCHECK_EQ(inside_as_value_into_, false); |
| 70 } | 154 } |
| 71 | 155 |
| 72 bool BeginFrameSourceMixIn::NeedsBeginFrames() const { | 156 bool BeginFrameSourceMixIn::NeedsBeginFrames() const { |
| 73 return needs_begin_frames_; | 157 return needs_begin_frames_; |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 if (!observer_->LastUsedBeginFrameArgs().IsValid()) | 555 if (!observer_->LastUsedBeginFrameArgs().IsValid()) |
| 472 return true; | 556 return true; |
| 473 | 557 |
| 474 // Only allow new args have a *strictly bigger* frame_time value and statisfy | 558 // Only allow new args have a *strictly bigger* frame_time value and statisfy |
| 475 // minimum interval requirement. | 559 // minimum interval requirement. |
| 476 return (args.frame_time >= | 560 return (args.frame_time >= |
| 477 observer_->LastUsedBeginFrameArgs().frame_time + minimum_interval_); | 561 observer_->LastUsedBeginFrameArgs().frame_time + minimum_interval_); |
| 478 } | 562 } |
| 479 | 563 |
| 480 } // namespace cc | 564 } // namespace cc |
| OLD | NEW |