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

Unified Diff: cc/tiles/tile_manager_unittest.cc

Issue 1381163002: Add a flag to disable partial raster in renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 5 years, 2 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 73a3cec228e9817802a3d4f2f7686b09001cd32e..532d5ae8463c97542f7c7829f4358459e19ef087 100644
--- a/cc/tiles/tile_manager_unittest.cc
+++ b/cc/tiles/tile_manager_unittest.cc
@@ -1452,10 +1452,13 @@ class TileManagerTest : public testing::Test {
public:
TileManagerTest()
: output_surface_(FakeOutputSurface::CreateSoftware(
- make_scoped_ptr(new SoftwareOutputDevice))),
- host_impl_(new MockLayerTreeHostImpl(&proxy_,
- &shared_bitmap_manager_,
- &task_graph_runner_)) {
+ make_scoped_ptr(new SoftwareOutputDevice))) {}
+
+ void SetUp() override {
+ LayerTreeSettings settings;
+ CustomizeSettings(&settings);
+ host_impl_.reset(new MockLayerTreeHostImpl(
+ settings, &proxy_, &shared_bitmap_manager_, &task_graph_runner_));
host_impl_->SetVisible(true);
host_impl_->InitializeRenderer(output_surface_.get());
}
@@ -1464,14 +1467,18 @@ class TileManagerTest : public testing::Test {
// MockLayerTreeHostImpl allows us to intercept tile manager callbacks.
class MockLayerTreeHostImpl : public FakeLayerTreeHostImpl {
public:
- MockLayerTreeHostImpl(Proxy* proxy,
+ MockLayerTreeHostImpl(const LayerTreeSettings& settings,
+ Proxy* proxy,
SharedBitmapManager* manager,
TaskGraphRunner* task_graph_runner)
- : FakeLayerTreeHostImpl(proxy, manager, task_graph_runner) {}
+ : FakeLayerTreeHostImpl(settings, proxy, manager, task_graph_runner) {}
MOCK_METHOD0(NotifyAllTileTasksCompleted, void());
};
+ // By default do no customization.
+ virtual void CustomizeSettings(LayerTreeSettings* settings) {}
+
TestSharedBitmapManager shared_bitmap_manager_;
TestTaskGraphRunner task_graph_runner_;
FakeImplProxy proxy_;
@@ -1592,10 +1599,11 @@ TEST_F(TileManagerTest, LowResHasNoImage) {
}
}
-// Fake TileTaskRunner that just cancels all scheduled tasks immediately.
-class CancellingTileTaskRunner : public TileTaskRunner, public TileTaskClient {
+// Fake TileTaskRunner that just no-ops all calls.
+class FakeTileTaskRunner : public TileTaskRunner, public TileTaskClient {
public:
- CancellingTileTaskRunner() {}
+ FakeTileTaskRunner() {}
+ ~FakeTileTaskRunner() override {}
// TileTaskRunner methods.
void SetClient(TileTaskRunnerClient* client) override {}
@@ -1608,13 +1616,7 @@ class CancellingTileTaskRunner : public TileTaskRunner, public TileTaskClient {
return false;
}
- void ScheduleTasks(TileTaskQueue* queue) 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& task : queue->items) {
- task.task->CompleteOnOriginThread(this);
- }
- }
+ void ScheduleTasks(TileTaskQueue* queue) override {}
// TileTaskClient methods.
scoped_ptr<RasterBuffer> AcquireBufferForRaster(
@@ -1625,30 +1627,51 @@ class CancellingTileTaskRunner : public TileTaskRunner, public TileTaskClient {
return nullptr;
}
void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override {}
+};
+// Fake TileTaskRunner that just cancels all scheduled tasks immediately.
+class CancellingTileTaskRunner : public FakeTileTaskRunner {
+ public:
+ CancellingTileTaskRunner() {}
~CancellingTileTaskRunner() override {}
+
+ void ScheduleTasks(TileTaskQueue* queue) 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& task : queue->items) {
+ task.task->CompleteOnOriginThread(this);
+ }
+ }
+};
+
+class PartialRasterTileManagerTest : public TileManagerTest {
+ public:
+ void CustomizeSettings(LayerTreeSettings* settings) override {
+ settings->use_partial_raster = true;
+ }
};
// Ensures that if a raster task is cancelled, it gets returned to the resource
// pool with an invalid content ID, not with its invalidated content ID.
-TEST_F(TileManagerTest, CancelledTasksHaveNoContentId) {
+TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) {
// Create a CancellingTaskRunner and set it on the tile manager so that all
// scheduled work is immediately cancelled.
CancellingTileTaskRunner cancelling_runner;
host_impl_->tile_manager()->SetTileTaskRunnerForTesting(&cancelling_runner);
// Pick arbitrary IDs - they don't really matter as long as they're constant.
- int layer_id = 7;
- int invalidated_id = 43;
+ const int kLayerId = 7;
+ const uint64_t kInvalidatedId = 43;
+ const gfx::Size kTileSize(128, 128);
scoped_refptr<FakeDisplayListRasterSource> pending_raster_source =
- FakeDisplayListRasterSource::CreateFilled(gfx::Size(128, 128));
+ FakeDisplayListRasterSource::CreateFilled(kTileSize);
host_impl_->CreatePendingTree();
LayerTreeImpl* pending_tree = host_impl_->pending_tree();
// Steal from the recycled tree.
scoped_ptr<FakePictureLayerImpl> pending_layer =
- FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id,
+ FakePictureLayerImpl::CreateWithRasterSource(pending_tree, kLayerId,
pending_raster_source);
pending_layer->SetDrawsContent(true);
pending_layer->SetHasRenderSurface(true);
@@ -1664,7 +1687,7 @@ TEST_F(TileManagerTest, CancelledTasksHaveNoContentId) {
scoped_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue(
SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL));
EXPECT_FALSE(queue->IsEmpty());
- queue->Top().tile()->SetInvalidated(gfx::Rect(), invalidated_id);
+ queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
// PrepareTiles to schedule tasks. Due to the CancellingTileTaskRunner, these
// tasks will immediately be canceled.
@@ -1674,7 +1697,144 @@ TEST_F(TileManagerTest, CancelledTasksHaveNoContentId) {
// with its invalidated resource ID.
host_impl_->resource_pool()->CheckBusyResources();
EXPECT_FALSE(host_impl_->resource_pool()->TryAcquireResourceWithContentId(
- invalidated_id));
+ kInvalidatedId));
+
+ // Free our host_impl_ before the cancelling_runner we passed it, as it will
+ // use that class in clean up.
+ host_impl_ = nullptr;
+}
+
+// Fake TileTaskRunner that verifies the resource content ID of raster tasks.
+class VerifyResourceContentIdTileTaskRunner : public FakeTileTaskRunner {
+ public:
+ explicit VerifyResourceContentIdTileTaskRunner(uint64_t expected_resource_id)
+ : expected_resource_id_(expected_resource_id) {}
+ ~VerifyResourceContentIdTileTaskRunner() override {}
+
+ void ScheduleTasks(TileTaskQueue* queue) override {
+ for (const auto& task : queue->items) {
+ // Triggers a call to AcquireBufferForRaster.
+ task.task->ScheduleOnOriginThread(this);
+ // Calls TileManager as though task was cancelled.
+ task.task->CompleteOnOriginThread(this);
+ }
+ }
+
+ // TileTaskClient methods.
+ scoped_ptr<RasterBuffer> AcquireBufferForRaster(
+ const Resource* resource,
+ uint64_t resource_content_id,
+ uint64_t previous_content_id) override {
+ EXPECT_EQ(expected_resource_id_, resource_content_id);
+ return nullptr;
+ }
+
+ private:
+ uint64_t expected_resource_id_;
+};
+
+// Ensures that the tile manager does not attempt to reuse tiles when partial
+// raster is disabled.
danakj 2015/10/16 18:13:08 copypasta alert: comment does not match test
ericrk 2015/10/16 20:27:13 Done.
+TEST_F(PartialRasterTileManagerTest, PartialRasterSuccessfullyEnabled) {
+ // Pick arbitrary IDs - they don't really matter as long as they're constant.
+ const int kLayerId = 7;
danakj 2015/10/16 18:13:08 It would be nice to share code. It looks like you
ericrk 2015/10/16 20:27:13 yup, done - had to transfer ownership of host_impl
+ const uint64_t kInvalidatedId = 43;
+ const gfx::Size kTileSize(128, 128);
+
+ // Create a VerifyResourceContentIdTileTaskRunner to ensure that the raster
+ // task we see is created with |kInvalidatedId|.
+ VerifyResourceContentIdTileTaskRunner verifying_runner(kInvalidatedId);
+ host_impl_->tile_manager()->SetTileTaskRunnerForTesting(&verifying_runner);
+
+ // Ensure there's a resource with our |kInvalidatedId| in the resource pool.
+ host_impl_->resource_pool()->ReleaseResource(
+ host_impl_->resource_pool()->AcquireResource(kTileSize, RGBA_8888),
+ kInvalidatedId);
+ host_impl_->resource_pool()->CheckBusyResources();
+
+ scoped_refptr<FakeDisplayListRasterSource> pending_raster_source =
+ FakeDisplayListRasterSource::CreateFilled(kTileSize);
+ host_impl_->CreatePendingTree();
+ LayerTreeImpl* pending_tree = host_impl_->pending_tree();
+
+ // Steal from the recycled tree.
+ scoped_ptr<FakePictureLayerImpl> pending_layer =
+ FakePictureLayerImpl::CreateWithRasterSource(pending_tree, kLayerId,
+ pending_raster_source);
+ pending_layer->SetDrawsContent(true);
+ pending_layer->SetHasRenderSurface(true);
+
+ // The bounds() just mirror the raster source size.
+ pending_layer->SetBounds(pending_layer->raster_source()->GetSize());
+ pending_tree->SetRootLayer(pending_layer.Pass());
+
+ // Add tilings/tiles for the layer.
+ host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */);
+
+ // Build the raster queue and invalidate the top tile.
+ scoped_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue(
+ SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL));
+ EXPECT_FALSE(queue->IsEmpty());
+ queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
+
+ // PrepareTiles to schedule tasks. Due to the
+ // VerifyPreviousContentTileTaskRunner, these tasks will verified and
+ // cancelled.
+ host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state());
+
+ // Free our host_impl_ before the cancelling_runner we passed it, as it will
+ // use that class in clean up.
+ host_impl_ = nullptr;
+}
+
+// Ensures that the tile manager does not attempt to reuse tiles when partial
+// raster is disabled.
+TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) {
+ // Pick arbitrary IDs - they don't really matter as long as they're constant.
+ const int kLayerId = 7;
+ const uint64_t kInvalidatedId = 43;
+ const gfx::Size kTileSize(128, 128);
+
+ // Create a VerifyResourceContentIdTileTaskRunner to ensure that the raster
+ // task we see is 0, not our |kInvalidatedId|.
+ VerifyResourceContentIdTileTaskRunner verifying_runner(0u);
+ host_impl_->tile_manager()->SetTileTaskRunnerForTesting(&verifying_runner);
+
+ // Ensure there's a resource with our |kInvalidatedId| in the resource pool.
+ host_impl_->resource_pool()->ReleaseResource(
+ host_impl_->resource_pool()->AcquireResource(kTileSize, RGBA_8888),
+ kInvalidatedId);
+ host_impl_->resource_pool()->CheckBusyResources();
+
+ scoped_refptr<FakeDisplayListRasterSource> pending_raster_source =
+ FakeDisplayListRasterSource::CreateFilled(kTileSize);
+ host_impl_->CreatePendingTree();
+ LayerTreeImpl* pending_tree = host_impl_->pending_tree();
+
+ // Steal from the recycled tree.
+ scoped_ptr<FakePictureLayerImpl> pending_layer =
+ FakePictureLayerImpl::CreateWithRasterSource(pending_tree, kLayerId,
+ pending_raster_source);
+ pending_layer->SetDrawsContent(true);
+ pending_layer->SetHasRenderSurface(true);
+
+ // The bounds() just mirror the raster source size.
+ pending_layer->SetBounds(pending_layer->raster_source()->GetSize());
+ pending_tree->SetRootLayer(pending_layer.Pass());
+
+ // Add tilings/tiles for the layer.
+ host_impl_->pending_tree()->UpdateDrawProperties(false /* update_lcd_text */);
+
+ // Build the raster queue and invalidate the top tile.
+ scoped_ptr<RasterTilePriorityQueue> queue(host_impl_->BuildRasterQueue(
+ SAME_PRIORITY_FOR_BOTH_TREES, RasterTilePriorityQueue::Type::ALL));
+ EXPECT_FALSE(queue->IsEmpty());
+ queue->Top().tile()->SetInvalidated(gfx::Rect(), kInvalidatedId);
+
+ // PrepareTiles to schedule tasks. Due to the
+ // VerifyPreviousContentTileTaskRunner, these tasks will verified and
+ // cancelled.
+ host_impl_->tile_manager()->PrepareTiles(host_impl_->global_tile_state());
// Free our host_impl_ before the cancelling_runner we passed it, as it will
// use that class in clean up.

Powered by Google App Engine
This is Rietveld 408576698