Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: cc/scheduler/frame_rate_controller.cc

Issue 15836005: cc: Emulate BeginFrame in OutputSurfaces that don't support it natively (Closed) Base URL: http://git.chromium.org/chromium/src.git@nofrc
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "cc/scheduler/time_source.h" 11 #include "cc/scheduler/time_source.h"
12 12
13 namespace cc { 13 namespace cc {
14 14
15 class FrameRateControllerTimeSourceAdapter : public TimeSourceClient { 15 class FrameRateControllerTimeSourceAdapter : public TimeSourceClient {
16 public: 16 public:
17 static scoped_ptr<FrameRateControllerTimeSourceAdapter> Create( 17 static scoped_ptr<FrameRateControllerTimeSourceAdapter> Create(
18 FrameRateController* frame_rate_controller) { 18 FrameRateController* frame_rate_controller) {
19 return make_scoped_ptr( 19 return make_scoped_ptr(
20 new FrameRateControllerTimeSourceAdapter(frame_rate_controller)); 20 new FrameRateControllerTimeSourceAdapter(frame_rate_controller));
21 } 21 }
22 virtual ~FrameRateControllerTimeSourceAdapter() {} 22 virtual ~FrameRateControllerTimeSourceAdapter() {}
23 23
24 virtual void OnTimerTick() OVERRIDE { frame_rate_controller_->OnTimerTick(); } 24 virtual void OnTimerTick() OVERRIDE {
25 frame_rate_controller_->OnTimerTick();
26 }
25 27
26 private: 28 private:
27 explicit FrameRateControllerTimeSourceAdapter( 29 explicit FrameRateControllerTimeSourceAdapter(
28 FrameRateController* frame_rate_controller) 30 FrameRateController* frame_rate_controller)
29 : frame_rate_controller_(frame_rate_controller) {} 31 : frame_rate_controller_(frame_rate_controller) {}
30 32
31 FrameRateController* frame_rate_controller_; 33 FrameRateController* frame_rate_controller_;
32 }; 34 };
33 35
34 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) 36 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 base::TimeDelta interval) { 88 base::TimeDelta interval) {
87 if (is_time_source_throttling_) 89 if (is_time_source_throttling_)
88 time_source_->SetTimebaseAndInterval(timebase, interval); 90 time_source_->SetTimebaseAndInterval(timebase, interval);
89 } 91 }
90 92
91 void FrameRateController::SetSwapBuffersCompleteSupported(bool supported) { 93 void FrameRateController::SetSwapBuffersCompleteSupported(bool supported) {
92 swap_buffers_complete_supported_ = supported; 94 swap_buffers_complete_supported_ = supported;
93 } 95 }
94 96
95 void FrameRateController::OnTimerTick() { 97 void FrameRateController::OnTimerTick() {
98 TRACE_EVENT0("cc", "FrameRateController::OnTimerTick");
96 DCHECK(active_); 99 DCHECK(active_);
97 100
98 // Check if we have too many frames in flight. 101 // Check if we have too many frames in flight.
99 bool throttled = 102 bool throttled =
100 max_frames_pending_ && num_frames_pending_ >= max_frames_pending_; 103 max_frames_pending_ && num_frames_pending_ >= max_frames_pending_;
101 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled); 104 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled);
102 105
103 if (client_) 106 if (client_) {
104 client_->BeginFrame(throttled); 107 client_->FrameRateControllerTick(throttled);
108 }
105 109
106 if (swap_buffers_complete_supported_ && !is_time_source_throttling_ && 110 if (swap_buffers_complete_supported_ && !is_time_source_throttling_ &&
107 !throttled) 111 !throttled)
108 PostManualTick(); 112 PostManualTick();
109 } 113 }
110 114
111 void FrameRateController::PostManualTick() { 115 void FrameRateController::PostManualTick() {
112 if (active_) { 116 if (active_) {
113 thread_->PostTask(base::Bind(&FrameRateController::ManualTick, 117 thread_->PostTask(base::Bind(&FrameRateController::ManualTick,
114 weak_factory_.GetWeakPtr())); 118 weak_factory_.GetWeakPtr()));
115 } 119 }
116 } 120 }
117 121
118 void FrameRateController::ManualTick() { OnTimerTick(); } 122 void FrameRateController::ManualTick() {
123 OnTimerTick();
124 }
119 125
120 void FrameRateController::DidSwapBuffers() { 126 void FrameRateController::WillSwapBuffers() {
brianderson 2013/06/01 04:30:29 This now corresponds to a BeginFrame rather than a
121 if (swap_buffers_complete_supported_) 127 if (swap_buffers_complete_supported_)
122 num_frames_pending_++; 128 num_frames_pending_++;
123 else if (!is_time_source_throttling_) 129 else if (!is_time_source_throttling_)
124 PostManualTick(); 130 PostManualTick();
125 } 131 }
126 132
127 void FrameRateController::DidSwapBuffersComplete() { 133 void FrameRateController::DidSwapBuffersComplete() {
128 DCHECK(swap_buffers_complete_supported_); 134 DCHECK(swap_buffers_complete_supported_);
129 135
130 DCHECK_GT(num_frames_pending_, 0); 136 DCHECK_GT(num_frames_pending_, 0);
(...skipping 14 matching lines...) Expand all
145 } 151 }
146 152
147 base::TimeTicks FrameRateController::LastTickTime() { 153 base::TimeTicks FrameRateController::LastTickTime() {
148 if (is_time_source_throttling_) 154 if (is_time_source_throttling_)
149 return time_source_->LastTickTime(); 155 return time_source_->LastTickTime();
150 156
151 return base::TimeTicks::Now(); 157 return base::TimeTicks::Now();
152 } 158 }
153 159
154 } // namespace cc 160 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698