| 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/layers/layer.h" | 5 #include "cc/layers/layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ | 52 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ |
| 53 do { \ | 53 do { \ |
| 54 EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times((expect)); \ | 54 EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times((expect)); \ |
| 55 code_to_test; \ | 55 code_to_test; \ |
| 56 Mock::VerifyAndClearExpectations(layer_tree_); \ | 56 Mock::VerifyAndClearExpectations(layer_tree_); \ |
| 57 } while (false) | 57 } while (false) |
| 58 | 58 |
| 59 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ | 59 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ |
| 60 code_to_test; \ | 60 code_to_test; \ |
| 61 root->layer_tree_host()->BuildPropertyTreesForTesting(); \ | 61 root->GetLayerTree()->BuildPropertyTreesForTesting(); \ |
| 62 EXPECT_TRUE(root->subtree_property_changed()); \ | 62 EXPECT_TRUE(root->subtree_property_changed()); \ |
| 63 EXPECT_TRUE( \ | 63 EXPECT_TRUE( \ |
| 64 root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ | 64 root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ |
| 65 EXPECT_TRUE(child->subtree_property_changed()); \ | 65 EXPECT_TRUE(child->subtree_property_changed()); \ |
| 66 EXPECT_TRUE( \ | 66 EXPECT_TRUE( \ |
| 67 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ | 67 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ |
| 68 EXPECT_TRUE(grand_child->subtree_property_changed()); \ | 68 EXPECT_TRUE(grand_child->subtree_property_changed()); \ |
| 69 EXPECT_TRUE(grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ | 69 EXPECT_TRUE(grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ |
| 70 grand_child.get())); | 70 grand_child.get())); |
| 71 | 71 |
| 72 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ | 72 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ |
| 73 code_to_test; \ | 73 code_to_test; \ |
| 74 EXPECT_FALSE(root->subtree_property_changed()); \ | 74 EXPECT_FALSE(root->subtree_property_changed()); \ |
| 75 EXPECT_FALSE( \ | 75 EXPECT_FALSE( \ |
| 76 root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ | 76 root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ |
| 77 EXPECT_FALSE(child->subtree_property_changed()); \ | 77 EXPECT_FALSE(child->subtree_property_changed()); \ |
| 78 EXPECT_FALSE( \ | 78 EXPECT_FALSE( \ |
| 79 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ | 79 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ |
| 80 EXPECT_FALSE(grand_child->subtree_property_changed()); \ | 80 EXPECT_FALSE(grand_child->subtree_property_changed()); \ |
| 81 EXPECT_FALSE( \ | 81 EXPECT_FALSE( \ |
| 82 grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ | 82 grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ |
| 83 grand_child.get())); | 83 grand_child.get())); |
| 84 | 84 |
| 85 #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(code_to_test) \ | 85 #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(code_to_test) \ |
| 86 code_to_test; \ | 86 code_to_test; \ |
| 87 root->layer_tree_host()->BuildPropertyTreesForTesting(); \ | 87 root->GetLayerTree()->BuildPropertyTreesForTesting(); \ |
| 88 EXPECT_TRUE(root->layer_property_changed()); \ | 88 EXPECT_TRUE(root->layer_property_changed()); \ |
| 89 EXPECT_FALSE(root->subtree_property_changed()); \ | 89 EXPECT_FALSE(root->subtree_property_changed()); \ |
| 90 EXPECT_TRUE( \ | 90 EXPECT_TRUE( \ |
| 91 root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ | 91 root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ |
| 92 EXPECT_FALSE(child->layer_property_changed()); \ | 92 EXPECT_FALSE(child->layer_property_changed()); \ |
| 93 EXPECT_FALSE(child->subtree_property_changed()); \ | 93 EXPECT_FALSE(child->subtree_property_changed()); \ |
| 94 EXPECT_FALSE( \ | 94 EXPECT_FALSE( \ |
| 95 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ | 95 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ |
| 96 EXPECT_FALSE(grand_child->layer_property_changed()); \ | 96 EXPECT_FALSE(grand_child->layer_property_changed()); \ |
| 97 EXPECT_FALSE(grand_child->subtree_property_changed()); \ | 97 EXPECT_FALSE(grand_child->subtree_property_changed()); \ |
| (...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1882 | 1882 |
| 1883 private: | 1883 private: |
| 1884 FakeLayerTreeHostClient client_; | 1884 FakeLayerTreeHostClient client_; |
| 1885 StubLayerTreeHostSingleThreadClient single_thread_client_; | 1885 StubLayerTreeHostSingleThreadClient single_thread_client_; |
| 1886 TestSharedBitmapManager shared_bitmap_manager_; | 1886 TestSharedBitmapManager shared_bitmap_manager_; |
| 1887 TestTaskGraphRunner task_graph_runner_; | 1887 TestTaskGraphRunner task_graph_runner_; |
| 1888 TestGpuMemoryBufferManager gpu_memory_buffer_manager_; | 1888 TestGpuMemoryBufferManager gpu_memory_buffer_manager_; |
| 1889 }; | 1889 }; |
| 1890 | 1890 |
| 1891 void AssertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) { | 1891 void AssertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) { |
| 1892 EXPECT_EQ(host, layer->layer_tree_host()); | 1892 EXPECT_EQ(host, layer->GetLayerTreeHostForTesting()); |
| 1893 | 1893 |
| 1894 for (size_t i = 0; i < layer->children().size(); ++i) | 1894 for (size_t i = 0; i < layer->children().size(); ++i) |
| 1895 AssertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); | 1895 AssertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); |
| 1896 | 1896 |
| 1897 if (layer->mask_layer()) | 1897 if (layer->mask_layer()) |
| 1898 AssertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host); | 1898 AssertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host); |
| 1899 | 1899 |
| 1900 if (layer->replica_layer()) | 1900 if (layer->replica_layer()) |
| 1901 AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); | 1901 AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); |
| 1902 } | 1902 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 } | 1936 } |
| 1937 | 1937 |
| 1938 TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { | 1938 TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { |
| 1939 scoped_refptr<Layer> parent = Layer::Create(); | 1939 scoped_refptr<Layer> parent = Layer::Create(); |
| 1940 LayerTreeHostFactory factory; | 1940 LayerTreeHostFactory factory; |
| 1941 std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 1941 std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
| 1942 LayerTree* layer_tree = layer_tree_host->GetLayerTree(); | 1942 LayerTree* layer_tree = layer_tree_host->GetLayerTree(); |
| 1943 | 1943 |
| 1944 layer_tree->SetRootLayer(parent.get()); | 1944 layer_tree->SetRootLayer(parent.get()); |
| 1945 | 1945 |
| 1946 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get()); | 1946 EXPECT_EQ(parent->GetLayerTreeHostForTesting(), layer_tree_host.get()); |
| 1947 | 1947 |
| 1948 // Adding a subtree to a layer already associated with a host should set the | 1948 // Adding a subtree to a layer already associated with a host should set the |
| 1949 // host pointer on all layers in that subtree. | 1949 // host pointer on all layers in that subtree. |
| 1950 scoped_refptr<Layer> child = Layer::Create(); | 1950 scoped_refptr<Layer> child = Layer::Create(); |
| 1951 scoped_refptr<Layer> grand_child = Layer::Create(); | 1951 scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1952 child->AddChild(grand_child); | 1952 child->AddChild(grand_child); |
| 1953 | 1953 |
| 1954 // Masks, replicas, and replica masks should pick up the new host too. | 1954 // Masks, replicas, and replica masks should pick up the new host too. |
| 1955 scoped_refptr<Layer> child_mask = Layer::Create(); | 1955 scoped_refptr<Layer> child_mask = Layer::Create(); |
| 1956 child->SetMaskLayer(child_mask.get()); | 1956 child->SetMaskLayer(child_mask.get()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2016 first_layer_tree_host.get()); | 2016 first_layer_tree_host.get()); |
| 2017 | 2017 |
| 2018 // Now reparent the subtree starting at second_child to a layer in a different | 2018 // Now reparent the subtree starting at second_child to a layer in a different |
| 2019 // tree. | 2019 // tree. |
| 2020 std::unique_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(); | 2020 std::unique_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(); |
| 2021 second_layer_tree_host->GetLayerTree()->SetRootLayer(second_parent.get()); | 2021 second_layer_tree_host->GetLayerTree()->SetRootLayer(second_parent.get()); |
| 2022 | 2022 |
| 2023 second_parent->AddChild(second_child); | 2023 second_parent->AddChild(second_child); |
| 2024 | 2024 |
| 2025 // The moved layer and its children should point to the new host. | 2025 // The moved layer and its children should point to the new host. |
| 2026 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host()); | |
| 2027 EXPECT_EQ(second_layer_tree_host.get(), | 2026 EXPECT_EQ(second_layer_tree_host.get(), |
| 2028 second_grand_child->layer_tree_host()); | 2027 second_child->GetLayerTreeHostForTesting()); |
| 2028 EXPECT_EQ(second_layer_tree_host.get(), |
| 2029 second_grand_child->GetLayerTreeHostForTesting()); |
| 2029 | 2030 |
| 2030 // Test over, cleanup time. | 2031 // Test over, cleanup time. |
| 2031 first_layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); | 2032 first_layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); |
| 2032 second_layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); | 2033 second_layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); |
| 2033 } | 2034 } |
| 2034 | 2035 |
| 2035 TEST_F(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { | 2036 TEST_F(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { |
| 2036 scoped_refptr<Layer> parent = Layer::Create(); | 2037 scoped_refptr<Layer> parent = Layer::Create(); |
| 2037 scoped_refptr<Layer> mask = Layer::Create(); | 2038 scoped_refptr<Layer> mask = Layer::Create(); |
| 2038 scoped_refptr<Layer> replica = Layer::Create(); | 2039 scoped_refptr<Layer> replica = Layer::Create(); |
| 2039 scoped_refptr<Layer> mask_child = Layer::Create(); | 2040 scoped_refptr<Layer> mask_child = Layer::Create(); |
| 2040 scoped_refptr<Layer> replica_child = Layer::Create(); | 2041 scoped_refptr<Layer> replica_child = Layer::Create(); |
| 2041 scoped_refptr<Layer> mask_replacement = Layer::Create(); | 2042 scoped_refptr<Layer> mask_replacement = Layer::Create(); |
| 2042 scoped_refptr<Layer> replica_replacement = Layer::Create(); | 2043 scoped_refptr<Layer> replica_replacement = Layer::Create(); |
| 2043 | 2044 |
| 2044 parent->SetMaskLayer(mask.get()); | 2045 parent->SetMaskLayer(mask.get()); |
| 2045 parent->SetReplicaLayer(replica.get()); | 2046 parent->SetReplicaLayer(replica.get()); |
| 2046 mask->AddChild(mask_child); | 2047 mask->AddChild(mask_child); |
| 2047 replica->AddChild(replica_child); | 2048 replica->AddChild(replica_child); |
| 2048 | 2049 |
| 2049 LayerTreeHostFactory factory; | 2050 LayerTreeHostFactory factory; |
| 2050 std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 2051 std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
| 2051 layer_tree_host->GetLayerTree()->SetRootLayer(parent.get()); | 2052 layer_tree_host->GetLayerTree()->SetRootLayer(parent.get()); |
| 2052 | 2053 |
| 2053 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 2054 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
| 2054 | 2055 |
| 2055 // Replacing the mask should clear out the old mask's subtree's host pointers. | 2056 // Replacing the mask should clear out the old mask's subtree's host pointers. |
| 2056 parent->SetMaskLayer(mask_replacement.get()); | 2057 parent->SetMaskLayer(mask_replacement.get()); |
| 2057 EXPECT_EQ(nullptr, mask->layer_tree_host()); | 2058 EXPECT_EQ(nullptr, mask->GetLayerTreeHostForTesting()); |
| 2058 EXPECT_EQ(nullptr, mask_child->layer_tree_host()); | 2059 EXPECT_EQ(nullptr, mask_child->GetLayerTreeHostForTesting()); |
| 2059 | 2060 |
| 2060 // Same for replacing a replica layer. | 2061 // Same for replacing a replica layer. |
| 2061 parent->SetReplicaLayer(replica_replacement.get()); | 2062 parent->SetReplicaLayer(replica_replacement.get()); |
| 2062 EXPECT_EQ(nullptr, replica->layer_tree_host()); | 2063 EXPECT_EQ(nullptr, replica->GetLayerTreeHostForTesting()); |
| 2063 EXPECT_EQ(nullptr, replica_child->layer_tree_host()); | 2064 EXPECT_EQ(nullptr, replica_child->GetLayerTreeHostForTesting()); |
| 2064 | 2065 |
| 2065 // Test over, cleanup time. | 2066 // Test over, cleanup time. |
| 2066 layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); | 2067 layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); |
| 2067 } | 2068 } |
| 2068 | 2069 |
| 2069 TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { | 2070 TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { |
| 2070 scoped_refptr<Layer> root = Layer::Create(); | 2071 scoped_refptr<Layer> root = Layer::Create(); |
| 2071 scoped_refptr<Layer> child = Layer::Create(); | 2072 scoped_refptr<Layer> child = Layer::Create(); |
| 2072 root->AddChild(child); | 2073 root->AddChild(child); |
| 2073 LayerTreeHostFactory factory; | 2074 LayerTreeHostFactory factory; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2086 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { | 2087 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { |
| 2087 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { | 2088 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { |
| 2088 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { | 2089 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { |
| 2089 layer->SetContentsOpaque(!!contents_opaque); | 2090 layer->SetContentsOpaque(!!contents_opaque); |
| 2090 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED | 2091 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED |
| 2091 : SK_ColorTRANSPARENT); | 2092 : SK_ColorTRANSPARENT); |
| 2092 layer_tree->set_background_color(host_opaque ? SK_ColorRED | 2093 layer_tree->set_background_color(host_opaque ? SK_ColorRED |
| 2093 : SK_ColorTRANSPARENT); | 2094 : SK_ColorTRANSPARENT); |
| 2094 | 2095 |
| 2095 layer_tree->property_trees()->needs_rebuild = true; | 2096 layer_tree->property_trees()->needs_rebuild = true; |
| 2096 layer_tree_host->BuildPropertyTreesForTesting(); | 2097 layer_tree_host->GetLayerTree()->BuildPropertyTreesForTesting(); |
| 2097 SkColor safe_color = layer->SafeOpaqueBackgroundColor(); | 2098 SkColor safe_color = layer->SafeOpaqueBackgroundColor(); |
| 2098 if (contents_opaque) { | 2099 if (contents_opaque) { |
| 2099 EXPECT_EQ(SkColorGetA(safe_color), 255u) | 2100 EXPECT_EQ(SkColorGetA(safe_color), 255u) |
| 2100 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " | 2101 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " |
| 2101 << host_opaque << "\n"; | 2102 << host_opaque << "\n"; |
| 2102 } else { | 2103 } else { |
| 2103 EXPECT_NE(SkColorGetA(safe_color), 255u) | 2104 EXPECT_NE(SkColorGetA(safe_color), 255u) |
| 2104 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " | 2105 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " |
| 2105 << host_opaque << "\n"; | 2106 << host_opaque << "\n"; |
| 2106 } | 2107 } |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2552 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); | 2553 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); |
| 2553 | 2554 |
| 2554 test_layer->PushPropertiesTo(impl_layer.get()); | 2555 test_layer->PushPropertiesTo(impl_layer.get()); |
| 2555 | 2556 |
| 2556 EXPECT_EQ(ElementId(2, 0), impl_layer->element_id()); | 2557 EXPECT_EQ(ElementId(2, 0), impl_layer->element_id()); |
| 2557 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); | 2558 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); |
| 2558 } | 2559 } |
| 2559 | 2560 |
| 2560 } // namespace | 2561 } // namespace |
| 2561 } // namespace cc | 2562 } // namespace cc |
| OLD | NEW |