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

Side by Side Diff: cc/tiles/tile_manager_unittest.cc

Issue 2560253003: Delay Activation/Draw in smoothness mode.
Patch Set: more unit tests 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
« no previous file with comments | « cc/tiles/tile_manager.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h"
9 #include "base/callback.h"
8 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 11 #include "base/run_loop.h"
10 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
11 #include "cc/playback/raster_source.h" 13 #include "cc/playback/raster_source.h"
12 #include "cc/playback/recording_source.h" 14 #include "cc/playback/recording_source.h"
13 #include "cc/raster/raster_buffer.h" 15 #include "cc/raster/raster_buffer.h"
14 #include "cc/raster/synchronous_task_graph_runner.h" 16 #include "cc/raster/synchronous_task_graph_runner.h"
15 #include "cc/resources/resource_pool.h" 17 #include "cc/resources/resource_pool.h"
16 #include "cc/test/begin_frame_args_test.h" 18 #include "cc/test/begin_frame_args_test.h"
17 #include "cc/test/fake_compositor_frame_sink.h" 19 #include "cc/test/fake_compositor_frame_sink.h"
(...skipping 14 matching lines...) Expand all
32 #include "cc/tiles/raster_tile_priority_queue.h" 34 #include "cc/tiles/raster_tile_priority_queue.h"
33 #include "cc/tiles/tile.h" 35 #include "cc/tiles/tile.h"
34 #include "cc/tiles/tile_priority.h" 36 #include "cc/tiles/tile_priority.h"
35 #include "cc/tiles/tiling_set_raster_queue_all.h" 37 #include "cc/tiles/tiling_set_raster_queue_all.h"
36 #include "cc/trees/layer_tree_impl.h" 38 #include "cc/trees/layer_tree_impl.h"
37 #include "testing/gmock/include/gmock/gmock.h" 39 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
39 #include "third_party/skia/include/core/SkRefCnt.h" 41 #include "third_party/skia/include/core/SkRefCnt.h"
40 #include "third_party/skia/include/core/SkSurface.h" 42 #include "third_party/skia/include/core/SkSurface.h"
41 43
44 using testing::_;
45 using testing::Invoke;
46 using testing::Return;
47 using testing::StrictMock;
48
42 namespace cc { 49 namespace cc {
43 namespace { 50 namespace {
44 51
45 class TileManagerTilePriorityQueueTest : public TestLayerTreeHostBase { 52 class TileManagerTilePriorityQueueTest : public TestLayerTreeHostBase {
46 public: 53 public:
47 LayerTreeSettings CreateSettings() override { 54 LayerTreeSettings CreateSettings() override {
48 LayerTreeSettingsForTesting settings; 55 LayerTreeSettingsForTesting settings;
49 settings.create_low_res_tiling = true; 56 settings.create_low_res_tiling = true;
50 settings.renderer_settings.buffer_to_texture_target_map = 57 settings.renderer_settings.buffer_to_texture_target_map =
51 DefaultBufferToTextureTargetMapForTesting(); 58 DefaultBufferToTextureTargetMapForTesting();
(...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 public: 1482 public:
1476 MockLayerTreeHostImpl(const LayerTreeSettings& settings, 1483 MockLayerTreeHostImpl(const LayerTreeSettings& settings,
1477 TaskRunnerProvider* task_runner_provider, 1484 TaskRunnerProvider* task_runner_provider,
1478 TaskGraphRunner* task_graph_runner) 1485 TaskGraphRunner* task_graph_runner)
1479 : FakeLayerTreeHostImpl(settings, 1486 : FakeLayerTreeHostImpl(settings,
1480 task_runner_provider, 1487 task_runner_provider,
1481 task_graph_runner) {} 1488 task_graph_runner) {}
1482 1489
1483 MOCK_METHOD0(NotifyAllTileTasksCompleted, void()); 1490 MOCK_METHOD0(NotifyAllTileTasksCompleted, void());
1484 MOCK_METHOD0(NotifyReadyToDraw, void()); 1491 MOCK_METHOD0(NotifyReadyToDraw, void());
1492 MOCK_METHOD0(NotifyReadyToActivate, void());
1485 }; 1493 };
1486 1494
1487 std::unique_ptr<FakeLayerTreeHostImpl> CreateHostImpl( 1495 std::unique_ptr<FakeLayerTreeHostImpl> CreateHostImpl(
1488 const LayerTreeSettings& settings, 1496 const LayerTreeSettings& settings,
1489 TaskRunnerProvider* task_runner_provider, 1497 TaskRunnerProvider* task_runner_provider,
1490 TaskGraphRunner* task_graph_runner) override { 1498 TaskGraphRunner* task_graph_runner) override {
1491 return base::MakeUnique<MockLayerTreeHostImpl>( 1499 return base::MakeUnique<testing::NiceMock<MockLayerTreeHostImpl>>(
1492 settings, task_runner_provider, task_graph_runner); 1500 settings, task_runner_provider, task_graph_runner);
1493 } 1501 }
1494 1502
1495 // By default use software compositing (no context provider). 1503 // By default use software compositing (no context provider).
1496 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { 1504 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override {
1497 return FakeCompositorFrameSink::CreateSoftware(); 1505 return FakeCompositorFrameSink::CreateSoftware();
1498 } 1506 }
1499 1507
1500 MockLayerTreeHostImpl& MockHostImpl() { 1508 MockLayerTreeHostImpl& MockHostImpl() {
1501 return *static_cast<MockLayerTreeHostImpl*>(host_impl()); 1509 return *static_cast<MockLayerTreeHostImpl*>(host_impl());
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) { 1885 TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) {
1878 RunPartialRasterCheck(TakeHostImpl(), true /* partial_raster_enabled */); 1886 RunPartialRasterCheck(TakeHostImpl(), true /* partial_raster_enabled */);
1879 } 1887 }
1880 1888
1881 // Ensures that the tile manager does not attempt to reuse tiles when partial 1889 // Ensures that the tile manager does not attempt to reuse tiles when partial
1882 // raster is disabled. 1890 // raster is disabled.
1883 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) { 1891 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) {
1884 RunPartialRasterCheck(TakeHostImpl(), false /* partial_raster_enabled */); 1892 RunPartialRasterCheck(TakeHostImpl(), false /* partial_raster_enabled */);
1885 } 1893 }
1886 1894
1895 // FakeRasterBufferProviderImpl that allows us to mock ready to draw
1896 // functionality.
1897 class MockReadyToDrawRasterBufferProviderImpl
1898 : public FakeRasterBufferProviderImpl {
1899 public:
1900 MOCK_CONST_METHOD1(IsResourceReadyToDraw, bool(ResourceId resource_id));
1901 MOCK_CONST_METHOD3(
1902 SetReadyToDrawCallback,
1903 uint64_t(const ResourceProvider::ResourceIdArray& resource_ids,
1904 const base::Callback<void(uint64_t)>& callback,
1905 uint64_t pending_callback_id));
1906
1907 std::unique_ptr<RasterBuffer> AcquireBufferForRaster(
1908 const Resource* resource,
1909 uint64_t resource_content_id,
1910 uint64_t previous_content_id) override {
1911 return base::MakeUnique<FakeRasterBuffer>();
1912 }
1913
1914 private:
1915 class FakeRasterBuffer : public RasterBuffer {
1916 public:
1917 void Playback(
1918 const RasterSource* raster_source,
1919 const gfx::Rect& raster_full_rect,
1920 const gfx::Rect& raster_dirty_rect,
1921 uint64_t new_content_id,
1922 const gfx::SizeF& scales,
1923 const RasterSource::PlaybackSettings& playback_settings) override {}
1924 };
1925 };
1926
1927 class TileManagerReadyToDrawTest : public TileManagerTest {
1928 public:
1929 ~TileManagerReadyToDrawTest() override {
1930 // Ensure that the host impl doesn't outlive |raster_buffer_provider_|.
1931 TakeHostImpl();
1932 }
1933
1934 void SetUp() override {
1935 TileManagerTest::SetUp();
1936 host_impl()->tile_manager()->SetRasterBufferProviderForTesting(
1937 &mock_raster_buffer_provider_);
1938
1939 const gfx::Size layer_bounds(1000, 1000);
1940
1941 no_tiles_recording_source_ =
1942 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
1943
1944 SkPaint solid_paint;
1945 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
1946 solid_paint.setColor(solid_color);
1947 no_tiles_recording_source_->add_draw_rect_with_paint(
1948 gfx::Rect(layer_bounds), solid_paint);
1949
1950 no_tiles_recording_source_->Rerecord();
1951
1952 tiles_recording_source_ =
1953 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
1954 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
1955 SkPaint non_solid_paint;
1956 non_solid_paint.setColor(non_solid_color);
1957
1958 for (int i = 0; i < 100; ++i) {
1959 for (int j = 0; j < 100; ++j) {
1960 tiles_recording_source_->add_draw_rect_with_paint(
1961 gfx::Rect(10 * i, 10 * j, 5, 5), non_solid_paint);
1962 }
1963 }
1964 tiles_recording_source_->Rerecord();
1965 }
1966
1967 LayerTreeSettings CreateSettings() override {
1968 LayerTreeSettingsForTesting settings;
1969 settings.renderer_settings.buffer_to_texture_target_map =
1970 DefaultBufferToTextureTargetMapForTesting();
1971 return settings;
1972 }
1973
1974 void SetupActiveTree() {
1975 scoped_refptr<RasterSource> active_tree_raster_source =
1976 RasterSource::CreateFromRecordingSource(tiles_recording_source_.get(),
1977 false);
1978 scoped_refptr<RasterSource> pending_tree_raster_source =
1979 RasterSource::CreateFromRecordingSource(
1980 no_tiles_recording_source_.get(), false);
1981
1982 SetupTrees(pending_tree_raster_source, active_tree_raster_source);
1983 }
1984
1985 void SetupPendingTree() {
1986 scoped_refptr<RasterSource> active_tree_raster_source =
1987 RasterSource::CreateFromRecordingSource(
1988 no_tiles_recording_source_.get(), false);
1989 scoped_refptr<RasterSource> pending_tree_raster_source =
1990 RasterSource::CreateFromRecordingSource(tiles_recording_source_.get(),
1991 false);
1992
1993 SetupTrees(pending_tree_raster_source, active_tree_raster_source);
1994 }
1995
1996 TileManager* tile_manager() { return host_impl()->tile_manager(); }
1997 MockReadyToDrawRasterBufferProviderImpl* mock_raster_buffer_provider() {
1998 return &mock_raster_buffer_provider_;
1999 }
2000
2001 private:
2002 StrictMock<MockReadyToDrawRasterBufferProviderImpl>
2003 mock_raster_buffer_provider_;
2004 std::unique_ptr<FakeRecordingSource> tiles_recording_source_;
2005 std::unique_ptr<FakeRecordingSource> no_tiles_recording_source_;
2006 };
2007
2008 TEST_F(TileManagerReadyToDrawTest, SmoothActivationWaitsOnCallback) {
2009 host_impl()->SetTreePriority(SMOOTHNESS_TAKES_PRIORITY);
2010 SetupPendingTree();
2011
2012 base::Callback<void(uint64_t)> callback;
2013 {
2014 base::RunLoop run_loop;
2015
2016 // Until we activate our ready to draw callback, treat all resources as not
2017 // ready to draw.
2018 EXPECT_CALL(*mock_raster_buffer_provider(),
2019 IsResourceReadyToDraw(testing::_))
2020 .WillRepeatedly(Return(false));
2021
2022 EXPECT_CALL(*mock_raster_buffer_provider(), SetReadyToDrawCallback(_, _, 0))
2023 .WillOnce(testing::Invoke([&run_loop, &callback](
2024 const ResourceProvider::ResourceIdArray& resource_ids,
2025 const base::Callback<void(uint64_t)>& callback_in,
2026 uint64_t pending_callback_id) {
2027 callback = callback_in;
2028 run_loop.Quit();
2029 return 1;
2030 }));
2031 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2032 run_loop.Run();
2033 }
2034
2035 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2036 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate());
2037
2038 {
2039 base::RunLoop run_loop;
2040 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2041 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2042 EXPECT_CALL(*mock_raster_buffer_provider(),
2043 IsResourceReadyToDraw(testing::_))
2044 .WillRepeatedly(Return(true));
2045 callback.Run(1);
2046 run_loop.Run();
2047 }
2048
2049 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2050 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2051 }
2052
2053 TEST_F(TileManagerReadyToDrawTest, NonSmoothActivationDoesNotWaitOnCallback) {
2054 SetupPendingTree();
2055
2056 // We're using a StrictMock on the RasterBufferProvider, so any function call
2057 // will cause a test failure.
2058 base::RunLoop run_loop;
2059
2060 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2061 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2062 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2063 run_loop.Run();
2064
2065 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2066 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2067 }
2068
2069 TEST_F(TileManagerReadyToDrawTest, SmoothDrawWaitsOnCallback) {
2070 host_impl()->SetTreePriority(SMOOTHNESS_TAKES_PRIORITY);
2071 SetupActiveTree();
2072
2073 base::Callback<void(uint64_t)> callback;
2074 {
2075 base::RunLoop run_loop;
2076
2077 // Until we activate our ready to draw callback, treat all resources as not
2078 // ready to draw.
2079 EXPECT_CALL(*mock_raster_buffer_provider(),
2080 IsResourceReadyToDraw(testing::_))
2081 .WillRepeatedly(Return(false));
2082
2083 EXPECT_CALL(*mock_raster_buffer_provider(), SetReadyToDrawCallback(_, _, 0))
2084 .WillOnce(Invoke([&run_loop, &callback](
2085 const ResourceProvider::ResourceIdArray& resource_ids,
2086 const base::Callback<void(uint64_t)>& callback_in,
2087 uint64_t pending_callback_id) {
2088 callback = callback_in;
2089 run_loop.Quit();
2090 return 1;
2091 }));
2092 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2093 run_loop.Run();
2094 }
2095
2096 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToDraw());
2097 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2098
2099 {
2100 base::RunLoop run_loop;
2101 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw())
2102 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); }));
2103 EXPECT_CALL(*mock_raster_buffer_provider(),
2104 IsResourceReadyToDraw(testing::_))
2105 .WillRepeatedly(Return(true));
2106 callback.Run(1);
2107 run_loop.Run();
2108 }
2109
2110 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2111 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2112 }
2113
2114 TEST_F(TileManagerReadyToDrawTest, NonSmoothDrawDoesNotWaitOnCallback) {
2115 SetupActiveTree();
2116
2117 // We're using a StrictMock on the RasterBufferProvider, so any function call
2118 // will cause a test failure.
2119 base::RunLoop run_loop;
2120
2121 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2122 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw())
2123 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2124 run_loop.Run();
2125
2126 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2127 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2128 }
2129
2130 TEST_F(TileManagerReadyToDrawTest, NoCallbackWhenAlreadyReadyToDraw) {
2131 host_impl()->SetTreePriority(SMOOTHNESS_TAKES_PRIORITY);
2132 SetupPendingTree();
2133
2134 base::RunLoop run_loop;
2135 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2136 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2137 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2138 EXPECT_CALL(*mock_raster_buffer_provider(), IsResourceReadyToDraw(_))
2139 .WillRepeatedly(Return(true));
2140 run_loop.Run();
2141
2142 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2143 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2144 }
2145
2146 void UpdateVisibleRect(FakePictureLayerImpl* layer,
2147 const gfx::Rect visible_rect) {
2148 for (size_t i = 0; i < layer->num_tilings(); ++i) {
2149 PictureLayerTilingSet* tiling_set = &layer->tilings()[i];
2150 for (size_t j = 0; j < tiling_set->num_tilings(); ++j) {
2151 PictureLayerTiling* tiling = tiling_set->tiling_at(j);
2152 tiling->SetTilePriorityRectsForTesting(
2153 visible_rect, // Visible rect.
2154 visible_rect, // Skewport rect.
2155 visible_rect, // Soon rect.
2156 gfx::Rect(0, 0, 1000, 1000)); // Eventually rect.
2157 }
2158 }
2159 }
2160
2161 TEST_F(TileManagerReadyToDrawTest, ReadyToDrawRespectsRequirementChange) {
2162 host_impl()->SetTreePriority(SMOOTHNESS_TAKES_PRIORITY);
2163 SetupPendingTree();
2164
2165 // Initially create a tiling with a visible rect of (0, 0, 100, 100) and
2166 // a soon rect of the rest of the layer.
2167 UpdateVisibleRect(pending_layer(), gfx::Rect(0, 0, 100, 100));
2168
2169 // Mark all these tiles as ready to draw.
2170 base::RunLoop run_loop;
2171 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2172 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2173 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2174 EXPECT_CALL(*mock_raster_buffer_provider(), IsResourceReadyToDraw(_))
2175 .WillRepeatedly(Return(true));
2176 run_loop.Run();
2177
2178 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2179 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2180
2181 // Move the viewport to (900, 900, 100, 100), so that we need a different set
2182 // of tilings.
2183 UpdateVisibleRect(pending_layer(), gfx::Rect(900, 900, 100, 100));
2184
2185 EXPECT_CALL(*mock_raster_buffer_provider(), IsResourceReadyToDraw(testing::_))
2186 .WillRepeatedly(Return(false));
2187
2188 base::Callback<void(uint64_t)> callback;
2189 {
2190 base::RunLoop run_loop;
2191
2192 EXPECT_CALL(*mock_raster_buffer_provider(), SetReadyToDrawCallback(_, _, 0))
2193 .WillOnce(testing::Invoke([&run_loop, &callback](
2194 const ResourceProvider::ResourceIdArray& resource_ids,
2195 const base::Callback<void(uint64_t)>& callback_in,
2196 uint64_t pending_callback_id) {
2197 callback = callback_in;
2198 run_loop.Quit();
2199 return 1;
2200 }));
2201 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2202 run_loop.Run();
2203 }
2204
2205 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2206 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate());
2207
2208 // Now switch back to our original tiling. We should be immediately able to
2209 // activate, as we still have the original tile, and no longer need the
2210 // tiles from the previous callback.
2211 UpdateVisibleRect(pending_layer(), gfx::Rect(0, 0, 100, 100));
2212
2213 {
2214 base::RunLoop run_loop;
2215 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2216 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2217 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2218 run_loop.Run();
2219 }
2220
2221 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2222 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2223 }
2224
1887 } // namespace 2225 } // namespace
1888 } // namespace cc 2226 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/tile_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698