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

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

Issue 1910213005: cc: Refactor TileTaskWorkerPool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@task_states
Patch Set: feedback Created 4 years, 7 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
« no previous file with comments | « cc/tiles/tile_manager_perftest.cc ('k') | cc/tiles/tile_task_manager.h » ('j') | 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/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "cc/playback/raster_source.h" 11 #include "cc/playback/raster_source.h"
12 #include "cc/playback/recording_source.h" 12 #include "cc/playback/recording_source.h"
13 #include "cc/raster/raster_buffer.h" 13 #include "cc/raster/raster_buffer.h"
14 #include "cc/raster/synchronous_task_graph_runner.h" 14 #include "cc/raster/synchronous_task_graph_runner.h"
15 #include "cc/resources/resource_pool.h" 15 #include "cc/resources/resource_pool.h"
16 #include "cc/test/begin_frame_args_test.h" 16 #include "cc/test/begin_frame_args_test.h"
17 #include "cc/test/fake_impl_task_runner_provider.h" 17 #include "cc/test/fake_impl_task_runner_provider.h"
18 #include "cc/test/fake_layer_tree_host_impl.h" 18 #include "cc/test/fake_layer_tree_host_impl.h"
19 #include "cc/test/fake_output_surface.h" 19 #include "cc/test/fake_output_surface.h"
20 #include "cc/test/fake_output_surface_client.h" 20 #include "cc/test/fake_output_surface_client.h"
21 #include "cc/test/fake_picture_layer_impl.h" 21 #include "cc/test/fake_picture_layer_impl.h"
22 #include "cc/test/fake_picture_layer_tiling_client.h" 22 #include "cc/test/fake_picture_layer_tiling_client.h"
23 #include "cc/test/fake_raster_source.h" 23 #include "cc/test/fake_raster_source.h"
24 #include "cc/test/fake_recording_source.h" 24 #include "cc/test/fake_recording_source.h"
25 #include "cc/test/fake_tile_manager.h" 25 #include "cc/test/fake_tile_manager.h"
26 #include "cc/test/fake_tile_task_manager.h"
26 #include "cc/test/test_gpu_memory_buffer_manager.h" 27 #include "cc/test/test_gpu_memory_buffer_manager.h"
27 #include "cc/test/test_shared_bitmap_manager.h" 28 #include "cc/test/test_shared_bitmap_manager.h"
28 #include "cc/test/test_task_graph_runner.h" 29 #include "cc/test/test_task_graph_runner.h"
29 #include "cc/test/test_tile_priorities.h" 30 #include "cc/test/test_tile_priorities.h"
30 #include "cc/tiles/eviction_tile_priority_queue.h" 31 #include "cc/tiles/eviction_tile_priority_queue.h"
31 #include "cc/tiles/raster_tile_priority_queue.h" 32 #include "cc/tiles/raster_tile_priority_queue.h"
32 #include "cc/tiles/tile.h" 33 #include "cc/tiles/tile.h"
33 #include "cc/tiles/tile_priority.h" 34 #include "cc/tiles/tile_priority.h"
34 #include "cc/tiles/tiling_set_raster_queue_all.h" 35 #include "cc/tiles/tiling_set_raster_queue_all.h"
35 #include "cc/trees/layer_tree_impl.h" 36 #include "cc/trees/layer_tree_impl.h"
(...skipping 1864 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 1901
1901 // The first task to run should be ReadyToDraw (this should not be blocked by 1902 // The first task to run should be ReadyToDraw (this should not be blocked by
1902 // the tasks required for activation). 1903 // the tasks required for activation).
1903 base::RunLoop run_loop; 1904 base::RunLoop run_loop;
1904 EXPECT_CALL(*host_impl_, NotifyReadyToDraw()) 1905 EXPECT_CALL(*host_impl_, NotifyReadyToDraw())
1905 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); })); 1906 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); }));
1906 GetSynchronousTaskGraphRunner()->RunSingleTaskForTesting(); 1907 GetSynchronousTaskGraphRunner()->RunSingleTaskForTesting();
1907 run_loop.Run(); 1908 run_loop.Run();
1908 } 1909 }
1909 1910
1910 // Fake TileTaskRunner that just no-ops all calls. 1911 // Fake TileTaskManager that just cancels all scheduled tasks immediately.
1911 // Fake TileTaskWorkerPool that just no-ops all calls. 1912 class CancellingTileTaskManager : public FakeTileTaskManagerImpl {
1912 class FakeTileTaskWorkerPool : public TileTaskWorkerPool,
1913 public RasterBufferProvider {
1914 public: 1913 public:
1915 FakeTileTaskWorkerPool() {} 1914 CancellingTileTaskManager() {}
1916 ~FakeTileTaskWorkerPool() override {} 1915 ~CancellingTileTaskManager() override {}
1917
1918 // TileTaskWorkerPool methods.
1919 void Shutdown() override {}
1920 void CheckForCompletedTasks() override {}
1921 ResourceFormat GetResourceFormat(bool must_support_alpha) const override {
1922 return ResourceFormat::RGBA_8888;
1923 }
1924 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override {
1925 return false;
1926 }
1927 RasterBufferProvider* AsRasterBufferProvider() override { return this; }
1928
1929 void ScheduleTasks(TaskGraph* graph) override {}
1930
1931 // RasterBufferProvider methods.
1932 std::unique_ptr<RasterBuffer> AcquireBufferForRaster(
1933 const Resource* resource,
1934 uint64_t resource_content_id,
1935 uint64_t previous_content_id) override {
1936 NOTREACHED();
1937 return nullptr;
1938 }
1939 void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) override {}
1940 };
1941
1942 // Fake TileTaskWorkerPool that just cancels all scheduled tasks immediately.
1943 class CancellingTileTaskWorkerPool : public FakeTileTaskWorkerPool {
1944 public:
1945 CancellingTileTaskWorkerPool() {}
1946 ~CancellingTileTaskWorkerPool() override {}
1947 1916
1948 void ScheduleTasks(TaskGraph* graph) override { 1917 void ScheduleTasks(TaskGraph* graph) override {
1949 // Just call CompleteOnOriginThread on each item in the queue. As none of 1918 // Just call CompleteOnOriginThread on each item in the queue. As none of
1950 // these items have run yet, they will be treated as cancelled tasks. 1919 // these items have run yet, they will be treated as cancelled tasks.
1951 for (const auto& node : graph->nodes) { 1920 for (const auto& node : graph->nodes) {
1952 static_cast<TileTask*>(node.task)->CompleteOnOriginThread(this); 1921 static_cast<TileTask*>(node.task)->CompleteOnOriginThread(
1922 raster_buffer_provider_.get());
1953 } 1923 }
1954 } 1924 }
1925 void CheckForCompletedTasks() override {}
1955 }; 1926 };
1956 1927
1957 class PartialRasterTileManagerTest : public TileManagerTest { 1928 class PartialRasterTileManagerTest : public TileManagerTest {
1958 public: 1929 public:
1959 void CustomizeSettings(LayerTreeSettings* settings) override { 1930 void CustomizeSettings(LayerTreeSettings* settings) override {
1960 settings->use_partial_raster = true; 1931 settings->use_partial_raster = true;
1961 } 1932 }
1962 }; 1933 };
1963 1934
1964 // Ensures that if a raster task is cancelled, it gets returned to the resource 1935 // Ensures that if a raster task is cancelled, it gets returned to the resource
1965 // pool with an invalid content ID, not with its invalidated content ID. 1936 // pool with an invalid content ID, not with its invalidated content ID.
1966 TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) { 1937 TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) {
1967 // Create a CancellingTaskRunner and set it on the tile manager so that all 1938 // Create a CancellingTaskRunner and set it on the tile manager so that all
1968 // scheduled work is immediately cancelled. 1939 // scheduled work is immediately cancelled.
1969 CancellingTileTaskWorkerPool cancelling_worker_pool; 1940 CancellingTileTaskManager cancelling_task_manager;
1970 host_impl_->tile_manager()->SetTileTaskWorkerPoolForTesting( 1941 host_impl_->tile_manager()->SetTileTaskManagerForTesting(
1971 &cancelling_worker_pool); 1942 &cancelling_task_manager);
1972 1943
1973 // Pick arbitrary IDs - they don't really matter as long as they're constant. 1944 // Pick arbitrary IDs - they don't really matter as long as they're constant.
1974 const int kLayerId = 7; 1945 const int kLayerId = 7;
1975 const uint64_t kInvalidatedId = 43; 1946 const uint64_t kInvalidatedId = 43;
1976 const gfx::Size kTileSize(128, 128); 1947 const gfx::Size kTileSize(128, 128);
1977 1948
1978 scoped_refptr<FakeRasterSource> pending_raster_source = 1949 scoped_refptr<FakeRasterSource> pending_raster_source =
1979 FakeRasterSource::CreateFilled(kTileSize); 1950 FakeRasterSource::CreateFilled(kTileSize);
1980 host_impl_->CreatePendingTree(); 1951 host_impl_->CreatePendingTree();
1981 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); 1952 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
(...skipping 12 matching lines...) Expand all
1994 // Add tilings/tiles for the layer. 1965 // Add tilings/tiles for the layer.
1995 host_impl_->pending_tree()->BuildPropertyTreesForTesting(); 1966 host_impl_->pending_tree()->BuildPropertyTreesForTesting();
1996 host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */); 1967 host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */);
1997 1968
1998 // Build the raster queue and invalidate the top tile. 1969 // Build the raster queue and invalidate the top tile.
1999 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue( 1970 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue(
2000 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); 1971 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL));
2001 EXPECT_FALSE(queue->IsEmpty()); 1972 EXPECT_FALSE(queue->IsEmpty());
2002 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); 1973 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
2003 1974
2004 // PrepareTiles to schedule tasks. Due to the CancellingTileTaskWorkerPool, 1975 // PrepareTiles to schedule tasks. Due to the CancellingTileTaskManager,
2005 // these 1976 // these tasks will immediately be canceled.
2006 // tasks will immediately be canceled.
2007 host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state()); 1977 host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state());
2008 1978
2009 // Make sure that the tile we invalidated above was not returned to the pool 1979 // Make sure that the tile we invalidated above was not returned to the pool
2010 // with its invalidated resource ID. 1980 // with its invalidated resource ID.
2011 host_impl_->resource_pool()->CheckBusyResources(); 1981 host_impl_->resource_pool()->CheckBusyResources();
2012 EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId( 1982 EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId(
2013 kInvalidatedId)); 1983 kInvalidatedId));
2014 1984
2015 // Free our host_impl_ before the cancelling_worker_pool we passed it, as it 1985 // Free our host_impl_ before the cancelling_task_manager we passed it, as it
2016 // will 1986 // will use that class in clean up.
2017 // use that class in clean up.
2018 host_impl_ = nullptr; 1987 host_impl_ = nullptr;
2019 } 1988 }
2020 1989
2021 // Fake TileTaskWorkerPool that verifies the resource content ID of raster 1990 // FakeRasterBufferProviderImpl that verifies the resource content ID of raster
2022 // tasks. 1991 // tasks.
2023 class VerifyResourceContentIdTileTaskWorkerPool 1992 class VerifyResourceContentIdRasterBufferProvider
2024 : public FakeTileTaskWorkerPool { 1993 : public FakeRasterBufferProviderImpl {
2025 public: 1994 public:
2026 explicit VerifyResourceContentIdTileTaskWorkerPool( 1995 explicit VerifyResourceContentIdRasterBufferProvider(
2027 uint64_t expected_resource_id) 1996 uint64_t expected_resource_id)
2028 : expected_resource_id_(expected_resource_id) {} 1997 : expected_resource_id_(expected_resource_id) {}
2029 ~VerifyResourceContentIdTileTaskWorkerPool() override {} 1998 ~VerifyResourceContentIdRasterBufferProvider() override {}
2030
2031 void ScheduleTasks(TaskGraph* graph) override {
2032 for (const auto& node : graph->nodes) {
2033 TileTask* task = static_cast<TileTask*>(node.task);
2034 // Triggers a call to AcquireBufferForRaster.
2035 task->ScheduleOnOriginThread(this);
2036 // Calls TileManager as though task was cancelled.
2037 task->CompleteOnOriginThread(this);
2038 }
2039 }
2040 1999
2041 // RasterBufferProvider methods. 2000 // RasterBufferProvider methods.
2042 std::unique_ptr<RasterBuffer> AcquireBufferForRaster( 2001 std::unique_ptr<RasterBuffer> AcquireBufferForRaster(
2043 const Resource* resource, 2002 const Resource* resource,
2044 uint64_t resource_content_id, 2003 uint64_t resource_content_id,
2045 uint64_t previous_content_id) override { 2004 uint64_t previous_content_id) override {
2046 EXPECT_EQ(expected_resource_id_, resource_content_id); 2005 EXPECT_EQ(expected_resource_id_, resource_content_id);
2047 return nullptr; 2006 return nullptr;
2048 } 2007 }
2049 2008
2050 private: 2009 private:
2051 uint64_t expected_resource_id_; 2010 uint64_t expected_resource_id_;
2052 }; 2011 };
2053 2012
2013 class VerifyResourceContentIdTileTaskManager : public FakeTileTaskManagerImpl {
2014 public:
2015 explicit VerifyResourceContentIdTileTaskManager(uint64_t expected_resource_id)
2016 : FakeTileTaskManagerImpl(base::WrapUnique<RasterBufferProvider>(
2017 new VerifyResourceContentIdRasterBufferProvider(
2018 expected_resource_id))) {}
2019 ~VerifyResourceContentIdTileTaskManager() override {}
2020
2021 void ScheduleTasks(TaskGraph* graph) override {
2022 for (const auto& node : graph->nodes) {
2023 TileTask* task = static_cast<TileTask*>(node.task);
2024 // Triggers a call to AcquireBufferForRaster.
2025 task->ScheduleOnOriginThread(raster_buffer_provider_.get());
2026 // Calls TileManager as though task was cancelled.
2027 task->CompleteOnOriginThread(raster_buffer_provider_.get());
2028 }
2029 }
2030 void CheckForCompletedTasks() override {}
2031 };
2032
2054 // Runs a test to ensure that partial raster is either enabled or disabled, 2033 // Runs a test to ensure that partial raster is either enabled or disabled,
2055 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl 2034 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl
2056 // so that cleanup order can be controlled. 2035 // so that cleanup order can be controlled.
2057 void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl, 2036 void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl,
2058 bool partial_raster_enabled) { 2037 bool partial_raster_enabled) {
2059 // Pick arbitrary IDs - they don't really matter as long as they're constant. 2038 // Pick arbitrary IDs - they don't really matter as long as they're constant.
2060 const int kLayerId = 7; 2039 const int kLayerId = 7;
2061 const uint64_t kInvalidatedId = 43; 2040 const uint64_t kInvalidatedId = 43;
2062 const uint64_t kExpectedId = partial_raster_enabled ? kInvalidatedId : 0u; 2041 const uint64_t kExpectedId = partial_raster_enabled ? kInvalidatedId : 0u;
2063 const gfx::Size kTileSize(128, 128); 2042 const gfx::Size kTileSize(128, 128);
2064 2043
2065 // Create a VerifyResourceContentIdTileTaskWorkerPool to ensure that the 2044 // Create a VerifyResourceContentIdTileTaskManager to ensure that the
2066 // raster 2045 // raster task we see is created with |kExpectedId|.
2067 // task we see is created with |kExpectedId|. 2046 VerifyResourceContentIdTileTaskManager verifying_task_manager(kExpectedId);
2068 VerifyResourceContentIdTileTaskWorkerPool verifying_worker_pool(kExpectedId); 2047 host_impl->tile_manager()->SetTileTaskManagerForTesting(
2069 host_impl->tile_manager()->SetTileTaskWorkerPoolForTesting( 2048 &verifying_task_manager);
2070 &verifying_worker_pool);
2071 2049
2072 // Ensure there's a resource with our |kInvalidatedId| in the resource pool. 2050 // Ensure there's a resource with our |kInvalidatedId| in the resource pool.
2073 host_impl->resource_pool()->ReleaseResource( 2051 host_impl->resource_pool()->ReleaseResource(
2074 host_impl->resource_pool()->AcquireResource(kTileSize, RGBA_8888), 2052 host_impl->resource_pool()->AcquireResource(kTileSize, RGBA_8888),
2075 kInvalidatedId); 2053 kInvalidatedId);
2076 host_impl->resource_pool()->CheckBusyResources(); 2054 host_impl->resource_pool()->CheckBusyResources();
2077 2055
2078 scoped_refptr<FakeRasterSource> pending_raster_source = 2056 scoped_refptr<FakeRasterSource> pending_raster_source =
2079 FakeRasterSource::CreateFilled(kTileSize); 2057 FakeRasterSource::CreateFilled(kTileSize);
2080 host_impl->CreatePendingTree(); 2058 host_impl->CreatePendingTree();
(...skipping 14 matching lines...) Expand all
2095 host_impl->pending_tree()->BuildPropertyTreesForTesting(); 2073 host_impl->pending_tree()->BuildPropertyTreesForTesting();
2096 host_impl->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */); 2074 host_impl->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */);
2097 2075
2098 // Build the raster queue and invalidate the top tile. 2076 // Build the raster queue and invalidate the top tile.
2099 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl->BuildRasterQueue( 2077 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl->BuildRasterQueue(
2100 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); 2078 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL));
2101 EXPECT_FALSE(queue->IsEmpty()); 2079 EXPECT_FALSE(queue->IsEmpty());
2102 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); 2080 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
2103 2081
2104 // PrepareTiles to schedule tasks. Due to the 2082 // PrepareTiles to schedule tasks. Due to the
2105 // VerifyPreviousContentTileTaskWorkerPool, these tasks will verified and 2083 // VerifyPreviousContentRasterBufferProvider, these tasks will verified and
2106 // cancelled. 2084 // cancelled.
2107 host_impl->tile_manager()->PrepareTiles(host_impl->global_tile_state()); 2085 host_impl->tile_manager()->PrepareTiles(host_impl->global_tile_state());
2108 2086
2109 // Free our host_impl before the cancelling_worker_pool we passed it, as it 2087 // Free our host_impl before the verifying_task_manager we passed it, as it
2110 // will 2088 // will use that class in clean up.
2111 // use that class in clean up.
2112 host_impl = nullptr; 2089 host_impl = nullptr;
2113 } 2090 }
2114 2091
2115 // Ensures that the tile manager successfully reuses tiles when partial 2092 // Ensures that the tile manager successfully reuses tiles when partial
2116 // raster is enabled. 2093 // raster is enabled.
2117 TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) { 2094 TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) {
2118 RunPartialRasterCheck(std::move(host_impl_), 2095 RunPartialRasterCheck(std::move(host_impl_),
2119 true /* partial_raster_enabled */); 2096 true /* partial_raster_enabled */);
2120 } 2097 }
2121 2098
2122 // Ensures that the tile manager does not attempt to reuse tiles when partial 2099 // Ensures that the tile manager does not attempt to reuse tiles when partial
2123 // raster is disabled. 2100 // raster is disabled.
2124 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) { 2101 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) {
2125 RunPartialRasterCheck(std::move(host_impl_), 2102 RunPartialRasterCheck(std::move(host_impl_),
2126 false /* partial_raster_enabled */); 2103 false /* partial_raster_enabled */);
2127 } 2104 }
2128 2105
2129 } // namespace 2106 } // namespace
2130 } // namespace cc 2107 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/tile_manager_perftest.cc ('k') | cc/tiles/tile_task_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698