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

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

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

Powered by Google App Engine
This is Rietveld 408576698