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/surface_embedding.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 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 | 1803 |
1803 // Resize layer. | 1804 // Resize layer. |
1804 child->SetBounds(gfx::Rect(200, 200, 400, 400)); | 1805 child->SetBounds(gfx::Rect(200, 200, 400, 400)); |
1805 child->SetVisible(true); | 1806 child->SetVisible(true); |
1806 DrawTree(root.get()); | 1807 DrawTree(root.get()); |
1807 EXPECT_TRUE(delegate.painted()); | 1808 EXPECT_TRUE(delegate.painted()); |
1808 } | 1809 } |
1809 | 1810 |
1810 namespace { | 1811 namespace { |
1811 | 1812 |
1812 void FakeSatisfyCallback(const cc::SurfaceSequence&) {} | 1813 class SurfaceEmbedding : public cc::SurfaceEmbeddingUsingSequence { |
| 1814 protected: |
| 1815 ~SurfaceEmbedding() override = default; |
1813 | 1816 |
1814 void FakeRequireCallback(const cc::SurfaceId&, const cc::SurfaceSequence&) {} | 1817 private: |
1815 | 1818 void SatisfySequence(const cc::SurfaceSequence& seq) const override {} |
| 1819 void RequireSequence(const cc::SurfaceId& id, |
| 1820 const cc::SurfaceSequence& seq) const override {} |
| 1821 }; |
1816 } // namespace | 1822 } // namespace |
1817 | 1823 |
1818 TEST_F(LayerWithDelegateTest, ExternalContent) { | 1824 TEST_F(LayerWithDelegateTest, ExternalContent) { |
1819 std::unique_ptr<Layer> root( | 1825 std::unique_ptr<Layer> root( |
1820 CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); | 1826 CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); |
1821 std::unique_ptr<Layer> child(CreateLayer(LAYER_SOLID_COLOR)); | 1827 std::unique_ptr<Layer> child(CreateLayer(LAYER_SOLID_COLOR)); |
1822 | 1828 |
1823 child->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1829 child->SetBounds(gfx::Rect(0, 0, 10, 10)); |
1824 child->SetVisible(true); | 1830 child->SetVisible(true); |
1825 root->Add(child.get()); | 1831 root->Add(child.get()); |
1826 | 1832 |
1827 // The layer is already showing solid color content, so the cc layer won't | 1833 // The layer is already showing solid color content, so the cc layer won't |
1828 // change. | 1834 // change. |
1829 scoped_refptr<cc::Layer> before = child->cc_layer_for_testing(); | 1835 scoped_refptr<cc::Layer> before = child->cc_layer_for_testing(); |
1830 child->SetShowSolidColorContent(); | 1836 child->SetShowSolidColorContent(); |
1831 EXPECT_TRUE(child->cc_layer_for_testing()); | 1837 EXPECT_TRUE(child->cc_layer_for_testing()); |
1832 EXPECT_EQ(before.get(), child->cc_layer_for_testing()); | 1838 EXPECT_EQ(before.get(), child->cc_layer_for_testing()); |
1833 | 1839 |
1834 // Showing surface content changes the underlying cc layer. | 1840 // Showing surface content changes the underlying cc layer. |
1835 before = child->cc_layer_for_testing(); | 1841 before = child->cc_layer_for_testing(); |
1836 child->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), | 1842 child->SetShowSurface( |
1837 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), | 1843 cc::SurfaceInfo(cc::SurfaceId(), 1.0, gfx::Size(10, 10)), |
1838 1.0, gfx::Size(10, 10)); | 1844 new SurfaceEmbedding(), gfx::Size(10, 10)); |
1839 EXPECT_TRUE(child->cc_layer_for_testing()); | 1845 EXPECT_TRUE(child->cc_layer_for_testing()); |
1840 EXPECT_NE(before.get(), child->cc_layer_for_testing()); | 1846 EXPECT_NE(before.get(), child->cc_layer_for_testing()); |
1841 | 1847 |
1842 // Changing to painted content should change the underlying cc layer. | 1848 // Changing to painted content should change the underlying cc layer. |
1843 before = child->cc_layer_for_testing(); | 1849 before = child->cc_layer_for_testing(); |
1844 child->SetShowSolidColorContent(); | 1850 child->SetShowSolidColorContent(); |
1845 EXPECT_TRUE(child->cc_layer_for_testing()); | 1851 EXPECT_TRUE(child->cc_layer_for_testing()); |
1846 EXPECT_NE(before.get(), child->cc_layer_for_testing()); | 1852 EXPECT_NE(before.get(), child->cc_layer_for_testing()); |
1847 } | 1853 } |
1848 | 1854 |
1849 TEST_F(LayerWithDelegateTest, ExternalContentMirroring) { | 1855 TEST_F(LayerWithDelegateTest, ExternalContentMirroring) { |
1850 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR)); | 1856 std::unique_ptr<Layer> layer(CreateLayer(LAYER_SOLID_COLOR)); |
1851 | 1857 |
1852 const auto satisfy_callback = base::Bind(&FakeSatisfyCallback); | |
1853 const auto require_callback = base::Bind(&FakeRequireCallback); | |
1854 | |
1855 cc::SurfaceId surface_id( | 1858 cc::SurfaceId surface_id( |
1856 cc::FrameSinkId(0, 1), | 1859 cc::FrameSinkId(0, 1), |
1857 cc::LocalFrameId(2, base::UnguessableToken::Create())); | 1860 cc::LocalFrameId(2, base::UnguessableToken::Create())); |
1858 layer->SetShowSurface(surface_id, satisfy_callback, require_callback, | 1861 cc::SurfaceInfo surface_info(surface_id, 1.0f, gfx::Size(10, 10)); |
1859 gfx::Size(10, 10), 1.0f, gfx::Size(10, 10)); | 1862 layer->SetShowSurface(surface_info, new SurfaceEmbedding(), |
| 1863 gfx::Size(10, 10)); |
1860 | 1864 |
1861 const auto mirror = layer->Mirror(); | 1865 const auto mirror = layer->Mirror(); |
1862 auto* const cc_layer = mirror->cc_layer_for_testing(); | 1866 auto* const cc_layer = mirror->cc_layer_for_testing(); |
1863 const auto* surface = static_cast<cc::SurfaceLayer*>(cc_layer); | 1867 const auto* surface = static_cast<cc::SurfaceLayer*>(cc_layer); |
1864 | 1868 |
1865 // Mirroring preserves surface state. | 1869 // Mirroring preserves surface state. |
1866 EXPECT_EQ(surface_id, surface->surface_id()); | 1870 EXPECT_EQ(surface_info, surface->surface_info()); |
1867 EXPECT_TRUE(satisfy_callback.Equals(surface->satisfy_callback())); | |
1868 EXPECT_TRUE(require_callback.Equals(surface->require_callback())); | |
1869 EXPECT_EQ(gfx::Size(10, 10), surface->surface_size()); | |
1870 EXPECT_EQ(1.0f, surface->surface_scale()); | |
1871 | 1871 |
1872 surface_id = | 1872 surface_id = |
1873 cc::SurfaceId(cc::FrameSinkId(1, 2), | 1873 cc::SurfaceId(cc::FrameSinkId(1, 2), |
1874 cc::LocalFrameId(3, base::UnguessableToken::Create())); | 1874 cc::LocalFrameId(3, base::UnguessableToken::Create())); |
1875 layer->SetShowSurface(surface_id, satisfy_callback, require_callback, | 1875 cc::SurfaceInfo surface_info_2(surface_id, 2.0f, gfx::Size(20, 20)); |
1876 gfx::Size(20, 20), 2.0f, gfx::Size(20, 20)); | 1876 layer->SetShowSurface(surface_info_2, new SurfaceEmbedding(), |
| 1877 gfx::Size(20, 20)); |
1877 | 1878 |
1878 // A new cc::Layer should be created for the mirror. | 1879 // A new cc::Layer should be created for the mirror. |
1879 EXPECT_NE(cc_layer, mirror->cc_layer_for_testing()); | 1880 EXPECT_NE(cc_layer, mirror->cc_layer_for_testing()); |
1880 surface = static_cast<cc::SurfaceLayer*>(mirror->cc_layer_for_testing()); | 1881 surface = static_cast<cc::SurfaceLayer*>(mirror->cc_layer_for_testing()); |
1881 | 1882 |
1882 // Surface updates propagate to the mirror. | 1883 // Surface updates propagate to the mirror. |
1883 EXPECT_EQ(surface_id, surface->surface_id()); | 1884 EXPECT_EQ(surface_info_2, surface->surface_info()); |
1884 EXPECT_EQ(gfx::Size(20, 20), surface->surface_size()); | |
1885 EXPECT_EQ(2.0f, surface->surface_scale()); | |
1886 } | 1885 } |
1887 | 1886 |
1888 // Verifies that layer filters still attached after changing implementation | 1887 // Verifies that layer filters still attached after changing implementation |
1889 // layer. | 1888 // layer. |
1890 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { | 1889 TEST_F(LayerWithDelegateTest, LayerFiltersSurvival) { |
1891 std::unique_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED)); | 1890 std::unique_ptr<Layer> layer(CreateLayer(LAYER_TEXTURED)); |
1892 layer->SetBounds(gfx::Rect(0, 0, 10, 10)); | 1891 layer->SetBounds(gfx::Rect(0, 0, 10, 10)); |
1893 EXPECT_TRUE(layer->cc_layer_for_testing()); | 1892 EXPECT_TRUE(layer->cc_layer_for_testing()); |
1894 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size()); | 1893 EXPECT_EQ(0u, layer->cc_layer_for_testing()->filters().size()); |
1895 | 1894 |
1896 layer->SetLayerGrayscale(0.5f); | 1895 layer->SetLayerGrayscale(0.5f); |
1897 EXPECT_EQ(layer->layer_grayscale(), 0.5f); | 1896 EXPECT_EQ(layer->layer_grayscale(), 0.5f); |
1898 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); | 1897 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); |
1899 | 1898 |
1900 // Showing surface content changes the underlying cc layer. | 1899 // Showing surface content changes the underlying cc layer. |
1901 scoped_refptr<cc::Layer> before = layer->cc_layer_for_testing(); | 1900 scoped_refptr<cc::Layer> before = layer->cc_layer_for_testing(); |
1902 layer->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), | 1901 layer->SetShowSurface( |
1903 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), | 1902 cc::SurfaceInfo(cc::SurfaceId(), 1.0, gfx::Size(10, 10)), |
1904 1.0, gfx::Size(10, 10)); | 1903 new SurfaceEmbedding(), gfx::Size(10, 10)); |
1905 EXPECT_EQ(layer->layer_grayscale(), 0.5f); | 1904 EXPECT_EQ(layer->layer_grayscale(), 0.5f); |
1906 EXPECT_TRUE(layer->cc_layer_for_testing()); | 1905 EXPECT_TRUE(layer->cc_layer_for_testing()); |
1907 EXPECT_NE(before.get(), layer->cc_layer_for_testing()); | 1906 EXPECT_NE(before.get(), layer->cc_layer_for_testing()); |
1908 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); | 1907 EXPECT_EQ(1u, layer->cc_layer_for_testing()->filters().size()); |
1909 } | 1908 } |
1910 | 1909 |
1911 // Tests Layer::AddThreadedAnimation and Layer::RemoveThreadedAnimation. | 1910 // Tests Layer::AddThreadedAnimation and Layer::RemoveThreadedAnimation. |
1912 TEST_F(LayerWithRealCompositorTest, AddRemoveThreadedAnimations) { | 1911 TEST_F(LayerWithRealCompositorTest, AddRemoveThreadedAnimations) { |
1913 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1912 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1914 std::unique_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); | 1913 std::unique_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 | 2214 |
2216 DISALLOW_COPY_AND_ASSIGN(FrameDamageCheckingDelegate); | 2215 DISALLOW_COPY_AND_ASSIGN(FrameDamageCheckingDelegate); |
2217 }; | 2216 }; |
2218 | 2217 |
2219 TEST(LayerDelegateTest, DelegatedFrameDamage) { | 2218 TEST(LayerDelegateTest, DelegatedFrameDamage) { |
2220 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); | 2219 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); |
2221 gfx::Rect damage_rect(2, 1, 5, 3); | 2220 gfx::Rect damage_rect(2, 1, 5, 3); |
2222 | 2221 |
2223 FrameDamageCheckingDelegate delegate; | 2222 FrameDamageCheckingDelegate delegate; |
2224 layer->set_delegate(&delegate); | 2223 layer->set_delegate(&delegate); |
2225 layer->SetShowSurface(cc::SurfaceId(), base::Bind(&FakeSatisfyCallback), | 2224 layer->SetShowSurface( |
2226 base::Bind(&FakeRequireCallback), gfx::Size(10, 10), | 2225 cc::SurfaceInfo(cc::SurfaceId(), 1.0, gfx::Size(10, 10)), |
2227 1.0, gfx::Size(10, 10)); | 2226 new SurfaceEmbedding(), gfx::Size(10, 10)); |
2228 | 2227 |
2229 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 2228 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
2230 layer->OnDelegatedFrameDamage(damage_rect); | 2229 layer->OnDelegatedFrameDamage(damage_rect); |
2231 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 2230 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
2232 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 2231 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
2233 } | 2232 } |
2234 | 2233 |
2235 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { | 2234 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { |
2236 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 2235 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
2237 | 2236 |
(...skipping 16 matching lines...) Expand all Loading... |
2254 layer.set_name("foo"); | 2253 layer.set_name("foo"); |
2255 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = | 2254 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = |
2256 layer.TakeDebugInfo(nullptr); | 2255 layer.TakeDebugInfo(nullptr); |
2257 std::string trace_format("bar,"); | 2256 std::string trace_format("bar,"); |
2258 debug_info->AppendAsTraceFormat(&trace_format); | 2257 debug_info->AppendAsTraceFormat(&trace_format); |
2259 std::string expected("bar,{\"layer_name\":\"foo\"}"); | 2258 std::string expected("bar,{\"layer_name\":\"foo\"}"); |
2260 EXPECT_EQ(expected, trace_format); | 2259 EXPECT_EQ(expected, trace_format); |
2261 } | 2260 } |
2262 | 2261 |
2263 } // namespace ui | 2262 } // namespace ui |
OLD | NEW |