OLD | NEW |
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 Loading... |
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), | |
53 client_(NULL), | 52 client_(NULL), |
54 check_for_retroactive_begin_impl_frame_pending_(false), | 53 check_for_retroactive_begin_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_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_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_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_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 28 matching lines...) Expand all Loading... |
126 "interval", | 123 "interval", |
127 interval.InSecondsF()); | 124 interval.InSecondsF()); |
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_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_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_frame_args_ = skipped; |
155 } | 151 } |
156 if (needs_begin_impl_frame_) | 152 if (needs_begin_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_frame_ || (pending_swap_buffers_ >= max_frames_pending_ && |
166 (pending_swap_buffers_ >= max_frames_pending_ && | 162 max_frames_pending_ > 0)) { |
167 max_frames_pending_ > 0)) { | 163 skipped_begin_frame_args_ = args; |
168 skipped_begin_impl_frame_args_ = args; | |
169 } else { | 164 } else { |
170 client_ready_for_begin_impl_frame_ = false; | 165 client_->BeginFrame(args); |
171 client_->BeginImplFrame(args); | 166 // args might be an alias for skipped_begin_frame_args_. |
172 // args might be an alias for skipped_begin_impl_frame_args_. | 167 // Do not reset it before calling BeginFrame! |
173 // Do not reset it before calling BeginImplFrame! | 168 skipped_begin_frame_args_ = BeginFrameArgs(); |
174 skipped_begin_impl_frame_args_ = BeginFrameArgs(); | |
175 } | 169 } |
176 } | 170 } |
177 | 171 |
178 base::TimeTicks OutputSurface::RetroactiveBeginImplFrameDeadline() { | 172 base::TimeTicks OutputSurface::RetroactiveBeginFrameDeadline() { |
179 // TODO(brianderson): Remove the alternative deadline once we have better | 173 // TODO(brianderson): Remove the alternative deadline once we have better |
180 // deadline estimations. | 174 // deadline estimations. |
181 base::TimeTicks alternative_deadline = | 175 base::TimeTicks alternative_deadline = |
182 skipped_begin_impl_frame_args_.frame_time + | 176 skipped_begin_frame_args_.frame_time + |
183 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); | 177 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); |
184 return std::max(skipped_begin_impl_frame_args_.deadline, | 178 return std::max(skipped_begin_frame_args_.deadline, alternative_deadline); |
185 alternative_deadline); | |
186 } | 179 } |
187 | 180 |
188 void OutputSurface::PostCheckForRetroactiveBeginImplFrame() { | 181 void OutputSurface::PostCheckForRetroactiveBeginFrame() { |
189 if (!skipped_begin_impl_frame_args_.IsValid() || | 182 if (!skipped_begin_frame_args_.IsValid() || |
190 check_for_retroactive_begin_impl_frame_pending_) | 183 check_for_retroactive_begin_frame_pending_) |
191 return; | 184 return; |
192 | 185 |
193 base::MessageLoop::current()->PostTask( | 186 base::MessageLoop::current()->PostTask( |
194 FROM_HERE, | 187 FROM_HERE, |
195 base::Bind(&OutputSurface::CheckForRetroactiveBeginImplFrame, | 188 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, |
196 weak_ptr_factory_.GetWeakPtr())); | 189 weak_ptr_factory_.GetWeakPtr())); |
197 check_for_retroactive_begin_impl_frame_pending_ = true; | 190 check_for_retroactive_begin_frame_pending_ = true; |
198 } | 191 } |
199 | 192 |
200 void OutputSurface::CheckForRetroactiveBeginImplFrame() { | 193 void OutputSurface::CheckForRetroactiveBeginFrame() { |
201 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginImplFrame"); | 194 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); |
202 check_for_retroactive_begin_impl_frame_pending_ = false; | 195 check_for_retroactive_begin_frame_pending_ = false; |
203 if (gfx::FrameTime::Now() < RetroactiveBeginImplFrameDeadline()) | 196 if (gfx::FrameTime::Now() < RetroactiveBeginFrameDeadline()) |
204 BeginImplFrame(skipped_begin_impl_frame_args_); | 197 BeginFrame(skipped_begin_frame_args_); |
205 } | 198 } |
206 | 199 |
207 void OutputSurface::DidSwapBuffers() { | 200 void OutputSurface::DidSwapBuffers() { |
208 pending_swap_buffers_++; | 201 pending_swap_buffers_++; |
209 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", | 202 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", |
210 "pending_swap_buffers_", pending_swap_buffers_); | 203 "pending_swap_buffers_", pending_swap_buffers_); |
211 client_->DidSwapBuffers(); | 204 client_->DidSwapBuffers(); |
212 if (frame_rate_controller_) | 205 if (frame_rate_controller_) |
213 frame_rate_controller_->DidSwapBuffers(); | 206 frame_rate_controller_->DidSwapBuffers(); |
214 PostCheckForRetroactiveBeginImplFrame(); | 207 PostCheckForRetroactiveBeginFrame(); |
215 } | 208 } |
216 | 209 |
217 void OutputSurface::OnSwapBuffersComplete() { | 210 void OutputSurface::OnSwapBuffersComplete() { |
218 pending_swap_buffers_--; | 211 pending_swap_buffers_--; |
219 TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete", | 212 TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete", |
220 "pending_swap_buffers_", pending_swap_buffers_); | 213 "pending_swap_buffers_", pending_swap_buffers_); |
221 client_->OnSwapBuffersComplete(); | 214 client_->OnSwapBuffersComplete(); |
222 if (frame_rate_controller_) | 215 if (frame_rate_controller_) |
223 frame_rate_controller_->DidSwapBuffersComplete(); | 216 frame_rate_controller_->DidSwapBuffersComplete(); |
224 PostCheckForRetroactiveBeginImplFrame(); | 217 PostCheckForRetroactiveBeginFrame(); |
225 } | 218 } |
226 | 219 |
227 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) { | 220 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) { |
228 client_->ReclaimResources(ack); | 221 client_->ReclaimResources(ack); |
229 } | 222 } |
230 | 223 |
231 void OutputSurface::DidLoseOutputSurface() { | 224 void OutputSurface::DidLoseOutputSurface() { |
232 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); | 225 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); |
233 client_ready_for_begin_impl_frame_ = true; | |
234 pending_swap_buffers_ = 0; | 226 pending_swap_buffers_ = 0; |
235 skipped_begin_impl_frame_args_ = BeginFrameArgs(); | 227 skipped_begin_frame_args_ = BeginFrameArgs(); |
236 if (frame_rate_controller_) | 228 if (frame_rate_controller_) |
237 frame_rate_controller_->SetActive(false); | 229 frame_rate_controller_->SetActive(false); |
238 pending_gpu_latency_query_ids_.clear(); | 230 pending_gpu_latency_query_ids_.clear(); |
239 available_gpu_latency_query_ids_.clear(); | 231 available_gpu_latency_query_ids_.clear(); |
240 client_->DidLoseOutputSurface(); | 232 client_->DidLoseOutputSurface(); |
241 } | 233 } |
242 | 234 |
243 void OutputSurface::SetExternalStencilTest(bool enabled) { | 235 void OutputSurface::SetExternalStencilTest(bool enabled) { |
244 external_stencil_test_enabled_ = enabled; | 236 external_stencil_test_enabled_ = enabled; |
245 } | 237 } |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", | 479 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", |
488 "bytes_limit_when_visible", policy.bytes_limit_when_visible); | 480 "bytes_limit_when_visible", policy.bytes_limit_when_visible); |
489 // Just ignore the memory manager when it says to set the limit to zero | 481 // 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 | 482 // bytes. This will happen when the memory manager thinks that the renderer |
491 // is not visible (which the renderer knows better). | 483 // is not visible (which the renderer knows better). |
492 if (policy.bytes_limit_when_visible) | 484 if (policy.bytes_limit_when_visible) |
493 client_->SetMemoryPolicy(policy); | 485 client_->SetMemoryPolicy(policy); |
494 } | 486 } |
495 | 487 |
496 } // namespace cc | 488 } // namespace cc |
OLD | NEW |