OLD | NEW |
---|---|
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/trees/single_thread_proxy.h" | 5 #include "cc/trees/single_thread_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "cc/debug/benchmark_instrumentation.h" | 9 #include "cc/debug/benchmark_instrumentation.h" |
10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 return make_scoped_ptr( | 26 return make_scoped_ptr( |
27 new SingleThreadProxy(layer_tree_host, client)).PassAs<Proxy>(); | 27 new SingleThreadProxy(layer_tree_host, client)).PassAs<Proxy>(); |
28 } | 28 } |
29 | 29 |
30 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, | 30 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, |
31 LayerTreeHostSingleThreadClient* client) | 31 LayerTreeHostSingleThreadClient* client) |
32 : Proxy(NULL), | 32 : Proxy(NULL), |
33 layer_tree_host_(layer_tree_host), | 33 layer_tree_host_(layer_tree_host), |
34 client_(client), | 34 client_(client), |
35 next_frame_is_newly_committed_frame_(false), | 35 next_frame_is_newly_committed_frame_(false), |
36 inside_draw_(false) { | 36 inside_draw_(false), |
37 defer_commits_(false), | |
38 finish_commit_deferred_(false), | |
39 weak_factory_(this) { | |
37 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 40 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
38 DCHECK(Proxy::IsMainThread()); | 41 DCHECK(Proxy::IsMainThread()); |
39 DCHECK(layer_tree_host); | 42 DCHECK(layer_tree_host); |
40 | 43 |
41 // Impl-side painting not supported without threaded compositing. | 44 // Impl-side painting not supported without threaded compositing. |
42 CHECK(!layer_tree_host->settings().impl_side_painting) | 45 CHECK(!layer_tree_host->settings().impl_side_painting) |
43 << "Threaded compositing must be enabled to use impl-side painting."; | 46 << "Threaded compositing must be enabled to use impl-side painting."; |
44 } | 47 } |
45 | 48 |
46 void SingleThreadProxy::Start() { | 49 void SingleThreadProxy::Start() { |
(...skipping 19 matching lines...) Expand all Loading... | |
66 | 69 |
67 bool SingleThreadProxy::IsStarted() const { | 70 bool SingleThreadProxy::IsStarted() const { |
68 DCHECK(Proxy::IsMainThread()); | 71 DCHECK(Proxy::IsMainThread()); |
69 return layer_tree_host_impl_; | 72 return layer_tree_host_impl_; |
70 } | 73 } |
71 | 74 |
72 void SingleThreadProxy::SetLayerTreeHostClientReady() { | 75 void SingleThreadProxy::SetLayerTreeHostClientReady() { |
73 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); | 76 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); |
74 // Scheduling is controlled by the embedder in the single thread case, so | 77 // Scheduling is controlled by the embedder in the single thread case, so |
75 // nothing to do. | 78 // nothing to do. |
79 DCHECK(Proxy::IsMainThread()); | |
80 DebugScopedSetImplThread impl(this); | |
81 if (layer_tree_host_->settings().single_thread_proxy_scheduler && | |
82 !scheduler_on_impl_thread_) { | |
83 SchedulerSettings scheduler_settings(layer_tree_host_->settings()); | |
84 scheduler_on_impl_thread_ = Scheduler::Create(this, | |
85 scheduler_settings, | |
86 layer_tree_host_->id(), | |
87 MainThreadTaskRunner()); | |
88 scheduler_on_impl_thread_->SetCanStart(); | |
89 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | |
90 } | |
76 } | 91 } |
77 | 92 |
78 void SingleThreadProxy::SetVisible(bool visible) { | 93 void SingleThreadProxy::SetVisible(bool visible) { |
79 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); | 94 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); |
80 DebugScopedSetImplThread impl(this); | 95 DebugScopedSetImplThread impl(this); |
81 layer_tree_host_impl_->SetVisible(visible); | 96 layer_tree_host_impl_->SetVisible(visible); |
82 | |
83 // Changing visibility could change ShouldComposite(). | 97 // Changing visibility could change ShouldComposite(). |
84 UpdateBackgroundAnimateTicking(); | 98 UpdateBackgroundAnimateTicking(); |
danakj
2014/06/19 17:20:36
I probably asked you to put the scheduler call las
enne (OOO)
2014/06/19 20:32:28
Done. I don't think the order matters here, but I
| |
99 if (scheduler_on_impl_thread_) | |
100 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | |
85 } | 101 } |
86 | 102 |
87 void SingleThreadProxy::CreateAndInitializeOutputSurface() { | 103 void SingleThreadProxy::CreateAndInitializeOutputSurface() { |
88 TRACE_EVENT0( | 104 TRACE_EVENT0( |
89 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); | 105 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); |
90 DCHECK(Proxy::IsMainThread()); | 106 DCHECK(Proxy::IsMainThread()); |
91 DCHECK(layer_tree_host_->output_surface_lost()); | 107 DCHECK(layer_tree_host_->output_surface_lost()); |
92 | 108 |
93 scoped_ptr<OutputSurface> output_surface = | 109 scoped_ptr<OutputSurface> output_surface = |
94 layer_tree_host_->CreateOutputSurface(); | 110 layer_tree_host_->CreateOutputSurface(); |
95 | 111 |
96 renderer_capabilities_for_main_thread_ = RendererCapabilities(); | 112 renderer_capabilities_for_main_thread_ = RendererCapabilities(); |
97 | 113 |
98 bool success = !!output_surface; | 114 bool success = !!output_surface; |
99 if (success) { | 115 if (success) { |
100 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 116 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
101 DebugScopedSetImplThread impl(this); | 117 DebugScopedSetImplThread impl(this); |
102 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 118 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
103 layer_tree_host_impl_->resource_provider()); | 119 layer_tree_host_impl_->resource_provider()); |
104 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); | 120 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); |
105 } | 121 } |
106 | 122 |
107 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); | 123 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
108 | 124 |
109 if (!success) { | 125 if (success) { |
110 // Force another recreation attempt to happen by requesting another commit. | 126 if (scheduler_on_impl_thread_) |
111 SetNeedsCommit(); | 127 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); |
128 } else if (Proxy::MainThreadTaskRunner()) { | |
danakj
2014/06/19 17:20:36
If there's no scheduler we should SNC()? Is this r
| |
129 Proxy::MainThreadTaskRunner()->PostTask( | |
130 FROM_HERE, | |
131 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface, | |
132 weak_factory_.GetWeakPtr())); | |
112 } | 133 } |
113 } | 134 } |
114 | 135 |
115 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { | 136 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
116 DCHECK(Proxy::IsMainThread()); | 137 DCHECK(Proxy::IsMainThread()); |
117 DCHECK(!layer_tree_host_->output_surface_lost()); | 138 DCHECK(!layer_tree_host_->output_surface_lost()); |
118 return renderer_capabilities_for_main_thread_; | 139 return renderer_capabilities_for_main_thread_; |
119 } | 140 } |
120 | 141 |
121 void SingleThreadProxy::SetNeedsAnimate() { | 142 void SingleThreadProxy::SetNeedsAnimate() { |
122 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); | 143 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); |
123 DCHECK(Proxy::IsMainThread()); | 144 DCHECK(Proxy::IsMainThread()); |
124 client_->ScheduleAnimation(); | 145 client_->ScheduleAnimation(); |
danakj
2014/06/19 17:20:36
This will ScheduleAnimation() and then ScheduleCom
enne (OOO)
2014/06/19 20:32:28
Yeah, for now it calls root_window_->Animate in Co
| |
146 SetNeedsCommit(); | |
125 } | 147 } |
126 | 148 |
127 void SingleThreadProxy::SetNeedsUpdateLayers() { | 149 void SingleThreadProxy::SetNeedsUpdateLayers() { |
128 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); | 150 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); |
129 DCHECK(Proxy::IsMainThread()); | 151 DCHECK(Proxy::IsMainThread()); |
130 client_->ScheduleComposite(); | 152 client_->ScheduleComposite(); |
danakj
2014/06/19 17:20:36
This will ScheduleComposite() twice now, remove th
enne (OOO)
2014/06/19 20:32:28
Done.
| |
153 SetNeedsCommit(); | |
131 } | 154 } |
132 | 155 |
133 void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { | 156 void SingleThreadProxy::DoCommit(base::TimeTicks frame_begin_time) { |
134 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); | 157 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
135 DCHECK(Proxy::IsMainThread()); | 158 DCHECK(Proxy::IsMainThread()); |
159 layer_tree_host_->WillBeginMainFrame(); | |
160 layer_tree_host_->Layout(); | |
161 layer_tree_host_->AnimateLayers(frame_begin_time); | |
162 | |
163 if (PrioritizedResourceManager* contents_texture_manager = | |
164 layer_tree_host_->contents_texture_manager()) { | |
165 contents_texture_manager->UnlinkAndClearEvictedBackings(); | |
166 contents_texture_manager->SetMaxMemoryLimitBytes( | |
167 layer_tree_host_impl_->memory_allocation_limit_bytes()); | |
168 contents_texture_manager->SetExternalPriorityCutoff( | |
169 layer_tree_host_impl_->memory_allocation_priority_cutoff()); | |
170 } | |
171 | |
172 scoped_ptr<ResourceUpdateQueue> queue = | |
173 make_scoped_ptr(new ResourceUpdateQueue); | |
174 | |
175 layer_tree_host_->UpdateLayers(queue.get()); | |
176 | |
177 layer_tree_host_->WillCommit(); | |
178 | |
136 // Commit immediately. | 179 // Commit immediately. |
137 { | 180 { |
138 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 181 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
139 DebugScopedSetImplThread impl(this); | 182 DebugScopedSetImplThread impl(this); |
140 | 183 |
141 // This CapturePostTasks should be destroyed before CommitComplete() is | 184 // This CapturePostTasks should be destroyed before CommitComplete() is |
142 // called since that goes out to the embedder, and we want the embedder | 185 // called since that goes out to the embedder, and we want the embedder |
143 // to receive its callbacks before that. | 186 // to receive its callbacks before that. |
144 BlockingTaskRunner::CapturePostTasks blocked; | 187 BlockingTaskRunner::CapturePostTasks blocked; |
145 | 188 |
(...skipping 11 matching lines...) Expand all Loading... | |
157 Proxy::MainThreadTaskRunner(), | 200 Proxy::MainThreadTaskRunner(), |
158 queue.Pass(), | 201 queue.Pass(), |
159 layer_tree_host_impl_->resource_provider()); | 202 layer_tree_host_impl_->resource_provider()); |
160 update_controller->Finalize(); | 203 update_controller->Finalize(); |
161 | 204 |
162 if (layer_tree_host_impl_->EvictedUIResourcesExist()) | 205 if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
163 layer_tree_host_->RecreateUIResources(); | 206 layer_tree_host_->RecreateUIResources(); |
164 | 207 |
165 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); | 208 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
166 | 209 |
210 UpdateBackgroundAnimateTicking(); | |
danakj
2014/06/19 17:20:36
This happens after LTHI::CommitComplete() on the t
enne (OOO)
2014/06/19 20:32:28
Done.
| |
211 | |
167 layer_tree_host_impl_->CommitComplete(); | 212 layer_tree_host_impl_->CommitComplete(); |
168 | 213 |
169 #if DCHECK_IS_ON | 214 #if DCHECK_IS_ON |
170 // In the single-threaded case, the scale and scroll deltas should never be | 215 // In the single-threaded case, the scale and scroll deltas should never be |
171 // touched on the impl layer tree. | 216 // touched on the impl layer tree. |
172 scoped_ptr<ScrollAndScaleSet> scroll_info = | 217 scoped_ptr<ScrollAndScaleSet> scroll_info = |
173 layer_tree_host_impl_->ProcessScrollDeltas(); | 218 layer_tree_host_impl_->ProcessScrollDeltas(); |
174 DCHECK(!scroll_info->scrolls.size()); | 219 DCHECK(!scroll_info->scrolls.size()); |
175 DCHECK_EQ(1.f, scroll_info->page_scale_delta); | 220 DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
176 #endif | 221 #endif |
177 | 222 |
178 RenderingStatsInstrumentation* stats_instrumentation = | 223 RenderingStatsInstrumentation* stats_instrumentation = |
179 layer_tree_host_->rendering_stats_instrumentation(); | 224 layer_tree_host_->rendering_stats_instrumentation(); |
180 BenchmarkInstrumentation::IssueMainThreadRenderingStatsEvent( | 225 BenchmarkInstrumentation::IssueMainThreadRenderingStatsEvent( |
181 stats_instrumentation->main_thread_rendering_stats()); | 226 stats_instrumentation->main_thread_rendering_stats()); |
182 stats_instrumentation->AccumulateAndClearMainThreadStats(); | 227 stats_instrumentation->AccumulateAndClearMainThreadStats(); |
183 } | 228 } |
184 layer_tree_host_->CommitComplete(); | 229 layer_tree_host_->CommitComplete(); |
230 layer_tree_host_->DidBeginMainFrame(); | |
231 timing_history_.DidCommit(); | |
232 | |
185 next_frame_is_newly_committed_frame_ = true; | 233 next_frame_is_newly_committed_frame_ = true; |
186 } | 234 } |
187 | 235 |
188 void SingleThreadProxy::SetNeedsCommit() { | 236 void SingleThreadProxy::SetNeedsCommit() { |
189 DCHECK(Proxy::IsMainThread()); | 237 DCHECK(Proxy::IsMainThread()); |
238 DebugScopedSetImplThread impl(this); | |
190 client_->ScheduleComposite(); | 239 client_->ScheduleComposite(); |
240 if (scheduler_on_impl_thread_) | |
241 scheduler_on_impl_thread_->SetNeedsCommit(); | |
191 } | 242 } |
192 | 243 |
193 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { | 244 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
194 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); | 245 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); |
246 DCHECK(Proxy::IsMainThread()); | |
247 DebugScopedSetImplThread impl(this); | |
248 client_->ScheduleComposite(); | |
195 SetNeedsRedrawRectOnImplThread(damage_rect); | 249 SetNeedsRedrawRectOnImplThread(damage_rect); |
196 client_->ScheduleComposite(); | |
197 } | 250 } |
198 | 251 |
199 void SingleThreadProxy::SetNextCommitWaitsForActivation() { | 252 void SingleThreadProxy::SetNextCommitWaitsForActivation() { |
200 // There is no activation here other than commit. So do nothing. | 253 // There is no activation here other than commit. So do nothing. |
254 DCHECK(Proxy::IsMainThread()); | |
201 } | 255 } |
202 | 256 |
203 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { | 257 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
204 // Thread-only feature. | 258 DCHECK(Proxy::IsMainThread()); |
205 NOTREACHED(); | 259 DCHECK(scheduler_on_impl_thread_); |
260 if (defer_commits_ == defer_commits) | |
261 return; | |
262 | |
263 if (defer_commits) | |
264 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this); | |
265 else | |
266 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this); | |
267 | |
268 defer_commits_ = defer_commits; | |
269 if (!defer_commits_ && finish_commit_deferred_) { | |
270 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | |
271 scheduler_on_impl_thread_->NotifyReadyToCommit(); | |
272 finish_commit_deferred_ = false; | |
273 } | |
206 } | 274 } |
207 | 275 |
208 bool SingleThreadProxy::CommitRequested() const { return false; } | 276 bool SingleThreadProxy::CommitRequested() const { |
277 DCHECK(Proxy::IsMainThread()); | |
278 return finish_commit_deferred_; | |
279 } | |
209 | 280 |
210 bool SingleThreadProxy::BeginMainFrameRequested() const { return false; } | 281 bool SingleThreadProxy::BeginMainFrameRequested() const { |
282 DCHECK(Proxy::IsMainThread()); | |
283 return finish_commit_deferred_; | |
284 } | |
211 | 285 |
212 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { | 286 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { |
213 return std::numeric_limits<size_t>::max(); | 287 return std::numeric_limits<size_t>::max(); |
214 } | 288 } |
215 | 289 |
216 void SingleThreadProxy::Stop() { | 290 void SingleThreadProxy::Stop() { |
217 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); | 291 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
218 DCHECK(Proxy::IsMainThread()); | 292 DCHECK(Proxy::IsMainThread()); |
219 { | 293 { |
220 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 294 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
221 DebugScopedSetImplThread impl(this); | 295 DebugScopedSetImplThread impl(this); |
222 | 296 |
223 BlockingTaskRunner::CapturePostTasks blocked; | 297 BlockingTaskRunner::CapturePostTasks blocked; |
224 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 298 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
225 layer_tree_host_impl_->resource_provider()); | 299 layer_tree_host_impl_->resource_provider()); |
300 scheduler_on_impl_thread_.reset(); | |
226 layer_tree_host_impl_.reset(); | 301 layer_tree_host_impl_.reset(); |
227 } | 302 } |
228 layer_tree_host_ = NULL; | 303 layer_tree_host_ = NULL; |
229 } | 304 } |
230 | 305 |
231 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 306 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
232 TRACE_EVENT1( | 307 TRACE_EVENT1( |
233 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 308 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
234 DCHECK(Proxy::IsImplThread()); | 309 DCHECK(Proxy::IsImplThread()); |
235 UpdateBackgroundAnimateTicking(); | 310 UpdateBackgroundAnimateTicking(); |
311 if (scheduler_on_impl_thread_) | |
312 scheduler_on_impl_thread_->SetCanDraw(can_draw); | |
236 } | 313 } |
237 | 314 |
238 void SingleThreadProxy::NotifyReadyToActivate() { | 315 void SingleThreadProxy::NotifyReadyToActivate() { |
239 // Thread-only feature. | 316 // Impl-side painting only. |
240 NOTREACHED(); | 317 NOTREACHED(); |
241 } | 318 } |
242 | 319 |
243 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { | 320 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
244 client_->ScheduleComposite(); | 321 client_->ScheduleComposite(); |
322 if (scheduler_on_impl_thread_) | |
323 scheduler_on_impl_thread_->SetNeedsRedraw(); | |
245 } | 324 } |
246 | 325 |
247 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { | 326 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
248 SetNeedsRedrawOnImplThread(); | 327 SetNeedsRedrawOnImplThread(); |
249 } | 328 } |
250 | 329 |
251 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { | 330 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
252 // Thread-only/Impl-side-painting-only feature. | 331 // Impl-side painting only. |
253 NOTREACHED(); | 332 NOTREACHED(); |
254 } | 333 } |
255 | 334 |
256 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( | 335 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
257 const gfx::Rect& damage_rect) { | 336 const gfx::Rect& damage_rect) { |
258 // TODO(brianderson): Once we move render_widget scheduling into this class, | |
259 // we can treat redraw requests more efficiently than CommitAndRedraw | |
260 // requests. | |
261 layer_tree_host_impl_->SetViewportDamage(damage_rect); | 337 layer_tree_host_impl_->SetViewportDamage(damage_rect); |
262 SetNeedsCommit(); | 338 SetNeedsRedrawOnImplThread(); |
263 } | 339 } |
264 | 340 |
265 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { | 341 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
266 // Impl-side painting only. | 342 // Impl-side painting only. |
267 NOTREACHED(); | 343 NOTREACHED(); |
268 } | 344 } |
269 | 345 |
270 void SingleThreadProxy::SetNeedsCommitOnImplThread() { | 346 void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
271 client_->ScheduleComposite(); | 347 client_->ScheduleComposite(); |
348 if (scheduler_on_impl_thread_) | |
349 scheduler_on_impl_thread_->SetNeedsCommit(); | |
272 } | 350 } |
273 | 351 |
274 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 352 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
275 scoped_ptr<AnimationEventsVector> events) { | 353 scoped_ptr<AnimationEventsVector> events) { |
276 TRACE_EVENT0( | 354 TRACE_EVENT0( |
277 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); | 355 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
278 DCHECK(Proxy::IsImplThread()); | 356 DCHECK(Proxy::IsImplThread()); |
279 DebugScopedSetMainThread main(this); | 357 DebugScopedSetMainThread main(this); |
280 layer_tree_host_->SetAnimationEvents(events.Pass()); | 358 layer_tree_host_->SetAnimationEvents(events.Pass()); |
281 } | 359 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 } | 391 } |
314 | 392 |
315 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } | 393 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
316 | 394 |
317 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { | 395 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
318 DCHECK(IsImplThread()); | 396 DCHECK(IsImplThread()); |
319 renderer_capabilities_for_main_thread_ = | 397 renderer_capabilities_for_main_thread_ = |
320 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); | 398 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); |
321 } | 399 } |
322 | 400 |
401 void SingleThreadProxy::DidActivatePendingTree() { | |
402 // Impl-side painting only. | |
403 NOTREACHED(); | |
404 } | |
405 | |
406 void SingleThreadProxy::DidManageTiles() { | |
407 // Impl-side painting only. | |
408 NOTREACHED(); | |
409 } | |
410 | |
323 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 411 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
324 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 412 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
325 // Cause a commit so we can notice the lost context. | 413 { |
326 SetNeedsCommitOnImplThread(); | 414 DebugScopedSetMainThread main(this); |
415 // This must happen before we notify the scheduler as it may try to recreate | |
416 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. | |
417 layer_tree_host_->DidLoseOutputSurface(); | |
418 } | |
327 client_->DidAbortSwapBuffers(); | 419 client_->DidAbortSwapBuffers(); |
420 if (scheduler_on_impl_thread_) | |
421 scheduler_on_impl_thread_->DidLoseOutputSurface(); | |
328 } | 422 } |
329 | 423 |
330 void SingleThreadProxy::DidSwapBuffersOnImplThread() { | 424 void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
425 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); | |
426 if (scheduler_on_impl_thread_) | |
427 scheduler_on_impl_thread_->DidSwapBuffers(); | |
331 client_->DidPostSwapBuffers(); | 428 client_->DidPostSwapBuffers(); |
332 } | 429 } |
333 | 430 |
334 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { | 431 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
335 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); | 432 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
336 client_->DidCompleteSwapBuffers(); | 433 if (scheduler_on_impl_thread_) |
434 scheduler_on_impl_thread_->DidSwapBuffersComplete(); | |
435 layer_tree_host_->DidCompleteSwapBuffers(); | |
337 } | 436 } |
338 | 437 |
339 // Called by the legacy scheduling path (e.g. where render_widget does the | 438 void SingleThreadProxy::BeginFrame(const BeginFrameArgs& args) { |
340 // scheduling) | 439 TRACE_EVENT0("cc", "SingleThreadProxy::BeginFrame"); |
440 if (scheduler_on_impl_thread_) | |
441 scheduler_on_impl_thread_->BeginImplFrame(args); | |
442 } | |
443 | |
341 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 444 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
342 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); | 445 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); |
343 DCHECK(Proxy::IsMainThread()); | 446 DCHECK(Proxy::IsMainThread()); |
344 DCHECK(!layer_tree_host_->output_surface_lost()); | 447 DCHECK(!layer_tree_host_->output_surface_lost()); |
345 | 448 |
346 layer_tree_host_->AnimateLayers(frame_begin_time); | 449 DoCommit(frame_begin_time); |
347 | |
348 if (PrioritizedResourceManager* contents_texture_manager = | |
349 layer_tree_host_->contents_texture_manager()) { | |
350 contents_texture_manager->UnlinkAndClearEvictedBackings(); | |
351 contents_texture_manager->SetMaxMemoryLimitBytes( | |
352 layer_tree_host_impl_->memory_allocation_limit_bytes()); | |
353 contents_texture_manager->SetExternalPriorityCutoff( | |
354 layer_tree_host_impl_->memory_allocation_priority_cutoff()); | |
355 } | |
356 | |
357 scoped_ptr<ResourceUpdateQueue> queue = | |
358 make_scoped_ptr(new ResourceUpdateQueue); | |
359 layer_tree_host_->UpdateLayers(queue.get()); | |
360 layer_tree_host_->WillCommit(); | |
361 DoCommit(queue.Pass()); | |
362 layer_tree_host_->DidBeginMainFrame(); | |
363 | 450 |
364 LayerTreeHostImpl::FrameData frame; | 451 LayerTreeHostImpl::FrameData frame; |
365 if (DoComposite(frame_begin_time, &frame)) { | 452 DoComposite(frame_begin_time, &frame); |
366 { | |
367 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
368 DebugScopedSetImplThread impl(this); | |
369 | |
370 // This CapturePostTasks should be destroyed before | |
371 // DidCommitAndDrawFrame() is called since that goes out to the embedder, | |
372 // and we want the embedder to receive its callbacks before that. | |
373 // NOTE: This maintains consistent ordering with the ThreadProxy since | |
374 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread | |
375 // there as the main thread is not blocked, so any posted tasks inside | |
376 // the swap buffers will execute first. | |
377 BlockingTaskRunner::CapturePostTasks blocked; | |
378 | |
379 layer_tree_host_impl_->SwapBuffers(frame); | |
380 } | |
381 DidSwapFrame(); | |
382 } | |
383 } | 453 } |
384 | 454 |
385 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { | 455 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
386 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 456 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
387 { | 457 { |
388 // The following line casts away const modifiers because it is just | 458 // The following line casts away const modifiers because it is just |
389 // setting debug state. We still want the AsValue() function and its | 459 // setting debug state. We still want the AsValue() function and its |
390 // call chain to be const throughout. | 460 // call chain to be const throughout. |
391 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); | 461 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
392 | 462 |
(...skipping 18 matching lines...) Expand all Loading... | |
411 return layer_tree_host_impl_->visible() && | 481 return layer_tree_host_impl_->visible() && |
412 layer_tree_host_impl_->CanDraw(); | 482 layer_tree_host_impl_->CanDraw(); |
413 } | 483 } |
414 | 484 |
415 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { | 485 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { |
416 DCHECK(Proxy::IsImplThread()); | 486 DCHECK(Proxy::IsImplThread()); |
417 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | 487 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( |
418 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); | 488 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); |
419 } | 489 } |
420 | 490 |
421 bool SingleThreadProxy::DoComposite( | 491 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
422 base::TimeTicks frame_begin_time, | 492 LayerTreeHostImpl::FrameData* frame) { |
423 LayerTreeHostImpl::FrameData* frame) { | |
424 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 493 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
425 DCHECK(!layer_tree_host_->output_surface_lost()); | 494 DCHECK(!layer_tree_host_->output_surface_lost()); |
426 | 495 |
427 bool lost_output_surface = false; | |
428 { | 496 { |
429 DebugScopedSetImplThread impl(this); | 497 DebugScopedSetImplThread impl(this); |
430 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 498 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
431 | 499 |
432 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 500 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
433 // frame, so can only be used when such a frame is possible. Since | 501 // frame, so can only be used when such a frame is possible. Since |
434 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 502 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
435 // CanDraw() as well. | 503 // CanDraw() as well. |
436 if (!ShouldComposite()) { | 504 if (!ShouldComposite()) { |
437 UpdateBackgroundAnimateTicking(); | 505 UpdateBackgroundAnimateTicking(); |
438 return false; | 506 return DRAW_ABORTED_CANT_DRAW; |
439 } | 507 } |
440 | 508 |
509 timing_history_.DidStartDrawing(); | |
510 | |
441 layer_tree_host_impl_->Animate( | 511 layer_tree_host_impl_->Animate( |
442 layer_tree_host_impl_->CurrentFrameTimeTicks()); | 512 layer_tree_host_impl_->CurrentFrameTimeTicks()); |
443 UpdateBackgroundAnimateTicking(); | 513 UpdateBackgroundAnimateTicking(); |
444 | 514 |
445 if (!layer_tree_host_impl_->IsContextLost()) { | 515 if (!layer_tree_host_impl_->IsContextLost()) { |
446 layer_tree_host_impl_->PrepareToDraw(frame); | 516 layer_tree_host_impl_->PrepareToDraw(frame); |
447 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); | 517 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
448 layer_tree_host_impl_->DidDrawAllLayers(*frame); | 518 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
449 } | 519 } |
450 lost_output_surface = layer_tree_host_impl_->IsContextLost(); | |
451 | 520 |
452 bool start_ready_animations = true; | 521 bool start_ready_animations = true; |
453 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 522 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
454 | 523 |
455 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | 524 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
525 | |
526 timing_history_.DidFinishDrawing(); | |
456 } | 527 } |
457 | 528 |
458 if (lost_output_surface) { | 529 { |
459 layer_tree_host_->DidLoseOutputSurface(); | 530 DebugScopedSetImplThread impl(this); |
460 return false; | 531 |
532 if (layer_tree_host_impl_->IsContextLost()) { | |
533 DidLoseOutputSurfaceOnImplThread(); | |
534 } else { | |
535 // This CapturePostTasks should be destroyed before | |
536 // DidCommitAndDrawFrame() is called since that goes out to the embedder, | |
537 // and we want the embedder to receive its callbacks before that. | |
538 // NOTE: This maintains consistent ordering with the ThreadProxy since | |
539 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread | |
540 // there as the main thread is not blocked, so any posted tasks inside | |
541 // the swap buffers will execute first. | |
542 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
543 | |
544 BlockingTaskRunner::CapturePostTasks blocked; | |
545 layer_tree_host_impl_->SwapBuffers(*frame); | |
546 } | |
461 } | 547 } |
548 DidCommitAndDrawFrame(); | |
462 | 549 |
463 return true; | 550 return DRAW_SUCCESS; |
464 } | 551 } |
465 | 552 |
466 void SingleThreadProxy::DidSwapFrame() { | 553 void SingleThreadProxy::DidCommitAndDrawFrame() { |
467 if (next_frame_is_newly_committed_frame_) { | 554 if (next_frame_is_newly_committed_frame_) { |
555 DebugScopedSetMainThread main(this); | |
468 next_frame_is_newly_committed_frame_ = false; | 556 next_frame_is_newly_committed_frame_ = false; |
469 layer_tree_host_->DidCommitAndDrawFrame(); | 557 layer_tree_host_->DidCommitAndDrawFrame(); |
470 } | 558 } |
471 } | 559 } |
472 | 560 |
473 bool SingleThreadProxy::CommitPendingForTesting() { return false; } | 561 bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
474 | 562 |
563 scoped_ptr<base::Value> SingleThreadProxy::SchedulerAsValueForTesting() { | |
564 DebugScopedSetImplThread impl(this); | |
565 if (!scheduler_on_impl_thread_) | |
566 return make_scoped_ptr(base::Value::CreateNullValue()).Pass(); | |
567 return scheduler_on_impl_thread_->AsValue().Pass(); | |
568 } | |
569 | |
570 void SingleThreadProxy::SetNeedsBeginFrame(bool enable) { | |
571 layer_tree_host_impl_->SetNeedsBeginFrame(enable); | |
572 } | |
573 | |
574 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { | |
575 layer_tree_host_impl_->WillBeginImplFrame(args); | |
576 } | |
577 | |
578 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { | |
579 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); | |
580 if (defer_commits_) { | |
581 DCHECK(!finish_commit_deferred_); | |
582 finish_commit_deferred_ = true; | |
583 layer_tree_host_->DidDeferCommit(); | |
584 return; | |
585 } | |
586 timing_history_.DidBeginMainFrame(); | |
587 | |
588 DCHECK(scheduler_on_impl_thread_); | |
589 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | |
590 scheduler_on_impl_thread_->NotifyReadyToCommit(); | |
591 } | |
592 | |
593 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { | |
594 DebugScopedSetImplThread impl(this); | |
595 if (layer_tree_host_impl_->IsContextLost()) { | |
596 DidCommitAndDrawFrame(); | |
597 return DRAW_SUCCESS; | |
598 } | |
599 | |
600 LayerTreeHostImpl::FrameData frame; | |
601 return DoComposite(gfx::FrameTime::Now(), &frame); | |
602 } | |
603 | |
604 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { | |
605 NOTREACHED(); | |
606 return INVALID_RESULT; | |
607 } | |
608 | |
609 void SingleThreadProxy::ScheduledActionCommit() { | |
610 DebugScopedSetMainThread main(this); | |
611 DoCommit(gfx::FrameTime::Now()); | |
612 } | |
613 | |
614 void SingleThreadProxy::ScheduledActionAnimate() { | |
615 TRACE_EVENT0("cc", "ScheduledActionAnimate"); | |
616 layer_tree_host_impl_->Animate( | |
617 layer_tree_host_impl_->CurrentFrameTimeTicks()); | |
618 } | |
619 | |
620 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { | |
621 // Impl-side painting only. | |
622 NOTREACHED(); | |
623 } | |
624 | |
625 void SingleThreadProxy::ScheduledActionActivatePendingTree() { | |
626 // Impl-side painting only. | |
627 NOTREACHED(); | |
628 } | |
629 | |
630 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | |
631 DebugScopedSetMainThread main(this); | |
632 DCHECK(scheduler_on_impl_thread_); | |
633 // If possible, create the output surface in a post task. Synchronously | |
634 // creating the output surface makes tests more awkward since this differs | |
635 // from the ThreadProxy behavior. However, sometimes there is no | |
636 // task runner. | |
637 if (Proxy::MainThreadTaskRunner()) { | |
638 Proxy::MainThreadTaskRunner()->PostTask( | |
639 FROM_HERE, | |
640 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface, | |
641 weak_factory_.GetWeakPtr())); | |
642 } else { | |
643 CreateAndInitializeOutputSurface(); | |
644 } | |
645 } | |
646 | |
647 void SingleThreadProxy::ScheduledActionManageTiles() { | |
648 // Impl-side painting only. | |
649 NOTREACHED(); | |
650 } | |
651 | |
652 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | |
653 } | |
654 | |
655 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { | |
656 return timing_history_.DrawDurationEstimate(); | |
657 } | |
658 | |
659 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { | |
660 return timing_history_.BeginMainFrameToCommitDurationEstimate(); | |
661 } | |
662 | |
663 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { | |
664 return timing_history_.CommitToActivateDurationEstimate(); | |
665 } | |
666 | |
667 void SingleThreadProxy::DidBeginImplFrameDeadline() { | |
668 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
669 } | |
670 | |
475 } // namespace cc | 671 } // namespace cc |
OLD | NEW |