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" |
11 #include "cc/output/output_surface.h" | 11 #include "cc/output/output_surface.h" |
12 #include "cc/quads/draw_quad.h" | 12 #include "cc/quads/draw_quad.h" |
13 #include "cc/resources/prioritized_resource_manager.h" | 13 #include "cc/resources/prioritized_resource_manager.h" |
14 #include "cc/resources/resource_update_controller.h" | 14 #include "cc/resources/resource_update_controller.h" |
15 #include "cc/trees/blocking_task_runner.h" | |
16 #include "cc/trees/layer_tree_host.h" | 15 #include "cc/trees/layer_tree_host.h" |
17 #include "cc/trees/layer_tree_host_single_thread_client.h" | 16 #include "cc/trees/layer_tree_host_single_thread_client.h" |
18 #include "cc/trees/layer_tree_impl.h" | 17 #include "cc/trees/layer_tree_impl.h" |
19 #include "cc/trees/scoped_abort_remaining_swap_promises.h" | 18 #include "cc/trees/scoped_abort_remaining_swap_promises.h" |
20 #include "ui/gfx/frame_time.h" | 19 #include "ui/gfx/frame_time.h" |
21 | 20 |
22 namespace cc { | 21 namespace cc { |
23 | 22 |
24 scoped_ptr<Proxy> SingleThreadProxy::Create( | 23 scoped_ptr<Proxy> SingleThreadProxy::Create( |
25 LayerTreeHost* layer_tree_host, | 24 LayerTreeHost* layer_tree_host, |
(...skipping 13 matching lines...) Expand all Loading... |
39 timing_history_(layer_tree_host->rendering_stats_instrumentation()), | 38 timing_history_(layer_tree_host->rendering_stats_instrumentation()), |
40 next_frame_is_newly_committed_frame_(false), | 39 next_frame_is_newly_committed_frame_(false), |
41 inside_draw_(false), | 40 inside_draw_(false), |
42 defer_commits_(false), | 41 defer_commits_(false), |
43 commit_was_deferred_(false), | 42 commit_was_deferred_(false), |
44 commit_requested_(false), | 43 commit_requested_(false), |
45 weak_factory_(this) { | 44 weak_factory_(this) { |
46 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 45 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
47 DCHECK(Proxy::IsMainThread()); | 46 DCHECK(Proxy::IsMainThread()); |
48 DCHECK(layer_tree_host); | 47 DCHECK(layer_tree_host); |
49 | |
50 // Impl-side painting not supported without threaded compositing. | |
51 CHECK(!layer_tree_host->settings().impl_side_painting) | |
52 << "Threaded compositing must be enabled to use impl-side painting."; | |
53 } | 48 } |
54 | 49 |
55 void SingleThreadProxy::Start() { | 50 void SingleThreadProxy::Start() { |
56 DebugScopedSetImplThread impl(this); | 51 DebugScopedSetImplThread impl(this); |
57 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); | 52 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
58 } | 53 } |
59 | 54 |
60 SingleThreadProxy::~SingleThreadProxy() { | 55 SingleThreadProxy::~SingleThreadProxy() { |
61 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); | 56 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
62 DCHECK(Proxy::IsMainThread()); | 57 DCHECK(Proxy::IsMainThread()); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 client_->ScheduleAnimation(); | 147 client_->ScheduleAnimation(); |
153 SetNeedsCommit(); | 148 SetNeedsCommit(); |
154 } | 149 } |
155 | 150 |
156 void SingleThreadProxy::SetNeedsUpdateLayers() { | 151 void SingleThreadProxy::SetNeedsUpdateLayers() { |
157 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); | 152 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); |
158 DCHECK(Proxy::IsMainThread()); | 153 DCHECK(Proxy::IsMainThread()); |
159 SetNeedsCommit(); | 154 SetNeedsCommit(); |
160 } | 155 } |
161 | 156 |
162 void SingleThreadProxy::DoCommit(const BeginFrameArgs& begin_frame_args) { | 157 void SingleThreadProxy::DoCommit() { |
163 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); | 158 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
164 DCHECK(Proxy::IsMainThread()); | 159 DCHECK(Proxy::IsMainThread()); |
165 layer_tree_host_->WillBeginMainFrame(); | 160 |
166 layer_tree_host_->BeginMainFrame(begin_frame_args); | |
167 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); | |
168 layer_tree_host_->Layout(); | |
169 commit_requested_ = false; | 161 commit_requested_ = false; |
170 | |
171 if (PrioritizedResourceManager* contents_texture_manager = | |
172 layer_tree_host_->contents_texture_manager()) { | |
173 contents_texture_manager->UnlinkAndClearEvictedBackings(); | |
174 contents_texture_manager->SetMaxMemoryLimitBytes( | |
175 layer_tree_host_impl_->memory_allocation_limit_bytes()); | |
176 contents_texture_manager->SetExternalPriorityCutoff( | |
177 layer_tree_host_impl_->memory_allocation_priority_cutoff()); | |
178 } | |
179 | |
180 scoped_ptr<ResourceUpdateQueue> queue = | |
181 make_scoped_ptr(new ResourceUpdateQueue); | |
182 | |
183 layer_tree_host_->UpdateLayers(queue.get()); | |
184 | |
185 layer_tree_host_->WillCommit(); | 162 layer_tree_host_->WillCommit(); |
186 | 163 |
187 // Commit immediately. | 164 // Commit immediately. |
188 { | 165 { |
189 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 166 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
190 DebugScopedSetImplThread impl(this); | 167 DebugScopedSetImplThread impl(this); |
191 | 168 |
192 // This CapturePostTasks should be destroyed before CommitComplete() is | 169 // This CapturePostTasks should be destroyed before CommitComplete() is |
193 // called since that goes out to the embedder, and we want the embedder | 170 // called since that goes out to the embedder, and we want the embedder |
194 // to receive its callbacks before that. | 171 // to receive its callbacks before that. |
195 BlockingTaskRunner::CapturePostTasks blocked( | 172 commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks( |
196 blocking_main_thread_task_runner()); | 173 blocking_main_thread_task_runner())); |
197 | 174 |
198 layer_tree_host_impl_->BeginCommit(); | 175 layer_tree_host_impl_->BeginCommit(); |
199 | 176 |
200 if (PrioritizedResourceManager* contents_texture_manager = | 177 if (PrioritizedResourceManager* contents_texture_manager = |
201 layer_tree_host_->contents_texture_manager()) { | 178 layer_tree_host_->contents_texture_manager()) { |
202 contents_texture_manager->PushTexturePrioritiesToBackings(); | 179 contents_texture_manager->PushTexturePrioritiesToBackings(); |
203 } | 180 } |
204 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); | 181 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); |
205 | 182 |
206 scoped_ptr<ResourceUpdateController> update_controller = | 183 scoped_ptr<ResourceUpdateController> update_controller = |
207 ResourceUpdateController::Create( | 184 ResourceUpdateController::Create( |
208 NULL, | 185 NULL, |
209 MainThreadTaskRunner(), | 186 MainThreadTaskRunner(), |
210 queue.Pass(), | 187 queue_for_commit_.Pass(), |
211 layer_tree_host_impl_->resource_provider()); | 188 layer_tree_host_impl_->resource_provider()); |
212 update_controller->Finalize(); | 189 update_controller->Finalize(); |
213 | 190 |
214 if (layer_tree_host_impl_->EvictedUIResourcesExist()) | 191 if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
215 layer_tree_host_->RecreateUIResources(); | 192 layer_tree_host_->RecreateUIResources(); |
216 | 193 |
217 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); | 194 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
218 | 195 |
219 layer_tree_host_impl_->CommitComplete(); | 196 layer_tree_host_impl_->CommitComplete(); |
220 | 197 |
221 UpdateBackgroundAnimateTicking(); | 198 UpdateBackgroundAnimateTicking(); |
222 | 199 |
223 #if DCHECK_IS_ON | 200 #if DCHECK_IS_ON |
224 // In the single-threaded case, the scale and scroll deltas should never be | 201 // In the single-threaded case, the scale and scroll deltas should never be |
225 // touched on the impl layer tree. | 202 // touched on the impl layer tree. |
226 scoped_ptr<ScrollAndScaleSet> scroll_info = | 203 scoped_ptr<ScrollAndScaleSet> scroll_info = |
227 layer_tree_host_impl_->ProcessScrollDeltas(); | 204 layer_tree_host_impl_->ProcessScrollDeltas(); |
228 DCHECK(!scroll_info->scrolls.size()); | 205 DCHECK(!scroll_info->scrolls.size()); |
229 DCHECK_EQ(1.f, scroll_info->page_scale_delta); | 206 DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
230 #endif | 207 #endif |
231 | 208 |
232 RenderingStatsInstrumentation* stats_instrumentation = | 209 RenderingStatsInstrumentation* stats_instrumentation = |
233 layer_tree_host_->rendering_stats_instrumentation(); | 210 layer_tree_host_->rendering_stats_instrumentation(); |
234 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent( | 211 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent( |
235 stats_instrumentation->main_thread_rendering_stats()); | 212 stats_instrumentation->main_thread_rendering_stats()); |
236 stats_instrumentation->AccumulateAndClearMainThreadStats(); | 213 stats_instrumentation->AccumulateAndClearMainThreadStats(); |
237 } | 214 } |
| 215 |
| 216 if (layer_tree_host_->settings().impl_side_painting) { |
| 217 // TODO(enne): just commit directly to the active tree. |
| 218 // |
| 219 // Synchronously activate during commit to satisfy any potential |
| 220 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree |
| 221 // might not be ready to draw, so DidActivateSyncTree must set |
| 222 // the flag to force the tree to not draw until textures are ready. |
| 223 NotifyReadyToActivate(); |
| 224 } else { |
| 225 CommitComplete(); |
| 226 } |
| 227 } |
| 228 |
| 229 void SingleThreadProxy::CommitComplete() { |
| 230 DCHECK(!layer_tree_host_impl_->pending_tree()) |
| 231 << "Activation is expected to have synchronously occurred by now."; |
| 232 DCHECK(commit_blocking_task_runner_); |
| 233 |
| 234 DebugScopedSetMainThread main(this); |
| 235 commit_blocking_task_runner_.reset(); |
238 layer_tree_host_->CommitComplete(); | 236 layer_tree_host_->CommitComplete(); |
239 layer_tree_host_->DidBeginMainFrame(); | 237 layer_tree_host_->DidBeginMainFrame(); |
240 timing_history_.DidCommit(); | 238 timing_history_.DidCommit(); |
241 | 239 |
242 next_frame_is_newly_committed_frame_ = true; | 240 next_frame_is_newly_committed_frame_ = true; |
243 } | 241 } |
244 | 242 |
245 void SingleThreadProxy::SetNeedsCommit() { | 243 void SingleThreadProxy::SetNeedsCommit() { |
246 DCHECK(Proxy::IsMainThread()); | 244 DCHECK(Proxy::IsMainThread()); |
247 DebugScopedSetImplThread impl(this); | 245 DebugScopedSetImplThread impl(this); |
248 client_->ScheduleComposite(); | 246 client_->ScheduleComposite(); |
249 if (scheduler_on_impl_thread_) | 247 if (scheduler_on_impl_thread_) |
250 scheduler_on_impl_thread_->SetNeedsCommit(); | 248 scheduler_on_impl_thread_->SetNeedsCommit(); |
251 commit_requested_ = true; | 249 commit_requested_ = true; |
252 } | 250 } |
253 | 251 |
254 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { | 252 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
255 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); | 253 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); |
256 DCHECK(Proxy::IsMainThread()); | 254 DCHECK(Proxy::IsMainThread()); |
257 DebugScopedSetImplThread impl(this); | 255 DebugScopedSetImplThread impl(this); |
258 client_->ScheduleComposite(); | 256 client_->ScheduleComposite(); |
259 SetNeedsRedrawRectOnImplThread(damage_rect); | 257 SetNeedsRedrawRectOnImplThread(damage_rect); |
260 } | 258 } |
261 | 259 |
262 void SingleThreadProxy::SetNextCommitWaitsForActivation() { | 260 void SingleThreadProxy::SetNextCommitWaitsForActivation() { |
263 // There is no activation here other than commit. So do nothing. | 261 // Activation always forced in commit, so nothing to do. |
264 DCHECK(Proxy::IsMainThread()); | 262 DCHECK(Proxy::IsMainThread()); |
265 } | 263 } |
266 | 264 |
267 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { | 265 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
268 DCHECK(Proxy::IsMainThread()); | 266 DCHECK(Proxy::IsMainThread()); |
269 // Deferring commits only makes sense if there's a scheduler. | 267 // Deferring commits only makes sense if there's a scheduler. |
270 if (!scheduler_on_impl_thread_) | 268 if (!scheduler_on_impl_thread_) |
271 return; | 269 return; |
272 if (defer_commits_ == defer_commits) | 270 if (defer_commits_ == defer_commits) |
273 return; | 271 return; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 320 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
323 TRACE_EVENT1( | 321 TRACE_EVENT1( |
324 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 322 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
325 DCHECK(Proxy::IsImplThread()); | 323 DCHECK(Proxy::IsImplThread()); |
326 UpdateBackgroundAnimateTicking(); | 324 UpdateBackgroundAnimateTicking(); |
327 if (scheduler_on_impl_thread_) | 325 if (scheduler_on_impl_thread_) |
328 scheduler_on_impl_thread_->SetCanDraw(can_draw); | 326 scheduler_on_impl_thread_->SetCanDraw(can_draw); |
329 } | 327 } |
330 | 328 |
331 void SingleThreadProxy::NotifyReadyToActivate() { | 329 void SingleThreadProxy::NotifyReadyToActivate() { |
332 // Impl-side painting only. | 330 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate"); |
333 NOTREACHED(); | 331 DebugScopedSetImplThread impl(this); |
| 332 if (scheduler_on_impl_thread_) |
| 333 scheduler_on_impl_thread_->NotifyReadyToActivate(); |
334 } | 334 } |
335 | 335 |
336 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { | 336 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
337 client_->ScheduleComposite(); | 337 client_->ScheduleComposite(); |
338 if (scheduler_on_impl_thread_) | 338 if (scheduler_on_impl_thread_) |
339 scheduler_on_impl_thread_->SetNeedsRedraw(); | 339 scheduler_on_impl_thread_->SetNeedsRedraw(); |
340 } | 340 } |
341 | 341 |
342 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { | 342 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
343 SetNeedsRedrawOnImplThread(); | 343 SetNeedsRedrawOnImplThread(); |
344 } | 344 } |
345 | 345 |
346 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { | 346 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
347 // Impl-side painting only. | 347 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsManageTilesOnImplThread"); |
348 NOTREACHED(); | 348 if (scheduler_on_impl_thread_) |
| 349 scheduler_on_impl_thread_->SetNeedsManageTiles(); |
349 } | 350 } |
350 | 351 |
351 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( | 352 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
352 const gfx::Rect& damage_rect) { | 353 const gfx::Rect& damage_rect) { |
353 layer_tree_host_impl_->SetViewportDamage(damage_rect); | 354 layer_tree_host_impl_->SetViewportDamage(damage_rect); |
354 SetNeedsRedrawOnImplThread(); | 355 SetNeedsRedrawOnImplThread(); |
355 } | 356 } |
356 | 357 |
357 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { | 358 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
358 // Impl-side painting only. | 359 TRACE_EVENT0("cc", "SingleThreadProxy::DidInitializeVisibleTileOnImplThread"); |
359 NOTREACHED(); | 360 if (scheduler_on_impl_thread_) |
| 361 scheduler_on_impl_thread_->SetNeedsRedraw(); |
360 } | 362 } |
361 | 363 |
362 void SingleThreadProxy::SetNeedsCommitOnImplThread() { | 364 void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
363 client_->ScheduleComposite(); | 365 client_->ScheduleComposite(); |
364 if (scheduler_on_impl_thread_) | 366 if (scheduler_on_impl_thread_) |
365 scheduler_on_impl_thread_->SetNeedsCommit(); | 367 scheduler_on_impl_thread_->SetNeedsCommit(); |
366 } | 368 } |
367 | 369 |
368 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 370 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
369 scoped_ptr<AnimationEventsVector> events) { | 371 scoped_ptr<AnimationEventsVector> events) { |
(...skipping 16 matching lines...) Expand all Loading... |
386 | 388 |
387 if (!contents_texture_manager || !resource_provider) | 389 if (!contents_texture_manager || !resource_provider) |
388 return false; | 390 return false; |
389 | 391 |
390 return contents_texture_manager->ReduceMemoryOnImplThread( | 392 return contents_texture_manager->ReduceMemoryOnImplThread( |
391 limit_bytes, priority_cutoff, resource_provider); | 393 limit_bytes, priority_cutoff, resource_provider); |
392 } | 394 } |
393 | 395 |
394 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } | 396 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
395 | 397 |
| 398 void SingleThreadProxy::DidActivateSyncTree() { |
| 399 // Non-impl-side painting finishes commit in DoCommit. Impl-side painting |
| 400 // defers until here to simulate SetNextCommitWaitsForActivation. |
| 401 if (layer_tree_host_impl_->settings().impl_side_painting) { |
| 402 // This is required because NotifyReadyToActivate gets called when |
| 403 // the pending tree is not actually ready in the SingleThreadProxy. |
| 404 layer_tree_host_impl_->SetRequiresHighResToDraw(); |
| 405 |
| 406 // Since activation could cause tasks to run, post CommitComplete |
| 407 // separately so that it runs after these tasks. This is the loose |
| 408 // equivalent of blocking commit until activation and also running |
| 409 // all tasks posted during commit/activation before CommitComplete. |
| 410 MainThreadTaskRunner()->PostTask( |
| 411 FROM_HERE, |
| 412 base::Bind(&SingleThreadProxy::CommitComplete, |
| 413 weak_factory_.GetWeakPtr())); |
| 414 } |
| 415 |
| 416 UpdateBackgroundAnimateTicking(); |
| 417 timing_history_.DidActivateSyncTree(); |
| 418 } |
| 419 |
| 420 void SingleThreadProxy::DidManageTiles() { |
| 421 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
| 422 DCHECK(Proxy::IsImplThread()); |
| 423 if (scheduler_on_impl_thread_) |
| 424 scheduler_on_impl_thread_->DidManageTiles(); |
| 425 } |
| 426 |
396 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { | 427 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
397 DCHECK(IsImplThread()); | 428 DCHECK(IsImplThread()); |
398 renderer_capabilities_for_main_thread_ = | 429 renderer_capabilities_for_main_thread_ = |
399 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); | 430 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); |
400 } | 431 } |
401 | 432 |
402 void SingleThreadProxy::DidManageTiles() { | |
403 // Impl-side painting only. | |
404 NOTREACHED(); | |
405 } | |
406 | |
407 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 433 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
408 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 434 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
409 { | 435 { |
410 DebugScopedSetMainThread main(this); | 436 DebugScopedSetMainThread main(this); |
411 // This must happen before we notify the scheduler as it may try to recreate | 437 // This must happen before we notify the scheduler as it may try to recreate |
412 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. | 438 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. |
413 layer_tree_host_->DidLoseOutputSurface(); | 439 layer_tree_host_->DidLoseOutputSurface(); |
414 } | 440 } |
415 client_->DidAbortSwapBuffers(); | 441 client_->DidAbortSwapBuffers(); |
416 if (scheduler_on_impl_thread_) | 442 if (scheduler_on_impl_thread_) |
(...skipping 11 matching lines...) Expand all Loading... |
428 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); | 454 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
429 if (scheduler_on_impl_thread_) | 455 if (scheduler_on_impl_thread_) |
430 scheduler_on_impl_thread_->DidSwapBuffersComplete(); | 456 scheduler_on_impl_thread_->DidSwapBuffersComplete(); |
431 layer_tree_host_->DidCompleteSwapBuffers(); | 457 layer_tree_host_->DidCompleteSwapBuffers(); |
432 } | 458 } |
433 | 459 |
434 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 460 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
435 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); | 461 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); |
436 DCHECK(Proxy::IsMainThread()); | 462 DCHECK(Proxy::IsMainThread()); |
437 DCHECK(!layer_tree_host_->output_surface_lost()); | 463 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 464 DCHECK(!layer_tree_host_impl_->settings().impl_side_painting) |
| 465 << "Impl-side painting and synchronous compositing are not supported."; |
438 | 466 |
439 BeginFrameArgs begin_frame_args = BeginFrameArgs::Create( | 467 { |
440 frame_begin_time, base::TimeTicks(), BeginFrameArgs::DefaultInterval()); | 468 BeginFrameArgs begin_frame_args( |
441 DoCommit(begin_frame_args); | 469 BeginFrameArgs::Create(frame_begin_time, |
| 470 base::TimeTicks(), |
| 471 BeginFrameArgs::DefaultInterval())); |
| 472 DoBeginMainFrame(begin_frame_args); |
| 473 DoCommit(); |
442 | 474 |
443 LayerTreeHostImpl::FrameData frame; | 475 DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises()) |
444 DoComposite(frame_begin_time, &frame); | 476 << "Commit should always succeed and transfer promises."; |
| 477 } |
| 478 |
| 479 { |
| 480 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
| 481 LayerTreeHostImpl::FrameData frame; |
| 482 DoComposite(frame_begin_time, &frame); |
| 483 |
| 484 // DoComposite could abort, but because this is a synchronous composite |
| 485 // another draw will never be scheduled, so break remaining promises. |
| 486 layer_tree_host_impl_->active_tree()->BreakSwapPromises( |
| 487 SwapPromise::SWAP_FAILS); |
| 488 } |
445 } | 489 } |
446 | 490 |
447 void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const { | 491 void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const { |
448 // The following line casts away const modifiers because it is just | 492 // The following line casts away const modifiers because it is just |
449 // setting debug state. We still want the AsValue() function and its | 493 // setting debug state. We still want the AsValue() function and its |
450 // call chain to be const throughout. | 494 // call chain to be const throughout. |
451 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); | 495 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
452 | 496 |
453 state->BeginDictionary("layer_tree_host_impl"); | 497 state->BeginDictionary("layer_tree_host_impl"); |
454 layer_tree_host_impl_->AsValueInto(state); | 498 layer_tree_host_impl_->AsValueInto(state); |
(...skipping 24 matching lines...) Expand all Loading... |
479 DCHECK(Proxy::IsImplThread()); | 523 DCHECK(Proxy::IsImplThread()); |
480 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | 524 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( |
481 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); | 525 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); |
482 } | 526 } |
483 | 527 |
484 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, | 528 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
485 LayerTreeHostImpl::FrameData* frame) { | 529 LayerTreeHostImpl::FrameData* frame) { |
486 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 530 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
487 DCHECK(!layer_tree_host_->output_surface_lost()); | 531 DCHECK(!layer_tree_host_->output_surface_lost()); |
488 | 532 |
| 533 DrawResult draw_result; |
| 534 bool draw_frame; |
489 { | 535 { |
490 DebugScopedSetImplThread impl(this); | 536 DebugScopedSetImplThread impl(this); |
491 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 537 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
492 | 538 |
493 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 539 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
494 // frame, so can only be used when such a frame is possible. Since | 540 // frame, so can only be used when such a frame is possible. Since |
495 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 541 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
496 // CanDraw() as well. | 542 // CanDraw() as well. |
497 if (!ShouldComposite()) { | 543 if (!ShouldComposite()) { |
498 UpdateBackgroundAnimateTicking(); | 544 UpdateBackgroundAnimateTicking(); |
499 return DRAW_ABORTED_CANT_DRAW; | 545 return DRAW_ABORTED_CANT_DRAW; |
500 } | 546 } |
501 | 547 |
502 timing_history_.DidStartDrawing(); | 548 timing_history_.DidStartDrawing(); |
503 | 549 |
504 layer_tree_host_impl_->Animate( | 550 layer_tree_host_impl_->Animate( |
505 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); | 551 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); |
506 UpdateBackgroundAnimateTicking(); | 552 UpdateBackgroundAnimateTicking(); |
507 | 553 |
508 layer_tree_host_impl_->PrepareToDraw(frame); | 554 draw_result = layer_tree_host_impl_->PrepareToDraw(frame); |
509 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); | 555 draw_frame = draw_result == DRAW_SUCCESS; |
| 556 if (draw_frame) |
| 557 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
510 layer_tree_host_impl_->DidDrawAllLayers(*frame); | 558 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
511 | 559 |
512 bool start_ready_animations = true; | 560 bool start_ready_animations = draw_frame; |
513 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 561 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
514 | |
515 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 562 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
516 | 563 |
517 timing_history_.DidFinishDrawing(); | 564 timing_history_.DidFinishDrawing(); |
518 } | 565 } |
519 | 566 |
520 { | 567 if (draw_frame) { |
521 DebugScopedSetImplThread impl(this); | 568 DebugScopedSetImplThread impl(this); |
522 | 569 |
523 // This CapturePostTasks should be destroyed before | 570 // This CapturePostTasks should be destroyed before |
524 // DidCommitAndDrawFrame() is called since that goes out to the | 571 // DidCommitAndDrawFrame() is called since that goes out to the |
525 // embedder, | 572 // embedder, |
526 // and we want the embedder to receive its callbacks before that. | 573 // and we want the embedder to receive its callbacks before that. |
527 // NOTE: This maintains consistent ordering with the ThreadProxy since | 574 // NOTE: This maintains consistent ordering with the ThreadProxy since |
528 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread | 575 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread |
529 // there as the main thread is not blocked, so any posted tasks inside | 576 // there as the main thread is not blocked, so any posted tasks inside |
530 // the swap buffers will execute first. | 577 // the swap buffers will execute first. |
531 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 578 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
532 | 579 |
533 BlockingTaskRunner::CapturePostTasks blocked( | 580 BlockingTaskRunner::CapturePostTasks blocked( |
534 blocking_main_thread_task_runner()); | 581 blocking_main_thread_task_runner()); |
535 layer_tree_host_impl_->SwapBuffers(*frame); | 582 layer_tree_host_impl_->SwapBuffers(*frame); |
536 } | 583 } |
537 DidCommitAndDrawFrame(); | 584 DidCommitAndDrawFrame(); |
538 | 585 |
539 return DRAW_SUCCESS; | 586 return draw_result; |
540 } | 587 } |
541 | 588 |
542 void SingleThreadProxy::DidCommitAndDrawFrame() { | 589 void SingleThreadProxy::DidCommitAndDrawFrame() { |
543 if (next_frame_is_newly_committed_frame_) { | 590 if (next_frame_is_newly_committed_frame_) { |
544 DebugScopedSetMainThread main(this); | 591 DebugScopedSetMainThread main(this); |
545 next_frame_is_newly_committed_frame_ = false; | 592 next_frame_is_newly_committed_frame_ = false; |
546 layer_tree_host_->DidCommitAndDrawFrame(); | 593 layer_tree_host_->DidCommitAndDrawFrame(); |
547 } | 594 } |
548 } | 595 } |
549 | 596 |
(...skipping 25 matching lines...) Expand all Loading... |
575 } | 622 } |
576 | 623 |
577 void SingleThreadProxy::BeginMainFrame() { | 624 void SingleThreadProxy::BeginMainFrame() { |
578 if (defer_commits_) { | 625 if (defer_commits_) { |
579 DCHECK(!commit_was_deferred_); | 626 DCHECK(!commit_was_deferred_); |
580 commit_was_deferred_ = true; | 627 commit_was_deferred_ = true; |
581 layer_tree_host_->DidDeferCommit(); | 628 layer_tree_host_->DidDeferCommit(); |
582 return; | 629 return; |
583 } | 630 } |
584 | 631 |
585 // This checker assumes NotifyReadyToCommit below causes a synchronous commit. | 632 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous |
| 633 // commit. |
586 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); | 634 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); |
587 | 635 |
588 if (!layer_tree_host_->visible()) { | 636 if (!layer_tree_host_->visible()) { |
589 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); | 637 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
590 BeginMainFrameAbortedOnImplThread(); | 638 BeginMainFrameAbortedOnImplThread(); |
591 return; | 639 return; |
592 } | 640 } |
593 | 641 |
594 if (layer_tree_host_->output_surface_lost()) { | 642 if (layer_tree_host_->output_surface_lost()) { |
595 TRACE_EVENT_INSTANT0( | 643 TRACE_EVENT_INSTANT0( |
596 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); | 644 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); |
597 BeginMainFrameAbortedOnImplThread(); | 645 BeginMainFrameAbortedOnImplThread(); |
598 return; | 646 return; |
599 } | 647 } |
600 | 648 |
| 649 const BeginFrameArgs& begin_frame_args = |
| 650 layer_tree_host_impl_->CurrentBeginFrameArgs(); |
| 651 DoBeginMainFrame(begin_frame_args); |
| 652 } |
| 653 |
| 654 void SingleThreadProxy::DoBeginMainFrame( |
| 655 const BeginFrameArgs& begin_frame_args) { |
| 656 layer_tree_host_->WillBeginMainFrame(); |
| 657 layer_tree_host_->BeginMainFrame(begin_frame_args); |
| 658 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); |
| 659 layer_tree_host_->Layout(); |
| 660 |
| 661 if (PrioritizedResourceManager* contents_texture_manager = |
| 662 layer_tree_host_->contents_texture_manager()) { |
| 663 contents_texture_manager->UnlinkAndClearEvictedBackings(); |
| 664 contents_texture_manager->SetMaxMemoryLimitBytes( |
| 665 layer_tree_host_impl_->memory_allocation_limit_bytes()); |
| 666 contents_texture_manager->SetExternalPriorityCutoff( |
| 667 layer_tree_host_impl_->memory_allocation_priority_cutoff()); |
| 668 } |
| 669 |
| 670 DCHECK(!queue_for_commit_); |
| 671 queue_for_commit_ = make_scoped_ptr(new ResourceUpdateQueue); |
| 672 |
| 673 layer_tree_host_->UpdateLayers(queue_for_commit_.get()); |
| 674 |
601 timing_history_.DidBeginMainFrame(); | 675 timing_history_.DidBeginMainFrame(); |
602 | 676 |
603 DCHECK(scheduler_on_impl_thread_); | 677 if (scheduler_on_impl_thread_) { |
604 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | 678 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); |
605 scheduler_on_impl_thread_->NotifyReadyToCommit(); | 679 scheduler_on_impl_thread_->NotifyReadyToCommit(); |
| 680 } |
606 } | 681 } |
607 | 682 |
608 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread() { | 683 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread() { |
609 DebugScopedSetImplThread impl(this); | 684 DebugScopedSetImplThread impl(this); |
610 DCHECK(scheduler_on_impl_thread_->CommitPending()); | 685 DCHECK(scheduler_on_impl_thread_->CommitPending()); |
611 DCHECK(!layer_tree_host_impl_->pending_tree()); | 686 DCHECK(!layer_tree_host_impl_->pending_tree()); |
612 | 687 |
613 // TODO(enne): SingleThreadProxy does not support cancelling commits yet so | 688 // TODO(enne): SingleThreadProxy does not support cancelling commits yet so |
614 // did_handle is always false. | 689 // did_handle is always false. |
615 bool did_handle = false; | 690 bool did_handle = false; |
616 layer_tree_host_impl_->BeginMainFrameAborted(did_handle); | 691 layer_tree_host_impl_->BeginMainFrameAborted(did_handle); |
617 scheduler_on_impl_thread_->BeginMainFrameAborted(did_handle); | 692 scheduler_on_impl_thread_->BeginMainFrameAborted(did_handle); |
618 } | 693 } |
619 | 694 |
620 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { | 695 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { |
621 DebugScopedSetImplThread impl(this); | 696 DebugScopedSetImplThread impl(this); |
622 LayerTreeHostImpl::FrameData frame; | 697 LayerTreeHostImpl::FrameData frame; |
623 return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time, | 698 return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time, |
624 &frame); | 699 &frame); |
625 } | 700 } |
626 | 701 |
627 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { | 702 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { |
628 NOTREACHED(); | 703 NOTREACHED(); |
629 return INVALID_RESULT; | 704 return INVALID_RESULT; |
630 } | 705 } |
631 | 706 |
632 void SingleThreadProxy::ScheduledActionCommit() { | 707 void SingleThreadProxy::ScheduledActionCommit() { |
633 DebugScopedSetMainThread main(this); | 708 DebugScopedSetMainThread main(this); |
634 DoCommit(layer_tree_host_impl_->CurrentBeginFrameArgs()); | 709 DoCommit(); |
635 } | 710 } |
636 | 711 |
637 void SingleThreadProxy::ScheduledActionAnimate() { | 712 void SingleThreadProxy::ScheduledActionAnimate() { |
638 TRACE_EVENT0("cc", "ScheduledActionAnimate"); | 713 TRACE_EVENT0("cc", "ScheduledActionAnimate"); |
639 layer_tree_host_impl_->Animate( | 714 layer_tree_host_impl_->Animate( |
640 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); | 715 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); |
641 } | 716 } |
642 | 717 |
643 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { | 718 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { |
644 // Impl-side painting only. | 719 DebugScopedSetImplThread impl(this); |
645 NOTREACHED(); | 720 layer_tree_host_impl_->UpdateVisibleTiles(); |
646 } | 721 } |
647 | 722 |
648 void SingleThreadProxy::ScheduledActionActivateSyncTree() { | 723 void SingleThreadProxy::ScheduledActionActivateSyncTree() { |
| 724 DebugScopedSetImplThread impl(this); |
| 725 layer_tree_host_impl_->ActivateSyncTree(); |
649 } | 726 } |
650 | 727 |
651 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | 728 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
652 DebugScopedSetMainThread main(this); | 729 DebugScopedSetMainThread main(this); |
653 DCHECK(scheduler_on_impl_thread_); | 730 DCHECK(scheduler_on_impl_thread_); |
654 // If possible, create the output surface in a post task. Synchronously | 731 // If possible, create the output surface in a post task. Synchronously |
655 // creating the output surface makes tests more awkward since this differs | 732 // creating the output surface makes tests more awkward since this differs |
656 // from the ThreadProxy behavior. However, sometimes there is no | 733 // from the ThreadProxy behavior. However, sometimes there is no |
657 // task runner. | 734 // task runner. |
658 if (Proxy::MainThreadTaskRunner()) { | 735 if (Proxy::MainThreadTaskRunner()) { |
659 MainThreadTaskRunner()->PostTask( | 736 MainThreadTaskRunner()->PostTask( |
660 FROM_HERE, | 737 FROM_HERE, |
661 base::Bind(&SingleThreadProxy::RequestNewOutputSurface, | 738 base::Bind(&SingleThreadProxy::RequestNewOutputSurface, |
662 weak_factory_.GetWeakPtr())); | 739 weak_factory_.GetWeakPtr())); |
663 } else { | 740 } else { |
664 RequestNewOutputSurface(); | 741 RequestNewOutputSurface(); |
665 } | 742 } |
666 } | 743 } |
667 | 744 |
668 void SingleThreadProxy::ScheduledActionManageTiles() { | 745 void SingleThreadProxy::ScheduledActionManageTiles() { |
669 // Impl-side painting only. | 746 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionManageTiles"); |
670 NOTREACHED(); | 747 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
| 748 DebugScopedSetImplThread impl(this); |
| 749 layer_tree_host_impl_->ManageTiles(); |
671 } | 750 } |
672 | 751 |
673 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | 752 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
674 } | 753 } |
675 | 754 |
676 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { | 755 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { |
677 return timing_history_.DrawDurationEstimate(); | 756 return timing_history_.DrawDurationEstimate(); |
678 } | 757 } |
679 | 758 |
680 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { | 759 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { |
681 return timing_history_.BeginMainFrameToCommitDurationEstimate(); | 760 return timing_history_.BeginMainFrameToCommitDurationEstimate(); |
682 } | 761 } |
683 | 762 |
684 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { | 763 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { |
685 return timing_history_.CommitToActivateDurationEstimate(); | 764 return timing_history_.CommitToActivateDurationEstimate(); |
686 } | 765 } |
687 | 766 |
688 void SingleThreadProxy::DidBeginImplFrameDeadline() { | 767 void SingleThreadProxy::DidBeginImplFrameDeadline() { |
689 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 768 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
690 } | 769 } |
691 | 770 |
692 } // namespace cc | 771 } // namespace cc |
OLD | NEW |