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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "base/trace_event/trace_event_argument.h" | 15 #include "base/trace_event/trace_event_argument.h" |
| 16 #include "cc/scheduler/delay_based_time_source.h" | 16 #include "cc/scheduler/delay_based_time_source.h" |
| 17 #include "cc/scheduler/scheduler.h" | 17 #include "cc/scheduler/scheduler.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 // kDoubleTickDivisor prevents the SyntheticBFS from sending BeginFrames too | 22 // kDoubleTickDivisor prevents the SyntheticBFS from sending BeginFrames too |
| 23 // often to an observer. | 23 // often to an observer. |
| 24 static const double kDoubleTickDivisor = 2.0; | 24 static const double kDoubleTickDivisor = 2.0; |
| 25 } | 25 } |
| 26 | 26 |
| 27 // BeginFrameObserverBase ----------------------------------------------- | |
| 28 BeginFrameObserverBase::BeginFrameObserverBase() | |
| 29 : last_begin_frame_args_(), dropped_begin_frame_args_(0) { | |
| 30 } | |
| 31 | |
| 32 const BeginFrameArgs& BeginFrameObserverBase::LastUsedBeginFrameArgs() const { | |
| 33 return last_begin_frame_args_; | |
| 34 } | |
| 35 void BeginFrameObserverBase::OnBeginFrame(const BeginFrameArgs& args) { | |
| 36 DEBUG_FRAMES("BeginFrameObserverBase::OnBeginFrame", | |
| 37 "last args", | |
| 38 last_begin_frame_args_.AsValue(), | |
| 39 "new args", | |
| 40 args.AsValue()); | |
| 41 DCHECK(args.IsValid()); | |
| 42 DCHECK(args.frame_time >= last_begin_frame_args_.frame_time); | |
| 43 bool used = OnBeginFrameDerivedImpl(args); | |
| 44 if (used) { | |
| 45 last_begin_frame_args_ = args; | |
| 46 } else { | |
| 47 ++dropped_begin_frame_args_; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 void BeginFrameObserverBase::AsValueInto( | |
| 52 base::trace_event::TracedValue* dict) const { | |
| 53 dict->BeginDictionary("last_begin_frame_args_"); | |
| 54 last_begin_frame_args_.AsValueInto(dict); | |
| 55 dict->EndDictionary(); | |
| 56 dict->SetInteger("dropped_begin_frame_args_", dropped_begin_frame_args_); | |
| 57 } | |
| 58 | |
| 59 // BeginFrameSourceBase ------------------------------------------------------ | 27 // BeginFrameSourceBase ------------------------------------------------------ |
| 60 BeginFrameSourceBase::BeginFrameSourceBase() | 28 BeginFrameSourceBase::BeginFrameSourceBase() |
| 61 : paused_(false), inside_as_value_into_(false) {} | 29 : paused_(false), inside_as_value_into_(false) {} |
| 62 | 30 |
| 63 BeginFrameSourceBase::~BeginFrameSourceBase() {} | 31 BeginFrameSourceBase::~BeginFrameSourceBase() {} |
| 64 | 32 |
| 65 void BeginFrameSourceBase::AddObserver(BeginFrameObserver* obs) { | 33 void BeginFrameSourceBase::AddObserver(BeginFrameObserver* obs) { |
| 66 DEBUG_FRAMES("BeginFrameSourceBase::AddObserver", "num observers", | 34 DEBUG_FRAMES("BeginFrameSourceBase::AddObserver", "num observers", |
| 67 observers_.size(), "to add observer", obs); | 35 observers_.size(), "to add observer", obs); |
| 68 DCHECK(obs); | 36 DCHECK(obs); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 DCHECK(needs_begin_frames()); | 135 DCHECK(needs_begin_frames()); |
| 168 DCHECK(!begin_frame_task_.IsCancelled()); | 136 DCHECK(!begin_frame_task_.IsCancelled()); |
| 169 begin_frame_task_.Cancel(); | 137 begin_frame_task_.Cancel(); |
| 170 base::TimeTicks now = Now(); | 138 base::TimeTicks now = Now(); |
| 171 BeginFrameArgs args = BeginFrameArgs::Create( | 139 BeginFrameArgs args = BeginFrameArgs::Create( |
| 172 BEGINFRAME_FROM_HERE, now, now + BeginFrameArgs::DefaultInterval(), | 140 BEGINFRAME_FROM_HERE, now, now + BeginFrameArgs::DefaultInterval(), |
| 173 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL); | 141 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL); |
| 174 CallOnBeginFrame(args); | 142 CallOnBeginFrame(args); |
| 175 } | 143 } |
| 176 | 144 |
| 177 void BackToBackBeginFrameSource::DidFinishFrame(size_t remaining_frames) { | 145 void BackToBackBeginFrameSource::DidFinishFrame(BeginFrameObserver* obs) { |
| 178 BeginFrameSourceBase::DidFinishFrame(remaining_frames); | 146 if (needs_begin_frames()) |
| 179 if (needs_begin_frames() && remaining_frames == 0) | |
| 180 PostBeginFrame(); | 147 PostBeginFrame(); |
|
enne (OOO)
2016/04/14 23:02:26
Hmm. Should this only post a begin frame to the o
| |
| 181 } | 148 } |
| 182 | 149 |
| 183 // Tracing support | 150 // Tracing support |
| 184 void BackToBackBeginFrameSource::AsValueInto( | 151 void BackToBackBeginFrameSource::AsValueInto( |
| 185 base::trace_event::TracedValue* dict) const { | 152 base::trace_event::TracedValue* dict) const { |
| 186 dict->SetString("type", "BackToBackBeginFrameSource"); | 153 dict->SetString("type", "BackToBackBeginFrameSource"); |
| 187 BeginFrameSourceBase::AsValueInto(dict); | 154 BeginFrameSourceBase::AsValueInto(dict); |
| 188 } | 155 } |
| 189 | 156 |
| 190 // SyntheticBeginFrameSource --------------------------------------------- | 157 // SyntheticBeginFrameSource --------------------------------------------- |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 212 | 179 |
| 213 BeginFrameArgs SyntheticBeginFrameSource::CreateBeginFrameArgs( | 180 BeginFrameArgs SyntheticBeginFrameSource::CreateBeginFrameArgs( |
| 214 base::TimeTicks frame_time, | 181 base::TimeTicks frame_time, |
| 215 BeginFrameArgs::BeginFrameArgsType type) { | 182 BeginFrameArgs::BeginFrameArgsType type) { |
| 216 return BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, | 183 return BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, |
| 217 time_source_->NextTickTime(), | 184 time_source_->NextTickTime(), |
| 218 time_source_->Interval(), type); | 185 time_source_->Interval(), type); |
| 219 } | 186 } |
| 220 | 187 |
| 221 // BeginFrameSource support | 188 // BeginFrameSource support |
| 189 void SyntheticBeginFrameSource::DidFinishFrame(BeginFrameObserver* obs) { | |
| 190 BeginFrameArgs args = CreateBeginFrameArgs( | |
| 191 time_source_->NextTickTime() - time_source_->Interval(), | |
| 192 BeginFrameArgs::MISSED); | |
| 193 BeginFrameArgs last_args = obs->LastUsedBeginFrameArgs(); | |
| 194 if (!last_args.IsValid() || | |
| 195 (args.frame_time > | |
| 196 last_args.frame_time + args.interval / kDoubleTickDivisor)) { | |
| 197 obs->OnBeginFrame(args); | |
| 198 } | |
| 199 } | |
| 200 | |
| 222 void SyntheticBeginFrameSource::AddObserver(BeginFrameObserver* obs) { | 201 void SyntheticBeginFrameSource::AddObserver(BeginFrameObserver* obs) { |
| 223 BeginFrameSourceBase::AddObserver(obs); | 202 BeginFrameSourceBase::AddObserver(obs); |
| 224 BeginFrameArgs args = CreateBeginFrameArgs( | 203 BeginFrameArgs args = CreateBeginFrameArgs( |
| 225 time_source_->NextTickTime() - time_source_->Interval(), | 204 time_source_->NextTickTime() - time_source_->Interval(), |
| 226 BeginFrameArgs::MISSED); | 205 BeginFrameArgs::MISSED); |
| 227 BeginFrameArgs last_args = obs->LastUsedBeginFrameArgs(); | 206 BeginFrameArgs last_args = obs->LastUsedBeginFrameArgs(); |
| 228 if (!last_args.IsValid() || | 207 if (!last_args.IsValid() || |
| 229 (args.frame_time > | 208 (args.frame_time > |
| 230 last_args.frame_time + args.interval / kDoubleTickDivisor)) { | 209 last_args.frame_time + args.interval / kDoubleTickDivisor)) { |
| 231 obs->OnBeginFrame(args); | 210 obs->OnBeginFrame(args); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 257 base::trace_event::TracedValue* dict) const { | 236 base::trace_event::TracedValue* dict) const { |
| 258 dict->SetString("type", "SyntheticBeginFrameSource"); | 237 dict->SetString("type", "SyntheticBeginFrameSource"); |
| 259 BeginFrameSourceBase::AsValueInto(dict); | 238 BeginFrameSourceBase::AsValueInto(dict); |
| 260 | 239 |
| 261 dict->BeginDictionary("time_source"); | 240 dict->BeginDictionary("time_source"); |
| 262 time_source_->AsValueInto(dict); | 241 time_source_->AsValueInto(dict); |
| 263 dict->EndDictionary(); | 242 dict->EndDictionary(); |
| 264 } | 243 } |
| 265 | 244 |
| 266 } // namespace cc | 245 } // namespace cc |
| OLD | NEW |