| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, | 66 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, |
| 67 gpu::CommandBufferId::FromUnsafeValue(id), 1); | 67 gpu::CommandBufferId::FromUnsafeValue(id), 1); |
| 68 return token; | 68 return token; |
| 69 } | 69 } |
| 70 | 70 |
| 71 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { | 71 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { |
| 72 public: | 72 public: |
| 73 SurfaceFactoryTest() | 73 SurfaceFactoryTest() |
| 74 : factory_( | 74 : factory_( |
| 75 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), | 75 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), |
| 76 local_frame_id_(3, kArbitraryToken), | 76 local_surface_id_(3, kArbitraryToken), |
| 77 frame_sync_token_(GenTestSyncToken(4)), | 77 frame_sync_token_(GenTestSyncToken(4)), |
| 78 consumer_sync_token_(GenTestSyncToken(5)) { | 78 consumer_sync_token_(GenTestSyncToken(5)) { |
| 79 manager_.AddObserver(this); | 79 manager_.AddObserver(this); |
| 80 } | 80 } |
| 81 | 81 |
| 82 const SurfaceId& last_created_surface_id() const { | 82 const SurfaceId& last_created_surface_id() const { |
| 83 return last_created_surface_id_; | 83 return last_created_surface_id_; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // SurfaceObserver implementation. | 86 // SurfaceObserver implementation. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 102 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 102 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
| 103 size_t num_resource_ids) { | 103 size_t num_resource_ids) { |
| 104 CompositorFrame frame; | 104 CompositorFrame frame; |
| 105 for (size_t i = 0u; i < num_resource_ids; ++i) { | 105 for (size_t i = 0u; i < num_resource_ids; ++i) { |
| 106 TransferableResource resource; | 106 TransferableResource resource; |
| 107 resource.id = resource_ids[i]; | 107 resource.id = resource_ids[i]; |
| 108 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 108 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 109 resource.mailbox_holder.sync_token = frame_sync_token_; | 109 resource.mailbox_holder.sync_token = frame_sync_token_; |
| 110 frame.resource_list.push_back(resource); | 110 frame.resource_list.push_back(resource); |
| 111 } | 111 } |
| 112 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 112 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame), |
| 113 SurfaceFactory::DrawCallback()); | 113 SurfaceFactory::DrawCallback()); |
| 114 EXPECT_EQ(last_created_surface_id_.local_frame_id(), local_frame_id_); | 114 EXPECT_EQ(last_created_surface_id_.local_surface_id(), local_surface_id_); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void UnrefResources(ResourceId* ids_to_unref, | 117 void UnrefResources(ResourceId* ids_to_unref, |
| 118 int* counts_to_unref, | 118 int* counts_to_unref, |
| 119 size_t num_ids_to_unref) { | 119 size_t num_ids_to_unref) { |
| 120 ReturnedResourceArray unref_array; | 120 ReturnedResourceArray unref_array; |
| 121 for (size_t i = 0; i < num_ids_to_unref; ++i) { | 121 for (size_t i = 0; i < num_ids_to_unref; ++i) { |
| 122 ReturnedResource resource; | 122 ReturnedResource resource; |
| 123 resource.sync_token = consumer_sync_token_; | 123 resource.sync_token = consumer_sync_token_; |
| 124 resource.id = ids_to_unref[i]; | 124 resource.id = ids_to_unref[i]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 139 ReturnedResource resource = actual_resources[i]; | 139 ReturnedResource resource = actual_resources[i]; |
| 140 EXPECT_EQ(expected_sync_token, resource.sync_token); | 140 EXPECT_EQ(expected_sync_token, resource.sync_token); |
| 141 EXPECT_EQ(expected_returned_ids[i], resource.id); | 141 EXPECT_EQ(expected_returned_ids[i], resource.id); |
| 142 EXPECT_EQ(expected_returned_counts[i], resource.count); | 142 EXPECT_EQ(expected_returned_counts[i], resource.count); |
| 143 } | 143 } |
| 144 client_.clear_returned_resources(); | 144 client_.clear_returned_resources(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void RefCurrentFrameResources() { | 147 void RefCurrentFrameResources() { |
| 148 Surface* surface = manager_.GetSurfaceForId( | 148 Surface* surface = manager_.GetSurfaceForId( |
| 149 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); | 149 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); |
| 150 factory_->RefResources(surface->GetEligibleFrame().resource_list); | 150 factory_->RefResources(surface->GetEligibleFrame().resource_list); |
| 151 } | 151 } |
| 152 | 152 |
| 153 protected: | 153 protected: |
| 154 SurfaceManager manager_; | 154 SurfaceManager manager_; |
| 155 TestSurfaceFactoryClient client_; | 155 TestSurfaceFactoryClient client_; |
| 156 std::unique_ptr<SurfaceFactory> factory_; | 156 std::unique_ptr<SurfaceFactory> factory_; |
| 157 LocalFrameId local_frame_id_; | 157 LocalSurfaceId local_surface_id_; |
| 158 SurfaceId last_created_surface_id_; | 158 SurfaceId last_created_surface_id_; |
| 159 SurfaceInfo last_surface_info_; | 159 SurfaceInfo last_surface_info_; |
| 160 | 160 |
| 161 // This is the sync token submitted with the frame. It should never be | 161 // This is the sync token submitted with the frame. It should never be |
| 162 // returned to the client. | 162 // returned to the client. |
| 163 const gpu::SyncToken frame_sync_token_; | 163 const gpu::SyncToken frame_sync_token_; |
| 164 | 164 |
| 165 // This is the sync token returned by the consumer. It should always be | 165 // This is the sync token returned by the consumer. It should always be |
| 166 // returned to the client. | 166 // returned to the client. |
| 167 const gpu::SyncToken consumer_sync_token_; | 167 const gpu::SyncToken consumer_sync_token_; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 SCOPED_TRACE("fourth frame, second unref"); | 428 SCOPED_TRACE("fourth frame, second unref"); |
| 429 ResourceId expected_returned_ids[] = {12, 13}; | 429 ResourceId expected_returned_ids[] = {12, 13}; |
| 430 int expected_returned_counts[] = {2, 2}; | 430 int expected_returned_counts[] = {2, 2}; |
| 431 CheckReturnedResourcesMatchExpected( | 431 CheckReturnedResourcesMatchExpected( |
| 432 expected_returned_ids, expected_returned_counts, | 432 expected_returned_ids, expected_returned_counts, |
| 433 arraysize(expected_returned_counts), consumer_sync_token_); | 433 arraysize(expected_returned_counts), consumer_sync_token_); |
| 434 } | 434 } |
| 435 } | 435 } |
| 436 | 436 |
| 437 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 437 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
| 438 LocalFrameId local_frame_id(6, kArbitraryToken); | 438 LocalSurfaceId local_surface_id(6, kArbitraryToken); |
| 439 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); | 439 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); |
| 440 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), | 440 factory_->SubmitCompositorFrame(local_surface_id, CompositorFrame(), |
| 441 SurfaceFactory::DrawCallback()); | 441 SurfaceFactory::DrawCallback()); |
| 442 Surface* surface = manager_.GetSurfaceForId(surface_id); | 442 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 443 ASSERT_NE(nullptr, surface); | 443 ASSERT_NE(nullptr, surface); |
| 444 EXPECT_EQ(2, surface->frame_index()); | 444 EXPECT_EQ(2, surface->frame_index()); |
| 445 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); | 445 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); |
| 446 } | 446 } |
| 447 | 447 |
| 448 void CreateSurfaceDrawCallback(SurfaceFactory* factory, | 448 void CreateSurfaceDrawCallback(SurfaceFactory* factory, |
| 449 uint32_t* execute_count) { | 449 uint32_t* execute_count) { |
| 450 LocalFrameId new_id(7, base::UnguessableToken::Create()); | 450 LocalSurfaceId new_id(7, base::UnguessableToken::Create()); |
| 451 factory->SubmitCompositorFrame(new_id, CompositorFrame(), | 451 factory->SubmitCompositorFrame(new_id, CompositorFrame(), |
| 452 SurfaceFactory::DrawCallback()); | 452 SurfaceFactory::DrawCallback()); |
| 453 factory->EvictSurface(); | 453 factory->EvictSurface(); |
| 454 *execute_count += 1; | 454 *execute_count += 1; |
| 455 } | 455 } |
| 456 | 456 |
| 457 TEST_F(SurfaceFactoryTest, AddDuringEviction) { | 457 TEST_F(SurfaceFactoryTest, AddDuringEviction) { |
| 458 LocalFrameId local_frame_id(6, kArbitraryToken); | 458 LocalSurfaceId local_surface_id(6, kArbitraryToken); |
| 459 | 459 |
| 460 uint32_t execute_count = 0; | 460 uint32_t execute_count = 0; |
| 461 factory_->SubmitCompositorFrame( | 461 factory_->SubmitCompositorFrame( |
| 462 local_frame_id, CompositorFrame(), | 462 local_surface_id, CompositorFrame(), |
| 463 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), | 463 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), |
| 464 &execute_count)); | 464 &execute_count)); |
| 465 EXPECT_EQ(0u, execute_count); | 465 EXPECT_EQ(0u, execute_count); |
| 466 factory_->EvictSurface(); | 466 factory_->EvictSurface(); |
| 467 EXPECT_EQ(1u, execute_count); | 467 EXPECT_EQ(1u, execute_count); |
| 468 } | 468 } |
| 469 | 469 |
| 470 void DrawCallback(uint32_t* execute_count) { | 470 void DrawCallback(uint32_t* execute_count) { |
| 471 *execute_count += 1; | 471 *execute_count += 1; |
| 472 } | 472 } |
| 473 | 473 |
| 474 // Tests doing an EvictSurface before shutting down the factory. | 474 // Tests doing an EvictSurface before shutting down the factory. |
| 475 TEST_F(SurfaceFactoryTest, EvictSurface) { | 475 TEST_F(SurfaceFactoryTest, EvictSurface) { |
| 476 LocalFrameId id(7, kArbitraryToken); | 476 LocalSurfaceId id(7, kArbitraryToken); |
| 477 | 477 |
| 478 TransferableResource resource; | 478 TransferableResource resource; |
| 479 resource.id = 1; | 479 resource.id = 1; |
| 480 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 480 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 481 CompositorFrame frame; | 481 CompositorFrame frame; |
| 482 frame.resource_list.push_back(resource); | 482 frame.resource_list.push_back(resource); |
| 483 uint32_t execute_count = 0; | 483 uint32_t execute_count = 0; |
| 484 factory_->SubmitCompositorFrame(id, std::move(frame), | 484 factory_->SubmitCompositorFrame(id, std::move(frame), |
| 485 base::Bind(&DrawCallback, &execute_count)); | 485 base::Bind(&DrawCallback, &execute_count)); |
| 486 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); | 486 EXPECT_EQ(last_created_surface_id().local_surface_id(), id); |
| 487 local_frame_id_ = LocalFrameId(); | 487 local_surface_id_ = LocalSurfaceId(); |
| 488 factory_->EvictSurface(); | 488 factory_->EvictSurface(); |
| 489 EXPECT_EQ(1u, execute_count); | 489 EXPECT_EQ(1u, execute_count); |
| 490 } | 490 } |
| 491 | 491 |
| 492 // Tests that SurfaceFactory doesn't return resources after Reset(). | 492 // Tests that SurfaceFactory doesn't return resources after Reset(). |
| 493 TEST_F(SurfaceFactoryTest, Reset) { | 493 TEST_F(SurfaceFactoryTest, Reset) { |
| 494 LocalFrameId id(7, kArbitraryToken); | 494 LocalSurfaceId id(7, kArbitraryToken); |
| 495 | 495 |
| 496 TransferableResource resource; | 496 TransferableResource resource; |
| 497 resource.id = 1; | 497 resource.id = 1; |
| 498 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 498 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 499 CompositorFrame frame; | 499 CompositorFrame frame; |
| 500 frame.resource_list.push_back(resource); | 500 frame.resource_list.push_back(resource); |
| 501 factory_->SubmitCompositorFrame(id, std::move(frame), | 501 factory_->SubmitCompositorFrame(id, std::move(frame), |
| 502 SurfaceFactory::DrawCallback()); | 502 SurfaceFactory::DrawCallback()); |
| 503 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); | 503 EXPECT_EQ(last_created_surface_id().local_surface_id(), id); |
| 504 | 504 |
| 505 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); | 505 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); |
| 506 | 506 |
| 507 SurfaceId surface_id(kArbitraryFrameSinkId, id); | 507 SurfaceId surface_id(kArbitraryFrameSinkId, id); |
| 508 Surface* surface = manager_.GetSurfaceForId(surface_id); | 508 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 509 surface->AddDestructionDependency( | 509 surface->AddDestructionDependency( |
| 510 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); | 510 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| 511 factory_->Reset(); | 511 factory_->Reset(); |
| 512 EXPECT_TRUE(client_.returned_resources().empty()); | 512 EXPECT_TRUE(client_.returned_resources().empty()); |
| 513 | 513 |
| 514 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); | 514 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| 515 EXPECT_TRUE(client_.returned_resources().empty()); | 515 EXPECT_TRUE(client_.returned_resources().empty()); |
| 516 local_frame_id_ = LocalFrameId(); | 516 local_surface_id_ = LocalSurfaceId(); |
| 517 } | 517 } |
| 518 | 518 |
| 519 TEST_F(SurfaceFactoryTest, DestroySequence) { | 519 TEST_F(SurfaceFactoryTest, DestroySequence) { |
| 520 LocalFrameId local_frame_id2(5, kArbitraryToken); | 520 LocalSurfaceId local_surface_id2(5, kArbitraryToken); |
| 521 std::unique_ptr<SurfaceFactory> factory2( | 521 std::unique_ptr<SurfaceFactory> factory2( |
| 522 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); | 522 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); |
| 523 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); | 523 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); |
| 524 factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(), | 524 factory2->SubmitCompositorFrame(local_surface_id2, CompositorFrame(), |
| 525 SurfaceFactory::DrawCallback()); | 525 SurfaceFactory::DrawCallback()); |
| 526 | 526 |
| 527 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); | 527 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); |
| 528 | 528 |
| 529 // Check that waiting before the sequence is satisfied works. | 529 // Check that waiting before the sequence is satisfied works. |
| 530 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 530 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 531 SurfaceSequence(kArbitraryFrameSinkId, 4)); | 531 SurfaceSequence(kArbitraryFrameSinkId, 4)); |
| 532 factory2->EvictSurface(); | 532 factory2->EvictSurface(); |
| 533 | 533 |
| 534 CompositorFrame frame; | 534 CompositorFrame frame; |
| 535 DCHECK(manager_.GetSurfaceForId(id2)); | 535 DCHECK(manager_.GetSurfaceForId(id2)); |
| 536 manager_.SatisfySequence(SurfaceSequence(kArbitraryFrameSinkId, 4)); | 536 manager_.SatisfySequence(SurfaceSequence(kArbitraryFrameSinkId, 4)); |
| 537 manager_.SatisfySequence(SurfaceSequence(kArbitraryFrameSinkId, 6)); | 537 manager_.SatisfySequence(SurfaceSequence(kArbitraryFrameSinkId, 6)); |
| 538 DCHECK(!manager_.GetSurfaceForId(id2)); | 538 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 539 | 539 |
| 540 // Check that waiting after the sequence is satisfied works. | 540 // Check that waiting after the sequence is satisfied works. |
| 541 factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(), | 541 factory2->SubmitCompositorFrame(local_surface_id2, CompositorFrame(), |
| 542 SurfaceFactory::DrawCallback()); | 542 SurfaceFactory::DrawCallback()); |
| 543 DCHECK(manager_.GetSurfaceForId(id2)); | 543 DCHECK(manager_.GetSurfaceForId(id2)); |
| 544 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 544 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 545 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6)); | 545 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6)); |
| 546 factory2->EvictSurface(); | 546 factory2->EvictSurface(); |
| 547 DCHECK(!manager_.GetSurfaceForId(id2)); | 547 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 548 } | 548 } |
| 549 | 549 |
| 550 // Tests that Surface ID namespace invalidation correctly allows | 550 // Tests that Surface ID namespace invalidation correctly allows |
| 551 // Sequences to be ignored. | 551 // Sequences to be ignored. |
| 552 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { | 552 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { |
| 553 FrameSinkId frame_sink_id(1234, 5678); | 553 FrameSinkId frame_sink_id(1234, 5678); |
| 554 | 554 |
| 555 LocalFrameId local_frame_id(5, kArbitraryToken); | 555 LocalSurfaceId local_surface_id(5, kArbitraryToken); |
| 556 SurfaceId id(factory_->frame_sink_id(), local_frame_id); | 556 SurfaceId id(factory_->frame_sink_id(), local_surface_id); |
| 557 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), | 557 factory_->SubmitCompositorFrame(local_surface_id, CompositorFrame(), |
| 558 SurfaceFactory::DrawCallback()); | 558 SurfaceFactory::DrawCallback()); |
| 559 | 559 |
| 560 manager_.RegisterFrameSinkId(frame_sink_id); | 560 manager_.RegisterFrameSinkId(frame_sink_id); |
| 561 manager_.GetSurfaceForId(id)->AddDestructionDependency( | 561 manager_.GetSurfaceForId(id)->AddDestructionDependency( |
| 562 SurfaceSequence(frame_sink_id, 4)); | 562 SurfaceSequence(frame_sink_id, 4)); |
| 563 | 563 |
| 564 factory_->EvictSurface(); | 564 factory_->EvictSurface(); |
| 565 | 565 |
| 566 // Verify the dependency has prevented the surface from getting destroyed. | 566 // Verify the dependency has prevented the surface from getting destroyed. |
| 567 EXPECT_TRUE(manager_.GetSurfaceForId(id)); | 567 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
| 568 | 568 |
| 569 manager_.InvalidateFrameSinkId(frame_sink_id); | 569 manager_.InvalidateFrameSinkId(frame_sink_id); |
| 570 | 570 |
| 571 // Verify that the invalidated namespace caused the unsatisfied sequence | 571 // Verify that the invalidated namespace caused the unsatisfied sequence |
| 572 // to be ignored. | 572 // to be ignored. |
| 573 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 573 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
| 574 } | 574 } |
| 575 | 575 |
| 576 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 576 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
| 577 LocalFrameId local_frame_id2(5, kArbitraryToken); | 577 LocalSurfaceId local_surface_id2(5, kArbitraryToken); |
| 578 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); | 578 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); |
| 579 std::unique_ptr<SurfaceFactory> factory2( | 579 std::unique_ptr<SurfaceFactory> factory2( |
| 580 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); | 580 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); |
| 581 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); | 581 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); |
| 582 // Give id2 a frame that references local_frame_id_. | 582 // Give id2 a frame that references local_surface_id_. |
| 583 { | 583 { |
| 584 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 584 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 585 CompositorFrame frame; | 585 CompositorFrame frame; |
| 586 frame.render_pass_list.push_back(std::move(render_pass)); | 586 frame.render_pass_list.push_back(std::move(render_pass)); |
| 587 frame.metadata.referenced_surfaces.push_back( | 587 frame.metadata.referenced_surfaces.push_back( |
| 588 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); | 588 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); |
| 589 factory2->SubmitCompositorFrame(local_frame_id2, std::move(frame), | 589 factory2->SubmitCompositorFrame(local_surface_id2, std::move(frame), |
| 590 SurfaceFactory::DrawCallback()); | 590 SurfaceFactory::DrawCallback()); |
| 591 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2); | 591 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id2); |
| 592 } | 592 } |
| 593 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 593 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 594 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); | 594 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| 595 factory2->EvictSurface(); | 595 factory2->EvictSurface(); |
| 596 // Give local_frame_id_ a frame that references id2. | 596 // Give local_surface_id_ a frame that references id2. |
| 597 { | 597 { |
| 598 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 598 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 599 CompositorFrame frame; | 599 CompositorFrame frame; |
| 600 frame.render_pass_list.push_back(std::move(render_pass)); | 600 frame.render_pass_list.push_back(std::move(render_pass)); |
| 601 frame.metadata.referenced_surfaces.push_back(id2); | 601 frame.metadata.referenced_surfaces.push_back(id2); |
| 602 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 602 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame), |
| 603 SurfaceFactory::DrawCallback()); | 603 SurfaceFactory::DrawCallback()); |
| 604 } | 604 } |
| 605 factory_->EvictSurface(); | 605 factory_->EvictSurface(); |
| 606 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); | 606 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); |
| 607 // local_frame_id_ should be retained by reference from id2. | 607 // local_surface_id_ should be retained by reference from id2. |
| 608 EXPECT_TRUE(manager_.GetSurfaceForId( | 608 EXPECT_TRUE(manager_.GetSurfaceForId( |
| 609 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); | 609 SurfaceId(factory_->frame_sink_id(), local_surface_id_))); |
| 610 | 610 |
| 611 // Satisfy last destruction dependency for id2. | 611 // Satisfy last destruction dependency for id2. |
| 612 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); | 612 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| 613 | 613 |
| 614 // id2 and local_frame_id_ are in a reference cycle that has no surface | 614 // id2 and local_surface_id_ are in a reference cycle that has no surface |
| 615 // sequences holding on to it, so they should be destroyed. | 615 // sequences holding on to it, so they should be destroyed. |
| 616 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); | 616 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); |
| 617 EXPECT_TRUE(!manager_.GetSurfaceForId( | 617 EXPECT_TRUE(!manager_.GetSurfaceForId( |
| 618 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); | 618 SurfaceId(factory_->frame_sink_id(), local_surface_id_))); |
| 619 | 619 |
| 620 local_frame_id_ = LocalFrameId(); | 620 local_surface_id_ = LocalSurfaceId(); |
| 621 } | 621 } |
| 622 | 622 |
| 623 void CopyRequestTestCallback(bool* called, | 623 void CopyRequestTestCallback(bool* called, |
| 624 std::unique_ptr<CopyOutputResult> result) { | 624 std::unique_ptr<CopyOutputResult> result) { |
| 625 *called = true; | 625 *called = true; |
| 626 } | 626 } |
| 627 | 627 |
| 628 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { | 628 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { |
| 629 { | 629 { |
| 630 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 630 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 631 CompositorFrame frame; | 631 CompositorFrame frame; |
| 632 frame.render_pass_list.push_back(std::move(render_pass)); | 632 frame.render_pass_list.push_back(std::move(render_pass)); |
| 633 frame.metadata.referenced_surfaces.push_back( | 633 frame.metadata.referenced_surfaces.push_back( |
| 634 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); | 634 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); |
| 635 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 635 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame), |
| 636 SurfaceFactory::DrawCallback()); | 636 SurfaceFactory::DrawCallback()); |
| 637 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); | 637 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id_); |
| 638 } | 638 } |
| 639 void* source1 = &source1; | 639 void* source1 = &source1; |
| 640 void* source2 = &source2; | 640 void* source2 = &source2; |
| 641 | 641 |
| 642 bool called1 = false; | 642 bool called1 = false; |
| 643 std::unique_ptr<CopyOutputRequest> request; | 643 std::unique_ptr<CopyOutputRequest> request; |
| 644 request = CopyOutputRequest::CreateRequest( | 644 request = CopyOutputRequest::CreateRequest( |
| 645 base::Bind(&CopyRequestTestCallback, &called1)); | 645 base::Bind(&CopyRequestTestCallback, &called1)); |
| 646 request->set_source(source1); | 646 request->set_source(source1); |
| 647 | 647 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 663 base::Bind(&CopyRequestTestCallback, &called3)); | 663 base::Bind(&CopyRequestTestCallback, &called3)); |
| 664 request->set_source(source1); | 664 request->set_source(source1); |
| 665 | 665 |
| 666 factory_->RequestCopyOfSurface(std::move(request)); | 666 factory_->RequestCopyOfSurface(std::move(request)); |
| 667 // Two callbacks are from source1, so the first should be called. | 667 // Two callbacks are from source1, so the first should be called. |
| 668 EXPECT_TRUE(called1); | 668 EXPECT_TRUE(called1); |
| 669 EXPECT_FALSE(called2); | 669 EXPECT_FALSE(called2); |
| 670 EXPECT_FALSE(called3); | 670 EXPECT_FALSE(called3); |
| 671 | 671 |
| 672 factory_->EvictSurface(); | 672 factory_->EvictSurface(); |
| 673 local_frame_id_ = LocalFrameId(); | 673 local_surface_id_ = LocalSurfaceId(); |
| 674 EXPECT_TRUE(called1); | 674 EXPECT_TRUE(called1); |
| 675 EXPECT_TRUE(called2); | 675 EXPECT_TRUE(called2); |
| 676 EXPECT_TRUE(called3); | 676 EXPECT_TRUE(called3); |
| 677 } | 677 } |
| 678 | 678 |
| 679 // Check whether the SurfaceInfo object is created and populated correctly | 679 // Check whether the SurfaceInfo object is created and populated correctly |
| 680 // after the frame submission. | 680 // after the frame submission. |
| 681 TEST_F(SurfaceFactoryTest, SurfaceInfo) { | 681 TEST_F(SurfaceFactoryTest, SurfaceInfo) { |
| 682 CompositorFrame frame; | 682 CompositorFrame frame; |
| 683 | 683 |
| 684 auto render_pass = RenderPass::Create(); | 684 auto render_pass = RenderPass::Create(); |
| 685 render_pass->SetNew(1, gfx::Rect(5, 6), gfx::Rect(), gfx::Transform()); | 685 render_pass->SetNew(1, gfx::Rect(5, 6), gfx::Rect(), gfx::Transform()); |
| 686 frame.render_pass_list.push_back(std::move(render_pass)); | 686 frame.render_pass_list.push_back(std::move(render_pass)); |
| 687 | 687 |
| 688 render_pass = RenderPass::Create(); | 688 render_pass = RenderPass::Create(); |
| 689 render_pass->SetNew(2, gfx::Rect(7, 8), gfx::Rect(), gfx::Transform()); | 689 render_pass->SetNew(2, gfx::Rect(7, 8), gfx::Rect(), gfx::Transform()); |
| 690 frame.render_pass_list.push_back(std::move(render_pass)); | 690 frame.render_pass_list.push_back(std::move(render_pass)); |
| 691 | 691 |
| 692 frame.metadata.device_scale_factor = 2.5f; | 692 frame.metadata.device_scale_factor = 2.5f; |
| 693 | 693 |
| 694 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 694 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame), |
| 695 SurfaceFactory::DrawCallback()); | 695 SurfaceFactory::DrawCallback()); |
| 696 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_frame_id_); | 696 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_surface_id_); |
| 697 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); | 697 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); |
| 698 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); | 698 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); |
| 699 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); | 699 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); |
| 700 } | 700 } |
| 701 | 701 |
| 702 } // namespace | 702 } // namespace |
| 703 } // namespace cc | 703 } // namespace cc |
| OLD | NEW |