| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/frame_rate_controller.h" | 5 #include "cc/scheduler/frame_rate_controller.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/location.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "cc/base/thread.h" | 10 #include "base/single_thread_task_runner.h" |
| 10 #include "cc/scheduler/delay_based_time_source.h" | 11 #include "cc/scheduler/delay_based_time_source.h" |
| 11 #include "cc/scheduler/time_source.h" | 12 #include "cc/scheduler/time_source.h" |
| 12 | 13 |
| 13 namespace cc { | 14 namespace cc { |
| 14 | 15 |
| 15 class FrameRateControllerTimeSourceAdapter : public TimeSourceClient { | 16 class FrameRateControllerTimeSourceAdapter : public TimeSourceClient { |
| 16 public: | 17 public: |
| 17 static scoped_ptr<FrameRateControllerTimeSourceAdapter> Create( | 18 static scoped_ptr<FrameRateControllerTimeSourceAdapter> Create( |
| 18 FrameRateController* frame_rate_controller) { | 19 FrameRateController* frame_rate_controller) { |
| 19 return make_scoped_ptr( | 20 return make_scoped_ptr( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) | 37 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) |
| 37 : client_(NULL), | 38 : client_(NULL), |
| 38 num_frames_pending_(0), | 39 num_frames_pending_(0), |
| 39 max_swaps_pending_(0), | 40 max_swaps_pending_(0), |
| 40 time_source_(timer), | 41 time_source_(timer), |
| 41 active_(false), | 42 active_(false), |
| 42 is_time_source_throttling_(true), | 43 is_time_source_throttling_(true), |
| 43 weak_factory_(this), | 44 weak_factory_(this), |
| 44 thread_(NULL) { | 45 task_runner_(NULL) { |
| 45 time_source_client_adapter_ = | 46 time_source_client_adapter_ = |
| 46 FrameRateControllerTimeSourceAdapter::Create(this); | 47 FrameRateControllerTimeSourceAdapter::Create(this); |
| 47 time_source_->SetClient(time_source_client_adapter_.get()); | 48 time_source_->SetClient(time_source_client_adapter_.get()); |
| 48 } | 49 } |
| 49 | 50 |
| 50 FrameRateController::FrameRateController(Thread* thread) | 51 FrameRateController::FrameRateController( |
| 52 base::SingleThreadTaskRunner* task_runner) |
| 51 : client_(NULL), | 53 : client_(NULL), |
| 52 num_frames_pending_(0), | 54 num_frames_pending_(0), |
| 53 max_swaps_pending_(0), | 55 max_swaps_pending_(0), |
| 54 active_(false), | 56 active_(false), |
| 55 is_time_source_throttling_(false), | 57 is_time_source_throttling_(false), |
| 56 weak_factory_(this), | 58 weak_factory_(this), |
| 57 thread_(thread) {} | 59 task_runner_(task_runner) {} |
| 58 | 60 |
| 59 FrameRateController::~FrameRateController() { | 61 FrameRateController::~FrameRateController() { |
| 60 if (is_time_source_throttling_) | 62 if (is_time_source_throttling_) |
| 61 time_source_->SetActive(false); | 63 time_source_->SetActive(false); |
| 62 } | 64 } |
| 63 | 65 |
| 64 void FrameRateController::SetActive(bool active) { | 66 void FrameRateController::SetActive(bool active) { |
| 65 if (active_ == active) | 67 if (active_ == active) |
| 66 return; | 68 return; |
| 67 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); | 69 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 88 time_source_->SetTimebaseAndInterval(timebase, interval); | 90 time_source_->SetTimebaseAndInterval(timebase, interval); |
| 89 } | 91 } |
| 90 | 92 |
| 91 void FrameRateController::OnTimerTick() { | 93 void FrameRateController::OnTimerTick() { |
| 92 TRACE_EVENT0("cc", "FrameRateController::OnTimerTick"); | 94 TRACE_EVENT0("cc", "FrameRateController::OnTimerTick"); |
| 93 DCHECK(active_); | 95 DCHECK(active_); |
| 94 | 96 |
| 95 // Check if we have too many frames in flight. | 97 // Check if we have too many frames in flight. |
| 96 bool throttled = | 98 bool throttled = |
| 97 max_swaps_pending_ && num_frames_pending_ >= max_swaps_pending_; | 99 max_swaps_pending_ && num_frames_pending_ >= max_swaps_pending_; |
| 98 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled); | 100 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", task_runner_, throttled); |
| 99 | 101 |
| 100 if (client_) { | 102 if (client_) { |
| 101 client_->FrameRateControllerTick(throttled); | 103 client_->FrameRateControllerTick(throttled); |
| 102 } | 104 } |
| 103 | 105 |
| 104 if (!is_time_source_throttling_ && !throttled) | 106 if (!is_time_source_throttling_ && !throttled) |
| 105 PostManualTick(); | 107 PostManualTick(); |
| 106 } | 108 } |
| 107 | 109 |
| 108 void FrameRateController::PostManualTick() { | 110 void FrameRateController::PostManualTick() { |
| 109 if (active_) { | 111 if (active_) { |
| 110 thread_->PostTask(base::Bind(&FrameRateController::ManualTick, | 112 task_runner_->PostTask(FROM_HERE, |
| 111 weak_factory_.GetWeakPtr())); | 113 base::Bind(&FrameRateController::ManualTick, |
| 114 weak_factory_.GetWeakPtr())); |
| 112 } | 115 } |
| 113 } | 116 } |
| 114 | 117 |
| 115 void FrameRateController::ManualTick() { | 118 void FrameRateController::ManualTick() { |
| 116 OnTimerTick(); | 119 OnTimerTick(); |
| 117 } | 120 } |
| 118 | 121 |
| 119 void FrameRateController::DidSwapBuffers() { | 122 void FrameRateController::DidSwapBuffers() { |
| 120 num_frames_pending_++; | 123 num_frames_pending_++; |
| 121 } | 124 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 139 } | 142 } |
| 140 | 143 |
| 141 base::TimeTicks FrameRateController::LastTickTime() { | 144 base::TimeTicks FrameRateController::LastTickTime() { |
| 142 if (is_time_source_throttling_) | 145 if (is_time_source_throttling_) |
| 143 return time_source_->LastTickTime(); | 146 return time_source_->LastTickTime(); |
| 144 | 147 |
| 145 return base::TimeTicks::Now(); | 148 return base::TimeTicks::Now(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 } // namespace cc | 151 } // namespace cc |
| OLD | NEW |