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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/debug/trace_event_argument.h" | 9 #include "base/debug/trace_event_argument.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 void BeginFrameObserverMixIn::AsValueInto( | 54 void BeginFrameObserverMixIn::AsValueInto( |
| 55 base::debug::TracedValue* dict) const { | 55 base::debug::TracedValue* dict) const { |
| 56 dict->BeginDictionary("last_begin_frame_args_"); | 56 dict->BeginDictionary("last_begin_frame_args_"); |
| 57 last_begin_frame_args_.AsValueInto(dict); | 57 last_begin_frame_args_.AsValueInto(dict); |
| 58 dict->EndDictionary(); | 58 dict->EndDictionary(); |
| 59 dict->SetInteger("dropped_begin_frame_args_", dropped_begin_frame_args_); | 59 dict->SetInteger("dropped_begin_frame_args_", dropped_begin_frame_args_); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // BeginFrameSourceMixIn ------------------------------------------------------ | 62 // BeginFrameSourceMixIn ------------------------------------------------------ |
| 63 BeginFrameSourceMixIn::BeginFrameSourceMixIn() | 63 BeginFrameSourceMixIn::BeginFrameSourceMixIn() |
| 64 : observer_(NULL), | 64 : observer_(nullptr), |
| 65 needs_begin_frames_(false), | 65 needs_begin_frames_(false), |
| 66 inside_as_value_into_(false) { | 66 inside_as_value_into_(false) { |
| 67 DCHECK(!observer_); | 67 DCHECK(!observer_); |
| 68 DCHECK_EQ(inside_as_value_into_, false); | 68 DCHECK_EQ(inside_as_value_into_, false); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool BeginFrameSourceMixIn::NeedsBeginFrames() const { | 71 bool BeginFrameSourceMixIn::NeedsBeginFrames() const { |
| 72 return needs_begin_frames_; | 72 return needs_begin_frames_; |
| 73 } | 73 } |
| 74 | 74 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 94 observer_ = obs; | 94 observer_ = obs; |
| 95 } | 95 } |
| 96 | 96 |
| 97 void BeginFrameSourceMixIn::RemoveObserver(BeginFrameObserver* obs) { | 97 void BeginFrameSourceMixIn::RemoveObserver(BeginFrameObserver* obs) { |
| 98 DEBUG_FRAMES("BeginFrameSourceMixIn::RemoveObserver", | 98 DEBUG_FRAMES("BeginFrameSourceMixIn::RemoveObserver", |
| 99 "current observer", | 99 "current observer", |
| 100 observer_, | 100 observer_, |
| 101 "to remove observer", | 101 "to remove observer", |
| 102 obs); | 102 obs); |
| 103 DCHECK_EQ(observer_, obs); | 103 DCHECK_EQ(observer_, obs); |
| 104 observer_ = NULL; | 104 observer_ = nullptr; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void BeginFrameSourceMixIn::CallOnBeginFrame(const BeginFrameArgs& args) { | 107 void BeginFrameSourceMixIn::CallOnBeginFrame(const BeginFrameArgs& args) { |
| 108 DEBUG_FRAMES("BeginFrameSourceMixIn::CallOnBeginFrame", | 108 DEBUG_FRAMES("BeginFrameSourceMixIn::CallOnBeginFrame", |
| 109 "current observer", | 109 "current observer", |
| 110 observer_, | 110 observer_, |
| 111 "args", | 111 "args", |
| 112 args.AsValue()); | 112 args.AsValue()); |
| 113 if (observer_) { | 113 if (observer_) { |
| 114 return observer_->OnBeginFrame(args); | 114 return observer_->OnBeginFrame(args); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Tracing support | 118 // Tracing support |
| 119 void BeginFrameSourceMixIn::AsValueInto(base::debug::TracedValue* dict) const { | 119 void BeginFrameSourceMixIn::AsValueInto(base::debug::TracedValue* dict) const { |
| 120 // As the observer might try to trace the source, prevent an infinte loop | 120 // As the observer might try to trace the source, prevent an infinte loop |
| 121 // from occuring. | 121 // from occuring. |
| 122 if (inside_as_value_into_) { | 122 if (inside_as_value_into_) { |
| 123 dict->SetString("observer", "<loop detected>"); | 123 dict->SetString("observer", "<loop detected>"); |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 | 126 |
| 127 if (observer_) { | 127 if (observer_) { |
| 128 base::AutoReset<bool> prevent_loops( | 128 base::AutoReset<bool> prevent_loops( |
| 129 const_cast<bool*>(&inside_as_value_into_), true); | 129 const_cast<bool*>(&inside_as_value_into_), true); |
| 130 dict->BeginDictionary("observer"); | 130 dict->BeginDictionary("observer"); |
| 131 observer_->AsValueInto(dict); | 131 observer_->AsValueInto(dict); |
| 132 dict->EndDictionary(); | 132 dict->EndDictionary(); |
| 133 } else { | 133 } else { |
| 134 dict->SetString("observer", "NULL"); | 134 dict->SetString("observer", "nullptr"); |
|
viettrungluu
2014/10/10 17:16:20
WAT
danakj
2014/10/10 17:18:52
This will change the output of tracing to show nul
| |
| 135 } | 135 } |
| 136 dict->SetBoolean("needs_begin_frames", NeedsBeginFrames()); | 136 dict->SetBoolean("needs_begin_frames", NeedsBeginFrames()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // BackToBackBeginFrameSourceMixIn -------------------------------------------- | 139 // BackToBackBeginFrameSourceMixIn -------------------------------------------- |
| 140 scoped_ptr<BackToBackBeginFrameSource> BackToBackBeginFrameSource::Create( | 140 scoped_ptr<BackToBackBeginFrameSource> BackToBackBeginFrameSource::Create( |
| 141 base::SingleThreadTaskRunner* task_runner) { | 141 base::SingleThreadTaskRunner* task_runner) { |
| 142 return make_scoped_ptr(new BackToBackBeginFrameSource(task_runner)); | 142 return make_scoped_ptr(new BackToBackBeginFrameSource(task_runner)); |
| 143 } | 143 } |
| 144 | 144 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 } | 280 } |
| 281 | 281 |
| 282 // BeginFrameSourceMultiplexer ------------------------------------------- | 282 // BeginFrameSourceMultiplexer ------------------------------------------- |
| 283 scoped_ptr<BeginFrameSourceMultiplexer> BeginFrameSourceMultiplexer::Create() { | 283 scoped_ptr<BeginFrameSourceMultiplexer> BeginFrameSourceMultiplexer::Create() { |
| 284 return make_scoped_ptr(new BeginFrameSourceMultiplexer()); | 284 return make_scoped_ptr(new BeginFrameSourceMultiplexer()); |
| 285 } | 285 } |
| 286 | 286 |
| 287 BeginFrameSourceMultiplexer::BeginFrameSourceMultiplexer() | 287 BeginFrameSourceMultiplexer::BeginFrameSourceMultiplexer() |
| 288 : BeginFrameSourceMixIn(), | 288 : BeginFrameSourceMixIn(), |
| 289 minimum_interval_(base::TimeDelta()), | 289 minimum_interval_(base::TimeDelta()), |
| 290 active_source_(NULL), | 290 active_source_(nullptr), |
| 291 source_list_() { | 291 source_list_() { |
| 292 } | 292 } |
| 293 | 293 |
| 294 BeginFrameSourceMultiplexer::BeginFrameSourceMultiplexer( | 294 BeginFrameSourceMultiplexer::BeginFrameSourceMultiplexer( |
| 295 base::TimeDelta minimum_interval) | 295 base::TimeDelta minimum_interval) |
| 296 : BeginFrameSourceMixIn(), | 296 : BeginFrameSourceMixIn(), |
| 297 minimum_interval_(minimum_interval), | 297 minimum_interval_(minimum_interval), |
| 298 active_source_(NULL), | 298 active_source_(nullptr), |
| 299 source_list_() { | 299 source_list_() { |
| 300 } | 300 } |
| 301 | 301 |
| 302 BeginFrameSourceMultiplexer::~BeginFrameSourceMultiplexer() { | 302 BeginFrameSourceMultiplexer::~BeginFrameSourceMultiplexer() { |
| 303 } | 303 } |
| 304 | 304 |
| 305 void BeginFrameSourceMultiplexer::SetMinimumInterval( | 305 void BeginFrameSourceMultiplexer::SetMinimumInterval( |
| 306 base::TimeDelta new_minimum_interval) { | 306 base::TimeDelta new_minimum_interval) { |
| 307 DEBUG_FRAMES("BeginFrameSourceMultiplexer::SetMinimumInterval", | 307 DEBUG_FRAMES("BeginFrameSourceMultiplexer::SetMinimumInterval", |
| 308 "current minimum (us)", | 308 "current minimum (us)", |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 } | 343 } |
| 344 | 344 |
| 345 void BeginFrameSourceMultiplexer::SetActiveSource( | 345 void BeginFrameSourceMultiplexer::SetActiveSource( |
| 346 BeginFrameSource* new_source) { | 346 BeginFrameSource* new_source) { |
| 347 DEBUG_FRAMES("BeginFrameSourceMultiplexer::SetActiveSource", | 347 DEBUG_FRAMES("BeginFrameSourceMultiplexer::SetActiveSource", |
| 348 "current active", | 348 "current active", |
| 349 active_source_, | 349 active_source_, |
| 350 "to become active", | 350 "to become active", |
| 351 new_source); | 351 new_source); |
| 352 | 352 |
| 353 DCHECK(HasSource(new_source) || new_source == NULL); | 353 DCHECK(HasSource(new_source) || new_source == nullptr); |
| 354 | 354 |
| 355 bool needs_begin_frames = NeedsBeginFrames(); | 355 bool needs_begin_frames = NeedsBeginFrames(); |
| 356 if (active_source_) { | 356 if (active_source_) { |
| 357 if (needs_begin_frames) | 357 if (needs_begin_frames) |
| 358 SetNeedsBeginFrames(false); | 358 SetNeedsBeginFrames(false); |
| 359 | 359 |
| 360 // Technically we shouldn't need to remove observation, but this prevents | 360 // Technically we shouldn't need to remove observation, but this prevents |
| 361 // the case where SetNeedsBeginFrames message gets to the source after a | 361 // the case where SetNeedsBeginFrames message gets to the source after a |
| 362 // message has already been sent. | 362 // message has already been sent. |
| 363 active_source_->RemoveObserver(this); | 363 active_source_->RemoveObserver(this); |
| 364 active_source_ = NULL; | 364 active_source_ = nullptr; |
| 365 } | 365 } |
| 366 DCHECK(!active_source_); | 366 DCHECK(!active_source_); |
| 367 active_source_ = new_source; | 367 active_source_ = new_source; |
| 368 | 368 |
| 369 if (active_source_) { | 369 if (active_source_) { |
| 370 active_source_->AddObserver(this); | 370 active_source_->AddObserver(this); |
| 371 | 371 |
| 372 if (needs_begin_frames) { | 372 if (needs_begin_frames) { |
| 373 SetNeedsBeginFrames(true); | 373 SetNeedsBeginFrames(true); |
| 374 } | 374 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 dict->BeginDictionary("last_begin_frame_args"); | 448 dict->BeginDictionary("last_begin_frame_args"); |
| 449 observer_->LastUsedBeginFrameArgs().AsValueInto(dict); | 449 observer_->LastUsedBeginFrameArgs().AsValueInto(dict); |
| 450 dict->EndDictionary(); | 450 dict->EndDictionary(); |
| 451 } | 451 } |
| 452 | 452 |
| 453 if (active_source_) { | 453 if (active_source_) { |
| 454 dict->BeginDictionary("active_source"); | 454 dict->BeginDictionary("active_source"); |
| 455 active_source_->AsValueInto(dict); | 455 active_source_->AsValueInto(dict); |
| 456 dict->EndDictionary(); | 456 dict->EndDictionary(); |
| 457 } else { | 457 } else { |
| 458 dict->SetString("active_source", "NULL"); | 458 dict->SetString("active_source", "nullptr"); |
|
viettrungluu
2014/10/10 17:16:20
"
| |
| 459 } | 459 } |
| 460 | 460 |
| 461 dict->BeginArray("sources"); | 461 dict->BeginArray("sources"); |
| 462 for (std::set<BeginFrameSource*>::const_iterator it = source_list_.begin(); | 462 for (std::set<BeginFrameSource*>::const_iterator it = source_list_.begin(); |
| 463 it != source_list_.end(); | 463 it != source_list_.end(); |
| 464 ++it) { | 464 ++it) { |
| 465 dict->BeginDictionary(); | 465 dict->BeginDictionary(); |
| 466 (*it)->AsValueInto(dict); | 466 (*it)->AsValueInto(dict); |
| 467 dict->EndDictionary(); | 467 dict->EndDictionary(); |
| 468 } | 468 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 483 if (!observer_->LastUsedBeginFrameArgs().IsValid()) | 483 if (!observer_->LastUsedBeginFrameArgs().IsValid()) |
| 484 return true; | 484 return true; |
| 485 | 485 |
| 486 // Only allow new args have a *strictly bigger* frame_time value and statisfy | 486 // Only allow new args have a *strictly bigger* frame_time value and statisfy |
| 487 // minimum interval requirement. | 487 // minimum interval requirement. |
| 488 return (args.frame_time >= | 488 return (args.frame_time >= |
| 489 observer_->LastUsedBeginFrameArgs().frame_time + minimum_interval_); | 489 observer_->LastUsedBeginFrameArgs().frame_time + minimum_interval_); |
| 490 } | 490 } |
| 491 | 491 |
| 492 } // namespace cc | 492 } // namespace cc |
| OLD | NEW |