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

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

Issue 2555743004: Delay activation/draw on GPU tile work completion (Closed)
Patch Set: rebase Created 3 years, 11 months 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/tiles/tile_manager.cc ('K') | « 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::Closure& 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();
vmpstr 2017/01/05 22:00:46 nit: solid_color_recording_source_ and just.. reco
ericrk 2017/01/09 23:05:22 Done.
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() {
vmpstr 2017/01/05 22:00:47 I'm a bit confused by the names here, since both S
ericrk 2017/01/09 23:05:22 Renamed to make it clearer. We are always setting
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::Closure 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));
vmpstr 2017/01/05 22:00:47 I'm always amazed by this gmock magic.
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::Closure& callback_in, uint64_t pending_callback_id) {
2026 callback = callback_in;
2027 run_loop.Quit();
2028 return 1;
2029 }));
2030 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2031 run_loop.Run();
2032 }
2033
2034 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2035 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate());
2036
2037 {
2038 base::RunLoop run_loop;
2039 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2040 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2041 EXPECT_CALL(*mock_raster_buffer_provider(),
2042 IsResourceReadyToDraw(testing::_))
2043 .WillRepeatedly(Return(true));
2044 callback.Run();
2045 run_loop.Run();
2046 }
2047
2048 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2049 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2050 }
2051
2052 TEST_F(TileManagerReadyToDrawTest, NonSmoothActivationDoesNotWaitOnCallback) {
2053 SetupPendingTree();
2054
2055 // We're using a StrictMock on the RasterBufferProvider, so any function call
2056 // will cause a test failure.
2057 base::RunLoop run_loop;
2058
2059 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2060 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2061 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2062 run_loop.Run();
2063
2064 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2065 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2066 }
2067
2068 TEST_F(TileManagerReadyToDrawTest, SmoothDrawWaitsOnCallback) {
2069 host_impl()->SetTreePriority(SMOOTHNESS_TAKES_PRIORITY);
2070 SetupActiveTree();
2071
2072 base::Closure callback;
2073 {
2074 base::RunLoop run_loop;
2075
2076 // Until we activate our ready to draw callback, treat all resources as not
2077 // ready to draw.
2078 EXPECT_CALL(*mock_raster_buffer_provider(),
2079 IsResourceReadyToDraw(testing::_))
2080 .WillRepeatedly(Return(false));
2081
2082 EXPECT_CALL(*mock_raster_buffer_provider(), SetReadyToDrawCallback(_, _, 0))
2083 .WillOnce(Invoke([&run_loop, &callback](
2084 const ResourceProvider::ResourceIdArray& resource_ids,
2085 const base::Closure& callback_in, uint64_t pending_callback_id) {
2086 callback = callback_in;
2087 run_loop.Quit();
2088 return 1;
2089 }));
2090 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2091 run_loop.Run();
2092 }
2093
2094 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToDraw());
2095 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2096
2097 {
2098 base::RunLoop run_loop;
2099 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw())
2100 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); }));
2101 EXPECT_CALL(*mock_raster_buffer_provider(),
2102 IsResourceReadyToDraw(testing::_))
2103 .WillRepeatedly(Return(true));
2104 callback.Run();
2105 run_loop.Run();
2106 }
2107
2108 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2109 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2110 }
2111
2112 TEST_F(TileManagerReadyToDrawTest, NonSmoothDrawDoesNotWaitOnCallback) {
2113 SetupActiveTree();
2114
2115 // We're using a StrictMock on the RasterBufferProvider, so any function call
2116 // will cause a test failure.
2117 base::RunLoop run_loop;
2118
2119 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2120 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw())
2121 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2122 run_loop.Run();
2123
2124 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2125 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2126 }
2127
2128 TEST_F(TileManagerReadyToDrawTest, NoCallbackWhenAlreadyReadyToDraw) {
2129 host_impl()->SetTreePriority(SMOOTHNESS_TAKES_PRIORITY);
2130 SetupPendingTree();
2131
2132 base::RunLoop run_loop;
2133 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2134 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2135 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2136 EXPECT_CALL(*mock_raster_buffer_provider(), IsResourceReadyToDraw(_))
2137 .WillRepeatedly(Return(true));
2138 run_loop.Run();
2139
2140 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2141 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2142 }
2143
2144 void UpdateVisibleRect(FakePictureLayerImpl* layer,
2145 const gfx::Rect visible_rect) {
2146 for (size_t i = 0; i < layer->num_tilings(); ++i) {
2147 PictureLayerTilingSet* tiling_set = &layer->tilings()[i];
vmpstr 2017/01/05 22:00:47 This doesn't seem right. layer->tilings() returns
ericrk 2017/01/09 23:05:22 Yup :D
2148 for (size_t j = 0; j < tiling_set->num_tilings(); ++j) {
2149 PictureLayerTiling* tiling = tiling_set->tiling_at(j);
2150 tiling->SetTilePriorityRectsForTesting(
2151 visible_rect, // Visible rect.
2152 visible_rect, // Skewport rect.
2153 visible_rect, // Soon rect.
2154 gfx::Rect(0, 0, 1000, 1000)); // Eventually rect.
2155 }
2156 }
2157 }
2158
2159 TEST_F(TileManagerReadyToDrawTest, ReadyToDrawRespectsRequirementChange) {
2160 host_impl()->SetTreePriority(SMOOTHNESS_TAKES_PRIORITY);
2161 SetupPendingTree();
2162
2163 // Initially create a tiling with a visible rect of (0, 0, 100, 100) and
2164 // a soon rect of the rest of the layer.
2165 UpdateVisibleRect(pending_layer(), gfx::Rect(0, 0, 100, 100));
2166
2167 // Mark all these tiles as ready to draw.
2168 base::RunLoop run_loop;
2169 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2170 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2171 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2172 EXPECT_CALL(*mock_raster_buffer_provider(), IsResourceReadyToDraw(_))
2173 .WillRepeatedly(Return(true));
2174 run_loop.Run();
2175
2176 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2177 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2178
2179 // Move the viewport to (900, 900, 100, 100), so that we need a different set
2180 // of tilings.
2181 UpdateVisibleRect(pending_layer(), gfx::Rect(900, 900, 100, 100));
2182
2183 EXPECT_CALL(*mock_raster_buffer_provider(), IsResourceReadyToDraw(testing::_))
2184 .WillRepeatedly(Return(false));
2185
2186 base::Closure callback;
2187 {
2188 base::RunLoop run_loop;
2189
2190 EXPECT_CALL(*mock_raster_buffer_provider(), SetReadyToDrawCallback(_, _, 0))
2191 .WillOnce(testing::Invoke([&run_loop, &callback](
2192 const ResourceProvider::ResourceIdArray& resource_ids,
2193 const base::Closure& callback_in, uint64_t pending_callback_id) {
2194 callback = callback_in;
2195 run_loop.Quit();
2196 return 1;
2197 }));
2198 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
vmpstr 2017/01/05 22:00:47 My concern here (as I commented in the code) is wh
ericrk 2017/01/09 23:05:22 Per other comment, updated so that we update the r
2199 run_loop.Run();
2200 }
2201
2202 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2203 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate());
2204
2205 // Now switch back to our original tiling. We should be immediately able to
2206 // activate, as we still have the original tile, and no longer need the
2207 // tiles from the previous callback.
2208 UpdateVisibleRect(pending_layer(), gfx::Rect(0, 0, 100, 100));
2209
2210 {
2211 base::RunLoop run_loop;
2212 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2213 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2214 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2215 run_loop.Run();
2216 }
2217
2218 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2219 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2220 }
2221
1887 } // namespace 2222 } // namespace
1888 } // namespace cc 2223 } // namespace cc
OLDNEW
« cc/tiles/tile_manager.cc ('K') | « cc/tiles/tile_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698