| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/surfaces/surface_factory.h" | 5 #include "cc/surfaces/surface_factory.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "cc/output/compositor_frame.h" | 14 #include "cc/output/compositor_frame.h" |
| 15 #include "cc/output/copy_output_request.h" | 15 #include "cc/output/copy_output_request.h" |
| 16 #include "cc/output/copy_output_result.h" | 16 #include "cc/output/copy_output_result.h" |
| 17 #include "cc/output/delegated_frame_data.h" | 17 #include "cc/output/delegated_frame_data.h" |
| 18 #include "cc/resources/resource_provider.h" | 18 #include "cc/resources/resource_provider.h" |
| 19 #include "cc/surfaces/surface.h" | 19 #include "cc/surfaces/surface.h" |
| 20 #include "cc/surfaces/surface_factory_client.h" | 20 #include "cc/surfaces/surface_factory_client.h" |
| 21 #include "cc/surfaces/surface_manager.h" | 21 #include "cc/surfaces/surface_manager.h" |
| 22 #include "cc/test/scheduler_test_common.h" | 22 #include "cc/test/scheduler_test_common.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
| 25 | 25 |
| 26 namespace cc { | 26 namespace cc { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 static constexpr uint32_t kArbitraryClientId = 0; |
| 30 |
| 29 class TestSurfaceFactoryClient : public SurfaceFactoryClient { | 31 class TestSurfaceFactoryClient : public SurfaceFactoryClient { |
| 30 public: | 32 public: |
| 31 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {} | 33 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {} |
| 32 ~TestSurfaceFactoryClient() override {} | 34 ~TestSurfaceFactoryClient() override {} |
| 33 | 35 |
| 34 void ReturnResources(const ReturnedResourceArray& resources) override { | 36 void ReturnResources(const ReturnedResourceArray& resources) override { |
| 35 returned_resources_.insert( | 37 returned_resources_.insert( |
| 36 returned_resources_.end(), resources.begin(), resources.end()); | 38 returned_resources_.end(), resources.begin(), resources.end()); |
| 37 } | 39 } |
| 38 | 40 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 59 gpu::SyncToken token; | 61 gpu::SyncToken token; |
| 60 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, | 62 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, |
| 61 gpu::CommandBufferId::FromUnsafeValue(id), 1); | 63 gpu::CommandBufferId::FromUnsafeValue(id), 1); |
| 62 return token; | 64 return token; |
| 63 } | 65 } |
| 64 | 66 |
| 65 class SurfaceFactoryTest : public testing::Test, public SurfaceDamageObserver { | 67 class SurfaceFactoryTest : public testing::Test, public SurfaceDamageObserver { |
| 66 public: | 68 public: |
| 67 SurfaceFactoryTest() | 69 SurfaceFactoryTest() |
| 68 : factory_(new SurfaceFactory(&manager_, &client_)), | 70 : factory_(new SurfaceFactory(&manager_, &client_)), |
| 69 surface_id_(0, 3, 0), | 71 surface_id_(kArbitraryClientId, 3, 0), |
| 70 frame_sync_token_(GenTestSyncToken(4)), | 72 frame_sync_token_(GenTestSyncToken(4)), |
| 71 consumer_sync_token_(GenTestSyncToken(5)) { | 73 consumer_sync_token_(GenTestSyncToken(5)) { |
| 72 manager_.AddObserver(this); | 74 manager_.AddObserver(this); |
| 73 factory_->Create(surface_id_); | 75 factory_->Create(surface_id_); |
| 74 } | 76 } |
| 75 | 77 |
| 76 // SurfaceDamageObserver implementation. | 78 // SurfaceDamageObserver implementation. |
| 77 void OnSurfaceDamaged(SurfaceId id, bool* changed) override { | 79 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { |
| 78 *changed = true; | 80 *changed = true; |
| 79 } | 81 } |
| 80 | 82 |
| 81 ~SurfaceFactoryTest() override { | 83 ~SurfaceFactoryTest() override { |
| 82 if (!surface_id_.is_null()) | 84 if (!surface_id_.is_null()) |
| 83 factory_->Destroy(surface_id_); | 85 factory_->Destroy(surface_id_); |
| 84 manager_.RemoveObserver(this); | 86 manager_.RemoveObserver(this); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 89 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 SCOPED_TRACE("fourth frame, second unref"); | 414 SCOPED_TRACE("fourth frame, second unref"); |
| 413 ResourceId expected_returned_ids[] = {12, 13}; | 415 ResourceId expected_returned_ids[] = {12, 13}; |
| 414 int expected_returned_counts[] = {2, 2}; | 416 int expected_returned_counts[] = {2, 2}; |
| 415 CheckReturnedResourcesMatchExpected( | 417 CheckReturnedResourcesMatchExpected( |
| 416 expected_returned_ids, expected_returned_counts, | 418 expected_returned_ids, expected_returned_counts, |
| 417 arraysize(expected_returned_counts), consumer_sync_token_); | 419 arraysize(expected_returned_counts), consumer_sync_token_); |
| 418 } | 420 } |
| 419 } | 421 } |
| 420 | 422 |
| 421 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 423 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
| 422 SurfaceId surface_id(0, 6, 0); | 424 SurfaceId surface_id(kArbitraryClientId, 6, 0); |
| 423 factory_->Create(surface_id); | 425 factory_->Create(surface_id); |
| 424 Surface* surface = manager_.GetSurfaceForId(surface_id); | 426 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 425 ASSERT_NE(nullptr, surface); | 427 ASSERT_NE(nullptr, surface); |
| 426 EXPECT_EQ(2, surface->frame_index()); | 428 EXPECT_EQ(2, surface->frame_index()); |
| 427 CompositorFrame frame; | 429 CompositorFrame frame; |
| 428 frame.delegated_frame_data.reset(new DelegatedFrameData); | 430 frame.delegated_frame_data.reset(new DelegatedFrameData); |
| 429 | 431 |
| 430 factory_->SubmitCompositorFrame(surface_id, std::move(frame), | 432 factory_->SubmitCompositorFrame(surface_id, std::move(frame), |
| 431 SurfaceFactory::DrawCallback()); | 433 SurfaceFactory::DrawCallback()); |
| 432 EXPECT_EQ(2, surface->frame_index()); | 434 EXPECT_EQ(2, surface->frame_index()); |
| 433 factory_->Destroy(surface_id); | 435 factory_->Destroy(surface_id); |
| 434 } | 436 } |
| 435 | 437 |
| 436 void CreateSurfaceDrawCallback(SurfaceFactory* factory, | 438 void CreateSurfaceDrawCallback(SurfaceFactory* factory, |
| 437 uint32_t* execute_count, | 439 uint32_t* execute_count, |
| 438 SurfaceDrawStatus* result, | 440 SurfaceDrawStatus* result, |
| 439 SurfaceDrawStatus drawn) { | 441 SurfaceDrawStatus drawn) { |
| 440 SurfaceId new_id(0, 7, 0); | 442 SurfaceId new_id(kArbitraryClientId, 7, 0); |
| 441 factory->Create(new_id); | 443 factory->Create(new_id); |
| 442 factory->Destroy(new_id); | 444 factory->Destroy(new_id); |
| 443 *execute_count += 1; | 445 *execute_count += 1; |
| 444 *result = drawn; | 446 *result = drawn; |
| 445 } | 447 } |
| 446 | 448 |
| 447 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { | 449 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { |
| 448 SurfaceId surface_id(0, 6, 0); | 450 SurfaceId surface_id(kArbitraryClientId, 6, 0); |
| 449 factory_->Create(surface_id); | 451 factory_->Create(surface_id); |
| 450 CompositorFrame frame; | 452 CompositorFrame frame; |
| 451 frame.delegated_frame_data.reset(new DelegatedFrameData); | 453 frame.delegated_frame_data.reset(new DelegatedFrameData); |
| 452 | 454 |
| 453 uint32_t execute_count = 0; | 455 uint32_t execute_count = 0; |
| 454 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; | 456 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; |
| 455 factory_->SubmitCompositorFrame( | 457 factory_->SubmitCompositorFrame( |
| 456 surface_id, std::move(frame), | 458 surface_id, std::move(frame), |
| 457 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), | 459 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), |
| 458 &execute_count, &drawn)); | 460 &execute_count, &drawn)); |
| 459 EXPECT_EQ(0u, execute_count); | 461 EXPECT_EQ(0u, execute_count); |
| 460 factory_->Destroy(surface_id); | 462 factory_->Destroy(surface_id); |
| 461 EXPECT_EQ(1u, execute_count); | 463 EXPECT_EQ(1u, execute_count); |
| 462 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); | 464 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); |
| 463 } | 465 } |
| 464 | 466 |
| 465 void DrawCallback(uint32_t* execute_count, | 467 void DrawCallback(uint32_t* execute_count, |
| 466 SurfaceDrawStatus* result, | 468 SurfaceDrawStatus* result, |
| 467 SurfaceDrawStatus drawn) { | 469 SurfaceDrawStatus drawn) { |
| 468 *execute_count += 1; | 470 *execute_count += 1; |
| 469 *result = drawn; | 471 *result = drawn; |
| 470 } | 472 } |
| 471 | 473 |
| 472 // Tests doing a DestroyAll before shutting down the factory; | 474 // Tests doing a DestroyAll before shutting down the factory; |
| 473 TEST_F(SurfaceFactoryTest, DestroyAll) { | 475 TEST_F(SurfaceFactoryTest, DestroyAll) { |
| 474 SurfaceId id(0, 7, 0); | 476 SurfaceId id(kArbitraryClientId, 7, 0); |
| 475 factory_->Create(id); | 477 factory_->Create(id); |
| 476 | 478 |
| 477 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 479 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 478 TransferableResource resource; | 480 TransferableResource resource; |
| 479 resource.id = 1; | 481 resource.id = 1; |
| 480 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 482 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 481 frame_data->resource_list.push_back(resource); | 483 frame_data->resource_list.push_back(resource); |
| 482 CompositorFrame frame; | 484 CompositorFrame frame; |
| 483 frame.delegated_frame_data = std::move(frame_data); | 485 frame.delegated_frame_data = std::move(frame_data); |
| 484 uint32_t execute_count = 0; | 486 uint32_t execute_count = 0; |
| 485 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; | 487 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; |
| 486 | 488 |
| 487 factory_->SubmitCompositorFrame( | 489 factory_->SubmitCompositorFrame( |
| 488 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); | 490 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); |
| 489 | 491 |
| 490 surface_id_ = SurfaceId(); | 492 surface_id_ = SurfaceId(); |
| 491 factory_->DestroyAll(); | 493 factory_->DestroyAll(); |
| 492 EXPECT_EQ(1u, execute_count); | 494 EXPECT_EQ(1u, execute_count); |
| 493 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); | 495 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); |
| 494 } | 496 } |
| 495 | 497 |
| 496 TEST_F(SurfaceFactoryTest, DestroySequence) { | 498 TEST_F(SurfaceFactoryTest, DestroySequence) { |
| 497 SurfaceId id2(0, 5, 0); | 499 SurfaceId id2(kArbitraryClientId, 5, 0); |
| 498 factory_->Create(id2); | 500 factory_->Create(id2); |
| 499 | 501 |
| 500 manager_.RegisterSurfaceIdNamespace(0); | 502 manager_.RegisterSurfaceClientId(0); |
| 501 | 503 |
| 502 // Check that waiting before the sequence is satisfied works. | 504 // Check that waiting before the sequence is satisfied works. |
| 503 manager_.GetSurfaceForId(id2) | 505 manager_.GetSurfaceForId(id2) |
| 504 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 506 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
| 505 factory_->Destroy(id2); | 507 factory_->Destroy(id2); |
| 506 | 508 |
| 507 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 509 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 508 CompositorFrame frame; | 510 CompositorFrame frame; |
| 509 frame.metadata.satisfies_sequences.push_back(6); | 511 frame.metadata.satisfies_sequences.push_back(6); |
| 510 frame.metadata.satisfies_sequences.push_back(4); | 512 frame.metadata.satisfies_sequences.push_back(4); |
| 511 frame.delegated_frame_data = std::move(frame_data); | 513 frame.delegated_frame_data = std::move(frame_data); |
| 512 DCHECK(manager_.GetSurfaceForId(id2)); | 514 DCHECK(manager_.GetSurfaceForId(id2)); |
| 513 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 515 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 514 SurfaceFactory::DrawCallback()); | 516 SurfaceFactory::DrawCallback()); |
| 515 DCHECK(!manager_.GetSurfaceForId(id2)); | 517 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 516 | 518 |
| 517 // Check that waiting after the sequence is satisfied works. | 519 // Check that waiting after the sequence is satisfied works. |
| 518 factory_->Create(id2); | 520 factory_->Create(id2); |
| 519 DCHECK(manager_.GetSurfaceForId(id2)); | 521 DCHECK(manager_.GetSurfaceForId(id2)); |
| 520 manager_.GetSurfaceForId(id2) | 522 manager_.GetSurfaceForId(id2) |
| 521 ->AddDestructionDependency(SurfaceSequence(0, 6)); | 523 ->AddDestructionDependency(SurfaceSequence(0, 6)); |
| 522 factory_->Destroy(id2); | 524 factory_->Destroy(id2); |
| 523 DCHECK(!manager_.GetSurfaceForId(id2)); | 525 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 524 } | 526 } |
| 525 | 527 |
| 526 // Tests that Surface ID namespace invalidation correctly allows | 528 // Tests that Surface ID namespace invalidation correctly allows |
| 527 // Sequences to be ignored. | 529 // Sequences to be ignored. |
| 528 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { | 530 TEST_F(SurfaceFactoryTest, InvalidClientId) { |
| 529 uint32_t id_namespace = 9u; | 531 uint32_t id_namespace = 9u; |
| 530 SurfaceId id(id_namespace, 5, 0); | 532 SurfaceId id(id_namespace, 5, 0); |
| 531 factory_->Create(id); | 533 factory_->Create(id); |
| 532 | 534 |
| 533 manager_.RegisterSurfaceIdNamespace(id_namespace); | 535 manager_.RegisterSurfaceClientId(id_namespace); |
| 534 manager_.GetSurfaceForId(id) | 536 manager_.GetSurfaceForId(id) |
| 535 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); | 537 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); |
| 536 factory_->Destroy(id); | 538 factory_->Destroy(id); |
| 537 | 539 |
| 538 // Verify the dependency has prevented the surface from getting destroyed. | 540 // Verify the dependency has prevented the surface from getting destroyed. |
| 539 EXPECT_TRUE(manager_.GetSurfaceForId(id)); | 541 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
| 540 | 542 |
| 541 manager_.InvalidateSurfaceIdNamespace(id_namespace); | 543 manager_.InvalidateSurfaceClientId(id_namespace); |
| 542 | 544 |
| 543 // Verify that the invalidated namespace caused the unsatisfied sequence | 545 // Verify that the invalidated namespace caused the unsatisfied sequence |
| 544 // to be ignored. | 546 // to be ignored. |
| 545 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 547 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
| 546 } | 548 } |
| 547 | 549 |
| 548 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 550 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
| 549 SurfaceId id2(0, 5, 0); | 551 SurfaceId id2(kArbitraryClientId, 5, 0); |
| 550 factory_->Create(id2); | 552 factory_->Create(id2); |
| 551 | 553 |
| 552 manager_.RegisterSurfaceIdNamespace(0); | 554 manager_.RegisterSurfaceClientId(0); |
| 553 | 555 |
| 554 manager_.GetSurfaceForId(id2) | 556 manager_.GetSurfaceForId(id2) |
| 555 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 557 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
| 556 | 558 |
| 557 // Give id2 a frame that references surface_id_. | 559 // Give id2 a frame that references surface_id_. |
| 558 { | 560 { |
| 559 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 561 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 560 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 562 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 561 frame_data->render_pass_list.push_back(std::move(render_pass)); | 563 frame_data->render_pass_list.push_back(std::move(render_pass)); |
| 562 CompositorFrame frame; | 564 CompositorFrame frame; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 | 649 |
| 648 factory_->Destroy(surface_id_); | 650 factory_->Destroy(surface_id_); |
| 649 surface_id_ = SurfaceId(); | 651 surface_id_ = SurfaceId(); |
| 650 EXPECT_TRUE(called1); | 652 EXPECT_TRUE(called1); |
| 651 EXPECT_TRUE(called2); | 653 EXPECT_TRUE(called2); |
| 652 EXPECT_TRUE(called3); | 654 EXPECT_TRUE(called3); |
| 653 } | 655 } |
| 654 | 656 |
| 655 } // namespace | 657 } // namespace |
| 656 } // namespace cc | 658 } // namespace cc |
| OLD | NEW |