| 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 "cc/animation/keyframed_animation_curve.h" | 7 #include "cc/animation/keyframed_animation_curve.h" |
| 8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
| 9 #include "cc/base/thread.h" | 9 #include "cc/base/thread.h" |
| 10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
| 11 #include "cc/resources/layer_painter.h" | 11 #include "cc/resources/layer_painter.h" |
| 12 #include "cc/test/animation_test_common.h" | 12 #include "cc/test/animation_test_common.h" |
| 13 #include "cc/test/fake_impl_proxy.h" | 13 #include "cc/test/fake_impl_proxy.h" |
| 14 #include "cc/test/fake_layer_tree_host_client.h" | 14 #include "cc/test/fake_layer_tree_host_client.h" |
| 15 #include "cc/test/fake_layer_tree_host_impl.h" | 15 #include "cc/test/fake_layer_tree_host_impl.h" |
| 16 #include "cc/test/geometry_test_utils.h" | 16 #include "cc/test/geometry_test_utils.h" |
| 17 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
| 18 #include "cc/trees/single_thread_proxy.h" | 18 #include "cc/trees/single_thread_proxy.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/gfx/transform.h" | 21 #include "ui/gfx/transform.h" |
| 22 | 22 |
| 23 using ::testing::AnyNumber; | 23 using ::testing::AnyNumber; |
| 24 using ::testing::AtLeast; | 24 using ::testing::AtLeast; |
| 25 using ::testing::Mock; | 25 using ::testing::Mock; |
| 26 using ::testing::StrictMock; | 26 using ::testing::StrictMock; |
| 27 using ::testing::_; | 27 using ::testing::_; |
| 28 | 28 |
| 29 #define EXPECT_SET_NEEDS_COMMIT(expect, codeToTest) do { \ | 29 #define EXPECT_SET_NEEDS_COMMIT(expect, codeToTest) do { \ |
| 30 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \ | 30 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \ |
| 31 codeToTest; \ | 31 codeToTest; \ |
| 32 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ | 32 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ |
| 33 } while (0) | 33 } while (false) |
| 34 | 34 |
| 35 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, codeToTest) do { \ | 35 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, codeToTest) do { \ |
| 36 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect));
\ | 36 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ |
| 37 codeToTest; \ | 37 codeToTest; \ |
| 38 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
\ | 38 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ |
| 39 } while (0) | 39 } while (false) |
| 40 | 40 |
| 41 | 41 |
| 42 namespace cc { | 42 namespace cc { |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 class MockLayerImplTreeHost : public LayerTreeHost { | 45 class MockLayerTreeHost : public LayerTreeHost { |
| 46 public: | 46 public: |
| 47 MockLayerImplTreeHost() | 47 MockLayerTreeHost() |
| 48 : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) | 48 : LayerTreeHost(&fake_client_, LayerTreeSettings()) { |
| 49 { | 49 Initialize(scoped_ptr<Thread>(NULL)); |
| 50 Initialize(scoped_ptr<Thread>(NULL)); | 50 } |
| 51 } | 51 |
| 52 | 52 MOCK_METHOD0(SetNeedsCommit, void()); |
| 53 MOCK_METHOD0(SetNeedsCommit, void()); | 53 MOCK_METHOD0(SetNeedsFullTreeSync, void()); |
| 54 MOCK_METHOD0(SetNeedsFullTreeSync, void()); | 54 |
| 55 | 55 private: |
| 56 private: | 56 FakeLayerImplTreeHostClient fake_client_; |
| 57 FakeLayerImplTreeHostClient m_fakeClient; | |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 class MockLayerPainter : public LayerPainter { | 59 class MockLayerPainter : public LayerPainter { |
| 61 public: | 60 public: |
| 62 virtual void Paint(SkCanvas* canvas, gfx::Rect content_rect, gfx::RectF* opa
que) OVERRIDE { } | 61 virtual void Paint(SkCanvas* canvas, |
| 62 gfx::Rect content_rect, |
| 63 gfx::RectF* opaque) OVERRIDE {} |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 | 66 |
| 66 class LayerTest : public testing::Test { | 67 class LayerTest : public testing::Test { |
| 67 public: | 68 public: |
| 68 LayerTest() | 69 LayerTest() |
| 69 : m_hostImpl(&m_proxy) | 70 : host_impl_(&proxy_) {} |
| 70 { | 71 |
| 71 } | 72 protected: |
| 72 | 73 virtual void SetUp() OVERRIDE { |
| 73 protected: | 74 layer_tree_host_.reset(new StrictMock<MockLayerTreeHost>); |
| 74 virtual void SetUp() | 75 } |
| 75 { | 76 |
| 76 layer_tree_host_.reset(new StrictMock<MockLayerImplTreeHost>); | 77 virtual void TearDown() OVERRIDE { |
| 77 } | 78 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 78 | 79 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); |
| 79 virtual void TearDown() | 80 parent_ = NULL; |
| 80 { | 81 child1_ = NULL; |
| 81 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 82 child2_ = NULL; |
| 82 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()
); | 83 child3_ = NULL; |
| 83 parent_ = NULL; | 84 grand_child1_ = NULL; |
| 84 m_child1 = NULL; | 85 grand_child2_ = NULL; |
| 85 m_child2 = NULL; | 86 grand_child3_ = NULL; |
| 86 m_child3 = NULL; | 87 |
| 87 m_grandChild1 = NULL; | 88 layer_tree_host_->SetRootLayer(NULL); |
| 88 m_grandChild2 = NULL; | 89 layer_tree_host_.reset(); |
| 89 m_grandChild3 = NULL; | 90 } |
| 90 | 91 |
| 91 layer_tree_host_->SetRootLayer(NULL); | 92 void VerifyTestTreeInitialState() const { |
| 92 layer_tree_host_.reset(); | 93 ASSERT_EQ(3U, parent_->children().size()); |
| 93 } | 94 EXPECT_EQ(child1_, parent_->children()[0]); |
| 94 | 95 EXPECT_EQ(child2_, parent_->children()[1]); |
| 95 void verifyTestTreeInitialState() const | 96 EXPECT_EQ(child3_, parent_->children()[2]); |
| 96 { | 97 EXPECT_EQ(parent_.get(), child1_->parent()); |
| 97 ASSERT_EQ(3U, parent_->children().size()); | 98 EXPECT_EQ(parent_.get(), child2_->parent()); |
| 98 EXPECT_EQ(m_child1, parent_->children()[0]); | 99 EXPECT_EQ(parent_.get(), child3_->parent()); |
| 99 EXPECT_EQ(m_child2, parent_->children()[1]); | 100 |
| 100 EXPECT_EQ(m_child3, parent_->children()[2]); | 101 ASSERT_EQ(2U, child1_->children().size()); |
| 101 EXPECT_EQ(parent_.get(), m_child1->parent()); | 102 EXPECT_EQ(grand_child1_, child1_->children()[0]); |
| 102 EXPECT_EQ(parent_.get(), m_child2->parent()); | 103 EXPECT_EQ(grand_child2_, child1_->children()[1]); |
| 103 EXPECT_EQ(parent_.get(), m_child3->parent()); | 104 EXPECT_EQ(child1_.get(), grand_child1_->parent()); |
| 104 | 105 EXPECT_EQ(child1_.get(), grand_child2_->parent()); |
| 105 ASSERT_EQ(2U, m_child1->children().size()); | 106 |
| 106 EXPECT_EQ(m_grandChild1, m_child1->children()[0]); | 107 ASSERT_EQ(1U, child2_->children().size()); |
| 107 EXPECT_EQ(m_grandChild2, m_child1->children()[1]); | 108 EXPECT_EQ(grand_child3_, child2_->children()[0]); |
| 108 EXPECT_EQ(m_child1.get(), m_grandChild1->parent()); | 109 EXPECT_EQ(child2_.get(), grand_child3_->parent()); |
| 109 EXPECT_EQ(m_child1.get(), m_grandChild2->parent()); | 110 |
| 110 | 111 ASSERT_EQ(0U, child3_->children().size()); |
| 111 ASSERT_EQ(1U, m_child2->children().size()); | 112 } |
| 112 EXPECT_EQ(m_grandChild3, m_child2->children()[0]); | 113 |
| 113 EXPECT_EQ(m_child2.get(), m_grandChild3->parent()); | 114 void CreateSimpleTestTree() { |
| 114 | 115 parent_ = Layer::Create(); |
| 115 ASSERT_EQ(0U, m_child3->children().size()); | 116 child1_ = Layer::Create(); |
| 116 } | 117 child2_ = Layer::Create(); |
| 117 | 118 child3_ = Layer::Create(); |
| 118 void createSimpleTestTree() | 119 grand_child1_ = Layer::Create(); |
| 119 { | 120 grand_child2_ = Layer::Create(); |
| 120 parent_ = Layer::Create(); | 121 grand_child3_ = Layer::Create(); |
| 121 m_child1 = Layer::Create(); | 122 |
| 122 m_child2 = Layer::Create(); | 123 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); |
| 123 m_child3 = Layer::Create(); | 124 layer_tree_host_->SetRootLayer(parent_); |
| 124 m_grandChild1 = Layer::Create(); | 125 |
| 125 m_grandChild2 = Layer::Create(); | 126 parent_->AddChild(child1_); |
| 126 m_grandChild3 = Layer::Create(); | 127 parent_->AddChild(child2_); |
| 127 | 128 parent_->AddChild(child3_); |
| 128 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()
); | 129 child1_->AddChild(grand_child1_); |
| 129 layer_tree_host_->SetRootLayer(parent_); | 130 child1_->AddChild(grand_child2_); |
| 130 | 131 child2_->AddChild(grand_child3_); |
| 131 parent_->AddChild(m_child1); | 132 |
| 132 parent_->AddChild(m_child2); | 133 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 133 parent_->AddChild(m_child3); | 134 |
| 134 m_child1->AddChild(m_grandChild1); | 135 VerifyTestTreeInitialState(); |
| 135 m_child1->AddChild(m_grandChild2); | 136 } |
| 136 m_child2->AddChild(m_grandChild3); | 137 |
| 137 | 138 FakeImplProxy proxy_; |
| 138 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 139 FakeLayerTreeHostImpl host_impl_; |
| 139 | 140 |
| 140 verifyTestTreeInitialState(); | 141 scoped_ptr<StrictMock<MockLayerTreeHost> > layer_tree_host_; |
| 141 } | 142 scoped_refptr<Layer> parent_; |
| 142 | 143 scoped_refptr<Layer> child1_; |
| 143 FakeImplProxy m_proxy; | 144 scoped_refptr<Layer> child2_; |
| 144 FakeLayerTreeHostImpl m_hostImpl; | 145 scoped_refptr<Layer> child3_; |
| 145 | 146 scoped_refptr<Layer> grand_child1_; |
| 146 scoped_ptr<StrictMock<MockLayerImplTreeHost> > layer_tree_host_; | 147 scoped_refptr<Layer> grand_child2_; |
| 147 scoped_refptr<Layer> parent_; | 148 scoped_refptr<Layer> grand_child3_; |
| 148 scoped_refptr<Layer> m_child1; | |
| 149 scoped_refptr<Layer> m_child2; | |
| 150 scoped_refptr<Layer> m_child3; | |
| 151 scoped_refptr<Layer> m_grandChild1; | |
| 152 scoped_refptr<Layer> m_grandChild2; | |
| 153 scoped_refptr<Layer> m_grandChild3; | |
| 154 }; | 149 }; |
| 155 | 150 |
| 156 TEST_F(LayerTest, basicCreateAndDestroy) | 151 TEST_F(LayerTest, BasicCreateAndDestroy) { |
| 157 { | 152 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 158 scoped_refptr<Layer> testLayer = Layer::Create(); | 153 ASSERT_TRUE(test_layer); |
| 159 ASSERT_TRUE(testLayer); | 154 |
| 160 | 155 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
| 161 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 156 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
| 162 testLayer->SetLayerTreeHost(layer_tree_host_.get()); | 157 } |
| 163 } | 158 |
| 164 | 159 TEST_F(LayerTest, AddAndRemoveChild) { |
| 165 TEST_F(LayerTest, addAndRemoveChild) | 160 scoped_refptr<Layer> parent = Layer::Create(); |
| 166 { | 161 scoped_refptr<Layer> child = Layer::Create(); |
| 167 scoped_refptr<Layer> parent = Layer::Create(); | 162 |
| 168 scoped_refptr<Layer> child = Layer::Create(); | 163 // Upon creation, layers should not have children or parent. |
| 169 | 164 ASSERT_EQ(0U, parent->children().size()); |
| 170 // Upon creation, layers should not have children or parent. | 165 EXPECT_FALSE(child->parent()); |
| 171 ASSERT_EQ(0U, parent->children().size()); | 166 |
| 172 EXPECT_FALSE(child->parent()); | 167 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
| 173 | 168 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); |
| 174 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 169 |
| 175 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); | 170 ASSERT_EQ(1U, parent->children().size()); |
| 176 | 171 EXPECT_EQ(child.get(), parent->children()[0]); |
| 177 ASSERT_EQ(1U, parent->children().size()); | 172 EXPECT_EQ(parent.get(), child->parent()); |
| 178 EXPECT_EQ(child.get(), parent->children()[0]); | 173 EXPECT_EQ(parent.get(), child->RootLayer()); |
| 179 EXPECT_EQ(parent.get(), child->parent()); | 174 |
| 180 EXPECT_EQ(parent.get(), child->RootLayer()); | 175 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent()); |
| 181 | 176 } |
| 182 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent()); | 177 |
| 183 } | 178 TEST_F(LayerTest, AddSameChildTwice) { |
| 184 | 179 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); |
| 185 TEST_F(LayerTest, addSameChildTwice) | 180 |
| 186 { | 181 scoped_refptr<Layer> parent = Layer::Create(); |
| 187 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | 182 scoped_refptr<Layer> child = Layer::Create(); |
| 188 | 183 |
| 189 scoped_refptr<Layer> parent = Layer::Create(); | 184 layer_tree_host_->SetRootLayer(parent); |
| 190 scoped_refptr<Layer> child = Layer::Create(); | 185 |
| 191 | 186 ASSERT_EQ(0u, parent->children().size()); |
| 192 layer_tree_host_->SetRootLayer(parent); | 187 |
| 193 | 188 parent->AddChild(child); |
| 194 ASSERT_EQ(0u, parent->children().size()); | 189 ASSERT_EQ(1u, parent->children().size()); |
| 195 | 190 EXPECT_EQ(parent.get(), child->parent()); |
| 196 parent->AddChild(child); | 191 |
| 197 ASSERT_EQ(1u, parent->children().size()); | 192 parent->AddChild(child); |
| 198 EXPECT_EQ(parent.get(), child->parent()); | 193 ASSERT_EQ(1u, parent->children().size()); |
| 199 | 194 EXPECT_EQ(parent.get(), child->parent()); |
| 200 parent->AddChild(child); | 195 } |
| 201 ASSERT_EQ(1u, parent->children().size()); | 196 |
| 202 EXPECT_EQ(parent.get(), child->parent()); | 197 TEST_F(LayerTest, InsertChild) { |
| 203 } | 198 scoped_refptr<Layer> parent = Layer::Create(); |
| 204 | 199 scoped_refptr<Layer> child1 = Layer::Create(); |
| 205 TEST_F(LayerTest, insertChild) | 200 scoped_refptr<Layer> child2 = Layer::Create(); |
| 206 { | 201 scoped_refptr<Layer> child3 = Layer::Create(); |
| 207 scoped_refptr<Layer> parent = Layer::Create(); | 202 scoped_refptr<Layer> child4 = Layer::Create(); |
| 208 scoped_refptr<Layer> child1 = Layer::Create(); | 203 |
| 209 scoped_refptr<Layer> child2 = Layer::Create(); | 204 parent->SetLayerTreeHost(layer_tree_host_.get()); |
| 210 scoped_refptr<Layer> child3 = Layer::Create(); | 205 |
| 211 scoped_refptr<Layer> child4 = Layer::Create(); | 206 ASSERT_EQ(0U, parent->children().size()); |
| 212 | 207 |
| 213 parent->SetLayerTreeHost(layer_tree_host_.get()); | 208 // Case 1: inserting to empty list. |
| 214 | 209 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0)); |
| 215 ASSERT_EQ(0U, parent->children().size()); | 210 ASSERT_EQ(1U, parent->children().size()); |
| 216 | 211 EXPECT_EQ(child3, parent->children()[0]); |
| 217 // Case 1: inserting to empty list. | 212 EXPECT_EQ(parent.get(), child3->parent()); |
| 218 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0)); | 213 |
| 219 ASSERT_EQ(1U, parent->children().size()); | 214 // Case 2: inserting to beginning of list |
| 220 EXPECT_EQ(child3, parent->children()[0]); | 215 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
| 221 EXPECT_EQ(parent.get(), child3->parent()); | 216 ASSERT_EQ(2U, parent->children().size()); |
| 222 | 217 EXPECT_EQ(child1, parent->children()[0]); |
| 223 // Case 2: inserting to beginning of list | 218 EXPECT_EQ(child3, parent->children()[1]); |
| 224 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 219 EXPECT_EQ(parent.get(), child1->parent()); |
| 225 ASSERT_EQ(2U, parent->children().size()); | 220 |
| 226 EXPECT_EQ(child1, parent->children()[0]); | 221 // Case 3: inserting to middle of list |
| 227 EXPECT_EQ(child3, parent->children()[1]); | 222 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
| 228 EXPECT_EQ(parent.get(), child1->parent()); | 223 ASSERT_EQ(3U, parent->children().size()); |
| 229 | 224 EXPECT_EQ(child1, parent->children()[0]); |
| 230 // Case 3: inserting to middle of list | 225 EXPECT_EQ(child2, parent->children()[1]); |
| 231 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 226 EXPECT_EQ(child3, parent->children()[2]); |
| 232 ASSERT_EQ(3U, parent->children().size()); | 227 EXPECT_EQ(parent.get(), child2->parent()); |
| 233 EXPECT_EQ(child1, parent->children()[0]); | 228 |
| 234 EXPECT_EQ(child2, parent->children()[1]); | 229 // Case 4: inserting to end of list |
| 235 EXPECT_EQ(child3, parent->children()[2]); | 230 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child4, 3)); |
| 236 EXPECT_EQ(parent.get(), child2->parent()); | 231 |
| 237 | 232 ASSERT_EQ(4U, parent->children().size()); |
| 238 // Case 4: inserting to end of list | 233 EXPECT_EQ(child1, parent->children()[0]); |
| 239 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child4, 3)); | 234 EXPECT_EQ(child2, parent->children()[1]); |
| 240 | 235 EXPECT_EQ(child3, parent->children()[2]); |
| 241 ASSERT_EQ(4U, parent->children().size()); | 236 EXPECT_EQ(child4, parent->children()[3]); |
| 242 EXPECT_EQ(child1, parent->children()[0]); | 237 EXPECT_EQ(parent.get(), child4->parent()); |
| 243 EXPECT_EQ(child2, parent->children()[1]); | 238 |
| 244 EXPECT_EQ(child3, parent->children()[2]); | 239 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); |
| 245 EXPECT_EQ(child4, parent->children()[3]); | 240 } |
| 246 EXPECT_EQ(parent.get(), child4->parent()); | 241 |
| 247 | 242 TEST_F(LayerTest, InsertChildPastEndOfList) { |
| 248 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | 243 scoped_refptr<Layer> parent = Layer::Create(); |
| 249 } | 244 scoped_refptr<Layer> child1 = Layer::Create(); |
| 250 | 245 scoped_refptr<Layer> child2 = Layer::Create(); |
| 251 TEST_F(LayerTest, insertChildPastEndOfList) | 246 |
| 252 { | 247 ASSERT_EQ(0U, parent->children().size()); |
| 253 scoped_refptr<Layer> parent = Layer::Create(); | 248 |
| 254 scoped_refptr<Layer> child1 = Layer::Create(); | 249 // insert to an out-of-bounds index |
| 255 scoped_refptr<Layer> child2 = Layer::Create(); | 250 parent->InsertChild(child1, 53); |
| 256 | 251 |
| 257 ASSERT_EQ(0U, parent->children().size()); | 252 ASSERT_EQ(1U, parent->children().size()); |
| 258 | 253 EXPECT_EQ(child1, parent->children()[0]); |
| 259 // insert to an out-of-bounds index | 254 |
| 260 parent->InsertChild(child1, 53); | 255 // insert another child to out-of-bounds, when list is not already empty. |
| 261 | 256 parent->InsertChild(child2, 2459); |
| 262 ASSERT_EQ(1U, parent->children().size()); | 257 |
| 263 EXPECT_EQ(child1, parent->children()[0]); | 258 ASSERT_EQ(2U, parent->children().size()); |
| 264 | 259 EXPECT_EQ(child1, parent->children()[0]); |
| 265 // insert another child to out-of-bounds, when list is not already empty. | 260 EXPECT_EQ(child2, parent->children()[1]); |
| 266 parent->InsertChild(child2, 2459); | 261 } |
| 267 | 262 |
| 268 ASSERT_EQ(2U, parent->children().size()); | 263 TEST_F(LayerTest, InsertSameChildTwice) { |
| 269 EXPECT_EQ(child1, parent->children()[0]); | 264 scoped_refptr<Layer> parent = Layer::Create(); |
| 270 EXPECT_EQ(child2, parent->children()[1]); | 265 scoped_refptr<Layer> child1 = Layer::Create(); |
| 271 } | 266 scoped_refptr<Layer> child2 = Layer::Create(); |
| 272 | 267 |
| 273 TEST_F(LayerTest, insertSameChildTwice) | 268 parent->SetLayerTreeHost(layer_tree_host_.get()); |
| 274 { | 269 |
| 275 scoped_refptr<Layer> parent = Layer::Create(); | 270 ASSERT_EQ(0U, parent->children().size()); |
| 276 scoped_refptr<Layer> child1 = Layer::Create(); | 271 |
| 277 scoped_refptr<Layer> child2 = Layer::Create(); | 272 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
| 278 | 273 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
| 279 parent->SetLayerTreeHost(layer_tree_host_.get()); | 274 |
| 280 | 275 ASSERT_EQ(2U, parent->children().size()); |
| 281 ASSERT_EQ(0U, parent->children().size()); | 276 EXPECT_EQ(child1, parent->children()[0]); |
| 282 | 277 EXPECT_EQ(child2, parent->children()[1]); |
| 283 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 278 |
| 284 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 279 // Inserting the same child again should cause the child to be removed and |
| 285 | 280 // re-inserted at the new location. |
| 286 ASSERT_EQ(2U, parent->children().size()); | 281 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1)); |
| 287 EXPECT_EQ(child1, parent->children()[0]); | 282 |
| 288 EXPECT_EQ(child2, parent->children()[1]); | 283 // child1 should now be at the end of the list. |
| 289 | 284 ASSERT_EQ(2U, parent->children().size()); |
| 290 // Inserting the same child again should cause the child to be removed and r
e-inserted at the new location. | 285 EXPECT_EQ(child2, parent->children()[0]); |
| 291 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1)); | 286 EXPECT_EQ(child1, parent->children()[1]); |
| 292 | 287 |
| 293 // child1 should now be at the end of the list. | 288 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); |
| 294 ASSERT_EQ(2U, parent->children().size()); | 289 } |
| 295 EXPECT_EQ(child2, parent->children()[0]); | 290 |
| 296 EXPECT_EQ(child1, parent->children()[1]); | 291 TEST_F(LayerTest, ReplaceChildWithNewChild) { |
| 297 | 292 CreateSimpleTestTree(); |
| 298 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | 293 scoped_refptr<Layer> child4 = Layer::Create(); |
| 299 } | 294 |
| 300 | 295 EXPECT_FALSE(child4->parent()); |
| 301 TEST_F(LayerTest, replaceChildWithNewChild) | 296 |
| 302 { | 297 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 303 createSimpleTestTree(); | 298 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); |
| 304 scoped_refptr<Layer> child4 = Layer::Create(); | 299 EXPECT_FALSE(parent_->NeedsDisplayForTesting()); |
| 305 | 300 EXPECT_FALSE(child1_->NeedsDisplayForTesting()); |
| 306 EXPECT_FALSE(child4->parent()); | 301 EXPECT_FALSE(child2_->NeedsDisplayForTesting()); |
| 307 | 302 EXPECT_FALSE(child3_->NeedsDisplayForTesting()); |
| 308 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent_->ReplaceChild(m_child2.g
et(), child4)); | 303 EXPECT_FALSE(child4->NeedsDisplayForTesting()); |
| 309 EXPECT_FALSE(parent_->NeedsDisplayForTesting()); | 304 |
| 310 EXPECT_FALSE(m_child1->NeedsDisplayForTesting()); | 305 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size()); |
| 311 EXPECT_FALSE(m_child2->NeedsDisplayForTesting()); | 306 EXPECT_EQ(child1_, parent_->children()[0]); |
| 312 EXPECT_FALSE(m_child3->NeedsDisplayForTesting()); | 307 EXPECT_EQ(child4, parent_->children()[1]); |
| 313 EXPECT_FALSE(child4->NeedsDisplayForTesting()); | 308 EXPECT_EQ(child3_, parent_->children()[2]); |
| 314 | 309 EXPECT_EQ(parent_.get(), child4->parent()); |
| 315 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size()); | 310 |
| 316 EXPECT_EQ(m_child1, parent_->children()[0]); | 311 EXPECT_FALSE(child2_->parent()); |
| 317 EXPECT_EQ(child4, parent_->children()[1]); | 312 } |
| 318 EXPECT_EQ(m_child3, parent_->children()[2]); | 313 |
| 319 EXPECT_EQ(parent_.get(), child4->parent()); | 314 TEST_F(LayerTest, ReplaceChildWithNewChildAutomaticRasterScale) { |
| 320 | 315 CreateSimpleTestTree(); |
| 321 EXPECT_FALSE(m_child2->parent()); | 316 scoped_refptr<Layer> child4 = Layer::Create(); |
| 322 } | 317 EXPECT_SET_NEEDS_COMMIT(1, child1_->SetAutomaticallyComputeRasterScale(true)); |
| 323 | 318 EXPECT_SET_NEEDS_COMMIT(1, child2_->SetAutomaticallyComputeRasterScale(true)); |
| 324 TEST_F(LayerTest, replaceChildWithNewChildAutomaticRasterScale) | 319 EXPECT_SET_NEEDS_COMMIT(1, child3_->SetAutomaticallyComputeRasterScale(true)); |
| 325 { | 320 |
| 326 createSimpleTestTree(); | 321 EXPECT_FALSE(child4->parent()); |
| 327 scoped_refptr<Layer> child4 = Layer::Create(); | 322 |
| 328 EXPECT_SET_NEEDS_COMMIT(1, m_child1->SetAutomaticallyComputeRasterScale(true
)); | 323 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 329 EXPECT_SET_NEEDS_COMMIT(1, m_child2->SetAutomaticallyComputeRasterScale(true
)); | 324 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); |
| 330 EXPECT_SET_NEEDS_COMMIT(1, m_child3->SetAutomaticallyComputeRasterScale(true
)); | 325 EXPECT_FALSE(parent_->NeedsDisplayForTesting()); |
| 331 | 326 EXPECT_FALSE(child1_->NeedsDisplayForTesting()); |
| 332 EXPECT_FALSE(child4->parent()); | 327 EXPECT_FALSE(child2_->NeedsDisplayForTesting()); |
| 333 | 328 EXPECT_FALSE(child3_->NeedsDisplayForTesting()); |
| 334 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent_->ReplaceChild(m_child2.g
et(), child4)); | 329 EXPECT_FALSE(child4->NeedsDisplayForTesting()); |
| 335 EXPECT_FALSE(parent_->NeedsDisplayForTesting()); | 330 |
| 336 EXPECT_FALSE(m_child1->NeedsDisplayForTesting()); | 331 ASSERT_EQ(3U, parent_->children().size()); |
| 337 EXPECT_FALSE(m_child2->NeedsDisplayForTesting()); | 332 EXPECT_EQ(child1_, parent_->children()[0]); |
| 338 EXPECT_FALSE(m_child3->NeedsDisplayForTesting()); | 333 EXPECT_EQ(child4, parent_->children()[1]); |
| 339 EXPECT_FALSE(child4->NeedsDisplayForTesting()); | 334 EXPECT_EQ(child3_, parent_->children()[2]); |
| 340 | 335 EXPECT_EQ(parent_.get(), child4->parent()); |
| 341 ASSERT_EQ(3U, parent_->children().size()); | 336 |
| 342 EXPECT_EQ(m_child1, parent_->children()[0]); | 337 EXPECT_FALSE(child2_->parent()); |
| 343 EXPECT_EQ(child4, parent_->children()[1]); | 338 } |
| 344 EXPECT_EQ(m_child3, parent_->children()[2]); | 339 |
| 345 EXPECT_EQ(parent_.get(), child4->parent()); | 340 TEST_F(LayerTest, ReplaceChildWithNewChildThatHasOtherParent) { |
| 346 | 341 CreateSimpleTestTree(); |
| 347 EXPECT_FALSE(m_child2->parent()); | 342 |
| 348 } | 343 // create another simple tree with test_layer and child4. |
| 349 | 344 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 350 TEST_F(LayerTest, replaceChildWithNewChildThatHasOtherParent) | 345 scoped_refptr<Layer> child4 = Layer::Create(); |
| 351 { | 346 test_layer->AddChild(child4); |
| 352 createSimpleTestTree(); | 347 ASSERT_EQ(1U, test_layer->children().size()); |
| 353 | 348 EXPECT_EQ(child4, test_layer->children()[0]); |
| 354 // create another simple tree with testLayer and child4. | 349 EXPECT_EQ(test_layer.get(), child4->parent()); |
| 355 scoped_refptr<Layer> testLayer = Layer::Create(); | 350 |
| 356 scoped_refptr<Layer> child4 = Layer::Create(); | 351 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 357 testLayer->AddChild(child4); | 352 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); |
| 358 ASSERT_EQ(1U, testLayer->children().size()); | 353 |
| 359 EXPECT_EQ(child4, testLayer->children()[0]); | 354 ASSERT_EQ(3U, parent_->children().size()); |
| 360 EXPECT_EQ(testLayer.get(), child4->parent()); | 355 EXPECT_EQ(child1_, parent_->children()[0]); |
| 361 | 356 EXPECT_EQ(child4, parent_->children()[1]); |
| 362 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent_->ReplaceChild(m_child2.g
et(), child4)); | 357 EXPECT_EQ(child3_, parent_->children()[2]); |
| 363 | 358 EXPECT_EQ(parent_.get(), child4->parent()); |
| 364 ASSERT_EQ(3U, parent_->children().size()); | 359 |
| 365 EXPECT_EQ(m_child1, parent_->children()[0]); | 360 // test_layer should no longer have child4, |
| 366 EXPECT_EQ(child4, parent_->children()[1]); | 361 // and child2 should no longer have a parent. |
| 367 EXPECT_EQ(m_child3, parent_->children()[2]); | 362 ASSERT_EQ(0U, test_layer->children().size()); |
| 368 EXPECT_EQ(parent_.get(), child4->parent()); | 363 EXPECT_FALSE(child2_->parent()); |
| 369 | 364 } |
| 370 // testLayer should no longer have child4, | 365 |
| 371 // and child2 should no longer have a parent. | 366 TEST_F(LayerTest, ReplaceChildWithSameChild) { |
| 372 ASSERT_EQ(0U, testLayer->children().size()); | 367 CreateSimpleTestTree(); |
| 373 EXPECT_FALSE(m_child2->parent()); | 368 |
| 374 } | 369 // SetNeedsFullTreeSync / SetNeedsCommit should not be called because its the |
| 375 | 370 // same child. |
| 376 TEST_F(LayerTest, replaceChildWithSameChild) | 371 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
| 377 { | 372 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(0); |
| 378 createSimpleTestTree(); | 373 parent_->ReplaceChild(child2_.get(), child2_); |
| 379 | 374 |
| 380 // SetNeedsFullTreeSync / SetNeedsCommit should not be called because its th
e same child | 375 VerifyTestTreeInitialState(); |
| 381 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 376 } |
| 382 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(0); | 377 |
| 383 parent_->ReplaceChild(m_child2.get(), m_child2); | 378 TEST_F(LayerTest, RemoveAllChildren) { |
| 384 | 379 CreateSimpleTestTree(); |
| 385 verifyTestTreeInitialState(); | 380 |
| 386 } | 381 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren()); |
| 387 | 382 |
| 388 TEST_F(LayerTest, removeAllChildren) | 383 ASSERT_EQ(0U, parent_->children().size()); |
| 389 { | 384 EXPECT_FALSE(child1_->parent()); |
| 390 createSimpleTestTree(); | 385 EXPECT_FALSE(child2_->parent()); |
| 391 | 386 EXPECT_FALSE(child3_->parent()); |
| 392 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren()); | 387 } |
| 393 | 388 |
| 394 ASSERT_EQ(0U, parent_->children().size()); | 389 TEST_F(LayerTest, SetChildren) { |
| 395 EXPECT_FALSE(m_child1->parent()); | 390 scoped_refptr<Layer> old_parent = Layer::Create(); |
| 396 EXPECT_FALSE(m_child2->parent()); | 391 scoped_refptr<Layer> new_parent = Layer::Create(); |
| 397 EXPECT_FALSE(m_child3->parent()); | 392 |
| 398 } | 393 scoped_refptr<Layer> child1 = Layer::Create(); |
| 399 | 394 scoped_refptr<Layer> child2 = Layer::Create(); |
| 400 TEST_F(LayerTest, setChildren) | 395 |
| 401 { | 396 std::vector<scoped_refptr<Layer> > newChildren; |
| 402 scoped_refptr<Layer> oldParent = Layer::Create(); | 397 newChildren.push_back(child1); |
| 403 scoped_refptr<Layer> newParent = Layer::Create(); | 398 newChildren.push_back(child2); |
| 404 | 399 |
| 405 scoped_refptr<Layer> child1 = Layer::Create(); | 400 // Set up and verify initial test conditions: child1 has a parent, child2 has |
| 406 scoped_refptr<Layer> child2 = Layer::Create(); | 401 // no parent. |
| 407 | 402 old_parent->AddChild(child1); |
| 408 std::vector<scoped_refptr<Layer> > newChildren; | 403 ASSERT_EQ(0U, new_parent->children().size()); |
| 409 newChildren.push_back(child1); | 404 EXPECT_EQ(old_parent.get(), child1->parent()); |
| 410 newChildren.push_back(child2); | 405 EXPECT_FALSE(child2->parent()); |
| 411 | 406 |
| 412 // Set up and verify initial test conditions: child1 has a parent, child2 ha
s no parent. | 407 new_parent->SetLayerTreeHost(layer_tree_host_.get()); |
| 413 oldParent->AddChild(child1); | 408 |
| 414 ASSERT_EQ(0U, newParent->children().size()); | 409 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 415 EXPECT_EQ(oldParent.get(), child1->parent()); | 410 AtLeast(1), new_parent->SetChildren(newChildren)); |
| 416 EXPECT_FALSE(child2->parent()); | 411 |
| 417 | 412 ASSERT_EQ(2U, new_parent->children().size()); |
| 418 newParent->SetLayerTreeHost(layer_tree_host_.get()); | 413 EXPECT_EQ(new_parent.get(), child1->parent()); |
| 419 | 414 EXPECT_EQ(new_parent.get(), child2->parent()); |
| 420 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), newParent->SetChildren(newChildr
en)); | 415 |
| 421 | 416 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); |
| 422 ASSERT_EQ(2U, newParent->children().size()); | 417 } |
| 423 EXPECT_EQ(newParent.get(), child1->parent()); | 418 |
| 424 EXPECT_EQ(newParent.get(), child2->parent()); | 419 TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { |
| 425 | 420 CreateSimpleTestTree(); |
| 426 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | 421 |
| 427 } | 422 // For this test we don't care about SetNeedsFullTreeSync calls. |
| 428 | 423 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); |
| 429 TEST_F(LayerTest, getRootLayerAfterTreeManipulations) | 424 |
| 430 { | 425 scoped_refptr<Layer> child4 = Layer::Create(); |
| 431 createSimpleTestTree(); | 426 |
| 432 | 427 EXPECT_EQ(parent_.get(), parent_->RootLayer()); |
| 433 // For this test we don't care about SetNeedsFullTreeSync calls. | 428 EXPECT_EQ(parent_.get(), child1_->RootLayer()); |
| 434 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); | 429 EXPECT_EQ(parent_.get(), child2_->RootLayer()); |
| 435 | 430 EXPECT_EQ(parent_.get(), child3_->RootLayer()); |
| 436 scoped_refptr<Layer> child4 = Layer::Create(); | 431 EXPECT_EQ(child4.get(), child4->RootLayer()); |
| 437 | 432 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); |
| 438 EXPECT_EQ(parent_.get(), parent_->RootLayer()); | 433 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); |
| 439 EXPECT_EQ(parent_.get(), m_child1->RootLayer()); | 434 EXPECT_EQ(parent_.get(), grand_child3_->RootLayer()); |
| 440 EXPECT_EQ(parent_.get(), m_child2->RootLayer()); | 435 |
| 441 EXPECT_EQ(parent_.get(), m_child3->RootLayer()); | 436 child1_->RemoveFromParent(); |
| 442 EXPECT_EQ(child4.get(), child4->RootLayer()); | 437 |
| 443 EXPECT_EQ(parent_.get(), m_grandChild1->RootLayer()); | 438 // |child1| and its children, grand_child1 and grand_child2 are now on a |
| 444 EXPECT_EQ(parent_.get(), m_grandChild2->RootLayer()); | 439 // separate subtree. |
| 445 EXPECT_EQ(parent_.get(), m_grandChild3->RootLayer()); | 440 EXPECT_EQ(parent_.get(), parent_->RootLayer()); |
| 446 | 441 EXPECT_EQ(child1_.get(), child1_->RootLayer()); |
| 447 m_child1->RemoveFromParent(); | 442 EXPECT_EQ(parent_.get(), child2_->RootLayer()); |
| 448 | 443 EXPECT_EQ(parent_.get(), child3_->RootLayer()); |
| 449 // child1 and its children, grandChild1 and grandChild2 are now on a separat
e subtree. | 444 EXPECT_EQ(child4.get(), child4->RootLayer()); |
| 450 EXPECT_EQ(parent_.get(), parent_->RootLayer()); | 445 EXPECT_EQ(child1_.get(), grand_child1_->RootLayer()); |
| 451 EXPECT_EQ(m_child1.get(), m_child1->RootLayer()); | 446 EXPECT_EQ(child1_.get(), grand_child2_->RootLayer()); |
| 452 EXPECT_EQ(parent_.get(), m_child2->RootLayer()); | 447 EXPECT_EQ(parent_.get(), grand_child3_->RootLayer()); |
| 453 EXPECT_EQ(parent_.get(), m_child3->RootLayer()); | 448 |
| 454 EXPECT_EQ(child4.get(), child4->RootLayer()); | 449 grand_child3_->AddChild(child4); |
| 455 EXPECT_EQ(m_child1.get(), m_grandChild1->RootLayer()); | 450 |
| 456 EXPECT_EQ(m_child1.get(), m_grandChild2->RootLayer()); | 451 EXPECT_EQ(parent_.get(), parent_->RootLayer()); |
| 457 EXPECT_EQ(parent_.get(), m_grandChild3->RootLayer()); | 452 EXPECT_EQ(child1_.get(), child1_->RootLayer()); |
| 458 | 453 EXPECT_EQ(parent_.get(), child2_->RootLayer()); |
| 459 m_grandChild3->AddChild(child4); | 454 EXPECT_EQ(parent_.get(), child3_->RootLayer()); |
| 460 | 455 EXPECT_EQ(parent_.get(), child4->RootLayer()); |
| 461 EXPECT_EQ(parent_.get(), parent_->RootLayer()); | 456 EXPECT_EQ(child1_.get(), grand_child1_->RootLayer()); |
| 462 EXPECT_EQ(m_child1.get(), m_child1->RootLayer()); | 457 EXPECT_EQ(child1_.get(), grand_child2_->RootLayer()); |
| 463 EXPECT_EQ(parent_.get(), m_child2->RootLayer()); | 458 EXPECT_EQ(parent_.get(), grand_child3_->RootLayer()); |
| 464 EXPECT_EQ(parent_.get(), m_child3->RootLayer()); | 459 |
| 465 EXPECT_EQ(parent_.get(), child4->RootLayer()); | 460 child2_->ReplaceChild(grand_child3_.get(), child1_); |
| 466 EXPECT_EQ(m_child1.get(), m_grandChild1->RootLayer()); | 461 |
| 467 EXPECT_EQ(m_child1.get(), m_grandChild2->RootLayer()); | 462 // |grand_child3| gets orphaned and the child1 subtree gets planted back into |
| 468 EXPECT_EQ(parent_.get(), m_grandChild3->RootLayer()); | 463 // the tree under child2. |
| 469 | 464 EXPECT_EQ(parent_.get(), parent_->RootLayer()); |
| 470 m_child2->ReplaceChild(m_grandChild3.get(), m_child1); | 465 EXPECT_EQ(parent_.get(), child1_->RootLayer()); |
| 471 | 466 EXPECT_EQ(parent_.get(), child2_->RootLayer()); |
| 472 // grandChild3 gets orphaned and the child1 subtree gets planted back into t
he tree under child2. | 467 EXPECT_EQ(parent_.get(), child3_->RootLayer()); |
| 473 EXPECT_EQ(parent_.get(), parent_->RootLayer()); | 468 EXPECT_EQ(grand_child3_.get(), child4->RootLayer()); |
| 474 EXPECT_EQ(parent_.get(), m_child1->RootLayer()); | 469 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); |
| 475 EXPECT_EQ(parent_.get(), m_child2->RootLayer()); | 470 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); |
| 476 EXPECT_EQ(parent_.get(), m_child3->RootLayer()); | 471 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); |
| 477 EXPECT_EQ(m_grandChild3.get(), child4->RootLayer()); | 472 } |
| 478 EXPECT_EQ(parent_.get(), m_grandChild1->RootLayer()); | 473 |
| 479 EXPECT_EQ(parent_.get(), m_grandChild2->RootLayer()); | 474 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { |
| 480 EXPECT_EQ(m_grandChild3.get(), m_grandChild3->RootLayer()); | 475 // The semantics for setNeedsDisplay which are tested here: |
| 481 } | 476 // 1. sets NeedsDisplay flag appropriately. |
| 482 | 477 // 2. indirectly calls SetNeedsCommit, exactly once for each call to |
| 483 TEST_F(LayerTest, checkSetNeedsDisplayCausesCorrectBehavior) | 478 // SetNeedsDisplay. |
| 484 { | 479 |
| 485 // The semantics for setNeedsDisplay which are tested here: | 480 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 486 // 1. sets needsDisplay flag appropriately. | 481 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
| 487 // 2. indirectly calls SetNeedsCommit, exactly once for each call to setNe
edsDisplay. | 482 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
| 488 | 483 |
| 489 scoped_refptr<Layer> testLayer = Layer::Create(); | 484 gfx::Size test_bounds = gfx::Size(501, 508); |
| 490 testLayer->SetLayerTreeHost(layer_tree_host_.get()); | 485 |
| 491 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(true)); | 486 gfx::RectF dirty1 = gfx::RectF(10.f, 15.f, 1.f, 2.f); |
| 492 | 487 gfx::RectF dirty2 = gfx::RectF(20.f, 25.f, 3.f, 4.f); |
| 493 gfx::Size testBounds = gfx::Size(501, 508); | 488 gfx::RectF empty_dirty_rect = gfx::RectF(40.f, 45.f, 0.f, 0.f); |
| 494 | 489 gfx::RectF out_of_bounds_dirty_rect = gfx::RectF(400.f, 405.f, 500.f, 502.f); |
| 495 gfx::RectF dirty1 = gfx::RectF(10, 15, 1, 2); | 490 |
| 496 gfx::RectF dirty2 = gfx::RectF(20, 25, 3, 4); | 491 // Before anything, test_layer should not be dirty. |
| 497 gfx::RectF emptyDirtyRect = gfx::RectF(40, 45, 0, 0); | 492 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 498 gfx::RectF outOfBoundsDirtyRect = gfx::RectF(400, 405, 500, 502); | 493 |
| 499 | 494 // This is just initialization, but SetNeedsCommit behavior is verified anyway |
| 500 // Before anything, testLayer should not be dirty. | 495 // to avoid warnings. |
| 501 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 496 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(test_bounds)); |
| 502 | 497 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
| 503 // This is just initialization, but SetNeedsCommit behavior is verified anyw
ay to avoid warnings. | 498 |
| 504 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(testBounds)); | 499 // The real test begins here. |
| 505 EXPECT_TRUE(testLayer->NeedsDisplayForTesting()); | 500 test_layer->ResetNeedsDisplayForTesting(); |
| 506 | 501 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 507 // The real test begins here. | 502 |
| 508 testLayer->ResetNeedsDisplayForTesting(); | 503 // Case 1: Layer should accept dirty rects that go beyond its bounds. |
| 509 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 504 test_layer->ResetNeedsDisplayForTesting(); |
| 510 | 505 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 511 // Case 1: Layer should accept dirty rects that go beyond its bounds. | 506 EXPECT_SET_NEEDS_COMMIT( |
| 512 testLayer->ResetNeedsDisplayForTesting(); | 507 1, test_layer->SetNeedsDisplayRect(out_of_bounds_dirty_rect)); |
| 513 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 508 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
| 514 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetNeedsDisplayRect(outOfBoundsDirtyRe
ct)); | 509 test_layer->ResetNeedsDisplayForTesting(); |
| 515 EXPECT_TRUE(testLayer->NeedsDisplayForTesting()); | 510 |
| 516 testLayer->ResetNeedsDisplayForTesting(); | 511 // Case 2: SetNeedsDisplay() without the dirty rect arg. |
| 517 | 512 test_layer->ResetNeedsDisplayForTesting(); |
| 518 // Case 2: SetNeedsDisplay() without the dirty rect arg. | 513 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 519 testLayer->ResetNeedsDisplayForTesting(); | 514 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNeedsDisplay()); |
| 520 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 515 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
| 521 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetNeedsDisplay()); | 516 test_layer->ResetNeedsDisplayForTesting(); |
| 522 EXPECT_TRUE(testLayer->NeedsDisplayForTesting()); | 517 |
| 523 testLayer->ResetNeedsDisplayForTesting(); | 518 // Case 3: SetNeedsDisplay() with a non-drawable layer |
| 524 | 519 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false)); |
| 525 // Case 3: SetNeedsDisplay() with a non-drawable layer | 520 test_layer->ResetNeedsDisplayForTesting(); |
| 526 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(false)); | 521 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 527 testLayer->ResetNeedsDisplayForTesting(); | 522 EXPECT_SET_NEEDS_COMMIT(0, test_layer->SetNeedsDisplayRect(dirty1)); |
| 528 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 523 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
| 529 EXPECT_SET_NEEDS_COMMIT(0, testLayer->SetNeedsDisplayRect(dirty1)); | 524 } |
| 530 EXPECT_TRUE(testLayer->NeedsDisplayForTesting()); | 525 |
| 531 } | 526 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
| 532 | 527 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 533 TEST_F(LayerTest, checkPropertyChangeCausesCorrectBehavior) | 528 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
| 534 { | 529 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
| 535 scoped_refptr<Layer> testLayer = Layer::Create(); | 530 |
| 536 testLayer->SetLayerTreeHost(layer_tree_host_.get()); | 531 scoped_refptr<Layer> dummy_layer1 = Layer::Create(); |
| 537 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(true)); | 532 scoped_refptr<Layer> dummy_layer2 = Layer::Create(); |
| 538 | 533 |
| 539 scoped_refptr<Layer> dummyLayer1 = Layer::Create(); // just a dummy layer fo
r this test case. | 534 // sanity check of initial test condition |
| 540 scoped_refptr<Layer> dummyLayer2 = Layer::Create(); // just a dummy layer fo
r this test case. | 535 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 541 | 536 |
| 542 // sanity check of initial test condition | 537 // Next, test properties that should call SetNeedsCommit (but not |
| 543 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 538 // SetNeedsDisplay). All properties need to be set to new values in order for |
| 544 | 539 // SetNeedsCommit to be called. |
| 545 // Next, test properties that should call SetNeedsCommit (but not setNeedsDi
splay) | 540 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetAnchorPoint( |
| 546 // All properties need to be set to new values in order for SetNeedsCommit t
o be called. | 541 gfx::PointF(1.23f, 4.56f))); |
| 547 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetAnchorPoint(gfx::PointF(1.23f, 4.56
f))); | 542 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetAnchorPointZ(0.7f)); |
| 548 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetAnchorPointZ(0.7f)); | 543 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBackgroundColor(SK_ColorLTGRAY)); |
| 549 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBackgroundColor(SK_ColorLTGRAY)); | 544 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetMasksToBounds(true)); |
| 550 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetMasksToBounds(true)); | 545 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); |
| 551 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetOpacity(0.5)); | 546 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetContentsOpaque(true)); |
| 552 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetContentsOpaque(true)); | 547 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPosition(gfx::PointF(4.f, 9.f))); |
| 553 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetPosition(gfx::PointF(4, 9))); | 548 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetSublayerTransform( |
| 554 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetSublayerTransform(gfx::Transform(0.
0, 0.0, 0.0, 0.0, 0.0, 0.0))); | 549 gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0))); |
| 555 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetScrollable(true)); | 550 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetScrollable(true)); |
| 556 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetScrollOffset(gfx::Vector2d(10, 10))
); | 551 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetScrollOffset( |
| 557 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetShouldScrollOnMainThread(true)); | 552 gfx::Vector2d(10, 10))); |
| 558 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetNonFastScrollableRegion(gfx::Rect(1
, 1, 2, 2))); | 553 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetShouldScrollOnMainThread(true)); |
| 559 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetHaveWheelEventHandlers(true)); | 554 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNonFastScrollableRegion( |
| 560 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetTransform(gfx::Transform(0.0, 0.0,
0.0, 0.0, 0.0, 0.0))); | 555 gfx::Rect(1, 1, 2, 2))); |
| 561 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetDoubleSided(false)); | 556 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetHaveWheelEventHandlers(true)); |
| 562 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetDebugName("Test Layer")); | 557 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform( |
| 563 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetDrawCheckerboardForMissingTiles(!te
stLayer->DrawCheckerboardForMissingTiles())); | 558 gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0))); |
| 564 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetForceRenderSurface(true)); | 559 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetDoubleSided(false)); |
| 565 | 560 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetDebugName("Test Layer")); |
| 566 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, testLayer->SetMaskLayer(dummyLayer1.get()
)); | 561 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetDrawCheckerboardForMissingTiles( |
| 567 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, testLayer->SetReplicaLayer(dummyLayer2.ge
t())); | 562 !test_layer->DrawCheckerboardForMissingTiles())); |
| 568 | 563 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetForceRenderSurface(true)); |
| 569 // The above tests should not have caused a change to the needsDisplay flag. | 564 |
| 570 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 565 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, test_layer->SetMaskLayer( |
| 571 | 566 dummy_layer1.get())); |
| 572 // As layers are removed from the tree, they will cause a tree sync. | 567 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, test_layer->SetReplicaLayer( |
| 573 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); | 568 dummy_layer2.get())); |
| 574 } | 569 |
| 575 | 570 // The above tests should not have caused a change to the needsDisplay flag. |
| 576 TEST_F(LayerTest, setBoundsTriggersSetNeedsRedrawAfterGettingNonEmptyBounds) | 571 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 577 { | 572 |
| 578 scoped_refptr<Layer> testLayer = Layer::Create(); | 573 // As layers are removed from the tree, they will cause a tree sync. |
| 579 testLayer->SetLayerTreeHost(layer_tree_host_.get()); | 574 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); |
| 580 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(true)); | 575 } |
| 581 | 576 |
| 582 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 577 TEST_F(LayerTest, SetBoundsTriggersSetNeedsRedrawAfterGettingNonEmptyBounds) { |
| 583 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(gfx::Size(0, 10))); | 578 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 584 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 579 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
| 585 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(gfx::Size(10, 10))); | 580 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
| 586 EXPECT_TRUE(testLayer->NeedsDisplayForTesting()); | 581 |
| 587 | 582 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 588 testLayer->ResetNeedsDisplayForTesting(); | 583 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(gfx::Size(0, 10))); |
| 589 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 584 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 590 | 585 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(gfx::Size(10, 10))); |
| 591 // Calling setBounds only invalidates on the first time. | 586 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
| 592 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(gfx::Size(7, 10))); | 587 |
| 593 EXPECT_FALSE(testLayer->NeedsDisplayForTesting()); | 588 test_layer->ResetNeedsDisplayForTesting(); |
| 594 } | 589 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 595 | 590 |
| 596 TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect) | 591 // Calling setBounds only invalidates on the first time. |
| 597 { | 592 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(gfx::Size(7, 10))); |
| 598 scoped_refptr<Layer> testLayer = Layer::Create(); | 593 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 599 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree()
, 1); | 594 } |
| 600 | 595 |
| 601 testLayer->SetNeedsDisplayRect(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5))); | 596 TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { |
| 602 testLayer->PushPropertiesTo(implLayer.get()); | 597 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 603 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)), implLayer-
>update_rect()); | 598 scoped_ptr<LayerImpl> impl_layer = |
| 604 | 599 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 605 // The LayerImpl's updateRect should be accumulated here, since we did not d
o anything to clear it. | 600 |
| 606 testLayer->SetNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5,
5))); | 601 test_layer->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); |
| 607 testLayer->PushPropertiesTo(implLayer.get()); | 602 test_layer->PushPropertiesTo(impl_layer.get()); |
| 608 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(15, 15)), implLaye
r->update_rect()); | 603 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 5.f, 5.f), |
| 609 | 604 impl_layer->update_rect()); |
| 610 // If we do clear the LayerImpl side, then the next updateRect should be fre
sh without accumulation. | 605 |
| 611 implLayer->ResetAllChangeTrackingForSubtree(); | 606 // The LayerImpl's update_rect() should be accumulated here, since we did not |
| 612 testLayer->SetNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5,
5))); | 607 // do anything to clear it. |
| 613 testLayer->PushPropertiesTo(implLayer.get()); | 608 test_layer->SetNeedsDisplayRect(gfx::RectF(10.f, 10.f, 5.f, 5.f)); |
| 614 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)), impl
Layer->update_rect()); | 609 test_layer->PushPropertiesTo(impl_layer.get()); |
| 615 } | 610 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 15.f, 15.f), |
| 616 | 611 impl_layer->update_rect()); |
| 617 TEST_F(LayerTest, verifyPushPropertiesCausesSurfacePropertyChangedForTransform) | 612 |
| 618 { | 613 // If we do clear the LayerImpl side, then the next update_rect() should be |
| 619 scoped_refptr<Layer> testLayer = Layer::Create(); | 614 // fresh without accumulation. |
| 620 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree()
, 1); | 615 impl_layer->ResetAllChangeTrackingForSubtree(); |
| 621 | 616 test_layer->SetNeedsDisplayRect(gfx::RectF(10.f, 10.f, 5.f, 5.f)); |
| 622 gfx::Transform transform; | 617 test_layer->PushPropertiesTo(impl_layer.get()); |
| 623 transform.Rotate(45.0); | 618 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10.f, 10.f, 5.f, 5.f), |
| 624 testLayer->SetTransform(transform); | 619 impl_layer->update_rect()); |
| 625 | 620 } |
| 626 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged()); | 621 |
| 627 | 622 TEST_F(LayerTest, PushPropertiesCausesSurfacePropertyChangedForTransform) { |
| 628 testLayer->PushPropertiesTo(implLayer.get()); | 623 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 629 | 624 scoped_ptr<LayerImpl> impl_layer = |
| 630 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged()); | 625 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 631 } | 626 |
| 632 | 627 gfx::Transform transform; |
| 633 TEST_F(LayerTest, verifyPushPropertiesCausesSurfacePropertyChangedForOpacity) | 628 transform.Rotate(45.0); |
| 634 { | 629 test_layer->SetTransform(transform); |
| 635 scoped_refptr<Layer> testLayer = Layer::Create(); | 630 |
| 636 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree()
, 1); | 631 EXPECT_FALSE(impl_layer->LayerSurfacePropertyChanged()); |
| 637 | 632 |
| 638 testLayer->SetOpacity(0.5); | 633 test_layer->PushPropertiesTo(impl_layer.get()); |
| 639 | 634 |
| 640 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged()); | 635 EXPECT_TRUE(impl_layer->LayerSurfacePropertyChanged()); |
| 641 | 636 } |
| 642 testLayer->PushPropertiesTo(implLayer.get()); | 637 |
| 643 | 638 TEST_F(LayerTest, PushPropertiesCausesSurfacePropertyChangedForOpacity) { |
| 644 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged()); | 639 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 645 } | 640 scoped_ptr<LayerImpl> impl_layer = |
| 646 | 641 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 647 TEST_F(LayerTest, verifyPushPropertiesDoesNotCauseSurfacePropertyChangedDuringIm
plOnlyTransformAnimation) | 642 |
| 648 { | 643 test_layer->SetOpacity(0.5f); |
| 649 scoped_refptr<Layer> testLayer = Layer::Create(); | 644 |
| 650 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree()
, 1); | 645 EXPECT_FALSE(impl_layer->LayerSurfacePropertyChanged()); |
| 651 | 646 |
| 652 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create(); | 647 test_layer->PushPropertiesTo(impl_layer.get()); |
| 653 implLayer->layer_animation_controller()->SetAnimationRegistrar(registrar.get
()); | 648 |
| 654 | 649 EXPECT_TRUE(impl_layer->LayerSurfacePropertyChanged()); |
| 655 addAnimatedTransformToController(*implLayer->layer_animation_controller(), 1
.0, 0, 100); | 650 } |
| 656 | 651 |
| 657 gfx::Transform transform; | 652 TEST_F(LayerTest, |
| 658 transform.Rotate(45.0); | 653 PushPropertiesDoesNotCauseSurfacePropertyChangedDuringImplOnlyTransformAn
imation) { |
| 659 testLayer->SetTransform(transform); | 654 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 660 | 655 scoped_ptr<LayerImpl> impl_layer = |
| 661 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged()); | 656 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 662 testLayer->PushPropertiesTo(implLayer.get()); | 657 |
| 663 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged()); | 658 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create(); |
| 664 | 659 impl_layer->layer_animation_controller()->SetAnimationRegistrar( |
| 665 implLayer->ResetAllChangeTrackingForSubtree(); | 660 registrar.get()); |
| 666 addAnimatedTransformToController(*implLayer->layer_animation_controller(), 1
.0, 0, 100); | 661 |
| 667 implLayer->layer_animation_controller()->GetAnimation(Animation::Transform)-
>set_is_impl_only(true); | 662 addAnimatedTransformToController(*impl_layer->layer_animation_controller(), |
| 668 transform.Rotate(45.0); | 663 1.0, |
| 669 testLayer->SetTransform(transform); | 664 0, |
| 670 | 665 100); |
| 671 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged()); | 666 |
| 672 testLayer->PushPropertiesTo(implLayer.get()); | 667 gfx::Transform transform; |
| 673 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged()); | 668 transform.Rotate(45.0); |
| 674 } | 669 test_layer->SetTransform(transform); |
| 675 | 670 |
| 676 TEST_F(LayerTest, verifyPushPropertiesDoesNotCauseSurfacePropertyChangedDuringIm
plOnlyOpacityAnimation) | 671 EXPECT_FALSE(impl_layer->LayerSurfacePropertyChanged()); |
| 677 { | 672 test_layer->PushPropertiesTo(impl_layer.get()); |
| 678 scoped_refptr<Layer> testLayer = Layer::Create(); | 673 EXPECT_TRUE(impl_layer->LayerSurfacePropertyChanged()); |
| 679 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.active_tree()
, 1); | 674 |
| 680 | 675 impl_layer->ResetAllChangeTrackingForSubtree(); |
| 681 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create(); | 676 addAnimatedTransformToController(*impl_layer->layer_animation_controller(), |
| 682 implLayer->layer_animation_controller()->SetAnimationRegistrar(registrar.get
()); | 677 1.0, |
| 683 | 678 0, |
| 684 addOpacityTransitionToController(*implLayer->layer_animation_controller(), 1
.0, 0.3f, 0.7f, false); | 679 100); |
| 685 | 680 impl_layer->layer_animation_controller()->GetAnimation(Animation::Transform)-> |
| 686 testLayer->SetOpacity(0.5f); | 681 set_is_impl_only(true); |
| 687 | 682 transform.Rotate(45.0); |
| 688 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged()); | 683 test_layer->SetTransform(transform); |
| 689 testLayer->PushPropertiesTo(implLayer.get()); | 684 |
| 690 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged()); | 685 EXPECT_FALSE(impl_layer->LayerSurfacePropertyChanged()); |
| 691 | 686 test_layer->PushPropertiesTo(impl_layer.get()); |
| 692 implLayer->ResetAllChangeTrackingForSubtree(); | 687 EXPECT_FALSE(impl_layer->LayerSurfacePropertyChanged()); |
| 693 addOpacityTransitionToController(*implLayer->layer_animation_controller(), 1
.0, 0.3f, 0.7f, false); | 688 } |
| 694 implLayer->layer_animation_controller()->GetAnimation(Animation::Opacity)->s
et_is_impl_only(true); | 689 |
| 695 testLayer->SetOpacity(0.75f); | 690 TEST_F(LayerTest, |
| 696 | 691 PushPropertiesDoesNotCauseSurfacePropertyChangedDuringImplOnlyOpacityAnim
ation) { |
| 697 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged()); | 692 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 698 testLayer->PushPropertiesTo(implLayer.get()); | 693 scoped_ptr<LayerImpl> impl_layer = |
| 699 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged()); | 694 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 700 } | 695 |
| 701 | 696 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create(); |
| 702 | 697 impl_layer->layer_animation_controller()->SetAnimationRegistrar( |
| 703 TEST_F(LayerTest, maskAndReplicaHasParent) | 698 registrar.get()); |
| 704 { | 699 |
| 705 scoped_refptr<Layer> parent = Layer::Create(); | 700 addOpacityTransitionToController(*impl_layer->layer_animation_controller(), |
| 706 scoped_refptr<Layer> child = Layer::Create(); | 701 1.0, |
| 707 scoped_refptr<Layer> mask = Layer::Create(); | 702 0.3f, |
| 708 scoped_refptr<Layer> replica = Layer::Create(); | 703 0.7f, |
| 709 scoped_refptr<Layer> replicaMask = Layer::Create(); | 704 false); |
| 710 scoped_refptr<Layer> maskReplacement = Layer::Create(); | 705 |
| 711 scoped_refptr<Layer> replicaReplacement = Layer::Create(); | 706 test_layer->SetOpacity(0.5f); |
| 712 scoped_refptr<Layer> replicaMaskReplacement = Layer::Create(); | 707 |
| 713 | 708 EXPECT_FALSE(impl_layer->LayerSurfacePropertyChanged()); |
| 714 parent->AddChild(child); | 709 test_layer->PushPropertiesTo(impl_layer.get()); |
| 715 child->SetMaskLayer(mask.get()); | 710 EXPECT_TRUE(impl_layer->LayerSurfacePropertyChanged()); |
| 716 child->SetReplicaLayer(replica.get()); | 711 |
| 717 replica->SetMaskLayer(replicaMask.get()); | 712 impl_layer->ResetAllChangeTrackingForSubtree(); |
| 718 | 713 addOpacityTransitionToController(*impl_layer->layer_animation_controller(), |
| 719 EXPECT_EQ(parent, child->parent()); | 714 1.0, |
| 720 EXPECT_EQ(child, mask->parent()); | 715 0.3f, |
| 721 EXPECT_EQ(child, replica->parent()); | 716 0.7f, |
| 722 EXPECT_EQ(replica, replicaMask->parent()); | 717 false); |
| 723 | 718 impl_layer->layer_animation_controller()->GetAnimation(Animation::Opacity)-> |
| 724 replica->SetMaskLayer(replicaMaskReplacement.get()); | 719 set_is_impl_only(true); |
| 725 EXPECT_EQ(NULL, replicaMask->parent()); | 720 test_layer->SetOpacity(0.75f); |
| 726 EXPECT_EQ(replica, replicaMaskReplacement->parent()); | 721 |
| 727 | 722 EXPECT_FALSE(impl_layer->LayerSurfacePropertyChanged()); |
| 728 child->SetMaskLayer(maskReplacement.get()); | 723 test_layer->PushPropertiesTo(impl_layer.get()); |
| 729 EXPECT_EQ(NULL, mask->parent()); | 724 EXPECT_FALSE(impl_layer->LayerSurfacePropertyChanged()); |
| 730 EXPECT_EQ(child, maskReplacement->parent()); | 725 } |
| 731 | 726 |
| 732 child->SetReplicaLayer(replicaReplacement.get()); | 727 |
| 733 EXPECT_EQ(NULL, replica->parent()); | 728 TEST_F(LayerTest, MaskAndReplicaHasParent) { |
| 734 EXPECT_EQ(child, replicaReplacement->parent()); | 729 scoped_refptr<Layer> parent = Layer::Create(); |
| 735 | 730 scoped_refptr<Layer> child = Layer::Create(); |
| 736 EXPECT_EQ(replica, replica->mask_layer()->parent()); | 731 scoped_refptr<Layer> mask = Layer::Create(); |
| 732 scoped_refptr<Layer> replica = Layer::Create(); |
| 733 scoped_refptr<Layer> replica_mask = Layer::Create(); |
| 734 scoped_refptr<Layer> mask_replacement = Layer::Create(); |
| 735 scoped_refptr<Layer> replica_replacement = Layer::Create(); |
| 736 scoped_refptr<Layer> replica_mask_replacement = Layer::Create(); |
| 737 |
| 738 parent->AddChild(child); |
| 739 child->SetMaskLayer(mask.get()); |
| 740 child->SetReplicaLayer(replica.get()); |
| 741 replica->SetMaskLayer(replica_mask.get()); |
| 742 |
| 743 EXPECT_EQ(parent, child->parent()); |
| 744 EXPECT_EQ(child, mask->parent()); |
| 745 EXPECT_EQ(child, replica->parent()); |
| 746 EXPECT_EQ(replica, replica_mask->parent()); |
| 747 |
| 748 replica->SetMaskLayer(replica_mask_replacement.get()); |
| 749 EXPECT_EQ(NULL, replica_mask->parent()); |
| 750 EXPECT_EQ(replica, replica_mask_replacement->parent()); |
| 751 |
| 752 child->SetMaskLayer(mask_replacement.get()); |
| 753 EXPECT_EQ(NULL, mask->parent()); |
| 754 EXPECT_EQ(child, mask_replacement->parent()); |
| 755 |
| 756 child->SetReplicaLayer(replica_replacement.get()); |
| 757 EXPECT_EQ(NULL, replica->parent()); |
| 758 EXPECT_EQ(child, replica_replacement->parent()); |
| 759 |
| 760 EXPECT_EQ(replica, replica->mask_layer()->parent()); |
| 737 } | 761 } |
| 738 | 762 |
| 739 class FakeLayerImplTreeHost : public LayerTreeHost { | 763 class FakeLayerImplTreeHost : public LayerTreeHost { |
| 740 public: | 764 public: |
| 741 static scoped_ptr<FakeLayerImplTreeHost> Create() | 765 static scoped_ptr<FakeLayerImplTreeHost> Create() { |
| 742 { | 766 scoped_ptr<FakeLayerImplTreeHost> host = |
| 743 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(LayerTr
eeSettings())); | 767 make_scoped_ptr(new FakeLayerImplTreeHost(LayerTreeSettings())); |
| 744 // The initialize call will fail, since our client doesn't provide a val
id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i
gnore the return value. | 768 // The initialize call will fail, since our client doesn't provide a valid |
| 745 host->Initialize(scoped_ptr<Thread>(NULL)); | 769 // GraphicsContext3D, but it doesn't matter in the tests that use this fake |
| 746 return host.Pass(); | 770 // so ignore the return value. |
| 747 } | 771 host->Initialize(scoped_ptr<Thread>(NULL)); |
| 748 | 772 return host.Pass(); |
| 749 static scoped_ptr<FakeLayerImplTreeHost> Create(LayerTreeSettings settings) | 773 } |
| 750 { | 774 |
| 751 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(setting
s)); | 775 static scoped_ptr<FakeLayerImplTreeHost> Create(LayerTreeSettings settings) { |
| 752 host->Initialize(scoped_ptr<Thread>(NULL)); | 776 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(settings)); |
| 753 return host.Pass(); | 777 host->Initialize(scoped_ptr<Thread>(NULL)); |
| 754 } | 778 return host.Pass(); |
| 755 | 779 } |
| 756 private: | 780 |
| 757 FakeLayerImplTreeHost(const LayerTreeSettings& settings) | 781 private: |
| 758 : LayerTreeHost(&m_client, settings) | 782 FakeLayerImplTreeHost(const LayerTreeSettings& settings) |
| 759 { | 783 : LayerTreeHost(&client_, settings) {} |
| 760 } | 784 |
| 761 | 785 FakeLayerImplTreeHostClient client_; |
| 762 FakeLayerImplTreeHostClient m_client; | |
| 763 }; | 786 }; |
| 764 | 787 |
| 765 void assertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) | 788 void AssertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) { |
| 766 { | 789 EXPECT_EQ(host, layer->layer_tree_host()); |
| 767 EXPECT_EQ(host, layer->layer_tree_host()); | 790 |
| 768 | 791 for (size_t i = 0; i < layer->children().size(); ++i) |
| 769 for (size_t i = 0; i < layer->children().size(); ++i) | 792 AssertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); |
| 770 assertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); | 793 |
| 771 | 794 if (layer->mask_layer()) |
| 772 if (layer->mask_layer()) | 795 AssertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host); |
| 773 assertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host); | 796 |
| 774 | 797 if (layer->replica_layer()) |
| 775 if (layer->replica_layer()) | 798 AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); |
| 776 assertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); | 799 } |
| 777 } | 800 |
| 778 | 801 TEST(LayerLayerTreeHostTest, EnteringTree) { |
| 779 TEST(LayerLayerTreeHostTest, enteringTree) | 802 scoped_refptr<Layer> parent = Layer::Create(); |
| 780 { | 803 scoped_refptr<Layer> child = Layer::Create(); |
| 781 scoped_refptr<Layer> parent = Layer::Create(); | 804 scoped_refptr<Layer> mask = Layer::Create(); |
| 782 scoped_refptr<Layer> child = Layer::Create(); | 805 scoped_refptr<Layer> replica = Layer::Create(); |
| 783 scoped_refptr<Layer> mask = Layer::Create(); | 806 scoped_refptr<Layer> replica_mask = Layer::Create(); |
| 784 scoped_refptr<Layer> replica = Layer::Create(); | 807 |
| 785 scoped_refptr<Layer> replicaMask = Layer::Create(); | 808 // Set up a detached tree of layers. The host pointer should be nil for these |
| 786 | 809 // layers. |
| 787 // Set up a detached tree of layers. The host pointer should be nil for thes
e layers. | 810 parent->AddChild(child); |
| 788 parent->AddChild(child); | 811 child->SetMaskLayer(mask.get()); |
| 789 child->SetMaskLayer(mask.get()); | 812 child->SetReplicaLayer(replica.get()); |
| 790 child->SetReplicaLayer(replica.get()); | 813 replica->SetMaskLayer(replica_mask.get()); |
| 791 replica->SetMaskLayer(replicaMask.get()); | 814 |
| 792 | 815 AssertLayerTreeHostMatchesForSubtree(parent.get(), NULL); |
| 793 assertLayerTreeHostMatchesForSubtree(parent.get(), 0); | 816 |
| 794 | 817 scoped_ptr<FakeLayerImplTreeHost> layer_tree_host = |
| 795 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat
e()); | 818 FakeLayerImplTreeHost::Create(); |
| 796 // Setting the root layer should set the host pointer for all layers in the
tree. | 819 // Setting the root layer should set the host pointer for all layers in the |
| 797 layerTreeHost->SetRootLayer(parent.get()); | 820 // tree. |
| 798 | 821 layer_tree_host->SetRootLayer(parent.get()); |
| 799 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get()); | 822 |
| 800 | 823 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
| 801 // Clearing the root layer should also clear out the host pointers for all l
ayers in the tree. | 824 |
| 802 layerTreeHost->SetRootLayer(NULL); | 825 // Clearing the root layer should also clear out the host pointers for all |
| 803 | 826 // layers in the tree. |
| 804 assertLayerTreeHostMatchesForSubtree(parent.get(), 0); | 827 layer_tree_host->SetRootLayer(NULL); |
| 805 } | 828 |
| 806 | 829 AssertLayerTreeHostMatchesForSubtree(parent.get(), NULL); |
| 807 TEST(LayerLayerTreeHostTest, addingLayerSubtree) | 830 } |
| 808 { | 831 |
| 809 scoped_refptr<Layer> parent = Layer::Create(); | 832 TEST(LayerLayerTreeHostTest, AddingLayerSubtree) { |
| 810 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat
e()); | 833 scoped_refptr<Layer> parent = Layer::Create(); |
| 811 | 834 scoped_ptr<FakeLayerImplTreeHost> layer_tree_host = |
| 812 layerTreeHost->SetRootLayer(parent.get()); | 835 FakeLayerImplTreeHost::Create(); |
| 813 | 836 |
| 814 EXPECT_EQ(parent->layer_tree_host(), layerTreeHost.get()); | 837 layer_tree_host->SetRootLayer(parent.get()); |
| 815 | 838 |
| 816 // Adding a subtree to a layer already associated with a host should set the
host pointer on all layers in that subtree. | 839 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get()); |
| 817 scoped_refptr<Layer> child = Layer::Create(); | 840 |
| 818 scoped_refptr<Layer> grandChild = Layer::Create(); | 841 // Adding a subtree to a layer already associated with a host should set the |
| 819 child->AddChild(grandChild); | 842 // host pointer on all layers in that subtree. |
| 820 | 843 scoped_refptr<Layer> child = Layer::Create(); |
| 821 // Masks, replicas, and replica masks should pick up the new host too. | 844 scoped_refptr<Layer> grand_child = Layer::Create(); |
| 822 scoped_refptr<Layer> childMask = Layer::Create(); | 845 child->AddChild(grand_child); |
| 823 child->SetMaskLayer(childMask.get()); | 846 |
| 824 scoped_refptr<Layer> childReplica = Layer::Create(); | 847 // Masks, replicas, and replica masks should pick up the new host too. |
| 825 child->SetReplicaLayer(childReplica.get()); | 848 scoped_refptr<Layer> child_mask = Layer::Create(); |
| 826 scoped_refptr<Layer> childReplicaMask = Layer::Create(); | 849 child->SetMaskLayer(child_mask.get()); |
| 827 childReplica->SetMaskLayer(childReplicaMask.get()); | 850 scoped_refptr<Layer> child_replica = Layer::Create(); |
| 828 | 851 child->SetReplicaLayer(child_replica.get()); |
| 829 parent->AddChild(child); | 852 scoped_refptr<Layer> child_replica_mask = Layer::Create(); |
| 830 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get()); | 853 child_replica->SetMaskLayer(child_replica_mask.get()); |
| 831 | 854 |
| 832 layerTreeHost->SetRootLayer(NULL); | 855 parent->AddChild(child); |
| 833 } | 856 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
| 834 | 857 |
| 835 TEST(LayerLayerTreeHostTest, changeHost) | 858 layer_tree_host->SetRootLayer(NULL); |
| 836 { | 859 } |
| 837 scoped_refptr<Layer> parent = Layer::Create(); | 860 |
| 838 scoped_refptr<Layer> child = Layer::Create(); | 861 TEST(LayerLayerTreeHostTest, ChangeHost) { |
| 839 scoped_refptr<Layer> mask = Layer::Create(); | 862 scoped_refptr<Layer> parent = Layer::Create(); |
| 840 scoped_refptr<Layer> replica = Layer::Create(); | 863 scoped_refptr<Layer> child = Layer::Create(); |
| 841 scoped_refptr<Layer> replicaMask = Layer::Create(); | 864 scoped_refptr<Layer> mask = Layer::Create(); |
| 842 | 865 scoped_refptr<Layer> replica = Layer::Create(); |
| 843 // Same setup as the previous test. | 866 scoped_refptr<Layer> replica_mask = Layer::Create(); |
| 844 parent->AddChild(child); | 867 |
| 845 child->SetMaskLayer(mask.get()); | 868 // Same setup as the previous test. |
| 846 child->SetReplicaLayer(replica.get()); | 869 parent->AddChild(child); |
| 847 replica->SetMaskLayer(replicaMask.get()); | 870 child->SetMaskLayer(mask.get()); |
| 848 | 871 child->SetReplicaLayer(replica.get()); |
| 849 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost::
Create()); | 872 replica->SetMaskLayer(replica_mask.get()); |
| 850 firstLayerTreeHost->SetRootLayer(parent.get()); | 873 |
| 851 | 874 scoped_ptr<FakeLayerImplTreeHost> first_layer_tree_host = |
| 852 assertLayerTreeHostMatchesForSubtree(parent.get(), firstLayerTreeHost.get())
; | 875 FakeLayerImplTreeHost::Create(); |
| 853 | 876 first_layer_tree_host->SetRootLayer(parent.get()); |
| 854 // Now re-root the tree to a new host (simulating what we do on a context lo
st event). | 877 |
| 855 // This should update the host pointers for all layers in the tree. | 878 AssertLayerTreeHostMatchesForSubtree(parent.get(), |
| 856 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost:
:Create()); | 879 first_layer_tree_host.get()); |
| 857 secondLayerTreeHost->SetRootLayer(parent.get()); | 880 |
| 858 | 881 // Now re-root the tree to a new host (simulating what we do on a context lost |
| 859 assertLayerTreeHostMatchesForSubtree(parent.get(), secondLayerTreeHost.get()
); | 882 // event). This should update the host pointers for all layers in the tree. |
| 860 | 883 scoped_ptr<FakeLayerImplTreeHost> second_layer_tree_host = |
| 861 secondLayerTreeHost->SetRootLayer(NULL); | 884 FakeLayerImplTreeHost::Create(); |
| 862 } | 885 second_layer_tree_host->SetRootLayer(parent.get()); |
| 863 | 886 |
| 864 TEST(LayerLayerTreeHostTest, changeHostInSubtree) | 887 AssertLayerTreeHostMatchesForSubtree(parent.get(), |
| 865 { | 888 second_layer_tree_host.get()); |
| 866 scoped_refptr<Layer> firstParent = Layer::Create(); | 889 |
| 867 scoped_refptr<Layer> firstChild = Layer::Create(); | 890 second_layer_tree_host->SetRootLayer(NULL); |
| 868 scoped_refptr<Layer> secondParent = Layer::Create(); | 891 } |
| 869 scoped_refptr<Layer> secondChild = Layer::Create(); | 892 |
| 870 scoped_refptr<Layer> secondGrandChild = Layer::Create(); | 893 TEST(LayerLayerTreeHostTest, ChangeHostInSubtree) { |
| 871 | 894 scoped_refptr<Layer> first_parent = Layer::Create(); |
| 872 // First put all children under the first parent and set the first host. | 895 scoped_refptr<Layer> first_child = Layer::Create(); |
| 873 firstParent->AddChild(firstChild); | 896 scoped_refptr<Layer> second_parent = Layer::Create(); |
| 874 secondChild->AddChild(secondGrandChild); | 897 scoped_refptr<Layer> second_child = Layer::Create(); |
| 875 firstParent->AddChild(secondChild); | 898 scoped_refptr<Layer> second_grand_child = Layer::Create(); |
| 876 | 899 |
| 877 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost::
Create()); | 900 // First put all children under the first parent and set the first host. |
| 878 firstLayerTreeHost->SetRootLayer(firstParent.get()); | 901 first_parent->AddChild(first_child); |
| 879 | 902 second_child->AddChild(second_grand_child); |
| 880 assertLayerTreeHostMatchesForSubtree(firstParent.get(), firstLayerTreeHost.g
et()); | 903 first_parent->AddChild(second_child); |
| 881 | 904 |
| 882 // Now reparent the subtree starting at secondChild to a layer in a differen
t tree. | 905 scoped_ptr<FakeLayerImplTreeHost> first_layer_tree_host = |
| 883 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost:
:Create()); | 906 FakeLayerImplTreeHost::Create(); |
| 884 secondLayerTreeHost->SetRootLayer(secondParent.get()); | 907 first_layer_tree_host->SetRootLayer(first_parent.get()); |
| 885 | 908 |
| 886 secondParent->AddChild(secondChild); | 909 AssertLayerTreeHostMatchesForSubtree(first_parent.get(), |
| 887 | 910 first_layer_tree_host.get()); |
| 888 // The moved layer and its children should point to the new host. | 911 |
| 889 EXPECT_EQ(secondLayerTreeHost.get(), secondChild->layer_tree_host()); | 912 // Now reparent the subtree starting at second_child to a layer in a different |
| 890 EXPECT_EQ(secondLayerTreeHost.get(), secondGrandChild->layer_tree_host()); | 913 // tree. |
| 891 | 914 scoped_ptr<FakeLayerImplTreeHost> second_layer_tree_host = |
| 892 // Test over, cleanup time. | 915 FakeLayerImplTreeHost::Create(); |
| 893 firstLayerTreeHost->SetRootLayer(NULL); | 916 second_layer_tree_host->SetRootLayer(second_parent.get()); |
| 894 secondLayerTreeHost->SetRootLayer(NULL); | 917 |
| 895 } | 918 second_parent->AddChild(second_child); |
| 896 | 919 |
| 897 TEST(LayerLayerTreeHostTest, replaceMaskAndReplicaLayer) | 920 // The moved layer and its children should point to the new host. |
| 898 { | 921 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host()); |
| 899 scoped_refptr<Layer> parent = Layer::Create(); | 922 EXPECT_EQ(second_layer_tree_host.get(), |
| 900 scoped_refptr<Layer> mask = Layer::Create(); | 923 second_grand_child->layer_tree_host()); |
| 901 scoped_refptr<Layer> replica = Layer::Create(); | 924 |
| 902 scoped_refptr<Layer> maskChild = Layer::Create(); | 925 // Test over, cleanup time. |
| 903 scoped_refptr<Layer> replicaChild = Layer::Create(); | 926 first_layer_tree_host->SetRootLayer(NULL); |
| 904 scoped_refptr<Layer> maskReplacement = Layer::Create(); | 927 second_layer_tree_host->SetRootLayer(NULL); |
| 905 scoped_refptr<Layer> replicaReplacement = Layer::Create(); | 928 } |
| 906 | 929 |
| 907 parent->SetMaskLayer(mask.get()); | 930 TEST(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { |
| 908 parent->SetReplicaLayer(replica.get()); | 931 scoped_refptr<Layer> parent = Layer::Create(); |
| 909 mask->AddChild(maskChild); | 932 scoped_refptr<Layer> mask = Layer::Create(); |
| 910 replica->AddChild(replicaChild); | 933 scoped_refptr<Layer> replica = Layer::Create(); |
| 911 | 934 scoped_refptr<Layer> mask_child = Layer::Create(); |
| 912 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat
e()); | 935 scoped_refptr<Layer> replica_child = Layer::Create(); |
| 913 layerTreeHost->SetRootLayer(parent.get()); | 936 scoped_refptr<Layer> mask_replacement = Layer::Create(); |
| 914 | 937 scoped_refptr<Layer> replica_replacement = Layer::Create(); |
| 915 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get()); | 938 |
| 916 | 939 parent->SetMaskLayer(mask.get()); |
| 917 // Replacing the mask should clear out the old mask's subtree's host pointer
s. | 940 parent->SetReplicaLayer(replica.get()); |
| 918 parent->SetMaskLayer(maskReplacement.get()); | 941 mask->AddChild(mask_child); |
| 919 EXPECT_EQ(0, mask->layer_tree_host()); | 942 replica->AddChild(replica_child); |
| 920 EXPECT_EQ(0, maskChild->layer_tree_host()); | 943 |
| 921 | 944 scoped_ptr<FakeLayerImplTreeHost> layer_tree_host = |
| 922 // Same for replacing a replica layer. | 945 FakeLayerImplTreeHost::Create(); |
| 923 parent->SetReplicaLayer(replicaReplacement.get()); | 946 layer_tree_host->SetRootLayer(parent.get()); |
| 924 EXPECT_EQ(0, replica->layer_tree_host()); | 947 |
| 925 EXPECT_EQ(0, replicaChild->layer_tree_host()); | 948 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
| 926 | 949 |
| 927 // Test over, cleanup time. | 950 // Replacing the mask should clear out the old mask's subtree's host pointers. |
| 928 layerTreeHost->SetRootLayer(NULL); | 951 parent->SetMaskLayer(mask_replacement.get()); |
| 929 } | 952 EXPECT_EQ(NULL, mask->layer_tree_host()); |
| 930 | 953 EXPECT_EQ(NULL, mask_child->layer_tree_host()); |
| 931 TEST(LayerLayerTreeHostTest, destroyHostWithNonNullRootLayer) | 954 |
| 932 { | 955 // Same for replacing a replica layer. |
| 933 scoped_refptr<Layer> root = Layer::Create(); | 956 parent->SetReplicaLayer(replica_replacement.get()); |
| 934 scoped_refptr<Layer> child = Layer::Create(); | 957 EXPECT_EQ(NULL, replica->layer_tree_host()); |
| 935 root->AddChild(child); | 958 EXPECT_EQ(NULL, replica_child->layer_tree_host()); |
| 936 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat
e()); | 959 |
| 937 layerTreeHost->SetRootLayer(root); | 960 // Test over, cleanup time. |
| 938 } | 961 layer_tree_host->SetRootLayer(NULL); |
| 939 | 962 } |
| 940 static bool addTestAnimation(Layer* layer) | 963 |
| 941 { | 964 TEST(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { |
| 942 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve:
:Create()); | 965 scoped_refptr<Layer> root = Layer::Create(); |
| 943 curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.3f, scoped_ptr<TimingFunctio
n>())); | 966 scoped_refptr<Layer> child = Layer::Create(); |
| 944 curve->AddKeyframe(FloatKeyframe::Create(1.0, 0.7f, scoped_ptr<TimingFunctio
n>())); | 967 root->AddChild(child); |
| 945 scoped_ptr<Animation> animation(Animation::Create(curve.PassAs<AnimationCurv
e>(), 0, 0, Animation::Opacity)); | 968 scoped_ptr<FakeLayerImplTreeHost> layer_tree_host = |
| 946 | 969 FakeLayerImplTreeHost::Create(); |
| 947 return layer->AddAnimation(animation.Pass()); | 970 layer_tree_host->SetRootLayer(root); |
| 948 } | 971 } |
| 949 | 972 |
| 950 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutAnimationRegistrar) | 973 static bool AddTestAnimation(Layer* layer) { |
| 951 { | 974 scoped_ptr<KeyframedFloatAnimationCurve> curve = |
| 952 scoped_refptr<Layer> layer = Layer::Create(); | 975 KeyframedFloatAnimationCurve::Create(); |
| 953 | 976 curve->AddKeyframe(FloatKeyframe::Create(0.0, |
| 954 // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the | 977 0.3f, |
| 955 // animation should not be accepted. | 978 scoped_ptr<TimingFunction>())); |
| 956 EXPECT_FALSE(addTestAnimation(layer.get())); | 979 curve->AddKeyframe(FloatKeyframe::Create(1.0, |
| 957 | 980 0.7f, |
| 958 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create(); | 981 scoped_ptr<TimingFunction>())); |
| 959 layer->layer_animation_controller()->SetAnimationRegistrar(registrar.get()); | 982 scoped_ptr<Animation> animation = |
| 960 | 983 Animation::Create(curve.PassAs<AnimationCurve>(), |
| 961 // Case 2: with an AnimationRegistrar, the animation should be accepted. | 984 0, |
| 962 EXPECT_TRUE(addTestAnimation(layer.get())); | 985 0, |
| 963 | 986 Animation::Opacity); |
| 964 LayerTreeSettings settings; | 987 |
| 965 settings.acceleratedAnimationEnabled = false; | 988 return layer->AddAnimation(animation.Pass()); |
| 966 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat
e(settings)); | 989 } |
| 967 layerTreeHost->SetRootLayer(layer); | 990 |
| 968 layer->SetLayerTreeHost(layerTreeHost.get()); | 991 TEST(LayerLayerTreeHostTest, ShouldNotAddAnimationWithoutAnimationRegistrar) { |
| 969 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get()); | 992 scoped_refptr<Layer> layer = Layer::Create(); |
| 970 | 993 |
| 971 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the | 994 // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the |
| 972 // animation should be rejected. | 995 // animation should not be accepted. |
| 973 EXPECT_FALSE(addTestAnimation(layer.get())); | 996 EXPECT_FALSE(AddTestAnimation(layer.get())); |
| 997 |
| 998 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create(); |
| 999 layer->layer_animation_controller()->SetAnimationRegistrar(registrar.get()); |
| 1000 |
| 1001 // Case 2: with an AnimationRegistrar, the animation should be accepted. |
| 1002 EXPECT_TRUE(AddTestAnimation(layer.get())); |
| 1003 |
| 1004 LayerTreeSettings settings; |
| 1005 settings.acceleratedAnimationEnabled = false; |
| 1006 scoped_ptr<FakeLayerImplTreeHost> layer_tree_host = |
| 1007 FakeLayerImplTreeHost::Create(settings); |
| 1008 layer_tree_host->SetRootLayer(layer); |
| 1009 layer->SetLayerTreeHost(layer_tree_host.get()); |
| 1010 AssertLayerTreeHostMatchesForSubtree(layer.get(), layer_tree_host.get()); |
| 1011 |
| 1012 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the |
| 1013 // animation should be rejected. |
| 1014 EXPECT_FALSE(AddTestAnimation(layer.get())); |
| 974 } | 1015 } |
| 975 | 1016 |
| 976 } // namespace | 1017 } // namespace |
| 977 } // namespace cc | 1018 } // namespace cc |
| OLD | NEW |