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