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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: cc/tiles/tile_manager_unittest.cc
diff --git a/cc/tiles/tile_manager_unittest.cc b/cc/tiles/tile_manager_unittest.cc
index 3b82483b45eac140aa09b2fe504b36dcf2b34f9b..a11c1349b9b5760d659f0a23bd1320213b422ace 100644
--- a/cc/tiles/tile_manager_unittest.cc
+++ b/cc/tiles/tile_manager_unittest.cc
@@ -1835,8 +1835,7 @@ class FakeTileTaskWorkerPool : public TileTaskWorkerPool,
~FakeTileTaskWorkerPool() override {}
// TileTaskWorkerPool methods.
- void Shutdown() override {}
- void CheckForCompletedTasks() override {}
+ void BarrierToSyncResources() override {}
ResourceFormat GetResourceFormat(bool must_support_alpha) const override {
return ResourceFormat::RGBA_8888;
}
@@ -1845,8 +1844,6 @@ class FakeTileTaskWorkerPool : public TileTaskWorkerPool,
}
RasterBufferProvider* AsRasterBufferProvider() override { return this; }
- void ScheduleTasks(TaskGraph* graph) override {}
-
// RasterBufferProvider methods.
std::unique_ptr<RasterBuffer> AcquireBufferForRaster(
const Resource* resource,
@@ -1858,17 +1855,36 @@ class FakeTileTaskWorkerPool : public TileTaskWorkerPool,
void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) override {}
};
-// Fake TileTaskWorkerPool that just cancels all scheduled tasks immediately.
-class CancellingTileTaskWorkerPool : public FakeTileTaskWorkerPool {
+class FakeTileTaskManager : public TileTaskManager {
+ public:
+ explicit FakeTileTaskManager(
+ std::unique_ptr<TileTaskWorkerPool> tile_task_worker_pool)
+ : TileTaskManager(std::move(tile_task_worker_pool)) {}
+ ~FakeTileTaskManager() override {}
+ void Shutdown() override {}
+ void ScheduleTasks(TaskGraph* graph) override {}
+ void CheckForCompletedTasks() override {}
+
+ // Get TileTaskWorkerPool.
+ TileTaskWorkerPool* GetTileTaskWorkerPool() const override {
+ return tile_task_worker_pool_.get();
+ }
+};
+
+// Fake TileTaskManager that just cancels all scheduled tasks immediately.
+class CancellingTileTaskManager : public FakeTileTaskManager {
public:
- CancellingTileTaskWorkerPool() {}
- ~CancellingTileTaskWorkerPool() override {}
+ CancellingTileTaskManager()
+ : FakeTileTaskManager(
+ base::WrapUnique<TileTaskWorkerPool>(new FakeTileTaskWorkerPool)) {}
+ ~CancellingTileTaskManager() override {}
void ScheduleTasks(TaskGraph* graph) override {
// Just call CompleteOnOriginThread on each item in the queue. As none of
// these items have run yet, they will be treated as cancelled tasks.
for (const auto& node : graph->nodes) {
- static_cast<TileTask*>(node.task)->CompleteOnOriginThread(this);
+ static_cast<TileTask*>(node.task)->CompleteOnOriginThread(
+ tile_task_worker_pool_->AsRasterBufferProvider());
}
}
};
@@ -1885,9 +1901,9 @@ class PartialRasterTileManagerTest : public TileManagerTest {
TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) {
// Create a CancellingTaskRunner and set it on the tile manager so that all
// scheduled work is immediately cancelled.
- CancellingTileTaskWorkerPool cancelling_worker_pool;
- host_impl_->tile_manager()->SetTileTaskWorkerPoolForTesting(
- &cancelling_worker_pool);
+ CancellingTileTaskManager cancelling_task_manager;
+ host_impl_->tile_manager()->SetTileTaskManagerForTesting(
+ &cancelling_task_manager);
// Pick arbitrary IDs - they don't really matter as long as they're constant.
const int kLayerId = 7;
@@ -1920,9 +1936,8 @@ TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) {
EXPECT_FALSE(queue->IsEmpty());
queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
- // PrepareTiles to schedule tasks. Due to the CancellingTileTaskWorkerPool,
- // these
- // tasks will immediately be canceled.
+ // PrepareTiles to schedule tasks. Due to the CancellingTileTaskManager,
+ // these tasks will immediately be canceled.
host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state());
// Make sure that the tile we invalidated above was not returned to the pool
@@ -1931,13 +1946,12 @@ TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) {
EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId(
kInvalidatedId));
- // Free our host_impl_ before the cancelling_worker_pool we passed it, as it
- // will
- // use that class in clean up.
+ // Free our host_impl_ before the cancelling_task_manager we passed it, as it
+ // will use that class in clean up.
host_impl_ = nullptr;
}
-// Fake TileTaskWorkerPool that verifies the resource content ID of raster
+// FakeTileTaskWorkerPool that verifies the resource content ID of raster
// tasks.
class VerifyResourceContentIdTileTaskWorkerPool
: public FakeTileTaskWorkerPool {
@@ -1947,16 +1961,6 @@ class VerifyResourceContentIdTileTaskWorkerPool
: expected_resource_id_(expected_resource_id) {}
~VerifyResourceContentIdTileTaskWorkerPool() override {}
- void ScheduleTasks(TaskGraph* graph) override {
- for (const auto& node : graph->nodes) {
- TileTask* task = static_cast<TileTask*>(node.task);
- // Triggers a call to AcquireBufferForRaster.
- task->ScheduleOnOriginThread(this);
- // Calls TileManager as though task was cancelled.
- task->CompleteOnOriginThread(this);
- }
- }
-
// RasterBufferProvider methods.
std::unique_ptr<RasterBuffer> AcquireBufferForRaster(
const Resource* resource,
@@ -1970,6 +1974,27 @@ class VerifyResourceContentIdTileTaskWorkerPool
uint64_t expected_resource_id_;
};
+class VerifyResourceContentIdTileTaskManager : public FakeTileTaskManager {
+ public:
+ explicit VerifyResourceContentIdTileTaskManager(uint64_t expected_resource_id)
+ : FakeTileTaskManager(base::WrapUnique<TileTaskWorkerPool>(
+ new VerifyResourceContentIdTileTaskWorkerPool(
+ expected_resource_id))) {}
+ ~VerifyResourceContentIdTileTaskManager() override {}
+
+ void ScheduleTasks(TaskGraph* graph) override {
+ for (const auto& node : graph->nodes) {
+ TileTask* task = static_cast<TileTask*>(node.task);
+ // Triggers a call to AcquireBufferForRaster.
+ task->ScheduleOnOriginThread(
+ tile_task_worker_pool_->AsRasterBufferProvider());
+ // Calls TileManager as though task was cancelled.
+ task->CompleteOnOriginThread(
+ tile_task_worker_pool_->AsRasterBufferProvider());
+ }
+ }
+};
+
// Runs a test to ensure that partial raster is either enabled or disabled,
// depending on |partial_raster_enabled|'s value. Takes ownership of host_impl
// so that cleanup order can be controlled.
@@ -1981,12 +2006,11 @@ void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl,
const uint64_t kExpectedId = partial_raster_enabled ? kInvalidatedId : 0u;
const gfx::Size kTileSize(128, 128);
- // Create a VerifyResourceContentIdTileTaskWorkerPool to ensure that the
- // raster
- // task we see is created with |kExpectedId|.
- VerifyResourceContentIdTileTaskWorkerPool verifying_worker_pool(kExpectedId);
- host_impl->tile_manager()->SetTileTaskWorkerPoolForTesting(
- &verifying_worker_pool);
+ // Create a VerifyResourceContentIdTileTaskManager to ensure that the
+ // raster task we see is created with |kExpectedId|.
+ VerifyResourceContentIdTileTaskManager verifying_task_manager(kExpectedId);
+ host_impl->tile_manager()->SetTileTaskManagerForTesting(
+ &verifying_task_manager);
// Ensure there's a resource with our |kInvalidatedId| in the resource pool.
host_impl->resource_pool()->ReleaseResource(
@@ -2025,9 +2049,8 @@ void RunPartialRasterCheck(std::unique_ptr<LayerTreeHostImpl> host_impl,
// cancelled.
host_impl->tile_manager()->PrepareTiles(host_impl->global_tile_state());
- // Free our host_impl before the cancelling_worker_pool we passed it, as it
- // will
- // use that class in clean up.
+ // Free our host_impl before the verifying_task_manager we passed it, as it
+ // will use that class in clean up.
host_impl = nullptr;
}

Powered by Google App Engine
This is Rietveld 408576698