Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "cc/output/delegated_frame_data.h" | 22 #include "cc/output/delegated_frame_data.h" |
| 23 #include "cc/test/pixel_test_utils.h" | 23 #include "cc/test/pixel_test_utils.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "ui/compositor/compositor_observer.h" | 25 #include "ui/compositor/compositor_observer.h" |
| 26 #include "ui/compositor/dip_util.h" | 26 #include "ui/compositor/dip_util.h" |
| 27 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
| 28 #include "ui/compositor/layer_animation_sequence.h" | 28 #include "ui/compositor/layer_animation_sequence.h" |
| 29 #include "ui/compositor/layer_animator.h" | 29 #include "ui/compositor/layer_animator.h" |
| 30 #include "ui/compositor/paint_context.h" | 30 #include "ui/compositor/paint_context.h" |
| 31 #include "ui/compositor/paint_recorder.h" | 31 #include "ui/compositor/paint_recorder.h" |
| 32 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | |
| 33 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 32 #include "ui/compositor/test/context_factories_for_test.h" | 34 #include "ui/compositor/test/context_factories_for_test.h" |
| 33 #include "ui/compositor/test/draw_waiter_for_test.h" | 35 #include "ui/compositor/test/draw_waiter_for_test.h" |
| 34 #include "ui/compositor/test/test_compositor_host.h" | 36 #include "ui/compositor/test/test_compositor_host.h" |
| 35 #include "ui/compositor/test/test_layers.h" | 37 #include "ui/compositor/test/test_layers.h" |
| 36 #include "ui/gfx/canvas.h" | 38 #include "ui/gfx/canvas.h" |
| 37 #include "ui/gfx/codec/png_codec.h" | 39 #include "ui/gfx/codec/png_codec.h" |
| 38 #include "ui/gfx/gfx_paths.h" | 40 #include "ui/gfx/gfx_paths.h" |
| 39 #include "ui/gfx/skia_util.h" | 41 #include "ui/gfx/skia_util.h" |
| 40 | 42 |
| 41 using cc::MatchesPNGFile; | 43 using cc::MatchesPNGFile; |
| (...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1597 // Trigger a threaded animation. | 1599 // Trigger a threaded animation. |
| 1598 l1->SetOpacity(0.5f); | 1600 l1->SetOpacity(0.5f); |
| 1599 | 1601 |
| 1600 // Change l1's cc::Layer. | 1602 // Change l1's cc::Layer. |
| 1601 l1->SwitchCCLayerForTest(); | 1603 l1->SwitchCCLayerForTest(); |
| 1602 | 1604 |
| 1603 // Ensure that the opacity animation completed. | 1605 // Ensure that the opacity animation completed. |
| 1604 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); | 1606 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); |
| 1605 } | 1607 } |
| 1606 | 1608 |
| 1609 // Tests that when a LAYER_SOLID_COLOR has its CC layer switched, that | |
| 1610 // opaqueness and color set while not animating, are maintained. | |
| 1611 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerSolidColorNotAnimating) { | |
| 1612 SkColor transparent = SK_ColorTRANSPARENT; | |
| 1613 scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); | |
| 1614 GetCompositor()->SetRootLayer(root.get()); | |
| 1615 root->SetFillsBoundsOpaquely(false); | |
| 1616 root->SetColor(transparent); | |
| 1617 | |
| 1618 ASSERT_FALSE(root->fills_bounds_opaquely()); | |
|
danakj
2015/05/19 21:56:25
EXPECT rather than ASSERT everywhere
jonross
2015/05/20 01:03:54
Done.
| |
| 1619 ASSERT_FALSE( | |
| 1620 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); | |
| 1621 ASSERT_EQ(transparent, root->background_color()); | |
| 1622 ASSERT_EQ(transparent, root->GetTargetColor()); | |
| 1623 | |
| 1624 // Changing the underlying layer should not affect targets. | |
| 1625 root->SwitchCCLayerForTest(); | |
| 1626 | |
| 1627 EXPECT_FALSE(root->fills_bounds_opaquely()); | |
| 1628 EXPECT_FALSE( | |
| 1629 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); | |
| 1630 EXPECT_EQ(transparent, root->background_color()); | |
| 1631 EXPECT_EQ(transparent, root->GetTargetColor()); | |
| 1632 } | |
| 1633 | |
| 1634 // Tests that when a LAYER_SOLID_COLOR has its CC layer switched during an | |
| 1635 // animation of its opaquness and color, that both the current values, and the | |
| 1636 // targets are maintained. | |
| 1637 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerSolidColorWhileAnimating) { | |
| 1638 SkColor transparent = SK_ColorTRANSPARENT; | |
| 1639 scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); | |
| 1640 GetCompositor()->SetRootLayer(root.get()); | |
| 1641 root->SetColor(SK_ColorBLACK); | |
| 1642 | |
| 1643 ASSERT_TRUE(root->fills_bounds_opaquely()); | |
| 1644 ASSERT_EQ(SK_ColorBLACK, root->GetTargetColor()); | |
| 1645 | |
| 1646 scoped_ptr<ui::ScopedAnimationDurationScaleMode> long_duration_animation( | |
| 1647 new ui::ScopedAnimationDurationScaleMode( | |
| 1648 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | |
| 1649 { | |
| 1650 ui::ScopedLayerAnimationSettings animation(root->GetAnimator()); | |
| 1651 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); | |
| 1652 root->SetFillsBoundsOpaquely(false); | |
| 1653 root->SetColor(transparent); | |
| 1654 } | |
| 1655 | |
| 1656 EXPECT_TRUE(root->fills_bounds_opaquely()); | |
| 1657 EXPECT_TRUE( | |
| 1658 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); | |
| 1659 EXPECT_EQ(SK_ColorBLACK, root->background_color()); | |
| 1660 EXPECT_EQ(transparent, root->GetTargetColor()); | |
| 1661 | |
| 1662 // Changing the underlying layer should not affect targets. | |
| 1663 root->SwitchCCLayerForTest(); | |
| 1664 | |
| 1665 EXPECT_TRUE(root->fills_bounds_opaquely()); | |
| 1666 EXPECT_TRUE( | |
| 1667 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); | |
| 1668 EXPECT_EQ(SK_ColorBLACK, root->background_color()); | |
| 1669 EXPECT_EQ(transparent, root->GetTargetColor()); | |
| 1670 | |
| 1671 // End all animations. | |
| 1672 root->GetAnimator()->StopAnimating(); | |
| 1673 EXPECT_FALSE(root->fills_bounds_opaquely()); | |
| 1674 EXPECT_FALSE( | |
| 1675 root->GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)); | |
| 1676 EXPECT_EQ(transparent, root->background_color()); | |
| 1677 EXPECT_EQ(transparent, root->GetTargetColor()); | |
| 1678 } | |
| 1679 | |
| 1607 // Tests that the animators in the layer tree is added to the | 1680 // Tests that the animators in the layer tree is added to the |
| 1608 // animator-collection when the root-layer is set to the compositor. | 1681 // animator-collection when the root-layer is set to the compositor. |
| 1609 TEST_F(LayerWithDelegateTest, RootLayerAnimatorsInCompositor) { | 1682 TEST_F(LayerWithDelegateTest, RootLayerAnimatorsInCompositor) { |
| 1610 scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); | 1683 scoped_ptr<Layer> root(CreateLayer(LAYER_SOLID_COLOR)); |
| 1611 scoped_ptr<Layer> child(CreateColorLayer(SK_ColorRED, gfx::Rect(10, 10))); | 1684 scoped_ptr<Layer> child(CreateColorLayer(SK_ColorRED, gfx::Rect(10, 10))); |
| 1612 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1685 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
| 1613 child->SetOpacity(0.5f); | 1686 child->SetOpacity(0.5f); |
| 1614 root->Add(child.get()); | 1687 root->Add(child.get()); |
| 1615 | 1688 |
| 1616 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1689 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1730 MakeFrameData(gfx::Size(10, 10)))); | 1803 MakeFrameData(gfx::Size(10, 10)))); |
| 1731 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); | 1804 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); |
| 1732 | 1805 |
| 1733 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 1806 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
| 1734 layer->OnDelegatedFrameDamage(damage_rect); | 1807 layer->OnDelegatedFrameDamage(damage_rect); |
| 1735 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 1808 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
| 1736 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 1809 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
| 1737 } | 1810 } |
| 1738 | 1811 |
| 1739 } // namespace ui | 1812 } // namespace ui |
| OLD | NEW |