| 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> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, | 62 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, |
| 63 gpu::CommandBufferId::FromUnsafeValue(id), 1); | 63 gpu::CommandBufferId::FromUnsafeValue(id), 1); |
| 64 return token; | 64 return token; |
| 65 } | 65 } |
| 66 | 66 |
| 67 class SurfaceFactoryTest : public testing::Test, public SurfaceDamageObserver { | 67 class SurfaceFactoryTest : public testing::Test, public SurfaceDamageObserver { |
| 68 public: | 68 public: |
| 69 SurfaceFactoryTest() | 69 SurfaceFactoryTest() |
| 70 : factory_( | 70 : factory_( |
| 71 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), | 71 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), |
| 72 surface_id_(kArbitraryFrameSinkId, 3, 0), | 72 local_frame_id_(3, 0), |
| 73 frame_sync_token_(GenTestSyncToken(4)), | 73 frame_sync_token_(GenTestSyncToken(4)), |
| 74 consumer_sync_token_(GenTestSyncToken(5)) { | 74 consumer_sync_token_(GenTestSyncToken(5)) { |
| 75 manager_.AddObserver(this); | 75 manager_.AddObserver(this); |
| 76 factory_->Create(surface_id_); | 76 factory_->Create(local_frame_id_); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // SurfaceDamageObserver implementation. | 79 // SurfaceDamageObserver implementation. |
| 80 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { | 80 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { |
| 81 *changed = true; | 81 *changed = true; |
| 82 } | 82 } |
| 83 | 83 |
| 84 ~SurfaceFactoryTest() override { | 84 ~SurfaceFactoryTest() override { |
| 85 if (!surface_id_.is_null()) | 85 if (!local_frame_id_.is_null()) |
| 86 factory_->Destroy(surface_id_); | 86 factory_->Destroy(local_frame_id_); |
| 87 manager_.RemoveObserver(this); | 87 manager_.RemoveObserver(this); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 90 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
| 91 size_t num_resource_ids) { | 91 size_t num_resource_ids) { |
| 92 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 92 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 93 for (size_t i = 0u; i < num_resource_ids; ++i) { | 93 for (size_t i = 0u; i < num_resource_ids; ++i) { |
| 94 TransferableResource resource; | 94 TransferableResource resource; |
| 95 resource.id = resource_ids[i]; | 95 resource.id = resource_ids[i]; |
| 96 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 96 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 97 resource.mailbox_holder.sync_token = frame_sync_token_; | 97 resource.mailbox_holder.sync_token = frame_sync_token_; |
| 98 frame_data->resource_list.push_back(resource); | 98 frame_data->resource_list.push_back(resource); |
| 99 } | 99 } |
| 100 CompositorFrame frame; | 100 CompositorFrame frame; |
| 101 frame.delegated_frame_data = std::move(frame_data); | 101 frame.delegated_frame_data = std::move(frame_data); |
| 102 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 102 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 103 SurfaceFactory::DrawCallback()); | 103 SurfaceFactory::DrawCallback()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void UnrefResources(ResourceId* ids_to_unref, | 106 void UnrefResources(ResourceId* ids_to_unref, |
| 107 int* counts_to_unref, | 107 int* counts_to_unref, |
| 108 size_t num_ids_to_unref) { | 108 size_t num_ids_to_unref) { |
| 109 ReturnedResourceArray unref_array; | 109 ReturnedResourceArray unref_array; |
| 110 for (size_t i = 0; i < num_ids_to_unref; ++i) { | 110 for (size_t i = 0; i < num_ids_to_unref; ++i) { |
| 111 ReturnedResource resource; | 111 ReturnedResource resource; |
| 112 resource.sync_token = consumer_sync_token_; | 112 resource.sync_token = consumer_sync_token_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 127 for (size_t i = 0; i < expected_resources; ++i) { | 127 for (size_t i = 0; i < expected_resources; ++i) { |
| 128 ReturnedResource resource = actual_resources[i]; | 128 ReturnedResource resource = actual_resources[i]; |
| 129 EXPECT_EQ(expected_sync_token, resource.sync_token); | 129 EXPECT_EQ(expected_sync_token, resource.sync_token); |
| 130 EXPECT_EQ(expected_returned_ids[i], resource.id); | 130 EXPECT_EQ(expected_returned_ids[i], resource.id); |
| 131 EXPECT_EQ(expected_returned_counts[i], resource.count); | 131 EXPECT_EQ(expected_returned_counts[i], resource.count); |
| 132 } | 132 } |
| 133 client_.clear_returned_resources(); | 133 client_.clear_returned_resources(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void RefCurrentFrameResources() { | 136 void RefCurrentFrameResources() { |
| 137 Surface* surface = manager_.GetSurfaceForId(surface_id_); | 137 Surface* surface = manager_.GetSurfaceForId( |
| 138 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); |
| 138 factory_->RefResources( | 139 factory_->RefResources( |
| 139 surface->GetEligibleFrame().delegated_frame_data->resource_list); | 140 surface->GetEligibleFrame().delegated_frame_data->resource_list); |
| 140 } | 141 } |
| 141 | 142 |
| 142 protected: | 143 protected: |
| 143 SurfaceManager manager_; | 144 SurfaceManager manager_; |
| 144 TestSurfaceFactoryClient client_; | 145 TestSurfaceFactoryClient client_; |
| 145 std::unique_ptr<SurfaceFactory> factory_; | 146 std::unique_ptr<SurfaceFactory> factory_; |
| 146 SurfaceId surface_id_; | 147 LocalFrameId local_frame_id_; |
| 147 | 148 |
| 148 // This is the sync token submitted with the frame. It should never be | 149 // This is the sync token submitted with the frame. It should never be |
| 149 // returned to the client. | 150 // returned to the client. |
| 150 const gpu::SyncToken frame_sync_token_; | 151 const gpu::SyncToken frame_sync_token_; |
| 151 | 152 |
| 152 // This is the sync token returned by the consumer. It should always be | 153 // This is the sync token returned by the consumer. It should always be |
| 153 // returned to the client. | 154 // returned to the client. |
| 154 const gpu::SyncToken consumer_sync_token_; | 155 const gpu::SyncToken consumer_sync_token_; |
| 155 }; | 156 }; |
| 156 | 157 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 SCOPED_TRACE("fourth frame, second unref"); | 416 SCOPED_TRACE("fourth frame, second unref"); |
| 416 ResourceId expected_returned_ids[] = {12, 13}; | 417 ResourceId expected_returned_ids[] = {12, 13}; |
| 417 int expected_returned_counts[] = {2, 2}; | 418 int expected_returned_counts[] = {2, 2}; |
| 418 CheckReturnedResourcesMatchExpected( | 419 CheckReturnedResourcesMatchExpected( |
| 419 expected_returned_ids, expected_returned_counts, | 420 expected_returned_ids, expected_returned_counts, |
| 420 arraysize(expected_returned_counts), consumer_sync_token_); | 421 arraysize(expected_returned_counts), consumer_sync_token_); |
| 421 } | 422 } |
| 422 } | 423 } |
| 423 | 424 |
| 424 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 425 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
| 425 SurfaceId surface_id(kArbitraryFrameSinkId, 6, 0); | 426 LocalFrameId local_frame_id(6, 0); |
| 426 factory_->Create(surface_id); | 427 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); |
| 428 factory_->Create(local_frame_id); |
| 427 Surface* surface = manager_.GetSurfaceForId(surface_id); | 429 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 428 ASSERT_NE(nullptr, surface); | 430 ASSERT_NE(nullptr, surface); |
| 429 EXPECT_EQ(2, surface->frame_index()); | 431 EXPECT_EQ(2, surface->frame_index()); |
| 430 CompositorFrame frame; | 432 CompositorFrame frame; |
| 431 frame.delegated_frame_data.reset(new DelegatedFrameData); | 433 frame.delegated_frame_data.reset(new DelegatedFrameData); |
| 432 | 434 |
| 433 factory_->SubmitCompositorFrame(surface_id, std::move(frame), | 435 factory_->SubmitCompositorFrame(local_frame_id, std::move(frame), |
| 434 SurfaceFactory::DrawCallback()); | 436 SurfaceFactory::DrawCallback()); |
| 435 EXPECT_EQ(2, surface->frame_index()); | 437 EXPECT_EQ(2, surface->frame_index()); |
| 436 factory_->Destroy(surface_id); | 438 factory_->Destroy(local_frame_id); |
| 437 } | 439 } |
| 438 | 440 |
| 439 void CreateSurfaceDrawCallback(SurfaceFactory* factory, | 441 void CreateSurfaceDrawCallback(SurfaceFactory* factory, |
| 440 uint32_t* execute_count) { | 442 uint32_t* execute_count) { |
| 441 SurfaceId new_id(kArbitraryFrameSinkId, 7, 0); | 443 LocalFrameId new_id(7, 0); |
| 442 factory->Create(new_id); | 444 factory->Create(new_id); |
| 443 factory->Destroy(new_id); | 445 factory->Destroy(new_id); |
| 444 *execute_count += 1; | 446 *execute_count += 1; |
| 445 } | 447 } |
| 446 | 448 |
| 447 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { | 449 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { |
| 448 SurfaceId surface_id(kArbitraryFrameSinkId, 6, 0); | 450 LocalFrameId local_frame_id(6, 0); |
| 449 factory_->Create(surface_id); | 451 factory_->Create(local_frame_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 factory_->SubmitCompositorFrame( | 456 factory_->SubmitCompositorFrame( |
| 455 surface_id, std::move(frame), | 457 local_frame_id, std::move(frame), |
| 456 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), | 458 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), |
| 457 &execute_count)); | 459 &execute_count)); |
| 458 EXPECT_EQ(0u, execute_count); | 460 EXPECT_EQ(0u, execute_count); |
| 459 factory_->Destroy(surface_id); | 461 factory_->Destroy(local_frame_id); |
| 460 EXPECT_EQ(1u, execute_count); | 462 EXPECT_EQ(1u, execute_count); |
| 461 } | 463 } |
| 462 | 464 |
| 463 void DrawCallback(uint32_t* execute_count) { | 465 void DrawCallback(uint32_t* execute_count) { |
| 464 *execute_count += 1; | 466 *execute_count += 1; |
| 465 } | 467 } |
| 466 | 468 |
| 467 // Tests doing a DestroyAll before shutting down the factory; | 469 // Tests doing a DestroyAll before shutting down the factory; |
| 468 TEST_F(SurfaceFactoryTest, DestroyAll) { | 470 TEST_F(SurfaceFactoryTest, DestroyAll) { |
| 469 SurfaceId id(kArbitraryFrameSinkId, 7, 0); | 471 LocalFrameId id(7, 0); |
| 470 factory_->Create(id); | 472 factory_->Create(id); |
| 471 | 473 |
| 472 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 474 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 473 TransferableResource resource; | 475 TransferableResource resource; |
| 474 resource.id = 1; | 476 resource.id = 1; |
| 475 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 477 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 476 frame_data->resource_list.push_back(resource); | 478 frame_data->resource_list.push_back(resource); |
| 477 CompositorFrame frame; | 479 CompositorFrame frame; |
| 478 frame.delegated_frame_data = std::move(frame_data); | 480 frame.delegated_frame_data = std::move(frame_data); |
| 479 uint32_t execute_count = 0; | 481 uint32_t execute_count = 0; |
| 480 factory_->SubmitCompositorFrame(id, std::move(frame), | 482 factory_->SubmitCompositorFrame(id, std::move(frame), |
| 481 base::Bind(&DrawCallback, &execute_count)); | 483 base::Bind(&DrawCallback, &execute_count)); |
| 482 | 484 |
| 483 surface_id_ = SurfaceId(); | 485 local_frame_id_ = LocalFrameId(); |
| 484 factory_->DestroyAll(); | 486 factory_->DestroyAll(); |
| 485 EXPECT_EQ(1u, execute_count); | 487 EXPECT_EQ(1u, execute_count); |
| 486 } | 488 } |
| 487 | 489 |
| 488 TEST_F(SurfaceFactoryTest, DestroySequence) { | 490 TEST_F(SurfaceFactoryTest, DestroySequence) { |
| 489 SurfaceId id2(kArbitraryFrameSinkId, 5, 0); | 491 LocalFrameId local_frame_id2(5, 0); |
| 490 factory_->Create(id2); | 492 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); |
| 493 factory_->Create(local_frame_id2); |
| 491 | 494 |
| 492 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); | 495 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); |
| 493 | 496 |
| 494 // Check that waiting before the sequence is satisfied works. | 497 // Check that waiting before the sequence is satisfied works. |
| 495 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 498 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 496 SurfaceSequence(kArbitraryFrameSinkId, 4)); | 499 SurfaceSequence(kArbitraryFrameSinkId, 4)); |
| 497 factory_->Destroy(id2); | 500 factory_->Destroy(local_frame_id2); |
| 498 | 501 |
| 499 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 502 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 500 CompositorFrame frame; | 503 CompositorFrame frame; |
| 501 frame.metadata.satisfies_sequences.push_back(6); | 504 frame.metadata.satisfies_sequences.push_back(6); |
| 502 frame.metadata.satisfies_sequences.push_back(4); | 505 frame.metadata.satisfies_sequences.push_back(4); |
| 503 frame.delegated_frame_data = std::move(frame_data); | 506 frame.delegated_frame_data = std::move(frame_data); |
| 504 DCHECK(manager_.GetSurfaceForId(id2)); | 507 DCHECK(manager_.GetSurfaceForId(id2)); |
| 505 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 508 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 506 SurfaceFactory::DrawCallback()); | 509 SurfaceFactory::DrawCallback()); |
| 507 DCHECK(!manager_.GetSurfaceForId(id2)); | 510 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 508 | 511 |
| 509 // Check that waiting after the sequence is satisfied works. | 512 // Check that waiting after the sequence is satisfied works. |
| 510 factory_->Create(id2); | 513 factory_->Create(local_frame_id2); |
| 511 DCHECK(manager_.GetSurfaceForId(id2)); | 514 DCHECK(manager_.GetSurfaceForId(id2)); |
| 512 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 515 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 513 SurfaceSequence(FrameSinkId(0, 0), 6)); | 516 SurfaceSequence(FrameSinkId(0, 0), 6)); |
| 514 factory_->Destroy(id2); | 517 factory_->Destroy(local_frame_id2); |
| 515 DCHECK(!manager_.GetSurfaceForId(id2)); | 518 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 516 } | 519 } |
| 517 | 520 |
| 518 // Tests that Surface ID namespace invalidation correctly allows | 521 // Tests that Surface ID namespace invalidation correctly allows |
| 519 // Sequences to be ignored. | 522 // Sequences to be ignored. |
| 520 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { | 523 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { |
| 521 FrameSinkId frame_sink_id(1234, 5678); | 524 FrameSinkId frame_sink_id(1234, 5678); |
| 522 | 525 |
| 523 SurfaceId id(factory_->frame_sink_id(), 5, 0); | 526 LocalFrameId local_frame_id(5, 0); |
| 524 factory_->Create(id); | 527 SurfaceId id(factory_->frame_sink_id(), local_frame_id); |
| 528 factory_->Create(local_frame_id); |
| 525 | 529 |
| 526 manager_.RegisterFrameSinkId(frame_sink_id); | 530 manager_.RegisterFrameSinkId(frame_sink_id); |
| 527 manager_.GetSurfaceForId(id)->AddDestructionDependency( | 531 manager_.GetSurfaceForId(id)->AddDestructionDependency( |
| 528 SurfaceSequence(frame_sink_id, 4)); | 532 SurfaceSequence(frame_sink_id, 4)); |
| 529 factory_->Destroy(id); | 533 factory_->Destroy(local_frame_id); |
| 530 | 534 |
| 531 // Verify the dependency has prevented the surface from getting destroyed. | 535 // Verify the dependency has prevented the surface from getting destroyed. |
| 532 EXPECT_TRUE(manager_.GetSurfaceForId(id)); | 536 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
| 533 | 537 |
| 534 manager_.InvalidateFrameSinkId(frame_sink_id); | 538 manager_.InvalidateFrameSinkId(frame_sink_id); |
| 535 | 539 |
| 536 // Verify that the invalidated namespace caused the unsatisfied sequence | 540 // Verify that the invalidated namespace caused the unsatisfied sequence |
| 537 // to be ignored. | 541 // to be ignored. |
| 538 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 542 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
| 539 } | 543 } |
| 540 | 544 |
| 541 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 545 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
| 542 SurfaceId id2(kArbitraryFrameSinkId, 5, 0); | 546 LocalFrameId local_frame_id2(5, 0); |
| 543 factory_->Create(id2); | 547 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); |
| 548 factory_->Create(local_frame_id2); |
| 544 | 549 |
| 545 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); | 550 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); |
| 546 | 551 |
| 547 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 552 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 548 SurfaceSequence(FrameSinkId(0, 0), 4)); | 553 SurfaceSequence(FrameSinkId(0, 0), 4)); |
| 549 | 554 |
| 550 // Give id2 a frame that references surface_id_. | 555 // Give id2 a frame that references local_frame_id_. |
| 551 { | 556 { |
| 552 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 557 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 553 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 558 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 554 frame_data->render_pass_list.push_back(std::move(render_pass)); | 559 frame_data->render_pass_list.push_back(std::move(render_pass)); |
| 555 CompositorFrame frame; | 560 CompositorFrame frame; |
| 556 frame.metadata.referenced_surfaces.push_back(surface_id_); | 561 frame.metadata.referenced_surfaces.push_back( |
| 562 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); |
| 557 frame.delegated_frame_data = std::move(frame_data); | 563 frame.delegated_frame_data = std::move(frame_data); |
| 558 factory_->SubmitCompositorFrame(id2, std::move(frame), | 564 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), |
| 559 SurfaceFactory::DrawCallback()); | 565 SurfaceFactory::DrawCallback()); |
| 560 } | 566 } |
| 561 factory_->Destroy(id2); | 567 factory_->Destroy(local_frame_id2); |
| 562 | 568 |
| 563 // Give surface_id_ a frame that references id2. | 569 // Give local_frame_id_ a frame that references id2. |
| 564 { | 570 { |
| 565 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 571 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 566 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 572 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 567 frame_data->render_pass_list.push_back(std::move(render_pass)); | 573 frame_data->render_pass_list.push_back(std::move(render_pass)); |
| 568 CompositorFrame frame; | 574 CompositorFrame frame; |
| 569 frame.metadata.referenced_surfaces.push_back(id2); | 575 frame.metadata.referenced_surfaces.push_back(id2); |
| 570 frame.delegated_frame_data = std::move(frame_data); | 576 frame.delegated_frame_data = std::move(frame_data); |
| 571 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 577 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 572 SurfaceFactory::DrawCallback()); | 578 SurfaceFactory::DrawCallback()); |
| 573 } | 579 } |
| 574 factory_->Destroy(surface_id_); | 580 factory_->Destroy(local_frame_id_); |
| 575 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); | 581 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); |
| 576 // surface_id_ should be retained by reference from id2. | 582 // local_frame_id_ should be retained by reference from id2. |
| 577 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id_)); | 583 EXPECT_TRUE(manager_.GetSurfaceForId( |
| 584 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); |
| 578 | 585 |
| 579 // Satisfy last destruction dependency for id2. | 586 // Satisfy last destruction dependency for id2. |
| 580 std::vector<uint32_t> to_satisfy; | 587 std::vector<uint32_t> to_satisfy; |
| 581 to_satisfy.push_back(4); | 588 to_satisfy.push_back(4); |
| 582 manager_.DidSatisfySequences(FrameSinkId(0, 0), &to_satisfy); | 589 manager_.DidSatisfySequences(FrameSinkId(0, 0), &to_satisfy); |
| 583 | 590 |
| 584 // id2 and surface_id_ are in a reference cycle that has no surface | 591 // id2 and local_frame_id_ are in a reference cycle that has no surface |
| 585 // sequences holding on to it, so they should be destroyed. | 592 // sequences holding on to it, so they should be destroyed. |
| 586 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); | 593 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); |
| 587 EXPECT_TRUE(!manager_.GetSurfaceForId(surface_id_)); | 594 EXPECT_TRUE(!manager_.GetSurfaceForId( |
| 595 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); |
| 588 | 596 |
| 589 surface_id_ = SurfaceId(); | 597 local_frame_id_ = LocalFrameId(); |
| 590 } | 598 } |
| 591 | 599 |
| 592 void CopyRequestTestCallback(bool* called, | 600 void CopyRequestTestCallback(bool* called, |
| 593 std::unique_ptr<CopyOutputResult> result) { | 601 std::unique_ptr<CopyOutputResult> result) { |
| 594 *called = true; | 602 *called = true; |
| 595 } | 603 } |
| 596 | 604 |
| 597 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { | 605 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { |
| 598 { | 606 { |
| 599 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 607 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 600 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 608 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 601 frame_data->render_pass_list.push_back(std::move(render_pass)); | 609 frame_data->render_pass_list.push_back(std::move(render_pass)); |
| 602 CompositorFrame frame; | 610 CompositorFrame frame; |
| 603 frame.metadata.referenced_surfaces.push_back(surface_id_); | 611 frame.metadata.referenced_surfaces.push_back( |
| 612 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); |
| 604 frame.delegated_frame_data = std::move(frame_data); | 613 frame.delegated_frame_data = std::move(frame_data); |
| 605 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 614 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 606 SurfaceFactory::DrawCallback()); | 615 SurfaceFactory::DrawCallback()); |
| 607 } | 616 } |
| 608 void* source1 = &source1; | 617 void* source1 = &source1; |
| 609 void* source2 = &source2; | 618 void* source2 = &source2; |
| 610 | 619 |
| 611 bool called1 = false; | 620 bool called1 = false; |
| 612 std::unique_ptr<CopyOutputRequest> request; | 621 std::unique_ptr<CopyOutputRequest> request; |
| 613 request = CopyOutputRequest::CreateRequest( | 622 request = CopyOutputRequest::CreateRequest( |
| 614 base::Bind(&CopyRequestTestCallback, &called1)); | 623 base::Bind(&CopyRequestTestCallback, &called1)); |
| 615 request->set_source(source1); | 624 request->set_source(source1); |
| 616 | 625 |
| 617 factory_->RequestCopyOfSurface(surface_id_, std::move(request)); | 626 factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); |
| 618 EXPECT_FALSE(called1); | 627 EXPECT_FALSE(called1); |
| 619 | 628 |
| 620 bool called2 = false; | 629 bool called2 = false; |
| 621 request = CopyOutputRequest::CreateRequest( | 630 request = CopyOutputRequest::CreateRequest( |
| 622 base::Bind(&CopyRequestTestCallback, &called2)); | 631 base::Bind(&CopyRequestTestCallback, &called2)); |
| 623 request->set_source(source2); | 632 request->set_source(source2); |
| 624 | 633 |
| 625 factory_->RequestCopyOfSurface(surface_id_, std::move(request)); | 634 factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); |
| 626 // Callbacks have different sources so neither should be called. | 635 // Callbacks have different sources so neither should be called. |
| 627 EXPECT_FALSE(called1); | 636 EXPECT_FALSE(called1); |
| 628 EXPECT_FALSE(called2); | 637 EXPECT_FALSE(called2); |
| 629 | 638 |
| 630 bool called3 = false; | 639 bool called3 = false; |
| 631 request = CopyOutputRequest::CreateRequest( | 640 request = CopyOutputRequest::CreateRequest( |
| 632 base::Bind(&CopyRequestTestCallback, &called3)); | 641 base::Bind(&CopyRequestTestCallback, &called3)); |
| 633 request->set_source(source1); | 642 request->set_source(source1); |
| 634 | 643 |
| 635 factory_->RequestCopyOfSurface(surface_id_, std::move(request)); | 644 factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); |
| 636 // Two callbacks are from source1, so the first should be called. | 645 // Two callbacks are from source1, so the first should be called. |
| 637 EXPECT_TRUE(called1); | 646 EXPECT_TRUE(called1); |
| 638 EXPECT_FALSE(called2); | 647 EXPECT_FALSE(called2); |
| 639 EXPECT_FALSE(called3); | 648 EXPECT_FALSE(called3); |
| 640 | 649 |
| 641 factory_->Destroy(surface_id_); | 650 factory_->Destroy(local_frame_id_); |
| 642 surface_id_ = SurfaceId(); | 651 local_frame_id_ = LocalFrameId(); |
| 643 EXPECT_TRUE(called1); | 652 EXPECT_TRUE(called1); |
| 644 EXPECT_TRUE(called2); | 653 EXPECT_TRUE(called2); |
| 645 EXPECT_TRUE(called3); | 654 EXPECT_TRUE(called3); |
| 646 } | 655 } |
| 647 | 656 |
| 648 } // namespace | 657 } // namespace |
| 649 } // namespace cc | 658 } // namespace cc |
| OLD | NEW |