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

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

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

Powered by Google App Engine
This is Rietveld 408576698