Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: cc/layers/layer_unittest.cc

Issue 1101823002: CC Animations: Make LayerAnimationController creation optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Plumb LayerSettings parameter for cc::Layer construction. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "cc/animation/keyframed_animation_curve.h" 8 #include "cc/animation/keyframed_animation_curve.h"
9 #include "cc/base/math_util.h" 9 #include "cc/base/math_util.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 EXPECT_EQ(child1_.get(), grand_child2_->parent()); 102 EXPECT_EQ(child1_.get(), grand_child2_->parent());
103 103
104 ASSERT_EQ(1U, child2_->children().size()); 104 ASSERT_EQ(1U, child2_->children().size());
105 EXPECT_EQ(grand_child3_, child2_->children()[0]); 105 EXPECT_EQ(grand_child3_, child2_->children()[0]);
106 EXPECT_EQ(child2_.get(), grand_child3_->parent()); 106 EXPECT_EQ(child2_.get(), grand_child3_->parent());
107 107
108 ASSERT_EQ(0U, child3_->children().size()); 108 ASSERT_EQ(0U, child3_->children().size());
109 } 109 }
110 110
111 void CreateSimpleTestTree() { 111 void CreateSimpleTestTree() {
112 parent_ = Layer::Create(); 112 parent_ = Layer::Create(layer_settings_);
113 child1_ = Layer::Create(); 113 child1_ = Layer::Create(layer_settings_);
114 child2_ = Layer::Create(); 114 child2_ = Layer::Create(layer_settings_);
115 child3_ = Layer::Create(); 115 child3_ = Layer::Create(layer_settings_);
116 grand_child1_ = Layer::Create(); 116 grand_child1_ = Layer::Create(layer_settings_);
117 grand_child2_ = Layer::Create(); 117 grand_child2_ = Layer::Create(layer_settings_);
118 grand_child3_ = Layer::Create(); 118 grand_child3_ = Layer::Create(layer_settings_);
119 119
120 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); 120 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber());
121 layer_tree_host_->SetRootLayer(parent_); 121 layer_tree_host_->SetRootLayer(parent_);
122 122
123 parent_->AddChild(child1_); 123 parent_->AddChild(child1_);
124 parent_->AddChild(child2_); 124 parent_->AddChild(child2_);
125 parent_->AddChild(child3_); 125 parent_->AddChild(child3_);
126 child1_->AddChild(grand_child1_); 126 child1_->AddChild(grand_child1_);
127 child1_->AddChild(grand_child2_); 127 child1_->AddChild(grand_child2_);
128 child2_->AddChild(grand_child3_); 128 child2_->AddChild(grand_child3_);
(...skipping 10 matching lines...) Expand all
139 139
140 FakeLayerTreeHostClient fake_client_; 140 FakeLayerTreeHostClient fake_client_;
141 scoped_ptr<StrictMock<MockLayerTreeHost>> layer_tree_host_; 141 scoped_ptr<StrictMock<MockLayerTreeHost>> layer_tree_host_;
142 scoped_refptr<Layer> parent_; 142 scoped_refptr<Layer> parent_;
143 scoped_refptr<Layer> child1_; 143 scoped_refptr<Layer> child1_;
144 scoped_refptr<Layer> child2_; 144 scoped_refptr<Layer> child2_;
145 scoped_refptr<Layer> child3_; 145 scoped_refptr<Layer> child3_;
146 scoped_refptr<Layer> grand_child1_; 146 scoped_refptr<Layer> grand_child1_;
147 scoped_refptr<Layer> grand_child2_; 147 scoped_refptr<Layer> grand_child2_;
148 scoped_refptr<Layer> grand_child3_; 148 scoped_refptr<Layer> grand_child3_;
149
150 LayerSettings layer_settings_;
149 }; 151 };
150 152
151 TEST_F(LayerTest, BasicCreateAndDestroy) { 153 TEST_F(LayerTest, BasicCreateAndDestroy) {
152 scoped_refptr<Layer> test_layer = Layer::Create(); 154 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
153 ASSERT_TRUE(test_layer.get()); 155 ASSERT_TRUE(test_layer.get());
154 156
155 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); 157 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
156 test_layer->SetLayerTreeHost(layer_tree_host_.get()); 158 test_layer->SetLayerTreeHost(layer_tree_host_.get());
157 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 159 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
158 160
159 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); 161 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
160 test_layer->SetLayerTreeHost(nullptr); 162 test_layer->SetLayerTreeHost(nullptr);
161 } 163 }
162 164
163 TEST_F(LayerTest, AddAndRemoveChild) { 165 TEST_F(LayerTest, AddAndRemoveChild) {
164 scoped_refptr<Layer> parent = Layer::Create(); 166 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
165 scoped_refptr<Layer> child = Layer::Create(); 167 scoped_refptr<Layer> child = Layer::Create(layer_settings_);
166 168
167 // Upon creation, layers should not have children or parent. 169 // Upon creation, layers should not have children or parent.
168 ASSERT_EQ(0U, parent->children().size()); 170 ASSERT_EQ(0U, parent->children().size());
169 EXPECT_FALSE(child->parent()); 171 EXPECT_FALSE(child->parent());
170 172
171 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); 173 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent));
172 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); 174 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child));
173 175
174 ASSERT_EQ(1U, parent->children().size()); 176 ASSERT_EQ(1U, parent->children().size());
175 EXPECT_EQ(child.get(), parent->children()[0].get()); 177 EXPECT_EQ(child.get(), parent->children()[0].get());
176 EXPECT_EQ(parent.get(), child->parent()); 178 EXPECT_EQ(parent.get(), child->parent());
177 EXPECT_EQ(parent.get(), child->RootLayer()); 179 EXPECT_EQ(parent.get(), child->RootLayer());
178 180
179 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent()); 181 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent());
180 } 182 }
181 183
182 TEST_F(LayerTest, AddSameChildTwice) { 184 TEST_F(LayerTest, AddSameChildTwice) {
183 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); 185 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1));
184 186
185 scoped_refptr<Layer> parent = Layer::Create(); 187 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
186 scoped_refptr<Layer> child = Layer::Create(); 188 scoped_refptr<Layer> child = Layer::Create(layer_settings_);
187 189
188 layer_tree_host_->SetRootLayer(parent); 190 layer_tree_host_->SetRootLayer(parent);
189 191
190 ASSERT_EQ(0u, parent->children().size()); 192 ASSERT_EQ(0u, parent->children().size());
191 193
192 parent->AddChild(child); 194 parent->AddChild(child);
193 ASSERT_EQ(1u, parent->children().size()); 195 ASSERT_EQ(1u, parent->children().size());
194 EXPECT_EQ(parent.get(), child->parent()); 196 EXPECT_EQ(parent.get(), child->parent());
195 197
196 parent->AddChild(child); 198 parent->AddChild(child);
197 ASSERT_EQ(1u, parent->children().size()); 199 ASSERT_EQ(1u, parent->children().size());
198 EXPECT_EQ(parent.get(), child->parent()); 200 EXPECT_EQ(parent.get(), child->parent());
199 } 201 }
200 202
201 TEST_F(LayerTest, InsertChild) { 203 TEST_F(LayerTest, InsertChild) {
202 scoped_refptr<Layer> parent = Layer::Create(); 204 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
203 scoped_refptr<Layer> child1 = Layer::Create(); 205 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_);
204 scoped_refptr<Layer> child2 = Layer::Create(); 206 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_);
205 scoped_refptr<Layer> child3 = Layer::Create(); 207 scoped_refptr<Layer> child3 = Layer::Create(layer_settings_);
206 scoped_refptr<Layer> child4 = Layer::Create(); 208 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_);
207 209
208 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); 210 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent));
209 211
210 ASSERT_EQ(0U, parent->children().size()); 212 ASSERT_EQ(0U, parent->children().size());
211 213
212 // Case 1: inserting to empty list. 214 // Case 1: inserting to empty list.
213 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0)); 215 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0));
214 ASSERT_EQ(1U, parent->children().size()); 216 ASSERT_EQ(1U, parent->children().size());
215 EXPECT_EQ(child3, parent->children()[0]); 217 EXPECT_EQ(child3, parent->children()[0]);
216 EXPECT_EQ(parent.get(), child3->parent()); 218 EXPECT_EQ(parent.get(), child3->parent());
(...skipping 20 matching lines...) Expand all
237 EXPECT_EQ(child1, parent->children()[0]); 239 EXPECT_EQ(child1, parent->children()[0]);
238 EXPECT_EQ(child2, parent->children()[1]); 240 EXPECT_EQ(child2, parent->children()[1]);
239 EXPECT_EQ(child3, parent->children()[2]); 241 EXPECT_EQ(child3, parent->children()[2]);
240 EXPECT_EQ(child4, parent->children()[3]); 242 EXPECT_EQ(child4, parent->children()[3]);
241 EXPECT_EQ(parent.get(), child4->parent()); 243 EXPECT_EQ(parent.get(), child4->parent());
242 244
243 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); 245 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr));
244 } 246 }
245 247
246 TEST_F(LayerTest, InsertChildPastEndOfList) { 248 TEST_F(LayerTest, InsertChildPastEndOfList) {
247 scoped_refptr<Layer> parent = Layer::Create(); 249 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
248 scoped_refptr<Layer> child1 = Layer::Create(); 250 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_);
249 scoped_refptr<Layer> child2 = Layer::Create(); 251 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_);
250 252
251 ASSERT_EQ(0U, parent->children().size()); 253 ASSERT_EQ(0U, parent->children().size());
252 254
253 // insert to an out-of-bounds index 255 // insert to an out-of-bounds index
254 parent->InsertChild(child1, 53); 256 parent->InsertChild(child1, 53);
255 257
256 ASSERT_EQ(1U, parent->children().size()); 258 ASSERT_EQ(1U, parent->children().size());
257 EXPECT_EQ(child1, parent->children()[0]); 259 EXPECT_EQ(child1, parent->children()[0]);
258 260
259 // insert another child to out-of-bounds, when list is not already empty. 261 // insert another child to out-of-bounds, when list is not already empty.
260 parent->InsertChild(child2, 2459); 262 parent->InsertChild(child2, 2459);
261 263
262 ASSERT_EQ(2U, parent->children().size()); 264 ASSERT_EQ(2U, parent->children().size());
263 EXPECT_EQ(child1, parent->children()[0]); 265 EXPECT_EQ(child1, parent->children()[0]);
264 EXPECT_EQ(child2, parent->children()[1]); 266 EXPECT_EQ(child2, parent->children()[1]);
265 } 267 }
266 268
267 TEST_F(LayerTest, InsertSameChildTwice) { 269 TEST_F(LayerTest, InsertSameChildTwice) {
268 scoped_refptr<Layer> parent = Layer::Create(); 270 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
269 scoped_refptr<Layer> child1 = Layer::Create(); 271 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_);
270 scoped_refptr<Layer> child2 = Layer::Create(); 272 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_);
271 273
272 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); 274 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent));
273 275
274 ASSERT_EQ(0U, parent->children().size()); 276 ASSERT_EQ(0U, parent->children().size());
275 277
276 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); 278 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0));
277 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); 279 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1));
278 280
279 ASSERT_EQ(2U, parent->children().size()); 281 ASSERT_EQ(2U, parent->children().size());
280 EXPECT_EQ(child1, parent->children()[0]); 282 EXPECT_EQ(child1, parent->children()[0]);
281 EXPECT_EQ(child2, parent->children()[1]); 283 EXPECT_EQ(child2, parent->children()[1]);
282 284
283 // Inserting the same child again should cause the child to be removed and 285 // Inserting the same child again should cause the child to be removed and
284 // re-inserted at the new location. 286 // re-inserted at the new location.
285 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1)); 287 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1));
286 288
287 // child1 should now be at the end of the list. 289 // child1 should now be at the end of the list.
288 ASSERT_EQ(2U, parent->children().size()); 290 ASSERT_EQ(2U, parent->children().size());
289 EXPECT_EQ(child2, parent->children()[0]); 291 EXPECT_EQ(child2, parent->children()[0]);
290 EXPECT_EQ(child1, parent->children()[1]); 292 EXPECT_EQ(child1, parent->children()[1]);
291 293
292 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); 294 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr));
293 } 295 }
294 296
295 TEST_F(LayerTest, ReplaceChildWithNewChild) { 297 TEST_F(LayerTest, ReplaceChildWithNewChild) {
296 CreateSimpleTestTree(); 298 CreateSimpleTestTree();
297 scoped_refptr<Layer> child4 = Layer::Create(); 299 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_);
298 300
299 EXPECT_FALSE(child4->parent()); 301 EXPECT_FALSE(child4->parent());
300 302
301 EXPECT_SET_NEEDS_FULL_TREE_SYNC( 303 EXPECT_SET_NEEDS_FULL_TREE_SYNC(
302 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); 304 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4));
303 EXPECT_FALSE(parent_->NeedsDisplayForTesting()); 305 EXPECT_FALSE(parent_->NeedsDisplayForTesting());
304 EXPECT_FALSE(child1_->NeedsDisplayForTesting()); 306 EXPECT_FALSE(child1_->NeedsDisplayForTesting());
305 EXPECT_FALSE(child2_->NeedsDisplayForTesting()); 307 EXPECT_FALSE(child2_->NeedsDisplayForTesting());
306 EXPECT_FALSE(child3_->NeedsDisplayForTesting()); 308 EXPECT_FALSE(child3_->NeedsDisplayForTesting());
307 EXPECT_FALSE(child4->NeedsDisplayForTesting()); 309 EXPECT_FALSE(child4->NeedsDisplayForTesting());
308 310
309 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size()); 311 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size());
310 EXPECT_EQ(child1_, parent_->children()[0]); 312 EXPECT_EQ(child1_, parent_->children()[0]);
311 EXPECT_EQ(child4, parent_->children()[1]); 313 EXPECT_EQ(child4, parent_->children()[1]);
312 EXPECT_EQ(child3_, parent_->children()[2]); 314 EXPECT_EQ(child3_, parent_->children()[2]);
313 EXPECT_EQ(parent_.get(), child4->parent()); 315 EXPECT_EQ(parent_.get(), child4->parent());
314 316
315 EXPECT_FALSE(child2_->parent()); 317 EXPECT_FALSE(child2_->parent());
316 } 318 }
317 319
318 TEST_F(LayerTest, ReplaceChildWithNewChildThatHasOtherParent) { 320 TEST_F(LayerTest, ReplaceChildWithNewChildThatHasOtherParent) {
319 CreateSimpleTestTree(); 321 CreateSimpleTestTree();
320 322
321 // create another simple tree with test_layer and child4. 323 // create another simple tree with test_layer and child4.
322 scoped_refptr<Layer> test_layer = Layer::Create(); 324 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
323 scoped_refptr<Layer> child4 = Layer::Create(); 325 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_);
324 test_layer->AddChild(child4); 326 test_layer->AddChild(child4);
325 ASSERT_EQ(1U, test_layer->children().size()); 327 ASSERT_EQ(1U, test_layer->children().size());
326 EXPECT_EQ(child4, test_layer->children()[0]); 328 EXPECT_EQ(child4, test_layer->children()[0]);
327 EXPECT_EQ(test_layer.get(), child4->parent()); 329 EXPECT_EQ(test_layer.get(), child4->parent());
328 330
329 EXPECT_SET_NEEDS_FULL_TREE_SYNC( 331 EXPECT_SET_NEEDS_FULL_TREE_SYNC(
330 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); 332 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4));
331 333
332 ASSERT_EQ(3U, parent_->children().size()); 334 ASSERT_EQ(3U, parent_->children().size());
333 EXPECT_EQ(child1_, parent_->children()[0]); 335 EXPECT_EQ(child1_, parent_->children()[0]);
334 EXPECT_EQ(child4, parent_->children()[1]); 336 EXPECT_EQ(child4, parent_->children()[1]);
335 EXPECT_EQ(child3_, parent_->children()[2]); 337 EXPECT_EQ(child3_, parent_->children()[2]);
336 EXPECT_EQ(parent_.get(), child4->parent()); 338 EXPECT_EQ(parent_.get(), child4->parent());
337 339
338 // test_layer should no longer have child4, 340 // test_layer should no longer have child4,
339 // and child2 should no longer have a parent. 341 // and child2 should no longer have a parent.
340 ASSERT_EQ(0U, test_layer->children().size()); 342 ASSERT_EQ(0U, test_layer->children().size());
341 EXPECT_FALSE(child2_->parent()); 343 EXPECT_FALSE(child2_->parent());
342 } 344 }
343 345
344 TEST_F(LayerTest, DeleteRemovedScrollParent) { 346 TEST_F(LayerTest, DeleteRemovedScrollParent) {
345 scoped_refptr<Layer> parent = Layer::Create(); 347 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
346 scoped_refptr<Layer> child1 = Layer::Create(); 348 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_);
347 scoped_refptr<Layer> child2 = Layer::Create(); 349 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_);
348 350
349 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); 351 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent));
350 352
351 ASSERT_EQ(0U, parent->children().size()); 353 ASSERT_EQ(0U, parent->children().size());
352 354
353 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); 355 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0));
354 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); 356 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1));
355 357
356 ASSERT_EQ(2U, parent->children().size()); 358 ASSERT_EQ(2U, parent->children().size());
357 EXPECT_EQ(child1, parent->children()[0]); 359 EXPECT_EQ(child1, parent->children()[0]);
358 EXPECT_EQ(child2, parent->children()[1]); 360 EXPECT_EQ(child2, parent->children()[1]);
359 361
360 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); 362 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get()));
361 363
362 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); 364 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent());
363 365
364 child1->reset_needs_push_properties_for_testing(); 366 child1->reset_needs_push_properties_for_testing();
365 367
366 EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); 368 EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr);
367 369
368 EXPECT_TRUE(child1->needs_push_properties()); 370 EXPECT_TRUE(child1->needs_push_properties());
369 371
370 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); 372 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr));
371 } 373 }
372 374
373 TEST_F(LayerTest, DeleteRemovedScrollChild) { 375 TEST_F(LayerTest, DeleteRemovedScrollChild) {
374 scoped_refptr<Layer> parent = Layer::Create(); 376 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
375 scoped_refptr<Layer> child1 = Layer::Create(); 377 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_);
376 scoped_refptr<Layer> child2 = Layer::Create(); 378 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_);
377 379
378 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); 380 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent));
379 381
380 ASSERT_EQ(0U, parent->children().size()); 382 ASSERT_EQ(0U, parent->children().size());
381 383
382 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); 384 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0));
383 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); 385 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1));
384 386
385 ASSERT_EQ(2U, parent->children().size()); 387 ASSERT_EQ(2U, parent->children().size());
386 EXPECT_EQ(child1, parent->children()[0]); 388 EXPECT_EQ(child1, parent->children()[0]);
(...skipping 29 matching lines...) Expand all
416 418
417 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren()); 419 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren());
418 420
419 ASSERT_EQ(0U, parent_->children().size()); 421 ASSERT_EQ(0U, parent_->children().size());
420 EXPECT_FALSE(child1_->parent()); 422 EXPECT_FALSE(child1_->parent());
421 EXPECT_FALSE(child2_->parent()); 423 EXPECT_FALSE(child2_->parent());
422 EXPECT_FALSE(child3_->parent()); 424 EXPECT_FALSE(child3_->parent());
423 } 425 }
424 426
425 TEST_F(LayerTest, SetChildren) { 427 TEST_F(LayerTest, SetChildren) {
426 scoped_refptr<Layer> old_parent = Layer::Create(); 428 scoped_refptr<Layer> old_parent = Layer::Create(layer_settings_);
427 scoped_refptr<Layer> new_parent = Layer::Create(); 429 scoped_refptr<Layer> new_parent = Layer::Create(layer_settings_);
428 430
429 scoped_refptr<Layer> child1 = Layer::Create(); 431 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_);
430 scoped_refptr<Layer> child2 = Layer::Create(); 432 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_);
431 433
432 LayerList new_children; 434 LayerList new_children;
433 new_children.push_back(child1); 435 new_children.push_back(child1);
434 new_children.push_back(child2); 436 new_children.push_back(child2);
435 437
436 // Set up and verify initial test conditions: child1 has a parent, child2 has 438 // Set up and verify initial test conditions: child1 has a parent, child2 has
437 // no parent. 439 // no parent.
438 old_parent->AddChild(child1); 440 old_parent->AddChild(child1);
439 ASSERT_EQ(0U, new_parent->children().size()); 441 ASSERT_EQ(0U, new_parent->children().size());
440 EXPECT_EQ(old_parent.get(), child1->parent()); 442 EXPECT_EQ(old_parent.get(), child1->parent());
441 EXPECT_FALSE(child2->parent()); 443 EXPECT_FALSE(child2->parent());
442 444
443 EXPECT_SET_NEEDS_FULL_TREE_SYNC( 445 EXPECT_SET_NEEDS_FULL_TREE_SYNC(
444 1, layer_tree_host_->SetRootLayer(new_parent)); 446 1, layer_tree_host_->SetRootLayer(new_parent));
445 447
446 EXPECT_SET_NEEDS_FULL_TREE_SYNC( 448 EXPECT_SET_NEEDS_FULL_TREE_SYNC(
447 AtLeast(1), new_parent->SetChildren(new_children)); 449 AtLeast(1), new_parent->SetChildren(new_children));
448 450
449 ASSERT_EQ(2U, new_parent->children().size()); 451 ASSERT_EQ(2U, new_parent->children().size());
450 EXPECT_EQ(new_parent.get(), child1->parent()); 452 EXPECT_EQ(new_parent.get(), child1->parent());
451 EXPECT_EQ(new_parent.get(), child2->parent()); 453 EXPECT_EQ(new_parent.get(), child2->parent());
452 454
453 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); 455 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr));
454 } 456 }
455 457
456 TEST_F(LayerTest, HasAncestor) { 458 TEST_F(LayerTest, HasAncestor) {
457 scoped_refptr<Layer> parent = Layer::Create(); 459 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
458 EXPECT_FALSE(parent->HasAncestor(parent.get())); 460 EXPECT_FALSE(parent->HasAncestor(parent.get()));
459 461
460 scoped_refptr<Layer> child = Layer::Create(); 462 scoped_refptr<Layer> child = Layer::Create(layer_settings_);
461 parent->AddChild(child); 463 parent->AddChild(child);
462 464
463 EXPECT_FALSE(child->HasAncestor(child.get())); 465 EXPECT_FALSE(child->HasAncestor(child.get()));
464 EXPECT_TRUE(child->HasAncestor(parent.get())); 466 EXPECT_TRUE(child->HasAncestor(parent.get()));
465 EXPECT_FALSE(parent->HasAncestor(child.get())); 467 EXPECT_FALSE(parent->HasAncestor(child.get()));
466 468
467 scoped_refptr<Layer> child_child = Layer::Create(); 469 scoped_refptr<Layer> child_child = Layer::Create(layer_settings_);
468 child->AddChild(child_child); 470 child->AddChild(child_child);
469 471
470 EXPECT_FALSE(child_child->HasAncestor(child_child.get())); 472 EXPECT_FALSE(child_child->HasAncestor(child_child.get()));
471 EXPECT_TRUE(child_child->HasAncestor(parent.get())); 473 EXPECT_TRUE(child_child->HasAncestor(parent.get()));
472 EXPECT_TRUE(child_child->HasAncestor(child.get())); 474 EXPECT_TRUE(child_child->HasAncestor(child.get()));
473 EXPECT_FALSE(parent->HasAncestor(child.get())); 475 EXPECT_FALSE(parent->HasAncestor(child.get()));
474 EXPECT_FALSE(parent->HasAncestor(child_child.get())); 476 EXPECT_FALSE(parent->HasAncestor(child_child.get()));
475 } 477 }
476 478
477 TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { 479 TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) {
478 CreateSimpleTestTree(); 480 CreateSimpleTestTree();
479 481
480 // For this test we don't care about SetNeedsFullTreeSync calls. 482 // For this test we don't care about SetNeedsFullTreeSync calls.
481 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); 483 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber());
482 484
483 scoped_refptr<Layer> child4 = Layer::Create(); 485 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_);
484 486
485 EXPECT_EQ(parent_.get(), parent_->RootLayer()); 487 EXPECT_EQ(parent_.get(), parent_->RootLayer());
486 EXPECT_EQ(parent_.get(), child1_->RootLayer()); 488 EXPECT_EQ(parent_.get(), child1_->RootLayer());
487 EXPECT_EQ(parent_.get(), child2_->RootLayer()); 489 EXPECT_EQ(parent_.get(), child2_->RootLayer());
488 EXPECT_EQ(parent_.get(), child3_->RootLayer()); 490 EXPECT_EQ(parent_.get(), child3_->RootLayer());
489 EXPECT_EQ(child4.get(), child4->RootLayer()); 491 EXPECT_EQ(child4.get(), child4->RootLayer());
490 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); 492 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer());
491 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); 493 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer());
492 EXPECT_EQ(parent_.get(), grand_child3_->RootLayer()); 494 EXPECT_EQ(parent_.get(), grand_child3_->RootLayer());
493 495
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); 530 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer());
529 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); 531 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer());
530 } 532 }
531 533
532 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { 534 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) {
533 // The semantics for SetNeedsDisplay which are tested here: 535 // The semantics for SetNeedsDisplay which are tested here:
534 // 1. sets NeedsDisplay flag appropriately. 536 // 1. sets NeedsDisplay flag appropriately.
535 // 2. indirectly calls SetNeedsUpdate, exactly once for each call to 537 // 2. indirectly calls SetNeedsUpdate, exactly once for each call to
536 // SetNeedsDisplay. 538 // SetNeedsDisplay.
537 539
538 scoped_refptr<Layer> test_layer = Layer::Create(); 540 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
539 EXPECT_SET_NEEDS_FULL_TREE_SYNC( 541 EXPECT_SET_NEEDS_FULL_TREE_SYNC(
540 1, layer_tree_host_->SetRootLayer(test_layer)); 542 1, layer_tree_host_->SetRootLayer(test_layer));
541 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); 543 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true));
542 544
543 gfx::Size test_bounds = gfx::Size(501, 508); 545 gfx::Size test_bounds = gfx::Size(501, 508);
544 546
545 gfx::Rect dirty1 = gfx::Rect(10, 15, 1, 2); 547 gfx::Rect dirty1 = gfx::Rect(10, 15, 1, 2);
546 gfx::Rect dirty2 = gfx::Rect(20, 25, 3, 4); 548 gfx::Rect dirty2 = gfx::Rect(20, 25, 3, 4);
547 gfx::Rect out_of_bounds_dirty_rect = gfx::Rect(400, 405, 500, 502); 549 gfx::Rect out_of_bounds_dirty_rect = gfx::Rect(400, 405, 500, 502);
548 550
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 583
582 // Case 4: SetNeedsDisplay() with a non-drawable layer 584 // Case 4: SetNeedsDisplay() with a non-drawable layer
583 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false)); 585 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false));
584 test_layer->ResetNeedsDisplayForTesting(); 586 test_layer->ResetNeedsDisplayForTesting();
585 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); 587 EXPECT_FALSE(test_layer->NeedsDisplayForTesting());
586 EXPECT_SET_NEEDS_UPDATE(0, test_layer->SetNeedsDisplayRect(dirty1)); 588 EXPECT_SET_NEEDS_UPDATE(0, test_layer->SetNeedsDisplayRect(dirty1));
587 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); 589 EXPECT_TRUE(test_layer->NeedsDisplayForTesting());
588 } 590 }
589 591
590 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { 592 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) {
591 scoped_refptr<Layer> test_layer = Layer::Create(); 593 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
592 EXPECT_SET_NEEDS_FULL_TREE_SYNC( 594 EXPECT_SET_NEEDS_FULL_TREE_SYNC(
593 1, layer_tree_host_->SetRootLayer(test_layer)); 595 1, layer_tree_host_->SetRootLayer(test_layer));
594 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); 596 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true));
595 597
596 scoped_refptr<Layer> dummy_layer1 = Layer::Create(); 598 scoped_refptr<Layer> dummy_layer1 = Layer::Create(layer_settings_);
597 scoped_refptr<Layer> dummy_layer2 = Layer::Create(); 599 scoped_refptr<Layer> dummy_layer2 = Layer::Create(layer_settings_);
598 600
599 // sanity check of initial test condition 601 // sanity check of initial test condition
600 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); 602 EXPECT_FALSE(test_layer->NeedsDisplayForTesting());
601 603
602 // Next, test properties that should call SetNeedsCommit (but not 604 // Next, test properties that should call SetNeedsCommit (but not
603 // SetNeedsDisplay). All properties need to be set to new values in order for 605 // SetNeedsDisplay). All properties need to be set to new values in order for
604 // SetNeedsCommit to be called. 606 // SetNeedsCommit to be called.
605 EXPECT_SET_NEEDS_COMMIT( 607 EXPECT_SET_NEEDS_COMMIT(
606 1, test_layer->SetTransformOrigin(gfx::Point3F(1.23f, 4.56f, 0.f))); 608 1, test_layer->SetTransformOrigin(gfx::Point3F(1.23f, 4.56f, 0.f)));
607 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBackgroundColor(SK_ColorLTGRAY)); 609 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBackgroundColor(SK_ColorLTGRAY));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 dummy_layer2.get())); 642 dummy_layer2.get()));
641 643
642 // The above tests should not have caused a change to the needs_display flag. 644 // The above tests should not have caused a change to the needs_display flag.
643 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); 645 EXPECT_FALSE(test_layer->NeedsDisplayForTesting());
644 646
645 // As layers are removed from the tree, they will cause a tree sync. 647 // As layers are removed from the tree, they will cause a tree sync.
646 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); 648 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber()));
647 } 649 }
648 650
649 TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { 651 TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) {
650 scoped_refptr<Layer> test_layer = Layer::Create(); 652 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
651 scoped_ptr<LayerImpl> impl_layer = 653 scoped_ptr<LayerImpl> impl_layer =
652 LayerImpl::Create(host_impl_.active_tree(), 1); 654 LayerImpl::Create(host_impl_.active_tree(), 1);
653 655
654 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, 656 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1,
655 layer_tree_host_->SetRootLayer(test_layer)); 657 layer_tree_host_->SetRootLayer(test_layer));
656 658
657 test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5)); 659 test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5));
658 test_layer->PushPropertiesTo(impl_layer.get()); 660 test_layer->PushPropertiesTo(impl_layer.get());
659 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 5.f, 5.f), 661 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 5.f, 5.f),
660 impl_layer->update_rect()); 662 impl_layer->update_rect());
661 663
662 // The LayerImpl's update_rect() should be accumulated here, since we did not 664 // The LayerImpl's update_rect() should be accumulated here, since we did not
663 // do anything to clear it. 665 // do anything to clear it.
664 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); 666 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5));
665 test_layer->PushPropertiesTo(impl_layer.get()); 667 test_layer->PushPropertiesTo(impl_layer.get());
666 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 15.f, 15.f), 668 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 15.f, 15.f),
667 impl_layer->update_rect()); 669 impl_layer->update_rect());
668 670
669 // If we do clear the LayerImpl side, then the next update_rect() should be 671 // If we do clear the LayerImpl side, then the next update_rect() should be
670 // fresh without accumulation. 672 // fresh without accumulation.
671 impl_layer->ResetAllChangeTrackingForSubtree(); 673 impl_layer->ResetAllChangeTrackingForSubtree();
672 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); 674 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5));
673 test_layer->PushPropertiesTo(impl_layer.get()); 675 test_layer->PushPropertiesTo(impl_layer.get());
674 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10.f, 10.f, 5.f, 5.f), 676 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10.f, 10.f, 5.f, 5.f),
675 impl_layer->update_rect()); 677 impl_layer->update_rect());
676 } 678 }
677 679
678 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForTransform) { 680 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForTransform) {
679 scoped_refptr<Layer> test_layer = Layer::Create(); 681 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
680 scoped_ptr<LayerImpl> impl_layer = 682 scoped_ptr<LayerImpl> impl_layer =
681 LayerImpl::Create(host_impl_.active_tree(), 1); 683 LayerImpl::Create(host_impl_.active_tree(), 1);
682 684
683 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, 685 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1,
684 layer_tree_host_->SetRootLayer(test_layer)); 686 layer_tree_host_->SetRootLayer(test_layer));
685 687
686 gfx::Transform transform; 688 gfx::Transform transform;
687 transform.Rotate(45.0); 689 transform.Rotate(45.0);
688 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform)); 690 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform));
689 691
690 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); 692 EXPECT_FALSE(impl_layer->LayerPropertyChanged());
691 693
692 test_layer->PushPropertiesTo(impl_layer.get()); 694 test_layer->PushPropertiesTo(impl_layer.get());
693 695
694 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); 696 EXPECT_TRUE(impl_layer->LayerPropertyChanged());
695 } 697 }
696 698
697 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForOpacity) { 699 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForOpacity) {
698 scoped_refptr<Layer> test_layer = Layer::Create(); 700 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
699 scoped_ptr<LayerImpl> impl_layer = 701 scoped_ptr<LayerImpl> impl_layer =
700 LayerImpl::Create(host_impl_.active_tree(), 1); 702 LayerImpl::Create(host_impl_.active_tree(), 1);
701 703
702 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, 704 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1,
703 layer_tree_host_->SetRootLayer(test_layer)); 705 layer_tree_host_->SetRootLayer(test_layer));
704 706
705 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); 707 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f));
706 708
707 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); 709 EXPECT_FALSE(impl_layer->LayerPropertyChanged());
708 710
709 test_layer->PushPropertiesTo(impl_layer.get()); 711 test_layer->PushPropertiesTo(impl_layer.get());
710 712
711 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); 713 EXPECT_TRUE(impl_layer->LayerPropertyChanged());
712 } 714 }
713 715
714 TEST_F(LayerTest, 716 TEST_F(LayerTest,
715 PushPropsDoesntCauseLayerPropertyChangedDuringImplOnlyTransformAnim) { 717 PushPropsDoesntCauseLayerPropertyChangedDuringImplOnlyTransformAnim) {
716 scoped_refptr<Layer> test_layer = Layer::Create(); 718 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
717 scoped_ptr<LayerImpl> impl_layer = 719 scoped_ptr<LayerImpl> impl_layer =
718 LayerImpl::Create(host_impl_.active_tree(), 1); 720 LayerImpl::Create(host_impl_.active_tree(), 1);
719 721
720 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, 722 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1,
721 layer_tree_host_->SetRootLayer(test_layer)); 723 layer_tree_host_->SetRootLayer(test_layer));
722 724
723 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); 725 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create();
724 impl_layer->layer_animation_controller()->SetAnimationRegistrar( 726 impl_layer->layer_animation_controller()->SetAnimationRegistrar(
725 registrar.get()); 727 registrar.get());
726 728
(...skipping 21 matching lines...) Expand all
748 transform.Rotate(45.0); 750 transform.Rotate(45.0);
749 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform)); 751 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform));
750 752
751 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); 753 EXPECT_FALSE(impl_layer->LayerPropertyChanged());
752 test_layer->PushPropertiesTo(impl_layer.get()); 754 test_layer->PushPropertiesTo(impl_layer.get());
753 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); 755 EXPECT_FALSE(impl_layer->LayerPropertyChanged());
754 } 756 }
755 757
756 TEST_F(LayerTest, 758 TEST_F(LayerTest,
757 PushPropsDoesntCauseLayerPropertyChangedDuringImplOnlyOpacityAnim) { 759 PushPropsDoesntCauseLayerPropertyChangedDuringImplOnlyOpacityAnim) {
758 scoped_refptr<Layer> test_layer = Layer::Create(); 760 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
759 scoped_ptr<LayerImpl> impl_layer = 761 scoped_ptr<LayerImpl> impl_layer =
760 LayerImpl::Create(host_impl_.active_tree(), 1); 762 LayerImpl::Create(host_impl_.active_tree(), 1);
761 763
762 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, 764 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1,
763 layer_tree_host_->SetRootLayer(test_layer)); 765 layer_tree_host_->SetRootLayer(test_layer));
764 766
765 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); 767 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create();
766 impl_layer->layer_animation_controller()->SetAnimationRegistrar( 768 impl_layer->layer_animation_controller()->SetAnimationRegistrar(
767 registrar.get()); 769 registrar.get());
768 770
(...skipping 20 matching lines...) Expand all
789 ->set_is_impl_only(true); 791 ->set_is_impl_only(true);
790 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.75f)); 792 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.75f));
791 793
792 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); 794 EXPECT_FALSE(impl_layer->LayerPropertyChanged());
793 test_layer->PushPropertiesTo(impl_layer.get()); 795 test_layer->PushPropertiesTo(impl_layer.get());
794 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); 796 EXPECT_FALSE(impl_layer->LayerPropertyChanged());
795 } 797 }
796 798
797 TEST_F(LayerTest, 799 TEST_F(LayerTest,
798 PushPropsDoesntCauseLayerPropertyChangedDuringImplOnlyFilterAnim) { 800 PushPropsDoesntCauseLayerPropertyChangedDuringImplOnlyFilterAnim) {
799 scoped_refptr<Layer> test_layer = Layer::Create(); 801 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_);
800 scoped_ptr<LayerImpl> impl_layer = 802 scoped_ptr<LayerImpl> impl_layer =
801 LayerImpl::Create(host_impl_.active_tree(), 1); 803 LayerImpl::Create(host_impl_.active_tree(), 1);
802 804
803 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, 805 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1,
804 layer_tree_host_->SetRootLayer(test_layer)); 806 layer_tree_host_->SetRootLayer(test_layer));
805 807
806 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); 808 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create();
807 impl_layer->layer_animation_controller()->SetAnimationRegistrar( 809 impl_layer->layer_animation_controller()->SetAnimationRegistrar(
808 registrar.get()); 810 registrar.get());
809 811
(...skipping 16 matching lines...) Expand all
826 ->set_is_impl_only(true); 828 ->set_is_impl_only(true);
827 filters.Append(FilterOperation::CreateSepiaFilter(0.5f)); 829 filters.Append(FilterOperation::CreateSepiaFilter(0.5f));
828 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFilters(filters)); 830 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFilters(filters));
829 831
830 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); 832 EXPECT_FALSE(impl_layer->LayerPropertyChanged());
831 test_layer->PushPropertiesTo(impl_layer.get()); 833 test_layer->PushPropertiesTo(impl_layer.get());
832 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); 834 EXPECT_FALSE(impl_layer->LayerPropertyChanged());
833 } 835 }
834 836
835 TEST_F(LayerTest, MaskAndReplicaHasParent) { 837 TEST_F(LayerTest, MaskAndReplicaHasParent) {
836 scoped_refptr<Layer> parent = Layer::Create(); 838 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
837 scoped_refptr<Layer> child = Layer::Create(); 839 scoped_refptr<Layer> child = Layer::Create(layer_settings_);
838 scoped_refptr<Layer> mask = Layer::Create(); 840 scoped_refptr<Layer> mask = Layer::Create(layer_settings_);
839 scoped_refptr<Layer> replica = Layer::Create(); 841 scoped_refptr<Layer> replica = Layer::Create(layer_settings_);
840 scoped_refptr<Layer> replica_mask = Layer::Create(); 842 scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_);
841 scoped_refptr<Layer> mask_replacement = Layer::Create(); 843 scoped_refptr<Layer> mask_replacement = Layer::Create(layer_settings_);
842 scoped_refptr<Layer> replica_replacement = Layer::Create(); 844 scoped_refptr<Layer> replica_replacement = Layer::Create(layer_settings_);
843 scoped_refptr<Layer> replica_mask_replacement = Layer::Create(); 845 scoped_refptr<Layer> replica_mask_replacement =
846 Layer::Create(layer_settings_);
844 847
845 parent->AddChild(child); 848 parent->AddChild(child);
846 child->SetMaskLayer(mask.get()); 849 child->SetMaskLayer(mask.get());
847 child->SetReplicaLayer(replica.get()); 850 child->SetReplicaLayer(replica.get());
848 replica->SetMaskLayer(replica_mask.get()); 851 replica->SetMaskLayer(replica_mask.get());
849 852
850 EXPECT_EQ(parent.get(), child->parent()); 853 EXPECT_EQ(parent.get(), child->parent());
851 EXPECT_EQ(child.get(), mask->parent()); 854 EXPECT_EQ(child.get(), mask->parent());
852 EXPECT_EQ(child.get(), replica->parent()); 855 EXPECT_EQ(child.get(), replica->parent());
853 EXPECT_EQ(replica.get(), replica_mask->parent()); 856 EXPECT_EQ(replica.get(), replica_mask->parent());
854 857
855 replica->SetMaskLayer(replica_mask_replacement.get()); 858 replica->SetMaskLayer(replica_mask_replacement.get());
856 EXPECT_EQ(nullptr, replica_mask->parent()); 859 EXPECT_EQ(nullptr, replica_mask->parent());
857 EXPECT_EQ(replica.get(), replica_mask_replacement->parent()); 860 EXPECT_EQ(replica.get(), replica_mask_replacement->parent());
858 861
859 child->SetMaskLayer(mask_replacement.get()); 862 child->SetMaskLayer(mask_replacement.get());
860 EXPECT_EQ(nullptr, mask->parent()); 863 EXPECT_EQ(nullptr, mask->parent());
861 EXPECT_EQ(child.get(), mask_replacement->parent()); 864 EXPECT_EQ(child.get(), mask_replacement->parent());
862 865
863 child->SetReplicaLayer(replica_replacement.get()); 866 child->SetReplicaLayer(replica_replacement.get());
864 EXPECT_EQ(nullptr, replica->parent()); 867 EXPECT_EQ(nullptr, replica->parent());
865 EXPECT_EQ(child.get(), replica_replacement->parent()); 868 EXPECT_EQ(child.get(), replica_replacement->parent());
866 869
867 EXPECT_EQ(replica.get(), replica->mask_layer()->parent()); 870 EXPECT_EQ(replica.get(), replica->mask_layer()->parent());
868 } 871 }
869 872
870 TEST_F(LayerTest, CheckTranformIsInvertible) { 873 TEST_F(LayerTest, CheckTranformIsInvertible) {
871 scoped_refptr<Layer> layer = Layer::Create(); 874 scoped_refptr<Layer> layer = Layer::Create(layer_settings_);
872 scoped_ptr<LayerImpl> impl_layer = 875 scoped_ptr<LayerImpl> impl_layer =
873 LayerImpl::Create(host_impl_.active_tree(), 1); 876 LayerImpl::Create(host_impl_.active_tree(), 1);
874 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); 877 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1);
875 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 878 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
876 layer_tree_host_->SetRootLayer(layer); 879 layer_tree_host_->SetRootLayer(layer);
877 880
878 EXPECT_TRUE(layer->transform_is_invertible()); 881 EXPECT_TRUE(layer->transform_is_invertible());
879 882
880 gfx::Transform singular_transform; 883 gfx::Transform singular_transform;
881 singular_transform.Scale3d( 884 singular_transform.Scale3d(
(...skipping 10 matching lines...) Expand all
892 895
893 layer->SetTransform(rotation_transform); 896 layer->SetTransform(rotation_transform);
894 layer->PushPropertiesTo(impl_layer.get()); 897 layer->PushPropertiesTo(impl_layer.get());
895 EXPECT_TRUE(layer->transform_is_invertible()); 898 EXPECT_TRUE(layer->transform_is_invertible());
896 EXPECT_TRUE(impl_layer->transform_is_invertible()); 899 EXPECT_TRUE(impl_layer->transform_is_invertible());
897 900
898 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 901 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
899 } 902 }
900 903
901 TEST_F(LayerTest, TranformIsInvertibleAnimation) { 904 TEST_F(LayerTest, TranformIsInvertibleAnimation) {
902 scoped_refptr<Layer> layer = Layer::Create(); 905 scoped_refptr<Layer> layer = Layer::Create(layer_settings_);
903 scoped_ptr<LayerImpl> impl_layer = 906 scoped_ptr<LayerImpl> impl_layer =
904 LayerImpl::Create(host_impl_.active_tree(), 1); 907 LayerImpl::Create(host_impl_.active_tree(), 1);
905 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); 908 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1);
906 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 909 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
907 layer_tree_host_->SetRootLayer(layer); 910 layer_tree_host_->SetRootLayer(layer);
908 911
909 EXPECT_TRUE(layer->transform_is_invertible()); 912 EXPECT_TRUE(layer->transform_is_invertible());
910 913
911 gfx::Transform singular_transform; 914 gfx::Transform singular_transform;
912 singular_transform.Scale3d( 915 singular_transform.Scale3d(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 for (size_t i = 0; i < layer->children().size(); ++i) 966 for (size_t i = 0; i < layer->children().size(); ++i)
964 AssertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); 967 AssertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host);
965 968
966 if (layer->mask_layer()) 969 if (layer->mask_layer())
967 AssertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host); 970 AssertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host);
968 971
969 if (layer->replica_layer()) 972 if (layer->replica_layer())
970 AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); 973 AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host);
971 } 974 }
972 975
973 TEST(LayerLayerTreeHostTest, EnteringTree) { 976 class LayerLayerTreeHostTest : public testing::Test {
974 scoped_refptr<Layer> parent = Layer::Create(); 977 public:
975 scoped_refptr<Layer> child = Layer::Create(); 978 protected:
976 scoped_refptr<Layer> mask = Layer::Create(); 979 LayerSettings layer_settings_;
977 scoped_refptr<Layer> replica = Layer::Create(); 980 };
978 scoped_refptr<Layer> replica_mask = Layer::Create(); 981
982 TEST_F(LayerLayerTreeHostTest, EnteringTree) {
983 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
984 scoped_refptr<Layer> child = Layer::Create(layer_settings_);
985 scoped_refptr<Layer> mask = Layer::Create(layer_settings_);
986 scoped_refptr<Layer> replica = Layer::Create(layer_settings_);
987 scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_);
979 988
980 // Set up a detached tree of layers. The host pointer should be nil for these 989 // Set up a detached tree of layers. The host pointer should be nil for these
981 // layers. 990 // layers.
982 parent->AddChild(child); 991 parent->AddChild(child);
983 child->SetMaskLayer(mask.get()); 992 child->SetMaskLayer(mask.get());
984 child->SetReplicaLayer(replica.get()); 993 child->SetReplicaLayer(replica.get());
985 replica->SetMaskLayer(replica_mask.get()); 994 replica->SetMaskLayer(replica_mask.get());
986 995
987 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); 996 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr);
988 997
989 LayerTreeHostFactory factory; 998 LayerTreeHostFactory factory;
990 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); 999 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create();
991 // Setting the root layer should set the host pointer for all layers in the 1000 // Setting the root layer should set the host pointer for all layers in the
992 // tree. 1001 // tree.
993 layer_tree_host->SetRootLayer(parent.get()); 1002 layer_tree_host->SetRootLayer(parent.get());
994 1003
995 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); 1004 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get());
996 1005
997 // Clearing the root layer should also clear out the host pointers for all 1006 // Clearing the root layer should also clear out the host pointers for all
998 // layers in the tree. 1007 // layers in the tree.
999 layer_tree_host->SetRootLayer(nullptr); 1008 layer_tree_host->SetRootLayer(nullptr);
1000 1009
1001 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); 1010 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr);
1002 } 1011 }
1003 1012
1004 TEST(LayerLayerTreeHostTest, AddingLayerSubtree) { 1013 TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) {
1005 scoped_refptr<Layer> parent = Layer::Create(); 1014 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
1006 LayerTreeHostFactory factory; 1015 LayerTreeHostFactory factory;
1007 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); 1016 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create();
1008 1017
1009 layer_tree_host->SetRootLayer(parent.get()); 1018 layer_tree_host->SetRootLayer(parent.get());
1010 1019
1011 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get()); 1020 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get());
1012 1021
1013 // Adding a subtree to a layer already associated with a host should set the 1022 // Adding a subtree to a layer already associated with a host should set the
1014 // host pointer on all layers in that subtree. 1023 // host pointer on all layers in that subtree.
1015 scoped_refptr<Layer> child = Layer::Create(); 1024 scoped_refptr<Layer> child = Layer::Create(layer_settings_);
1016 scoped_refptr<Layer> grand_child = Layer::Create(); 1025 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings_);
1017 child->AddChild(grand_child); 1026 child->AddChild(grand_child);
1018 1027
1019 // Masks, replicas, and replica masks should pick up the new host too. 1028 // Masks, replicas, and replica masks should pick up the new host too.
1020 scoped_refptr<Layer> child_mask = Layer::Create(); 1029 scoped_refptr<Layer> child_mask = Layer::Create(layer_settings_);
1021 child->SetMaskLayer(child_mask.get()); 1030 child->SetMaskLayer(child_mask.get());
1022 scoped_refptr<Layer> child_replica = Layer::Create(); 1031 scoped_refptr<Layer> child_replica = Layer::Create(layer_settings_);
1023 child->SetReplicaLayer(child_replica.get()); 1032 child->SetReplicaLayer(child_replica.get());
1024 scoped_refptr<Layer> child_replica_mask = Layer::Create(); 1033 scoped_refptr<Layer> child_replica_mask = Layer::Create(layer_settings_);
1025 child_replica->SetMaskLayer(child_replica_mask.get()); 1034 child_replica->SetMaskLayer(child_replica_mask.get());
1026 1035
1027 parent->AddChild(child); 1036 parent->AddChild(child);
1028 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); 1037 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get());
1029 1038
1030 layer_tree_host->SetRootLayer(nullptr); 1039 layer_tree_host->SetRootLayer(nullptr);
1031 } 1040 }
1032 1041
1033 TEST(LayerLayerTreeHostTest, ChangeHost) { 1042 TEST_F(LayerLayerTreeHostTest, ChangeHost) {
1034 scoped_refptr<Layer> parent = Layer::Create(); 1043 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
1035 scoped_refptr<Layer> child = Layer::Create(); 1044 scoped_refptr<Layer> child = Layer::Create(layer_settings_);
1036 scoped_refptr<Layer> mask = Layer::Create(); 1045 scoped_refptr<Layer> mask = Layer::Create(layer_settings_);
1037 scoped_refptr<Layer> replica = Layer::Create(); 1046 scoped_refptr<Layer> replica = Layer::Create(layer_settings_);
1038 scoped_refptr<Layer> replica_mask = Layer::Create(); 1047 scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_);
1039 1048
1040 // Same setup as the previous test. 1049 // Same setup as the previous test.
1041 parent->AddChild(child); 1050 parent->AddChild(child);
1042 child->SetMaskLayer(mask.get()); 1051 child->SetMaskLayer(mask.get());
1043 child->SetReplicaLayer(replica.get()); 1052 child->SetReplicaLayer(replica.get());
1044 replica->SetMaskLayer(replica_mask.get()); 1053 replica->SetMaskLayer(replica_mask.get());
1045 1054
1046 LayerTreeHostFactory factory; 1055 LayerTreeHostFactory factory;
1047 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); 1056 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create();
1048 first_layer_tree_host->SetRootLayer(parent.get()); 1057 first_layer_tree_host->SetRootLayer(parent.get());
1049 1058
1050 AssertLayerTreeHostMatchesForSubtree(parent.get(), 1059 AssertLayerTreeHostMatchesForSubtree(parent.get(),
1051 first_layer_tree_host.get()); 1060 first_layer_tree_host.get());
1052 1061
1053 // Now re-root the tree to a new host (simulating what we do on a context lost 1062 // Now re-root the tree to a new host (simulating what we do on a context lost
1054 // event). This should update the host pointers for all layers in the tree. 1063 // event). This should update the host pointers for all layers in the tree.
1055 scoped_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(); 1064 scoped_ptr<LayerTreeHost> second_layer_tree_host = factory.Create();
1056 second_layer_tree_host->SetRootLayer(parent.get()); 1065 second_layer_tree_host->SetRootLayer(parent.get());
1057 1066
1058 AssertLayerTreeHostMatchesForSubtree(parent.get(), 1067 AssertLayerTreeHostMatchesForSubtree(parent.get(),
1059 second_layer_tree_host.get()); 1068 second_layer_tree_host.get());
1060 1069
1061 second_layer_tree_host->SetRootLayer(nullptr); 1070 second_layer_tree_host->SetRootLayer(nullptr);
1062 } 1071 }
1063 1072
1064 TEST(LayerLayerTreeHostTest, ChangeHostInSubtree) { 1073 TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) {
1065 scoped_refptr<Layer> first_parent = Layer::Create(); 1074 scoped_refptr<Layer> first_parent = Layer::Create(layer_settings_);
1066 scoped_refptr<Layer> first_child = Layer::Create(); 1075 scoped_refptr<Layer> first_child = Layer::Create(layer_settings_);
1067 scoped_refptr<Layer> second_parent = Layer::Create(); 1076 scoped_refptr<Layer> second_parent = Layer::Create(layer_settings_);
1068 scoped_refptr<Layer> second_child = Layer::Create(); 1077 scoped_refptr<Layer> second_child = Layer::Create(layer_settings_);
1069 scoped_refptr<Layer> second_grand_child = Layer::Create(); 1078 scoped_refptr<Layer> second_grand_child = Layer::Create(layer_settings_);
1070 1079
1071 // First put all children under the first parent and set the first host. 1080 // First put all children under the first parent and set the first host.
1072 first_parent->AddChild(first_child); 1081 first_parent->AddChild(first_child);
1073 second_child->AddChild(second_grand_child); 1082 second_child->AddChild(second_grand_child);
1074 first_parent->AddChild(second_child); 1083 first_parent->AddChild(second_child);
1075 1084
1076 LayerTreeHostFactory factory; 1085 LayerTreeHostFactory factory;
1077 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); 1086 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create();
1078 first_layer_tree_host->SetRootLayer(first_parent.get()); 1087 first_layer_tree_host->SetRootLayer(first_parent.get());
1079 1088
(...skipping 10 matching lines...) Expand all
1090 // The moved layer and its children should point to the new host. 1099 // The moved layer and its children should point to the new host.
1091 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host()); 1100 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host());
1092 EXPECT_EQ(second_layer_tree_host.get(), 1101 EXPECT_EQ(second_layer_tree_host.get(),
1093 second_grand_child->layer_tree_host()); 1102 second_grand_child->layer_tree_host());
1094 1103
1095 // Test over, cleanup time. 1104 // Test over, cleanup time.
1096 first_layer_tree_host->SetRootLayer(nullptr); 1105 first_layer_tree_host->SetRootLayer(nullptr);
1097 second_layer_tree_host->SetRootLayer(nullptr); 1106 second_layer_tree_host->SetRootLayer(nullptr);
1098 } 1107 }
1099 1108
1100 TEST(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { 1109 TEST_F(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) {
1101 scoped_refptr<Layer> parent = Layer::Create(); 1110 scoped_refptr<Layer> parent = Layer::Create(layer_settings_);
1102 scoped_refptr<Layer> mask = Layer::Create(); 1111 scoped_refptr<Layer> mask = Layer::Create(layer_settings_);
1103 scoped_refptr<Layer> replica = Layer::Create(); 1112 scoped_refptr<Layer> replica = Layer::Create(layer_settings_);
1104 scoped_refptr<Layer> mask_child = Layer::Create(); 1113 scoped_refptr<Layer> mask_child = Layer::Create(layer_settings_);
1105 scoped_refptr<Layer> replica_child = Layer::Create(); 1114 scoped_refptr<Layer> replica_child = Layer::Create(layer_settings_);
1106 scoped_refptr<Layer> mask_replacement = Layer::Create(); 1115 scoped_refptr<Layer> mask_replacement = Layer::Create(layer_settings_);
1107 scoped_refptr<Layer> replica_replacement = Layer::Create(); 1116 scoped_refptr<Layer> replica_replacement = Layer::Create(layer_settings_);
1108 1117
1109 parent->SetMaskLayer(mask.get()); 1118 parent->SetMaskLayer(mask.get());
1110 parent->SetReplicaLayer(replica.get()); 1119 parent->SetReplicaLayer(replica.get());
1111 mask->AddChild(mask_child); 1120 mask->AddChild(mask_child);
1112 replica->AddChild(replica_child); 1121 replica->AddChild(replica_child);
1113 1122
1114 LayerTreeHostFactory factory; 1123 LayerTreeHostFactory factory;
1115 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); 1124 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create();
1116 layer_tree_host->SetRootLayer(parent.get()); 1125 layer_tree_host->SetRootLayer(parent.get());
1117 1126
1118 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); 1127 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get());
1119 1128
1120 // Replacing the mask should clear out the old mask's subtree's host pointers. 1129 // Replacing the mask should clear out the old mask's subtree's host pointers.
1121 parent->SetMaskLayer(mask_replacement.get()); 1130 parent->SetMaskLayer(mask_replacement.get());
1122 EXPECT_EQ(nullptr, mask->layer_tree_host()); 1131 EXPECT_EQ(nullptr, mask->layer_tree_host());
1123 EXPECT_EQ(nullptr, mask_child->layer_tree_host()); 1132 EXPECT_EQ(nullptr, mask_child->layer_tree_host());
1124 1133
1125 // Same for replacing a replica layer. 1134 // Same for replacing a replica layer.
1126 parent->SetReplicaLayer(replica_replacement.get()); 1135 parent->SetReplicaLayer(replica_replacement.get());
1127 EXPECT_EQ(nullptr, replica->layer_tree_host()); 1136 EXPECT_EQ(nullptr, replica->layer_tree_host());
1128 EXPECT_EQ(nullptr, replica_child->layer_tree_host()); 1137 EXPECT_EQ(nullptr, replica_child->layer_tree_host());
1129 1138
1130 // Test over, cleanup time. 1139 // Test over, cleanup time.
1131 layer_tree_host->SetRootLayer(nullptr); 1140 layer_tree_host->SetRootLayer(nullptr);
1132 } 1141 }
1133 1142
1134 TEST(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { 1143 TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) {
1135 scoped_refptr<Layer> root = Layer::Create(); 1144 scoped_refptr<Layer> root = Layer::Create(layer_settings_);
1136 scoped_refptr<Layer> child = Layer::Create(); 1145 scoped_refptr<Layer> child = Layer::Create(layer_settings_);
1137 root->AddChild(child); 1146 root->AddChild(child);
1138 LayerTreeHostFactory factory; 1147 LayerTreeHostFactory factory;
1139 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); 1148 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create();
1140 layer_tree_host->SetRootLayer(root); 1149 layer_tree_host->SetRootLayer(root);
1141 } 1150 }
1142 1151
1143 static bool AddTestAnimation(Layer* layer) { 1152 static bool AddTestAnimation(Layer* layer) {
1144 scoped_ptr<KeyframedFloatAnimationCurve> curve = 1153 scoped_ptr<KeyframedFloatAnimationCurve> curve =
1145 KeyframedFloatAnimationCurve::Create(); 1154 KeyframedFloatAnimationCurve::Create();
1146 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.3f, nullptr)); 1155 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.3f, nullptr));
1147 curve->AddKeyframe( 1156 curve->AddKeyframe(
1148 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.7f, nullptr)); 1157 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.7f, nullptr));
1149 scoped_ptr<Animation> animation = 1158 scoped_ptr<Animation> animation =
1150 Animation::Create(curve.Pass(), 0, 0, Animation::OPACITY); 1159 Animation::Create(curve.Pass(), 0, 0, Animation::OPACITY);
1151 1160
1152 return layer->AddAnimation(animation.Pass()); 1161 return layer->AddAnimation(animation.Pass());
1153 } 1162 }
1154 1163
1155 TEST(LayerLayerTreeHostTest, ShouldNotAddAnimationWithoutAnimationRegistrar) { 1164 TEST_F(LayerLayerTreeHostTest, ShouldNotAddAnimationWithoutAnimationRegistrar) {
1156 scoped_refptr<Layer> layer = Layer::Create(); 1165 scoped_refptr<Layer> layer = Layer::Create(layer_settings_);
1157 1166
1158 // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the 1167 // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the
1159 // animation should not be accepted. 1168 // animation should not be accepted.
1160 EXPECT_FALSE(AddTestAnimation(layer.get())); 1169 EXPECT_FALSE(AddTestAnimation(layer.get()));
1161 1170
1162 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); 1171 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create();
1163 layer->layer_animation_controller()->SetAnimationRegistrar(registrar.get()); 1172 layer->RegisterForAnimations(registrar.get());
1164 1173
1165 // Case 2: with an AnimationRegistrar, the animation should be accepted. 1174 // Case 2: with an AnimationRegistrar, the animation should be accepted.
1166 EXPECT_TRUE(AddTestAnimation(layer.get())); 1175 EXPECT_TRUE(AddTestAnimation(layer.get()));
1167 1176
1168 LayerTreeSettings settings; 1177 LayerTreeSettings settings;
1169 settings.accelerated_animation_enabled = false; 1178 settings.accelerated_animation_enabled = false;
1170 LayerTreeHostFactory factory; 1179 LayerTreeHostFactory factory;
1171 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(settings); 1180 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(settings);
1172 layer_tree_host->SetRootLayer(layer); 1181 layer_tree_host->SetRootLayer(layer);
1173 AssertLayerTreeHostMatchesForSubtree(layer.get(), layer_tree_host.get()); 1182 AssertLayerTreeHostMatchesForSubtree(layer.get(), layer_tree_host.get());
1174 1183
1175 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the 1184 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the
1176 // animation should be rejected. 1185 // animation should be rejected.
1177 EXPECT_FALSE(AddTestAnimation(layer.get())); 1186 EXPECT_FALSE(AddTestAnimation(layer.get()));
1178 } 1187 }
1179 1188
1180 TEST_F(LayerTest, SafeOpaqueBackgroundColor) { 1189 TEST_F(LayerTest, SafeOpaqueBackgroundColor) {
1181 LayerTreeHostFactory factory; 1190 LayerTreeHostFactory factory;
1182 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); 1191 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create();
1183 1192
1184 scoped_refptr<Layer> layer = Layer::Create(); 1193 scoped_refptr<Layer> layer = Layer::Create(layer_settings_);
1185 layer_tree_host->SetRootLayer(layer); 1194 layer_tree_host->SetRootLayer(layer);
1186 1195
1187 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { 1196 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) {
1188 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { 1197 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) {
1189 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { 1198 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) {
1190 layer->SetContentsOpaque(!!contents_opaque); 1199 layer->SetContentsOpaque(!!contents_opaque);
1191 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED 1200 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED
1192 : SK_ColorTRANSPARENT); 1201 : SK_ColorTRANSPARENT);
1193 layer_tree_host->set_background_color( 1202 layer_tree_host->set_background_color(
1194 host_opaque ? SK_ColorRED : SK_ColorTRANSPARENT); 1203 host_opaque ? SK_ColorRED : SK_ColorTRANSPARENT);
1195 1204
1196 SkColor safe_color = layer->SafeOpaqueBackgroundColor(); 1205 SkColor safe_color = layer->SafeOpaqueBackgroundColor();
1197 if (contents_opaque) { 1206 if (contents_opaque) {
1198 EXPECT_EQ(SkColorGetA(safe_color), 255u) 1207 EXPECT_EQ(SkColorGetA(safe_color), 255u)
1199 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " 1208 << "Flags: " << contents_opaque << ", " << layer_opaque << ", "
1200 << host_opaque << "\n"; 1209 << host_opaque << "\n";
1201 } else { 1210 } else {
1202 EXPECT_NE(SkColorGetA(safe_color), 255u) 1211 EXPECT_NE(SkColorGetA(safe_color), 255u)
1203 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " 1212 << "Flags: " << contents_opaque << ", " << layer_opaque << ", "
1204 << host_opaque << "\n"; 1213 << host_opaque << "\n";
1205 } 1214 }
1206 } 1215 }
1207 } 1216 }
1208 } 1217 }
1209 } 1218 }
1210 1219
1211 class DrawsContentChangeLayer : public Layer { 1220 class DrawsContentChangeLayer : public Layer {
1212 public: 1221 public:
1213 static scoped_refptr<DrawsContentChangeLayer> Create() { 1222 static scoped_refptr<DrawsContentChangeLayer> Create(
1214 return make_scoped_refptr(new DrawsContentChangeLayer()); 1223 const LayerSettings& settings) {
1224 return make_scoped_refptr(new DrawsContentChangeLayer(settings));
1215 } 1225 }
1216 1226
1217 void SetLayerTreeHost(LayerTreeHost* host) override { 1227 void SetLayerTreeHost(LayerTreeHost* host) override {
1218 Layer::SetLayerTreeHost(host); 1228 Layer::SetLayerTreeHost(host);
1219 SetFakeDrawsContent(!fake_draws_content_); 1229 SetFakeDrawsContent(!fake_draws_content_);
1220 } 1230 }
1221 1231
1222 bool HasDrawableContent() const override { 1232 bool HasDrawableContent() const override {
1223 return fake_draws_content_ && Layer::HasDrawableContent(); 1233 return fake_draws_content_ && Layer::HasDrawableContent();
1224 } 1234 }
1225 1235
1226 void SetFakeDrawsContent(bool fake_draws_content) { 1236 void SetFakeDrawsContent(bool fake_draws_content) {
1227 fake_draws_content_ = fake_draws_content; 1237 fake_draws_content_ = fake_draws_content;
1228 UpdateDrawsContent(HasDrawableContent()); 1238 UpdateDrawsContent(HasDrawableContent());
1229 } 1239 }
1230 1240
1231 private: 1241 private:
1232 DrawsContentChangeLayer() : Layer(), fake_draws_content_(false) {} 1242 explicit DrawsContentChangeLayer(const LayerSettings& settings)
1243 : Layer(settings), fake_draws_content_(false) {}
1233 ~DrawsContentChangeLayer() override {} 1244 ~DrawsContentChangeLayer() override {}
1234 1245
1235 bool fake_draws_content_; 1246 bool fake_draws_content_;
1236 }; 1247 };
1237 1248
1238 TEST_F(LayerTest, DrawsContentChangedInSetLayerTreeHost) { 1249 TEST_F(LayerTest, DrawsContentChangedInSetLayerTreeHost) {
1239 scoped_refptr<Layer> root_layer = Layer::Create(); 1250 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings_);
1240 scoped_refptr<DrawsContentChangeLayer> becomes_not_draws_content = 1251 scoped_refptr<DrawsContentChangeLayer> becomes_not_draws_content =
1241 DrawsContentChangeLayer::Create(); 1252 DrawsContentChangeLayer::Create(layer_settings_);
1242 scoped_refptr<DrawsContentChangeLayer> becomes_draws_content = 1253 scoped_refptr<DrawsContentChangeLayer> becomes_draws_content =
1243 DrawsContentChangeLayer::Create(); 1254 DrawsContentChangeLayer::Create(layer_settings_);
1244 root_layer->SetIsDrawable(true); 1255 root_layer->SetIsDrawable(true);
1245 becomes_not_draws_content->SetIsDrawable(true); 1256 becomes_not_draws_content->SetIsDrawable(true);
1246 becomes_not_draws_content->SetFakeDrawsContent(true); 1257 becomes_not_draws_content->SetFakeDrawsContent(true);
1247 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); 1258 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent());
1248 root_layer->AddChild(becomes_not_draws_content); 1259 root_layer->AddChild(becomes_not_draws_content);
1249 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); 1260 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent());
1250 1261
1251 becomes_draws_content->SetIsDrawable(true); 1262 becomes_draws_content->SetIsDrawable(true);
1252 root_layer->AddChild(becomes_draws_content); 1263 root_layer->AddChild(becomes_draws_content);
1253 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent()); 1264 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent());
1254 } 1265 }
1255 1266
1256 void ReceiveCopyOutputResult(int* result_count, 1267 void ReceiveCopyOutputResult(int* result_count,
1257 scoped_ptr<CopyOutputResult> result) { 1268 scoped_ptr<CopyOutputResult> result) {
1258 ++(*result_count); 1269 ++(*result_count);
1259 } 1270 }
1260 1271
1261 TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { 1272 TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) {
1262 scoped_refptr<Layer> layer = Layer::Create(); 1273 scoped_refptr<Layer> layer = Layer::Create(layer_settings_);
1263 int result_count = 0; 1274 int result_count = 0;
1264 1275
1265 // Create identical requests without the source being set, and expect the 1276 // Create identical requests without the source being set, and expect the
1266 // layer does not abort either one. 1277 // layer does not abort either one.
1267 scoped_ptr<CopyOutputRequest> request = CopyOutputRequest::CreateRequest( 1278 scoped_ptr<CopyOutputRequest> request = CopyOutputRequest::CreateRequest(
1268 base::Bind(&ReceiveCopyOutputResult, &result_count)); 1279 base::Bind(&ReceiveCopyOutputResult, &result_count));
1269 layer->RequestCopyOfOutput(request.Pass()); 1280 layer->RequestCopyOfOutput(request.Pass());
1270 EXPECT_EQ(0, result_count); 1281 EXPECT_EQ(0, result_count);
1271 request = CopyOutputRequest::CreateRequest( 1282 request = CopyOutputRequest::CreateRequest(
1272 base::Bind(&ReceiveCopyOutputResult, &result_count)); 1283 base::Bind(&ReceiveCopyOutputResult, &result_count));
1273 layer->RequestCopyOfOutput(request.Pass()); 1284 layer->RequestCopyOfOutput(request.Pass());
1274 EXPECT_EQ(0, result_count); 1285 EXPECT_EQ(0, result_count);
1275 1286
1276 // When the layer is destroyed, expect both requests to be aborted. 1287 // When the layer is destroyed, expect both requests to be aborted.
1277 layer = nullptr; 1288 layer = nullptr;
1278 EXPECT_EQ(2, result_count); 1289 EXPECT_EQ(2, result_count);
1279 1290
1280 layer = Layer::Create(); 1291 layer = Layer::Create(layer_settings_);
1281 result_count = 0; 1292 result_count = 0;
1282 1293
1283 // Create identical requests, but this time the source is being set. Expect 1294 // Create identical requests, but this time the source is being set. Expect
1284 // the first request from |this| source aborts immediately when the second 1295 // the first request from |this| source aborts immediately when the second
1285 // request from |this| source is made. 1296 // request from |this| source is made.
1286 int did_receive_first_result_from_this_source = 0; 1297 int did_receive_first_result_from_this_source = 0;
1287 request = CopyOutputRequest::CreateRequest(base::Bind( 1298 request = CopyOutputRequest::CreateRequest(base::Bind(
1288 &ReceiveCopyOutputResult, &did_receive_first_result_from_this_source)); 1299 &ReceiveCopyOutputResult, &did_receive_first_result_from_this_source));
1289 request->set_source(this); 1300 request->set_source(this);
1290 layer->RequestCopyOfOutput(request.Pass()); 1301 layer->RequestCopyOfOutput(request.Pass());
(...skipping 25 matching lines...) Expand all
1316 // When the layer is destroyed, the other three requests should be aborted. 1327 // When the layer is destroyed, the other three requests should be aborted.
1317 layer = nullptr; 1328 layer = nullptr;
1318 EXPECT_EQ(1, did_receive_first_result_from_this_source); 1329 EXPECT_EQ(1, did_receive_first_result_from_this_source);
1319 EXPECT_EQ(1, did_receive_result_from_different_source); 1330 EXPECT_EQ(1, did_receive_result_from_different_source);
1320 EXPECT_EQ(1, did_receive_result_from_anonymous_source); 1331 EXPECT_EQ(1, did_receive_result_from_anonymous_source);
1321 EXPECT_EQ(1, did_receive_second_result_from_this_source); 1332 EXPECT_EQ(1, did_receive_second_result_from_this_source);
1322 } 1333 }
1323 1334
1324 } // namespace 1335 } // namespace
1325 } // namespace cc 1336 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698