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 14 matching lines...) Expand all Loading... |
25 LayerTreeHostSingleThreadClient* client) { | 25 LayerTreeHostSingleThreadClient* client) { |
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 created_offscreen_context_provider_(false), | |
36 next_frame_is_newly_committed_frame_(false), | 35 next_frame_is_newly_committed_frame_(false), |
37 inside_draw_(false) { | 36 inside_draw_(false) { |
38 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 37 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
39 DCHECK(Proxy::IsMainThread()); | 38 DCHECK(Proxy::IsMainThread()); |
40 DCHECK(layer_tree_host); | 39 DCHECK(layer_tree_host); |
41 | 40 |
42 // Impl-side painting not supported without threaded compositing. | 41 // Impl-side painting not supported without threaded compositing. |
43 CHECK(!layer_tree_host->settings().impl_side_painting) | 42 CHECK(!layer_tree_host->settings().impl_side_painting) |
44 << "Threaded compositing must be enabled to use impl-side painting."; | 43 << "Threaded compositing must be enabled to use impl-side painting."; |
45 } | 44 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); | 114 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); |
116 DCHECK(Proxy::IsMainThread()); | 115 DCHECK(Proxy::IsMainThread()); |
117 | 116 |
118 scoped_ptr<OutputSurface> output_surface = | 117 scoped_ptr<OutputSurface> output_surface = |
119 layer_tree_host_->CreateOutputSurface(); | 118 layer_tree_host_->CreateOutputSurface(); |
120 if (!output_surface) { | 119 if (!output_surface) { |
121 OnOutputSurfaceInitializeAttempted(false); | 120 OnOutputSurfaceInitializeAttempted(false); |
122 return; | 121 return; |
123 } | 122 } |
124 | 123 |
125 scoped_refptr<ContextProvider> offscreen_context_provider; | |
126 if (created_offscreen_context_provider_) { | |
127 offscreen_context_provider = | |
128 layer_tree_host_->client()->OffscreenContextProvider(); | |
129 if (!offscreen_context_provider.get() || | |
130 !offscreen_context_provider->BindToCurrentThread()) { | |
131 OnOutputSurfaceInitializeAttempted(false); | |
132 return; | |
133 } | |
134 } | |
135 | |
136 { | 124 { |
137 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 125 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
138 DebugScopedSetImplThread impl(this); | 126 DebugScopedSetImplThread impl(this); |
139 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 127 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
140 layer_tree_host_impl_->resource_provider()); | 128 layer_tree_host_impl_->resource_provider()); |
141 } | 129 } |
142 | 130 |
143 bool initialized; | 131 bool initialized; |
144 { | 132 { |
145 DebugScopedSetImplThread impl(this); | 133 DebugScopedSetImplThread impl(this); |
146 | 134 |
147 DCHECK(output_surface); | 135 DCHECK(output_surface); |
148 initialized = layer_tree_host_impl_->InitializeRenderer( | 136 initialized = layer_tree_host_impl_->InitializeRenderer( |
149 output_surface.Pass()); | 137 output_surface.Pass()); |
150 if (!initialized && offscreen_context_provider.get()) { | |
151 offscreen_context_provider->VerifyContexts(); | |
152 offscreen_context_provider = NULL; | |
153 } | |
154 | |
155 layer_tree_host_impl_->SetOffscreenContextProvider( | |
156 offscreen_context_provider); | |
157 } | 138 } |
158 | 139 |
159 OnOutputSurfaceInitializeAttempted(initialized); | 140 OnOutputSurfaceInitializeAttempted(initialized); |
160 } | 141 } |
161 | 142 |
162 void SingleThreadProxy::OnOutputSurfaceInitializeAttempted(bool success) { | 143 void SingleThreadProxy::OnOutputSurfaceInitializeAttempted(bool success) { |
163 LayerTreeHost::CreateResult result = | 144 LayerTreeHost::CreateResult result = |
164 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); | 145 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
165 if (result == LayerTreeHost::CreateFailedButTryAgain) { | 146 if (result == LayerTreeHost::CreateFailedButTryAgain) { |
166 // Force another recreation attempt to happen by requesting another commit. | 147 // Force another recreation attempt to happen by requesting another commit. |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 contents_texture_manager->SetExternalPriorityCutoff( | 443 contents_texture_manager->SetExternalPriorityCutoff( |
463 layer_tree_host_impl_->memory_allocation_priority_cutoff()); | 444 layer_tree_host_impl_->memory_allocation_priority_cutoff()); |
464 } | 445 } |
465 | 446 |
466 scoped_ptr<ResourceUpdateQueue> queue = | 447 scoped_ptr<ResourceUpdateQueue> queue = |
467 make_scoped_ptr(new ResourceUpdateQueue); | 448 make_scoped_ptr(new ResourceUpdateQueue); |
468 layer_tree_host_->UpdateLayers(queue.get()); | 449 layer_tree_host_->UpdateLayers(queue.get()); |
469 | 450 |
470 layer_tree_host_->WillCommit(); | 451 layer_tree_host_->WillCommit(); |
471 | 452 |
472 scoped_refptr<ContextProvider> offscreen_context_provider; | |
473 if (renderer_capabilities_for_main_thread_.using_offscreen_context3d && | |
474 layer_tree_host_->needs_offscreen_context()) { | |
475 offscreen_context_provider = | |
476 layer_tree_host_->client()->OffscreenContextProvider(); | |
477 if (offscreen_context_provider.get() && | |
478 !offscreen_context_provider->BindToCurrentThread()) | |
479 offscreen_context_provider = NULL; | |
480 | |
481 if (offscreen_context_provider.get()) | |
482 created_offscreen_context_provider_ = true; | |
483 } | |
484 | |
485 DoCommit(queue.Pass()); | 453 DoCommit(queue.Pass()); |
486 bool result = DoComposite(offscreen_context_provider, | 454 bool result = DoComposite( |
487 frame_begin_time, | 455 frame_begin_time, device_viewport_damage_rect, for_readback, frame); |
488 device_viewport_damage_rect, | |
489 for_readback, | |
490 frame); | |
491 layer_tree_host_->DidBeginMainFrame(); | 456 layer_tree_host_->DidBeginMainFrame(); |
492 return result; | 457 return result; |
493 } | 458 } |
494 | 459 |
495 bool SingleThreadProxy::ShouldComposite() const { | 460 bool SingleThreadProxy::ShouldComposite() const { |
496 DCHECK(Proxy::IsImplThread()); | 461 DCHECK(Proxy::IsImplThread()); |
497 return layer_tree_host_impl_->visible() && | 462 return layer_tree_host_impl_->visible() && |
498 layer_tree_host_impl_->CanDraw(); | 463 layer_tree_host_impl_->CanDraw(); |
499 } | 464 } |
500 | 465 |
501 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { | 466 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { |
502 DCHECK(Proxy::IsImplThread()); | 467 DCHECK(Proxy::IsImplThread()); |
503 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | 468 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( |
504 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); | 469 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); |
505 } | 470 } |
506 | 471 |
507 bool SingleThreadProxy::DoComposite( | 472 bool SingleThreadProxy::DoComposite( |
508 scoped_refptr<ContextProvider> offscreen_context_provider, | |
509 base::TimeTicks frame_begin_time, | 473 base::TimeTicks frame_begin_time, |
510 const gfx::Rect& device_viewport_damage_rect, | 474 const gfx::Rect& device_viewport_damage_rect, |
511 bool for_readback, | 475 bool for_readback, |
512 LayerTreeHostImpl::FrameData* frame) { | 476 LayerTreeHostImpl::FrameData* frame) { |
513 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 477 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
514 DCHECK(!layer_tree_host_->output_surface_lost()); | 478 DCHECK(!layer_tree_host_->output_surface_lost()); |
515 | 479 |
516 bool lost_output_surface = false; | 480 bool lost_output_surface = false; |
517 { | 481 { |
518 DebugScopedSetImplThread impl(this); | 482 DebugScopedSetImplThread impl(this); |
519 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 483 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
520 | 484 |
521 layer_tree_host_impl_->SetOffscreenContextProvider( | |
522 offscreen_context_provider); | |
523 | |
524 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); | 485 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); |
525 | 486 |
526 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 487 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
527 // frame, so can only be used when such a frame is possible. Since | 488 // frame, so can only be used when such a frame is possible. Since |
528 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 489 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
529 // CanDraw() as well. | 490 // CanDraw() as well. |
530 if (!ShouldComposite() || (for_readback && !can_do_readback)) { | 491 if (!ShouldComposite() || (for_readback && !can_do_readback)) { |
531 UpdateBackgroundAnimateTicking(); | 492 UpdateBackgroundAnimateTicking(); |
532 return false; | 493 return false; |
533 } | 494 } |
534 | 495 |
535 layer_tree_host_impl_->Animate( | 496 layer_tree_host_impl_->Animate( |
536 layer_tree_host_impl_->CurrentFrameTimeTicks()); | 497 layer_tree_host_impl_->CurrentFrameTimeTicks()); |
537 UpdateBackgroundAnimateTicking(); | 498 UpdateBackgroundAnimateTicking(); |
538 | 499 |
539 if (!layer_tree_host_impl_->IsContextLost()) { | 500 if (!layer_tree_host_impl_->IsContextLost()) { |
540 layer_tree_host_impl_->PrepareToDraw(frame, device_viewport_damage_rect); | 501 layer_tree_host_impl_->PrepareToDraw(frame, device_viewport_damage_rect); |
541 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); | 502 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
542 layer_tree_host_impl_->DidDrawAllLayers(*frame); | 503 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
543 } | 504 } |
544 lost_output_surface = layer_tree_host_impl_->IsContextLost(); | 505 lost_output_surface = layer_tree_host_impl_->IsContextLost(); |
545 | 506 |
546 bool start_ready_animations = true; | 507 bool start_ready_animations = true; |
547 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 508 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
548 | 509 |
549 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | 510 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
550 } | 511 } |
551 | 512 |
552 if (lost_output_surface) { | 513 if (lost_output_surface) { |
553 ContextProvider* offscreen_contexts = | |
554 layer_tree_host_impl_->offscreen_context_provider(); | |
555 if (offscreen_contexts) | |
556 offscreen_contexts->VerifyContexts(); | |
557 layer_tree_host_->DidLoseOutputSurface(); | 514 layer_tree_host_->DidLoseOutputSurface(); |
558 return false; | 515 return false; |
559 } | 516 } |
560 | 517 |
561 return true; | 518 return true; |
562 } | 519 } |
563 | 520 |
564 void SingleThreadProxy::DidSwapFrame() { | 521 void SingleThreadProxy::DidSwapFrame() { |
565 if (next_frame_is_newly_committed_frame_) { | 522 if (next_frame_is_newly_committed_frame_) { |
566 next_frame_is_newly_committed_frame_ = false; | 523 next_frame_is_newly_committed_frame_ = false; |
567 layer_tree_host_->DidCommitAndDrawFrame(); | 524 layer_tree_host_->DidCommitAndDrawFrame(); |
568 } | 525 } |
569 } | 526 } |
570 | 527 |
571 bool SingleThreadProxy::CommitPendingForTesting() { return false; } | 528 bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
572 | 529 |
573 } // namespace cc | 530 } // namespace cc |
OLD | NEW |