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/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <stack> | 8 #include <stack> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/atomic_sequence_num.h" | 11 #include "base/atomic_sequence_num.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "base/trace_event/trace_event_argument.h" | 19 #include "base/trace_event/trace_event_argument.h" |
20 #include "cc/animation/animation_registrar.h" | 20 #include "cc/animation/animation_registrar.h" |
21 #include "cc/animation/layer_animation_controller.h" | 21 #include "cc/animation/layer_animation_controller.h" |
22 #include "cc/base/math_util.h" | 22 #include "cc/base/math_util.h" |
23 #include "cc/debug/devtools_instrumentation.h" | 23 #include "cc/debug/devtools_instrumentation.h" |
| 24 #include "cc/debug/frame_viewer_instrumentation.h" |
24 #include "cc/debug/rendering_stats_instrumentation.h" | 25 #include "cc/debug/rendering_stats_instrumentation.h" |
25 #include "cc/input/layer_selection_bound.h" | 26 #include "cc/input/layer_selection_bound.h" |
26 #include "cc/input/page_scale_animation.h" | 27 #include "cc/input/page_scale_animation.h" |
27 #include "cc/input/top_controls_manager.h" | 28 #include "cc/input/top_controls_manager.h" |
28 #include "cc/layers/heads_up_display_layer.h" | 29 #include "cc/layers/heads_up_display_layer.h" |
29 #include "cc/layers/heads_up_display_layer_impl.h" | 30 #include "cc/layers/heads_up_display_layer_impl.h" |
30 #include "cc/layers/layer.h" | 31 #include "cc/layers/layer.h" |
31 #include "cc/layers/layer_iterator.h" | 32 #include "cc/layers/layer_iterator.h" |
32 #include "cc/layers/painted_scrollbar_layer.h" | 33 #include "cc/layers/painted_scrollbar_layer.h" |
33 #include "cc/layers/render_surface.h" | 34 #include "cc/layers/render_surface.h" |
(...skipping 14 matching lines...) Expand all Loading... |
48 namespace { | 49 namespace { |
49 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; | 50 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; |
50 } | 51 } |
51 | 52 |
52 namespace cc { | 53 namespace cc { |
53 | 54 |
54 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded( | 55 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded( |
55 LayerTreeHostClient* client, | 56 LayerTreeHostClient* client, |
56 SharedBitmapManager* shared_bitmap_manager, | 57 SharedBitmapManager* shared_bitmap_manager, |
57 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 58 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 59 TaskGraphRunner* task_graph_runner, |
58 const LayerTreeSettings& settings, | 60 const LayerTreeSettings& settings, |
59 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 61 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
60 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | 62 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
61 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 63 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
62 DCHECK(main_task_runner.get()); | 64 DCHECK(main_task_runner.get()); |
63 DCHECK(impl_task_runner.get()); | 65 DCHECK(impl_task_runner.get()); |
64 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost( | 66 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost( |
65 client, shared_bitmap_manager, gpu_memory_buffer_manager, settings)); | 67 client, shared_bitmap_manager, gpu_memory_buffer_manager, |
| 68 task_graph_runner, settings)); |
66 layer_tree_host->InitializeThreaded(main_task_runner, | 69 layer_tree_host->InitializeThreaded(main_task_runner, |
67 impl_task_runner, | 70 impl_task_runner, |
68 external_begin_frame_source.Pass()); | 71 external_begin_frame_source.Pass()); |
69 return layer_tree_host.Pass(); | 72 return layer_tree_host.Pass(); |
70 } | 73 } |
71 | 74 |
72 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded( | 75 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded( |
73 LayerTreeHostClient* client, | 76 LayerTreeHostClient* client, |
74 LayerTreeHostSingleThreadClient* single_thread_client, | 77 LayerTreeHostSingleThreadClient* single_thread_client, |
75 SharedBitmapManager* shared_bitmap_manager, | 78 SharedBitmapManager* shared_bitmap_manager, |
76 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 79 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 80 TaskGraphRunner* task_graph_runner, |
77 const LayerTreeSettings& settings, | 81 const LayerTreeSettings& settings, |
78 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 82 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
79 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 83 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
80 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost( | 84 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost( |
81 client, shared_bitmap_manager, gpu_memory_buffer_manager, settings)); | 85 client, shared_bitmap_manager, gpu_memory_buffer_manager, |
| 86 task_graph_runner, settings)); |
82 layer_tree_host->InitializeSingleThreaded(single_thread_client, | 87 layer_tree_host->InitializeSingleThreaded(single_thread_client, |
83 main_task_runner, | 88 main_task_runner, |
84 external_begin_frame_source.Pass()); | 89 external_begin_frame_source.Pass()); |
85 return layer_tree_host.Pass(); | 90 return layer_tree_host.Pass(); |
86 } | 91 } |
87 | 92 |
88 LayerTreeHost::LayerTreeHost( | 93 LayerTreeHost::LayerTreeHost( |
89 LayerTreeHostClient* client, | 94 LayerTreeHostClient* client, |
90 SharedBitmapManager* shared_bitmap_manager, | 95 SharedBitmapManager* shared_bitmap_manager, |
91 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 96 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 97 TaskGraphRunner* task_graph_runner, |
92 const LayerTreeSettings& settings) | 98 const LayerTreeSettings& settings) |
93 : micro_benchmark_controller_(this), | 99 : micro_benchmark_controller_(this), |
94 next_ui_resource_id_(1), | 100 next_ui_resource_id_(1), |
95 inside_begin_main_frame_(false), | 101 inside_begin_main_frame_(false), |
96 needs_full_tree_sync_(true), | 102 needs_full_tree_sync_(true), |
97 client_(client), | 103 client_(client), |
98 source_frame_number_(0), | 104 source_frame_number_(0), |
99 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), | 105 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
100 output_surface_lost_(true), | 106 output_surface_lost_(true), |
101 settings_(settings), | 107 settings_(settings), |
(...skipping 11 matching lines...) Expand all Loading... |
113 gpu_rasterization_histogram_recorded_(false), | 119 gpu_rasterization_histogram_recorded_(false), |
114 background_color_(SK_ColorWHITE), | 120 background_color_(SK_ColorWHITE), |
115 has_transparent_background_(false), | 121 has_transparent_background_(false), |
116 partial_texture_update_requests_(0), | 122 partial_texture_update_requests_(0), |
117 did_complete_scale_animation_(false), | 123 did_complete_scale_animation_(false), |
118 in_paint_layer_contents_(false), | 124 in_paint_layer_contents_(false), |
119 id_(s_layer_tree_host_sequence_number.GetNext() + 1), | 125 id_(s_layer_tree_host_sequence_number.GetNext() + 1), |
120 next_commit_forces_redraw_(false), | 126 next_commit_forces_redraw_(false), |
121 shared_bitmap_manager_(shared_bitmap_manager), | 127 shared_bitmap_manager_(shared_bitmap_manager), |
122 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 128 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 129 task_graph_runner_(task_graph_runner), |
123 surface_id_namespace_(0u), | 130 surface_id_namespace_(0u), |
124 next_surface_sequence_(1u) { | 131 next_surface_sequence_(1u) { |
125 if (settings_.accelerated_animation_enabled) | 132 if (settings_.accelerated_animation_enabled) |
126 animation_registrar_ = AnimationRegistrar::Create(); | 133 animation_registrar_ = AnimationRegistrar::Create(); |
127 rendering_stats_instrumentation_->set_record_rendering_stats( | 134 rendering_stats_instrumentation_->set_record_rendering_stats( |
128 debug_state_.RecordRenderingStats()); | 135 debug_state_.RecordRenderingStats()); |
129 } | 136 } |
130 | 137 |
131 void LayerTreeHost::InitializeThreaded( | 138 void LayerTreeHost::InitializeThreaded( |
132 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 139 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 } | 268 } |
262 | 269 |
263 host_impl->set_max_memory_needed_bytes( | 270 host_impl->set_max_memory_needed_bytes( |
264 contents_texture_manager_->MaxMemoryNeededBytes()); | 271 contents_texture_manager_->MaxMemoryNeededBytes()); |
265 | 272 |
266 contents_texture_manager_->UpdateBackingsState( | 273 contents_texture_manager_->UpdateBackingsState( |
267 host_impl->resource_provider()); | 274 host_impl->resource_provider()); |
268 contents_texture_manager_->ReduceMemory(host_impl->resource_provider()); | 275 contents_texture_manager_->ReduceMemory(host_impl->resource_provider()); |
269 } | 276 } |
270 | 277 |
| 278 bool is_new_trace; |
| 279 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); |
| 280 if (is_new_trace && |
| 281 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && |
| 282 root_layer()) { |
| 283 LayerTreeHostCommon::CallFunctionForSubtree( |
| 284 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); |
| 285 } |
| 286 |
271 LayerTreeImpl* sync_tree = host_impl->sync_tree(); | 287 LayerTreeImpl* sync_tree = host_impl->sync_tree(); |
272 | 288 |
273 if (next_commit_forces_redraw_) { | 289 if (next_commit_forces_redraw_) { |
274 sync_tree->ForceRedrawNextActivation(); | 290 sync_tree->ForceRedrawNextActivation(); |
275 next_commit_forces_redraw_ = false; | 291 next_commit_forces_redraw_ = false; |
276 } | 292 } |
277 | 293 |
278 sync_tree->set_source_frame_number(source_frame_number()); | 294 sync_tree->set_source_frame_number(source_frame_number()); |
279 | 295 |
280 if (needs_full_tree_sync_) { | 296 if (needs_full_tree_sync_) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 429 } |
414 | 430 |
415 void LayerTreeHost::DidFailToInitializeOutputSurface() { | 431 void LayerTreeHost::DidFailToInitializeOutputSurface() { |
416 DCHECK(output_surface_lost_); | 432 DCHECK(output_surface_lost_); |
417 client_->DidFailToInitializeOutputSurface(); | 433 client_->DidFailToInitializeOutputSurface(); |
418 } | 434 } |
419 | 435 |
420 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 436 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
421 LayerTreeHostImplClient* client) { | 437 LayerTreeHostImplClient* client) { |
422 DCHECK(proxy_->IsImplThread()); | 438 DCHECK(proxy_->IsImplThread()); |
423 scoped_ptr<LayerTreeHostImpl> host_impl = | 439 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( |
424 LayerTreeHostImpl::Create(settings_, | 440 settings_, client, proxy_.get(), rendering_stats_instrumentation_.get(), |
425 client, | 441 shared_bitmap_manager_, gpu_memory_buffer_manager_, task_graph_runner_, |
426 proxy_.get(), | 442 id_); |
427 rendering_stats_instrumentation_.get(), | |
428 shared_bitmap_manager_, | |
429 gpu_memory_buffer_manager_, | |
430 id_); | |
431 host_impl->SetUseGpuRasterization(UseGpuRasterization()); | 443 host_impl->SetUseGpuRasterization(UseGpuRasterization()); |
432 shared_bitmap_manager_ = NULL; | 444 shared_bitmap_manager_ = NULL; |
433 gpu_memory_buffer_manager_ = NULL; | 445 gpu_memory_buffer_manager_ = NULL; |
| 446 task_graph_runner_ = NULL; |
434 top_controls_manager_weak_ptr_ = | 447 top_controls_manager_weak_ptr_ = |
435 host_impl->top_controls_manager()->AsWeakPtr(); | 448 host_impl->top_controls_manager()->AsWeakPtr(); |
436 input_handler_weak_ptr_ = host_impl->AsWeakPtr(); | 449 input_handler_weak_ptr_ = host_impl->AsWeakPtr(); |
437 return host_impl.Pass(); | 450 return host_impl.Pass(); |
438 } | 451 } |
439 | 452 |
440 void LayerTreeHost::DidLoseOutputSurface() { | 453 void LayerTreeHost::DidLoseOutputSurface() { |
441 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); | 454 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); |
442 DCHECK(proxy_->IsMainThread()); | 455 DCHECK(proxy_->IsMainThread()); |
443 | 456 |
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 bool children_need_begin_frames) const { | 1267 bool children_need_begin_frames) const { |
1255 proxy_->SetChildrenNeedBeginFrames(children_need_begin_frames); | 1268 proxy_->SetChildrenNeedBeginFrames(children_need_begin_frames); |
1256 } | 1269 } |
1257 | 1270 |
1258 void LayerTreeHost::SendBeginFramesToChildren( | 1271 void LayerTreeHost::SendBeginFramesToChildren( |
1259 const BeginFrameArgs& args) const { | 1272 const BeginFrameArgs& args) const { |
1260 client_->SendBeginFramesToChildren(args); | 1273 client_->SendBeginFramesToChildren(args); |
1261 } | 1274 } |
1262 | 1275 |
1263 } // namespace cc | 1276 } // namespace cc |
OLD | NEW |