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