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

Side by Side Diff: ui/compositor/layer_unittest.cc

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Rebase Created 4 years, 1 month 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
« no previous file with comments | « ui/compositor/layer_tree_owner.cc ('k') | ui/views/cocoa/bridged_native_widget.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 740 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
741 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 741 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5));
742 WaitForDraw(); 742 WaitForDraw();
743 743
744 // |d2| should not have received a paint notification since it has no texture. 744 // |d2| should not have received a paint notification since it has no texture.
745 EXPECT_FALSE(d2.painted()); 745 EXPECT_FALSE(d2.painted());
746 // |d3| should have received a paint notification. 746 // |d3| should have received a paint notification.
747 EXPECT_TRUE(d3.painted()); 747 EXPECT_TRUE(d3.painted());
748 } 748 }
749 749
750 TEST_F(LayerWithDelegateTest, Cloning) {
751 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR));
752
753 gfx::Transform transform;
754 transform.Scale(2, 1);
755 transform.Translate(10, 5);
756
757 layer->SetTransform(transform);
758 layer->SetColor(SK_ColorRED);
759 layer->SetLayerInverted(true);
760
761 auto clone = layer->Clone();
762
763 // Cloning preserves layer state.
764 EXPECT_EQ(transform, clone->GetTargetTransform());
765 EXPECT_EQ(SK_ColorRED, clone->background_color());
766 EXPECT_EQ(SK_ColorRED, clone->GetTargetColor());
767 EXPECT_TRUE(clone->layer_inverted());
768
769 layer->SetTransform(gfx::Transform());
770 layer->SetColor(SK_ColorGREEN);
771 layer->SetLayerInverted(false);
772
773 // The clone is an independent copy, so state changes do not propagate.
774 EXPECT_EQ(transform, clone->GetTargetTransform());
775 EXPECT_EQ(SK_ColorRED, clone->background_color());
776 EXPECT_EQ(SK_ColorRED, clone->GetTargetColor());
777 EXPECT_TRUE(clone->layer_inverted());
778
779 constexpr SkColor kTransparent = SK_ColorTRANSPARENT;
780 layer->SetColor(kTransparent);
781 layer->SetFillsBoundsOpaquely(false);
782 // Color and opaqueness targets should be preserved during cloning, even after
783 // switching away from solid color content.
784 layer->SwitchCCLayerForTest();
785
786 clone = layer->Clone();
787
788 // The clone is a copy of the latest state.
789 EXPECT_TRUE(clone->GetTargetTransform().IsIdentity());
790 EXPECT_EQ(kTransparent, clone->background_color());
791 EXPECT_EQ(kTransparent, clone->GetTargetColor());
792 EXPECT_FALSE(clone->layer_inverted());
793 EXPECT_FALSE(clone->fills_bounds_opaquely());
794
795 layer.reset(CreateLayer(LAYER_SOLID_COLOR));
796 layer->SetVisible(true);
797 layer->SetOpacity(1.0f);
798 layer->SetColor(SK_ColorRED);
799
800 ScopedLayerAnimationSettings settings(layer->GetAnimator());
801 layer->SetVisible(false);
802 layer->SetOpacity(0.0f);
803 layer->SetColor(SK_ColorGREEN);
804
805 EXPECT_TRUE(layer->visible());
806 EXPECT_EQ(1.0f, layer->opacity());
807 EXPECT_EQ(SK_ColorRED, layer->background_color());
808
809 clone = layer->Clone();
810
811 // Cloning copies animation targets.
812 EXPECT_FALSE(clone->visible());
813 EXPECT_EQ(0.0f, clone->opacity());
814 EXPECT_EQ(SK_ColorGREEN, clone->background_color());
815 }
816
817 TEST_F(LayerWithDelegateTest, Mirroring) {
818 std::unique_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 100, 100)));
819 std::unique_ptr<Layer> child(CreateLayer(LAYER_TEXTURED));
820
821 const gfx::Rect bounds(0, 0, 50, 50);
822 child->SetBounds(bounds);
823 child->SetVisible(true);
824
825 DrawTreeLayerDelegate delegate(child->bounds());
826 child->set_delegate(&delegate);
827
828 const auto mirror = child->Mirror();
829
830 // Bounds and visibility are preserved.
831 EXPECT_EQ(bounds, mirror->bounds());
832 EXPECT_TRUE(mirror->visible());
833
834 root->Add(child.get());
835 root->Add(mirror.get());
836
837 DrawTree(root.get());
838 EXPECT_TRUE(delegate.painted());
839 delegate.Reset();
840
841 // Both layers should be clean.
842 EXPECT_TRUE(child->damaged_region_for_testing().IsEmpty());
843 EXPECT_TRUE(mirror->damaged_region_for_testing().IsEmpty());
844
845 const gfx::Rect damaged_rect(10, 10, 20, 20);
846 EXPECT_TRUE(child->SchedulePaint(damaged_rect));
847 EXPECT_EQ(damaged_rect, child->damaged_region_for_testing().bounds());
848
849 DrawTree(root.get());
850 EXPECT_TRUE(delegate.painted());
851 delegate.Reset();
852
853 // Damage should be propagated to the mirror.
854 EXPECT_EQ(damaged_rect, mirror->damaged_region_for_testing().bounds());
855 EXPECT_TRUE(child->damaged_region_for_testing().IsEmpty());
856
857 DrawTree(root.get());
858 EXPECT_TRUE(delegate.painted());
859
860 // Mirror should be clean.
861 EXPECT_TRUE(mirror->damaged_region_for_testing().IsEmpty());
862
863 // Bounds are not synchronized by default.
864 const gfx::Rect new_bounds(10, 10, 10, 10);
865 child->SetBounds(new_bounds);
866 EXPECT_EQ(bounds, mirror->bounds());
867 child->SetBounds(bounds);
868
869 // Bounds should be synchronized if requested.
870 child->set_sync_bounds(true);
871 child->SetBounds(new_bounds);
872 EXPECT_EQ(new_bounds, mirror->bounds());
873 }
874
750 class LayerWithNullDelegateTest : public LayerWithDelegateTest { 875 class LayerWithNullDelegateTest : public LayerWithDelegateTest {
751 public: 876 public:
752 LayerWithNullDelegateTest() {} 877 LayerWithNullDelegateTest() {}
753 ~LayerWithNullDelegateTest() override {} 878 ~LayerWithNullDelegateTest() override {}
754 879
755 void SetUp() override { 880 void SetUp() override {
756 LayerWithDelegateTest::SetUp(); 881 LayerWithDelegateTest::SetUp();
757 default_layer_delegate_.reset(new NullLayerDelegate()); 882 default_layer_delegate_.reset(new NullLayerDelegate());
758 } 883 }
759 884
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 EXPECT_TRUE(child->cc_layer_for_testing()); 1839 EXPECT_TRUE(child->cc_layer_for_testing());
1715 EXPECT_NE(before.get(), child->cc_layer_for_testing()); 1840 EXPECT_NE(before.get(), child->cc_layer_for_testing());
1716 1841
1717 // Changing to painted content should change the underlying cc layer. 1842 // Changing to painted content should change the underlying cc layer.
1718 before = child->cc_layer_for_testing(); 1843 before = child->cc_layer_for_testing();
1719 child->SetShowSolidColorContent(); 1844 child->SetShowSolidColorContent();
1720 EXPECT_TRUE(child->cc_layer_for_testing()); 1845 EXPECT_TRUE(child->cc_layer_for_testing());
1721 EXPECT_NE(before.get(), child->cc_layer_for_testing()); 1846 EXPECT_NE(before.get(), child->cc_layer_for_testing());
1722 } 1847 }
1723 1848
1849 TEST_F(LayerWithDelegateTest, ExternalContentMirroring) {
1850 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR));
1851
1852 const auto satisfy_callback = base::Bind(&FakeSatisfyCallback);
1853 const auto require_callback = base::Bind(&FakeRequireCallback);
1854
1855 cc::SurfaceId surface_id(cc::FrameSinkId(0, 1), cc::LocalFrameId(2, 3));
1856 layer->SetShowSurface(surface_id, satisfy_callback, require_callback,
1857 gfx::Size(10, 10), 1.0f, gfx::Size(10, 10));
1858
1859 const auto mirror = layer->Mirror();
1860 auto* const cc_layer = mirror->cc_layer_for_testing();
1861 const auto* surface = static_cast<cc::SurfaceLayer*>(cc_layer);
1862
1863 // Mirroring preserves surface state.
1864 EXPECT_EQ(surface_id, surface->surface_id());
1865 EXPECT_TRUE(satisfy_callback.Equals(surface->satisfy_callback()));
1866 EXPECT_TRUE(require_callback.Equals(surface->require_callback()));
1867 EXPECT_EQ(gfx::Size(10, 10), surface->surface_size());
1868 EXPECT_EQ(1.0f, surface->surface_scale());
1869
1870 surface_id = cc::SurfaceId(cc::FrameSinkId(1, 2), cc::LocalFrameId(3, 4));
1871 layer->SetShowSurface(surface_id, satisfy_callback, require_callback,
1872 gfx::Size(20, 20), 2.0f, gfx::Size(20, 20));
1873
1874 // A new cc::Layer should be created for the mirror.
1875 EXPECT_NE(cc_layer, mirror->cc_layer_for_testing());
1876 surface = static_cast<cc::SurfaceLayer*>(mirror->cc_layer_for_testing());
1877
1878 // Surface updates propagate to the mirror.
1879 EXPECT_EQ(surface_id, surface->surface_id());
1880 EXPECT_EQ(gfx::Size(20, 20), surface->surface_size());
1881 EXPECT_EQ(2.0f, surface->surface_scale());
1882 }
1883
1724 // Verifies that layer filters still attached after changing implementation 1884 // Verifies that layer filters still attached after changing implementation
1725 // layer. 1885 // layer.
1726 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { 1886 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) {
1727 std::unique_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED)); 1887 std::unique_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED));
1728 layer->SetBounds(gfx::Rect(0, 0, 10, 10)); 1888 layer->SetBounds(gfx::Rect(0, 0, 10, 10));
1729 EXPECT_TRUE(layer->cc_layer_for_testing()); 1889 EXPECT_TRUE(layer->cc_layer_for_testing());
1730 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size()); 1890 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size());
1731 1891
1732 layer->SetLayerGrayscale(0.5f); 1892 layer->SetLayerGrayscale(0.5f);
1733 EXPECT_EQ(layer->layer_grayscale(), 0.5f); 1893 EXPECT_EQ(layer->layer_grayscale(), 0.5f);
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 root->SetOpacity(0.5f); 2239 root->SetOpacity(0.5f);
2080 WaitForSwap(); 2240 WaitForSwap();
2081 EXPECT_EQ(1u, animation_observer.animation_step_count()); 2241 EXPECT_EQ(1u, animation_observer.animation_step_count());
2082 2242
2083 EXPECT_FALSE(animation_observer.shutdown()); 2243 EXPECT_FALSE(animation_observer.shutdown());
2084 ResetCompositor(); 2244 ResetCompositor();
2085 EXPECT_TRUE(animation_observer.shutdown()); 2245 EXPECT_TRUE(animation_observer.shutdown());
2086 } 2246 }
2087 2247
2088 } // namespace ui 2248 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_tree_owner.cc ('k') | ui/views/cocoa/bridged_native_widget.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698