| 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/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 // The first task to run should be ReadyToDraw (this should not be blocked by | 1712 // The first task to run should be ReadyToDraw (this should not be blocked by |
| 1713 // the tasks required for activation). | 1713 // the tasks required for activation). |
| 1714 base::RunLoop run_loop; | 1714 base::RunLoop run_loop; |
| 1715 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw()) | 1715 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw()) |
| 1716 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); })); | 1716 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); })); |
| 1717 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner()) | 1717 static_cast<SynchronousTaskGraphRunner*>(task_graph_runner()) |
| 1718 ->RunSingleTaskForTesting(); | 1718 ->RunSingleTaskForTesting(); |
| 1719 run_loop.Run(); | 1719 run_loop.Run(); |
| 1720 } | 1720 } |
| 1721 | 1721 |
| 1722 // Fake TileTaskManager that just cancels all scheduled tasks immediately. | |
| 1723 class CancellingTileTaskManager : public FakeTileTaskManagerImpl { | |
| 1724 public: | |
| 1725 CancellingTileTaskManager() {} | |
| 1726 ~CancellingTileTaskManager() override {} | |
| 1727 | |
| 1728 void ScheduleTasks(TaskGraph* graph) override { | |
| 1729 // Just call CompleteOnOriginThread on each item in the queue. As none of | |
| 1730 // these items have run yet, they will be treated as cancelled tasks. | |
| 1731 for (const auto& node : graph->nodes) { | |
| 1732 static_cast<TileTask*>(node.task)->CompleteOnOriginThread( | |
| 1733 raster_buffer_provider_.get()); | |
| 1734 } | |
| 1735 } | |
| 1736 void CheckForCompletedTasks() override {} | |
| 1737 }; | |
| 1738 | |
| 1739 class PartialRasterTileManagerTest : public TileManagerTest { | 1722 class PartialRasterTileManagerTest : public TileManagerTest { |
| 1740 public: | 1723 public: |
| 1741 LayerTreeSettings CreateSettings() override { | 1724 LayerTreeSettings CreateSettings() override { |
| 1742 LayerTreeSettings settings = TileManagerTest::CreateSettings(); | 1725 LayerTreeSettings settings = TileManagerTest::CreateSettings(); |
| 1743 settings.use_partial_raster = true; | 1726 settings.use_partial_raster = true; |
| 1744 return settings; | 1727 return settings; |
| 1745 } | 1728 } |
| 1746 }; | 1729 }; |
| 1747 | 1730 |
| 1748 // Ensures that if a raster task is cancelled, it gets returned to the resource | 1731 // Ensures that if a raster task is cancelled, it gets returned to the resource |
| 1749 // pool with an invalid content ID, not with its invalidated content ID. | 1732 // pool with an invalid content ID, not with its invalidated content ID. |
| 1750 TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) { | 1733 TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) { |
| 1751 // Create a CancellingTaskRunner and set it on the tile manager so that all | 1734 // Create a FakeTileTaskManagerImpl and set it on the tile manager so that all |
| 1752 // scheduled work is immediately cancelled. | 1735 // scheduled work is immediately cancelled. |
| 1753 CancellingTileTaskManager cancelling_task_manager; | 1736 |
| 1754 host_impl()->tile_manager()->SetTileTaskManagerForTesting( | 1737 FakeTileTaskManagerImpl tile_task_manager; |
| 1755 &cancelling_task_manager); | 1738 host_impl()->tile_manager()->SetTileTaskManagerForTesting(&tile_task_manager); |
| 1756 | 1739 |
| 1757 // Pick arbitrary IDs - they don't really matter as long as they're constant. | 1740 // Pick arbitrary IDs - they don't really matter as long as they're constant. |
| 1758 const int kLayerId = 7; | 1741 const int kLayerId = 7; |
| 1759 const uint64_t kInvalidatedId = 43; | 1742 const uint64_t kInvalidatedId = 43; |
| 1760 const gfx::Size kTileSize(128, 128); | 1743 const gfx::Size kTileSize(128, 128); |
| 1761 | 1744 |
| 1762 scoped_refptr<FakeRasterSource> pending_raster_source = | 1745 scoped_refptr<FakeRasterSource> pending_raster_source = |
| 1763 FakeRasterSource::CreateFilled(kTileSize); | 1746 FakeRasterSource::CreateFilled(kTileSize); |
| 1764 host_impl()->CreatePendingTree(); | 1747 host_impl()->CreatePendingTree(); |
| 1765 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); | 1748 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1779 host_impl()->pending_tree()->BuildPropertyTreesForTesting(); | 1762 host_impl()->pending_tree()->BuildPropertyTreesForTesting(); |
| 1780 host_impl()->pending_tree()->UpdateDrawProperties( | 1763 host_impl()->pending_tree()->UpdateDrawProperties( |
| 1781 false /* update_lcd_text */); | 1764 false /* update_lcd_text */); |
| 1782 | 1765 |
| 1783 // Build the raster queue and invalidate the top tile. | 1766 // Build the raster queue and invalidate the top tile. |
| 1784 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl()->BuildRasterQueue( | 1767 std::unique_ptr<RasterTilePriorityQueue> queue(host_impl()->BuildRasterQueue( |
| 1785 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); | 1768 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); |
| 1786 EXPECT_FALSE(queue->IsEmpty()); | 1769 EXPECT_FALSE(queue->IsEmpty()); |
| 1787 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); | 1770 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); |
| 1788 | 1771 |
| 1789 // PrepareTiles to schedule tasks. Due to the CancellingTileTaskManager, | 1772 // PrepareTiles to schedule tasks. Due to the FakeTileTaskManagerImpl, |
| 1790 // these tasks will immediately be canceled. | 1773 // these tasks will immediately be canceled. |
| 1791 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); | 1774 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); |
| 1792 | 1775 |
| 1793 // Make sure that the tile we invalidated above was not returned to the pool | 1776 // Make sure that the tile we invalidated above was not returned to the pool |
| 1794 // with its invalidated resource ID. | 1777 // with its invalidated resource ID. |
| 1795 host_impl()->resource_pool()->CheckBusyResources(); | 1778 host_impl()->resource_pool()->CheckBusyResources(); |
| 1796 EXPECT_FALSE(host_impl()->resource_pool()->TryAcquireResourceWithContentId( | 1779 EXPECT_FALSE(host_impl()->resource_pool()->TryAcquireResourceWithContentId( |
| 1797 kInvalidatedId)); | 1780 kInvalidatedId)); |
| 1798 | 1781 |
| 1799 // Free our host_impl_ before the cancelling_task_manager we passed it, as it | 1782 // Free our host_impl_ before the tile_task_manager we passed it, as it |
| 1800 // will use that class in clean up. | 1783 // will use that class in clean up. |
| 1801 TakeHostImpl(); | 1784 TakeHostImpl(); |
| 1802 } | 1785 } |
| 1803 | 1786 |
| 1804 // FakeRasterBufferProviderImpl that verifies the resource content ID of raster | 1787 // FakeRasterBufferProviderImpl that verifies the resource content ID of raster |
| 1805 // tasks. | 1788 // tasks. |
| 1806 class VerifyResourceContentIdRasterBufferProvider | 1789 class VerifyResourceContentIdRasterBufferProvider |
| 1807 : public FakeRasterBufferProviderImpl { | 1790 : public FakeRasterBufferProviderImpl { |
| 1808 public: | 1791 public: |
| 1809 explicit VerifyResourceContentIdRasterBufferProvider( | 1792 explicit VerifyResourceContentIdRasterBufferProvider( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1824 uint64_t expected_resource_id_; | 1807 uint64_t expected_resource_id_; |
| 1825 }; | 1808 }; |
| 1826 | 1809 |
| 1827 class VerifyResourceContentIdTileTaskManager : public FakeTileTaskManagerImpl { | 1810 class VerifyResourceContentIdTileTaskManager : public FakeTileTaskManagerImpl { |
| 1828 public: | 1811 public: |
| 1829 explicit VerifyResourceContentIdTileTaskManager(uint64_t expected_resource_id) | 1812 explicit VerifyResourceContentIdTileTaskManager(uint64_t expected_resource_id) |
| 1830 : FakeTileTaskManagerImpl(base::WrapUnique<RasterBufferProvider>( | 1813 : FakeTileTaskManagerImpl(base::WrapUnique<RasterBufferProvider>( |
| 1831 new VerifyResourceContentIdRasterBufferProvider( | 1814 new VerifyResourceContentIdRasterBufferProvider( |
| 1832 expected_resource_id))) {} | 1815 expected_resource_id))) {} |
| 1833 ~VerifyResourceContentIdTileTaskManager() override {} | 1816 ~VerifyResourceContentIdTileTaskManager() override {} |
| 1834 | |
| 1835 void ScheduleTasks(TaskGraph* graph) override { | |
| 1836 for (const auto& node : graph->nodes) { | |
| 1837 TileTask* task = static_cast<TileTask*>(node.task); | |
| 1838 // Triggers a call to AcquireBufferForRaster. | |
| 1839 task->ScheduleOnOriginThread(raster_buffer_provider_.get()); | |
| 1840 // Calls TileManager as though task was cancelled. | |
| 1841 task->CompleteOnOriginThread(raster_buffer_provider_.get()); | |
| 1842 } | |
| 1843 } | |
| 1844 void CheckForCompletedTasks() override {} | |
| 1845 }; | 1817 }; |
| 1846 | 1818 |
| 1847 // Runs a test to ensure that partial raster is either enabled or disabled, | 1819 // Runs a test to ensure that partial raster is either enabled or disabled, |
| 1848 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl | 1820 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl |
| 1849 // so that cleanup order can be controlled. | 1821 // so that cleanup order can be controlled. |
| 1850 void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl, | 1822 void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl, |
| 1851 bool partial_raster_enabled) { | 1823 bool partial_raster_enabled) { |
| 1852 // Pick arbitrary IDs - they don't really matter as long as they're constant. | 1824 // Pick arbitrary IDs - they don't really matter as long as they're constant. |
| 1853 const int kLayerId = 7; | 1825 const int kLayerId = 7; |
| 1854 const uint64_t kInvalidatedId = 43; | 1826 const uint64_t kInvalidatedId = 43; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 } | 1882 } |
| 1911 | 1883 |
| 1912 // Ensures that the tile manager does not attempt to reuse tiles when partial | 1884 // Ensures that the tile manager does not attempt to reuse tiles when partial |
| 1913 // raster is disabled. | 1885 // raster is disabled. |
| 1914 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) { | 1886 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) { |
| 1915 RunPartialRasterCheck(TakeHostImpl(), false /* partial_raster_enabled */); | 1887 RunPartialRasterCheck(TakeHostImpl(), false /* partial_raster_enabled */); |
| 1916 } | 1888 } |
| 1917 | 1889 |
| 1918 } // namespace | 1890 } // namespace |
| 1919 } // namespace cc | 1891 } // namespace cc |
| OLD | NEW |