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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 LayerTreeHost::~LayerTreeHost() { | 162 LayerTreeHost::~LayerTreeHost() { |
163 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); | 163 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); |
164 | 164 |
165 DCHECK(swap_promise_monitor_.empty()); | 165 DCHECK(swap_promise_monitor_.empty()); |
166 | 166 |
167 BreakSwapPromises(SwapPromise::COMMIT_FAILS); | 167 BreakSwapPromises(SwapPromise::COMMIT_FAILS); |
168 | 168 |
169 overhang_ui_resource_ = nullptr; | 169 overhang_ui_resource_ = nullptr; |
170 | 170 |
171 if (root_layer_.get()) | 171 if (root_layer_.get()) |
172 root_layer_->SetLayerTreeHost(NULL); | 172 root_layer_->SetLayerTreeHost(nullptr); |
173 | 173 |
174 if (proxy_) { | 174 if (proxy_) { |
175 DCHECK(proxy_->IsMainThread()); | 175 DCHECK(proxy_->IsMainThread()); |
176 proxy_->Stop(); | 176 proxy_->Stop(); |
177 } | 177 } |
178 | 178 |
179 // We must clear any pointers into the layer tree prior to destroying it. | 179 // We must clear any pointers into the layer tree prior to destroying it. |
180 RegisterViewportLayers(NULL, NULL, NULL); | 180 RegisterViewportLayers(nullptr, nullptr, nullptr); |
181 | 181 |
182 if (root_layer_.get()) { | 182 if (root_layer_.get()) { |
183 // The layer tree must be destroyed before the layer tree host. We've | 183 // The layer tree must be destroyed before the layer tree host. We've |
184 // made a contract with our animation controllers that the registrar | 184 // made a contract with our animation controllers that the registrar |
185 // will outlive them, and we must make good. | 185 // will outlive them, and we must make good. |
186 root_layer_ = NULL; | 186 root_layer_ = nullptr; |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 void LayerTreeHost::SetLayerTreeHostClientReady() { | 190 void LayerTreeHost::SetLayerTreeHostClientReady() { |
191 proxy_->SetLayerTreeHostClientReady(); | 191 proxy_->SetLayerTreeHostClientReady(); |
192 } | 192 } |
193 | 193 |
194 static void LayerTreeHostOnOutputSurfaceCreatedCallback(Layer* layer) { | 194 static void LayerTreeHostOnOutputSurfaceCreatedCallback(Layer* layer) { |
195 layer->OnOutputSurfaceCreated(); | 195 layer->OnOutputSurfaceCreated(); |
196 } | 196 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } | 313 } |
314 | 314 |
315 sync_tree->set_needs_full_tree_sync(needs_full_tree_sync_); | 315 sync_tree->set_needs_full_tree_sync(needs_full_tree_sync_); |
316 needs_full_tree_sync_ = false; | 316 needs_full_tree_sync_ = false; |
317 | 317 |
318 if (hud_layer_.get()) { | 318 if (hud_layer_.get()) { |
319 LayerImpl* hud_impl = LayerTreeHostCommon::FindLayerInSubtree( | 319 LayerImpl* hud_impl = LayerTreeHostCommon::FindLayerInSubtree( |
320 sync_tree->root_layer(), hud_layer_->id()); | 320 sync_tree->root_layer(), hud_layer_->id()); |
321 sync_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(hud_impl)); | 321 sync_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(hud_impl)); |
322 } else { | 322 } else { |
323 sync_tree->set_hud_layer(NULL); | 323 sync_tree->set_hud_layer(nullptr); |
324 } | 324 } |
325 | 325 |
326 sync_tree->set_background_color(background_color_); | 326 sync_tree->set_background_color(background_color_); |
327 sync_tree->set_has_transparent_background(has_transparent_background_); | 327 sync_tree->set_has_transparent_background(has_transparent_background_); |
328 | 328 |
329 if (page_scale_layer_.get() && inner_viewport_scroll_layer_.get()) { | 329 if (page_scale_layer_.get() && inner_viewport_scroll_layer_.get()) { |
330 sync_tree->SetViewportLayersFromIds(page_scale_layer_->id(), | 330 sync_tree->SetViewportLayersFromIds(page_scale_layer_->id(), |
331 inner_viewport_scroll_layer_->id(), | 331 inner_viewport_scroll_layer_->id(), |
332 outer_viewport_scroll_layer_.get() | 332 outer_viewport_scroll_layer_.get() |
333 ? outer_viewport_scroll_layer_->id() | 333 ? outer_viewport_scroll_layer_->id() |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 | 397 |
398 void LayerTreeHost::UpdateHudLayer() { | 398 void LayerTreeHost::UpdateHudLayer() { |
399 if (debug_state_.ShowHudInfo()) { | 399 if (debug_state_.ShowHudInfo()) { |
400 if (!hud_layer_.get()) | 400 if (!hud_layer_.get()) |
401 hud_layer_ = HeadsUpDisplayLayer::Create(); | 401 hud_layer_ = HeadsUpDisplayLayer::Create(); |
402 | 402 |
403 if (root_layer_.get() && !hud_layer_->parent()) | 403 if (root_layer_.get() && !hud_layer_->parent()) |
404 root_layer_->AddChild(hud_layer_); | 404 root_layer_->AddChild(hud_layer_); |
405 } else if (hud_layer_.get()) { | 405 } else if (hud_layer_.get()) { |
406 hud_layer_->RemoveFromParent(); | 406 hud_layer_->RemoveFromParent(); |
407 hud_layer_ = NULL; | 407 hud_layer_ = nullptr; |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
411 void LayerTreeHost::CommitComplete() { | 411 void LayerTreeHost::CommitComplete() { |
412 source_frame_number_++; | 412 source_frame_number_++; |
413 client_->DidCommit(); | 413 client_->DidCommit(); |
414 } | 414 } |
415 | 415 |
416 void LayerTreeHost::SetOutputSurface(scoped_ptr<OutputSurface> surface) { | 416 void LayerTreeHost::SetOutputSurface(scoped_ptr<OutputSurface> surface) { |
417 proxy_->SetOutputSurface(surface.Pass()); | 417 proxy_->SetOutputSurface(surface.Pass()); |
418 } | 418 } |
419 | 419 |
420 void LayerTreeHost::RequestNewOutputSurface() { | 420 void LayerTreeHost::RequestNewOutputSurface() { |
421 client_->RequestNewOutputSurface(num_failed_recreate_attempts_ >= 4); | 421 client_->RequestNewOutputSurface(num_failed_recreate_attempts_ >= 4); |
422 } | 422 } |
423 | 423 |
424 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 424 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
425 LayerTreeHostImplClient* client) { | 425 LayerTreeHostImplClient* client) { |
426 DCHECK(proxy_->IsImplThread()); | 426 DCHECK(proxy_->IsImplThread()); |
427 scoped_ptr<LayerTreeHostImpl> host_impl = | 427 scoped_ptr<LayerTreeHostImpl> host_impl = |
428 LayerTreeHostImpl::Create(settings_, | 428 LayerTreeHostImpl::Create(settings_, |
429 client, | 429 client, |
430 proxy_.get(), | 430 proxy_.get(), |
431 rendering_stats_instrumentation_.get(), | 431 rendering_stats_instrumentation_.get(), |
432 shared_bitmap_manager_, | 432 shared_bitmap_manager_, |
433 id_); | 433 id_); |
434 host_impl->SetUseGpuRasterization(UseGpuRasterization()); | 434 host_impl->SetUseGpuRasterization(UseGpuRasterization()); |
435 shared_bitmap_manager_ = NULL; | 435 shared_bitmap_manager_ = nullptr; |
436 if (settings_.calculate_top_controls_position && | 436 if (settings_.calculate_top_controls_position && |
437 host_impl->top_controls_manager()) { | 437 host_impl->top_controls_manager()) { |
438 top_controls_manager_weak_ptr_ = | 438 top_controls_manager_weak_ptr_ = |
439 host_impl->top_controls_manager()->AsWeakPtr(); | 439 host_impl->top_controls_manager()->AsWeakPtr(); |
440 } | 440 } |
441 input_handler_weak_ptr_ = host_impl->AsWeakPtr(); | 441 input_handler_weak_ptr_ = host_impl->AsWeakPtr(); |
442 return host_impl.Pass(); | 442 return host_impl.Pass(); |
443 } | 443 } |
444 | 444 |
445 void LayerTreeHost::DidLoseOutputSurface() { | 445 void LayerTreeHost::DidLoseOutputSurface() { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 } | 564 } |
565 } | 565 } |
566 } | 566 } |
567 } | 567 } |
568 | 568 |
569 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { | 569 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { |
570 if (root_layer_.get() == root_layer.get()) | 570 if (root_layer_.get() == root_layer.get()) |
571 return; | 571 return; |
572 | 572 |
573 if (root_layer_.get()) | 573 if (root_layer_.get()) |
574 root_layer_->SetLayerTreeHost(NULL); | 574 root_layer_->SetLayerTreeHost(nullptr); |
575 root_layer_ = root_layer; | 575 root_layer_ = root_layer; |
576 if (root_layer_.get()) { | 576 if (root_layer_.get()) { |
577 DCHECK(!root_layer_->parent()); | 577 DCHECK(!root_layer_->parent()); |
578 root_layer_->SetLayerTreeHost(this); | 578 root_layer_->SetLayerTreeHost(this); |
579 } | 579 } |
580 | 580 |
581 if (hud_layer_.get()) | 581 if (hud_layer_.get()) |
582 hud_layer_->RemoveFromParent(); | 582 hud_layer_->RemoveFromParent(); |
583 | 583 |
584 // Reset gpu rasterization flag. | 584 // Reset gpu rasterization flag. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 | 743 |
744 bool result = UpdateLayers(root_layer(), queue); | 744 bool result = UpdateLayers(root_layer(), queue); |
745 | 745 |
746 micro_benchmark_controller_.DidUpdateLayers(); | 746 micro_benchmark_controller_.DidUpdateLayers(); |
747 | 747 |
748 return result || next_commit_forces_redraw_; | 748 return result || next_commit_forces_redraw_; |
749 } | 749 } |
750 | 750 |
751 static Layer* FindFirstScrollableLayer(Layer* layer) { | 751 static Layer* FindFirstScrollableLayer(Layer* layer) { |
752 if (!layer) | 752 if (!layer) |
753 return NULL; | 753 return nullptr; |
754 | 754 |
755 if (layer->scrollable()) | 755 if (layer->scrollable()) |
756 return layer; | 756 return layer; |
757 | 757 |
758 for (size_t i = 0; i < layer->children().size(); ++i) { | 758 for (size_t i = 0; i < layer->children().size(); ++i) { |
759 Layer* found = FindFirstScrollableLayer(layer->children()[i].get()); | 759 Layer* found = FindFirstScrollableLayer(layer->children()[i].get()); |
760 if (found) | 760 if (found) |
761 return found; | 761 return found; |
762 } | 762 } |
763 | 763 |
764 return NULL; | 764 return nullptr; |
765 } | 765 } |
766 | 766 |
767 void LayerTreeHost::RecordGpuRasterizationHistogram() { | 767 void LayerTreeHost::RecordGpuRasterizationHistogram() { |
768 // Gpu rasterization is only supported when impl-side painting is enabled. | 768 // Gpu rasterization is only supported when impl-side painting is enabled. |
769 if (gpu_rasterization_histogram_recorded_ || !settings_.impl_side_painting) | 769 if (gpu_rasterization_histogram_recorded_ || !settings_.impl_side_painting) |
770 return; | 770 return; |
771 | 771 |
772 // Record how widely gpu rasterization is enabled. | 772 // Record how widely gpu rasterization is enabled. |
773 // This number takes device/gpu whitelisting/backlisting into account. | 773 // This number takes device/gpu whitelisting/backlisting into account. |
774 // Note that we do not consider the forced gpu rasterization mode, which is | 774 // Note that we do not consider the forced gpu rasterization mode, which is |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 ResourceUpdateQueue* queue, | 990 ResourceUpdateQueue* queue, |
991 bool* did_paint_content, | 991 bool* did_paint_content, |
992 bool* need_more_updates) { | 992 bool* need_more_updates) { |
993 // Note: Masks and replicas only exist for layers that own render surfaces. If | 993 // Note: Masks and replicas only exist for layers that own render surfaces. If |
994 // we reach this point in code, we already know that at least something will | 994 // we reach this point in code, we already know that at least something will |
995 // be drawn into this render surface, so the mask and replica should be | 995 // be drawn into this render surface, so the mask and replica should be |
996 // painted. | 996 // painted. |
997 | 997 |
998 Layer* mask_layer = render_surface_layer->mask_layer(); | 998 Layer* mask_layer = render_surface_layer->mask_layer(); |
999 if (mask_layer) { | 999 if (mask_layer) { |
1000 *did_paint_content |= mask_layer->Update(queue, NULL); | 1000 *did_paint_content |= mask_layer->Update(queue, nullptr); |
1001 *need_more_updates |= mask_layer->NeedMoreUpdates(); | 1001 *need_more_updates |= mask_layer->NeedMoreUpdates(); |
1002 } | 1002 } |
1003 | 1003 |
1004 Layer* replica_mask_layer = | 1004 Layer* replica_mask_layer = |
1005 render_surface_layer->replica_layer() ? | 1005 render_surface_layer->replica_layer() |
1006 render_surface_layer->replica_layer()->mask_layer() : NULL; | 1006 ? render_surface_layer->replica_layer()->mask_layer() |
| 1007 : nullptr; |
1007 if (replica_mask_layer) { | 1008 if (replica_mask_layer) { |
1008 *did_paint_content |= replica_mask_layer->Update(queue, NULL); | 1009 *did_paint_content |= replica_mask_layer->Update(queue, nullptr); |
1009 *need_more_updates |= replica_mask_layer->NeedMoreUpdates(); | 1010 *need_more_updates |= replica_mask_layer->NeedMoreUpdates(); |
1010 } | 1011 } |
1011 } | 1012 } |
1012 | 1013 |
1013 void LayerTreeHost::PaintLayerContents( | 1014 void LayerTreeHost::PaintLayerContents( |
1014 const RenderSurfaceLayerList& render_surface_layer_list, | 1015 const RenderSurfaceLayerList& render_surface_layer_list, |
1015 ResourceUpdateQueue* queue, | 1016 ResourceUpdateQueue* queue, |
1016 bool* did_paint_content, | 1017 bool* did_paint_content, |
1017 bool* need_more_updates) { | 1018 bool* need_more_updates) { |
1018 OcclusionTracker<Layer> occlusion_tracker( | 1019 OcclusionTracker<Layer> occlusion_tracker( |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 | 1217 |
1217 TRACE_EVENT0("cc", "LayerTreeHost::AnimateLayers"); | 1218 TRACE_EVENT0("cc", "LayerTreeHost::AnimateLayers"); |
1218 | 1219 |
1219 AnimationRegistrar::AnimationControllerMap copy = | 1220 AnimationRegistrar::AnimationControllerMap copy = |
1220 animation_registrar_->active_animation_controllers(); | 1221 animation_registrar_->active_animation_controllers(); |
1221 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); | 1222 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
1222 iter != copy.end(); | 1223 iter != copy.end(); |
1223 ++iter) { | 1224 ++iter) { |
1224 (*iter).second->Animate(monotonic_time); | 1225 (*iter).second->Animate(monotonic_time); |
1225 bool start_ready_animations = true; | 1226 bool start_ready_animations = true; |
1226 (*iter).second->UpdateState(start_ready_animations, NULL); | 1227 (*iter).second->UpdateState(start_ready_animations, nullptr); |
1227 } | 1228 } |
1228 } | 1229 } |
1229 | 1230 |
1230 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { | 1231 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { |
1231 DCHECK(client); | 1232 DCHECK(client); |
1232 | 1233 |
1233 UIResourceId next_id = next_ui_resource_id_++; | 1234 UIResourceId next_id = next_ui_resource_id_++; |
1234 DCHECK(ui_resource_client_map_.find(next_id) == | 1235 DCHECK(ui_resource_client_map_.find(next_id) == |
1235 ui_resource_client_map_.end()); | 1236 ui_resource_client_map_.end()); |
1236 | 1237 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 swap_promise_list_.push_back(swap_promise.Pass()); | 1335 swap_promise_list_.push_back(swap_promise.Pass()); |
1335 } | 1336 } |
1336 | 1337 |
1337 void LayerTreeHost::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) { | 1338 void LayerTreeHost::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) { |
1338 for (size_t i = 0; i < swap_promise_list_.size(); i++) | 1339 for (size_t i = 0; i < swap_promise_list_.size(); i++) |
1339 swap_promise_list_[i]->DidNotSwap(reason); | 1340 swap_promise_list_[i]->DidNotSwap(reason); |
1340 swap_promise_list_.clear(); | 1341 swap_promise_list_.clear(); |
1341 } | 1342 } |
1342 | 1343 |
1343 } // namespace cc | 1344 } // namespace cc |
OLD | NEW |