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

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

Issue 199523002: cc: Throttle swaps in Scheduler instead of OutputSurface (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Actually, unittests need CC_EXPORT. 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
« no previous file with comments | « cc/output/output_surface.h ('k') | cc/output/output_surface_client.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 (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 28 matching lines...) Expand all
39 const size_t kGpuLatencyHistorySize = 60; 39 const size_t kGpuLatencyHistorySize = 60;
40 const double kGpuLatencyEstimationPercentile = 100.0; 40 const double kGpuLatencyEstimationPercentile = 100.0;
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 begin_frame_interval_(BeginFrameArgs::DefaultInterval()),
50 pending_swap_buffers_(0), 50 throttle_frame_production_(true),
51 needs_begin_frame_(false), 51 needs_begin_frame_(false),
52 client_ready_for_begin_frame_(true), 52 client_ready_for_begin_frame_(true),
53 client_(NULL), 53 client_(NULL),
54 check_for_retroactive_begin_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 begin_frame_interval_(BeginFrameArgs::DefaultInterval()),
63 pending_swap_buffers_(0), 63 throttle_frame_production_(true),
64 needs_begin_frame_(false), 64 needs_begin_frame_(false),
65 client_ready_for_begin_frame_(true), 65 client_ready_for_begin_frame_(true),
66 client_(NULL), 66 client_(NULL),
67 check_for_retroactive_begin_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 begin_frame_interval_(BeginFrameArgs::DefaultInterval()),
78 pending_swap_buffers_(0), 78 throttle_frame_production_(true),
79 needs_begin_frame_(false), 79 needs_begin_frame_(false),
80 client_ready_for_begin_frame_(true), 80 client_ready_for_begin_frame_(true),
81 client_(NULL), 81 client_(NULL),
82 check_for_retroactive_begin_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::SetThrottleFrameProduction(bool enable) {
88 DCHECK(!frame_rate_controller_);
89 throttle_frame_production_ = enable;
90 }
91
87 void OutputSurface::InitializeBeginFrameEmulation( 92 void OutputSurface::InitializeBeginFrameEmulation(
88 base::SingleThreadTaskRunner* task_runner, 93 base::SingleThreadTaskRunner* task_runner,
89 bool throttle_frame_production,
90 base::TimeDelta interval) { 94 base::TimeDelta interval) {
91 if (throttle_frame_production) { 95 DCHECK(throttle_frame_production_);
92 scoped_refptr<DelayBasedTimeSource> time_source; 96 scoped_refptr<DelayBasedTimeSource> time_source;
93 if (gfx::FrameTime::TimestampsAreHighRes()) 97 if (gfx::FrameTime::TimestampsAreHighRes())
94 time_source = DelayBasedTimeSourceHighRes::Create(interval, task_runner); 98 time_source = DelayBasedTimeSourceHighRes::Create(interval, task_runner);
95 else 99 else
96 time_source = DelayBasedTimeSource::Create(interval, task_runner); 100 time_source = DelayBasedTimeSource::Create(interval, task_runner);
97 frame_rate_controller_.reset(new FrameRateController(time_source)); 101 frame_rate_controller_.reset(new FrameRateController(time_source));
98 } else {
99 frame_rate_controller_.reset(new FrameRateController(task_runner));
100 }
101 102
102 frame_rate_controller_->SetClient(this); 103 frame_rate_controller_->SetClient(this);
103 frame_rate_controller_->SetMaxSwapsPending(max_frames_pending_);
104 frame_rate_controller_->SetDeadlineAdjustment( 104 frame_rate_controller_->SetDeadlineAdjustment(
105 capabilities_.adjust_deadline_for_parent ? 105 capabilities_.adjust_deadline_for_parent ?
106 BeginFrameArgs::DefaultDeadlineAdjustment() : base::TimeDelta()); 106 BeginFrameArgs::DefaultDeadlineAdjustment() : base::TimeDelta());
107
108 // The new frame rate controller will consume the swap acks of the old
109 // frame rate controller, so we set that expectation up here.
110 for (int i = 0; i < pending_swap_buffers_; i++)
111 frame_rate_controller_->DidSwapBuffers();
112 }
113
114 void OutputSurface::SetMaxFramesPending(int max_frames_pending) {
115 if (frame_rate_controller_)
116 frame_rate_controller_->SetMaxSwapsPending(max_frames_pending);
117 max_frames_pending_ = max_frames_pending;
118 } 107 }
119 108
120 void OutputSurface::CommitVSyncParameters(base::TimeTicks timebase, 109 void OutputSurface::CommitVSyncParameters(base::TimeTicks timebase,
121 base::TimeDelta interval) { 110 base::TimeDelta interval) {
122 TRACE_EVENT2("cc", 111 TRACE_EVENT2("cc",
123 "OutputSurface::CommitVSyncParameters", 112 "OutputSurface::CommitVSyncParameters",
124 "timebase", 113 "timebase",
125 (timebase - base::TimeTicks()).InSecondsF(), 114 (timebase - base::TimeTicks()).InSecondsF(),
126 "interval", 115 "interval",
127 interval.InSecondsF()); 116 interval.InSecondsF());
117 begin_frame_interval_ = interval;
128 if (frame_rate_controller_) 118 if (frame_rate_controller_)
129 frame_rate_controller_->SetTimebaseAndInterval(timebase, interval); 119 frame_rate_controller_->SetTimebaseAndInterval(timebase, interval);
130 } 120 }
131 121
132 void OutputSurface::FrameRateControllerTick(bool throttled, 122 void OutputSurface::FrameRateControllerTick(const BeginFrameArgs& args) {
133 const BeginFrameArgs& args) {
134 DCHECK(frame_rate_controller_); 123 DCHECK(frame_rate_controller_);
135 if (throttled) 124 BeginFrame(args);
136 skipped_begin_frame_args_ = args;
137 else
138 BeginFrame(args);
139 } 125 }
140 126
141 // Forwarded to OutputSurfaceClient 127 // Forwarded to OutputSurfaceClient
142 void OutputSurface::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { 128 void OutputSurface::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {
143 TRACE_EVENT0("cc", "OutputSurface::SetNeedsRedrawRect"); 129 TRACE_EVENT0("cc", "OutputSurface::SetNeedsRedrawRect");
144 client_->SetNeedsRedrawRect(damage_rect); 130 client_->SetNeedsRedrawRect(damage_rect);
145 } 131 }
146 132
147 void OutputSurface::SetNeedsBeginFrame(bool enable) { 133 void OutputSurface::SetNeedsBeginFrame(bool enable) {
148 TRACE_EVENT1("cc", "OutputSurface::SetNeedsBeginFrame", "enable", enable); 134 TRACE_EVENT1("cc", "OutputSurface::SetNeedsBeginFrame", "enable", enable);
149 needs_begin_frame_ = enable; 135 needs_begin_frame_ = enable;
150 client_ready_for_begin_frame_ = true; 136 client_ready_for_begin_frame_ = true;
151 if (frame_rate_controller_) { 137 if (!throttle_frame_production_) {
138 if (enable) {
139 base::TimeTicks frame_time = gfx::FrameTime::Now();
140 base::TimeTicks deadline = frame_time + begin_frame_interval_;
141 skipped_begin_frame_args_ =
142 BeginFrameArgs::Create(frame_time, deadline, begin_frame_interval_);
143 }
144 } else if (frame_rate_controller_) {
152 BeginFrameArgs skipped = frame_rate_controller_->SetActive(enable); 145 BeginFrameArgs skipped = frame_rate_controller_->SetActive(enable);
153 if (skipped.IsValid()) 146 if (skipped.IsValid())
154 skipped_begin_frame_args_ = skipped; 147 skipped_begin_frame_args_ = skipped;
155 } 148 }
149
156 if (needs_begin_frame_) 150 if (needs_begin_frame_)
157 PostCheckForRetroactiveBeginFrame(); 151 PostCheckForRetroactiveBeginFrame();
158 } 152 }
159 153
160 void OutputSurface::BeginFrame(const BeginFrameArgs& args) { 154 void OutputSurface::BeginFrame(const BeginFrameArgs& args) {
161 TRACE_EVENT2("cc", 155 TRACE_EVENT1("cc",
162 "OutputSurface::BeginFrame", 156 "OutputSurface::BeginFrame",
163 "client_ready_for_begin_frame_", 157 "client_ready_for_begin_frame_",
164 client_ready_for_begin_frame_, 158 client_ready_for_begin_frame_);
165 "pending_swap_buffers_", 159 if (!needs_begin_frame_ || !client_ready_for_begin_frame_) {
166 pending_swap_buffers_);
167 if (!needs_begin_frame_ || !client_ready_for_begin_frame_ ||
168 (pending_swap_buffers_ >= max_frames_pending_ &&
169 max_frames_pending_ > 0)) {
170 skipped_begin_frame_args_ = args; 160 skipped_begin_frame_args_ = args;
171 } else { 161 } else {
172 client_ready_for_begin_frame_ = false; 162 client_ready_for_begin_frame_ = false;
173 client_->BeginFrame(args); 163 client_->BeginFrame(args);
174 // args might be an alias for skipped_begin_frame_args_. 164 // args might be an alias for skipped_begin_frame_args_.
175 // Do not reset it before calling BeginFrame! 165 // Do not reset it before calling BeginFrame!
176 skipped_begin_frame_args_ = BeginFrameArgs(); 166 skipped_begin_frame_args_ = BeginFrameArgs();
177 } 167 }
178 } 168 }
179 169
(...skipping 14 matching lines...) Expand all
194 base::MessageLoop::current()->PostTask( 184 base::MessageLoop::current()->PostTask(
195 FROM_HERE, 185 FROM_HERE,
196 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, 186 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame,
197 weak_ptr_factory_.GetWeakPtr())); 187 weak_ptr_factory_.GetWeakPtr()));
198 check_for_retroactive_begin_frame_pending_ = true; 188 check_for_retroactive_begin_frame_pending_ = true;
199 } 189 }
200 190
201 void OutputSurface::CheckForRetroactiveBeginFrame() { 191 void OutputSurface::CheckForRetroactiveBeginFrame() {
202 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); 192 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame");
203 check_for_retroactive_begin_frame_pending_ = false; 193 check_for_retroactive_begin_frame_pending_ = false;
204 if (gfx::FrameTime::Now() < RetroactiveBeginFrameDeadline()) 194 if (!throttle_frame_production_ ||
195 gfx::FrameTime::Now() < RetroactiveBeginFrameDeadline())
205 BeginFrame(skipped_begin_frame_args_); 196 BeginFrame(skipped_begin_frame_args_);
206 } 197 }
207 198
208 void OutputSurface::DidSwapBuffers() { 199 void OutputSurface::DidSwapBuffers() {
209 pending_swap_buffers_++; 200 TRACE_EVENT0("cc", "OutputSurface::DidSwapBuffers");
210 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers",
211 "pending_swap_buffers_", pending_swap_buffers_);
212 client_->DidSwapBuffers(); 201 client_->DidSwapBuffers();
213 if (frame_rate_controller_)
214 frame_rate_controller_->DidSwapBuffers();
215 PostCheckForRetroactiveBeginFrame();
216 } 202 }
217 203
218 void OutputSurface::OnSwapBuffersComplete() { 204 void OutputSurface::OnSwapBuffersComplete() {
219 pending_swap_buffers_--; 205 TRACE_EVENT0("cc", "OutputSurface::OnSwapBuffersComplete");
220 TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete", 206 client_->DidSwapBuffersComplete();
221 "pending_swap_buffers_", pending_swap_buffers_);
222 client_->OnSwapBuffersComplete();
223 if (frame_rate_controller_)
224 frame_rate_controller_->DidSwapBuffersComplete();
225 PostCheckForRetroactiveBeginFrame();
226 } 207 }
227 208
228 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) { 209 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) {
229 client_->ReclaimResources(ack); 210 client_->ReclaimResources(ack);
230 } 211 }
231 212
232 void OutputSurface::DidLoseOutputSurface() { 213 void OutputSurface::DidLoseOutputSurface() {
233 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); 214 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface");
234 client_ready_for_begin_frame_ = true; 215 client_ready_for_begin_frame_ = true;
235 pending_swap_buffers_ = 0;
236 skipped_begin_frame_args_ = BeginFrameArgs(); 216 skipped_begin_frame_args_ = BeginFrameArgs();
237 if (frame_rate_controller_) 217 if (frame_rate_controller_)
238 frame_rate_controller_->SetActive(false); 218 frame_rate_controller_->SetActive(false);
239 pending_gpu_latency_query_ids_.clear(); 219 pending_gpu_latency_query_ids_.clear();
240 available_gpu_latency_query_ids_.clear(); 220 available_gpu_latency_query_ids_.clear();
241 client_->DidLoseOutputSurface(); 221 client_->DidLoseOutputSurface();
242 } 222 }
243 223
244 void OutputSurface::SetExternalStencilTest(bool enabled) { 224 void OutputSurface::SetExternalStencilTest(bool enabled) {
245 external_stencil_test_enabled_ = enabled; 225 external_stencil_test_enabled_ = enabled;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", 468 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy",
489 "bytes_limit_when_visible", policy.bytes_limit_when_visible); 469 "bytes_limit_when_visible", policy.bytes_limit_when_visible);
490 // Just ignore the memory manager when it says to set the limit to zero 470 // Just ignore the memory manager when it says to set the limit to zero
491 // bytes. This will happen when the memory manager thinks that the renderer 471 // bytes. This will happen when the memory manager thinks that the renderer
492 // is not visible (which the renderer knows better). 472 // is not visible (which the renderer knows better).
493 if (policy.bytes_limit_when_visible) 473 if (policy.bytes_limit_when_visible)
494 client_->SetMemoryPolicy(policy); 474 client_->SetMemoryPolicy(policy);
495 } 475 }
496 476
497 } // namespace cc 477 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/output_surface.h ('k') | cc/output/output_surface_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698