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

Unified Diff: cc/surfaces/surface_factory_unittest.cc

Issue 2506883002: Revert of Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: 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
« no previous file with comments | « cc/surfaces/surface_factory.cc ('k') | cc/surfaces/surface_hittest_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/surfaces/surface_factory_unittest.cc
diff --git a/cc/surfaces/surface_factory_unittest.cc b/cc/surfaces/surface_factory_unittest.cc
index a4a34094861f8b244e8958e511226c6db38f74b7..044aeb4b6dc63fe803212a680aee311cf98c9454 100644
--- a/cc/surfaces/surface_factory_unittest.cc
+++ b/cc/surfaces/surface_factory_unittest.cc
@@ -75,6 +75,7 @@
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 {
@@ -94,8 +95,9 @@
}
~SurfaceFactoryTest() override {
+ if (local_frame_id_.is_valid())
+ factory_->Destroy(local_frame_id_);
manager_.RemoveObserver(this);
- factory_->EvictSurface();
}
void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
@@ -435,25 +437,29 @@
TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
LocalFrameId local_frame_id(6, kArbitraryToken);
SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id);
- factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(),
- SurfaceFactory::DrawCallback());
+ 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());
+ 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->SubmitCompositorFrame(new_id, CompositorFrame(),
- SurfaceFactory::DrawCallback());
- factory->EvictSurface();
+ factory->Create(new_id);
+ factory->Destroy(new_id);
*execute_count += 1;
}
-TEST_F(SurfaceFactoryTest, AddDuringEviction) {
+TEST_F(SurfaceFactoryTest, AddDuringDestroy) {
LocalFrameId local_frame_id(6, kArbitraryToken);
+ factory_->Create(local_frame_id);
uint32_t execute_count = 0;
factory_->SubmitCompositorFrame(
@@ -461,7 +467,7 @@
base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()),
&execute_count));
EXPECT_EQ(0u, execute_count);
- factory_->EvictSurface();
+ factory_->Destroy(local_frame_id);
EXPECT_EQ(1u, execute_count);
}
@@ -469,9 +475,10 @@
*execute_count += 1;
}
-// Tests doing an EvictSurface before shutting down the factory.
-TEST_F(SurfaceFactoryTest, EvictSurface) {
+// 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;
@@ -483,21 +490,23 @@
base::Bind(&DrawCallback, &execute_count));
EXPECT_EQ(last_created_surface_id().local_frame_id(), id);
local_frame_id_ = LocalFrameId();
- factory_->EvictSurface();
+ 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),
- SurfaceFactory::DrawCallback());
+ base::Bind(&DrawCallback, &execute_count));
EXPECT_EQ(last_created_surface_id().local_frame_id(), id);
SurfaceId surface_id(kArbitraryFrameSinkId, id);
@@ -511,18 +520,15 @@
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);
- factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(),
- SurfaceFactory::DrawCallback());
+ factory_->Create(local_frame_id2);
manager_.RegisterFrameSinkId(kArbitraryFrameSinkId);
// Check that waiting before the sequence is satisfied works.
manager_.GetSurfaceForId(id2)->AddDestructionDependency(
SurfaceSequence(kArbitraryFrameSinkId, 4));
- factory2->EvictSurface();
+ factory_->Destroy(local_frame_id2);
CompositorFrame frame;
frame.metadata.satisfies_sequences.push_back(6);
@@ -530,15 +536,15 @@
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.
- factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(),
- SurfaceFactory::DrawCallback());
+ factory_->Create(local_frame_id2);
DCHECK(manager_.GetSurfaceForId(id2));
manager_.GetSurfaceForId(id2)->AddDestructionDependency(
SurfaceSequence(kAnotherArbitraryFrameSinkId, 6));
- factory2->EvictSurface();
+ factory_->Destroy(local_frame_id2);
DCHECK(!manager_.GetSurfaceForId(id2));
}
@@ -549,14 +555,12 @@
LocalFrameId local_frame_id(5, kArbitraryToken);
SurfaceId id(factory_->frame_sink_id(), local_frame_id);
- factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(),
- SurfaceFactory::DrawCallback());
+ factory_->Create(local_frame_id);
manager_.RegisterFrameSinkId(frame_sink_id);
manager_.GetSurfaceForId(id)->AddDestructionDependency(
SurfaceSequence(frame_sink_id, 4));
-
- factory_->EvictSurface();
+ factory_->Destroy(local_frame_id);
// Verify the dependency has prevented the surface from getting destroyed.
EXPECT_TRUE(manager_.GetSurfaceForId(id));
@@ -571,9 +575,13 @@
TEST_F(SurfaceFactoryTest, DestroyCycle) {
LocalFrameId local_frame_id2(5, kArbitraryToken);
SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
- std::unique_ptr<SurfaceFactory> factory2(
- new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_));
+ factory_->Create(local_frame_id2);
+
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());
@@ -581,13 +589,12 @@
frame.render_pass_list.push_back(std::move(render_pass));
frame.metadata.referenced_surfaces.push_back(
SurfaceId(factory_->frame_sink_id(), local_frame_id_));
- factory2->SubmitCompositorFrame(local_frame_id2, std::move(frame),
+ factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame),
SurfaceFactory::DrawCallback());
EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2);
}
- manager_.GetSurfaceForId(id2)->AddDestructionDependency(
- SurfaceSequence(kAnotherArbitraryFrameSinkId, 4));
- factory2->EvictSurface();
+ factory_->Destroy(local_frame_id2);
+
// Give local_frame_id_ a frame that references id2.
{
std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
@@ -596,8 +603,9 @@
frame.metadata.referenced_surfaces.push_back(id2);
factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
SurfaceFactory::DrawCallback());
- }
- factory_->EvictSurface();
+ EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
+ }
+ factory_->Destroy(local_frame_id_);
EXPECT_TRUE(manager_.GetSurfaceForId(id2));
// local_frame_id_ should be retained by reference from id2.
EXPECT_TRUE(manager_.GetSurfaceForId(
@@ -642,7 +650,7 @@
base::Bind(&CopyRequestTestCallback, &called1));
request->set_source(source1);
- factory_->RequestCopyOfSurface(std::move(request));
+ factory_->RequestCopyOfSurface(local_frame_id_, std::move(request));
EXPECT_FALSE(called1);
bool called2 = false;
@@ -650,7 +658,7 @@
base::Bind(&CopyRequestTestCallback, &called2));
request->set_source(source2);
- factory_->RequestCopyOfSurface(std::move(request));
+ factory_->RequestCopyOfSurface(local_frame_id_, std::move(request));
// Callbacks have different sources so neither should be called.
EXPECT_FALSE(called1);
EXPECT_FALSE(called2);
@@ -660,13 +668,13 @@
base::Bind(&CopyRequestTestCallback, &called3));
request->set_source(source1);
- factory_->RequestCopyOfSurface(std::move(request));
+ factory_->RequestCopyOfSurface(local_frame_id_, std::move(request));
// Two callbacks are from source1, so the first should be called.
EXPECT_TRUE(called1);
EXPECT_FALSE(called2);
EXPECT_FALSE(called3);
- factory_->EvictSurface();
+ factory_->Destroy(local_frame_id_);
local_frame_id_ = LocalFrameId();
EXPECT_TRUE(called1);
EXPECT_TRUE(called2);
« no previous file with comments | « cc/surfaces/surface_factory.cc ('k') | cc/surfaces/surface_hittest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698