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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
6 #include "base/thread_task_runner_handle.h" | 6 #include "base/thread_task_runner_handle.h" |
7 #include "cc/playback/display_list_raster_source.h" | 7 #include "cc/playback/display_list_raster_source.h" |
8 #include "cc/playback/display_list_recording_source.h" | 8 #include "cc/playback/display_list_recording_source.h" |
9 #include "cc/raster/raster_buffer.h" | 9 #include "cc/raster/raster_buffer.h" |
10 #include "cc/resources/resource_pool.h" | 10 #include "cc/resources/resource_pool.h" |
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 scoped_ptr<TilingSetRasterQueueAll> queue( | 1445 scoped_ptr<TilingSetRasterQueueAll> queue( |
1446 new TilingSetRasterQueueAll(tiling_set.get(), false)); | 1446 new TilingSetRasterQueueAll(tiling_set.get(), false)); |
1447 EXPECT_FALSE(queue->IsEmpty()); | 1447 EXPECT_FALSE(queue->IsEmpty()); |
1448 } | 1448 } |
1449 } | 1449 } |
1450 | 1450 |
1451 class TileManagerTest : public testing::Test { | 1451 class TileManagerTest : public testing::Test { |
1452 public: | 1452 public: |
1453 TileManagerTest() | 1453 TileManagerTest() |
1454 : output_surface_(FakeOutputSurface::CreateSoftware( | 1454 : output_surface_(FakeOutputSurface::CreateSoftware( |
1455 make_scoped_ptr(new SoftwareOutputDevice))), | 1455 make_scoped_ptr(new SoftwareOutputDevice))) {} |
1456 host_impl_(new MockLayerTreeHostImpl(&proxy_, | 1456 |
1457 &shared_bitmap_manager_, | 1457 void SetUp() override { |
1458 &task_graph_runner_)) { | 1458 LayerTreeSettings settings; |
| 1459 CustomizeSettings(&settings); |
| 1460 host_impl_.reset(new MockLayerTreeHostImpl( |
| 1461 settings, &proxy_, &shared_bitmap_manager_, &task_graph_runner_)); |
1459 host_impl_->SetVisible(true); | 1462 host_impl_->SetVisible(true); |
1460 host_impl_->InitializeRenderer(output_surface_.get()); | 1463 host_impl_->InitializeRenderer(output_surface_.get()); |
1461 } | 1464 } |
1462 | 1465 |
1463 protected: | 1466 protected: |
1464 // MockLayerTreeHostImpl allows us to intercept tile manager callbacks. | 1467 // MockLayerTreeHostImpl allows us to intercept tile manager callbacks. |
1465 class MockLayerTreeHostImpl : public FakeLayerTreeHostImpl { | 1468 class MockLayerTreeHostImpl : public FakeLayerTreeHostImpl { |
1466 public: | 1469 public: |
1467 MockLayerTreeHostImpl(Proxy* proxy, | 1470 MockLayerTreeHostImpl(const LayerTreeSettings& settings, |
| 1471 Proxy* proxy, |
1468 SharedBitmapManager* manager, | 1472 SharedBitmapManager* manager, |
1469 TaskGraphRunner* task_graph_runner) | 1473 TaskGraphRunner* task_graph_runner) |
1470 : FakeLayerTreeHostImpl(proxy, manager, task_graph_runner) {} | 1474 : FakeLayerTreeHostImpl(settings, proxy, manager, task_graph_runner) {} |
1471 | 1475 |
1472 MOCK_METHOD0(NotifyAllTileTasksCompleted, void()); | 1476 MOCK_METHOD0(NotifyAllTileTasksCompleted, void()); |
1473 }; | 1477 }; |
1474 | 1478 |
| 1479 // By default do no customization. |
| 1480 virtual void CustomizeSettings(LayerTreeSettings* settings) {} |
| 1481 |
1475 TestSharedBitmapManager shared_bitmap_manager_; | 1482 TestSharedBitmapManager shared_bitmap_manager_; |
1476 TestTaskGraphRunner task_graph_runner_; | 1483 TestTaskGraphRunner task_graph_runner_; |
1477 FakeImplProxy proxy_; | 1484 FakeImplProxy proxy_; |
1478 scoped_ptr<OutputSurface> output_surface_; | 1485 scoped_ptr<OutputSurface> output_surface_; |
1479 scoped_ptr<MockLayerTreeHostImpl> host_impl_; | 1486 scoped_ptr<MockLayerTreeHostImpl> host_impl_; |
1480 }; | 1487 }; |
1481 | 1488 |
1482 // Test to ensure that we call NotifyAllTileTasksCompleted when PrepareTiles is | 1489 // Test to ensure that we call NotifyAllTileTasksCompleted when PrepareTiles is |
1483 // called. | 1490 // called. |
1484 TEST_F(TileManagerTest, AllWorkFinishedTest) { | 1491 TEST_F(TileManagerTest, AllWorkFinishedTest) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 EXPECT_EQ(HIGH_RESOLUTION, resolutions[i]); | 1592 EXPECT_EQ(HIGH_RESOLUTION, resolutions[i]); |
1586 // Since it's high res, the bitmap (blue) was drawn, and the | 1593 // Since it's high res, the bitmap (blue) was drawn, and the |
1587 // background is not visible. | 1594 // background is not visible. |
1588 ASSERT_EQ(SK_ColorBLUE, bitmap->getColor(x, y)); | 1595 ASSERT_EQ(SK_ColorBLUE, bitmap->getColor(x, y)); |
1589 } | 1596 } |
1590 } | 1597 } |
1591 } | 1598 } |
1592 } | 1599 } |
1593 } | 1600 } |
1594 | 1601 |
1595 // Fake TileTaskRunner that just cancels all scheduled tasks immediately. | 1602 // Fake TileTaskRunner that just no-ops all calls. |
1596 class CancellingTileTaskRunner : public TileTaskRunner, public TileTaskClient { | 1603 class FakeTileTaskRunner : public TileTaskRunner, public TileTaskClient { |
1597 public: | 1604 public: |
1598 CancellingTileTaskRunner() {} | 1605 FakeTileTaskRunner() {} |
| 1606 ~FakeTileTaskRunner() override {} |
1599 | 1607 |
1600 // TileTaskRunner methods. | 1608 // TileTaskRunner methods. |
1601 void SetClient(TileTaskRunnerClient* client) override {} | 1609 void SetClient(TileTaskRunnerClient* client) override {} |
1602 void Shutdown() override {} | 1610 void Shutdown() override {} |
1603 void CheckForCompletedTasks() override {} | 1611 void CheckForCompletedTasks() override {} |
1604 ResourceFormat GetResourceFormat(bool must_support_alpha) const override { | 1612 ResourceFormat GetResourceFormat(bool must_support_alpha) const override { |
1605 return ResourceFormat::RGBA_8888; | 1613 return ResourceFormat::RGBA_8888; |
1606 } | 1614 } |
1607 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override { | 1615 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override { |
1608 return false; | 1616 return false; |
1609 } | 1617 } |
1610 | 1618 |
1611 void ScheduleTasks(TileTaskQueue* queue) override { | 1619 void ScheduleTasks(TileTaskQueue* queue) override {} |
1612 // Just call CompleteOnOriginThread on each item in the queue. As none of | |
1613 // these items have run yet, they will be treated as cancelled tasks. | |
1614 for (const auto& task : queue->items) { | |
1615 task.task->CompleteOnOriginThread(this); | |
1616 } | |
1617 } | |
1618 | 1620 |
1619 // TileTaskClient methods. | 1621 // TileTaskClient methods. |
1620 scoped_ptr<RasterBuffer> AcquireBufferForRaster( | 1622 scoped_ptr<RasterBuffer> AcquireBufferForRaster( |
1621 const Resource* resource, | 1623 const Resource* resource, |
1622 uint64_t resource_content_id, | 1624 uint64_t resource_content_id, |
1623 uint64_t previous_content_id) override { | 1625 uint64_t previous_content_id) override { |
1624 NOTREACHED(); | 1626 NOTREACHED(); |
1625 return nullptr; | 1627 return nullptr; |
1626 } | 1628 } |
1627 void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override {} | 1629 void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override {} |
| 1630 }; |
1628 | 1631 |
| 1632 // Fake TileTaskRunner that just cancels all scheduled tasks immediately. |
| 1633 class CancellingTileTaskRunner : public FakeTileTaskRunner { |
| 1634 public: |
| 1635 CancellingTileTaskRunner() {} |
1629 ~CancellingTileTaskRunner() override {} | 1636 ~CancellingTileTaskRunner() override {} |
| 1637 |
| 1638 void ScheduleTasks(TileTaskQueue* queue) override { |
| 1639 // Just call CompleteOnOriginThread on each item in the queue. As none of |
| 1640 // these items have run yet, they will be treated as cancelled tasks. |
| 1641 for (const auto& task : queue->items) { |
| 1642 task.task->CompleteOnOriginThread(this); |
| 1643 } |
| 1644 } |
| 1645 }; |
| 1646 |
| 1647 class PartialRasterTileManagerTest : public TileManagerTest { |
| 1648 public: |
| 1649 void CustomizeSettings(LayerTreeSettings* settings) override { |
| 1650 settings->use_partial_raster = true; |
| 1651 } |
1630 }; | 1652 }; |
1631 | 1653 |
1632 // Ensures that if a raster task is cancelled, it gets returned to the resource | 1654 // Ensures that if a raster task is cancelled, it gets returned to the resource |
1633 // pool with an invalid content ID, not with its invalidated content ID. | 1655 // pool with an invalid content ID, not with its invalidated content ID. |
1634 TEST_F(TileManagerTest, CancelledTasksHaveNoContentId) { | 1656 TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) { |
1635 // Create a CancellingTaskRunner and set it on the tile manager so that all | 1657 // Create a CancellingTaskRunner and set it on the tile manager so that all |
1636 // scheduled work is immediately cancelled. | 1658 // scheduled work is immediately cancelled. |
1637 CancellingTileTaskRunner cancelling_runner; | 1659 CancellingTileTaskRunner cancelling_runner; |
1638 host_impl_->tile_manager()->SetTileTaskRunnerForTesting(&cancelling_runner); | 1660 host_impl_->tile_manager()->SetTileTaskRunnerForTesting(&cancelling_runner); |
1639 | 1661 |
1640 // Pick arbitrary IDs - they don't really matter as long as they're constant. | 1662 // Pick arbitrary IDs - they don't really matter as long as they're constant. |
1641 int layer_id = 7; | 1663 const int kLayerId = 7; |
1642 int invalidated_id = 43; | 1664 const uint64_t kInvalidatedId = 43; |
| 1665 const gfx::Size kTileSize(128, 128); |
1643 | 1666 |
1644 scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = | 1667 scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = |
1645 FakeDisplayListRasterSource::CreateFilled(gfx::Size(128, 128)); | 1668 FakeDisplayListRasterSource::CreateFilled(kTileSize); |
1646 host_impl_->CreatePendingTree(); | 1669 host_impl_->CreatePendingTree(); |
1647 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); | 1670 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
1648 | 1671 |
1649 // Steal from the recycled tree. | 1672 // Steal from the recycled tree. |
1650 scoped_ptr<FakePictureLayerImpl> pending_layer = | 1673 scoped_ptr<FakePictureLayerImpl> pending_layer = |
1651 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id, | 1674 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, kLayerId, |
1652 pending_raster_source); | 1675 pending_raster_source); |
1653 pending_layer->SetDrawsContent(true); | 1676 pending_layer->SetDrawsContent(true); |
1654 pending_layer->SetHasRenderSurface(true); | 1677 pending_layer->SetHasRenderSurface(true); |
1655 | 1678 |
1656 // The bounds() just mirror the raster source size. | 1679 // The bounds() just mirror the raster source size. |
1657 pending_layer->SetBounds(pending_layer->raster_source()->GetSize()); | 1680 pending_layer->SetBounds(pending_layer->raster_source()->GetSize()); |
1658 pending_tree->SetRootLayer(pending_layer.Pass()); | 1681 pending_tree->SetRootLayer(pending_layer.Pass()); |
1659 | 1682 |
1660 // Add tilings/tiles for the layer. | 1683 // Add tilings/tiles for the layer. |
1661 host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */); | 1684 host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */); |
1662 | 1685 |
1663 // Build the raster queue and invalidate the top tile. | 1686 // Build the raster queue and invalidate the top tile. |
1664 scoped_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue( | 1687 scoped_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue( |
1665 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); | 1688 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); |
1666 EXPECT_FALSE(queue->IsEmpty()); | 1689 EXPECT_FALSE(queue->IsEmpty()); |
1667 queue->Top().tile()->SetInvalidated(gfx::Rect(), invalidated_id); | 1690 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); |
1668 | 1691 |
1669 // PrepareTiles to schedule tasks. Due to the CancellingTileTaskRunner, these | 1692 // PrepareTiles to schedule tasks. Due to the CancellingTileTaskRunner, these |
1670 // tasks will immediately be canceled. | 1693 // tasks will immediately be canceled. |
1671 host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state()); | 1694 host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state()); |
1672 | 1695 |
1673 // Make sure that the tile we invalidated above was not returned to the pool | 1696 // Make sure that the tile we invalidated above was not returned to the pool |
1674 // with its invalidated resource ID. | 1697 // with its invalidated resource ID. |
1675 host_impl_->resource_pool()->CheckBusyResources(); | 1698 host_impl_->resource_pool()->CheckBusyResources(); |
1676 EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId( | 1699 EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId( |
1677 invalidated_id)); | 1700 kInvalidatedId)); |
1678 | 1701 |
1679 // Free our host_impl_ before the cancelling_runner we passed it, as it will | 1702 // Free our host_impl_ before the cancelling_runner we passed it, as it will |
1680 // use that class in clean up. | 1703 // use that class in clean up. |
1681 host_impl_ = nullptr; | 1704 host_impl_ = nullptr; |
1682 } | 1705 } |
1683 | 1706 |
| 1707 // Fake TileTaskRunner that verifies the resource content ID of raster tasks. |
| 1708 class VerifyResourceContentIdTileTaskRunner : public FakeTileTaskRunner { |
| 1709 public: |
| 1710 explicit VerifyResourceContentIdTileTaskRunner(uint64_t expected_resource_id) |
| 1711 : expected_resource_id_(expected_resource_id) {} |
| 1712 ~VerifyResourceContentIdTileTaskRunner() override {} |
| 1713 |
| 1714 void ScheduleTasks(TileTaskQueue* queue) override { |
| 1715 for (const auto& task : queue->items) { |
| 1716 // Triggers a call to AcquireBufferForRaster. |
| 1717 task.task->ScheduleOnOriginThread(this); |
| 1718 // Calls TileManager as though task was cancelled. |
| 1719 task.task->CompleteOnOriginThread(this); |
| 1720 } |
| 1721 } |
| 1722 |
| 1723 // TileTaskClient methods. |
| 1724 scoped_ptr<RasterBuffer> AcquireBufferForRaster( |
| 1725 const Resource* resource, |
| 1726 uint64_t resource_content_id, |
| 1727 uint64_t previous_content_id) override { |
| 1728 EXPECT_EQ(expected_resource_id_, resource_content_id); |
| 1729 return nullptr; |
| 1730 } |
| 1731 |
| 1732 private: |
| 1733 uint64_t expected_resource_id_; |
| 1734 }; |
| 1735 |
| 1736 // Runs a test to ensure that partial raster is either enabled or disabled, |
| 1737 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl |
| 1738 // so that cleanup order can be controlled. |
| 1739 void RunPartialRasterCheck(scoped_ptr<LayerTreeHostImpl> host_impl, |
| 1740 bool partial_raster_enabled) { |
| 1741 // Pick arbitrary IDs - they don't really matter as long as they're constant. |
| 1742 const int kLayerId = 7; |
| 1743 const uint64_t kInvalidatedId = 43; |
| 1744 const uint64_t kExpectedId = partial_raster_enabled ? kInvalidatedId : 0u; |
| 1745 const gfx::Size kTileSize(128, 128); |
| 1746 |
| 1747 // Create a VerifyResourceContentIdTileTaskRunner to ensure that the raster |
| 1748 // task we see is created with |kExpectedId|. |
| 1749 VerifyResourceContentIdTileTaskRunner verifying_runner(kExpectedId); |
| 1750 host_impl->tile_manager()->SetTileTaskRunnerForTesting(&verifying_runner); |
| 1751 |
| 1752 // Ensure there's a resource with our |kInvalidatedId| in the resource pool. |
| 1753 host_impl->resource_pool()->ReleaseResource( |
| 1754 host_impl->resource_pool()->AcquireResource(kTileSize, RGBA_8888), |
| 1755 kInvalidatedId); |
| 1756 host_impl->resource_pool()->CheckBusyResources(); |
| 1757 |
| 1758 scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = |
| 1759 FakeDisplayListRasterSource::CreateFilled(kTileSize); |
| 1760 host_impl->CreatePendingTree(); |
| 1761 LayerTreeImpl* pending_tree = host_impl->pending_tree(); |
| 1762 |
| 1763 // Steal from the recycled tree. |
| 1764 scoped_ptr<FakePictureLayerImpl> pending_layer = |
| 1765 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, kLayerId, |
| 1766 pending_raster_source); |
| 1767 pending_layer->SetDrawsContent(true); |
| 1768 pending_layer->SetHasRenderSurface(true); |
| 1769 |
| 1770 // The bounds() just mirror the raster source size. |
| 1771 pending_layer->SetBounds(pending_layer->raster_source()->GetSize()); |
| 1772 pending_tree->SetRootLayer(pending_layer.Pass()); |
| 1773 |
| 1774 // Add tilings/tiles for the layer. |
| 1775 host_impl->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */); |
| 1776 |
| 1777 // Build the raster queue and invalidate the top tile. |
| 1778 scoped_ptr<RasterTilePriorityQueue> queue(host_impl->BuildRasterQueue( |
| 1779 SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL)); |
| 1780 EXPECT_FALSE(queue->IsEmpty()); |
| 1781 queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId); |
| 1782 |
| 1783 // PrepareTiles to schedule tasks. Due to the |
| 1784 // VerifyPreviousContentTileTaskRunner, these tasks will verified and |
| 1785 // cancelled. |
| 1786 host_impl->tile_manager()->PrepareTiles(host_impl->global_tile_state()); |
| 1787 |
| 1788 // Free our host_impl before the cancelling_runner we passed it, as it will |
| 1789 // use that class in clean up. |
| 1790 host_impl = nullptr; |
| 1791 } |
| 1792 |
| 1793 // Ensures that the tile manager successfully reuses tiles when partial |
| 1794 // raster is enabled. |
| 1795 TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) { |
| 1796 RunPartialRasterCheck(host_impl_.Pass(), true /* partial_raster_enabled */); |
| 1797 } |
| 1798 |
| 1799 // Ensures that the tile manager does not attempt to reuse tiles when partial |
| 1800 // raster is disabled. |
| 1801 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) { |
| 1802 RunPartialRasterCheck(host_impl_.Pass(), false /* partial_raster_enabled */); |
| 1803 } |
| 1804 |
1684 } // namespace | 1805 } // namespace |
1685 } // namespace cc | 1806 } // namespace cc |
OLD | NEW |