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

Unified Diff: cc/surfaces/surface_factory_unittest.cc

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: 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 6592fcbfbb3035d2c69a20ae44aed309308a4e76..99044b4ad0d15046b84645678c2eab3b2b4c70d9 100644
--- a/cc/surfaces/surface_factory_unittest.cc
+++ b/cc/surfaces/surface_factory_unittest.cc
@@ -73,7 +73,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 {
@@ -93,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);
}
@@ -435,76 +434,25 @@ TEST_F(SurfaceFactoryTest, ResourceLifetime) {
TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
LocalFrameId local_frame_id(6, 1);
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, 0);
- factory->Create(new_id);
- factory->Destroy(new_id);
- *execute_count += 1;
-}
-
-TEST_F(SurfaceFactoryTest, AddDuringDestroy) {
- LocalFrameId local_frame_id(6, 1);
- 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, 1);
- 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, 0);
- 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);
@@ -518,15 +466,19 @@ TEST_F(SurfaceFactoryTest, Reset) {
TEST_F(SurfaceFactoryTest, DestroySequence) {
LocalFrameId local_frame_id2(5, 1);
+ 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->SubmitCompositorFrame(LocalFrameId(0, 0), CompositorFrame(),
Fady Samuel 2016/11/10 23:33:37 If staraz@ lands his patch first then this will no
danakj 2016/11/10 23:57:58 Also if you use 0s to signify nothing instead of O
Saman Sami 2016/11/11 17:49:59 Done.
+ SurfaceFactory::DrawCallback());
CompositorFrame frame;
frame.metadata.satisfies_sequences.push_back(6);
@@ -534,15 +486,16 @@ 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->SubmitCompositorFrame(LocalFrameId(0, 1), CompositorFrame(),
+ SurfaceFactory::DrawCallback());
DCHECK(!manager_.GetSurfaceForId(id2));
}
@@ -553,12 +506,16 @@ TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) {
LocalFrameId local_frame_id(5, 1);
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);
+
+ LocalFrameId local_frame_id_2(6, 0);
+ factory_->SubmitCompositorFrame(local_frame_id_2, CompositorFrame(),
+ SurfaceFactory::DrawCallback());
// Verify the dependency has prevented the surface from getting destroyed.
EXPECT_TRUE(manager_.GetSurfaceForId(id));
@@ -573,13 +530,9 @@ TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) {
TEST_F(SurfaceFactoryTest, DestroyCycle) {
LocalFrameId local_frame_id2(5, 1);
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());
@@ -587,12 +540,14 @@ 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->SubmitCompositorFrame(LocalFrameId(0, 0), CompositorFrame(),
+ SurfaceFactory::DrawCallback());
// Give local_frame_id_ a frame that references id2.
{
std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
@@ -601,9 +556,9 @@ 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_->SubmitCompositorFrame(LocalFrameId(0, 1), CompositorFrame(),
+ SurfaceFactory::DrawCallback());
EXPECT_TRUE(manager_.GetSurfaceForId(id2));
// local_frame_id_ should be retained by reference from id2.
EXPECT_TRUE(manager_.GetSurfaceForId(
@@ -672,8 +627,9 @@ TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) {
EXPECT_FALSE(called2);
EXPECT_FALSE(called3);
- factory_->Destroy(local_frame_id_);
local_frame_id_ = LocalFrameId();
+ factory_->SubmitCompositorFrame(local_frame_id_, CompositorFrame(),
+ SurfaceFactory::DrawCallback());
EXPECT_TRUE(called1);
EXPECT_TRUE(called2);
EXPECT_TRUE(called3);

Powered by Google App Engine
This is Rietveld 408576698