Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Unified Diff: cc/surfaces/surface_factory_unittest.cc

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: surface factory test clean up Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..9392a43bf1e3e4c0c2f3a4707f1cea4cab6e3642 100644
--- a/cc/surfaces/surface_factory_unittest.cc
+++ b/cc/surfaces/surface_factory_unittest.cc
@@ -75,7 +75,8 @@ 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_);
+ factory_->SubmitCompositorFrame(local_frame_id_, CompositorFrame(),
+ SurfaceFactory::DrawCallback());
}
const SurfaceId& last_created_surface_id() const {
@@ -95,8 +96,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 +436,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 +468,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->Reset();
CompositorFrame frame;
frame.metadata.satisfies_sequences.push_back(6);
@@ -536,15 +487,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->Reset();
DCHECK(!manager_.GetSurfaceForId(id2));
}
@@ -555,12 +506,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_->Reset();
// Verify the dependency has prevented the surface from getting destroyed.
EXPECT_TRUE(manager_.GetSurfaceForId(id));
@@ -575,13 +528,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 +538,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->Reset();
// Give local_frame_id_ a frame that references id2.
{
std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
@@ -603,9 +553,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_->Reset();
EXPECT_TRUE(manager_.GetSurfaceForId(id2));
// local_frame_id_ should be retained by reference from id2.
EXPECT_TRUE(manager_.GetSurfaceForId(
@@ -674,8 +623,9 @@ TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) {
EXPECT_FALSE(called2);
EXPECT_FALSE(called3);
- factory_->Destroy(local_frame_id_);
+ factory_->Reset();
local_frame_id_ = LocalFrameId();
+
EXPECT_TRUE(called1);
EXPECT_TRUE(called2);
EXPECT_TRUE(called3);

Powered by Google App Engine
This is Rietveld 408576698