Chromium Code Reviews| Index: cc/surfaces/surface_factory_unittest.cc |
| diff --git a/cc/surfaces/surface_factory_unittest.cc b/cc/surfaces/surface_factory_unittest.cc |
| index 044aeb4b6dc63fe803212a680aee311cf98c9454..873ca4d9396d8cc2ae50a0ed28f30ce0329d3599 100644 |
| --- a/cc/surfaces/surface_factory_unittest.cc |
| +++ b/cc/surfaces/surface_factory_unittest.cc |
| @@ -75,7 +75,6 @@ class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { |
| frame_sync_token_(GenTestSyncToken(4)), |
| consumer_sync_token_(GenTestSyncToken(5)) { |
| manager_.AddObserver(this); |
| - factory_->Create(local_frame_id_); |
| } |
| const SurfaceId& last_created_surface_id() const { |
| @@ -95,8 +94,6 @@ class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { |
| } |
| ~SurfaceFactoryTest() override { |
| - if (local_frame_id_.is_valid()) |
| - factory_->Destroy(local_frame_id_); |
| manager_.RemoveObserver(this); |
| } |
| @@ -437,76 +434,25 @@ TEST_F(SurfaceFactoryTest, ResourceLifetime) { |
| TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
| LocalFrameId local_frame_id(6, kArbitraryToken); |
| SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); |
| - factory_->Create(local_frame_id); |
| - Surface* surface = manager_.GetSurfaceForId(surface_id); |
| - ASSERT_NE(nullptr, surface); |
| - EXPECT_EQ(2, surface->frame_index()); |
| - |
| factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), |
| SurfaceFactory::DrawCallback()); |
| + Surface* surface = manager_.GetSurfaceForId(surface_id); |
| + ASSERT_NE(nullptr, surface); |
| EXPECT_EQ(2, surface->frame_index()); |
| EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); |
| - factory_->Destroy(local_frame_id); |
| -} |
| - |
| -void CreateSurfaceDrawCallback(SurfaceFactory* factory, |
| - uint32_t* execute_count) { |
| - LocalFrameId new_id(7, base::UnguessableToken::Create()); |
| - factory->Create(new_id); |
| - factory->Destroy(new_id); |
| - *execute_count += 1; |
| -} |
| - |
| -TEST_F(SurfaceFactoryTest, AddDuringDestroy) { |
| - LocalFrameId local_frame_id(6, kArbitraryToken); |
| - factory_->Create(local_frame_id); |
| - |
| - uint32_t execute_count = 0; |
| - factory_->SubmitCompositorFrame( |
| - local_frame_id, CompositorFrame(), |
| - base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), |
| - &execute_count)); |
| - EXPECT_EQ(0u, execute_count); |
| - factory_->Destroy(local_frame_id); |
| - EXPECT_EQ(1u, execute_count); |
| -} |
| - |
| -void DrawCallback(uint32_t* execute_count) { |
| - *execute_count += 1; |
| -} |
| - |
| -// Tests doing a DestroyAll before shutting down the factory; |
| -TEST_F(SurfaceFactoryTest, DestroyAll) { |
| - LocalFrameId id(7, kArbitraryToken); |
| - factory_->Create(id); |
| - |
| - TransferableResource resource; |
| - resource.id = 1; |
| - resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| - CompositorFrame frame; |
| - frame.resource_list.push_back(resource); |
| - uint32_t execute_count = 0; |
| - factory_->SubmitCompositorFrame(id, std::move(frame), |
| - base::Bind(&DrawCallback, &execute_count)); |
| - EXPECT_EQ(last_created_surface_id().local_frame_id(), id); |
| - local_frame_id_ = LocalFrameId(); |
| - factory_->DestroyAll(); |
| - EXPECT_EQ(1u, execute_count); |
| } |
| // Tests that SurfaceFactory doesn't return resources after Reset(). |
| TEST_F(SurfaceFactoryTest, Reset) { |
| LocalFrameId id(7, kArbitraryToken); |
| - factory_->Create(id); |
| TransferableResource resource; |
| resource.id = 1; |
| resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| CompositorFrame frame; |
| frame.resource_list.push_back(resource); |
| - uint32_t execute_count = 0; |
| factory_->SubmitCompositorFrame(id, std::move(frame), |
| - base::Bind(&DrawCallback, &execute_count)); |
| + SurfaceFactory::DrawCallback()); |
| EXPECT_EQ(last_created_surface_id().local_frame_id(), id); |
| SurfaceId surface_id(kArbitraryFrameSinkId, id); |
| @@ -520,15 +466,18 @@ TEST_F(SurfaceFactoryTest, Reset) { |
| TEST_F(SurfaceFactoryTest, DestroySequence) { |
| LocalFrameId local_frame_id2(5, kArbitraryToken); |
| + std::unique_ptr<SurfaceFactory> factory2( |
| + new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); |
| SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); |
| - factory_->Create(local_frame_id2); |
| + factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(), |
| + SurfaceFactory::DrawCallback()); |
| manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); |
| // Check that waiting before the sequence is satisfied works. |
| manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| SurfaceSequence(kArbitraryFrameSinkId, 4)); |
| - factory_->Destroy(local_frame_id2); |
| + factory2->EvictFrame(); |
| CompositorFrame frame; |
| frame.metadata.satisfies_sequences.push_back(6); |
| @@ -536,15 +485,15 @@ TEST_F(SurfaceFactoryTest, DestroySequence) { |
| DCHECK(manager_.GetSurfaceForId(id2)); |
| factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| SurfaceFactory::DrawCallback()); |
| - EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); |
| DCHECK(!manager_.GetSurfaceForId(id2)); |
| // Check that waiting after the sequence is satisfied works. |
| - factory_->Create(local_frame_id2); |
| + factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(), |
| + SurfaceFactory::DrawCallback()); |
| DCHECK(manager_.GetSurfaceForId(id2)); |
| manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| SurfaceSequence(kAnotherArbitraryFrameSinkId, 6)); |
| - factory_->Destroy(local_frame_id2); |
| + factory2->EvictFrame(); |
| DCHECK(!manager_.GetSurfaceForId(id2)); |
| } |
| @@ -555,12 +504,14 @@ TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { |
| LocalFrameId local_frame_id(5, kArbitraryToken); |
| SurfaceId id(factory_->frame_sink_id(), local_frame_id); |
| - factory_->Create(local_frame_id); |
| + factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), |
| + SurfaceFactory::DrawCallback()); |
| manager_.RegisterFrameSinkId(frame_sink_id); |
| manager_.GetSurfaceForId(id)->AddDestructionDependency( |
| SurfaceSequence(frame_sink_id, 4)); |
| - factory_->Destroy(local_frame_id); |
| + |
| + factory_->EvictFrame(); |
| // Verify the dependency has prevented the surface from getting destroyed. |
| EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
| @@ -575,13 +526,9 @@ TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { |
| TEST_F(SurfaceFactoryTest, DestroyCycle) { |
| LocalFrameId local_frame_id2(5, kArbitraryToken); |
| SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); |
| - factory_->Create(local_frame_id2); |
| - |
| + std::unique_ptr<SurfaceFactory> factory2( |
| + new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); |
| manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); |
| - |
| - manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| - SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| - |
| // Give id2 a frame that references local_frame_id_. |
| { |
| std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| @@ -589,12 +536,13 @@ TEST_F(SurfaceFactoryTest, DestroyCycle) { |
| frame.render_pass_list.push_back(std::move(render_pass)); |
| frame.metadata.referenced_surfaces.push_back( |
| SurfaceId(factory_->frame_sink_id(), local_frame_id_)); |
| - factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), |
| + factory2->SubmitCompositorFrame(local_frame_id2, std::move(frame), |
| SurfaceFactory::DrawCallback()); |
| EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2); |
| } |
| - factory_->Destroy(local_frame_id2); |
| - |
| + manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| + SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| + factory2->EvictFrame(); |
| // Give local_frame_id_ a frame that references id2. |
| { |
| std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| @@ -603,9 +551,8 @@ TEST_F(SurfaceFactoryTest, DestroyCycle) { |
| frame.metadata.referenced_surfaces.push_back(id2); |
| factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| SurfaceFactory::DrawCallback()); |
| - EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); |
| } |
| - factory_->Destroy(local_frame_id_); |
| + factory_->EvictFrame(); |
| EXPECT_TRUE(manager_.GetSurfaceForId(id2)); |
| // local_frame_id_ should be retained by reference from id2. |
| EXPECT_TRUE(manager_.GetSurfaceForId( |
| @@ -650,7 +597,7 @@ TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { |
| base::Bind(&CopyRequestTestCallback, &called1)); |
| request->set_source(source1); |
| - factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); |
| + factory_->RequestCopyOfSurface(std::move(request)); |
| EXPECT_FALSE(called1); |
| bool called2 = false; |
| @@ -658,7 +605,7 @@ TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { |
| base::Bind(&CopyRequestTestCallback, &called2)); |
| request->set_source(source2); |
| - factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); |
| + factory_->RequestCopyOfSurface(std::move(request)); |
| // Callbacks have different sources so neither should be called. |
| EXPECT_FALSE(called1); |
| EXPECT_FALSE(called2); |
| @@ -668,14 +615,15 @@ TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { |
| base::Bind(&CopyRequestTestCallback, &called3)); |
| request->set_source(source1); |
| - factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); |
| + factory_->RequestCopyOfSurface(std::move(request)); |
| // Two callbacks are from source1, so the first should be called. |
| EXPECT_TRUE(called1); |
| EXPECT_FALSE(called2); |
| EXPECT_FALSE(called3); |
| - factory_->Destroy(local_frame_id_); |
| + factory_->EvictFrame(); |
| local_frame_id_ = LocalFrameId(); |
| + |
|
danakj
2016/11/12 00:27:21
nit: random whitespace?
Saman Sami
2016/11/14 23:39:01
Done.
|
| EXPECT_TRUE(called1); |
| EXPECT_TRUE(called2); |
| EXPECT_TRUE(called3); |