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

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

Issue 2795683003: [cc]Replace use of SurfaceFactory with CompositorFrameSinkSupport in tests (Closed)
Patch Set: Update returned_resources_ in FakeCompositorFrameSinkSupportClient::DidReceiveCompositorFrameAck Created 3 years, 8 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/surfaces/surface_manager_ref_unittest.cc ('k') | cc/surfaces/surfaces_pixeltest.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/surface.h" 5 #include "cc/surfaces/surface.h"
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "cc/output/copy_output_result.h" 7 #include "cc/output/copy_output_result.h"
8 #include "cc/surfaces/compositor_frame_sink_support.h"
8 #include "cc/surfaces/local_surface_id_allocator.h" 9 #include "cc/surfaces/local_surface_id_allocator.h"
9 #include "cc/surfaces/surface_dependency_tracker.h" 10 #include "cc/surfaces/surface_dependency_tracker.h"
10 #include "cc/surfaces/surface_factory.h"
11 #include "cc/surfaces/surface_factory_client.h"
12 #include "cc/surfaces/surface_manager.h" 11 #include "cc/surfaces/surface_manager.h"
13 #include "cc/test/begin_frame_args_test.h" 12 #include "cc/test/begin_frame_args_test.h"
14 #include "cc/test/fake_external_begin_frame_source.h" 13 #include "cc/test/fake_external_begin_frame_source.h"
15 #include "cc/test/scheduler_test_common.h" 14 #include "cc/test/scheduler_test_common.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/gfx/geometry/size.h" 16 #include "ui/gfx/geometry/size.h"
18 17
19 namespace cc { 18 namespace cc {
20 namespace { 19 namespace {
21 20
22 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); 21 constexpr FrameSinkId kArbitraryFrameSinkId(1, 1);
23 22 constexpr bool kIsRoot = true;
24 class FakeSurfaceFactoryClient : public SurfaceFactoryClient { 23 constexpr bool kHandlesFrameSinkIdInvalidation = true;
25 public: 24 constexpr bool kNeedsSyncPoints = true;
26 FakeSurfaceFactoryClient() : begin_frame_source_(nullptr) {}
27
28 void ReturnResources(const ReturnedResourceArray& resources) override {}
29
30 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {
31 begin_frame_source_ = begin_frame_source;
32 }
33
34 BeginFrameSource* begin_frame_source() { return begin_frame_source_; }
35
36 private:
37 BeginFrameSource* begin_frame_source_;
38 };
39 25
40 TEST(SurfaceTest, SurfaceLifetime) { 26 TEST(SurfaceTest, SurfaceLifetime) {
41 SurfaceManager manager; 27 SurfaceManager manager;
42 FakeSurfaceFactoryClient surface_factory_client; 28 std::unique_ptr<CompositorFrameSinkSupport> support =
43 SurfaceFactory factory(kArbitraryFrameSinkId, &manager, 29 CompositorFrameSinkSupport::Create(
44 &surface_factory_client); 30 nullptr, &manager, kArbitraryFrameSinkId, kIsRoot,
31 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
45 32
46 LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); 33 LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create());
47 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); 34 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id);
48 factory.SubmitCompositorFrame(local_surface_id, CompositorFrame(), 35 support->SubmitCompositorFrame(local_surface_id, CompositorFrame());
49 SurfaceFactory::DrawCallback());
50 EXPECT_TRUE(manager.GetSurfaceForId(surface_id)); 36 EXPECT_TRUE(manager.GetSurfaceForId(surface_id));
51 factory.EvictSurface(); 37 support->EvictFrame();
52 38
53 EXPECT_EQ(NULL, manager.GetSurfaceForId(surface_id)); 39 EXPECT_EQ(NULL, manager.GetSurfaceForId(surface_id));
54 } 40 }
55 41
56 TEST(SurfaceTest, SurfaceIds) { 42 TEST(SurfaceTest, SurfaceIds) {
57 for (size_t i = 0; i < 3; ++i) { 43 for (size_t i = 0; i < 3; ++i) {
58 LocalSurfaceIdAllocator allocator; 44 LocalSurfaceIdAllocator allocator;
59 LocalSurfaceId id1 = allocator.GenerateId(); 45 LocalSurfaceId id1 = allocator.GenerateId();
60 LocalSurfaceId id2 = allocator.GenerateId(); 46 LocalSurfaceId id2 = allocator.GenerateId();
61 EXPECT_NE(id1, id2); 47 EXPECT_NE(id1, id2);
62 } 48 }
63 } 49 }
64 50
65 void TestCopyResultCallback(bool* called, 51 void TestCopyResultCallback(bool* called,
66 std::unique_ptr<CopyOutputResult> result) { 52 std::unique_ptr<CopyOutputResult> result) {
67 *called = true; 53 *called = true;
68 } 54 }
69 55
70 // Test that CopyOutputRequests can outlive the current frame and be 56 // Test that CopyOutputRequests can outlive the current frame and be
71 // aggregated on the next frame. 57 // aggregated on the next frame.
72 TEST(SurfaceTest, CopyRequestLifetime) { 58 TEST(SurfaceTest, CopyRequestLifetime) {
73 SurfaceManager manager; 59 SurfaceManager manager;
74 FakeSurfaceFactoryClient surface_factory_client; 60 std::unique_ptr<CompositorFrameSinkSupport> support =
75 SurfaceFactory factory(kArbitraryFrameSinkId, &manager, 61 CompositorFrameSinkSupport::Create(
76 &surface_factory_client); 62 nullptr, &manager, kArbitraryFrameSinkId, kIsRoot,
63 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
77 64
78 LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); 65 LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create());
79 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); 66 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id);
80 CompositorFrame frame; 67 CompositorFrame frame;
81 frame.render_pass_list.push_back(RenderPass::Create()); 68 frame.render_pass_list.push_back(RenderPass::Create());
82 factory.SubmitCompositorFrame(local_surface_id, std::move(frame), 69 support->SubmitCompositorFrame(local_surface_id, std::move(frame));
83 SurfaceFactory::DrawCallback());
84 Surface* surface = manager.GetSurfaceForId(surface_id); 70 Surface* surface = manager.GetSurfaceForId(surface_id);
85 ASSERT_TRUE(!!surface); 71 ASSERT_TRUE(!!surface);
86 72
87 bool copy_called = false; 73 bool copy_called = false;
88 factory.RequestCopyOfSurface(CopyOutputRequest::CreateRequest( 74 support->RequestCopyOfSurface(CopyOutputRequest::CreateRequest(
89 base::Bind(&TestCopyResultCallback, &copy_called))); 75 base::Bind(&TestCopyResultCallback, &copy_called)));
90 EXPECT_TRUE(manager.GetSurfaceForId(surface_id)); 76 EXPECT_TRUE(manager.GetSurfaceForId(surface_id));
91 EXPECT_FALSE(copy_called); 77 EXPECT_FALSE(copy_called);
92 78
93 int max_frame = 3, start_id = 200; 79 int max_frame = 3, start_id = 200;
94 for (int i = 0; i < max_frame; ++i) { 80 for (int i = 0; i < max_frame; ++i) {
95 CompositorFrame frame; 81 CompositorFrame frame;
96 frame.render_pass_list.push_back(RenderPass::Create()); 82 frame.render_pass_list.push_back(RenderPass::Create());
97 frame.render_pass_list.back()->id = i * 3 + start_id; 83 frame.render_pass_list.back()->id = i * 3 + start_id;
98 frame.render_pass_list.push_back(RenderPass::Create()); 84 frame.render_pass_list.push_back(RenderPass::Create());
99 frame.render_pass_list.back()->id = i * 3 + start_id + 1; 85 frame.render_pass_list.back()->id = i * 3 + start_id + 1;
100 frame.render_pass_list.push_back(RenderPass::Create()); 86 frame.render_pass_list.push_back(RenderPass::Create());
101 frame.render_pass_list.back()->id = i * 3 + start_id + 2; 87 frame.render_pass_list.back()->id = i * 3 + start_id + 2;
102 factory.SubmitCompositorFrame(local_surface_id, std::move(frame), 88 support->SubmitCompositorFrame(local_surface_id, std::move(frame));
103 SurfaceFactory::DrawCallback());
104 } 89 }
105 90
106 int last_pass_id = (max_frame - 1) * 3 + start_id + 2; 91 int last_pass_id = (max_frame - 1) * 3 + start_id + 2;
107 // The copy request should stay on the Surface until TakeCopyOutputRequests 92 // The copy request should stay on the Surface until TakeCopyOutputRequests
108 // is called. 93 // is called.
109 EXPECT_FALSE(copy_called); 94 EXPECT_FALSE(copy_called);
110 EXPECT_EQ( 95 EXPECT_EQ(
111 1u, 96 1u,
112 surface->GetActiveFrame().render_pass_list.back()->copy_requests.size()); 97 surface->GetActiveFrame().render_pass_list.back()->copy_requests.size());
113 98
114 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests; 99 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests;
115 surface->TakeCopyOutputRequests(&copy_requests); 100 surface->TakeCopyOutputRequests(&copy_requests);
116 EXPECT_EQ(1u, copy_requests.size()); 101 EXPECT_EQ(1u, copy_requests.size());
117 // Last (root) pass should receive copy request. 102 // Last (root) pass should receive copy request.
118 ASSERT_EQ(1u, copy_requests.count(last_pass_id)); 103 ASSERT_EQ(1u, copy_requests.count(last_pass_id));
119 EXPECT_FALSE(copy_called); 104 EXPECT_FALSE(copy_called);
120 copy_requests.find(last_pass_id)->second->SendEmptyResult(); 105 copy_requests.find(last_pass_id)->second->SendEmptyResult();
121 EXPECT_TRUE(copy_called); 106 EXPECT_TRUE(copy_called);
122 107
123 factory.EvictSurface(); 108 support->EvictFrame();
124 } 109 }
125 110
126 } // namespace 111 } // namespace
127 } // namespace cc 112 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_manager_ref_unittest.cc ('k') | cc/surfaces/surfaces_pixeltest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698