| 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); | 766 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); |
| 767 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5)); | 767 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5)); |
| 768 WaitForDraw(); | 768 WaitForDraw(); |
| 769 | 769 |
| 770 // |d2| should not have received a paint notification since it has no texture. | 770 // |d2| should not have received a paint notification since it has no texture. |
| 771 EXPECT_FALSE(d2.painted()); | 771 EXPECT_FALSE(d2.painted()); |
| 772 // |d3| should have received a paint notification. | 772 // |d3| should have received a paint notification. |
| 773 EXPECT_TRUE(d3.painted()); | 773 EXPECT_TRUE(d3.painted()); |
| 774 } | 774 } |
| 775 | 775 |
| 776 TEST_F(LayerWithDelegateTest, Cloning) { |
| 777 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR)); |
| 778 |
| 779 gfx::Transform transform; |
| 780 transform.Scale(2, 1); |
| 781 transform.Translate(10, 5); |
| 782 |
| 783 layer->SetTransform(transform); |
| 784 layer->SetColor(SK_ColorRED); |
| 785 layer->SetLayerInverted(true); |
| 786 |
| 787 auto clone = layer->Clone(); |
| 788 |
| 789 // Cloning preserves layer state. |
| 790 EXPECT_EQ(transform, clone->GetTargetTransform()); |
| 791 EXPECT_EQ(SK_ColorRED, clone->background_color()); |
| 792 EXPECT_EQ(SK_ColorRED, clone->GetTargetColor()); |
| 793 EXPECT_TRUE(clone->layer_inverted()); |
| 794 |
| 795 layer->SetTransform(gfx::Transform()); |
| 796 layer->SetColor(SK_ColorGREEN); |
| 797 layer->SetLayerInverted(false); |
| 798 |
| 799 // The clone is an independent copy, so state changes do not propagate. |
| 800 EXPECT_EQ(transform, clone->GetTargetTransform()); |
| 801 EXPECT_EQ(SK_ColorRED, clone->background_color()); |
| 802 EXPECT_EQ(SK_ColorRED, clone->GetTargetColor()); |
| 803 EXPECT_TRUE(clone->layer_inverted()); |
| 804 |
| 805 constexpr SkColor kTransparent = SK_ColorTRANSPARENT; |
| 806 layer->SetColor(kTransparent); |
| 807 layer->SetFillsBoundsOpaquely(false); |
| 808 // Color and opaqueness targets should be preserved during cloning, even after |
| 809 // switching away from solid color content. |
| 810 layer->SwitchCCLayerForTest(); |
| 811 |
| 812 clone = layer->Clone(); |
| 813 |
| 814 // The clone is a copy of the latest state. |
| 815 EXPECT_TRUE(clone->GetTargetTransform().IsIdentity()); |
| 816 EXPECT_EQ(kTransparent, clone->background_color()); |
| 817 EXPECT_EQ(kTransparent, clone->GetTargetColor()); |
| 818 EXPECT_FALSE(clone->layer_inverted()); |
| 819 EXPECT_FALSE(clone->fills_bounds_opaquely()); |
| 820 |
| 821 layer.reset(CreateLayer(LAYER_SOLID_COLOR)); |
| 822 layer->SetVisible(true); |
| 823 layer->SetOpacity(1.0f); |
| 824 layer->SetColor(SK_ColorRED); |
| 825 |
| 826 ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
| 827 layer->SetVisible(false); |
| 828 layer->SetOpacity(0.0f); |
| 829 layer->SetColor(SK_ColorGREEN); |
| 830 |
| 831 EXPECT_TRUE(layer->visible()); |
| 832 EXPECT_EQ(1.0f, layer->opacity()); |
| 833 EXPECT_EQ(SK_ColorRED, layer->background_color()); |
| 834 |
| 835 clone = layer->Clone(); |
| 836 |
| 837 // Cloning copies animation targets. |
| 838 EXPECT_FALSE(clone->visible()); |
| 839 EXPECT_EQ(0.0f, clone->opacity()); |
| 840 EXPECT_EQ(SK_ColorGREEN, clone->background_color()); |
| 841 } |
| 842 |
| 843 TEST_F(LayerWithDelegateTest, Mirroring) { |
| 844 std::unique_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 100, 100))); |
| 845 std::unique_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); |
| 846 |
| 847 const gfx::Rect bounds(0, 0, 50, 50); |
| 848 child->SetBounds(bounds); |
| 849 child->SetVisible(true); |
| 850 |
| 851 DrawTreeLayerDelegate delegate(child->bounds()); |
| 852 child->set_delegate(&delegate); |
| 853 |
| 854 const auto mirror = child->Mirror(); |
| 855 |
| 856 // Bounds and visibility are preserved. |
| 857 EXPECT_EQ(bounds, mirror->bounds()); |
| 858 EXPECT_TRUE(mirror->visible()); |
| 859 |
| 860 root->Add(child.get()); |
| 861 root->Add(mirror.get()); |
| 862 |
| 863 DrawTree(root.get()); |
| 864 EXPECT_TRUE(delegate.painted()); |
| 865 delegate.Reset(); |
| 866 |
| 867 // Both layers should be clean. |
| 868 EXPECT_TRUE(child->damaged_region_for_testing().IsEmpty()); |
| 869 EXPECT_TRUE(mirror->damaged_region_for_testing().IsEmpty()); |
| 870 |
| 871 const gfx::Rect damaged_rect(10, 10, 20, 20); |
| 872 EXPECT_TRUE(child->SchedulePaint(damaged_rect)); |
| 873 EXPECT_EQ(damaged_rect, child->damaged_region_for_testing().bounds()); |
| 874 |
| 875 DrawTree(root.get()); |
| 876 EXPECT_TRUE(delegate.painted()); |
| 877 delegate.Reset(); |
| 878 |
| 879 // Damage should be propagated to the mirror. |
| 880 EXPECT_EQ(damaged_rect, mirror->damaged_region_for_testing().bounds()); |
| 881 EXPECT_TRUE(child->damaged_region_for_testing().IsEmpty()); |
| 882 |
| 883 DrawTree(root.get()); |
| 884 EXPECT_TRUE(delegate.painted()); |
| 885 |
| 886 // Mirror should be clean. |
| 887 EXPECT_TRUE(mirror->damaged_region_for_testing().IsEmpty()); |
| 888 |
| 889 // Bounds are not synchronized by default. |
| 890 const gfx::Rect new_bounds(10, 10, 10, 10); |
| 891 child->SetBounds(new_bounds); |
| 892 EXPECT_EQ(bounds, mirror->bounds()); |
| 893 child->SetBounds(bounds); |
| 894 |
| 895 // Bounds should be synchronized if requested. |
| 896 child->set_sync_bounds(true); |
| 897 child->SetBounds(new_bounds); |
| 898 EXPECT_EQ(new_bounds, mirror->bounds()); |
| 899 } |
| 900 |
| 776 class LayerWithNullDelegateTest : public LayerWithDelegateTest { | 901 class LayerWithNullDelegateTest : public LayerWithDelegateTest { |
| 777 public: | 902 public: |
| 778 LayerWithNullDelegateTest() {} | 903 LayerWithNullDelegateTest() {} |
| 779 ~LayerWithNullDelegateTest() override {} | 904 ~LayerWithNullDelegateTest() override {} |
| 780 | 905 |
| 781 void SetUp() override { | 906 void SetUp() override { |
| 782 LayerWithDelegateTest::SetUp(); | 907 LayerWithDelegateTest::SetUp(); |
| 783 default_layer_delegate_.reset(new NullLayerDelegate()); | 908 default_layer_delegate_.reset(new NullLayerDelegate()); |
| 784 } | 909 } |
| 785 | 910 |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 EXPECT_TRUE(child->cc_layer_for_testing()); | 1878 EXPECT_TRUE(child->cc_layer_for_testing()); |
| 1754 EXPECT_NE(before.get(), child->cc_layer_for_testing()); | 1879 EXPECT_NE(before.get(), child->cc_layer_for_testing()); |
| 1755 | 1880 |
| 1756 // Changing to painted content should change the underlying cc layer. | 1881 // Changing to painted content should change the underlying cc layer. |
| 1757 before = child->cc_layer_for_testing(); | 1882 before = child->cc_layer_for_testing(); |
| 1758 child->SetShowSolidColorContent(); | 1883 child->SetShowSolidColorContent(); |
| 1759 EXPECT_TRUE(child->cc_layer_for_testing()); | 1884 EXPECT_TRUE(child->cc_layer_for_testing()); |
| 1760 EXPECT_NE(before.get(), child->cc_layer_for_testing()); | 1885 EXPECT_NE(before.get(), child->cc_layer_for_testing()); |
| 1761 } | 1886 } |
| 1762 | 1887 |
| 1888 TEST_F(LayerWithDelegateTest, ExternalContentMirroring) { |
| 1889 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR)); |
| 1890 |
| 1891 const auto satisfy_callback = base::Bind(&FakeSatisfyCallback); |
| 1892 const auto require_callback = base::Bind(&FakeRequireCallback); |
| 1893 |
| 1894 cc::SurfaceId surface_id(cc::FrameSinkId(0, 1), cc::LocalFrameId(2, 3)); |
| 1895 layer->SetShowSurface(surface_id, satisfy_callback, require_callback, |
| 1896 gfx::Size(10, 10), 1.0f, gfx::Size(10, 10)); |
| 1897 |
| 1898 const auto mirror = layer->Mirror(); |
| 1899 auto* const cc_layer = mirror->cc_layer_for_testing(); |
| 1900 const auto* surface = static_cast<cc::SurfaceLayer*>(cc_layer); |
| 1901 |
| 1902 // Mirroring preserves surface state. |
| 1903 EXPECT_EQ(surface_id, surface->surface_id()); |
| 1904 EXPECT_TRUE(satisfy_callback.Equals(surface->satisfy_callback())); |
| 1905 EXPECT_TRUE(require_callback.Equals(surface->require_callback())); |
| 1906 EXPECT_EQ(gfx::Size(10, 10), surface->surface_size()); |
| 1907 EXPECT_EQ(1.0f, surface->surface_scale()); |
| 1908 |
| 1909 surface_id = cc::SurfaceId(cc::FrameSinkId(1, 2), cc::LocalFrameId(3, 4)); |
| 1910 layer->SetShowSurface(surface_id, satisfy_callback, require_callback, |
| 1911 gfx::Size(20, 20), 2.0f, gfx::Size(20, 20)); |
| 1912 |
| 1913 // A new cc::Layer should be created for the mirror. |
| 1914 EXPECT_NE(cc_layer, mirror->cc_layer_for_testing()); |
| 1915 surface = static_cast<cc::SurfaceLayer*>(mirror->cc_layer_for_testing()); |
| 1916 |
| 1917 // Surface updates propagate to the mirror. |
| 1918 EXPECT_EQ(surface_id, surface->surface_id()); |
| 1919 EXPECT_EQ(gfx::Size(20, 20), surface->surface_size()); |
| 1920 EXPECT_EQ(2.0f, surface->surface_scale()); |
| 1921 } |
| 1922 |
| 1763 // Verifies that layer filters still attached after changing implementation | 1923 // Verifies that layer filters still attached after changing implementation |
| 1764 // layer. | 1924 // layer. |
| 1765 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { | 1925 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { |
| 1766 std::unique_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED)); | 1926 std::unique_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED)); |
| 1767 layer->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1927 layer->SetBounds(gfx::Rect(0, 0, 10, 10)); |
| 1768 EXPECT_TRUE(layer->cc_layer_for_testing()); | 1928 EXPECT_TRUE(layer->cc_layer_for_testing()); |
| 1769 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size()); | 1929 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size()); |
| 1770 | 1930 |
| 1771 layer->SetLayerGrayscale(0.5f); | 1931 layer->SetLayerGrayscale(0.5f); |
| 1772 EXPECT_EQ(layer->layer_grayscale(), 0.5f); | 1932 EXPECT_EQ(layer->layer_grayscale(), 0.5f); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2118 root->SetOpacity(0.5f); | 2278 root->SetOpacity(0.5f); |
| 2119 WaitForSwap(); | 2279 WaitForSwap(); |
| 2120 EXPECT_EQ(1u, animation_observer.animation_step_count()); | 2280 EXPECT_EQ(1u, animation_observer.animation_step_count()); |
| 2121 | 2281 |
| 2122 EXPECT_FALSE(animation_observer.shutdown()); | 2282 EXPECT_FALSE(animation_observer.shutdown()); |
| 2123 ResetCompositor(); | 2283 ResetCompositor(); |
| 2124 EXPECT_TRUE(animation_observer.shutdown()); | 2284 EXPECT_TRUE(animation_observer.shutdown()); |
| 2125 } | 2285 } |
| 2126 | 2286 |
| 2127 } // namespace ui | 2287 } // namespace ui |
| OLD | NEW |