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

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: rebase on pending patches 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 30 matching lines...) Expand all
41 41
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_frame_(false),
52 client_ready_for_begin_impl_frame_(true), 52 client_ready_for_begin_frame_(true),
53 client_(NULL), 53 client_(NULL),
54 check_for_retroactive_begin_impl_frame_pending_(false), 54 check_for_retroactive_begin_frame_pending_(false),
55 external_stencil_test_enabled_(false), 55 external_stencil_test_enabled_(false),
56 weak_ptr_factory_(this), 56 weak_ptr_factory_(this),
57 gpu_latency_history_(kGpuLatencyHistorySize) {} 57 gpu_latency_history_(kGpuLatencyHistorySize) {}
58 58
59 OutputSurface::OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device) 59 OutputSurface::OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device)
60 : software_device_(software_device.Pass()), 60 : software_device_(software_device.Pass()),
61 device_scale_factor_(-1), 61 device_scale_factor_(-1),
62 max_frames_pending_(0), 62 max_frames_pending_(0),
63 pending_swap_buffers_(0), 63 pending_swap_buffers_(0),
64 needs_begin_impl_frame_(false), 64 needs_begin_frame_(false),
65 client_ready_for_begin_impl_frame_(true), 65 client_ready_for_begin_frame_(true),
66 client_(NULL), 66 client_(NULL),
67 check_for_retroactive_begin_impl_frame_pending_(false), 67 check_for_retroactive_begin_frame_pending_(false),
68 external_stencil_test_enabled_(false), 68 external_stencil_test_enabled_(false),
69 weak_ptr_factory_(this), 69 weak_ptr_factory_(this),
70 gpu_latency_history_(kGpuLatencyHistorySize) {} 70 gpu_latency_history_(kGpuLatencyHistorySize) {}
71 71
72 OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider, 72 OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider,
73 scoped_ptr<SoftwareOutputDevice> software_device) 73 scoped_ptr<SoftwareOutputDevice> software_device)
74 : context_provider_(context_provider), 74 : context_provider_(context_provider),
75 software_device_(software_device.Pass()), 75 software_device_(software_device.Pass()),
76 device_scale_factor_(-1), 76 device_scale_factor_(-1),
77 max_frames_pending_(0), 77 max_frames_pending_(0),
78 pending_swap_buffers_(0), 78 pending_swap_buffers_(0),
79 needs_begin_impl_frame_(false), 79 needs_begin_frame_(false),
80 client_ready_for_begin_impl_frame_(true), 80 client_ready_for_begin_frame_(true),
81 client_(NULL), 81 client_(NULL),
82 check_for_retroactive_begin_impl_frame_pending_(false), 82 check_for_retroactive_begin_frame_pending_(false),
83 external_stencil_test_enabled_(false), 83 external_stencil_test_enabled_(false),
84 weak_ptr_factory_(this), 84 weak_ptr_factory_(this),
85 gpu_latency_history_(kGpuLatencyHistorySize) {} 85 gpu_latency_history_(kGpuLatencyHistorySize) {}
86 86
87 void OutputSurface::InitializeBeginImplFrameEmulation( 87 void OutputSurface::InitializeBeginFrameEmulation(
88 base::SingleThreadTaskRunner* task_runner, 88 base::SingleThreadTaskRunner* task_runner,
89 bool throttle_frame_production, 89 bool throttle_frame_production,
90 base::TimeDelta interval) { 90 base::TimeDelta interval) {
91 if (throttle_frame_production) { 91 if (throttle_frame_production) {
92 scoped_refptr<DelayBasedTimeSource> time_source; 92 scoped_refptr<DelayBasedTimeSource> time_source;
93 if (gfx::FrameTime::TimestampsAreHighRes()) 93 if (gfx::FrameTime::TimestampsAreHighRes())
94 time_source = DelayBasedTimeSourceHighRes::Create(interval, task_runner); 94 time_source = DelayBasedTimeSourceHighRes::Create(interval, task_runner);
95 else 95 else
96 time_source = DelayBasedTimeSource::Create(interval, task_runner); 96 time_source = DelayBasedTimeSource::Create(interval, task_runner);
97 frame_rate_controller_.reset(new FrameRateController(time_source)); 97 frame_rate_controller_.reset(new FrameRateController(time_source));
(...skipping 28 matching lines...) Expand all
126 "interval", 126 "interval",
127 interval.InSecondsF()); 127 interval.InSecondsF());
128 if (frame_rate_controller_) 128 if (frame_rate_controller_)
129 frame_rate_controller_->SetTimebaseAndInterval(timebase, interval); 129 frame_rate_controller_->SetTimebaseAndInterval(timebase, interval);
130 } 130 }
131 131
132 void OutputSurface::FrameRateControllerTick(bool throttled, 132 void OutputSurface::FrameRateControllerTick(bool throttled,
133 const BeginFrameArgs& args) { 133 const BeginFrameArgs& args) {
134 DCHECK(frame_rate_controller_); 134 DCHECK(frame_rate_controller_);
135 if (throttled) 135 if (throttled)
136 skipped_begin_impl_frame_args_ = args; 136 skipped_begin_frame_args_ = args;
137 else 137 else
138 BeginImplFrame(args); 138 BeginFrame(args);
139 } 139 }
140 140
141 // Forwarded to OutputSurfaceClient 141 // Forwarded to OutputSurfaceClient
142 void OutputSurface::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { 142 void OutputSurface::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {
143 TRACE_EVENT0("cc", "OutputSurface::SetNeedsRedrawRect"); 143 TRACE_EVENT0("cc", "OutputSurface::SetNeedsRedrawRect");
144 client_->SetNeedsRedrawRect(damage_rect); 144 client_->SetNeedsRedrawRect(damage_rect);
145 } 145 }
146 146
147 void OutputSurface::SetNeedsBeginImplFrame(bool enable) { 147 void OutputSurface::SetNeedsBeginFrame(bool enable) {
148 TRACE_EVENT1("cc", "OutputSurface::SetNeedsBeginImplFrame", "enable", enable); 148 TRACE_EVENT1("cc", "OutputSurface::SetNeedsBeginFrame", "enable", enable);
149 needs_begin_impl_frame_ = enable; 149 needs_begin_frame_ = enable;
150 client_ready_for_begin_impl_frame_ = true; 150 client_ready_for_begin_frame_ = true;
151 if (frame_rate_controller_) { 151 if (frame_rate_controller_) {
152 BeginFrameArgs skipped = frame_rate_controller_->SetActive(enable); 152 BeginFrameArgs skipped = frame_rate_controller_->SetActive(enable);
153 if (skipped.IsValid()) 153 if (skipped.IsValid())
154 skipped_begin_impl_frame_args_ = skipped; 154 skipped_begin_frame_args_ = skipped;
155 } 155 }
156 if (needs_begin_impl_frame_) 156 if (needs_begin_frame_)
157 PostCheckForRetroactiveBeginImplFrame(); 157 PostCheckForRetroactiveBeginFrame();
158 } 158 }
159 159
160 void OutputSurface::BeginImplFrame(const BeginFrameArgs& args) { 160 void OutputSurface::BeginFrame(const BeginFrameArgs& args) {
161 TRACE_EVENT2("cc", "OutputSurface::BeginImplFrame", 161 TRACE_EVENT2("cc",
162 "client_ready_for_begin_impl_frame_", 162 "OutputSurface::BeginFrame",
163 client_ready_for_begin_impl_frame_, 163 "client_ready_for_begin_frame_",
164 "pending_swap_buffers_", pending_swap_buffers_); 164 client_ready_for_begin_frame_,
165 if (!needs_begin_impl_frame_ || !client_ready_for_begin_impl_frame_ || 165 "pending_swap_buffers_",
166 pending_swap_buffers_);
167 if (!needs_begin_frame_ || !client_ready_for_begin_frame_ ||
166 (pending_swap_buffers_ >= max_frames_pending_ && 168 (pending_swap_buffers_ >= max_frames_pending_ &&
167 max_frames_pending_ > 0)) { 169 max_frames_pending_ > 0)) {
168 skipped_begin_impl_frame_args_ = args; 170 skipped_begin_frame_args_ = args;
169 } else { 171 } else {
170 client_ready_for_begin_impl_frame_ = false; 172 client_ready_for_begin_frame_ = false;
171 client_->BeginImplFrame(args); 173 client_->BeginFrame(args);
172 // args might be an alias for skipped_begin_impl_frame_args_. 174 // args might be an alias for skipped_begin_frame_args_.
173 // Do not reset it before calling BeginImplFrame! 175 // Do not reset it before calling BeginFrame!
174 skipped_begin_impl_frame_args_ = BeginFrameArgs(); 176 skipped_begin_frame_args_ = BeginFrameArgs();
175 } 177 }
176 } 178 }
177 179
178 base::TimeTicks OutputSurface::RetroactiveBeginImplFrameDeadline() { 180 base::TimeTicks OutputSurface::RetroactiveBeginFrameDeadline() {
179 // TODO(brianderson): Remove the alternative deadline once we have better 181 // TODO(brianderson): Remove the alternative deadline once we have better
180 // deadline estimations. 182 // deadline estimations.
181 base::TimeTicks alternative_deadline = 183 base::TimeTicks alternative_deadline =
182 skipped_begin_impl_frame_args_.frame_time + 184 skipped_begin_frame_args_.frame_time +
183 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); 185 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod();
184 return std::max(skipped_begin_impl_frame_args_.deadline, 186 return std::max(skipped_begin_frame_args_.deadline, alternative_deadline);
185 alternative_deadline);
186 } 187 }
187 188
188 void OutputSurface::PostCheckForRetroactiveBeginImplFrame() { 189 void OutputSurface::PostCheckForRetroactiveBeginFrame() {
189 if (!skipped_begin_impl_frame_args_.IsValid() || 190 if (!skipped_begin_frame_args_.IsValid() ||
190 check_for_retroactive_begin_impl_frame_pending_) 191 check_for_retroactive_begin_frame_pending_)
191 return; 192 return;
192 193
193 base::MessageLoop::current()->PostTask( 194 base::MessageLoop::current()->PostTask(
194 FROM_HERE, 195 FROM_HERE,
195 base::Bind(&OutputSurface::CheckForRetroactiveBeginImplFrame, 196 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame,
196 weak_ptr_factory_.GetWeakPtr())); 197 weak_ptr_factory_.GetWeakPtr()));
197 check_for_retroactive_begin_impl_frame_pending_ = true; 198 check_for_retroactive_begin_frame_pending_ = true;
198 } 199 }
199 200
200 void OutputSurface::CheckForRetroactiveBeginImplFrame() { 201 void OutputSurface::CheckForRetroactiveBeginFrame() {
201 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginImplFrame"); 202 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame");
202 check_for_retroactive_begin_impl_frame_pending_ = false; 203 check_for_retroactive_begin_frame_pending_ = false;
203 if (gfx::FrameTime::Now() < RetroactiveBeginImplFrameDeadline()) 204 if (gfx::FrameTime::Now() < RetroactiveBeginFrameDeadline())
204 BeginImplFrame(skipped_begin_impl_frame_args_); 205 BeginFrame(skipped_begin_frame_args_);
205 } 206 }
206 207
207 void OutputSurface::DidSwapBuffers() { 208 void OutputSurface::DidSwapBuffers() {
209 client_ready_for_begin_frame_ = true;
Sami 2014/04/03 15:55:58 Re: this and DidLoseOutputSurface -- not sure why
brianderson 2014/04/03 16:36:17 Good catch. They shouldn't be needed. I'll try rem
brianderson 2014/04/03 21:55:55 Done.
208 pending_swap_buffers_++; 210 pending_swap_buffers_++;
209 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", 211 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers",
210 "pending_swap_buffers_", pending_swap_buffers_); 212 "pending_swap_buffers_", pending_swap_buffers_);
211 client_->DidSwapBuffers(); 213 client_->DidSwapBuffers();
212 if (frame_rate_controller_) 214 if (frame_rate_controller_)
213 frame_rate_controller_->DidSwapBuffers(); 215 frame_rate_controller_->DidSwapBuffers();
214 PostCheckForRetroactiveBeginImplFrame(); 216 PostCheckForRetroactiveBeginFrame();
215 } 217 }
216 218
217 void OutputSurface::OnSwapBuffersComplete() { 219 void OutputSurface::OnSwapBuffersComplete() {
218 pending_swap_buffers_--; 220 pending_swap_buffers_--;
219 TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete", 221 TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete",
220 "pending_swap_buffers_", pending_swap_buffers_); 222 "pending_swap_buffers_", pending_swap_buffers_);
221 client_->OnSwapBuffersComplete(); 223 client_->OnSwapBuffersComplete();
222 if (frame_rate_controller_) 224 if (frame_rate_controller_)
223 frame_rate_controller_->DidSwapBuffersComplete(); 225 frame_rate_controller_->DidSwapBuffersComplete();
224 PostCheckForRetroactiveBeginImplFrame(); 226 PostCheckForRetroactiveBeginFrame();
225 } 227 }
226 228
227 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) { 229 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) {
228 client_->ReclaimResources(ack); 230 client_->ReclaimResources(ack);
229 } 231 }
230 232
231 void OutputSurface::DidLoseOutputSurface() { 233 void OutputSurface::DidLoseOutputSurface() {
232 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); 234 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface");
233 client_ready_for_begin_impl_frame_ = true;
234 pending_swap_buffers_ = 0; 235 pending_swap_buffers_ = 0;
235 skipped_begin_impl_frame_args_ = BeginFrameArgs(); 236 skipped_begin_frame_args_ = BeginFrameArgs();
236 if (frame_rate_controller_) 237 if (frame_rate_controller_)
237 frame_rate_controller_->SetActive(false); 238 frame_rate_controller_->SetActive(false);
238 pending_gpu_latency_query_ids_.clear(); 239 pending_gpu_latency_query_ids_.clear();
239 available_gpu_latency_query_ids_.clear(); 240 available_gpu_latency_query_ids_.clear();
240 client_->DidLoseOutputSurface(); 241 client_->DidLoseOutputSurface();
241 } 242 }
242 243
243 void OutputSurface::SetExternalStencilTest(bool enabled) { 244 void OutputSurface::SetExternalStencilTest(bool enabled) {
244 external_stencil_test_enabled_ = enabled; 245 external_stencil_test_enabled_ = enabled;
245 } 246 }
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", 488 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy",
488 "bytes_limit_when_visible", policy.bytes_limit_when_visible); 489 "bytes_limit_when_visible", policy.bytes_limit_when_visible);
489 // Just ignore the memory manager when it says to set the limit to zero 490 // 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 491 // bytes. This will happen when the memory manager thinks that the renderer
491 // is not visible (which the renderer knows better). 492 // is not visible (which the renderer knows better).
492 if (policy.bytes_limit_when_visible) 493 if (policy.bytes_limit_when_visible)
493 client_->SetMemoryPolicy(policy); 494 client_->SetMemoryPolicy(policy);
494 } 495 }
495 496
496 } // namespace cc 497 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698