| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 4354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4365 class LayerTreeHostTestGpuRasterizationDefault : public LayerTreeHostTest { | 4365 class LayerTreeHostTestGpuRasterizationDefault : public LayerTreeHostTest { |
| 4366 protected: | 4366 protected: |
| 4367 void InitializeSettings(LayerTreeSettings* settings) override { | 4367 void InitializeSettings(LayerTreeSettings* settings) override { |
| 4368 EXPECT_FALSE(settings->gpu_rasterization_enabled); | 4368 EXPECT_FALSE(settings->gpu_rasterization_enabled); |
| 4369 EXPECT_FALSE(settings->gpu_rasterization_forced); | 4369 EXPECT_FALSE(settings->gpu_rasterization_forced); |
| 4370 } | 4370 } |
| 4371 | 4371 |
| 4372 void SetupTree() override { | 4372 void SetupTree() override { |
| 4373 LayerTreeHostTest::SetupTree(); | 4373 LayerTreeHostTest::SetupTree(); |
| 4374 | 4374 |
| 4375 scoped_ptr<FakeDisplayListRecordingSource> recording_source( | 4375 scoped_refptr<PictureLayer> layer = |
| 4376 new FakeDisplayListRecordingSource(gfx::Size(10, 10))); | 4376 PictureLayer::Create(layer_settings(), &layer_client_); |
| 4377 recording_source_ = recording_source.get(); | |
| 4378 | |
| 4379 scoped_refptr<FakePictureLayer> layer = | |
| 4380 FakePictureLayer::CreateWithRecordingSource( | |
| 4381 layer_settings(), &layer_client_, recording_source.Pass()); | |
| 4382 layer_ = layer.get(); | |
| 4383 layer->SetBounds(gfx::Size(10, 10)); | 4377 layer->SetBounds(gfx::Size(10, 10)); |
| 4384 layer->SetIsDrawable(true); | 4378 layer->SetIsDrawable(true); |
| 4385 layer_tree_host()->root_layer()->AddChild(layer); | 4379 layer_tree_host()->root_layer()->AddChild(layer); |
| 4386 } | 4380 } |
| 4387 | 4381 |
| 4388 void BeginTest() override { | 4382 void BeginTest() override { |
| 4389 // Verify default value. | 4383 Layer* root = layer_tree_host()->root_layer(); |
| 4384 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0)); |
| 4385 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); |
| 4386 |
| 4387 // Verify default values. |
| 4388 EXPECT_TRUE(root->IsSuitableForGpuRasterization()); |
| 4389 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); |
| 4390 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); |
| 4390 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger()); | 4391 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger()); |
| 4391 | 4392 |
| 4392 // Setting gpu rasterization trigger does not enable gpu rasterization. | 4393 // Setting gpu rasterization trigger does not enable gpu rasterization. |
| 4393 layer_tree_host()->SetHasGpuRasterizationTrigger(true); | 4394 layer_tree_host()->SetHasGpuRasterizationTrigger(true); |
| 4394 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger()); | 4395 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger()); |
| 4395 | 4396 |
| 4396 PostSetNeedsCommitToMainThread(); | 4397 PostSetNeedsCommitToMainThread(); |
| 4397 } | 4398 } |
| 4398 | 4399 |
| 4399 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 4400 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 4400 EXPECT_TRUE(recording_source_->IsSuitableForGpuRasterization()); | |
| 4401 EXPECT_TRUE(layer_->IsSuitableForGpuRasterization()); | |
| 4402 | |
| 4403 EXPECT_FALSE(host_impl->pending_tree()->use_gpu_rasterization()); | 4401 EXPECT_FALSE(host_impl->pending_tree()->use_gpu_rasterization()); |
| 4404 EXPECT_FALSE(host_impl->use_gpu_rasterization()); | 4402 EXPECT_FALSE(host_impl->use_gpu_rasterization()); |
| 4405 } | 4403 } |
| 4406 | 4404 |
| 4407 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 4405 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 4408 EXPECT_TRUE(recording_source_->IsSuitableForGpuRasterization()); | |
| 4409 EXPECT_TRUE(layer_->IsSuitableForGpuRasterization()); | |
| 4410 | |
| 4411 EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization()); | 4406 EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization()); |
| 4412 EXPECT_FALSE(host_impl->use_gpu_rasterization()); | 4407 EXPECT_FALSE(host_impl->use_gpu_rasterization()); |
| 4413 EndTest(); | 4408 EndTest(); |
| 4414 } | 4409 } |
| 4415 | 4410 |
| 4416 void AfterTest() override {} | 4411 void AfterTest() override {} |
| 4417 | 4412 |
| 4418 FakeContentLayerClient layer_client_; | 4413 FakeContentLayerClient layer_client_; |
| 4419 FakePictureLayer* layer_; | |
| 4420 FakeDisplayListRecordingSource* recording_source_; | |
| 4421 }; | 4414 }; |
| 4422 | 4415 |
| 4423 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationDefault); | 4416 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationDefault); |
| 4424 | 4417 |
| 4425 class LayerTreeHostTestGpuRasterizationEnabled : public LayerTreeHostTest { | 4418 class LayerTreeHostTestGpuRasterizationEnabled : public LayerTreeHostTest { |
| 4426 protected: | 4419 protected: |
| 4427 void InitializeSettings(LayerTreeSettings* settings) override { | 4420 void InitializeSettings(LayerTreeSettings* settings) override { |
| 4428 EXPECT_FALSE(settings->gpu_rasterization_enabled); | 4421 EXPECT_FALSE(settings->gpu_rasterization_enabled); |
| 4429 settings->gpu_rasterization_enabled = true; | 4422 settings->gpu_rasterization_enabled = true; |
| 4430 } | 4423 } |
| 4431 | 4424 |
| 4432 void SetupTree() override { | 4425 void SetupTree() override { |
| 4433 LayerTreeHostTest::SetupTree(); | 4426 LayerTreeHostTest::SetupTree(); |
| 4434 | 4427 |
| 4435 scoped_ptr<FakeDisplayListRecordingSource> recording_source( | 4428 scoped_ptr<FakeDisplayListRecordingSource> recording_source( |
| 4436 new FakeDisplayListRecordingSource(gfx::Size(10, 10))); | 4429 new FakeDisplayListRecordingSource(gfx::Size(10, 10))); |
| 4437 recording_source_ = recording_source.get(); | |
| 4438 | 4430 |
| 4439 scoped_refptr<FakePictureLayer> layer = | 4431 scoped_refptr<FakePictureLayer> layer = |
| 4440 FakePictureLayer::CreateWithRecordingSource( | 4432 FakePictureLayer::CreateWithRecordingSource( |
| 4441 layer_settings(), &layer_client_, recording_source.Pass()); | 4433 layer_settings(), &layer_client_, recording_source.Pass()); |
| 4442 layer_ = layer.get(); | |
| 4443 layer->SetBounds(gfx::Size(10, 10)); | 4434 layer->SetBounds(gfx::Size(10, 10)); |
| 4444 layer->SetIsDrawable(true); | 4435 layer->SetIsDrawable(true); |
| 4445 layer_tree_host()->root_layer()->AddChild(layer); | 4436 layer_tree_host()->root_layer()->AddChild(layer); |
| 4446 } | 4437 } |
| 4447 | 4438 |
| 4448 void BeginTest() override { | 4439 void BeginTest() override { |
| 4449 // Verify default value. | 4440 Layer* root = layer_tree_host()->root_layer(); |
| 4441 FakePictureLayer* layer = static_cast<FakePictureLayer*>(root->child_at(0)); |
| 4442 FakeDisplayListRecordingSource* recording_source = |
| 4443 static_cast<FakeDisplayListRecordingSource*>( |
| 4444 layer->GetRecordingSourceForTesting()); |
| 4445 |
| 4446 // Verify default values. |
| 4447 EXPECT_TRUE(root->IsSuitableForGpuRasterization()); |
| 4448 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); |
| 4449 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); |
| 4450 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger()); | 4450 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger()); |
| 4451 | 4451 |
| 4452 // Gpu rasterization trigger is relevant. | 4452 // Gpu rasterization trigger is relevant. |
| 4453 layer_tree_host()->SetHasGpuRasterizationTrigger(true); | 4453 layer_tree_host()->SetHasGpuRasterizationTrigger(true); |
| 4454 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger()); | 4454 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger()); |
| 4455 | 4455 |
| 4456 // Content-based veto is relevant as well. | 4456 // Content-based veto is relevant as well. |
| 4457 recording_source_->SetUnsuitableForGpuRasterization(); | 4457 recording_source->SetUnsuitableForGpuRasterizationForTesting(); |
| 4458 | 4458 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization()); |
| 4459 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); |
| 4459 // Veto will take effect when layers are updated. | 4460 // Veto will take effect when layers are updated. |
| 4460 // The results will be verified after commit is completed below. | 4461 // The results will be verified after commit is completed below. |
| 4461 // Since we are manually marking the source as unsuitable, | 4462 // Since we are manually marking picture pile as unsuitable, |
| 4462 // make sure that the layer gets a chance to update. | 4463 // make sure that the layer gets a chance to update. |
| 4463 layer_->SetNeedsDisplay(); | 4464 layer->SetNeedsDisplay(); |
| 4464 PostSetNeedsCommitToMainThread(); | 4465 PostSetNeedsCommitToMainThread(); |
| 4465 } | 4466 } |
| 4466 | 4467 |
| 4467 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 4468 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 4468 // Ensure the suitability bit sticks. | |
| 4469 EXPECT_FALSE(recording_source_->IsSuitableForGpuRasterization()); | |
| 4470 EXPECT_FALSE(layer_->IsSuitableForGpuRasterization()); | |
| 4471 | |
| 4472 EXPECT_FALSE(host_impl->pending_tree()->use_gpu_rasterization()); | 4469 EXPECT_FALSE(host_impl->pending_tree()->use_gpu_rasterization()); |
| 4473 EXPECT_FALSE(host_impl->use_gpu_rasterization()); | 4470 EXPECT_FALSE(host_impl->use_gpu_rasterization()); |
| 4474 } | 4471 } |
| 4475 | 4472 |
| 4476 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 4473 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 4477 EXPECT_FALSE(recording_source_->IsSuitableForGpuRasterization()); | |
| 4478 EXPECT_FALSE(layer_->IsSuitableForGpuRasterization()); | |
| 4479 | |
| 4480 EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization()); | 4474 EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization()); |
| 4481 EXPECT_FALSE(host_impl->use_gpu_rasterization()); | 4475 EXPECT_FALSE(host_impl->use_gpu_rasterization()); |
| 4482 EndTest(); | 4476 EndTest(); |
| 4483 } | 4477 } |
| 4484 | 4478 |
| 4485 void AfterTest() override {} | 4479 void AfterTest() override {} |
| 4486 | 4480 |
| 4487 FakeContentLayerClient layer_client_; | 4481 FakeContentLayerClient layer_client_; |
| 4488 FakePictureLayer* layer_; | |
| 4489 FakeDisplayListRecordingSource* recording_source_; | |
| 4490 }; | 4482 }; |
| 4491 | 4483 |
| 4492 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabled); | 4484 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabled); |
| 4493 | 4485 |
| 4494 class LayerTreeHostTestGpuRasterizationForced : public LayerTreeHostTest { | 4486 class LayerTreeHostTestGpuRasterizationForced : public LayerTreeHostTest { |
| 4495 protected: | 4487 protected: |
| 4496 void InitializeSettings(LayerTreeSettings* settings) override { | 4488 void InitializeSettings(LayerTreeSettings* settings) override { |
| 4497 EXPECT_FALSE(settings->gpu_rasterization_forced); | 4489 EXPECT_FALSE(settings->gpu_rasterization_forced); |
| 4498 settings->gpu_rasterization_forced = true; | 4490 settings->gpu_rasterization_forced = true; |
| 4499 } | 4491 } |
| 4500 | 4492 |
| 4501 void SetupTree() override { | 4493 void SetupTree() override { |
| 4502 LayerTreeHostTest::SetupTree(); | 4494 LayerTreeHostTest::SetupTree(); |
| 4503 | 4495 |
| 4504 scoped_ptr<FakeDisplayListRecordingSource> recording_source( | |
| 4505 new FakeDisplayListRecordingSource(gfx::Size(100, 100))); | |
| 4506 recording_source_ = recording_source.get(); | |
| 4507 | |
| 4508 scoped_refptr<FakePictureLayer> layer = | 4496 scoped_refptr<FakePictureLayer> layer = |
| 4509 FakePictureLayer::CreateWithRecordingSource( | 4497 FakePictureLayer::Create(layer_settings(), &layer_client_); |
| 4510 layer_settings(), &layer_client_, recording_source.Pass()); | |
| 4511 layer_ = layer.get(); | |
| 4512 | |
| 4513 layer->SetBounds(gfx::Size(10, 10)); | 4498 layer->SetBounds(gfx::Size(10, 10)); |
| 4514 layer->SetIsDrawable(true); | 4499 layer->SetIsDrawable(true); |
| 4515 layer_tree_host()->root_layer()->AddChild(layer); | 4500 layer_tree_host()->root_layer()->AddChild(layer); |
| 4516 } | 4501 } |
| 4517 | 4502 |
| 4518 void BeginTest() override { | 4503 void BeginTest() override { |
| 4519 // Verify default value. | 4504 Layer* root = layer_tree_host()->root_layer(); |
| 4505 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0)); |
| 4506 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); |
| 4507 |
| 4508 // Verify default values. |
| 4509 EXPECT_TRUE(root->IsSuitableForGpuRasterization()); |
| 4510 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); |
| 4511 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); |
| 4520 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger()); | 4512 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger()); |
| 4521 | 4513 |
| 4522 // With gpu rasterization forced, gpu rasterization trigger is irrelevant. | 4514 // With gpu rasterization forced, gpu rasterization trigger is irrelevant. |
| 4523 layer_tree_host()->SetHasGpuRasterizationTrigger(true); | 4515 layer_tree_host()->SetHasGpuRasterizationTrigger(true); |
| 4524 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger()); | 4516 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger()); |
| 4525 | 4517 |
| 4526 // Content-based veto is irrelevant as well. | 4518 // Content-based veto is irrelevant as well. |
| 4527 recording_source_->SetUnsuitableForGpuRasterization(); | 4519 recording_source->SetUnsuitableForGpuRasterizationForTesting(); |
| 4528 | 4520 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization()); |
| 4521 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); |
| 4529 // Veto will take effect when layers are updated. | 4522 // Veto will take effect when layers are updated. |
| 4530 // The results will be verified after commit is completed below. | 4523 // The results will be verified after commit is completed below. |
| 4531 // Since we are manually marking the source as unsuitable, | 4524 // Since we are manually marking picture pile as unsuitable, |
| 4532 // make sure that the layer gets a chance to update. | 4525 // make sure that the layer gets a chance to update. |
| 4533 layer_->SetNeedsDisplay(); | 4526 layer->SetNeedsDisplay(); |
| 4534 PostSetNeedsCommitToMainThread(); | 4527 PostSetNeedsCommitToMainThread(); |
| 4535 } | 4528 } |
| 4536 | 4529 |
| 4537 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 4530 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 4538 // Ensure the suitability bit sticks. | |
| 4539 EXPECT_FALSE(recording_source_->IsSuitableForGpuRasterization()); | |
| 4540 EXPECT_FALSE(layer_->IsSuitableForGpuRasterization()); | |
| 4541 | |
| 4542 EXPECT_TRUE(host_impl->sync_tree()->use_gpu_rasterization()); | 4531 EXPECT_TRUE(host_impl->sync_tree()->use_gpu_rasterization()); |
| 4543 EXPECT_TRUE(host_impl->use_gpu_rasterization()); | 4532 EXPECT_TRUE(host_impl->use_gpu_rasterization()); |
| 4544 } | 4533 } |
| 4545 | 4534 |
| 4546 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 4535 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 4547 EXPECT_FALSE(recording_source_->IsSuitableForGpuRasterization()); | |
| 4548 EXPECT_FALSE(layer_->IsSuitableForGpuRasterization()); | |
| 4549 | |
| 4550 EXPECT_TRUE(host_impl->active_tree()->use_gpu_rasterization()); | 4536 EXPECT_TRUE(host_impl->active_tree()->use_gpu_rasterization()); |
| 4551 EXPECT_TRUE(host_impl->use_gpu_rasterization()); | 4537 EXPECT_TRUE(host_impl->use_gpu_rasterization()); |
| 4552 EndTest(); | 4538 EndTest(); |
| 4553 } | 4539 } |
| 4554 | 4540 |
| 4555 void AfterTest() override {} | 4541 void AfterTest() override {} |
| 4556 | 4542 |
| 4557 FakeContentLayerClient layer_client_; | 4543 FakeContentLayerClient layer_client_; |
| 4558 FakePictureLayer* layer_; | |
| 4559 FakeDisplayListRecordingSource* recording_source_; | |
| 4560 }; | 4544 }; |
| 4561 | 4545 |
| 4562 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationForced); | 4546 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationForced); |
| 4563 | 4547 |
| 4564 class LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame | 4548 class LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame |
| 4565 : public LayerTreeHostTest { | 4549 : public LayerTreeHostTest { |
| 4566 public: | 4550 public: |
| 4567 enum { kExpectedNumImplFrames = 10 }; | 4551 enum { kExpectedNumImplFrames = 10 }; |
| 4568 | 4552 |
| 4569 LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame() | 4553 LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame() |
| (...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6201 ScrollAndScaleSet scale_info_; | 6185 ScrollAndScaleSet scale_info_; |
| 6202 ScrollAndScaleSet no_op_info_; | 6186 ScrollAndScaleSet no_op_info_; |
| 6203 bool requested_update_layers_; | 6187 bool requested_update_layers_; |
| 6204 int commit_count_; | 6188 int commit_count_; |
| 6205 }; | 6189 }; |
| 6206 | 6190 |
| 6207 MULTI_THREAD_TEST_F(LayerTreeHostScrollingAndScalingUpdatesLayers); | 6191 MULTI_THREAD_TEST_F(LayerTreeHostScrollingAndScalingUpdatesLayers); |
| 6208 | 6192 |
| 6209 } // namespace | 6193 } // namespace |
| 6210 } // namespace cc | 6194 } // namespace cc |
| OLD | NEW |