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

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

Issue 2555743004: Delay activation/draw on GPU tile work completion (Closed)
Patch Set: rebase #2 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 float scale,
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 solid_color_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 solid_color_recording_source_->add_draw_rect_with_paint(
1948 gfx::Rect(layer_bounds), solid_paint);
1949
1950 solid_color_recording_source_->Rerecord();
1951
1952 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 recording_source_->add_draw_rect_with_paint(
1961 gfx::Rect(10 * i, 10 * j, 5, 5), non_solid_paint);
1962 }
1963 }
1964 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 SetupTreesWithActiveTreeTiles() {
1975 scoped_refptr<RasterSource> active_tree_raster_source =
1976 RasterSource::CreateFromRecordingSource(recording_source_.get(), false);
1977 scoped_refptr<RasterSource> pending_tree_raster_source =
1978 RasterSource::CreateFromRecordingSource(
1979 solid_color_recording_source_.get(), false);
1980
1981 SetupTrees(pending_tree_raster_source, active_tree_raster_source);
1982 }
1983
1984 void SetupTreesWithPendingTreeTiles() {
1985 scoped_refptr<RasterSource> active_tree_raster_source =
1986 RasterSource::CreateFromRecordingSource(
1987 solid_color_recording_source_.get(), false);
1988 scoped_refptr<RasterSource> pending_tree_raster_source =
1989 RasterSource::CreateFromRecordingSource(recording_source_.get(), false);
1990
1991 SetupTrees(pending_tree_raster_source, active_tree_raster_source);
1992 }
1993
1994 TileManager* tile_manager() { return host_impl()->tile_manager(); }
1995 MockReadyToDrawRasterBufferProviderImpl* mock_raster_buffer_provider() {
1996 return &mock_raster_buffer_provider_;
1997 }
1998
1999 private:
2000 StrictMock<MockReadyToDrawRasterBufferProviderImpl>
2001 mock_raster_buffer_provider_;
2002 std::unique_ptr<FakeRecordingSource> recording_source_;
2003 std::unique_ptr<FakeRecordingSource> solid_color_recording_source_;
2004 };
2005
2006 TEST_F(TileManagerReadyToDrawTest, SmoothActivationWaitsOnCallback) {
2007 host_impl()->SetTreePriority(SMOOTHNESS_TAKES_PRIORITY);
2008 SetupTreesWithPendingTreeTiles();
2009
2010 base::Closure callback;
2011 {
2012 base::RunLoop run_loop;
2013
2014 // Until we activate our ready to draw callback, treat all resources as not
2015 // ready to draw.
2016 EXPECT_CALL(*mock_raster_buffer_provider(),
2017 IsResourceReadyToDraw(testing::_))
2018 .WillRepeatedly(Return(false));
2019
2020 EXPECT_CALL(*mock_raster_buffer_provider(), SetReadyToDrawCallback(_, _, 0))
2021 .WillOnce(testing::Invoke([&run_loop, &callback](
2022 const ResourceProvider::ResourceIdArray& resource_ids,
2023 const base::Closure& callback_in, uint64_t pending_callback_id) {
2024 callback = callback_in;
2025 run_loop.Quit();
2026 return 1;
2027 }));
2028 host_impl()->tile_manager()->DidModifyTilePriorities();
2029 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2030 run_loop.Run();
2031 }
2032
2033 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2034 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate());
2035
2036 {
2037 base::RunLoop run_loop;
2038 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2039 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2040 EXPECT_CALL(*mock_raster_buffer_provider(),
2041 IsResourceReadyToDraw(testing::_))
2042 .WillRepeatedly(Return(true));
2043 callback.Run();
2044 run_loop.Run();
2045 }
2046
2047 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2048 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2049 }
2050
2051 TEST_F(TileManagerReadyToDrawTest, NonSmoothActivationDoesNotWaitOnCallback) {
2052 SetupTreesWithPendingTreeTiles();
2053
2054 // We're using a StrictMock on the RasterBufferProvider, so any function call
2055 // will cause a test failure.
2056 base::RunLoop run_loop;
2057
2058 host_impl()->tile_manager()->DidModifyTilePriorities();
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 SetupTreesWithActiveTreeTiles();
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()->DidModifyTilePriorities();
2091 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2092 run_loop.Run();
2093 }
2094
2095 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToDraw());
2096 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2097
2098 {
2099 base::RunLoop run_loop;
2100 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw())
2101 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); }));
2102 EXPECT_CALL(*mock_raster_buffer_provider(),
2103 IsResourceReadyToDraw(testing::_))
2104 .WillRepeatedly(Return(true));
2105 callback.Run();
2106 run_loop.Run();
2107 }
2108
2109 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2110 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2111 }
2112
2113 TEST_F(TileManagerReadyToDrawTest, NonSmoothDrawDoesNotWaitOnCallback) {
2114 SetupTreesWithActiveTreeTiles();
2115
2116 // We're using a StrictMock on the RasterBufferProvider, so any function call
2117 // will cause a test failure.
2118 base::RunLoop run_loop;
2119
2120 host_impl()->tile_manager()->DidModifyTilePriorities();
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 SetupTreesWithPendingTreeTiles();
2133
2134 base::RunLoop run_loop;
2135 host_impl()->tile_manager()->DidModifyTilePriorities();
2136 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2137 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2138 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2139 EXPECT_CALL(*mock_raster_buffer_provider(), IsResourceReadyToDraw(_))
2140 .WillRepeatedly(Return(true));
2141 run_loop.Run();
2142
2143 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2144 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2145 }
2146
2147 void UpdateVisibleRect(FakePictureLayerImpl* layer,
2148 const gfx::Rect visible_rect) {
2149 PictureLayerTilingSet* tiling_set = layer->tilings();
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 TEST_F(TileManagerReadyToDrawTest, ReadyToDrawRespectsRequirementChange) {
2161 host_impl()->SetTreePriority(SMOOTHNESS_TAKES_PRIORITY);
2162 SetupTreesWithPendingTreeTiles();
2163
2164 // Initially create a tiling with a visible rect of (0, 0, 100, 100) and
2165 // a soon rect of the rest of the layer.
2166 UpdateVisibleRect(pending_layer(), gfx::Rect(0, 0, 100, 100));
2167
2168 // Mark all these tiles as ready to draw.
2169 base::RunLoop run_loop;
2170 host_impl()->tile_manager()->DidModifyTilePriorities();
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::Closure 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::Closure& callback_in, uint64_t pending_callback_id) {
2196 callback = callback_in;
2197 run_loop.Quit();
2198 return 1;
2199 }));
2200 host_impl()->tile_manager()->DidModifyTilePriorities();
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()->DidModifyTilePriorities();
2216 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
2217 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate())
2218 .WillOnce(Invoke([&run_loop]() { run_loop.Quit(); }));
2219 run_loop.Run();
2220 }
2221
2222 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
2223 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
2224 }
2225
1887 } // namespace 2226 } // namespace
1888 } // namespace cc 2227 } // 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