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 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 RendererCapabilities::~RendererCapabilities() {} | 71 RendererCapabilities::~RendererCapabilities() {} |
72 | 72 |
73 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded( | 73 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded( |
74 LayerTreeHostClient* client, | 74 LayerTreeHostClient* client, |
75 SharedBitmapManager* manager, | 75 SharedBitmapManager* manager, |
76 const LayerTreeSettings& settings, | 76 const LayerTreeSettings& settings, |
77 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 77 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
78 DCHECK(impl_task_runner); | 78 DCHECK(impl_task_runner); |
79 scoped_ptr<LayerTreeHost> layer_tree_host( | 79 scoped_ptr<LayerTreeHost> layer_tree_host( |
80 new LayerTreeHost(client, manager, settings)); | 80 new LayerTreeHost(client, manager, settings)); |
81 if (!layer_tree_host->InitializeThreaded(impl_task_runner)) | 81 layer_tree_host->InitializeThreaded(impl_task_runner); |
82 return scoped_ptr<LayerTreeHost>(); | |
83 return layer_tree_host.Pass(); | 82 return layer_tree_host.Pass(); |
84 } | 83 } |
85 | 84 |
86 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded( | 85 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded( |
87 LayerTreeHostClient* client, | 86 LayerTreeHostClient* client, |
88 LayerTreeHostSingleThreadClient* single_thread_client, | 87 LayerTreeHostSingleThreadClient* single_thread_client, |
89 SharedBitmapManager* manager, | 88 SharedBitmapManager* manager, |
90 const LayerTreeSettings& settings) { | 89 const LayerTreeSettings& settings) { |
91 scoped_ptr<LayerTreeHost> layer_tree_host( | 90 scoped_ptr<LayerTreeHost> layer_tree_host( |
92 new LayerTreeHost(client, manager, settings)); | 91 new LayerTreeHost(client, manager, settings)); |
93 if (!layer_tree_host->InitializeSingleThreaded(single_thread_client)) | 92 layer_tree_host->InitializeSingleThreaded(single_thread_client); |
94 return scoped_ptr<LayerTreeHost>(); | |
95 return layer_tree_host.Pass(); | 93 return layer_tree_host.Pass(); |
96 } | 94 } |
97 | 95 |
98 | 96 |
99 LayerTreeHost::LayerTreeHost( | 97 LayerTreeHost::LayerTreeHost( |
100 LayerTreeHostClient* client, | 98 LayerTreeHostClient* client, |
101 SharedBitmapManager* manager, | 99 SharedBitmapManager* manager, |
102 const LayerTreeSettings& settings) | 100 const LayerTreeSettings& settings) |
103 : micro_benchmark_controller_(this), | 101 : micro_benchmark_controller_(this), |
104 next_ui_resource_id_(1), | 102 next_ui_resource_id_(1), |
105 animating_(false), | 103 animating_(false), |
106 needs_full_tree_sync_(true), | 104 needs_full_tree_sync_(true), |
107 needs_filter_context_(false), | 105 needs_filter_context_(false), |
108 client_(client), | 106 client_(client), |
109 source_frame_number_(0), | 107 source_frame_number_(0), |
110 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), | 108 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
| 109 client_ready_(false), |
111 output_surface_can_be_initialized_(true), | 110 output_surface_can_be_initialized_(true), |
112 output_surface_lost_(true), | 111 output_surface_lost_(true), |
113 num_failed_recreate_attempts_(0), | 112 num_failed_recreate_attempts_(0), |
114 settings_(settings), | 113 settings_(settings), |
115 debug_state_(settings.initial_debug_state), | 114 debug_state_(settings.initial_debug_state), |
116 overdraw_bottom_height_(0.f), | 115 overdraw_bottom_height_(0.f), |
117 device_scale_factor_(1.f), | 116 device_scale_factor_(1.f), |
118 visible_(true), | 117 visible_(true), |
119 page_scale_factor_(1.f), | 118 page_scale_factor_(1.f), |
120 min_page_scale_factor_(1.f), | 119 min_page_scale_factor_(1.f), |
121 max_page_scale_factor_(1.f), | 120 max_page_scale_factor_(1.f), |
122 trigger_idle_updates_(true), | 121 trigger_idle_updates_(true), |
123 background_color_(SK_ColorWHITE), | 122 background_color_(SK_ColorWHITE), |
124 has_transparent_background_(false), | 123 has_transparent_background_(false), |
125 partial_texture_update_requests_(0), | 124 partial_texture_update_requests_(0), |
126 in_paint_layer_contents_(false), | 125 in_paint_layer_contents_(false), |
127 total_frames_used_for_lcd_text_metrics_(0), | 126 total_frames_used_for_lcd_text_metrics_(0), |
128 tree_id_(GetNextTreeId()), | 127 tree_id_(GetNextTreeId()), |
129 next_commit_forces_redraw_(false), | 128 next_commit_forces_redraw_(false), |
130 shared_bitmap_manager_(manager) { | 129 shared_bitmap_manager_(manager) { |
131 if (settings_.accelerated_animation_enabled) | 130 if (settings_.accelerated_animation_enabled) |
132 animation_registrar_ = AnimationRegistrar::Create(); | 131 animation_registrar_ = AnimationRegistrar::Create(); |
133 rendering_stats_instrumentation_->set_record_rendering_stats( | 132 rendering_stats_instrumentation_->set_record_rendering_stats( |
134 debug_state_.RecordRenderingStats()); | 133 debug_state_.RecordRenderingStats()); |
135 } | 134 } |
136 | 135 |
137 bool LayerTreeHost::InitializeThreaded( | 136 void LayerTreeHost::InitializeThreaded( |
138 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 137 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
139 return InitializeProxy(ThreadProxy::Create(this, impl_task_runner)); | 138 InitializeProxy(ThreadProxy::Create(this, impl_task_runner)); |
140 } | 139 } |
141 | 140 |
142 bool LayerTreeHost::InitializeSingleThreaded( | 141 void LayerTreeHost::InitializeSingleThreaded( |
143 LayerTreeHostSingleThreadClient* single_thread_client) { | 142 LayerTreeHostSingleThreadClient* single_thread_client) { |
144 return InitializeProxy( | 143 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client)); |
145 SingleThreadProxy::Create(this, single_thread_client)); | |
146 } | 144 } |
147 | 145 |
148 bool LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) { | 146 void LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) { |
149 return InitializeProxy(proxy_for_testing.Pass()); | 147 InitializeProxy(proxy_for_testing.Pass()); |
150 } | 148 } |
151 | 149 |
152 bool LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) { | 150 void LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) { |
153 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); | 151 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); |
154 | 152 |
155 scoped_ptr<OutputSurface> output_surface(CreateOutputSurface()); | |
156 if (!output_surface) | |
157 return false; | |
158 | |
159 proxy_ = proxy.Pass(); | 153 proxy_ = proxy.Pass(); |
160 proxy_->Start(output_surface.Pass()); | 154 proxy_->Start(); |
161 return true; | |
162 } | 155 } |
163 | 156 |
164 LayerTreeHost::~LayerTreeHost() { | 157 LayerTreeHost::~LayerTreeHost() { |
165 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); | 158 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); |
166 | 159 |
167 overhang_ui_resource_.reset(); | 160 overhang_ui_resource_.reset(); |
168 | 161 |
169 if (root_layer_.get()) | 162 if (root_layer_.get()) |
170 root_layer_->SetLayerTreeHost(NULL); | 163 root_layer_->SetLayerTreeHost(NULL); |
171 | 164 |
172 if (proxy_) { | 165 if (proxy_) { |
173 DCHECK(proxy_->IsMainThread()); | 166 DCHECK(proxy_->IsMainThread()); |
174 proxy_->Stop(); | 167 proxy_->Stop(); |
175 } | 168 } |
176 | 169 |
177 if (root_layer_.get()) { | 170 if (root_layer_.get()) { |
178 // The layer tree must be destroyed before the layer tree host. We've | 171 // The layer tree must be destroyed before the layer tree host. We've |
179 // made a contract with our animation controllers that the registrar | 172 // made a contract with our animation controllers that the registrar |
180 // will outlive them, and we must make good. | 173 // will outlive them, and we must make good. |
181 root_layer_ = NULL; | 174 root_layer_ = NULL; |
182 } | 175 } |
183 } | 176 } |
184 | 177 |
185 void LayerTreeHost::SetLayerTreeHostClientReady() { | 178 void LayerTreeHost::SetLayerTreeHostClientReady( |
186 proxy_->SetLayerTreeHostClientReady(); | 179 scoped_ptr<OutputSurface> first_output_surface) { |
| 180 DCHECK(!client_ready_); |
| 181 client_ready_ = true; |
| 182 proxy_->SetLayerTreeHostClientReady(first_output_surface.Pass()); |
187 } | 183 } |
188 | 184 |
189 static void LayerTreeHostOnOutputSurfaceCreatedCallback(Layer* layer) { | 185 static void LayerTreeHostOnOutputSurfaceCreatedCallback(Layer* layer) { |
190 layer->OnOutputSurfaceCreated(); | 186 layer->OnOutputSurfaceCreated(); |
191 } | 187 } |
192 | 188 |
193 LayerTreeHost::CreateResult | 189 LayerTreeHost::CreateResult |
194 LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted(bool success) { | 190 LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted(bool success) { |
195 TRACE_EVENT1("cc", | 191 TRACE_EVENT1("cc", |
196 "LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted", | 192 "LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted", |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 | 1258 |
1263 bool LayerTreeHost::ScheduleMicroBenchmark( | 1259 bool LayerTreeHost::ScheduleMicroBenchmark( |
1264 const std::string& benchmark_name, | 1260 const std::string& benchmark_name, |
1265 scoped_ptr<base::Value> value, | 1261 scoped_ptr<base::Value> value, |
1266 const MicroBenchmark::DoneCallback& callback) { | 1262 const MicroBenchmark::DoneCallback& callback) { |
1267 return micro_benchmark_controller_.ScheduleRun( | 1263 return micro_benchmark_controller_.ScheduleRun( |
1268 benchmark_name, value.Pass(), callback); | 1264 benchmark_name, value.Pass(), callback); |
1269 } | 1265 } |
1270 | 1266 |
1271 } // namespace cc | 1267 } // namespace cc |
OLD | NEW |