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

Side by Side Diff: cc/output/output_surface.cc

Issue 218633010: cc: Handle retroactive BeginFrames in the Scheduler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@compositorVsyncDisable
Patch Set: Created 6 years, 8 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/output/output_surface.h" 5 #include "cc/output/output_surface.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 namespace cc { 44 namespace cc {
45 45
46 OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider) 46 OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider)
47 : context_provider_(context_provider), 47 : context_provider_(context_provider),
48 device_scale_factor_(-1), 48 device_scale_factor_(-1),
49 max_frames_pending_(0), 49 max_frames_pending_(0),
50 pending_swap_buffers_(0), 50 pending_swap_buffers_(0),
51 needs_begin_impl_frame_(false), 51 needs_begin_impl_frame_(false),
52 client_ready_for_begin_impl_frame_(true),
53 client_(NULL), 52 client_(NULL),
54 check_for_retroactive_begin_impl_frame_pending_(false), 53 check_for_retroactive_begin_impl_frame_pending_(false),
55 external_stencil_test_enabled_(false), 54 external_stencil_test_enabled_(false),
56 weak_ptr_factory_(this), 55 weak_ptr_factory_(this),
57 gpu_latency_history_(kGpuLatencyHistorySize) {} 56 gpu_latency_history_(kGpuLatencyHistorySize) {}
58 57
59 OutputSurface::OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device) 58 OutputSurface::OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device)
60 : software_device_(software_device.Pass()), 59 : software_device_(software_device.Pass()),
61 device_scale_factor_(-1), 60 device_scale_factor_(-1),
62 max_frames_pending_(0), 61 max_frames_pending_(0),
63 pending_swap_buffers_(0), 62 pending_swap_buffers_(0),
64 needs_begin_impl_frame_(false), 63 needs_begin_impl_frame_(false),
65 client_ready_for_begin_impl_frame_(true),
66 client_(NULL), 64 client_(NULL),
67 check_for_retroactive_begin_impl_frame_pending_(false), 65 check_for_retroactive_begin_impl_frame_pending_(false),
68 external_stencil_test_enabled_(false), 66 external_stencil_test_enabled_(false),
69 weak_ptr_factory_(this), 67 weak_ptr_factory_(this),
70 gpu_latency_history_(kGpuLatencyHistorySize) {} 68 gpu_latency_history_(kGpuLatencyHistorySize) {}
71 69
72 OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider, 70 OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider,
73 scoped_ptr<SoftwareOutputDevice> software_device) 71 scoped_ptr<SoftwareOutputDevice> software_device)
74 : context_provider_(context_provider), 72 : context_provider_(context_provider),
75 software_device_(software_device.Pass()), 73 software_device_(software_device.Pass()),
76 device_scale_factor_(-1), 74 device_scale_factor_(-1),
77 max_frames_pending_(0), 75 max_frames_pending_(0),
78 pending_swap_buffers_(0), 76 pending_swap_buffers_(0),
79 needs_begin_impl_frame_(false), 77 needs_begin_impl_frame_(false),
80 client_ready_for_begin_impl_frame_(true),
81 client_(NULL), 78 client_(NULL),
82 check_for_retroactive_begin_impl_frame_pending_(false), 79 check_for_retroactive_begin_impl_frame_pending_(false),
83 external_stencil_test_enabled_(false), 80 external_stencil_test_enabled_(false),
84 weak_ptr_factory_(this), 81 weak_ptr_factory_(this),
85 gpu_latency_history_(kGpuLatencyHistorySize) {} 82 gpu_latency_history_(kGpuLatencyHistorySize) {}
86 83
87 void OutputSurface::InitializeBeginImplFrameEmulation( 84 void OutputSurface::InitializeBeginFrameEmulation(
88 base::SingleThreadTaskRunner* task_runner, 85 base::SingleThreadTaskRunner* task_runner,
89 bool throttle_frame_production, 86 bool throttle_frame_production,
90 base::TimeDelta interval) { 87 base::TimeDelta interval) {
91 if (throttle_frame_production) { 88 if (throttle_frame_production) {
92 scoped_refptr<DelayBasedTimeSource> time_source; 89 scoped_refptr<DelayBasedTimeSource> time_source;
93 if (gfx::FrameTime::TimestampsAreHighRes()) 90 if (gfx::FrameTime::TimestampsAreHighRes())
94 time_source = DelayBasedTimeSourceHighRes::Create(interval, task_runner); 91 time_source = DelayBasedTimeSourceHighRes::Create(interval, task_runner);
95 else 92 else
96 time_source = DelayBasedTimeSource::Create(interval, task_runner); 93 time_source = DelayBasedTimeSource::Create(interval, task_runner);
97 frame_rate_controller_.reset(new FrameRateController(time_source)); 94 frame_rate_controller_.reset(new FrameRateController(time_source));
(...skipping 30 matching lines...) Expand all
128 if (frame_rate_controller_) 125 if (frame_rate_controller_)
129 frame_rate_controller_->SetTimebaseAndInterval(timebase, interval); 126 frame_rate_controller_->SetTimebaseAndInterval(timebase, interval);
130 } 127 }
131 128
132 void OutputSurface::FrameRateControllerTick(bool throttled, 129 void OutputSurface::FrameRateControllerTick(bool throttled,
133 const BeginFrameArgs& args) { 130 const BeginFrameArgs& args) {
134 DCHECK(frame_rate_controller_); 131 DCHECK(frame_rate_controller_);
135 if (throttled) 132 if (throttled)
136 skipped_begin_impl_frame_args_ = args; 133 skipped_begin_impl_frame_args_ = args;
137 else 134 else
138 BeginImplFrame(args); 135 BeginFrame(args);
139 } 136 }
140 137
141 // Forwarded to OutputSurfaceClient 138 // Forwarded to OutputSurfaceClient
142 void OutputSurface::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { 139 void OutputSurface::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {
143 TRACE_EVENT0("cc", "OutputSurface::SetNeedsRedrawRect"); 140 TRACE_EVENT0("cc", "OutputSurface::SetNeedsRedrawRect");
144 client_->SetNeedsRedrawRect(damage_rect); 141 client_->SetNeedsRedrawRect(damage_rect);
145 } 142 }
146 143
147 void OutputSurface::SetNeedsBeginImplFrame(bool enable) { 144 void OutputSurface::SetNeedsBeginFrame(bool enable) {
148 TRACE_EVENT1("cc", "OutputSurface::SetNeedsBeginImplFrame", "enable", enable); 145 TRACE_EVENT1("cc", "OutputSurface::SetNeedsBeginFrame", "enable", enable);
149 needs_begin_impl_frame_ = enable; 146 needs_begin_impl_frame_ = enable;
150 client_ready_for_begin_impl_frame_ = true;
151 if (frame_rate_controller_) { 147 if (frame_rate_controller_) {
152 BeginFrameArgs skipped = frame_rate_controller_->SetActive(enable); 148 BeginFrameArgs skipped = frame_rate_controller_->SetActive(enable);
153 if (skipped.IsValid()) 149 if (skipped.IsValid())
154 skipped_begin_impl_frame_args_ = skipped; 150 skipped_begin_impl_frame_args_ = skipped;
155 } 151 }
156 if (needs_begin_impl_frame_) 152 if (needs_begin_impl_frame_)
157 PostCheckForRetroactiveBeginImplFrame(); 153 PostCheckForRetroactiveBeginFrame();
158 } 154 }
159 155
160 void OutputSurface::BeginImplFrame(const BeginFrameArgs& args) { 156 void OutputSurface::BeginFrame(const BeginFrameArgs& args) {
161 TRACE_EVENT2("cc", "OutputSurface::BeginImplFrame", 157 TRACE_EVENT1("cc",
162 "client_ready_for_begin_impl_frame_", 158 "OutputSurface::BeginFrame",
163 client_ready_for_begin_impl_frame_, 159 "pending_swap_buffers_",
164 "pending_swap_buffers_", pending_swap_buffers_); 160 pending_swap_buffers_);
165 if (!needs_begin_impl_frame_ || !client_ready_for_begin_impl_frame_ || 161 if (!needs_begin_impl_frame_ ||
166 (pending_swap_buffers_ >= max_frames_pending_ && 162 (pending_swap_buffers_ >= max_frames_pending_ &&
167 max_frames_pending_ > 0)) { 163 max_frames_pending_ > 0)) {
168 skipped_begin_impl_frame_args_ = args; 164 skipped_begin_impl_frame_args_ = args;
169 } else { 165 } else {
170 client_ready_for_begin_impl_frame_ = false; 166 client_->BeginFrame(args);
171 client_->BeginImplFrame(args);
172 // args might be an alias for skipped_begin_impl_frame_args_. 167 // args might be an alias for skipped_begin_impl_frame_args_.
173 // Do not reset it before calling BeginImplFrame! 168 // Do not reset it before calling BeginFrame!
174 skipped_begin_impl_frame_args_ = BeginFrameArgs(); 169 skipped_begin_impl_frame_args_ = BeginFrameArgs();
175 } 170 }
176 } 171 }
177 172
178 base::TimeTicks OutputSurface::RetroactiveBeginImplFrameDeadline() { 173 base::TimeTicks OutputSurface::RetroactiveBeginFrameDeadline() {
179 // TODO(brianderson): Remove the alternative deadline once we have better 174 // TODO(brianderson): Remove the alternative deadline once we have better
180 // deadline estimations. 175 // deadline estimations.
181 base::TimeTicks alternative_deadline = 176 base::TimeTicks alternative_deadline =
182 skipped_begin_impl_frame_args_.frame_time + 177 skipped_begin_impl_frame_args_.frame_time +
183 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); 178 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod();
184 return std::max(skipped_begin_impl_frame_args_.deadline, 179 return std::max(skipped_begin_impl_frame_args_.deadline,
185 alternative_deadline); 180 alternative_deadline);
186 } 181 }
187 182
188 void OutputSurface::PostCheckForRetroactiveBeginImplFrame() { 183 void OutputSurface::PostCheckForRetroactiveBeginFrame() {
189 if (!skipped_begin_impl_frame_args_.IsValid() || 184 if (!skipped_begin_impl_frame_args_.IsValid() ||
190 check_for_retroactive_begin_impl_frame_pending_) 185 check_for_retroactive_begin_impl_frame_pending_)
Sami 2014/04/01 13:09:10 Rename this flag too?
191 return; 186 return;
192 187
193 base::MessageLoop::current()->PostTask( 188 base::MessageLoop::current()->PostTask(
194 FROM_HERE, 189 FROM_HERE,
195 base::Bind(&OutputSurface::CheckForRetroactiveBeginImplFrame, 190 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame,
196 weak_ptr_factory_.GetWeakPtr())); 191 weak_ptr_factory_.GetWeakPtr()));
197 check_for_retroactive_begin_impl_frame_pending_ = true; 192 check_for_retroactive_begin_impl_frame_pending_ = true;
198 } 193 }
199 194
200 void OutputSurface::CheckForRetroactiveBeginImplFrame() { 195 void OutputSurface::CheckForRetroactiveBeginFrame() {
201 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginImplFrame"); 196 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame");
202 check_for_retroactive_begin_impl_frame_pending_ = false; 197 check_for_retroactive_begin_impl_frame_pending_ = false;
203 if (gfx::FrameTime::Now() < RetroactiveBeginImplFrameDeadline()) 198 if (gfx::FrameTime::Now() < RetroactiveBeginFrameDeadline())
204 BeginImplFrame(skipped_begin_impl_frame_args_); 199 BeginFrame(skipped_begin_impl_frame_args_);
205 } 200 }
206 201
207 void OutputSurface::DidSwapBuffers() { 202 void OutputSurface::DidSwapBuffers() {
208 pending_swap_buffers_++; 203 pending_swap_buffers_++;
209 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", 204 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers",
210 "pending_swap_buffers_", pending_swap_buffers_); 205 "pending_swap_buffers_", pending_swap_buffers_);
211 client_->DidSwapBuffers(); 206 client_->DidSwapBuffers();
212 if (frame_rate_controller_) 207 if (frame_rate_controller_)
213 frame_rate_controller_->DidSwapBuffers(); 208 frame_rate_controller_->DidSwapBuffers();
214 PostCheckForRetroactiveBeginImplFrame(); 209 PostCheckForRetroactiveBeginFrame();
215 } 210 }
216 211
217 void OutputSurface::OnSwapBuffersComplete() { 212 void OutputSurface::OnSwapBuffersComplete() {
218 pending_swap_buffers_--; 213 pending_swap_buffers_--;
219 TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete", 214 TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete",
220 "pending_swap_buffers_", pending_swap_buffers_); 215 "pending_swap_buffers_", pending_swap_buffers_);
221 client_->OnSwapBuffersComplete(); 216 client_->OnSwapBuffersComplete();
222 if (frame_rate_controller_) 217 if (frame_rate_controller_)
223 frame_rate_controller_->DidSwapBuffersComplete(); 218 frame_rate_controller_->DidSwapBuffersComplete();
224 PostCheckForRetroactiveBeginImplFrame(); 219 PostCheckForRetroactiveBeginFrame();
225 } 220 }
226 221
227 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) { 222 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) {
228 client_->ReclaimResources(ack); 223 client_->ReclaimResources(ack);
229 } 224 }
230 225
231 void OutputSurface::DidLoseOutputSurface() { 226 void OutputSurface::DidLoseOutputSurface() {
232 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); 227 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface");
233 client_ready_for_begin_impl_frame_ = true;
234 pending_swap_buffers_ = 0; 228 pending_swap_buffers_ = 0;
235 skipped_begin_impl_frame_args_ = BeginFrameArgs(); 229 skipped_begin_impl_frame_args_ = BeginFrameArgs();
236 if (frame_rate_controller_) 230 if (frame_rate_controller_)
237 frame_rate_controller_->SetActive(false); 231 frame_rate_controller_->SetActive(false);
238 pending_gpu_latency_query_ids_.clear(); 232 pending_gpu_latency_query_ids_.clear();
239 available_gpu_latency_query_ids_.clear(); 233 available_gpu_latency_query_ids_.clear();
240 client_->DidLoseOutputSurface(); 234 client_->DidLoseOutputSurface();
241 } 235 }
242 236
243 void OutputSurface::SetExternalStencilTest(bool enabled) { 237 void OutputSurface::SetExternalStencilTest(bool enabled) {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", 481 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy",
488 "bytes_limit_when_visible", policy.bytes_limit_when_visible); 482 "bytes_limit_when_visible", policy.bytes_limit_when_visible);
489 // Just ignore the memory manager when it says to set the limit to zero 483 // Just ignore the memory manager when it says to set the limit to zero
490 // bytes. This will happen when the memory manager thinks that the renderer 484 // bytes. This will happen when the memory manager thinks that the renderer
491 // is not visible (which the renderer knows better). 485 // is not visible (which the renderer knows better).
492 if (policy.bytes_limit_when_visible) 486 if (policy.bytes_limit_when_visible)
493 client_->SetMemoryPolicy(policy); 487 client_->SetMemoryPolicy(policy);
494 } 488 }
495 489
496 } // namespace cc 490 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698