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

Unified Diff: cc/surfaces/surface_manager_ref_unittest.cc

Issue 2638833002: Moving temporary reference logic to SurfaceManager (Closed)
Patch Set: c Created 3 years, 11 months 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_manager_ref_unittest.cc
diff --git a/cc/surfaces/surface_manager_ref_unittest.cc b/cc/surfaces/surface_manager_ref_unittest.cc
index b3b4995c44891cccfd566c9f3796cfef8dfdc460..2bf8817b46681998164117fd557f27ea584e5191 100644
--- a/cc/surfaces/surface_manager_ref_unittest.cc
+++ b/cc/surfaces/surface_manager_ref_unittest.cc
@@ -12,11 +12,11 @@
#include "cc/surfaces/surface_factory.h"
#include "cc/surfaces/surface_factory_client.h"
#include "cc/surfaces/surface_id.h"
+#include "cc/surfaces/surface_info.h"
kylechar 2017/01/17 16:15:35 Is this used?
Saman Sami 2017/01/17 18:29:05 Done.
#include "cc/surfaces/surface_manager.h"
#include "cc/surfaces/surface_sequence_generator.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
-namespace {
constexpr FrameSinkId kFrameSink1(1, 0);
kylechar 2017/01/17 16:15:35 You should leave constants/helper classes/helper f
Saman Sami 2017/01/17 18:29:05 Done.
constexpr FrameSinkId kFrameSink2(2, 0);
@@ -45,6 +45,14 @@ class SurfaceManagerRefTest : public testing::Test {
return SurfaceId(frame_sink_id, local_frame_id);
}
+ SurfaceId CreateSurface(uint32_t client_id,
+ uint32_t sink_id,
+ uint32_t local_id) {
+ return CreateSurface(
+ FrameSinkId(client_id, sink_id),
+ LocalFrameId(local_id, base::UnguessableToken::Deserialize(0, 1u)));
+ }
+
// Destroy Surface with |surface_id|.
void DestroySurface(const SurfaceId& surface_id) {
GetFactory(surface_id.frame_sink_id()).EvictSurface();
@@ -62,7 +70,8 @@ class SurfaceManagerRefTest : public testing::Test {
// testing::Test:
void SetUp() override {
// Start each test with a fresh SurfaceManager instance.
- manager_ = base::MakeUnique<SurfaceManager>();
+ manager_ = base::MakeUnique<SurfaceManager>(
+ SurfaceManager::LifetimeType::REFERENCES);
}
void TearDown() override {
for (auto& factory : factories_)
@@ -71,6 +80,15 @@ class SurfaceManagerRefTest : public testing::Test {
manager_.reset();
}
+ SurfaceManager::SurfaceIdSet refs(SurfaceId surface_id) {
+ return manager().parent_to_child_refs_[surface_id];
+ }
+
+ std::unordered_map<FrameSinkId, std::vector<LocalFrameId>, FrameSinkIdHash>
+ tmp_refs() {
+ return manager().temp_references_;
+ }
+
std::unordered_map<FrameSinkId,
std::unique_ptr<SurfaceFactory>,
FrameSinkIdHash>
@@ -79,8 +97,6 @@ class SurfaceManagerRefTest : public testing::Test {
StubSurfaceFactoryClient client_;
};
-} // namespace
-
TEST_F(SurfaceManagerRefTest, AddReference) {
SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1);
manager().AddSurfaceReference(manager().GetRootSurfaceId(), id1);
@@ -221,40 +237,6 @@ TEST_F(SurfaceManagerRefTest, CheckGCRecusiveFull) {
EXPECT_EQ(manager().GetSurfaceForId(id3), nullptr);
}
-TEST_F(SurfaceManagerRefTest, CheckGCWithSequences) {
- SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1);
- SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1);
-
- manager().AddSurfaceReference(manager().GetRootSurfaceId(), id1);
- manager().AddSurfaceReference(id1, id2);
-
- SurfaceId id3 = CreateSurface(kFrameSink3, kLocalFrame1);
- Surface* surface3 = manager().GetSurfaceForId(id3);
-
- // Add destruction dependency from |id2| to |id3|.
- manager().RegisterFrameSinkId(kFrameSink2);
- SurfaceSequence sequence(kFrameSink2, 1u);
- surface3->AddDestructionDependency(sequence);
- EXPECT_EQ(surface3->GetDestructionDependencyCount(), 1u);
-
- // Surface for |id3| isn't delete yet because it has a valid destruction
- // dependency from |kFrameSink2|.
- DestroySurface(id3);
- EXPECT_NE(manager().GetSurfaceForId(id3), nullptr);
-
- // Surface for |id2| isn't deleted because it has a reference.
- DestroySurface(id2);
- EXPECT_NE(manager().GetSurfaceForId(id2), nullptr);
-
- // Satisfy destruction dependency on |id3| and delete during GC.
- manager().SatisfySequence(sequence);
- EXPECT_EQ(manager().GetSurfaceForId(id3), nullptr);
-
- // Remove ref on |id2| and delete during GC.
- manager().RemoveSurfaceReference(id1, id2);
- EXPECT_EQ(manager().GetSurfaceForId(id2), nullptr);
-}
-
TEST_F(SurfaceManagerRefTest, TryAddReferenceToBadSurface) {
// Not creating an accompanying Surface and SurfaceFactory.
SurfaceId id(FrameSinkId(100u, 200u),
@@ -286,8 +268,9 @@ TEST_F(SurfaceManagerRefTest, TryAddSelfReference) {
// Adding a self reference should be ignored without crashing.
manager().AddSurfaceReference(id1, id1);
- EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 0u);
EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 0u);
+ // There should still be one temporary reference to id1
+ EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 1u);
kylechar 2017/01/17 16:15:35 Can you also check this is true before AddSurfaceR
Saman Sami 2017/01/17 18:29:05 Done.
}
TEST_F(SurfaceManagerRefTest, TryRemoveBadReference) {
@@ -301,4 +284,146 @@ TEST_F(SurfaceManagerRefTest, TryRemoveBadReference) {
EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u);
}
+// Temporary Reference Tests
+
+TEST_F(SurfaceManagerRefTest, AddSurfaceThenReference) {
+ const SurfaceId surface_id = CreateSurface(2, 1, 1);
+
+ // Temporary reference must be added.
+ EXPECT_EQ(1u, tmp_refs().size());
+ EXPECT_EQ(std::vector<LocalFrameId>{surface_id.local_frame_id()},
kylechar 2017/01/17 16:15:35 The tests become pretty difficult to read. Changin
Saman Sami 2017/01/17 18:29:05 Neat.
+ tmp_refs()[surface_id.frame_sink_id()]);
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id));
+
+ // Add a real reference to surface_id.
+ const SurfaceId parent_id = CreateSurface(1, 1, 1);
+ manager().AddSurfaceReference(parent_id, surface_id);
+
+ // Real reference is added and temporary reference to surface_id is removed.
+ EXPECT_EQ(1u, tmp_refs().size());
+ EXPECT_EQ(std::vector<LocalFrameId>{parent_id.local_frame_id()},
+ tmp_refs()[parent_id.frame_sink_id()]);
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(parent_id));
+ EXPECT_EQ(1u, refs(parent_id).size());
+ EXPECT_EQ(1u, refs(parent_id).count(surface_id));
+}
+
+TEST_F(SurfaceManagerRefTest, AddSurfaceThenRootReference) {
+ const SurfaceId surface_id = CreateSurface(1, 1, 1);
+
+ // Temporary reference should be added.
+ EXPECT_EQ(1u, tmp_refs().size());
+ EXPECT_EQ(std::vector<LocalFrameId>{surface_id.local_frame_id()},
+ tmp_refs()[surface_id.frame_sink_id()]);
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id));
+
+ // Add a real reference from root to surface_id.
+ manager().AddSurfaceReference(manager().GetRootSurfaceId(), surface_id);
+
+ // Adding real reference doesn't need to change anything in
+ // SurfaceReferenceManager does remove the temporary reference marker.
+ EXPECT_EQ(0u, tmp_refs().size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id));
+}
+
+TEST_F(SurfaceManagerRefTest, AddTwoSurfacesThenOneReference) {
+ // Add two surfaces with different FrameSinkIds.
+ const SurfaceId surface_id1 = CreateSurface(2, 1, 1);
+ const SurfaceId surface_id2 = CreateSurface(3, 1, 1);
+
+ // Temporary reference should be added for both surfaces.
+ EXPECT_EQ(2u, tmp_refs().size());
+ EXPECT_EQ(std::vector<LocalFrameId>{surface_id1.local_frame_id()},
+ tmp_refs()[surface_id1.frame_sink_id()]);
+ EXPECT_EQ(std::vector<LocalFrameId>{surface_id2.local_frame_id()},
+ tmp_refs()[surface_id2.frame_sink_id()]);
+ EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id1));
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2));
+
+ // Add a real reference to surface_id1.
+ const SurfaceId parent_id = CreateSurface(1, 1, 1);
+ manager().AddSurfaceReference(parent_id, surface_id1);
+
+ // Real reference is added then temporary reference removed for 2:1:1. There
+ // should still be a temporary reference left to 3:1:1
+ EXPECT_EQ(2u, tmp_refs().size());
+ EXPECT_EQ(std::vector<LocalFrameId>{surface_id2.local_frame_id()},
+ tmp_refs()[surface_id2.frame_sink_id()]);
+ EXPECT_EQ(std::vector<LocalFrameId>{parent_id.local_frame_id()},
+ tmp_refs()[parent_id.frame_sink_id()]);
+ EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(parent_id));
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2));
+ EXPECT_EQ(1u, refs(parent_id).size());
+ EXPECT_EQ(1u, refs(parent_id).count(surface_id1));
+}
+
+TEST_F(SurfaceManagerRefTest, AddSurfacesSkipReference) {
+ // Add two surfaces that have the same FrameSinkId. This would happen when a
+ // client submits two CFs before parent submits a new CF.
+ const SurfaceId surface_id1 = CreateSurface(2, 1, 1);
+ const SurfaceId surface_id2 = CreateSurface(2, 1, 2);
+
+ // Temporary references should be added for both surfaces.
+ std::vector<LocalFrameId> expected_ids = {surface_id1.local_frame_id(),
+ surface_id2.local_frame_id()};
+ EXPECT_EQ(1u, tmp_refs().size());
+ EXPECT_EQ(expected_ids, tmp_refs()[surface_id1.frame_sink_id()]);
+ EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id1));
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2));
+
+ // Add a reference to the surface with the later LocalFrameId.
+ const SurfaceId parent_id = CreateSurface(1, 1, 1);
+ manager().AddSurfaceReference(parent_id, surface_id2);
+
+ // The real reference should be added for 2:1:2 and both temporary references
+ // should be removed.
+ EXPECT_EQ(1u, tmp_refs().size());
+ EXPECT_EQ(std::vector<LocalFrameId>{parent_id.local_frame_id()},
+ tmp_refs()[parent_id.frame_sink_id()]);
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(parent_id));
+ EXPECT_EQ(1u, refs(parent_id).size());
+ EXPECT_EQ(1u, refs(parent_id).count(surface_id2));
+}
+
+TEST_F(SurfaceManagerRefTest, RemoveFirstTempRefOnly) {
+ // Add two surfaces that have the same FrameSinkId. This would happen when a
+ // client submits two CFs before parent submits a new CF.
+ const SurfaceId surface_id1 = CreateSurface(2, 1, 1);
+ const SurfaceId surface_id2 = CreateSurface(2, 1, 2);
+
+ // Temporary references should be added for both surfaces.
+ std::vector<LocalFrameId> expected_ids = {surface_id1.local_frame_id(),
+ surface_id2.local_frame_id()};
+ EXPECT_EQ(1u, tmp_refs().size());
+ EXPECT_EQ(expected_ids, tmp_refs()[surface_id1.frame_sink_id()]);
+ EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id1));
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2));
+
+ // Add a reference to the surface with the earlier LocalFrameId.
+ const SurfaceId parent_id = CreateSurface(1, 1, 1);
+ manager().AddSurfaceReference(parent_id, surface_id1);
+
+ // The real reference should be added for 2:1:1 and temporary reference
+ // should be removed. The temporary reference for 2:1:2 should remain.
+ EXPECT_EQ(2u, tmp_refs().size());
+ EXPECT_EQ(std::vector<LocalFrameId>{surface_id2.local_frame_id()},
+ tmp_refs()[surface_id2.frame_sink_id()]);
+ EXPECT_EQ(std::vector<LocalFrameId>{parent_id.local_frame_id()},
+ tmp_refs()[parent_id.frame_sink_id()]);
+ EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size());
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2));
+ EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(parent_id));
+ EXPECT_EQ(1u, refs(parent_id).size());
+ EXPECT_EQ(1u, refs(parent_id).count(surface_id1));
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698