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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
25 #include "cc/animation/animation_player.h" | 25 #include "cc/animation/animation_player.h" |
26 #include "cc/layers/layer.h" | 26 #include "cc/layers/layer.h" |
27 #include "cc/output/copy_output_request.h" | 27 #include "cc/output/copy_output_request.h" |
28 #include "cc/output/copy_output_result.h" | 28 #include "cc/output/copy_output_result.h" |
| 29 #include "cc/surfaces/sequence_surface_reference_factory.h" |
29 #include "cc/surfaces/surface_id.h" | 30 #include "cc/surfaces/surface_id.h" |
30 #include "cc/surfaces/surface_sequence.h" | 31 #include "cc/surfaces/surface_sequence.h" |
31 #include "cc/test/pixel_test_utils.h" | 32 #include "cc/test/pixel_test_utils.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "third_party/khronos/GLES2/gl2.h" | 34 #include "third_party/khronos/GLES2/gl2.h" |
34 #include "ui/compositor/compositor_observer.h" | 35 #include "ui/compositor/compositor_observer.h" |
35 #include "ui/compositor/dip_util.h" | 36 #include "ui/compositor/dip_util.h" |
36 #include "ui/compositor/layer_animation_element.h" | 37 #include "ui/compositor/layer_animation_element.h" |
37 #include "ui/compositor/layer_animation_observer.h" | 38 #include "ui/compositor/layer_animation_observer.h" |
38 #include "ui/compositor/layer_animation_sequence.h" | 39 #include "ui/compositor/layer_animation_sequence.h" |
(...skipping 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 | 1808 |
1808 // Resize layer. | 1809 // Resize layer. |
1809 child->SetBounds(gfx::Rect(200, 200, 400, 400)); | 1810 child->SetBounds(gfx::Rect(200, 200, 400, 400)); |
1810 child->SetVisible(true); | 1811 child->SetVisible(true); |
1811 DrawTree(root.get()); | 1812 DrawTree(root.get()); |
1812 EXPECT_TRUE(delegate.painted()); | 1813 EXPECT_TRUE(delegate.painted()); |
1813 } | 1814 } |
1814 | 1815 |
1815 namespace { | 1816 namespace { |
1816 | 1817 |
1817 void FakeSatisfyCallback(const cc::SurfaceSequence&) {} | 1818 class TestSurfaceReferenceFactory : public cc::SequenceSurfaceReferenceFactory { |
| 1819 public: |
| 1820 TestSurfaceReferenceFactory() = default; |
1818 | 1821 |
1819 void FakeRequireCallback(const cc::SurfaceId&, const cc::SurfaceSequence&) {} | 1822 private: |
| 1823 ~TestSurfaceReferenceFactory() override = default; |
| 1824 |
| 1825 // cc::SequenceSurfaceReferenceFactory implementation: |
| 1826 void SatisfySequence(const cc::SurfaceSequence& seq) const override {} |
| 1827 void RequireSequence(const cc::SurfaceId& id, |
| 1828 const cc::SurfaceSequence& seq) const override {} |
| 1829 |
| 1830 DISALLOW_COPY_AND_ASSIGN(TestSurfaceReferenceFactory); |
| 1831 }; |
1820 | 1832 |
1821 } // namespace | 1833 } // namespace |
1822 | 1834 |
1823 TEST_F(LayerWithDelegateTest, ExternalContent) { | 1835 TEST_F(LayerWithDelegateTest, ExternalContent) { |
1824 std::unique_ptr<Layer> root( | 1836 std::unique_ptr<Layer> root( |
1825 CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1837 CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); |
1826 std::unique_ptr<Layer> child(CreateLayer(LAYER_SOLID_COLOR)); | 1838 std::unique_ptr<Layer> child(CreateLayer(LAYER_SOLID_COLOR)); |
1827 | 1839 |
1828 child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1840 child->SetBounds(gfx::Rect(0, 0, 10, 10)); |
1829 child->SetVisible(true); | 1841 child->SetVisible(true); |
1830 root->Add(child.get()); | 1842 root->Add(child.get()); |
1831 | 1843 |
1832 // The layer is already showing solid color content, so the cc layer won't | 1844 // The layer is already showing solid color content, so the cc layer won't |
1833 // change. | 1845 // change. |
1834 scoped_refptr<cc::Layer> before = child->cc_layer_for_testing(); | 1846 scoped_refptr<cc::Layer> before = child->cc_layer_for_testing(); |
1835 child->SetShowSolidColorContent(); | 1847 child->SetShowSolidColorContent(); |
1836 EXPECT_TRUE(child->cc_layer_for_testing()); | 1848 EXPECT_TRUE(child->cc_layer_for_testing()); |
1837 EXPECT_EQ(before.get(), child->cc_layer_for_testing()); | 1849 EXPECT_EQ(before.get(), child->cc_layer_for_testing()); |
1838 | 1850 |
1839 // Showing surface content changes the underlying cc layer. | 1851 // Showing surface content changes the underlying cc layer. |
1840 before = child->cc_layer_for_testing(); | 1852 before = child->cc_layer_for_testing(); |
1841 child->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), | 1853 child->SetShowSurface( |
1842 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), | 1854 cc::SurfaceInfo(cc::SurfaceId(), 1.0, gfx::Size(10, 10)), |
1843 1.0); | 1855 new TestSurfaceReferenceFactory()); |
1844 EXPECT_TRUE(child->cc_layer_for_testing()); | 1856 EXPECT_TRUE(child->cc_layer_for_testing()); |
1845 EXPECT_NE(before.get(), child->cc_layer_for_testing()); | 1857 EXPECT_NE(before.get(), child->cc_layer_for_testing()); |
1846 | 1858 |
1847 // Changing to painted content should change the underlying cc layer. | 1859 // Changing to painted content should change the underlying cc layer. |
1848 before = child->cc_layer_for_testing(); | 1860 before = child->cc_layer_for_testing(); |
1849 child->SetShowSolidColorContent(); | 1861 child->SetShowSolidColorContent(); |
1850 EXPECT_TRUE(child->cc_layer_for_testing()); | 1862 EXPECT_TRUE(child->cc_layer_for_testing()); |
1851 EXPECT_NE(before.get(), child->cc_layer_for_testing()); | 1863 EXPECT_NE(before.get(), child->cc_layer_for_testing()); |
1852 } | 1864 } |
1853 | 1865 |
1854 TEST_F(LayerWithDelegateTest, ExternalContentMirroring) { | 1866 TEST_F(LayerWithDelegateTest, ExternalContentMirroring) { |
1855 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR)); | 1867 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR)); |
1856 | 1868 |
1857 const auto satisfy_callback = base::Bind(&FakeSatisfyCallback); | |
1858 const auto require_callback = base::Bind(&FakeRequireCallback); | |
1859 | |
1860 cc::SurfaceId surface_id( | 1869 cc::SurfaceId surface_id( |
1861 cc::FrameSinkId(0, 1), | 1870 cc::FrameSinkId(0, 1), |
1862 cc::LocalFrameId(2, base::UnguessableToken::Create())); | 1871 cc::LocalFrameId(2, base::UnguessableToken::Create())); |
1863 layer->SetShowSurface(surface_id, satisfy_callback, require_callback, | 1872 cc::SurfaceInfo surface_info(surface_id, 1.0f, gfx::Size(10, 10)); |
1864 gfx::Size(10, 10), 1.0f); | 1873 layer->SetShowSurface(surface_info, new TestSurfaceReferenceFactory()); |
1865 | 1874 |
1866 const auto mirror = layer->Mirror(); | 1875 const auto mirror = layer->Mirror(); |
1867 auto* const cc_layer = mirror->cc_layer_for_testing(); | 1876 auto* const cc_layer = mirror->cc_layer_for_testing(); |
1868 const auto* surface = static_cast<cc::SurfaceLayer*>(cc_layer); | 1877 const auto* surface = static_cast<cc::SurfaceLayer*>(cc_layer); |
1869 | 1878 |
1870 // Mirroring preserves surface state. | 1879 // Mirroring preserves surface state. |
1871 EXPECT_EQ(surface_id, surface->surface_id()); | 1880 EXPECT_EQ(surface_info, surface->surface_info()); |
1872 EXPECT_TRUE(satisfy_callback.Equals(surface->satisfy_callback())); | |
1873 EXPECT_TRUE(require_callback.Equals(surface->require_callback())); | |
1874 EXPECT_EQ(gfx::Size(10, 10), surface->surface_size()); | |
1875 EXPECT_EQ(1.0f, surface->surface_scale()); | |
1876 | 1881 |
1877 surface_id = | 1882 surface_id = |
1878 cc::SurfaceId(cc::FrameSinkId(1, 2), | 1883 cc::SurfaceId(cc::FrameSinkId(1, 2), |
1879 cc::LocalFrameId(3, base::UnguessableToken::Create())); | 1884 cc::LocalFrameId(3, base::UnguessableToken::Create())); |
1880 layer->SetShowSurface(surface_id, satisfy_callback, require_callback, | 1885 cc::SurfaceInfo surface_info_2(surface_id, 2.0f, gfx::Size(20, 20)); |
1881 gfx::Size(20, 20), 2.0f); | 1886 layer->SetShowSurface(surface_info_2, new TestSurfaceReferenceFactory()); |
1882 | 1887 |
1883 // A new cc::Layer should be created for the mirror. | 1888 // A new cc::Layer should be created for the mirror. |
1884 EXPECT_NE(cc_layer, mirror->cc_layer_for_testing()); | 1889 EXPECT_NE(cc_layer, mirror->cc_layer_for_testing()); |
1885 surface = static_cast<cc::SurfaceLayer*>(mirror->cc_layer_for_testing()); | 1890 surface = static_cast<cc::SurfaceLayer*>(mirror->cc_layer_for_testing()); |
1886 | 1891 |
1887 // Surface updates propagate to the mirror. | 1892 // Surface updates propagate to the mirror. |
1888 EXPECT_EQ(surface_id, surface->surface_id()); | 1893 EXPECT_EQ(surface_info_2, surface->surface_info()); |
1889 EXPECT_EQ(gfx::Size(20, 20), surface->surface_size()); | |
1890 EXPECT_EQ(2.0f, surface->surface_scale()); | |
1891 } | 1894 } |
1892 | 1895 |
1893 // Test if frame size in dip is properly calculated in SetShowSurface | 1896 // Test if frame size in dip is properly calculated in SetShowSurface |
1894 TEST_F(LayerWithDelegateTest, FrameSizeInDip) { | 1897 TEST_F(LayerWithDelegateTest, FrameSizeInDip) { |
1895 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR)); | 1898 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR)); |
1896 | 1899 |
1897 const auto satisfy_callback = base::Bind(&FakeSatisfyCallback); | |
1898 const auto require_callback = base::Bind(&FakeRequireCallback); | |
1899 | |
1900 cc::SurfaceId surface_id( | 1900 cc::SurfaceId surface_id( |
1901 cc::FrameSinkId(0, 1), | 1901 cc::FrameSinkId(0, 1), |
1902 cc::LocalFrameId(2, base::UnguessableToken::Create())); | 1902 cc::LocalFrameId(2, base::UnguessableToken::Create())); |
1903 | 1903 |
1904 layer->SetShowSurface(surface_id, satisfy_callback, require_callback, | 1904 layer->SetShowSurface(cc::SurfaceInfo(surface_id, 2.0f, gfx::Size(30, 40)), |
1905 gfx::Size(30, 40), 2.0f); | 1905 new TestSurfaceReferenceFactory()); |
1906 | 1906 |
1907 EXPECT_EQ(layer->frame_size_in_dip_for_testing(), gfx::Size(15, 20)); | 1907 EXPECT_EQ(layer->frame_size_in_dip_for_testing(), gfx::Size(15, 20)); |
1908 } | 1908 } |
1909 | 1909 |
1910 // Verifies that layer filters still attached after changing implementation | 1910 // Verifies that layer filters still attached after changing implementation |
1911 // layer. | 1911 // layer. |
1912 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { | 1912 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { |
1913 std::unique_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED)); | 1913 std::unique_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED)); |
1914 layer->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1914 layer->SetBounds(gfx::Rect(0, 0, 10, 10)); |
1915 EXPECT_TRUE(layer->cc_layer_for_testing()); | 1915 EXPECT_TRUE(layer->cc_layer_for_testing()); |
1916 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size()); | 1916 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size()); |
1917 | 1917 |
1918 layer->SetLayerGrayscale(0.5f); | 1918 layer->SetLayerGrayscale(0.5f); |
1919 EXPECT_EQ(layer->layer_grayscale(), 0.5f); | 1919 EXPECT_EQ(layer->layer_grayscale(), 0.5f); |
1920 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); | 1920 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); |
1921 | 1921 |
1922 // Showing surface content changes the underlying cc layer. | 1922 // Showing surface content changes the underlying cc layer. |
1923 scoped_refptr<cc::Layer> before = layer->cc_layer_for_testing(); | 1923 scoped_refptr<cc::Layer> before = layer->cc_layer_for_testing(); |
1924 layer->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), | 1924 layer->SetShowSurface( |
1925 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), | 1925 cc::SurfaceInfo(cc::SurfaceId(), 1.0, gfx::Size(10, 10)), |
1926 1.0); | 1926 new TestSurfaceReferenceFactory()); |
1927 EXPECT_EQ(layer->layer_grayscale(), 0.5f); | 1927 EXPECT_EQ(layer->layer_grayscale(), 0.5f); |
1928 EXPECT_TRUE(layer->cc_layer_for_testing()); | 1928 EXPECT_TRUE(layer->cc_layer_for_testing()); |
1929 EXPECT_NE(before.get(), layer->cc_layer_for_testing()); | 1929 EXPECT_NE(before.get(), layer->cc_layer_for_testing()); |
1930 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); | 1930 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); |
1931 } | 1931 } |
1932 | 1932 |
1933 // Tests Layer::AddThreadedAnimation and Layer::RemoveThreadedAnimation. | 1933 // Tests Layer::AddThreadedAnimation and Layer::RemoveThreadedAnimation. |
1934 TEST_F(LayerWithRealCompositorTest, AddRemoveThreadedAnimations) { | 1934 TEST_F(LayerWithRealCompositorTest, AddRemoveThreadedAnimations) { |
1935 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1935 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1936 std::unique_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); | 1936 std::unique_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2237 | 2237 |
2238 DISALLOW_COPY_AND_ASSIGN(FrameDamageCheckingDelegate); | 2238 DISALLOW_COPY_AND_ASSIGN(FrameDamageCheckingDelegate); |
2239 }; | 2239 }; |
2240 | 2240 |
2241 TEST(LayerDelegateTest, DelegatedFrameDamage) { | 2241 TEST(LayerDelegateTest, DelegatedFrameDamage) { |
2242 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); | 2242 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); |
2243 gfx::Rect damage_rect(2, 1, 5, 3); | 2243 gfx::Rect damage_rect(2, 1, 5, 3); |
2244 | 2244 |
2245 FrameDamageCheckingDelegate delegate; | 2245 FrameDamageCheckingDelegate delegate; |
2246 layer->set_delegate(&delegate); | 2246 layer->set_delegate(&delegate); |
2247 layer->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), | 2247 layer->SetShowSurface( |
2248 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), | 2248 cc::SurfaceInfo(cc::SurfaceId(), 1.0, gfx::Size(10, 10)), |
2249 1.0); | 2249 new TestSurfaceReferenceFactory()); |
2250 | 2250 |
2251 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 2251 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
2252 layer->OnDelegatedFrameDamage(damage_rect); | 2252 layer->OnDelegatedFrameDamage(damage_rect); |
2253 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 2253 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
2254 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 2254 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
2255 } | 2255 } |
2256 | 2256 |
2257 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { | 2257 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { |
2258 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 2258 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
2259 | 2259 |
(...skipping 16 matching lines...) Expand all Loading... |
2276 layer.set_name("foo"); | 2276 layer.set_name("foo"); |
2277 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = | 2277 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = |
2278 layer.TakeDebugInfo(nullptr); | 2278 layer.TakeDebugInfo(nullptr); |
2279 std::string trace_format("bar,"); | 2279 std::string trace_format("bar,"); |
2280 debug_info->AppendAsTraceFormat(&trace_format); | 2280 debug_info->AppendAsTraceFormat(&trace_format); |
2281 std::string expected("bar,{\"layer_name\":\"foo\"}"); | 2281 std::string expected("bar,{\"layer_name\":\"foo\"}"); |
2282 EXPECT_EQ(expected, trace_format); | 2282 EXPECT_EQ(expected, trace_format); |
2283 } | 2283 } |
2284 | 2284 |
2285 } // namespace ui | 2285 } // namespace ui |
OLD | NEW |