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 12 matching lines...) Expand all Loading... |
32 }; | 33 }; |
33 | 34 |
34 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) | 35 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) |
35 : client_(NULL), | 36 : client_(NULL), |
36 num_frames_pending_(0), | 37 num_frames_pending_(0), |
37 max_frames_pending_(0), | 38 max_frames_pending_(0), |
38 time_source_(timer), | 39 time_source_(timer), |
39 active_(false), | 40 active_(false), |
40 is_time_source_throttling_(true), | 41 is_time_source_throttling_(true), |
41 weak_factory_(this), | 42 weak_factory_(this), |
42 thread_(NULL) { | 43 task_runner_(NULL) { |
43 time_source_client_adapter_ = | 44 time_source_client_adapter_ = |
44 FrameRateControllerTimeSourceAdapter::Create(this); | 45 FrameRateControllerTimeSourceAdapter::Create(this); |
45 time_source_->SetClient(time_source_client_adapter_.get()); | 46 time_source_->SetClient(time_source_client_adapter_.get()); |
46 } | 47 } |
47 | 48 |
48 FrameRateController::FrameRateController(Thread* thread) | 49 FrameRateController::FrameRateController( |
| 50 base::SingleThreadTaskRunner* task_runner) |
49 : client_(NULL), | 51 : client_(NULL), |
50 num_frames_pending_(0), | 52 num_frames_pending_(0), |
51 max_frames_pending_(0), | 53 max_frames_pending_(0), |
52 active_(false), | 54 active_(false), |
53 is_time_source_throttling_(false), | 55 is_time_source_throttling_(false), |
54 weak_factory_(this), | 56 weak_factory_(this), |
55 thread_(thread) {} | 57 task_runner_(task_runner) {} |
56 | 58 |
57 FrameRateController::~FrameRateController() { | 59 FrameRateController::~FrameRateController() { |
58 if (is_time_source_throttling_) | 60 if (is_time_source_throttling_) |
59 time_source_->SetActive(false); | 61 time_source_->SetActive(false); |
60 } | 62 } |
61 | 63 |
62 void FrameRateController::SetActive(bool active) { | 64 void FrameRateController::SetActive(bool active) { |
63 if (active_ == active) | 65 if (active_ == active) |
64 return; | 66 return; |
65 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); | 67 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); |
(...skipping 19 matching lines...) Expand all Loading... |
85 if (is_time_source_throttling_) | 87 if (is_time_source_throttling_) |
86 time_source_->SetTimebaseAndInterval(timebase, interval); | 88 time_source_->SetTimebaseAndInterval(timebase, interval); |
87 } | 89 } |
88 | 90 |
89 void FrameRateController::OnTimerTick() { | 91 void FrameRateController::OnTimerTick() { |
90 DCHECK(active_); | 92 DCHECK(active_); |
91 | 93 |
92 // Check if we have too many frames in flight. | 94 // Check if we have too many frames in flight. |
93 bool throttled = | 95 bool throttled = |
94 max_frames_pending_ && num_frames_pending_ >= max_frames_pending_; | 96 max_frames_pending_ && num_frames_pending_ >= max_frames_pending_; |
95 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled); | 97 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", task_runner_, throttled); |
96 | 98 |
97 if (client_) | 99 if (client_) |
98 client_->BeginFrame(throttled); | 100 client_->BeginFrame(throttled); |
99 | 101 |
100 if (!is_time_source_throttling_ && !throttled) | 102 if (!is_time_source_throttling_ && !throttled) |
101 PostManualTick(); | 103 PostManualTick(); |
102 } | 104 } |
103 | 105 |
104 void FrameRateController::PostManualTick() { | 106 void FrameRateController::PostManualTick() { |
105 if (active_) { | 107 if (active_) { |
106 thread_->PostTask(base::Bind(&FrameRateController::ManualTick, | 108 task_runner_->PostTask(FROM_HERE, |
107 weak_factory_.GetWeakPtr())); | 109 base::Bind(&FrameRateController::ManualTick, |
| 110 weak_factory_.GetWeakPtr())); |
108 } | 111 } |
109 } | 112 } |
110 | 113 |
111 void FrameRateController::ManualTick() { OnTimerTick(); } | 114 void FrameRateController::ManualTick() { OnTimerTick(); } |
112 | 115 |
113 void FrameRateController::DidSwapBuffers() { | 116 void FrameRateController::DidSwapBuffers() { |
114 num_frames_pending_++; | 117 num_frames_pending_++; |
115 } | 118 } |
116 | 119 |
117 void FrameRateController::DidSwapBuffersComplete() { | 120 void FrameRateController::DidSwapBuffersComplete() { |
(...skipping 15 matching lines...) Expand all Loading... |
133 } | 136 } |
134 | 137 |
135 base::TimeTicks FrameRateController::LastTickTime() { | 138 base::TimeTicks FrameRateController::LastTickTime() { |
136 if (is_time_source_throttling_) | 139 if (is_time_source_throttling_) |
137 return time_source_->LastTickTime(); | 140 return time_source_->LastTickTime(); |
138 | 141 |
139 return base::TimeTicks::Now(); | 142 return base::TimeTicks::Now(); |
140 } | 143 } |
141 | 144 |
142 } // namespace cc | 145 } // namespace cc |
OLD | NEW |