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

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

Issue 16304003: Unified OutputSurface::SwapBuffers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to 205473 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 | Annotate | Revision Log
« no previous file with comments | « cc/scheduler/frame_rate_controller.h ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 19 matching lines...) Expand all
30 30
31 FrameRateController* frame_rate_controller_; 31 FrameRateController* frame_rate_controller_;
32 }; 32 };
33 33
34 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) 34 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer)
35 : client_(NULL), 35 : client_(NULL),
36 num_frames_pending_(0), 36 num_frames_pending_(0),
37 max_frames_pending_(0), 37 max_frames_pending_(0),
38 time_source_(timer), 38 time_source_(timer),
39 active_(false), 39 active_(false),
40 swap_buffers_complete_supported_(true),
41 is_time_source_throttling_(true), 40 is_time_source_throttling_(true),
42 weak_factory_(this), 41 weak_factory_(this),
43 thread_(NULL) { 42 thread_(NULL) {
44 time_source_client_adapter_ = 43 time_source_client_adapter_ =
45 FrameRateControllerTimeSourceAdapter::Create(this); 44 FrameRateControllerTimeSourceAdapter::Create(this);
46 time_source_->SetClient(time_source_client_adapter_.get()); 45 time_source_->SetClient(time_source_client_adapter_.get());
47 } 46 }
48 47
49 FrameRateController::FrameRateController(Thread* thread) 48 FrameRateController::FrameRateController(Thread* thread)
50 : client_(NULL), 49 : client_(NULL),
51 num_frames_pending_(0), 50 num_frames_pending_(0),
52 max_frames_pending_(0), 51 max_frames_pending_(0),
53 active_(false), 52 active_(false),
54 swap_buffers_complete_supported_(true),
55 is_time_source_throttling_(false), 53 is_time_source_throttling_(false),
56 weak_factory_(this), 54 weak_factory_(this),
57 thread_(thread) {} 55 thread_(thread) {}
58 56
59 FrameRateController::~FrameRateController() { 57 FrameRateController::~FrameRateController() {
60 if (is_time_source_throttling_) 58 if (is_time_source_throttling_)
61 time_source_->SetActive(false); 59 time_source_->SetActive(false);
62 } 60 }
63 61
64 void FrameRateController::SetActive(bool active) { 62 void FrameRateController::SetActive(bool active) {
(...skipping 16 matching lines...) Expand all
81 DCHECK_GE(max_frames_pending, 0); 79 DCHECK_GE(max_frames_pending, 0);
82 max_frames_pending_ = max_frames_pending; 80 max_frames_pending_ = max_frames_pending;
83 } 81 }
84 82
85 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase, 83 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase,
86 base::TimeDelta interval) { 84 base::TimeDelta interval) {
87 if (is_time_source_throttling_) 85 if (is_time_source_throttling_)
88 time_source_->SetTimebaseAndInterval(timebase, interval); 86 time_source_->SetTimebaseAndInterval(timebase, interval);
89 } 87 }
90 88
91 bool FrameRateController::swap_buffers_complete_supported() const {
92 return swap_buffers_complete_supported_;
93 }
94
95 void FrameRateController::SetSwapBuffersCompleteSupported(bool supported) {
96 swap_buffers_complete_supported_ = supported;
97 }
98
99 void FrameRateController::OnTimerTick() { 89 void FrameRateController::OnTimerTick() {
100 DCHECK(active_); 90 DCHECK(active_);
101 91
102 // Check if we have too many frames in flight. 92 // Check if we have too many frames in flight.
103 bool throttled = 93 bool throttled =
104 max_frames_pending_ && num_frames_pending_ >= max_frames_pending_; 94 max_frames_pending_ && num_frames_pending_ >= max_frames_pending_;
105 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled); 95 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled);
106 96
107 if (client_) 97 if (client_)
108 client_->BeginFrame(throttled); 98 client_->BeginFrame(throttled);
109 99
110 if (swap_buffers_complete_supported_ && !is_time_source_throttling_ && 100 if (!is_time_source_throttling_ && !throttled)
111 !throttled)
112 PostManualTick(); 101 PostManualTick();
113 } 102 }
114 103
115 void FrameRateController::PostManualTick() { 104 void FrameRateController::PostManualTick() {
116 if (active_) { 105 if (active_) {
117 thread_->PostTask(base::Bind(&FrameRateController::ManualTick, 106 thread_->PostTask(base::Bind(&FrameRateController::ManualTick,
118 weak_factory_.GetWeakPtr())); 107 weak_factory_.GetWeakPtr()));
119 } 108 }
120 } 109 }
121 110
122 void FrameRateController::ManualTick() { OnTimerTick(); } 111 void FrameRateController::ManualTick() { OnTimerTick(); }
123 112
124 void FrameRateController::DidSwapBuffers() { 113 void FrameRateController::DidSwapBuffers() {
125 if (swap_buffers_complete_supported_) 114 num_frames_pending_++;
126 num_frames_pending_++;
127 else if (!is_time_source_throttling_)
128 PostManualTick();
129 } 115 }
130 116
131 void FrameRateController::DidSwapBuffersComplete() { 117 void FrameRateController::DidSwapBuffersComplete() {
132 DCHECK(swap_buffers_complete_supported_);
133
134 DCHECK_GT(num_frames_pending_, 0); 118 DCHECK_GT(num_frames_pending_, 0);
135 num_frames_pending_--; 119 num_frames_pending_--;
136 if (!is_time_source_throttling_) 120 if (!is_time_source_throttling_)
137 PostManualTick(); 121 PostManualTick();
138 } 122 }
139 123
140 void FrameRateController::DidAbortAllPendingFrames() { 124 void FrameRateController::DidAbortAllPendingFrames() {
141 num_frames_pending_ = 0; 125 num_frames_pending_ = 0;
142 } 126 }
143 127
144 base::TimeTicks FrameRateController::NextTickTime() { 128 base::TimeTicks FrameRateController::NextTickTime() {
145 if (is_time_source_throttling_) 129 if (is_time_source_throttling_)
146 return time_source_->NextTickTime(); 130 return time_source_->NextTickTime();
147 131
148 return base::TimeTicks(); 132 return base::TimeTicks();
149 } 133 }
150 134
151 base::TimeTicks FrameRateController::LastTickTime() { 135 base::TimeTicks FrameRateController::LastTickTime() {
152 if (is_time_source_throttling_) 136 if (is_time_source_throttling_)
153 return time_source_->LastTickTime(); 137 return time_source_->LastTickTime();
154 138
155 return base::TimeTicks::Now(); 139 return base::TimeTicks::Now();
156 } 140 }
157 141
158 } // namespace cc 142 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/frame_rate_controller.h ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698