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

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: nits Created 4 years, 8 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
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"
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 } 1828 }
1829 1829
1830 // Fake TileTaskWorkerPool that just no-ops all calls. 1830 // Fake TileTaskWorkerPool that just no-ops all calls.
1831 class FakeTileTaskWorkerPool : public TileTaskWorkerPool, 1831 class FakeTileTaskWorkerPool : public TileTaskWorkerPool,
1832 public RasterBufferProvider { 1832 public RasterBufferProvider {
1833 public: 1833 public:
1834 FakeTileTaskWorkerPool() {} 1834 FakeTileTaskWorkerPool() {}
1835 ~FakeTileTaskWorkerPool() override {} 1835 ~FakeTileTaskWorkerPool() override {}
1836 1836
1837 // TileTaskWorkerPool methods. 1837 // TileTaskWorkerPool methods.
1838 void Shutdown() override {} 1838 void BarrierToSyncResources() override {}
1839 void CheckForCompletedTasks() override {}
1840 ResourceFormat GetResourceFormat(bool must_support_alpha) const override { 1839 ResourceFormat GetResourceFormat(bool must_support_alpha) const override {
1841 return ResourceFormat::RGBA_8888; 1840 return ResourceFormat::RGBA_8888;
1842 } 1841 }
1843 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override { 1842 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override {
1844 return false; 1843 return false;
1845 } 1844 }
1846 RasterBufferProvider* AsRasterBufferProvider() override { return this; } 1845 RasterBufferProvider* AsRasterBufferProvider() override { return this; }
1847 1846
1848 void ScheduleTasks(TaskGraph* graph) override {}
1849
1850 // RasterBufferProvider methods. 1847 // RasterBufferProvider methods.
1851 std::unique_ptr<RasterBuffer> AcquireBufferForRaster( 1848 std::unique_ptr<RasterBuffer> AcquireBufferForRaster(
1852 const Resource* resource, 1849 const Resource* resource,
1853 uint64_t resource_content_id, 1850 uint64_t resource_content_id,
1854 uint64_t previous_content_id) override { 1851 uint64_t previous_content_id) override {
1855 NOTREACHED(); 1852 NOTREACHED();
1856 return nullptr; 1853 return nullptr;
1857 } 1854 }
1858 void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) override {} 1855 void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) override {}
1859 }; 1856 };
1860 1857
1861 // Fake TileTaskWorkerPool that just cancels all scheduled tasks immediately. 1858 class FakeTileTaskManager : public TileTaskManager {
1862 class CancellingTileTaskWorkerPool : public FakeTileTaskWorkerPool {
1863 public: 1859 public:
1864 CancellingTileTaskWorkerPool() {} 1860 explicit FakeTileTaskManager(
1865 ~CancellingTileTaskWorkerPool() override {} 1861 std::unique_ptr<TileTaskWorkerPool> tile_task_worker_pool)
1862 : TileTaskManager(std::move(tile_task_worker_pool)) {}
1863 ~FakeTileTaskManager() override {}
1864 void Shutdown() override {}
1865 void ScheduleTasks(TaskGraph* graph) override {}
1866 void CheckForCompletedTasks() override {}
1867
1868 // Get TileTaskWorkerPool.
1869 TileTaskWorkerPool* GetTileTaskWorkerPool() const override {
1870 return tile_task_worker_pool_.get();
1871 }
1872 };
1873
1874 // Fake TileTaskManager that just cancels all scheduled tasks immediately.
1875 class CancellingTileTaskManager : public FakeTileTaskManager {
1876 public:
1877 CancellingTileTaskManager()
1878 : FakeTileTaskManager(
1879 base::WrapUnique<TileTaskWorkerPool>(new FakeTileTaskWorkerPool)) {}
1880 ~CancellingTileTaskManager() override {}
1866 1881
1867 void ScheduleTasks(TaskGraph* graph) override { 1882 void ScheduleTasks(TaskGraph* graph) override {
1868 // Just call CompleteOnOriginThread on each item in the queue. As none of 1883 // Just call CompleteOnOriginThread on each item in the queue. As none of
1869 // these items have run yet, they will be treated as cancelled tasks. 1884 // these items have run yet, they will be treated as cancelled tasks.
1870 for (const auto& node : graph->nodes) { 1885 for (const auto& node : graph->nodes) {
1871 static_cast<TileTask*>(node.task)->CompleteOnOriginThread(this); 1886 static_cast<TileTask*>(node.task)->CompleteOnOriginThread(
1887 tile_task_worker_pool_->AsRasterBufferProvider());
1872 } 1888 }
1873 } 1889 }
1874 }; 1890 };
1875 1891
1876 class PartialRasterTileManagerTest : public TileManagerTest { 1892 class PartialRasterTileManagerTest : public TileManagerTest {
1877 public: 1893 public:
1878 void CustomizeSettings(LayerTreeSettings* settings) override { 1894 void CustomizeSettings(LayerTreeSettings* settings) override {
1879 settings->use_partial_raster = true; 1895 settings->use_partial_raster = true;
1880 } 1896 }
1881 }; 1897 };
1882 1898
1883 // Ensures that if a raster task is cancelled, it gets returned to the resource 1899 // Ensures that if a raster task is cancelled, it gets returned to the resource
1884 // pool with an invalid content ID, not with its invalidated content ID. 1900 // pool with an invalid content ID, not with its invalidated content ID.
1885 TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) { 1901 TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) {
1886 // Create a CancellingTaskRunner and set it on the tile manager so that all 1902 // Create a CancellingTaskRunner and set it on the tile manager so that all
1887 // scheduled work is immediately cancelled. 1903 // scheduled work is immediately cancelled.
1888 CancellingTileTaskWorkerPool cancelling_worker_pool; 1904 CancellingTileTaskManager cancelling_task_manager;
1889 host_impl_->tile_manager()->SetTileTaskWorkerPoolForTesting( 1905 host_impl_->tile_manager()->SetTileTaskManagerForTesting(
1890 &cancelling_worker_pool); 1906 &cancelling_task_manager);
1891 1907
1892 // Pick arbitrary IDs - they don't really matter as long as they're constant. 1908 // Pick arbitrary IDs - they don't really matter as long as they're constant.
1893 const int kLayerId = 7; 1909 const int kLayerId = 7;
1894 const uint64_t kInvalidatedId = 43; 1910 const uint64_t kInvalidatedId = 43;
1895 const gfx::Size kTileSize(128, 128); 1911 const gfx::Size kTileSize(128, 128);
1896 1912
1897 scoped_refptr<FakeRasterSource> pending_raster_source = 1913 scoped_refptr<FakeRasterSource> pending_raster_source =
1898 FakeRasterSource::CreateFilled(kTileSize); 1914 FakeRasterSource::CreateFilled(kTileSize);
1899 host_impl_->CreatePendingTree(); 1915 host_impl_->CreatePendingTree();
1900 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); 1916 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
(...skipping 12 matching lines...) Expand all
1913 // Add tilings/tiles for the layer. 1929 // Add tilings/tiles for the layer.
1914 host_impl_->pending_tree()->BuildPropertyTreesForTesting(); 1930 host_impl_->pending_tree()->BuildPropertyTreesForTesting();
1915 host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */); 1931 host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */);
1916 1932
1917 // Build the raster queue and invalidate the top tile. 1933 // Build the raster queue and invalidate the top tile.
1918 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue( 1934 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue(
1919 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); 1935 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL));
1920 EXPECT_FALSE(queue->IsEmpty()); 1936 EXPECT_FALSE(queue->IsEmpty());
1921 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); 1937 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
1922 1938
1923 // PrepareTiles to schedule tasks. Due to the CancellingTileTaskWorkerPool, 1939 // PrepareTiles to schedule tasks. Due to the CancellingTileTaskManager,
1924 // these 1940 // these tasks will immediately be canceled.
1925 // tasks will immediately be canceled.
1926 host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state()); 1941 host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state());
1927 1942
1928 // Make sure that the tile we invalidated above was not returned to the pool 1943 // Make sure that the tile we invalidated above was not returned to the pool
1929 // with its invalidated resource ID. 1944 // with its invalidated resource ID.
1930 host_impl_->resource_pool()->CheckBusyResources(); 1945 host_impl_->resource_pool()->CheckBusyResources();
1931 EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId( 1946 EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId(
1932 kInvalidatedId)); 1947 kInvalidatedId));
1933 1948
1934 // Free our host_impl_ before the cancelling_worker_pool we passed it, as it 1949 // Free our host_impl_ before the cancelling_task_manager we passed it, as it
1935 // will 1950 // will use that class in clean up.
1936 // use that class in clean up.
1937 host_impl_ = nullptr; 1951 host_impl_ = nullptr;
1938 } 1952 }
1939 1953
1940 // Fake TileTaskWorkerPool that verifies the resource content ID of raster 1954 // FakeTileTaskWorkerPool that verifies the resource content ID of raster
1941 // tasks. 1955 // tasks.
1942 class VerifyResourceContentIdTileTaskWorkerPool 1956 class VerifyResourceContentIdTileTaskWorkerPool
1943 : public FakeTileTaskWorkerPool { 1957 : public FakeTileTaskWorkerPool {
1944 public: 1958 public:
1945 explicit VerifyResourceContentIdTileTaskWorkerPool( 1959 explicit VerifyResourceContentIdTileTaskWorkerPool(
1946 uint64_t expected_resource_id) 1960 uint64_t expected_resource_id)
1947 : expected_resource_id_(expected_resource_id) {} 1961 : expected_resource_id_(expected_resource_id) {}
1948 ~VerifyResourceContentIdTileTaskWorkerPool() override {} 1962 ~VerifyResourceContentIdTileTaskWorkerPool() override {}
1949 1963
1950 void ScheduleTasks(TaskGraph* graph) override {
1951 for (const auto& node : graph->nodes) {
1952 TileTask* task = static_cast<TileTask*>(node.task);
1953 // Triggers a call to AcquireBufferForRaster.
1954 task->ScheduleOnOriginThread(this);
1955 // Calls TileManager as though task was cancelled.
1956 task->CompleteOnOriginThread(this);
1957 }
1958 }
1959
1960 // RasterBufferProvider methods. 1964 // RasterBufferProvider methods.
1961 std::unique_ptr<RasterBuffer> AcquireBufferForRaster( 1965 std::unique_ptr<RasterBuffer> AcquireBufferForRaster(
1962 const Resource* resource, 1966 const Resource* resource,
1963 uint64_t resource_content_id, 1967 uint64_t resource_content_id,
1964 uint64_t previous_content_id) override { 1968 uint64_t previous_content_id) override {
1965 EXPECT_EQ(expected_resource_id_, resource_content_id); 1969 EXPECT_EQ(expected_resource_id_, resource_content_id);
1966 return nullptr; 1970 return nullptr;
1967 } 1971 }
1968 1972
1969 private: 1973 private:
1970 uint64_t expected_resource_id_; 1974 uint64_t expected_resource_id_;
1971 }; 1975 };
1972 1976
1977 class VerifyResourceContentIdTileTaskManager : public FakeTileTaskManager {
1978 public:
1979 explicit VerifyResourceContentIdTileTaskManager(uint64_t expected_resource_id)
1980 : FakeTileTaskManager(base::WrapUnique<TileTaskWorkerPool>(
1981 new VerifyResourceContentIdTileTaskWorkerPool(
1982 expected_resource_id))) {}
1983 ~VerifyResourceContentIdTileTaskManager() override {}
1984
1985 void ScheduleTasks(TaskGraph* graph) override {
1986 for (const auto& node : graph->nodes) {
1987 TileTask* task = static_cast<TileTask*>(node.task);
1988 // Triggers a call to AcquireBufferForRaster.
1989 task->ScheduleOnOriginThread(
1990 tile_task_worker_pool_->AsRasterBufferProvider());
1991 // Calls TileManager as though task was cancelled.
1992 task->CompleteOnOriginThread(
1993 tile_task_worker_pool_->AsRasterBufferProvider());
1994 }
1995 }
1996 };
1997
1973 // Runs a test to ensure that partial raster is either enabled or disabled, 1998 // Runs a test to ensure that partial raster is either enabled or disabled,
1974 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl 1999 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl
1975 // so that cleanup order can be controlled. 2000 // so that cleanup order can be controlled.
1976 void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl, 2001 void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl,
1977 bool partial_raster_enabled) { 2002 bool partial_raster_enabled) {
1978 // Pick arbitrary IDs - they don't really matter as long as they're constant. 2003 // Pick arbitrary IDs - they don't really matter as long as they're constant.
1979 const int kLayerId = 7; 2004 const int kLayerId = 7;
1980 const uint64_t kInvalidatedId = 43; 2005 const uint64_t kInvalidatedId = 43;
1981 const uint64_t kExpectedId = partial_raster_enabled ? kInvalidatedId : 0u; 2006 const uint64_t kExpectedId = partial_raster_enabled ? kInvalidatedId : 0u;
1982 const gfx::Size kTileSize(128, 128); 2007 const gfx::Size kTileSize(128, 128);
1983 2008
1984 // Create a VerifyResourceContentIdTileTaskWorkerPool to ensure that the 2009 // Create a VerifyResourceContentIdTileTaskManager to ensure that the
1985 // raster 2010 // raster task we see is created with |kExpectedId|.
1986 // task we see is created with |kExpectedId|. 2011 VerifyResourceContentIdTileTaskManager verifying_task_manager(kExpectedId);
1987 VerifyResourceContentIdTileTaskWorkerPool verifying_worker_pool(kExpectedId); 2012 host_impl->tile_manager()->SetTileTaskManagerForTesting(
1988 host_impl->tile_manager()->SetTileTaskWorkerPoolForTesting( 2013 &verifying_task_manager);
1989 &verifying_worker_pool);
1990 2014
1991 // Ensure there's a resource with our |kInvalidatedId| in the resource pool. 2015 // Ensure there's a resource with our |kInvalidatedId| in the resource pool.
1992 host_impl->resource_pool()->ReleaseResource( 2016 host_impl->resource_pool()->ReleaseResource(
1993 host_impl->resource_pool()->AcquireResource(kTileSize, RGBA_8888), 2017 host_impl->resource_pool()->AcquireResource(kTileSize, RGBA_8888),
1994 kInvalidatedId); 2018 kInvalidatedId);
1995 host_impl->resource_pool()->CheckBusyResources(); 2019 host_impl->resource_pool()->CheckBusyResources();
1996 2020
1997 scoped_refptr<FakeRasterSource> pending_raster_source = 2021 scoped_refptr<FakeRasterSource> pending_raster_source =
1998 FakeRasterSource::CreateFilled(kTileSize); 2022 FakeRasterSource::CreateFilled(kTileSize);
1999 host_impl->CreatePendingTree(); 2023 host_impl->CreatePendingTree();
(...skipping 18 matching lines...) Expand all
2018 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl->BuildRasterQueue( 2042 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl->BuildRasterQueue(
2019 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); 2043 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL));
2020 EXPECT_FALSE(queue->IsEmpty()); 2044 EXPECT_FALSE(queue->IsEmpty());
2021 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); 2045 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
2022 2046
2023 // PrepareTiles to schedule tasks. Due to the 2047 // PrepareTiles to schedule tasks. Due to the
2024 // VerifyPreviousContentTileTaskWorkerPool, these tasks will verified and 2048 // VerifyPreviousContentTileTaskWorkerPool, these tasks will verified and
2025 // cancelled. 2049 // cancelled.
2026 host_impl->tile_manager()->PrepareTiles(host_impl->global_tile_state()); 2050 host_impl->tile_manager()->PrepareTiles(host_impl->global_tile_state());
2027 2051
2028 // Free our host_impl before the cancelling_worker_pool we passed it, as it 2052 // Free our host_impl before the verifying_task_manager we passed it, as it
2029 // will 2053 // will use that class in clean up.
2030 // use that class in clean up.
2031 host_impl = nullptr; 2054 host_impl = nullptr;
2032 } 2055 }
2033 2056
2034 // Ensures that the tile manager successfully reuses tiles when partial 2057 // Ensures that the tile manager successfully reuses tiles when partial
2035 // raster is enabled. 2058 // raster is enabled.
2036 TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) { 2059 TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) {
2037 RunPartialRasterCheck(std::move(host_impl_), 2060 RunPartialRasterCheck(std::move(host_impl_),
2038 true /* partial_raster_enabled */); 2061 true /* partial_raster_enabled */);
2039 } 2062 }
2040 2063
2041 // Ensures that the tile manager does not attempt to reuse tiles when partial 2064 // Ensures that the tile manager does not attempt to reuse tiles when partial
2042 // raster is disabled. 2065 // raster is disabled.
2043 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) { 2066 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) {
2044 RunPartialRasterCheck(std::move(host_impl_), 2067 RunPartialRasterCheck(std::move(host_impl_),
2045 false /* partial_raster_enabled */); 2068 false /* partial_raster_enabled */);
2046 } 2069 }
2047 2070
2048 } // namespace 2071 } // namespace
2049 } // namespace cc 2072 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698