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