| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/layer.h" | 5 #include "cc/layers/layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "cc/animation/animation_host.h" | 11 #include "cc/animation/animation_host.h" |
| 12 #include "cc/animation/animation_id_provider.h" | 12 #include "cc/animation/animation_id_provider.h" |
| 13 #include "cc/animation/keyframed_animation_curve.h" | 13 #include "cc/animation/keyframed_animation_curve.h" |
| 14 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
| 15 #include "cc/input/main_thread_scrolling_reason.h" | 15 #include "cc/input/main_thread_scrolling_reason.h" |
| 16 #include "cc/layers/layer_impl.h" | 16 #include "cc/layers/layer_impl.h" |
| 17 #include "cc/layers/solid_color_scrollbar_layer.h" | 17 #include "cc/layers/solid_color_scrollbar_layer.h" |
| 18 #include "cc/output/copy_output_request.h" | 18 #include "cc/output/copy_output_request.h" |
| 19 #include "cc/output/copy_output_result.h" | 19 #include "cc/output/copy_output_result.h" |
| 20 #include "cc/test/animation_test_common.h" | 20 #include "cc/test/animation_test_common.h" |
| 21 #include "cc/test/fake_impl_task_runner_provider.h" | 21 #include "cc/test/fake_impl_task_runner_provider.h" |
| 22 #include "cc/test/fake_layer_tree_host.h" | 22 #include "cc/test/fake_layer_tree_host.h" |
| 23 #include "cc/test/fake_layer_tree_host_client.h" | 23 #include "cc/test/fake_layer_tree_host_client.h" |
| 24 #include "cc/test/fake_layer_tree_host_impl.h" | 24 #include "cc/test/fake_layer_tree_host_impl.h" |
| 25 #include "cc/test/geometry_test_utils.h" | 25 #include "cc/test/geometry_test_utils.h" |
| 26 #include "cc/test/layer_internals_for_test.h" | |
| 27 #include "cc/test/layer_test_common.h" | 26 #include "cc/test/layer_test_common.h" |
| 28 #include "cc/test/stub_layer_tree_host_single_thread_client.h" | 27 #include "cc/test/stub_layer_tree_host_single_thread_client.h" |
| 29 #include "cc/test/test_task_graph_runner.h" | 28 #include "cc/test/test_task_graph_runner.h" |
| 30 #include "cc/trees/layer_tree_host.h" | 29 #include "cc/trees/layer_tree_host.h" |
| 31 #include "cc/trees/mutable_properties.h" | 30 #include "cc/trees/mutable_properties.h" |
| 32 #include "cc/trees/single_thread_proxy.h" | 31 #include "cc/trees/single_thread_proxy.h" |
| 33 #include "cc/trees/transform_node.h" | 32 #include "cc/trees/transform_node.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "third_party/skia/include/core/SkColor.h" | 35 #include "third_party/skia/include/core/SkColor.h" |
| (...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1375 | 1374 |
| 1376 // When the layer is destroyed, the other three requests should be aborted. | 1375 // When the layer is destroyed, the other three requests should be aborted. |
| 1377 layer = nullptr; | 1376 layer = nullptr; |
| 1378 EXPECT_EQ(1, did_receive_first_result_from_this_source); | 1377 EXPECT_EQ(1, did_receive_first_result_from_this_source); |
| 1379 EXPECT_EQ(1, did_receive_result_from_different_source); | 1378 EXPECT_EQ(1, did_receive_result_from_different_source); |
| 1380 EXPECT_EQ(1, did_receive_result_from_anonymous_source); | 1379 EXPECT_EQ(1, did_receive_result_from_anonymous_source); |
| 1381 EXPECT_EQ(1, did_receive_second_result_from_this_source); | 1380 EXPECT_EQ(1, did_receive_second_result_from_this_source); |
| 1382 } | 1381 } |
| 1383 | 1382 |
| 1384 TEST_F(LayerTest, AnimationSchedulesLayerUpdate) { | 1383 TEST_F(LayerTest, AnimationSchedulesLayerUpdate) { |
| 1384 // TODO(weiliangc): This is really a LayerTreeHost unittest by this point, |
| 1385 // though currently there is no good place for this unittest to go. Move to |
| 1386 // LayerTreeHost unittest when there is a good setup. |
| 1385 scoped_refptr<Layer> layer = Layer::Create(); | 1387 scoped_refptr<Layer> layer = Layer::Create(); |
| 1388 layer->SetElementId(ElementId(2, 0)); |
| 1386 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(layer)); | 1389 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(layer)); |
| 1387 | 1390 auto element_id = layer->element_id(); |
| 1388 LayerInternalsForTest layer_internals(layer.get()); | |
| 1389 | 1391 |
| 1390 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); | 1392 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); |
| 1391 layer_internals.OnOpacityAnimated(0.5f); | 1393 layer_tree_host_->SetElementOpacityMutated(element_id, |
| 1394 ElementListType::ACTIVE, 0.5f); |
| 1392 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 1395 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 1393 | 1396 |
| 1394 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); | 1397 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); |
| 1395 gfx::Transform transform; | 1398 gfx::Transform transform; |
| 1396 transform.Rotate(45.0); | 1399 transform.Rotate(45.0); |
| 1397 layer_internals.OnTransformAnimated(transform); | 1400 layer_tree_host_->SetElementTransformMutated( |
| 1401 element_id, ElementListType::ACTIVE, transform); |
| 1398 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 1402 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 1399 | 1403 |
| 1400 // Scroll offset animation should not schedule a layer update since it is | 1404 // Scroll offset animation should not schedule a layer update since it is |
| 1401 // handled similarly to normal compositor scroll updates. | 1405 // handled similarly to normal compositor scroll updates. |
| 1402 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); | 1406 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); |
| 1403 layer_internals.OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); | 1407 layer_tree_host_->SetElementScrollOffsetMutated( |
| 1408 element_id, ElementListType::ACTIVE, gfx::ScrollOffset(10, 10)); |
| 1404 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 1409 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 1405 } | 1410 } |
| 1406 | 1411 |
| 1407 TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { | 1412 TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { |
| 1408 scoped_refptr<Layer> test_layer = Layer::Create(); | 1413 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 1409 std::unique_ptr<LayerImpl> impl_layer = | 1414 std::unique_ptr<LayerImpl> impl_layer = |
| 1410 LayerImpl::Create(host_impl_.active_tree(), 1); | 1415 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1411 | 1416 |
| 1412 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 1417 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
| 1413 layer_tree_host_->SetRootLayer(test_layer)); | 1418 layer_tree_host_->SetRootLayer(test_layer)); |
| 1414 | 1419 |
| 1415 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); | 1420 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); |
| 1416 | 1421 |
| 1417 test_layer->SetElementId(ElementId(2, 0)); | 1422 test_layer->SetElementId(ElementId(2, 0)); |
| 1418 test_layer->SetMutableProperties(MutableProperty::kTransform); | 1423 test_layer->SetMutableProperties(MutableProperty::kTransform); |
| 1419 | 1424 |
| 1420 EXPECT_FALSE(impl_layer->element_id()); | 1425 EXPECT_FALSE(impl_layer->element_id()); |
| 1421 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); | 1426 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); |
| 1422 | 1427 |
| 1423 test_layer->PushPropertiesTo(impl_layer.get()); | 1428 test_layer->PushPropertiesTo(impl_layer.get()); |
| 1424 | 1429 |
| 1425 EXPECT_EQ(ElementId(2, 0), impl_layer->element_id()); | 1430 EXPECT_EQ(ElementId(2, 0), impl_layer->element_id()); |
| 1426 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); | 1431 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); |
| 1427 } | 1432 } |
| 1428 | 1433 |
| 1429 } // namespace | 1434 } // namespace |
| 1430 } // namespace cc | 1435 } // namespace cc |
| OLD | NEW |