| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 DCHECK(args.frame_time >= last_begin_frame_args_.frame_time); | 46 DCHECK(args.frame_time >= last_begin_frame_args_.frame_time); |
| 47 bool used = OnBeginFrameMixInDelegate(args); | 47 bool used = OnBeginFrameMixInDelegate(args); |
| 48 if (used) { | 48 if (used) { |
| 49 last_begin_frame_args_ = args; | 49 last_begin_frame_args_ = args; |
| 50 } else { | 50 } else { |
| 51 ++dropped_begin_frame_args_; | 51 ++dropped_begin_frame_args_; |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 void BeginFrameObserverMixIn::AsValueInto( | 55 void BeginFrameObserverMixIn::AsValueInto( |
| 56 base::debug::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 // BeginFrameSourceMixIn ------------------------------------------------------ |
| 64 BeginFrameSourceMixIn::BeginFrameSourceMixIn() | 64 BeginFrameSourceMixIn::BeginFrameSourceMixIn() |
| 65 : observer_(NULL), | 65 : observer_(NULL), |
| 66 needs_begin_frames_(false), | 66 needs_begin_frames_(false), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 "current observer", | 110 "current observer", |
| 111 observer_, | 111 observer_, |
| 112 "args", | 112 "args", |
| 113 args.AsValue()); | 113 args.AsValue()); |
| 114 if (observer_) { | 114 if (observer_) { |
| 115 return observer_->OnBeginFrame(args); | 115 return observer_->OnBeginFrame(args); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Tracing support | 119 // Tracing support |
| 120 void BeginFrameSourceMixIn::AsValueInto(base::debug::TracedValue* dict) const { | 120 void BeginFrameSourceMixIn::AsValueInto( |
| 121 base::trace_event::TracedValue* dict) const { |
| 121 // As the observer might try to trace the source, prevent an infinte loop | 122 // As the observer might try to trace the source, prevent an infinte loop |
| 122 // from occuring. | 123 // from occuring. |
| 123 if (inside_as_value_into_) { | 124 if (inside_as_value_into_) { |
| 124 dict->SetString("observer", "<loop detected>"); | 125 dict->SetString("observer", "<loop detected>"); |
| 125 return; | 126 return; |
| 126 } | 127 } |
| 127 | 128 |
| 128 if (observer_) { | 129 if (observer_) { |
| 129 base::AutoReset<bool> prevent_loops( | 130 base::AutoReset<bool> prevent_loops( |
| 130 const_cast<bool*>(&inside_as_value_into_), true); | 131 const_cast<bool*>(&inside_as_value_into_), true); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // BeginFrameSource support | 192 // BeginFrameSource support |
| 192 | 193 |
| 193 void BackToBackBeginFrameSource::DidFinishFrame(size_t remaining_frames) { | 194 void BackToBackBeginFrameSource::DidFinishFrame(size_t remaining_frames) { |
| 194 if (remaining_frames == 0) { | 195 if (remaining_frames == 0) { |
| 195 OnNeedsBeginFramesChange(NeedsBeginFrames()); | 196 OnNeedsBeginFramesChange(NeedsBeginFrames()); |
| 196 } | 197 } |
| 197 } | 198 } |
| 198 | 199 |
| 199 // Tracing support | 200 // Tracing support |
| 200 void BackToBackBeginFrameSource::AsValueInto( | 201 void BackToBackBeginFrameSource::AsValueInto( |
| 201 base::debug::TracedValue* dict) const { | 202 base::trace_event::TracedValue* dict) const { |
| 202 dict->SetString("type", "BackToBackBeginFrameSource"); | 203 dict->SetString("type", "BackToBackBeginFrameSource"); |
| 203 BeginFrameSourceMixIn::AsValueInto(dict); | 204 BeginFrameSourceMixIn::AsValueInto(dict); |
| 204 dict->SetBoolean("send_begin_frame_posted_", send_begin_frame_posted_); | 205 dict->SetBoolean("send_begin_frame_posted_", send_begin_frame_posted_); |
| 205 } | 206 } |
| 206 | 207 |
| 207 // SyntheticBeginFrameSource --------------------------------------------- | 208 // SyntheticBeginFrameSource --------------------------------------------- |
| 208 scoped_ptr<SyntheticBeginFrameSource> SyntheticBeginFrameSource::Create( | 209 scoped_ptr<SyntheticBeginFrameSource> SyntheticBeginFrameSource::Create( |
| 209 base::SingleThreadTaskRunner* task_runner, | 210 base::SingleThreadTaskRunner* task_runner, |
| 210 base::TimeTicks initial_vsync_timebase, | 211 base::TimeTicks initial_vsync_timebase, |
| 211 base::TimeDelta initial_vsync_interval) { | 212 base::TimeDelta initial_vsync_interval) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 void SyntheticBeginFrameSource::OnNeedsBeginFramesChange( | 258 void SyntheticBeginFrameSource::OnNeedsBeginFramesChange( |
| 258 bool needs_begin_frames) { | 259 bool needs_begin_frames) { |
| 259 base::TimeTicks missed_tick_time = | 260 base::TimeTicks missed_tick_time = |
| 260 time_source_->SetActive(needs_begin_frames); | 261 time_source_->SetActive(needs_begin_frames); |
| 261 if (!missed_tick_time.is_null()) { | 262 if (!missed_tick_time.is_null()) { |
| 262 CallOnBeginFrame( | 263 CallOnBeginFrame( |
| 263 CreateBeginFrameArgs(missed_tick_time, BeginFrameArgs::MISSED)); | 264 CreateBeginFrameArgs(missed_tick_time, BeginFrameArgs::MISSED)); |
| 264 } | 265 } |
| 265 } | 266 } |
| 266 | 267 |
| 267 bool SyntheticBeginFrameSource::NeedsBeginFrames() const { | |
| 268 return time_source_->Active(); | |
| 269 } | |
| 270 | |
| 271 // Tracing support | 268 // Tracing support |
| 272 void SyntheticBeginFrameSource::AsValueInto( | 269 void SyntheticBeginFrameSource::AsValueInto( |
| 273 base::debug::TracedValue* dict) const { | 270 base::trace_event::TracedValue* dict) const { |
| 274 dict->SetString("type", "SyntheticBeginFrameSource"); | 271 dict->SetString("type", "SyntheticBeginFrameSource"); |
| 275 BeginFrameSourceMixIn::AsValueInto(dict); | 272 BeginFrameSourceMixIn::AsValueInto(dict); |
| 276 | 273 |
| 277 dict->BeginDictionary("time_source"); | 274 dict->BeginDictionary("time_source"); |
| 278 time_source_->AsValueInto(dict); | 275 time_source_->AsValueInto(dict); |
| 279 dict->EndDictionary(); | 276 dict->EndDictionary(); |
| 280 } | 277 } |
| 281 | 278 |
| 282 // BeginFrameSourceMultiplexer ------------------------------------------- | 279 // BeginFrameSourceMultiplexer ------------------------------------------- |
| 283 scoped_ptr<BeginFrameSourceMultiplexer> BeginFrameSourceMultiplexer::Create() { | 280 scoped_ptr<BeginFrameSourceMultiplexer> BeginFrameSourceMultiplexer::Create() { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 396 |
| 400 const BeginFrameArgs BeginFrameSourceMultiplexer::LastUsedBeginFrameArgs() | 397 const BeginFrameArgs BeginFrameSourceMultiplexer::LastUsedBeginFrameArgs() |
| 401 const { | 398 const { |
| 402 if (observer_) | 399 if (observer_) |
| 403 return observer_->LastUsedBeginFrameArgs(); | 400 return observer_->LastUsedBeginFrameArgs(); |
| 404 else | 401 else |
| 405 return BeginFrameArgs(); | 402 return BeginFrameArgs(); |
| 406 } | 403 } |
| 407 | 404 |
| 408 // BeginFrameSource support | 405 // BeginFrameSource support |
| 409 bool BeginFrameSourceMultiplexer::NeedsBeginFrames() const { | |
| 410 if (active_source_) { | |
| 411 return active_source_->NeedsBeginFrames(); | |
| 412 } else { | |
| 413 return false; | |
| 414 } | |
| 415 } | |
| 416 | |
| 417 void BeginFrameSourceMultiplexer::OnNeedsBeginFramesChange( | 406 void BeginFrameSourceMultiplexer::OnNeedsBeginFramesChange( |
| 418 bool needs_begin_frames) { | 407 bool needs_begin_frames) { |
| 419 DEBUG_FRAMES("BeginFrameSourceMultiplexer::OnNeedsBeginFramesChange", | 408 DEBUG_FRAMES("BeginFrameSourceMultiplexer::OnNeedsBeginFramesChange", |
| 420 "active_source", active_source_, "needs_begin_frames", | 409 "active_source", active_source_, "needs_begin_frames", |
| 421 needs_begin_frames); | 410 needs_begin_frames); |
| 422 if (active_source_) { | 411 if (active_source_) { |
| 423 active_source_->SetNeedsBeginFrames(needs_begin_frames); | 412 active_source_->SetNeedsBeginFrames(needs_begin_frames); |
| 424 } else { | 413 } else { |
| 425 DCHECK(!needs_begin_frames); | 414 DCHECK(!needs_begin_frames); |
| 426 } | 415 } |
| 427 } | 416 } |
| 428 | 417 |
| 429 void BeginFrameSourceMultiplexer::DidFinishFrame(size_t remaining_frames) { | 418 void BeginFrameSourceMultiplexer::DidFinishFrame(size_t remaining_frames) { |
| 430 DEBUG_FRAMES("BeginFrameSourceMultiplexer::DidFinishFrame", | 419 DEBUG_FRAMES("BeginFrameSourceMultiplexer::DidFinishFrame", |
| 431 "active_source", | 420 "active_source", |
| 432 active_source_, | 421 active_source_, |
| 433 "remaining_frames", | 422 "remaining_frames", |
| 434 remaining_frames); | 423 remaining_frames); |
| 435 if (active_source_) { | 424 if (active_source_) { |
| 436 active_source_->DidFinishFrame(remaining_frames); | 425 active_source_->DidFinishFrame(remaining_frames); |
| 437 } | 426 } |
| 438 } | 427 } |
| 439 | 428 |
| 440 // Tracing support | 429 // Tracing support |
| 441 void BeginFrameSourceMultiplexer::AsValueInto( | 430 void BeginFrameSourceMultiplexer::AsValueInto( |
| 442 base::debug::TracedValue* dict) const { | 431 base::trace_event::TracedValue* dict) const { |
| 443 dict->SetString("type", "BeginFrameSourceMultiplexer"); | 432 dict->SetString("type", "BeginFrameSourceMultiplexer"); |
| 444 | 433 |
| 445 dict->SetInteger("minimum_interval_us", minimum_interval_.InMicroseconds()); | 434 dict->SetInteger("minimum_interval_us", minimum_interval_.InMicroseconds()); |
| 446 if (observer_) { | 435 if (observer_) { |
| 447 dict->BeginDictionary("last_begin_frame_args"); | 436 dict->BeginDictionary("last_begin_frame_args"); |
| 448 observer_->LastUsedBeginFrameArgs().AsValueInto(dict); | 437 observer_->LastUsedBeginFrameArgs().AsValueInto(dict); |
| 449 dict->EndDictionary(); | 438 dict->EndDictionary(); |
| 450 } | 439 } |
| 451 | 440 |
| 452 if (active_source_) { | 441 if (active_source_) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 482 if (!observer_->LastUsedBeginFrameArgs().IsValid()) | 471 if (!observer_->LastUsedBeginFrameArgs().IsValid()) |
| 483 return true; | 472 return true; |
| 484 | 473 |
| 485 // Only allow new args have a *strictly bigger* frame_time value and statisfy | 474 // Only allow new args have a *strictly bigger* frame_time value and statisfy |
| 486 // minimum interval requirement. | 475 // minimum interval requirement. |
| 487 return (args.frame_time >= | 476 return (args.frame_time >= |
| 488 observer_->LastUsedBeginFrameArgs().frame_time + minimum_interval_); | 477 observer_->LastUsedBeginFrameArgs().frame_time + minimum_interval_); |
| 489 } | 478 } |
| 490 | 479 |
| 491 } // namespace cc | 480 } // namespace cc |
| OLD | NEW |