| 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/thread_proxy.h" | 5 #include "cc/trees/thread_proxy.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 base::Passed(&output_surface), | 328 base::Passed(&output_surface), |
| 329 offscreen_context_provider, | 329 offscreen_context_provider, |
| 330 &success, | 330 &success, |
| 331 &capabilities)); | 331 &capabilities)); |
| 332 completion.Wait(); | 332 completion.Wait(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 OnOutputSurfaceInitializeAttempted(success, capabilities); | 335 OnOutputSurfaceInitializeAttempted(success, capabilities); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void ThreadProxy::SetRendererCapabilitiesMainThreadCopy( |
| 339 const RendererCapabilities& capabilities) { |
| 340 DCHECK(IsMainThread()); |
| 341 main().renderer_capabilities_main_thread_copy = capabilities; |
| 342 layer_tree_host()->RendererCapabilitiesChanged(); |
| 343 } |
| 344 |
| 338 void ThreadProxy::OnOutputSurfaceInitializeAttempted( | 345 void ThreadProxy::OnOutputSurfaceInitializeAttempted( |
| 339 bool success, | 346 bool success, |
| 340 const RendererCapabilities& capabilities) { | 347 const RendererCapabilities& capabilities) { |
| 341 DCHECK(IsMainThread()); | 348 DCHECK(IsMainThread()); |
| 342 DCHECK(layer_tree_host()); | 349 DCHECK(layer_tree_host()); |
| 343 | 350 |
| 351 LayerTreeHost::CreateResult result = |
| 352 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(success); |
| 344 if (success) { | 353 if (success) { |
| 345 main().renderer_capabilities_main_thread_copy = capabilities; | 354 SetRendererCapabilitiesMainThreadCopy(capabilities); |
| 346 } | 355 } |
| 347 | 356 |
| 348 LayerTreeHost::CreateResult result = | |
| 349 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(success); | |
| 350 if (result == LayerTreeHost::CreateFailedButTryAgain) { | 357 if (result == LayerTreeHost::CreateFailedButTryAgain) { |
| 351 if (!main().output_surface_creation_callback.callback().is_null()) { | 358 if (!main().output_surface_creation_callback.callback().is_null()) { |
| 352 Proxy::MainThreadTaskRunner()->PostTask( | 359 Proxy::MainThreadTaskRunner()->PostTask( |
| 353 FROM_HERE, main().output_surface_creation_callback.callback()); | 360 FROM_HERE, main().output_surface_creation_callback.callback()); |
| 354 } | 361 } |
| 355 } else { | 362 } else { |
| 356 main().output_surface_creation_callback.Cancel(); | 363 main().output_surface_creation_callback.Cancel(); |
| 357 } | 364 } |
| 358 } | 365 } |
| 359 | 366 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 main().can_cancel_commit = false; | 408 main().can_cancel_commit = false; |
| 402 | 409 |
| 403 if (main().commit_requested) | 410 if (main().commit_requested) |
| 404 return; | 411 return; |
| 405 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommit"); | 412 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommit"); |
| 406 main().commit_requested = true; | 413 main().commit_requested = true; |
| 407 | 414 |
| 408 SendCommitRequestToImplThreadIfNeeded(); | 415 SendCommitRequestToImplThreadIfNeeded(); |
| 409 } | 416 } |
| 410 | 417 |
| 418 void ThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
| 419 DCHECK(IsImplThread()); |
| 420 // PrioritizedResourceManager is not cleared, so this won't yet work with |
| 421 // ContentLayer or ImageLayer, which are only used when impl_side_painting is |
| 422 // off. |
| 423 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); |
| 424 |
| 425 Proxy::MainThreadTaskRunner()->PostTask( |
| 426 FROM_HERE, |
| 427 base::Bind(&ThreadProxy::SetRendererCapabilitiesMainThreadCopy, |
| 428 main_thread_weak_ptr_, |
| 429 impl() |
| 430 .layer_tree_host_impl->GetRendererCapabilities() |
| 431 .MainThreadCapabilities())); |
| 432 } |
| 433 |
| 411 void ThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 434 void ThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
| 412 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 435 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
| 413 DCHECK(IsImplThread()); | 436 DCHECK(IsImplThread()); |
| 414 CheckOutputSurfaceStatusOnImplThread(); | 437 CheckOutputSurfaceStatusOnImplThread(); |
| 415 } | 438 } |
| 416 | 439 |
| 417 void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { | 440 void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { |
| 418 TRACE_EVENT0("cc", "ThreadProxy::CheckOutputSurfaceStatusOnImplThread"); | 441 TRACE_EVENT0("cc", "ThreadProxy::CheckOutputSurfaceStatusOnImplThread"); |
| 419 DCHECK(IsImplThread()); | 442 DCHECK(IsImplThread()); |
| 420 if (!impl().layer_tree_host_impl->IsContextLost()) | 443 if (!impl().layer_tree_host_impl->IsContextLost()) |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 // to receive its callbacks before that. | 975 // to receive its callbacks before that. |
| 953 BlockingTaskRunner::CapturePostTasks blocked; | 976 BlockingTaskRunner::CapturePostTasks blocked; |
| 954 | 977 |
| 955 CompletionEvent completion; | 978 CompletionEvent completion; |
| 956 Proxy::ImplThreadTaskRunner()->PostTask( | 979 Proxy::ImplThreadTaskRunner()->PostTask( |
| 957 FROM_HERE, | 980 FROM_HERE, |
| 958 base::Bind(&ThreadProxy::StartCommitOnImplThread, | 981 base::Bind(&ThreadProxy::StartCommitOnImplThread, |
| 959 impl_thread_weak_ptr_, | 982 impl_thread_weak_ptr_, |
| 960 &completion, | 983 &completion, |
| 961 queue.release(), | 984 queue.release(), |
| 962 offscreen_context_provider)); | 985 offscreen_context_provider, |
| 986 main().renderer_capabilities_main_thread_copy)); |
| 963 completion.Wait(); | 987 completion.Wait(); |
| 964 | 988 |
| 965 RenderingStatsInstrumentation* stats_instrumentation = | 989 RenderingStatsInstrumentation* stats_instrumentation = |
| 966 layer_tree_host()->rendering_stats_instrumentation(); | 990 layer_tree_host()->rendering_stats_instrumentation(); |
| 967 BenchmarkInstrumentation::IssueMainThreadRenderingStatsEvent( | 991 BenchmarkInstrumentation::IssueMainThreadRenderingStatsEvent( |
| 968 stats_instrumentation->main_thread_rendering_stats()); | 992 stats_instrumentation->main_thread_rendering_stats()); |
| 969 stats_instrumentation->AccumulateAndClearMainThreadStats(); | 993 stats_instrumentation->AccumulateAndClearMainThreadStats(); |
| 970 } | 994 } |
| 971 | 995 |
| 972 layer_tree_host()->CommitComplete(); | 996 layer_tree_host()->CommitComplete(); |
| 973 layer_tree_host()->DidBeginMainFrame(); | 997 layer_tree_host()->DidBeginMainFrame(); |
| 974 } | 998 } |
| 975 | 999 |
| 976 void ThreadProxy::StartCommitOnImplThread( | 1000 void ThreadProxy::StartCommitOnImplThread( |
| 977 CompletionEvent* completion, | 1001 CompletionEvent* completion, |
| 978 ResourceUpdateQueue* raw_queue, | 1002 ResourceUpdateQueue* raw_queue, |
| 979 scoped_refptr<ContextProvider> offscreen_context_provider) { | 1003 scoped_refptr<ContextProvider> offscreen_context_provider, |
| 1004 const RendererCapabilities& main_frame_renderer_caps) { |
| 980 scoped_ptr<ResourceUpdateQueue> queue(raw_queue); | 1005 scoped_ptr<ResourceUpdateQueue> queue(raw_queue); |
| 981 | 1006 |
| 982 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); | 1007 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); |
| 983 DCHECK(!impl().commit_completion_event); | 1008 DCHECK(!impl().commit_completion_event); |
| 984 DCHECK(IsImplThread() && IsMainThreadBlocked()); | 1009 DCHECK(IsImplThread() && IsMainThreadBlocked()); |
| 985 DCHECK(impl().scheduler); | 1010 DCHECK(impl().scheduler); |
| 986 DCHECK(impl().scheduler->CommitPending()); | 1011 DCHECK(impl().scheduler->CommitPending()); |
| 987 | 1012 |
| 988 if (!impl().layer_tree_host_impl) { | 1013 if (!impl().layer_tree_host_impl) { |
| 989 TRACE_EVENT_INSTANT0( | 1014 TRACE_EVENT_INSTANT0( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1012 // resources | 1037 // resources |
| 1013 queue->ClearUploadsToEvictedResources(); | 1038 queue->ClearUploadsToEvictedResources(); |
| 1014 // Some textures in the layer tree are invalid. Kick off another commit | 1039 // Some textures in the layer tree are invalid. Kick off another commit |
| 1015 // to fill them again. | 1040 // to fill them again. |
| 1016 SetNeedsCommitOnImplThread(); | 1041 SetNeedsCommitOnImplThread(); |
| 1017 } | 1042 } |
| 1018 | 1043 |
| 1019 impl().contents_texture_manager->PushTexturePrioritiesToBackings(); | 1044 impl().contents_texture_manager->PushTexturePrioritiesToBackings(); |
| 1020 } | 1045 } |
| 1021 | 1046 |
| 1047 impl().renderer_capabilities_for_commit = main_frame_renderer_caps; |
| 1022 impl().commit_completion_event = completion; | 1048 impl().commit_completion_event = completion; |
| 1023 impl().current_resource_update_controller = ResourceUpdateController::Create( | 1049 impl().current_resource_update_controller = ResourceUpdateController::Create( |
| 1024 this, | 1050 this, |
| 1025 Proxy::ImplThreadTaskRunner(), | 1051 Proxy::ImplThreadTaskRunner(), |
| 1026 queue.Pass(), | 1052 queue.Pass(), |
| 1027 impl().layer_tree_host_impl->resource_provider()); | 1053 impl().layer_tree_host_impl->resource_provider()); |
| 1028 impl().current_resource_update_controller->PerformMoreUpdates( | 1054 impl().current_resource_update_controller->PerformMoreUpdates( |
| 1029 impl().scheduler->AnticipatedDrawTime()); | 1055 impl().scheduler->AnticipatedDrawTime()); |
| 1030 } | 1056 } |
| 1031 | 1057 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 delta = base::TimeDelta(); | 1400 delta = base::TimeDelta(); |
| 1375 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, closure, delta); | 1401 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, closure, delta); |
| 1376 } | 1402 } |
| 1377 | 1403 |
| 1378 void ThreadProxy::DidBeginImplFrameDeadline() { | 1404 void ThreadProxy::DidBeginImplFrameDeadline() { |
| 1379 impl().layer_tree_host_impl->ResetCurrentFrameTimeForNextFrame(); | 1405 impl().layer_tree_host_impl->ResetCurrentFrameTimeForNextFrame(); |
| 1380 } | 1406 } |
| 1381 | 1407 |
| 1382 void ThreadProxy::ReadyToFinalizeTextureUpdates() { | 1408 void ThreadProxy::ReadyToFinalizeTextureUpdates() { |
| 1383 DCHECK(IsImplThread()); | 1409 DCHECK(IsImplThread()); |
| 1384 impl().scheduler->FinishCommit(); | 1410 |
| 1411 const RendererCapabilitiesImpl& impl_caps = |
| 1412 impl().layer_tree_host_impl->GetRendererCapabilities(); |
| 1413 if (impl_caps.MainThreadCapabilities() == |
| 1414 impl().renderer_capabilities_for_commit) { |
| 1415 impl().scheduler->FinishCommit(); |
| 1416 } else { |
| 1417 TRACE_EVENT_INSTANT0( |
| 1418 "cc", "EarlyOut_StaleRendererCaps", TRACE_EVENT_SCOPE_THREAD); |
| 1419 if (impl().commit_completion_event) { |
| 1420 impl().commit_completion_event->Signal(); |
| 1421 impl().commit_completion_event = NULL; |
| 1422 bool did_handle = true; |
| 1423 BeginMainFrameAbortedOnImplThread(did_handle); |
| 1424 } |
| 1425 } |
| 1385 } | 1426 } |
| 1386 | 1427 |
| 1387 void ThreadProxy::DidCommitAndDrawFrame() { | 1428 void ThreadProxy::DidCommitAndDrawFrame() { |
| 1388 DCHECK(IsMainThread()); | 1429 DCHECK(IsMainThread()); |
| 1389 if (!layer_tree_host()) | 1430 if (!layer_tree_host()) |
| 1390 return; | 1431 return; |
| 1391 layer_tree_host()->DidCommitAndDrawFrame(); | 1432 layer_tree_host()->DidCommitAndDrawFrame(); |
| 1392 } | 1433 } |
| 1393 | 1434 |
| 1394 void ThreadProxy::DidCompleteSwapBuffers() { | 1435 void ThreadProxy::DidCompleteSwapBuffers() { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 impl().commit_to_activate_duration_history.InsertSample( | 1753 impl().commit_to_activate_duration_history.InsertSample( |
| 1713 base::TimeTicks::HighResNow() - impl().commit_complete_time); | 1754 base::TimeTicks::HighResNow() - impl().commit_complete_time); |
| 1714 } | 1755 } |
| 1715 | 1756 |
| 1716 void ThreadProxy::DidManageTiles() { | 1757 void ThreadProxy::DidManageTiles() { |
| 1717 DCHECK(IsImplThread()); | 1758 DCHECK(IsImplThread()); |
| 1718 impl().scheduler->DidManageTiles(); | 1759 impl().scheduler->DidManageTiles(); |
| 1719 } | 1760 } |
| 1720 | 1761 |
| 1721 } // namespace cc | 1762 } // namespace cc |
| OLD | NEW |