| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/debug/trace_event_synthetic_delay.h" | 12 #include "base/debug/trace_event_synthetic_delay.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "cc/base/swap_promise.h" | 14 #include "cc/base/swap_promise.h" |
| 15 #include "cc/debug/benchmark_instrumentation.h" | 15 #include "cc/debug/benchmark_instrumentation.h" |
| 16 #include "cc/debug/devtools_instrumentation.h" |
| 16 #include "cc/input/input_handler.h" | 17 #include "cc/input/input_handler.h" |
| 17 #include "cc/output/context_provider.h" | 18 #include "cc/output/context_provider.h" |
| 18 #include "cc/output/output_surface.h" | 19 #include "cc/output/output_surface.h" |
| 19 #include "cc/quads/draw_quad.h" | 20 #include "cc/quads/draw_quad.h" |
| 20 #include "cc/resources/prioritized_resource_manager.h" | 21 #include "cc/resources/prioritized_resource_manager.h" |
| 21 #include "cc/scheduler/delay_based_time_source.h" | 22 #include "cc/scheduler/delay_based_time_source.h" |
| 22 #include "cc/scheduler/frame_rate_controller.h" | 23 #include "cc/scheduler/frame_rate_controller.h" |
| 23 #include "cc/scheduler/scheduler.h" | 24 #include "cc/scheduler/scheduler.h" |
| 24 #include "cc/trees/blocking_task_runner.h" | 25 #include "cc/trees/blocking_task_runner.h" |
| 25 #include "cc/trees/layer_tree_host.h" | 26 #include "cc/trees/layer_tree_host.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 return make_scoped_ptr(new ThreadProxy(layer_tree_host, impl_task_runner)) | 77 return make_scoped_ptr(new ThreadProxy(layer_tree_host, impl_task_runner)) |
| 77 .PassAs<Proxy>(); | 78 .PassAs<Proxy>(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 ThreadProxy::ThreadProxy( | 81 ThreadProxy::ThreadProxy( |
| 81 LayerTreeHost* layer_tree_host, | 82 LayerTreeHost* layer_tree_host, |
| 82 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | 83 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
| 83 : Proxy(impl_task_runner), | 84 : Proxy(impl_task_runner), |
| 84 main_thread_only_vars_unsafe_(this, layer_tree_host->id()), | 85 main_thread_only_vars_unsafe_(this, layer_tree_host->id()), |
| 85 main_thread_or_blocked_vars_unsafe_(layer_tree_host), | 86 main_thread_or_blocked_vars_unsafe_(layer_tree_host), |
| 86 compositor_thread_vars_unsafe_(this) { | 87 compositor_thread_vars_unsafe_(this, layer_tree_host->id()) { |
| 87 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); | 88 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); |
| 88 DCHECK(IsMainThread()); | 89 DCHECK(IsMainThread()); |
| 89 DCHECK(this->layer_tree_host()); | 90 DCHECK(this->layer_tree_host()); |
| 90 } | 91 } |
| 91 | 92 |
| 92 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, | 93 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, |
| 93 int layer_tree_host_id) | 94 int layer_tree_host_id) |
| 94 : layer_tree_host_id(layer_tree_host_id), | 95 : layer_tree_host_id(layer_tree_host_id), |
| 95 animate_requested(false), | 96 animate_requested(false), |
| 96 commit_requested(false), | 97 commit_requested(false), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 112 commit_waits_for_activation(false), | 113 commit_waits_for_activation(false), |
| 113 main_thread_inside_commit(false) {} | 114 main_thread_inside_commit(false) {} |
| 114 | 115 |
| 115 ThreadProxy::MainThreadOrBlockedMainThread::~MainThreadOrBlockedMainThread() {} | 116 ThreadProxy::MainThreadOrBlockedMainThread::~MainThreadOrBlockedMainThread() {} |
| 116 | 117 |
| 117 PrioritizedResourceManager* | 118 PrioritizedResourceManager* |
| 118 ThreadProxy::MainThreadOrBlockedMainThread::contents_texture_manager() { | 119 ThreadProxy::MainThreadOrBlockedMainThread::contents_texture_manager() { |
| 119 return layer_tree_host->contents_texture_manager(); | 120 return layer_tree_host->contents_texture_manager(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly(ThreadProxy* proxy) | 123 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly(ThreadProxy* proxy, |
| 123 : contents_texture_manager(NULL), | 124 int layer_tree_host_id) |
| 125 : layer_tree_host_id(layer_tree_host_id), |
| 126 contents_texture_manager(NULL), |
| 124 begin_main_frame_sent_completion_event(NULL), | 127 begin_main_frame_sent_completion_event(NULL), |
| 125 readback_request(NULL), | 128 readback_request(NULL), |
| 126 commit_completion_event(NULL), | 129 commit_completion_event(NULL), |
| 127 completion_event_for_commit_held_on_tree_activation(NULL), | 130 completion_event_for_commit_held_on_tree_activation(NULL), |
| 128 texture_acquisition_completion_event(NULL), | 131 texture_acquisition_completion_event(NULL), |
| 129 next_frame_is_newly_committed_frame(false), | 132 next_frame_is_newly_committed_frame(false), |
| 130 inside_draw(false), | 133 inside_draw(false), |
| 131 input_throttled_until_commit(false), | 134 input_throttled_until_commit(false), |
| 132 renew_tree_priority_pending(false), | 135 renew_tree_priority_pending(false), |
| 133 draw_duration_history(kDurationHistorySize), | 136 draw_duration_history(kDurationHistorySize), |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 DCHECK(IsMainThread()); | 676 DCHECK(IsMainThread()); |
| 674 DCHECK(Proxy::HasImplThread()); | 677 DCHECK(Proxy::HasImplThread()); |
| 675 | 678 |
| 676 // Create LayerTreeHostImpl. | 679 // Create LayerTreeHostImpl. |
| 677 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 680 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 678 CompletionEvent completion; | 681 CompletionEvent completion; |
| 679 Proxy::ImplThreadTaskRunner()->PostTask( | 682 Proxy::ImplThreadTaskRunner()->PostTask( |
| 680 FROM_HERE, | 683 FROM_HERE, |
| 681 base::Bind(&ThreadProxy::InitializeImplOnImplThread, | 684 base::Bind(&ThreadProxy::InitializeImplOnImplThread, |
| 682 base::Unretained(this), | 685 base::Unretained(this), |
| 683 &completion, | 686 &completion)); |
| 684 main().layer_tree_host_id)); | |
| 685 completion.Wait(); | 687 completion.Wait(); |
| 686 | 688 |
| 687 main_thread_weak_ptr_ = main().weak_factory.GetWeakPtr(); | 689 main_thread_weak_ptr_ = main().weak_factory.GetWeakPtr(); |
| 688 | 690 |
| 689 main().started = true; | 691 main().started = true; |
| 690 } | 692 } |
| 691 | 693 |
| 692 void ThreadProxy::Stop() { | 694 void ThreadProxy::Stop() { |
| 693 TRACE_EVENT0("cc", "ThreadProxy::Stop"); | 695 TRACE_EVENT0("cc", "ThreadProxy::Stop"); |
| 694 DCHECK(IsMainThread()); | 696 DCHECK(IsMainThread()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 impl().layer_tree_host_impl->memory_allocation_limit_bytes(); | 769 impl().layer_tree_host_impl->memory_allocation_limit_bytes(); |
| 768 begin_main_frame_state->memory_allocation_priority_cutoff = | 770 begin_main_frame_state->memory_allocation_priority_cutoff = |
| 769 impl().layer_tree_host_impl->memory_allocation_priority_cutoff(); | 771 impl().layer_tree_host_impl->memory_allocation_priority_cutoff(); |
| 770 begin_main_frame_state->evicted_ui_resources = | 772 begin_main_frame_state->evicted_ui_resources = |
| 771 impl().layer_tree_host_impl->EvictedUIResourcesExist(); | 773 impl().layer_tree_host_impl->EvictedUIResourcesExist(); |
| 772 Proxy::MainThreadTaskRunner()->PostTask( | 774 Proxy::MainThreadTaskRunner()->PostTask( |
| 773 FROM_HERE, | 775 FROM_HERE, |
| 774 base::Bind(&ThreadProxy::BeginMainFrame, | 776 base::Bind(&ThreadProxy::BeginMainFrame, |
| 775 main_thread_weak_ptr_, | 777 main_thread_weak_ptr_, |
| 776 base::Passed(&begin_main_frame_state))); | 778 base::Passed(&begin_main_frame_state))); |
| 777 | 779 devtools_instrumentation::didRequestMainThreadFrame( |
| 780 impl().layer_tree_host_id); |
| 778 if (impl().begin_main_frame_sent_completion_event) { | 781 if (impl().begin_main_frame_sent_completion_event) { |
| 779 impl().begin_main_frame_sent_completion_event->Signal(); | 782 impl().begin_main_frame_sent_completion_event->Signal(); |
| 780 impl().begin_main_frame_sent_completion_event = NULL; | 783 impl().begin_main_frame_sent_completion_event = NULL; |
| 781 } | 784 } |
| 782 impl().begin_main_frame_sent_time = base::TimeTicks::HighResNow(); | 785 impl().begin_main_frame_sent_time = base::TimeTicks::HighResNow(); |
| 783 } | 786 } |
| 784 | 787 |
| 785 void ThreadProxy::BeginMainFrame( | 788 void ThreadProxy::BeginMainFrame( |
| 786 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 789 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
| 787 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame"); | 790 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame"); |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 | 1402 |
| 1400 void ThreadProxy::HasInitializedOutputSurfaceOnImplThread( | 1403 void ThreadProxy::HasInitializedOutputSurfaceOnImplThread( |
| 1401 CompletionEvent* completion, | 1404 CompletionEvent* completion, |
| 1402 bool* has_initialized_output_surface) { | 1405 bool* has_initialized_output_surface) { |
| 1403 DCHECK(IsImplThread()); | 1406 DCHECK(IsImplThread()); |
| 1404 *has_initialized_output_surface = | 1407 *has_initialized_output_surface = |
| 1405 impl().scheduler->HasInitializedOutputSurface(); | 1408 impl().scheduler->HasInitializedOutputSurface(); |
| 1406 completion->Signal(); | 1409 completion->Signal(); |
| 1407 } | 1410 } |
| 1408 | 1411 |
| 1409 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion, | 1412 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { |
| 1410 int layer_tree_host_id) { | |
| 1411 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); | 1413 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); |
| 1412 DCHECK(IsImplThread()); | 1414 DCHECK(IsImplThread()); |
| 1413 impl().layer_tree_host_impl = | 1415 impl().layer_tree_host_impl = |
| 1414 layer_tree_host()->CreateLayerTreeHostImpl(this); | 1416 layer_tree_host()->CreateLayerTreeHostImpl(this); |
| 1415 const LayerTreeSettings& settings = layer_tree_host()->settings(); | 1417 const LayerTreeSettings& settings = layer_tree_host()->settings(); |
| 1416 SchedulerSettings scheduler_settings; | 1418 SchedulerSettings scheduler_settings; |
| 1417 scheduler_settings.deadline_scheduling_enabled = | 1419 scheduler_settings.deadline_scheduling_enabled = |
| 1418 settings.deadline_scheduling_enabled; | 1420 settings.deadline_scheduling_enabled; |
| 1419 scheduler_settings.impl_side_painting = settings.impl_side_painting; | 1421 scheduler_settings.impl_side_painting = settings.impl_side_painting; |
| 1420 scheduler_settings.timeout_and_draw_when_animation_checkerboards = | 1422 scheduler_settings.timeout_and_draw_when_animation_checkerboards = |
| 1421 settings.timeout_and_draw_when_animation_checkerboards; | 1423 settings.timeout_and_draw_when_animation_checkerboards; |
| 1422 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = | 1424 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = |
| 1423 settings.maximum_number_of_failed_draws_before_draw_is_forced_; | 1425 settings.maximum_number_of_failed_draws_before_draw_is_forced_; |
| 1424 scheduler_settings.using_synchronous_renderer_compositor = | 1426 scheduler_settings.using_synchronous_renderer_compositor = |
| 1425 settings.using_synchronous_renderer_compositor; | 1427 settings.using_synchronous_renderer_compositor; |
| 1426 scheduler_settings.throttle_frame_production = | 1428 scheduler_settings.throttle_frame_production = |
| 1427 settings.throttle_frame_production; | 1429 settings.throttle_frame_production; |
| 1428 impl().scheduler = | 1430 impl().scheduler = |
| 1429 Scheduler::Create(this, scheduler_settings, layer_tree_host_id); | 1431 Scheduler::Create(this, scheduler_settings, impl().layer_tree_host_id); |
| 1430 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); | 1432 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); |
| 1431 | 1433 |
| 1432 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); | 1434 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); |
| 1433 completion->Signal(); | 1435 completion->Signal(); |
| 1434 } | 1436 } |
| 1435 | 1437 |
| 1436 void ThreadProxy::InitializeOutputSurfaceOnImplThread( | 1438 void ThreadProxy::InitializeOutputSurfaceOnImplThread( |
| 1437 CompletionEvent* completion, | 1439 CompletionEvent* completion, |
| 1438 scoped_ptr<OutputSurface> output_surface, | 1440 scoped_ptr<OutputSurface> output_surface, |
| 1439 scoped_refptr<ContextProvider> offscreen_context_provider, | 1441 scoped_refptr<ContextProvider> offscreen_context_provider, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 impl().commit_to_activate_duration_history.InsertSample( | 1677 impl().commit_to_activate_duration_history.InsertSample( |
| 1676 base::TimeTicks::HighResNow() - impl().commit_complete_time); | 1678 base::TimeTicks::HighResNow() - impl().commit_complete_time); |
| 1677 } | 1679 } |
| 1678 | 1680 |
| 1679 void ThreadProxy::DidManageTiles() { | 1681 void ThreadProxy::DidManageTiles() { |
| 1680 DCHECK(IsImplThread()); | 1682 DCHECK(IsImplThread()); |
| 1681 impl().scheduler->DidManageTiles(); | 1683 impl().scheduler->DidManageTiles(); |
| 1682 } | 1684 } |
| 1683 | 1685 |
| 1684 } // namespace cc | 1686 } // namespace cc |
| OLD | NEW |