| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/base/thread.h" | 9 #include "cc/base/thread.h" |
| 10 #include "cc/scheduler/delay_based_time_source.h" | 10 #include "cc/scheduler/delay_based_time_source.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void FrameRateController::SetSwapBuffersCompleteSupported(bool supported) { | 91 void FrameRateController::SetSwapBuffersCompleteSupported(bool supported) { |
| 92 swap_buffers_complete_supported_ = supported; | 92 swap_buffers_complete_supported_ = supported; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void FrameRateController::OnTimerTick() { | 95 void FrameRateController::OnTimerTick() { |
| 96 DCHECK(active_); | 96 DCHECK(active_); |
| 97 | 97 |
| 98 // Check if we have too many frames in flight. | 98 // Check if we have too many frames in flight. |
| 99 bool throttled = | 99 bool throttled = |
| 100 max_frames_pending_ && num_frames_pending_ >= max_frames_pending_; | 100 max_frames_pending_ && num_frames_pending_ >= max_frames_pending_; |
| 101 TRACE_COUNTER_ID1("cc", "ThrottledVSyncInterval", thread_, throttled); | 101 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled); |
| 102 | 102 |
| 103 if (client_) | 103 if (client_) |
| 104 client_->VSyncTick(throttled); | 104 client_->BeginImplFrame(throttled); |
| 105 | 105 |
| 106 if (swap_buffers_complete_supported_ && !is_time_source_throttling_ && | 106 if (swap_buffers_complete_supported_ && !is_time_source_throttling_ && |
| 107 !throttled) | 107 !throttled) |
| 108 PostManualTick(); | 108 PostManualTick(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void FrameRateController::PostManualTick() { | 111 void FrameRateController::PostManualTick() { |
| 112 if (active_) { | 112 if (active_) { |
| 113 thread_->PostTask(base::Bind(&FrameRateController::ManualTick, | 113 thread_->PostTask(base::Bind(&FrameRateController::ManualTick, |
| 114 weak_factory_.GetWeakPtr())); | 114 weak_factory_.GetWeakPtr())); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 void FrameRateController::ManualTick() { OnTimerTick(); } | 118 void FrameRateController::ManualTick() { OnTimerTick(); } |
| 119 | 119 |
| 120 void FrameRateController::DidBeginFrame() { | 120 void FrameRateController::DidSwapBuffers() { |
| 121 if (swap_buffers_complete_supported_) | 121 if (swap_buffers_complete_supported_) |
| 122 num_frames_pending_++; | 122 num_frames_pending_++; |
| 123 else if (!is_time_source_throttling_) | 123 else if (!is_time_source_throttling_) |
| 124 PostManualTick(); | 124 PostManualTick(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void FrameRateController::DidFinishFrame() { | 127 void FrameRateController::DidSwapBuffersComplete() { |
| 128 DCHECK(swap_buffers_complete_supported_); | 128 DCHECK(swap_buffers_complete_supported_); |
| 129 | 129 |
| 130 DCHECK_GT(num_frames_pending_, 0); | 130 DCHECK_GT(num_frames_pending_, 0); |
| 131 num_frames_pending_--; | 131 num_frames_pending_--; |
| 132 if (!is_time_source_throttling_) | 132 if (!is_time_source_throttling_) |
| 133 PostManualTick(); | 133 PostManualTick(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void FrameRateController::DidAbortAllPendingFrames() { | 136 void FrameRateController::DidAbortAllPendingFrames() { |
| 137 num_frames_pending_ = 0; | 137 num_frames_pending_ = 0; |
| 138 } | 138 } |
| 139 | 139 |
| 140 base::TimeTicks FrameRateController::NextTickTime() { | 140 base::TimeTicks FrameRateController::NextTickTime() { |
| 141 if (is_time_source_throttling_) | 141 if (is_time_source_throttling_) |
| 142 return time_source_->NextTickTime(); | 142 return time_source_->NextTickTime(); |
| 143 | 143 |
| 144 return base::TimeTicks(); | 144 return base::TimeTicks(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 base::TimeTicks FrameRateController::LastTickTime() { | 147 base::TimeTicks FrameRateController::LastTickTime() { |
| 148 if (is_time_source_throttling_) | 148 if (is_time_source_throttling_) |
| 149 return time_source_->LastTickTime(); | 149 return time_source_->LastTickTime(); |
| 150 | 150 |
| 151 return base::TimeTicks::Now(); | 151 return base::TimeTicks::Now(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace cc | 154 } // namespace cc |
| OLD | NEW |