| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 210 } |
| 211 | 211 |
| 212 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) | 212 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) |
| 213 : micro_benchmark_controller_(this), | 213 : micro_benchmark_controller_(this), |
| 214 next_ui_resource_id_(1), | 214 next_ui_resource_id_(1), |
| 215 compositor_mode_(mode), | 215 compositor_mode_(mode), |
| 216 needs_full_tree_sync_(true), | 216 needs_full_tree_sync_(true), |
| 217 needs_meta_info_recomputation_(true), | 217 needs_meta_info_recomputation_(true), |
| 218 client_(params->client), | 218 client_(params->client), |
| 219 source_frame_number_(0), | 219 source_frame_number_(0), |
| 220 meta_information_sequence_number_(1), | |
| 221 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), | 220 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
| 222 output_surface_lost_(true), | 221 output_surface_lost_(true), |
| 223 settings_(*params->settings), | 222 settings_(*params->settings), |
| 224 debug_state_(settings_.initial_debug_state), | 223 debug_state_(settings_.initial_debug_state), |
| 225 top_controls_shrink_blink_size_(false), | 224 top_controls_shrink_blink_size_(false), |
| 226 top_controls_height_(0.f), | 225 top_controls_height_(0.f), |
| 227 top_controls_shown_ratio_(0.f), | 226 top_controls_shown_ratio_(0.f), |
| 228 device_scale_factor_(1.f), | 227 device_scale_factor_(1.f), |
| 229 painted_device_scale_factor_(1.f), | 228 painted_device_scale_factor_(1.f), |
| 230 visible_(false), | 229 visible_(false), |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 | 648 |
| 650 void LayerTreeHost::FinishAllRendering() { | 649 void LayerTreeHost::FinishAllRendering() { |
| 651 proxy_->FinishAllRendering(); | 650 proxy_->FinishAllRendering(); |
| 652 } | 651 } |
| 653 | 652 |
| 654 void LayerTreeHost::SetDeferCommits(bool defer_commits) { | 653 void LayerTreeHost::SetDeferCommits(bool defer_commits) { |
| 655 proxy_->SetDeferCommits(defer_commits); | 654 proxy_->SetDeferCommits(defer_commits); |
| 656 } | 655 } |
| 657 | 656 |
| 658 void LayerTreeHost::SetNeedsDisplayOnAllLayers() { | 657 void LayerTreeHost::SetNeedsDisplayOnAllLayers() { |
| 659 std::stack<Layer*> layer_stack; | 658 for (auto* layer : *this) |
| 660 layer_stack.push(root_layer()); | 659 layer->SetNeedsDisplay(); |
| 661 while (!layer_stack.empty()) { | |
| 662 Layer* current_layer = layer_stack.top(); | |
| 663 layer_stack.pop(); | |
| 664 current_layer->SetNeedsDisplay(); | |
| 665 for (unsigned int i = 0; i < current_layer->children().size(); i++) { | |
| 666 layer_stack.push(current_layer->child_at(i)); | |
| 667 } | |
| 668 } | |
| 669 } | 660 } |
| 670 | 661 |
| 671 void LayerTreeHost::SetOutputIsSecure(bool output_is_secure) { | 662 void LayerTreeHost::SetOutputIsSecure(bool output_is_secure) { |
| 672 proxy_->SetOutputIsSecure(output_is_secure); | 663 proxy_->SetOutputIsSecure(output_is_secure); |
| 673 } | 664 } |
| 674 | 665 |
| 675 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const { | 666 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const { |
| 676 return proxy_->GetRendererCapabilities(); | 667 return proxy_->GetRendererCapabilities(); |
| 677 } | 668 } |
| 678 | 669 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 } | 894 } |
| 904 | 895 |
| 905 LayerListIterator<Layer> LayerTreeHost::begin() { | 896 LayerListIterator<Layer> LayerTreeHost::begin() { |
| 906 return LayerListIterator<Layer>(root_layer_.get()); | 897 return LayerListIterator<Layer>(root_layer_.get()); |
| 907 } | 898 } |
| 908 | 899 |
| 909 LayerListIterator<Layer> LayerTreeHost::end() { | 900 LayerListIterator<Layer> LayerTreeHost::end() { |
| 910 return LayerListIterator<Layer>(nullptr); | 901 return LayerListIterator<Layer>(nullptr); |
| 911 } | 902 } |
| 912 | 903 |
| 904 const LayerListIterator<Layer> LayerTreeHost::begin() const { |
| 905 return LayerListIterator<Layer>(root_layer_.get()); |
| 906 } |
| 907 |
| 908 const LayerListIterator<Layer> LayerTreeHost::end() const { |
| 909 return LayerListIterator<Layer>(nullptr); |
| 910 } |
| 911 |
| 913 LayerListReverseIterator<Layer> LayerTreeHost::rbegin() { | 912 LayerListReverseIterator<Layer> LayerTreeHost::rbegin() { |
| 914 return LayerListReverseIterator<Layer>(root_layer_.get()); | 913 return LayerListReverseIterator<Layer>(root_layer_.get()); |
| 915 } | 914 } |
| 916 | 915 |
| 917 LayerListReverseIterator<Layer> LayerTreeHost::rend() { | 916 LayerListReverseIterator<Layer> LayerTreeHost::rend() { |
| 918 return LayerListReverseIterator<Layer>(nullptr); | 917 return LayerListReverseIterator<Layer>(nullptr); |
| 919 } | 918 } |
| 920 | 919 |
| 921 void LayerTreeHost::DidCompletePageScaleAnimation() { | 920 void LayerTreeHost::DidCompletePageScaleAnimation() { |
| 922 did_complete_scale_animation_ = true; | 921 did_complete_scale_animation_ = true; |
| 923 } | 922 } |
| 924 | 923 |
| 925 static Layer* FindFirstScrollableLayer(Layer* layer) { | |
| 926 if (!layer) | |
| 927 return NULL; | |
| 928 | |
| 929 if (layer->scrollable()) | |
| 930 return layer; | |
| 931 | |
| 932 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 933 Layer* found = FindFirstScrollableLayer(layer->children()[i].get()); | |
| 934 if (found) | |
| 935 return found; | |
| 936 } | |
| 937 | |
| 938 return NULL; | |
| 939 } | |
| 940 | |
| 941 void LayerTreeHost::RecordGpuRasterizationHistogram() { | 924 void LayerTreeHost::RecordGpuRasterizationHistogram() { |
| 942 // Gpu rasterization is only supported for Renderer compositors. | 925 // Gpu rasterization is only supported for Renderer compositors. |
| 943 // Checking for IsSingleThreaded() to exclude Browser compositors. | 926 // Checking for IsSingleThreaded() to exclude Browser compositors. |
| 944 if (gpu_rasterization_histogram_recorded_ || IsSingleThreaded()) | 927 if (gpu_rasterization_histogram_recorded_ || IsSingleThreaded()) |
| 945 return; | 928 return; |
| 946 | 929 |
| 947 // Record how widely gpu rasterization is enabled. | 930 // Record how widely gpu rasterization is enabled. |
| 948 // This number takes device/gpu whitelisting/backlisting into account. | 931 // This number takes device/gpu whitelisting/backlisting into account. |
| 949 // Note that we do not consider the forced gpu rasterization mode, which is | 932 // Note that we do not consider the forced gpu rasterization mode, which is |
| 950 // mostly used for debugging purposes. | 933 // mostly used for debugging purposes. |
| 951 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled", | 934 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled", |
| 952 settings_.gpu_rasterization_enabled); | 935 settings_.gpu_rasterization_enabled); |
| 953 if (settings_.gpu_rasterization_enabled) { | 936 if (settings_.gpu_rasterization_enabled) { |
| 954 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered", | 937 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered", |
| 955 has_gpu_rasterization_trigger_); | 938 has_gpu_rasterization_trigger_); |
| 956 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationSuitableContent", | 939 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationSuitableContent", |
| 957 content_is_suitable_for_gpu_rasterization_); | 940 content_is_suitable_for_gpu_rasterization_); |
| 958 // Record how many pages actually get gpu rasterization when enabled. | 941 // Record how many pages actually get gpu rasterization when enabled. |
| 959 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationUsed", | 942 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationUsed", |
| 960 (has_gpu_rasterization_trigger_ && | 943 (has_gpu_rasterization_trigger_ && |
| 961 content_is_suitable_for_gpu_rasterization_)); | 944 content_is_suitable_for_gpu_rasterization_)); |
| 962 } | 945 } |
| 963 | 946 |
| 964 gpu_rasterization_histogram_recorded_ = true; | 947 gpu_rasterization_histogram_recorded_ = true; |
| 965 } | 948 } |
| 966 | 949 |
| 967 void LayerTreeHost::BuildPropertyTreesForTesting() { | 950 void LayerTreeHost::BuildPropertyTreesForTesting() { |
| 968 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root_layer_.get()); | 951 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer_.get()); |
| 969 gfx::Transform identity_transform; | 952 gfx::Transform identity_transform; |
| 970 PropertyTreeBuilder::BuildPropertyTrees( | 953 PropertyTreeBuilder::BuildPropertyTrees( |
| 971 root_layer_.get(), page_scale_layer_.get(), | 954 root_layer_.get(), page_scale_layer_.get(), |
| 972 inner_viewport_scroll_layer_.get(), outer_viewport_scroll_layer_.get(), | 955 inner_viewport_scroll_layer_.get(), outer_viewport_scroll_layer_.get(), |
| 973 overscroll_elasticity_layer_.get(), elastic_overscroll_, | 956 overscroll_elasticity_layer_.get(), elastic_overscroll_, |
| 974 page_scale_factor_, device_scale_factor_, | 957 page_scale_factor_, device_scale_factor_, |
| 975 gfx::Rect(device_viewport_size_), identity_transform, &property_trees_); | 958 gfx::Rect(device_viewport_size_), identity_transform, &property_trees_); |
| 976 } | 959 } |
| 977 | 960 |
| 978 bool LayerTreeHost::UsingSharedMemoryResources() { | 961 bool LayerTreeHost::UsingSharedMemoryResources() { |
| 979 return GetRendererCapabilities().using_shared_memory_resources; | 962 return GetRendererCapabilities().using_shared_memory_resources; |
| 980 } | 963 } |
| 981 | 964 |
| 982 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) { | 965 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) { |
| 983 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number", | 966 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number", |
| 984 source_frame_number()); | 967 source_frame_number()); |
| 985 | 968 |
| 986 UpdateHudLayer(); | 969 UpdateHudLayer(); |
| 987 | 970 |
| 988 Layer* root_scroll = FindFirstScrollableLayer(root_layer); | 971 Layer* root_scroll = |
| 972 PropertyTreeBuilder::FindFirstScrollableLayer(root_layer); |
| 989 Layer* page_scale_layer = page_scale_layer_.get(); | 973 Layer* page_scale_layer = page_scale_layer_.get(); |
| 990 if (!page_scale_layer && root_scroll) | 974 if (!page_scale_layer && root_scroll) |
| 991 page_scale_layer = root_scroll->parent(); | 975 page_scale_layer = root_scroll->parent(); |
| 992 | 976 |
| 993 if (hud_layer_.get()) { | 977 if (hud_layer_.get()) { |
| 994 hud_layer_->PrepareForCalculateDrawProperties(device_viewport_size(), | 978 hud_layer_->PrepareForCalculateDrawProperties(device_viewport_size(), |
| 995 device_scale_factor_); | 979 device_scale_factor_); |
| 996 } | 980 } |
| 997 | 981 |
| 998 gfx::Transform identity_transform; | 982 gfx::Transform identity_transform; |
| 999 LayerList update_layer_list; | 983 LayerList update_layer_list; |
| 1000 | 984 |
| 1001 { | 985 { |
| 1002 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::BuildPropertyTrees"); | 986 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::BuildPropertyTrees"); |
| 1003 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), | 987 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), |
| 1004 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTrees"); | 988 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTrees"); |
| 1005 LayerTreeHostCommon::PreCalculateMetaInformation(root_layer); | 989 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 1006 bool can_render_to_separate_surface = true; | 990 bool can_render_to_separate_surface = true; |
| 1007 PropertyTreeBuilder::BuildPropertyTrees( | 991 PropertyTreeBuilder::BuildPropertyTrees( |
| 1008 root_layer, page_scale_layer, inner_viewport_scroll_layer_.get(), | 992 root_layer, page_scale_layer, inner_viewport_scroll_layer_.get(), |
| 1009 outer_viewport_scroll_layer_.get(), overscroll_elasticity_layer_.get(), | 993 outer_viewport_scroll_layer_.get(), overscroll_elasticity_layer_.get(), |
| 1010 elastic_overscroll_, page_scale_factor_, device_scale_factor_, | 994 elastic_overscroll_, page_scale_factor_, device_scale_factor_, |
| 1011 gfx::Rect(device_viewport_size_), identity_transform, &property_trees_); | 995 gfx::Rect(device_viewport_size_), identity_transform, &property_trees_); |
| 1012 draw_property_utils::UpdateRenderSurfaces(root_layer, &property_trees_); | 996 draw_property_utils::UpdateRenderSurfaces(root_layer, &property_trees_); |
| 1013 draw_property_utils::UpdatePropertyTrees(&property_trees_, | 997 draw_property_utils::UpdatePropertyTrees(&property_trees_, |
| 1014 can_render_to_separate_surface); | 998 can_render_to_separate_surface); |
| 1015 draw_property_utils::FindLayersThatNeedUpdates( | 999 draw_property_utils::FindLayersThatNeedUpdates( |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 // LayerTreeHost, so they are serialized outside of the LayerTreeHost | 1480 // LayerTreeHost, so they are serialized outside of the LayerTreeHost |
| 1497 // serialization. | 1481 // serialization. |
| 1498 // - The |visible_| flag will be controlled from the client separately and | 1482 // - The |visible_| flag will be controlled from the client separately and |
| 1499 // will need special handling outside of the serialization of the | 1483 // will need special handling outside of the serialization of the |
| 1500 // LayerTreeHost. | 1484 // LayerTreeHost. |
| 1501 // TODO(nyquist): Figure out how to support animations. See crbug.com/570376. | 1485 // TODO(nyquist): Figure out how to support animations. See crbug.com/570376. |
| 1502 TRACE_EVENT0("cc.remote", "LayerTreeHost::ToProtobufForCommit"); | 1486 TRACE_EVENT0("cc.remote", "LayerTreeHost::ToProtobufForCommit"); |
| 1503 proto->set_needs_full_tree_sync(needs_full_tree_sync_); | 1487 proto->set_needs_full_tree_sync(needs_full_tree_sync_); |
| 1504 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); | 1488 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); |
| 1505 proto->set_source_frame_number(source_frame_number_); | 1489 proto->set_source_frame_number(source_frame_number_); |
| 1506 proto->set_meta_information_sequence_number( | |
| 1507 meta_information_sequence_number_); | |
| 1508 | 1490 |
| 1509 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, | 1491 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, |
| 1510 proto->mutable_root_layer()); | 1492 proto->mutable_root_layer()); |
| 1511 | 1493 |
| 1512 // layers_that_should_push_properties_ should be serialized before layer | 1494 // layers_that_should_push_properties_ should be serialized before layer |
| 1513 // properties because it is cleared during the properties serialization. | 1495 // properties because it is cleared during the properties serialization. |
| 1514 for (auto layer : layers_that_should_push_properties_) | 1496 for (auto layer : layers_that_should_push_properties_) |
| 1515 proto->add_layers_that_should_push_properties(layer->id()); | 1497 proto->add_layers_that_should_push_properties(layer->id()); |
| 1516 | 1498 |
| 1517 LayerProtoConverter::SerializeLayerProperties(this, | 1499 LayerProtoConverter::SerializeLayerProperties(this, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 | 1551 |
| 1570 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 1552 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 1571 "cc.remote", "LayerTreeHostProto", source_frame_number_, | 1553 "cc.remote", "LayerTreeHostProto", source_frame_number_, |
| 1572 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); | 1554 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); |
| 1573 } | 1555 } |
| 1574 | 1556 |
| 1575 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { | 1557 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { |
| 1576 needs_full_tree_sync_ = proto.needs_full_tree_sync(); | 1558 needs_full_tree_sync_ = proto.needs_full_tree_sync(); |
| 1577 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); | 1559 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); |
| 1578 source_frame_number_ = proto.source_frame_number(); | 1560 source_frame_number_ = proto.source_frame_number(); |
| 1579 meta_information_sequence_number_ = proto.meta_information_sequence_number(); | |
| 1580 | 1561 |
| 1581 // Layer hierarchy. | 1562 // Layer hierarchy. |
| 1582 scoped_refptr<Layer> new_root_layer = | 1563 scoped_refptr<Layer> new_root_layer = |
| 1583 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, | 1564 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, |
| 1584 proto.root_layer(), this); | 1565 proto.root_layer(), this); |
| 1585 if (root_layer_ != new_root_layer) { | 1566 if (root_layer_ != new_root_layer) { |
| 1586 root_layer_ = new_root_layer; | 1567 root_layer_ = new_root_layer; |
| 1587 } | 1568 } |
| 1588 | 1569 |
| 1589 for (auto layer_id : proto.layers_that_should_push_properties()) | 1570 for (auto layer_id : proto.layers_that_should_push_properties()) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1653 int seq_num = property_trees_.sequence_number; | 1634 int seq_num = property_trees_.sequence_number; |
| 1654 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { | 1635 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { |
| 1655 layer->set_property_tree_sequence_number(seq_num); | 1636 layer->set_property_tree_sequence_number(seq_num); |
| 1656 }); | 1637 }); |
| 1657 | 1638 |
| 1658 surface_id_namespace_ = proto.surface_id_namespace(); | 1639 surface_id_namespace_ = proto.surface_id_namespace(); |
| 1659 next_surface_sequence_ = proto.next_surface_sequence(); | 1640 next_surface_sequence_ = proto.next_surface_sequence(); |
| 1660 } | 1641 } |
| 1661 | 1642 |
| 1662 } // namespace cc | 1643 } // namespace cc |
| OLD | NEW |