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

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

Issue 1888713002: cc: Merge TileTaskRunner to TileTaskWorkerPool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rename_tile_task_client
Patch Set: feedback 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
« no previous file with comments | « cc/tiles/tile_manager_perftest.cc ('k') | cc/trees/layer_tree_host_impl.cc » ('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"
(...skipping 1809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 EXPECT_EQ(HIGH_RESOLUTION, resolutions[i]); 1820 EXPECT_EQ(HIGH_RESOLUTION, resolutions[i]);
1821 // Since it's high res, the bitmap (blue) was drawn, and the 1821 // Since it's high res, the bitmap (blue) was drawn, and the
1822 // background is not visible. 1822 // background is not visible.
1823 ASSERT_EQ(SK_ColorBLUE, bitmap->getColor(x, y)); 1823 ASSERT_EQ(SK_ColorBLUE, bitmap->getColor(x, y));
1824 } 1824 }
1825 } 1825 }
1826 } 1826 }
1827 } 1827 }
1828 } 1828 }
1829 1829
1830 // Fake TileTaskRunner that just no-ops all calls. 1830 // Fake TileTaskWorkerPool that just no-ops all calls.
1831 class FakeTileTaskRunner : public TileTaskRunner, public RasterBufferProvider { 1831 class FakeTileTaskWorkerPool : public TileTaskWorkerPool,
1832 public RasterBufferProvider {
1832 public: 1833 public:
1833 FakeTileTaskRunner() {} 1834 FakeTileTaskWorkerPool() {}
1834 ~FakeTileTaskRunner() override {} 1835 ~FakeTileTaskWorkerPool() override {}
1835 1836
1836 // TileTaskRunner methods. 1837 // TileTaskWorkerPool methods.
1837 void Shutdown() override {} 1838 void Shutdown() override {}
1838 void CheckForCompletedTasks() override {} 1839 void CheckForCompletedTasks() override {}
1839 ResourceFormat GetResourceFormat(bool must_support_alpha) const override { 1840 ResourceFormat GetResourceFormat(bool must_support_alpha) const override {
1840 return ResourceFormat::RGBA_8888; 1841 return ResourceFormat::RGBA_8888;
1841 } 1842 }
1842 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override { 1843 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override {
1843 return false; 1844 return false;
1844 } 1845 }
1845 RasterBufferProvider* AsRasterBufferProvider() override { return this; } 1846 RasterBufferProvider* AsRasterBufferProvider() override { return this; }
1846 1847
1847 void ScheduleTasks(TaskGraph* graph) override {} 1848 void ScheduleTasks(TaskGraph* graph) override {}
1848 1849
1849 // RasterBufferProvider methods. 1850 // RasterBufferProvider methods.
1850 std::unique_ptr<RasterBuffer> AcquireBufferForRaster( 1851 std::unique_ptr<RasterBuffer> AcquireBufferForRaster(
1851 const Resource* resource, 1852 const Resource* resource,
1852 uint64_t resource_content_id, 1853 uint64_t resource_content_id,
1853 uint64_t previous_content_id) override { 1854 uint64_t previous_content_id) override {
1854 NOTREACHED(); 1855 NOTREACHED();
1855 return nullptr; 1856 return nullptr;
1856 } 1857 }
1857 void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) override {} 1858 void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) override {}
1858 }; 1859 };
1859 1860
1860 // Fake TileTaskRunner that just cancels all scheduled tasks immediately. 1861 // Fake TileTaskWorkerPool that just cancels all scheduled tasks immediately.
1861 class CancellingTileTaskRunner : public FakeTileTaskRunner { 1862 class CancellingTileTaskWorkerPool : public FakeTileTaskWorkerPool {
1862 public: 1863 public:
1863 CancellingTileTaskRunner() {} 1864 CancellingTileTaskWorkerPool() {}
1864 ~CancellingTileTaskRunner() override {} 1865 ~CancellingTileTaskWorkerPool() override {}
1865 1866
1866 void ScheduleTasks(TaskGraph* graph) override { 1867 void ScheduleTasks(TaskGraph* graph) override {
1867 // Just call CompleteOnOriginThread on each item in the queue. As none of 1868 // Just call CompleteOnOriginThread on each item in the queue. As none of
1868 // these items have run yet, they will be treated as cancelled tasks. 1869 // these items have run yet, they will be treated as cancelled tasks.
1869 for (const auto& node : graph->nodes) { 1870 for (const auto& node : graph->nodes) {
1870 static_cast<TileTask*>(node.task)->CompleteOnOriginThread(this); 1871 static_cast<TileTask*>(node.task)->CompleteOnOriginThread(this);
1871 } 1872 }
1872 } 1873 }
1873 }; 1874 };
1874 1875
1875 class PartialRasterTileManagerTest : public TileManagerTest { 1876 class PartialRasterTileManagerTest : public TileManagerTest {
1876 public: 1877 public:
1877 void CustomizeSettings(LayerTreeSettings* settings) override { 1878 void CustomizeSettings(LayerTreeSettings* settings) override {
1878 settings->use_partial_raster = true; 1879 settings->use_partial_raster = true;
1879 } 1880 }
1880 }; 1881 };
1881 1882
1882 // Ensures that if a raster task is cancelled, it gets returned to the resource 1883 // Ensures that if a raster task is cancelled, it gets returned to the resource
1883 // pool with an invalid content ID, not with its invalidated content ID. 1884 // pool with an invalid content ID, not with its invalidated content ID.
1884 TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) { 1885 TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) {
1885 // Create a CancellingTaskRunner and set it on the tile manager so that all 1886 // Create a CancellingTaskRunner and set it on the tile manager so that all
1886 // scheduled work is immediately cancelled. 1887 // scheduled work is immediately cancelled.
1887 CancellingTileTaskRunner cancelling_runner; 1888 CancellingTileTaskWorkerPool cancelling_worker_pool;
1888 host_impl_->tile_manager()->SetTileTaskRunnerForTesting(&cancelling_runner); 1889 host_impl_->tile_manager()->SetTileTaskWorkerPoolForTesting(
1890 &cancelling_worker_pool);
1889 1891
1890 // Pick arbitrary IDs - they don't really matter as long as they're constant. 1892 // Pick arbitrary IDs - they don't really matter as long as they're constant.
1891 const int kLayerId = 7; 1893 const int kLayerId = 7;
1892 const uint64_t kInvalidatedId = 43; 1894 const uint64_t kInvalidatedId = 43;
1893 const gfx::Size kTileSize(128, 128); 1895 const gfx::Size kTileSize(128, 128);
1894 1896
1895 scoped_refptr<FakeRasterSource> pending_raster_source = 1897 scoped_refptr<FakeRasterSource> pending_raster_source =
1896 FakeRasterSource::CreateFilled(kTileSize); 1898 FakeRasterSource::CreateFilled(kTileSize);
1897 host_impl_->CreatePendingTree(); 1899 host_impl_->CreatePendingTree();
1898 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); 1900 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
(...skipping 12 matching lines...) Expand all
1911 // Add tilings/tiles for the layer. 1913 // Add tilings/tiles for the layer.
1912 host_impl_->pending_tree()->BuildPropertyTreesForTesting(); 1914 host_impl_->pending_tree()->BuildPropertyTreesForTesting();
1913 host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */); 1915 host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */);
1914 1916
1915 // Build the raster queue and invalidate the top tile. 1917 // Build the raster queue and invalidate the top tile.
1916 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue( 1918 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue(
1917 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); 1919 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL));
1918 EXPECT_FALSE(queue->IsEmpty()); 1920 EXPECT_FALSE(queue->IsEmpty());
1919 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); 1921 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
1920 1922
1921 // PrepareTiles to schedule tasks. Due to the CancellingTileTaskRunner, these 1923 // PrepareTiles to schedule tasks. Due to the CancellingTileTaskWorkerPool,
1924 // these
1922 // tasks will immediately be canceled. 1925 // tasks will immediately be canceled.
1923 host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state()); 1926 host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state());
1924 1927
1925 // Make sure that the tile we invalidated above was not returned to the pool 1928 // Make sure that the tile we invalidated above was not returned to the pool
1926 // with its invalidated resource ID. 1929 // with its invalidated resource ID.
1927 host_impl_->resource_pool()->CheckBusyResources(); 1930 host_impl_->resource_pool()->CheckBusyResources();
1928 EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId( 1931 EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId(
1929 kInvalidatedId)); 1932 kInvalidatedId));
1930 1933
1931 // Free our host_impl_ before the cancelling_runner we passed it, as it will 1934 // Free our host_impl_ before the cancelling_worker_pool we passed it, as it
1935 // will
1932 // use that class in clean up. 1936 // use that class in clean up.
1933 host_impl_ = nullptr; 1937 host_impl_ = nullptr;
1934 } 1938 }
1935 1939
1936 // Fake TileTaskRunner that verifies the resource content ID of raster tasks. 1940 // Fake TileTaskWorkerPool that verifies the resource content ID of raster
1937 class VerifyResourceContentIdTileTaskRunner : public FakeTileTaskRunner { 1941 // tasks.
1942 class VerifyResourceContentIdTileTaskWorkerPool
1943 : public FakeTileTaskWorkerPool {
1938 public: 1944 public:
1939 explicit VerifyResourceContentIdTileTaskRunner(uint64_t expected_resource_id) 1945 explicit VerifyResourceContentIdTileTaskWorkerPool(
1946 uint64_t expected_resource_id)
1940 : expected_resource_id_(expected_resource_id) {} 1947 : expected_resource_id_(expected_resource_id) {}
1941 ~VerifyResourceContentIdTileTaskRunner() override {} 1948 ~VerifyResourceContentIdTileTaskWorkerPool() override {}
1942 1949
1943 void ScheduleTasks(TaskGraph* graph) override { 1950 void ScheduleTasks(TaskGraph* graph) override {
1944 for (const auto& node : graph->nodes) { 1951 for (const auto& node : graph->nodes) {
1945 TileTask* task = static_cast<TileTask*>(node.task); 1952 TileTask* task = static_cast<TileTask*>(node.task);
1946 // Triggers a call to AcquireBufferForRaster. 1953 // Triggers a call to AcquireBufferForRaster.
1947 task->ScheduleOnOriginThread(this); 1954 task->ScheduleOnOriginThread(this);
1948 // Calls TileManager as though task was cancelled. 1955 // Calls TileManager as though task was cancelled.
1949 task->CompleteOnOriginThread(this); 1956 task->CompleteOnOriginThread(this);
1950 } 1957 }
1951 } 1958 }
(...skipping 15 matching lines...) Expand all
1967 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl 1974 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl
1968 // so that cleanup order can be controlled. 1975 // so that cleanup order can be controlled.
1969 void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl, 1976 void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl,
1970 bool partial_raster_enabled) { 1977 bool partial_raster_enabled) {
1971 // Pick arbitrary IDs - they don't really matter as long as they're constant. 1978 // Pick arbitrary IDs - they don't really matter as long as they're constant.
1972 const int kLayerId = 7; 1979 const int kLayerId = 7;
1973 const uint64_t kInvalidatedId = 43; 1980 const uint64_t kInvalidatedId = 43;
1974 const uint64_t kExpectedId = partial_raster_enabled ? kInvalidatedId : 0u; 1981 const uint64_t kExpectedId = partial_raster_enabled ? kInvalidatedId : 0u;
1975 const gfx::Size kTileSize(128, 128); 1982 const gfx::Size kTileSize(128, 128);
1976 1983
1977 // Create a VerifyResourceContentIdTileTaskRunner to ensure that the raster 1984 // Create a VerifyResourceContentIdTileTaskWorkerPool to ensure that the
1985 // raster
1978 // task we see is created with |kExpectedId|. 1986 // task we see is created with |kExpectedId|.
1979 VerifyResourceContentIdTileTaskRunner verifying_runner(kExpectedId); 1987 VerifyResourceContentIdTileTaskWorkerPool verifying_worker_pool(kExpectedId);
1980 host_impl->tile_manager()->SetTileTaskRunnerForTesting(&verifying_runner); 1988 host_impl->tile_manager()->SetTileTaskWorkerPoolForTesting(
1989 &verifying_worker_pool);
1981 1990
1982 // Ensure there's a resource with our |kInvalidatedId| in the resource pool. 1991 // Ensure there's a resource with our |kInvalidatedId| in the resource pool.
1983 host_impl->resource_pool()->ReleaseResource( 1992 host_impl->resource_pool()->ReleaseResource(
1984 host_impl->resource_pool()->AcquireResource(kTileSize, RGBA_8888), 1993 host_impl->resource_pool()->AcquireResource(kTileSize, RGBA_8888),
1985 kInvalidatedId); 1994 kInvalidatedId);
1986 host_impl->resource_pool()->CheckBusyResources(); 1995 host_impl->resource_pool()->CheckBusyResources();
1987 1996
1988 scoped_refptr<FakeRasterSource> pending_raster_source = 1997 scoped_refptr<FakeRasterSource> pending_raster_source =
1989 FakeRasterSource::CreateFilled(kTileSize); 1998 FakeRasterSource::CreateFilled(kTileSize);
1990 host_impl->CreatePendingTree(); 1999 host_impl->CreatePendingTree();
(...skipping 14 matching lines...) Expand all
2005 host_impl->pending_tree()->BuildPropertyTreesForTesting(); 2014 host_impl->pending_tree()->BuildPropertyTreesForTesting();
2006 host_impl->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */); 2015 host_impl->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */);
2007 2016
2008 // Build the raster queue and invalidate the top tile. 2017 // Build the raster queue and invalidate the top tile.
2009 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl->BuildRasterQueue( 2018 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl->BuildRasterQueue(
2010 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); 2019 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL));
2011 EXPECT_FALSE(queue->IsEmpty()); 2020 EXPECT_FALSE(queue->IsEmpty());
2012 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); 2021 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
2013 2022
2014 // PrepareTiles to schedule tasks. Due to the 2023 // PrepareTiles to schedule tasks. Due to the
2015 // VerifyPreviousContentTileTaskRunner, these tasks will verified and 2024 // VerifyPreviousContentTileTaskWorkerPool, these tasks will verified and
2016 // cancelled. 2025 // cancelled.
2017 host_impl->tile_manager()->PrepareTiles(host_impl->global_tile_state()); 2026 host_impl->tile_manager()->PrepareTiles(host_impl->global_tile_state());
2018 2027
2019 // Free our host_impl before the cancelling_runner we passed it, as it will 2028 // Free our host_impl before the cancelling_worker_pool we passed it, as it
2029 // will
2020 // use that class in clean up. 2030 // use that class in clean up.
2021 host_impl = nullptr; 2031 host_impl = nullptr;
2022 } 2032 }
2023 2033
2024 // Ensures that the tile manager successfully reuses tiles when partial 2034 // Ensures that the tile manager successfully reuses tiles when partial
2025 // raster is enabled. 2035 // raster is enabled.
2026 TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) { 2036 TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) {
2027 RunPartialRasterCheck(std::move(host_impl_), 2037 RunPartialRasterCheck(std::move(host_impl_),
2028 true /* partial_raster_enabled */); 2038 true /* partial_raster_enabled */);
2029 } 2039 }
2030 2040
2031 // Ensures that the tile manager does not attempt to reuse tiles when partial 2041 // Ensures that the tile manager does not attempt to reuse tiles when partial
2032 // raster is disabled. 2042 // raster is disabled.
2033 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) { 2043 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) {
2034 RunPartialRasterCheck(std::move(host_impl_), 2044 RunPartialRasterCheck(std::move(host_impl_),
2035 false /* partial_raster_enabled */); 2045 false /* partial_raster_enabled */);
2036 } 2046 }
2037 2047
2038 } // namespace 2048 } // namespace
2039 } // namespace cc 2049 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/tile_manager_perftest.cc ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698