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/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/lazy_instance.h" | |
14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/synchronization/lock.h" | |
18 #include "cc/animation/animation_registrar.h" | 20 #include "cc/animation/animation_registrar.h" |
19 #include "cc/animation/layer_animation_controller.h" | 21 #include "cc/animation/layer_animation_controller.h" |
20 #include "cc/base/math_util.h" | 22 #include "cc/base/math_util.h" |
21 #include "cc/debug/devtools_instrumentation.h" | 23 #include "cc/debug/devtools_instrumentation.h" |
22 #include "cc/debug/overdraw_metrics.h" | 24 #include "cc/debug/overdraw_metrics.h" |
23 #include "cc/debug/rendering_stats_instrumentation.h" | 25 #include "cc/debug/rendering_stats_instrumentation.h" |
24 #include "cc/input/top_controls_manager.h" | 26 #include "cc/input/top_controls_manager.h" |
25 #include "cc/layers/heads_up_display_layer.h" | 27 #include "cc/layers/heads_up_display_layer.h" |
26 #include "cc/layers/heads_up_display_layer_impl.h" | 28 #include "cc/layers/heads_up_display_layer_impl.h" |
27 #include "cc/layers/layer.h" | 29 #include "cc/layers/layer.h" |
28 #include "cc/layers/layer_iterator.h" | 30 #include "cc/layers/layer_iterator.h" |
29 #include "cc/layers/painted_scrollbar_layer.h" | 31 #include "cc/layers/painted_scrollbar_layer.h" |
30 #include "cc/layers/render_surface.h" | 32 #include "cc/layers/render_surface.h" |
31 #include "cc/resources/prioritized_resource_manager.h" | 33 #include "cc/resources/prioritized_resource_manager.h" |
32 #include "cc/resources/ui_resource_client.h" | 34 #include "cc/resources/ui_resource_client.h" |
33 #include "cc/trees/layer_tree_host_client.h" | 35 #include "cc/trees/layer_tree_host_client.h" |
34 #include "cc/trees/layer_tree_host_common.h" | 36 #include "cc/trees/layer_tree_host_common.h" |
35 #include "cc/trees/layer_tree_host_impl.h" | 37 #include "cc/trees/layer_tree_host_impl.h" |
36 #include "cc/trees/layer_tree_impl.h" | 38 #include "cc/trees/layer_tree_impl.h" |
37 #include "cc/trees/occlusion_tracker.h" | 39 #include "cc/trees/occlusion_tracker.h" |
38 #include "cc/trees/single_thread_proxy.h" | 40 #include "cc/trees/single_thread_proxy.h" |
39 #include "cc/trees/thread_proxy.h" | 41 #include "cc/trees/thread_proxy.h" |
40 #include "cc/trees/tree_synchronizer.h" | 42 #include "cc/trees/tree_synchronizer.h" |
41 #include "ui/gfx/size_conversions.h" | 43 #include "ui/gfx/size_conversions.h" |
42 | 44 |
43 namespace { | 45 namespace { |
44 static int s_num_layer_tree_instances; | 46 static base::LazyInstance<base::Lock>::Leaky |
47 s_next_tree_id_lock = LAZY_INSTANCE_INITIALIZER; | |
48 | |
49 inline int GetNextTreeId() { | |
50 static int s_next_tree_id = 1; | |
51 base::AutoLock lock(s_next_tree_id_lock.Get()); | |
caseq
2013/11/07 09:20:03
Any reason to not use StaticAtomicSequenceNumber h
dshwang
2013/11/07 09:46:03
Hi, Patch Set 1 used AtomicSequenceNumber, but Ato
| |
52 return s_next_tree_id++; | |
53 } | |
45 } | 54 } |
46 | 55 |
47 namespace cc { | 56 namespace cc { |
48 | 57 |
49 RendererCapabilities::RendererCapabilities() | 58 RendererCapabilities::RendererCapabilities() |
50 : best_texture_format(RGBA_8888), | 59 : best_texture_format(RGBA_8888), |
51 using_partial_swap(false), | 60 using_partial_swap(false), |
52 using_set_visibility(false), | 61 using_set_visibility(false), |
53 using_egl_image(false), | 62 using_egl_image(false), |
54 allow_partial_texture_updates(false), | 63 allow_partial_texture_updates(false), |
(...skipping 27 matching lines...) Expand all Loading... | |
82 bitmap_ = make_scoped_ptr(new UIResourceBitmap(*request.bitmap_.get())); | 91 bitmap_ = make_scoped_ptr(new UIResourceBitmap(*request.bitmap_.get())); |
83 } else { | 92 } else { |
84 bitmap_.reset(); | 93 bitmap_.reset(); |
85 } | 94 } |
86 | 95 |
87 return *this; | 96 return *this; |
88 } | 97 } |
89 | 98 |
90 UIResourceRequest::~UIResourceRequest() {} | 99 UIResourceRequest::~UIResourceRequest() {} |
91 | 100 |
92 bool LayerTreeHost::AnyLayerTreeHostInstanceExists() { | |
93 return s_num_layer_tree_instances > 0; | |
94 } | |
95 | |
96 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( | 101 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( |
97 LayerTreeHostClient* client, | 102 LayerTreeHostClient* client, |
98 SharedBitmapManager* manager, | 103 SharedBitmapManager* manager, |
99 const LayerTreeSettings& settings, | 104 const LayerTreeSettings& settings, |
100 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 105 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
101 scoped_ptr<LayerTreeHost> layer_tree_host( | 106 scoped_ptr<LayerTreeHost> layer_tree_host( |
102 new LayerTreeHost(client, manager, settings)); | 107 new LayerTreeHost(client, manager, settings)); |
103 if (!layer_tree_host->Initialize(impl_task_runner)) | 108 if (!layer_tree_host->Initialize(impl_task_runner)) |
104 return scoped_ptr<LayerTreeHost>(); | 109 return scoped_ptr<LayerTreeHost>(); |
105 return layer_tree_host.Pass(); | 110 return layer_tree_host.Pass(); |
106 } | 111 } |
107 | 112 |
108 static int s_next_tree_id = 1; | |
109 | |
110 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, | 113 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, |
111 SharedBitmapManager* manager, | 114 SharedBitmapManager* manager, |
112 const LayerTreeSettings& settings) | 115 const LayerTreeSettings& settings) |
113 : next_ui_resource_id_(1), | 116 : next_ui_resource_id_(1), |
114 animating_(false), | 117 animating_(false), |
115 needs_full_tree_sync_(true), | 118 needs_full_tree_sync_(true), |
116 needs_filter_context_(false), | 119 needs_filter_context_(false), |
117 client_(client), | 120 client_(client), |
118 source_frame_number_(0), | 121 source_frame_number_(0), |
119 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), | 122 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
120 micro_benchmark_controller_(this), | 123 micro_benchmark_controller_(this), |
121 output_surface_can_be_initialized_(true), | 124 output_surface_can_be_initialized_(true), |
122 output_surface_lost_(true), | 125 output_surface_lost_(true), |
123 num_failed_recreate_attempts_(0), | 126 num_failed_recreate_attempts_(0), |
124 settings_(settings), | 127 settings_(settings), |
125 debug_state_(settings.initial_debug_state), | 128 debug_state_(settings.initial_debug_state), |
126 overdraw_bottom_height_(0.f), | 129 overdraw_bottom_height_(0.f), |
127 device_scale_factor_(1.f), | 130 device_scale_factor_(1.f), |
128 visible_(true), | 131 visible_(true), |
129 page_scale_factor_(1.f), | 132 page_scale_factor_(1.f), |
130 min_page_scale_factor_(1.f), | 133 min_page_scale_factor_(1.f), |
131 max_page_scale_factor_(1.f), | 134 max_page_scale_factor_(1.f), |
132 trigger_idle_updates_(true), | 135 trigger_idle_updates_(true), |
133 background_color_(SK_ColorWHITE), | 136 background_color_(SK_ColorWHITE), |
134 has_transparent_background_(false), | 137 has_transparent_background_(false), |
135 partial_texture_update_requests_(0), | 138 partial_texture_update_requests_(0), |
136 in_paint_layer_contents_(false), | 139 in_paint_layer_contents_(false), |
137 total_frames_used_for_lcd_text_metrics_(0), | 140 total_frames_used_for_lcd_text_metrics_(0), |
138 tree_id_(s_next_tree_id++), | 141 tree_id_(GetNextTreeId()), |
139 next_commit_forces_redraw_(false), | 142 next_commit_forces_redraw_(false), |
140 shared_bitmap_manager_(manager) { | 143 shared_bitmap_manager_(manager) { |
141 if (settings_.accelerated_animation_enabled) | 144 if (settings_.accelerated_animation_enabled) |
142 animation_registrar_ = AnimationRegistrar::Create(); | 145 animation_registrar_ = AnimationRegistrar::Create(); |
143 s_num_layer_tree_instances++; | |
144 rendering_stats_instrumentation_->set_record_rendering_stats( | 146 rendering_stats_instrumentation_->set_record_rendering_stats( |
145 debug_state_.RecordRenderingStats()); | 147 debug_state_.RecordRenderingStats()); |
146 } | 148 } |
147 | 149 |
148 bool LayerTreeHost::Initialize( | 150 bool LayerTreeHost::Initialize( |
149 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 151 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
150 if (impl_task_runner.get()) | 152 if (impl_task_runner.get()) |
151 return InitializeProxy(ThreadProxy::Create(this, impl_task_runner)); | 153 return InitializeProxy(ThreadProxy::Create(this, impl_task_runner)); |
152 else | 154 else |
153 return InitializeProxy(SingleThreadProxy::Create(this)); | 155 return InitializeProxy(SingleThreadProxy::Create(this)); |
(...skipping 21 matching lines...) Expand all Loading... | |
175 overhang_ui_resource_.reset(); | 177 overhang_ui_resource_.reset(); |
176 | 178 |
177 if (root_layer_.get()) | 179 if (root_layer_.get()) |
178 root_layer_->SetLayerTreeHost(NULL); | 180 root_layer_->SetLayerTreeHost(NULL); |
179 | 181 |
180 if (proxy_) { | 182 if (proxy_) { |
181 DCHECK(proxy_->IsMainThread()); | 183 DCHECK(proxy_->IsMainThread()); |
182 proxy_->Stop(); | 184 proxy_->Stop(); |
183 } | 185 } |
184 | 186 |
185 s_num_layer_tree_instances--; | |
186 | |
187 if (root_layer_.get()) { | 187 if (root_layer_.get()) { |
188 // The layer tree must be destroyed before the layer tree host. We've | 188 // The layer tree must be destroyed before the layer tree host. We've |
189 // made a contract with our animation controllers that the registrar | 189 // made a contract with our animation controllers that the registrar |
190 // will outlive them, and we must make good. | 190 // will outlive them, and we must make good. |
191 root_layer_ = NULL; | 191 root_layer_ = NULL; |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 void LayerTreeHost::SetLayerTreeHostClientReady() { | 195 void LayerTreeHost::SetLayerTreeHostClientReady() { |
196 proxy_->SetLayerTreeHostClientReady(); | 196 proxy_->SetLayerTreeHostClientReady(); |
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1274 | 1274 |
1275 bool LayerTreeHost::ScheduleMicroBenchmark( | 1275 bool LayerTreeHost::ScheduleMicroBenchmark( |
1276 const std::string& benchmark_name, | 1276 const std::string& benchmark_name, |
1277 scoped_ptr<base::Value> value, | 1277 scoped_ptr<base::Value> value, |
1278 const MicroBenchmark::DoneCallback& callback) { | 1278 const MicroBenchmark::DoneCallback& callback) { |
1279 return micro_benchmark_controller_.ScheduleRun( | 1279 return micro_benchmark_controller_.ScheduleRun( |
1280 benchmark_name, value.Pass(), callback); | 1280 benchmark_name, value.Pass(), callback); |
1281 } | 1281 } |
1282 | 1282 |
1283 } // namespace cc | 1283 } // namespace cc |
OLD | NEW |