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

Side by Side Diff: cc/surfaces/compositor_frame_sink_support_unittest.cc

Issue 2689563005: Surfaces: Receive resources only once (Closed)
Patch Set: Added a unit test Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « cc/resources/returned_resource.h ('k') | cc/surfaces/surface.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/surfaces/compositor_frame_sink_support.h" 5 #include "cc/surfaces/compositor_frame_sink_support.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "cc/output/compositor_frame.h" 8 #include "cc/output/compositor_frame.h"
9 #include "cc/surfaces/compositor_frame_sink_support_client.h" 9 #include "cc/surfaces/compositor_frame_sink_support_client.h"
10 #include "cc/surfaces/frame_sink_id.h" 10 #include "cc/surfaces/frame_sink_id.h"
(...skipping 27 matching lines...) Expand all
38 } 38 }
39 39
40 CompositorFrame MakeCompositorFrame( 40 CompositorFrame MakeCompositorFrame(
41 std::vector<SurfaceId> referenced_surfaces) { 41 std::vector<SurfaceId> referenced_surfaces) {
42 CompositorFrame compositor_frame; 42 CompositorFrame compositor_frame;
43 compositor_frame.metadata.referenced_surfaces = 43 compositor_frame.metadata.referenced_surfaces =
44 std::move(referenced_surfaces); 44 std::move(referenced_surfaces);
45 return compositor_frame; 45 return compositor_frame;
46 } 46 }
47 47
48 CompositorFrame MakeCompositorFrameWithResources(
49 std::vector<SurfaceId> referenced_surfaces,
50 TransferableResourceArray resource_list) {
51 CompositorFrame compositor_frame;
52 compositor_frame.metadata.referenced_surfaces =
53 std::move(referenced_surfaces);
54 compositor_frame.resource_list = std::move(resource_list);
55 return compositor_frame;
56 }
57
58 TransferableResource MakeResource(ResourceId id,
59 ResourceFormat format,
60 uint32_t filter,
61 const gfx::Size& size) {
62 TransferableResource resource;
63 resource.id = id;
64 resource.format = format;
65 resource.filter = filter;
66 resource.size = size;
67 return resource;
68 }
69
48 } // namespace 70 } // namespace
49 71
50 class CompositorFrameSinkSupportTest : public testing::Test, 72 class CompositorFrameSinkSupportTest : public testing::Test,
51 public CompositorFrameSinkSupportClient { 73 public CompositorFrameSinkSupportClient {
52 public: 74 public:
53 CompositorFrameSinkSupportTest() 75 CompositorFrameSinkSupportTest()
54 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES) {} 76 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES) {}
55 ~CompositorFrameSinkSupportTest() override {} 77 ~CompositorFrameSinkSupportTest() override {}
56 78
57 CompositorFrameSinkSupport& parent_support() { return *supports_[0]; } 79 CompositorFrameSinkSupport& parent_support() { return *supports_[0]; }
(...skipping 22 matching lines...) Expand all
80 SurfaceManager& surface_manager() { return surface_manager_; } 102 SurfaceManager& surface_manager() { return surface_manager_; }
81 103
82 SurfaceDependencyTracker& dependency_tracker() { 104 SurfaceDependencyTracker& dependency_tracker() {
83 return *surface_manager_.dependency_tracker(); 105 return *surface_manager_.dependency_tracker();
84 } 106 }
85 107
86 FakeExternalBeginFrameSource* begin_frame_source() { 108 FakeExternalBeginFrameSource* begin_frame_source() {
87 return begin_frame_source_.get(); 109 return begin_frame_source_.get();
88 } 110 }
89 111
112 ReturnedResourceArray& last_returned_resources() {
113 return last_returned_resources_;
114 }
115
90 // testing::Test: 116 // testing::Test:
91 void SetUp() override { 117 void SetUp() override {
92 testing::Test::SetUp(); 118 testing::Test::SetUp();
93 begin_frame_source_ = 119 begin_frame_source_ =
94 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); 120 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false);
95 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker( 121 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker(
96 new SurfaceDependencyTracker(&surface_manager_, 122 new SurfaceDependencyTracker(&surface_manager_,
97 begin_frame_source_.get())); 123 begin_frame_source_.get()));
98 surface_manager_.SetDependencyTracker(std::move(dependency_tracker)); 124 surface_manager_.SetDependencyTracker(std::move(dependency_tracker));
99 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>( 125 supports_.push_back(base::MakeUnique<CompositorFrameSinkSupport>(
(...skipping 13 matching lines...) Expand all
113 // SurfaceDependencyTracker depends on this BeginFrameSource and so it must 139 // SurfaceDependencyTracker depends on this BeginFrameSource and so it must
114 // be destroyed AFTER the dependency tracker is destroyed. 140 // be destroyed AFTER the dependency tracker is destroyed.
115 begin_frame_source_.reset(); 141 begin_frame_source_.reset();
116 142
117 supports_.clear(); 143 supports_.clear();
118 } 144 }
119 145
120 // CompositorFrameSinkSupportClient implementation. 146 // CompositorFrameSinkSupportClient implementation.
121 void DidReceiveCompositorFrameAck() override {} 147 void DidReceiveCompositorFrameAck() override {}
122 void OnBeginFrame(const BeginFrameArgs& args) override {} 148 void OnBeginFrame(const BeginFrameArgs& args) override {}
123 void ReclaimResources(const ReturnedResourceArray& resources) override {} 149 void ReclaimResources(const ReturnedResourceArray& resources) override {
150 last_returned_resources_ = resources;
151 }
124 void WillDrawSurface() override {} 152 void WillDrawSurface() override {}
125 153
126 private: 154 private:
127 SurfaceManager surface_manager_; 155 SurfaceManager surface_manager_;
128 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_; 156 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_;
129 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_; 157 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_;
158 ReturnedResourceArray last_returned_resources_;
130 159
131 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupportTest); 160 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupportTest);
132 }; 161 };
133 162
134 // The parent Surface is blocked on |child_id1| and |child_id2|. 163 // The parent Surface is blocked on |child_id1| and |child_id2|.
135 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedOnTwo) { 164 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedOnTwo) {
136 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 165 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
137 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); 166 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
138 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); 167 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
139 168
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 EXPECT_TRUE(parent_surface()->HasPendingFrame()); 465 EXPECT_TRUE(parent_surface()->HasPendingFrame());
437 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(), 466 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(),
438 UnorderedElementsAre(arbitrary_id)); 467 UnorderedElementsAre(arbitrary_id));
439 // Verify that the parent will add a reference to |arbitrary_id| and will not 468 // Verify that the parent will add a reference to |arbitrary_id| and will not
440 // remove a reference to |child_id|. 469 // remove a reference to |child_id|.
441 EXPECT_THAT(parent_reference_tracker().references_to_add(), 470 EXPECT_THAT(parent_reference_tracker().references_to_add(),
442 UnorderedElementsAre(parent_arbitrary_reference)); 471 UnorderedElementsAre(parent_arbitrary_reference));
443 EXPECT_THAT(parent_reference_tracker().references_to_remove(), IsEmpty()); 472 EXPECT_THAT(parent_reference_tracker().references_to_remove(), IsEmpty());
444 } 473 }
445 474
475 // This test verifies that we do not double count returned resources when a
476 // CompositorFrame starts out as pending, then becomes active, and then is
477 // replaced with another active CompositorFrame.
478 TEST_F(CompositorFrameSinkSupportTest,
479 DisplayCompositorLockingResourcesOnlyReturnedOnce) {
480 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
481 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1);
482
483 // The parent submits a CompositorFrame that depends on |child_id| before the
484 // child submits a CompositorFrame. The CompositorFrame also has resources in
485 // its resource list.
486 TransferableResource resource =
487 MakeResource(1337 /* id */, ALPHA_8 /* format */, 1234 /* filter */,
488 gfx::Size(1234, 5678));
489 TransferableResourceArray resource_list = {resource};
490 parent_support().SubmitCompositorFrame(
491 parent_id.local_surface_id(),
492 MakeCompositorFrameWithResources({child_id}, resource_list));
493
494 // Verify that the CompositorFrame is blocked on |child_id|.
495 EXPECT_FALSE(parent_surface()->HasActiveFrame());
496 EXPECT_TRUE(parent_surface()->HasPendingFrame());
497 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(),
498 UnorderedElementsAre(child_id));
499
500 child_support1().SubmitCompositorFrame(
501 child_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids()));
502
503 // Verify that the child CompositorFrame activates immediately.
504 EXPECT_TRUE(child_surface1()->HasActiveFrame());
505 EXPECT_FALSE(child_surface1()->HasPendingFrame());
506 EXPECT_THAT(child_surface1()->blocking_surfaces_for_testing(), IsEmpty());
507
508 // Verify that the parent has activated.
509 EXPECT_TRUE(parent_surface()->HasActiveFrame());
510 EXPECT_FALSE(parent_surface()->HasPendingFrame());
511 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(), IsEmpty());
512
513 // The parent submits a CompositorFrame without any dependencies. That frame
514 // should activate immediately, replacing the earlier frame. The resource from
515 // the earlier frame should be returned to the client.
516 parent_support().SubmitCompositorFrame(
517 parent_id.local_surface_id(), MakeCompositorFrame({empty_surface_ids()}));
518 EXPECT_TRUE(parent_surface()->HasActiveFrame());
519 EXPECT_FALSE(parent_surface()->HasPendingFrame());
520 EXPECT_THAT(parent_surface()->blocking_surfaces_for_testing(), IsEmpty());
521 ReturnedResource returned_resource = resource.ToReturnedResource();
522 EXPECT_THAT(last_returned_resources(),
523 UnorderedElementsAre(returned_resource));
524 }
525
446 } // namespace test 526 } // namespace test
447 } // namespace cc 527 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/returned_resource.h ('k') | cc/surfaces/surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698