Index: cc/surfaces/surface_synchronization_unittest.cc |
diff --git a/cc/surfaces/compositor_frame_sink_support_unittest.cc b/cc/surfaces/surface_synchronization_unittest.cc |
similarity index 89% |
copy from cc/surfaces/compositor_frame_sink_support_unittest.cc |
copy to cc/surfaces/surface_synchronization_unittest.cc |
index 03baed9f136e86d164576244f7934e0cf61af894..a18e75b5b3f23d62b8a60094db8221edef1bb567 100644 |
--- a/cc/surfaces/compositor_frame_sink_support_unittest.cc |
+++ b/cc/surfaces/surface_synchronization_unittest.cc |
@@ -3,68 +3,33 @@ |
// found in the LICENSE file. |
#include "cc/surfaces/compositor_frame_sink_support.h" |
- |
-#include "base/macros.h" |
-#include "cc/output/compositor_frame.h" |
-#include "cc/surfaces/compositor_frame_sink_support_client.h" |
-#include "cc/surfaces/frame_sink_id.h" |
#include "cc/surfaces/surface_id.h" |
#include "cc/surfaces/surface_manager.h" |
+#include "cc/surfaces/surface_observer.h" |
#include "cc/test/begin_frame_args_test.h" |
#include "cc/test/fake_external_begin_frame_source.h" |
+#include "cc/test/mock_compositor_frame_sink_support_client.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-using testing::UnorderedElementsAre; |
-using testing::IsEmpty; |
-using testing::SizeIs; |
-using testing::Invoke; |
-using testing::_; |
using testing::Eq; |
+using testing::IsEmpty; |
+using testing::UnorderedElementsAre; |
namespace cc { |
namespace test { |
namespace { |
+constexpr bool kIsRoot = true; |
+constexpr bool kIsChildRoot = false; |
+constexpr bool kHandlesFrameSinkIdInvalidation = true; |
+constexpr bool kNeedsSyncPoints = true; |
constexpr FrameSinkId kDisplayFrameSink(2, 0); |
constexpr FrameSinkId kParentFrameSink(3, 0); |
constexpr FrameSinkId kChildFrameSink1(65563, 0); |
constexpr FrameSinkId kChildFrameSink2(65564, 0); |
constexpr FrameSinkId kArbitraryFrameSink(1337, 7331); |
-class MockCompositorFrameSinkSupportClient |
- : public CompositorFrameSinkSupportClient { |
- public: |
- MockCompositorFrameSinkSupportClient() { |
- ON_CALL(*this, ReclaimResources(_)) |
- .WillByDefault(Invoke( |
- this, |
- &MockCompositorFrameSinkSupportClient::ReclaimResourcesInternal)); |
- ON_CALL(*this, DidReceiveCompositorFrameAck(_)) |
- .WillByDefault(Invoke( |
- this, |
- &MockCompositorFrameSinkSupportClient::ReclaimResourcesInternal)); |
- } |
- |
- ReturnedResourceArray& last_returned_resources() { |
- return last_returned_resources_; |
- } |
- |
- // CompositorFrameSinkSupportClient implementation. |
- MOCK_METHOD1(DidReceiveCompositorFrameAck, |
- void(const ReturnedResourceArray&)); |
- MOCK_METHOD1(OnBeginFrame, void(const BeginFrameArgs&)); |
- MOCK_METHOD1(ReclaimResources, void(const ReturnedResourceArray&)); |
- MOCK_METHOD2(WillDrawSurface, void(const LocalSurfaceId&, const gfx::Rect&)); |
- |
- private: |
- void ReclaimResourcesInternal(const ReturnedResourceArray& resources) { |
- last_returned_resources_ = resources; |
- } |
- |
- ReturnedResourceArray last_returned_resources_; |
-}; |
- |
std::vector<SurfaceId> empty_surface_ids() { |
return std::vector<SurfaceId>(); |
} |
@@ -75,63 +40,15 @@ SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) { |
LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u))); |
} |
-CompositorFrame MakeCompositorFrame(std::vector<SurfaceId> embedded_surfaces, |
- std::vector<SurfaceId> referenced_surfaces, |
- TransferableResourceArray resource_list) { |
- CompositorFrame compositor_frame; |
- compositor_frame.metadata.begin_frame_ack = BeginFrameAck(0, 1, 1, true); |
- compositor_frame.metadata.embedded_surfaces = std::move(embedded_surfaces); |
- compositor_frame.metadata.referenced_surfaces = |
- std::move(referenced_surfaces); |
- compositor_frame.resource_list = std::move(resource_list); |
- return compositor_frame; |
-} |
- |
-CompositorFrame MakeCompositorFrame() { |
- return MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(), |
- TransferableResourceArray()); |
-} |
- |
-CompositorFrame MakeCompositorFrame(std::vector<SurfaceId> embedded_surfaces) { |
- return MakeCompositorFrame(embedded_surfaces, embedded_surfaces, |
- TransferableResourceArray()); |
-} |
- |
-CompositorFrame MakeCompositorFrame( |
- std::vector<SurfaceId> embedded_surfaces, |
- std::vector<SurfaceId> referenced_surfaces) { |
- return MakeCompositorFrame(std::move(embedded_surfaces), |
- std::move(referenced_surfaces), |
- TransferableResourceArray()); |
-} |
- |
-CompositorFrame MakeCompositorFrameWithResources( |
- std::vector<SurfaceId> embedded_surfaces, |
- TransferableResourceArray resource_list) { |
- return MakeCompositorFrame(embedded_surfaces, embedded_surfaces, |
- std::move(resource_list)); |
-} |
- |
-TransferableResource MakeResource(ResourceId id, |
- ResourceFormat format, |
- uint32_t filter, |
- const gfx::Size& size) { |
- TransferableResource resource; |
- resource.id = id; |
- resource.format = format; |
- resource.filter = filter; |
- resource.size = size; |
- return resource; |
-} |
- |
} // namespace |
-class CompositorFrameSinkSupportTest : public testing::Test, |
- public SurfaceObserver { |
+class SurfaceSynchronizationTest : public testing::Test, |
+ public SurfaceObserver { |
public: |
- CompositorFrameSinkSupportTest() |
- : surface_manager_(SurfaceManager::LifetimeType::REFERENCES) {} |
- ~CompositorFrameSinkSupportTest() override {} |
+ SurfaceSynchronizationTest() |
+ : support_client_(false /* create_surface_during_eviction */), |
+ surface_manager_(SurfaceManager::LifetimeType::REFERENCES) {} |
+ ~SurfaceSynchronizationTest() override {} |
CompositorFrameSinkSupport& display_support() { return *supports_[0]; } |
Surface* display_surface() { |
@@ -185,10 +102,7 @@ class CompositorFrameSinkSupportTest : public testing::Test, |
// testing::Test: |
void SetUp() override { |
testing::Test::SetUp(); |
- constexpr bool is_root = true; |
- constexpr bool is_child_root = false; |
- constexpr bool handles_frame_sink_id_invalidation = true; |
- constexpr bool needs_sync_points = true; |
+ |
begin_frame_source_ = |
base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); |
surface_manager_.SetDependencyTracker( |
@@ -196,17 +110,17 @@ class CompositorFrameSinkSupportTest : public testing::Test, |
begin_frame_source_.get())); |
surface_manager_.AddObserver(this); |
supports_.push_back(CompositorFrameSinkSupport::Create( |
- &support_client_, &surface_manager_, kDisplayFrameSink, is_root, |
- handles_frame_sink_id_invalidation, needs_sync_points)); |
+ &support_client_, &surface_manager_, kDisplayFrameSink, kIsRoot, |
+ kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints)); |
supports_.push_back(CompositorFrameSinkSupport::Create( |
- &support_client_, &surface_manager_, kParentFrameSink, is_child_root, |
- handles_frame_sink_id_invalidation, needs_sync_points)); |
+ &support_client_, &surface_manager_, kParentFrameSink, kIsChildRoot, |
+ kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints)); |
supports_.push_back(CompositorFrameSinkSupport::Create( |
- &support_client_, &surface_manager_, kChildFrameSink1, is_child_root, |
- handles_frame_sink_id_invalidation, needs_sync_points)); |
+ &support_client_, &surface_manager_, kChildFrameSink1, kIsChildRoot, |
+ kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints)); |
supports_.push_back(CompositorFrameSinkSupport::Create( |
- &support_client_, &surface_manager_, kChildFrameSink2, is_child_root, |
- handles_frame_sink_id_invalidation, needs_sync_points)); |
+ &support_client_, &surface_manager_, kChildFrameSink2, kIsChildRoot, |
+ kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints)); |
// Normally, the BeginFrameSource would be registered by the Display. We |
// register it here so that BeginFrames are received by the display support, |
@@ -249,12 +163,12 @@ class CompositorFrameSinkSupportTest : public testing::Test, |
std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_; |
std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_; |
- DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupportTest); |
+ DISALLOW_COPY_AND_ASSIGN(SurfaceSynchronizationTest); |
}; |
// The display root surface should have a surface reference from the top-level |
// root added/removed when a CompositorFrame is submitted with a new SurfaceId. |
-TEST_F(CompositorFrameSinkSupportTest, RootSurfaceReceivesReferences) { |
+TEST_F(SurfaceSynchronizationTest, RootSurfaceReceivesReferences) { |
const SurfaceId display_id_first = MakeSurfaceId(kDisplayFrameSink, 1); |
const SurfaceId display_id_second = MakeSurfaceId(kDisplayFrameSink, 2); |
@@ -283,7 +197,7 @@ TEST_F(CompositorFrameSinkSupportTest, RootSurfaceReceivesReferences) { |
} |
// The parent Surface is blocked on |child_id1| and |child_id2|. |
-TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedOnTwo) { |
+TEST_F(SurfaceSynchronizationTest, BlockedOnTwo) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); |
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); |
@@ -322,7 +236,7 @@ TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedOnTwo) { |
} |
// The parent Surface is blocked on |child_id2| which is blocked on |child_id3|. |
-TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedChain) { |
+TEST_F(SurfaceSynchronizationTest, BlockedChain) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); |
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); |
@@ -381,8 +295,7 @@ TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedChain) { |
} |
// parent_surface and child_surface1 are blocked on |child_id2|. |
-TEST_F(CompositorFrameSinkSupportTest, |
- DisplayCompositorLockingTwoBlockedOnOne) { |
+TEST_F(SurfaceSynchronizationTest, TwoBlockedOnOne) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); |
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); |
@@ -431,7 +344,7 @@ TEST_F(CompositorFrameSinkSupportTest, |
// parent_surface is blocked on |child_id1|, and child_surface2 is blocked on |
// |child_id2| until the deadline hits. |
-TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingDeadlineHits) { |
+TEST_F(SurfaceSynchronizationTest, DeadlineHits) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); |
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); |
@@ -499,8 +412,7 @@ TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingDeadlineHits) { |
// Verifies that the deadline does not reset if we submit CompositorFrames |
// to new Surfaces with unresolved dependencies. |
-TEST_F(CompositorFrameSinkSupportTest, |
- DisplayCompositorLockingFramesSubmittedAfterDeadlineSet) { |
+TEST_F(SurfaceSynchronizationTest, FramesSubmittedAfterDeadlineSet) { |
const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1); |
BeginFrameArgs args = |
CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); |
@@ -532,8 +444,7 @@ TEST_F(CompositorFrameSinkSupportTest, |
// This test verifies at the Surface activates once a CompositorFrame is |
// submitted that has no unresolved dependencies. |
-TEST_F(CompositorFrameSinkSupportTest, |
- DisplayCompositorLockingNewFrameOverridesOldDependencies) { |
+TEST_F(SurfaceSynchronizationTest, NewFrameOverridesOldDependencies) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1); |
@@ -560,8 +471,7 @@ TEST_F(CompositorFrameSinkSupportTest, |
// This test verifies that a pending CompositorFrame does not affect surface |
// references. A new surface from a child will continue to exist as a temporary |
// reference until the parent's frame activates. |
-TEST_F(CompositorFrameSinkSupportTest, |
- OnlyActiveFramesAffectSurfaceReferences) { |
+TEST_F(SurfaceSynchronizationTest, OnlyActiveFramesAffectSurfaceReferences) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); |
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); |
@@ -627,8 +537,7 @@ TEST_F(CompositorFrameSinkSupportTest, |
// This test verifies that we do not double count returned resources when a |
// CompositorFrame starts out as pending, then becomes active, and then is |
// replaced with another active CompositorFrame. |
-TEST_F(CompositorFrameSinkSupportTest, |
- DisplayCompositorLockingResourcesOnlyReturnedOnce) { |
+TEST_F(SurfaceSynchronizationTest, ResourcesOnlyReturnedOnce) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); |
@@ -678,7 +587,7 @@ TEST_F(CompositorFrameSinkSupportTest, |
// The parent Surface is blocked on |child_id2| which is blocked on |child_id3|. |
// child_support1 evicts its blocked Surface. The parent surface should |
// activate. |
-TEST_F(CompositorFrameSinkSupportTest, EvictSurfaceWithPendingFrame) { |
+TEST_F(SurfaceSynchronizationTest, EvictSurfaceWithPendingFrame) { |
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); |
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); |
@@ -719,7 +628,7 @@ TEST_F(CompositorFrameSinkSupportTest, EvictSurfaceWithPendingFrame) { |
// existing active CompositorFrame, then the surface reference hierarchy will be |
// updated allowing garbage collection of surfaces that are no longer |
// referenced. |
-TEST_F(CompositorFrameSinkSupportTest, DropStaleReferencesAfterActivation) { |
+TEST_F(SurfaceSynchronizationTest, DropStaleReferencesAfterActivation) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); |
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); |
@@ -792,7 +701,7 @@ TEST_F(CompositorFrameSinkSupportTest, DropStaleReferencesAfterActivation) { |
// Checks whether the latency info are moved to the new surface from the old |
// one when LocalSurfaceId changes. No frame has unresolved dependencies. |
-TEST_F(CompositorFrameSinkSupportTest, |
+TEST_F(SurfaceSynchronizationTest, |
LatencyInfoCarriedOverOnResize_NoUnresolvedDependencies) { |
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
@@ -862,7 +771,7 @@ TEST_F(CompositorFrameSinkSupportTest, |
// Checks whether the latency info are moved to the new surface from the old |
// one when LocalSurfaceId changes. Old surface has unresolved dependencies. |
-TEST_F(CompositorFrameSinkSupportTest, |
+TEST_F(SurfaceSynchronizationTest, |
LatencyInfoCarriedOverOnResize_OldSurfaceHasPendingAndActiveFrame) { |
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
@@ -938,7 +847,7 @@ TEST_F(CompositorFrameSinkSupportTest, |
// Checks whether the latency info are moved to the new surface from the old |
// one when LocalSurfaceId changes. The new surface has unresolved dependencies. |
-TEST_F(CompositorFrameSinkSupportTest, |
+TEST_F(SurfaceSynchronizationTest, |
LatencyInfoCarriedOverOnResize_NewSurfaceHasPendingFrame) { |
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
@@ -1015,7 +924,7 @@ TEST_F(CompositorFrameSinkSupportTest, |
ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); |
} |
-TEST_F(CompositorFrameSinkSupportTest, PassesOnBeginFrameAcks) { |
+TEST_F(SurfaceSynchronizationTest, PassesOnBeginFrameAcks) { |
const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); |
// Request BeginFrames. |
@@ -1047,7 +956,7 @@ TEST_F(CompositorFrameSinkSupportTest, PassesOnBeginFrameAcks) { |
} |
// Checks that resources and ack are sent together if possible. |
-TEST_F(CompositorFrameSinkSupportTest, ReturnResourcesWithAck) { |
+TEST_F(SurfaceSynchronizationTest, ReturnResourcesWithAck) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
TransferableResource resource; |
resource.id = 1234; |
@@ -1065,7 +974,7 @@ TEST_F(CompositorFrameSinkSupportTest, ReturnResourcesWithAck) { |
// Verifies that if a surface is marked destroyed and a new frame arrives for |
// it, it will be recovered. |
-TEST_F(CompositorFrameSinkSupportTest, SurfaceResurrection) { |
+TEST_F(SurfaceSynchronizationTest, SurfaceResurrection) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); |
@@ -1103,7 +1012,7 @@ TEST_F(CompositorFrameSinkSupportTest, SurfaceResurrection) { |
// Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist |
// anymore, it can still be reused for new surfaces. |
-TEST_F(CompositorFrameSinkSupportTest, LocalSurfaceIdIsReusable) { |
+TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) { |
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); |
@@ -1138,7 +1047,7 @@ TEST_F(CompositorFrameSinkSupportTest, LocalSurfaceIdIsReusable) { |
// activated subtree refer to the same dependency. The old subtree was activated |
// by deadline, and the new subtree was activated by a dependency finally |
// resolving. |
-TEST_F(CompositorFrameSinkSupportTest, DependencyTrackingGarbageCollection) { |
+TEST_F(SurfaceSynchronizationTest, DependencyTrackingGarbageCollection) { |
const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); |
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
@@ -1192,7 +1101,7 @@ TEST_F(CompositorFrameSinkSupportTest, DependencyTrackingGarbageCollection) { |
// deadline activation. SurfaceDependencyTracker is also tracking a surface |
// from that subtree due to an unresolved dependency. This test verifies that |
// this dependency resolution does not crash. |
-TEST_F(CompositorFrameSinkSupportTest, GarbageCollectionOnDeadline) { |
+TEST_F(SurfaceSynchronizationTest, GarbageCollectionOnDeadline) { |
const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); |
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
@@ -1249,7 +1158,7 @@ TEST_F(CompositorFrameSinkSupportTest, GarbageCollectionOnDeadline) { |
// This test verifies that a CompositorFrame will only blocked on embedded |
// surfaces but not on other retained surface IDs in the CompositorFrame. |
-TEST_F(CompositorFrameSinkSupportTest, OnlyBlockOnEmbeddedSurfaces) { |
+TEST_F(SurfaceSynchronizationTest, OnlyBlockOnEmbeddedSurfaces) { |
const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); |
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); |
@@ -1287,7 +1196,7 @@ TEST_F(CompositorFrameSinkSupportTest, OnlyBlockOnEmbeddedSurfaces) { |
// This test verifies that a late arriving CompositorFrame activates immediately |
// and does not trigger a new deadline. |
-TEST_F(CompositorFrameSinkSupportTest, LateArrivingDependency) { |
+TEST_F(SurfaceSynchronizationTest, LateArrivingDependency) { |
const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); |
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); |
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); |