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

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

Issue 2795683003: [cc]Replace use of SurfaceFactory with CompositorFrameSinkSupport in tests (Closed)
Patch Set: Fix SurfaceManagerRefTest 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
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_aggregator.h" 5 #include "cc/surfaces/surface_aggregator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "cc/output/compositor_frame.h" 14 #include "cc/output/compositor_frame.h"
15 #include "cc/quads/render_pass.h" 15 #include "cc/quads/render_pass.h"
16 #include "cc/quads/render_pass_draw_quad.h" 16 #include "cc/quads/render_pass_draw_quad.h"
17 #include "cc/quads/solid_color_draw_quad.h" 17 #include "cc/quads/solid_color_draw_quad.h"
18 #include "cc/quads/surface_draw_quad.h" 18 #include "cc/quads/surface_draw_quad.h"
19 #include "cc/quads/texture_draw_quad.h" 19 #include "cc/quads/texture_draw_quad.h"
20 #include "cc/resources/shared_bitmap_manager.h" 20 #include "cc/resources/shared_bitmap_manager.h"
21 #include "cc/surfaces/compositor_frame_sink_support.h"
21 #include "cc/surfaces/local_surface_id_allocator.h" 22 #include "cc/surfaces/local_surface_id_allocator.h"
22 #include "cc/surfaces/surface.h" 23 #include "cc/surfaces/surface.h"
23 #include "cc/surfaces/surface_factory.h"
24 #include "cc/surfaces/surface_factory_client.h"
25 #include "cc/surfaces/surface_manager.h" 24 #include "cc/surfaces/surface_manager.h"
25 #include "cc/test/empty_compositor_frame_sink_support_client.h"
26 #include "cc/test/fake_resource_provider.h" 26 #include "cc/test/fake_resource_provider.h"
27 #include "cc/test/render_pass_test_utils.h" 27 #include "cc/test/render_pass_test_utils.h"
28 #include "cc/test/surface_aggregator_test_helpers.h" 28 #include "cc/test/surface_aggregator_test_helpers.h"
29 #include "cc/test/test_shared_bitmap_manager.h" 29 #include "cc/test/test_shared_bitmap_manager.h"
30 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "third_party/skia/include/core/SkColor.h" 32 #include "third_party/skia/include/core/SkColor.h"
33 33
34 namespace cc { 34 namespace cc {
35 namespace { 35 namespace {
36 36
37 constexpr FrameSinkId kArbitraryRootFrameSinkId(1, 1); 37 constexpr FrameSinkId kArbitraryRootFrameSinkId(1, 1);
38 constexpr FrameSinkId kArbitraryChildFrameSinkId1(2, 2); 38 constexpr FrameSinkId kArbitraryFrameSinkId1(2, 2);
39 constexpr FrameSinkId kArbitraryChildFrameSinkId2(3, 3); 39 constexpr FrameSinkId kArbitraryFrameSinkId2(3, 3);
40 constexpr FrameSinkId kArbitraryMiddleFrameSinkId(4, 4); 40 constexpr FrameSinkId kArbitraryMiddleFrameSinkId(4, 4);
41 constexpr FrameSinkId kArbitraryReservedFrameSinkId(5, 5);
42 constexpr FrameSinkId kArbitraryFrameSinkId3(6, 6);
41 const base::UnguessableToken kArbitraryToken = base::UnguessableToken::Create(); 43 const base::UnguessableToken kArbitraryToken = base::UnguessableToken::Create();
44 constexpr bool is_root = true;
danakj 2017/04/07 15:52:44 right, consts out in the namespace (or class) scop
Alex Z. 2017/04/07 20:43:58 Done.
45 constexpr bool is_root_child = false;
46 constexpr bool handles_frame_sink_id_invalidation = true;
47 constexpr bool needs_sync_points = false;
42 48
43 SurfaceId InvalidSurfaceId() { 49 SurfaceId InvalidSurfaceId() {
44 static SurfaceId invalid(FrameSinkId(), 50 static SurfaceId invalid(FrameSinkId(),
45 LocalSurfaceId(0xdeadbeef, kArbitraryToken)); 51 LocalSurfaceId(0xdeadbeef, kArbitraryToken));
46 return invalid; 52 return invalid;
47 } 53 }
48 54
49 gfx::Size SurfaceSize() { 55 gfx::Size SurfaceSize() {
50 static gfx::Size size(100, 100); 56 static gfx::Size size(100, 100);
51 return size; 57 return size;
52 } 58 }
53 59
54 class EmptySurfaceFactoryClient : public SurfaceFactoryClient {
55 public:
56 void ReturnResources(const ReturnedResourceArray& resources) override {}
57
58 void WillDrawSurface(const LocalSurfaceId& id,
59 const gfx::Rect& damage_rect) override {
60 last_local_surface_id_ = id;
61 last_damage_rect_ = damage_rect;
62 }
63
64 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {}
65
66 gfx::Rect last_damage_rect_;
67 LocalSurfaceId last_local_surface_id_;
68 };
69
70 class SurfaceAggregatorTest : public testing::Test { 60 class SurfaceAggregatorTest : public testing::Test {
71 public: 61 public:
72 explicit SurfaceAggregatorTest(bool use_damage_rect) 62 explicit SurfaceAggregatorTest(bool use_damage_rect)
73 : factory_(kArbitraryRootFrameSinkId, &manager_, &empty_client_), 63 : support_(&empty_client_,
64 &manager_,
65 kArbitraryRootFrameSinkId,
66 is_root,
67 handles_frame_sink_id_invalidation,
68 needs_sync_points),
74 aggregator_(&manager_, NULL, use_damage_rect) {} 69 aggregator_(&manager_, NULL, use_damage_rect) {}
75 70
76 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} 71 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {}
77 72
78 void TearDown() override { 73 void TearDown() override {
79 factory_.EvictSurface(); 74 support_.EvictFrame();
80 testing::Test::TearDown(); 75 testing::Test::TearDown();
81 } 76 }
82 77
83 protected: 78 protected:
84 SurfaceManager manager_; 79 SurfaceManager manager_;
85 EmptySurfaceFactoryClient empty_client_; 80 EmptyCompositorFrameSinkSupportClient empty_client_;
86 SurfaceFactory factory_; 81 CompositorFrameSinkSupport support_;
87 SurfaceAggregator aggregator_; 82 SurfaceAggregator aggregator_;
88 }; 83 };
89 84
90 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { 85 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) {
91 LocalSurfaceId local_surface_id(7, base::UnguessableToken::Create()); 86 LocalSurfaceId local_surface_id(7, base::UnguessableToken::Create());
92 SurfaceId one_id(kArbitraryRootFrameSinkId, local_surface_id); 87 SurfaceId one_id(kArbitraryRootFrameSinkId, local_surface_id);
93 factory_.SubmitCompositorFrame(local_surface_id, CompositorFrame(), 88 support_.SubmitCompositorFrame(local_surface_id, CompositorFrame());
94 SurfaceFactory::DrawCallback());
95 89
96 CompositorFrame frame = aggregator_.Aggregate(one_id); 90 CompositorFrame frame = aggregator_.Aggregate(one_id);
97 EXPECT_TRUE(frame.render_pass_list.empty()); 91 EXPECT_TRUE(frame.render_pass_list.empty());
98 } 92 }
99 93
100 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { 94 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest {
101 public: 95 public:
102 explicit SurfaceAggregatorValidSurfaceTest(bool use_damage_rect) 96 explicit SurfaceAggregatorValidSurfaceTest(bool use_damage_rect)
103 : SurfaceAggregatorTest(use_damage_rect), 97 : SurfaceAggregatorTest(use_damage_rect),
104 child_factory_(kArbitraryChildFrameSinkId1, 98 child_support_(nullptr,
105 &manager_, 99 &manager_,
106 &empty_child_client_) {} 100 kArbitraryReservedFrameSinkId,
101 is_root_child,
102 handles_frame_sink_id_invalidation,
103 needs_sync_points) {}
107 SurfaceAggregatorValidSurfaceTest() 104 SurfaceAggregatorValidSurfaceTest()
108 : SurfaceAggregatorValidSurfaceTest(false) {} 105 : SurfaceAggregatorValidSurfaceTest(false) {}
109 106
110 void SetUp() override { 107 void SetUp() override {
111 SurfaceAggregatorTest::SetUp(); 108 SurfaceAggregatorTest::SetUp();
112 root_local_surface_id_ = allocator_.GenerateId(); 109 root_local_surface_id_ = allocator_.GenerateId();
113 root_surface_ = manager_.GetSurfaceForId( 110 root_surface_ = manager_.GetSurfaceForId(
114 SurfaceId(factory_.frame_sink_id(), root_local_surface_id_)); 111 SurfaceId(support_.frame_sink_id(), root_local_surface_id_));
115 } 112 }
116 113
117 void TearDown() override { 114 void TearDown() override {
118 child_factory_.EvictSurface(); 115 child_support_.EvictFrame();
119 SurfaceAggregatorTest::TearDown(); 116 SurfaceAggregatorTest::TearDown();
120 } 117 }
121 118
122 void AggregateAndVerify(test::Pass* expected_passes, 119 void AggregateAndVerify(test::Pass* expected_passes,
123 size_t expected_pass_count, 120 size_t expected_pass_count,
124 SurfaceId* surface_ids, 121 SurfaceId* surface_ids,
125 size_t expected_surface_count) { 122 size_t expected_surface_count) {
126 CompositorFrame aggregated_frame = aggregator_.Aggregate( 123 CompositorFrame aggregated_frame = aggregator_.Aggregate(
127 SurfaceId(factory_.frame_sink_id(), root_local_surface_id_)); 124 SurfaceId(support_.frame_sink_id(), root_local_surface_id_));
128 125
129 TestPassesMatchExpectations(expected_passes, expected_pass_count, 126 TestPassesMatchExpectations(expected_passes, expected_pass_count,
130 &aggregated_frame.render_pass_list); 127 &aggregated_frame.render_pass_list);
131 128
132 // Ensure no duplicate pass ids output. 129 // Ensure no duplicate pass ids output.
133 std::set<int> used_passes; 130 std::set<int> used_passes;
134 for (const auto& pass : aggregated_frame.render_pass_list) { 131 for (const auto& pass : aggregated_frame.render_pass_list) {
135 EXPECT_TRUE(used_passes.insert(pass->id).second); 132 EXPECT_TRUE(used_passes.insert(pass->id).second);
136 } 133 }
137 134
138 EXPECT_EQ(expected_surface_count, 135 EXPECT_EQ(expected_surface_count,
139 aggregator_.previous_contained_surfaces().size()); 136 aggregator_.previous_contained_surfaces().size());
140 for (size_t i = 0; i < expected_surface_count; i++) { 137 for (size_t i = 0; i < expected_surface_count; i++) {
141 EXPECT_TRUE( 138 EXPECT_TRUE(
142 aggregator_.previous_contained_surfaces().find(surface_ids[i]) != 139 aggregator_.previous_contained_surfaces().find(surface_ids[i]) !=
143 aggregator_.previous_contained_surfaces().end()); 140 aggregator_.previous_contained_surfaces().end());
144 } 141 }
145 } 142 }
146 143
147 void SubmitPassListAsFrame(SurfaceFactory* factory, 144 void SubmitPassListAsFrame(CompositorFrameSinkSupport* support,
148 const LocalSurfaceId& local_surface_id, 145 const LocalSurfaceId& local_surface_id,
149 RenderPassList* pass_list) { 146 RenderPassList* pass_list) {
150 CompositorFrame frame; 147 CompositorFrame frame;
151 pass_list->swap(frame.render_pass_list); 148 pass_list->swap(frame.render_pass_list);
152 149
153 factory->SubmitCompositorFrame(local_surface_id, std::move(frame), 150 support->SubmitCompositorFrame(local_surface_id, std::move(frame));
154 SurfaceFactory::DrawCallback());
155 } 151 }
156 152
157 void SubmitCompositorFrame(SurfaceFactory* factory, 153 void SubmitCompositorFrame(CompositorFrameSinkSupport* support,
158 test::Pass* passes, 154 test::Pass* passes,
159 size_t pass_count, 155 size_t pass_count,
160 const LocalSurfaceId& local_surface_id) { 156 const LocalSurfaceId& local_surface_id) {
161 RenderPassList pass_list; 157 RenderPassList pass_list;
162 AddPasses(&pass_list, gfx::Rect(SurfaceSize()), passes, pass_count); 158 AddPasses(&pass_list, gfx::Rect(SurfaceSize()), passes, pass_count);
163 SubmitPassListAsFrame(factory, local_surface_id, &pass_list); 159 SubmitPassListAsFrame(support, local_surface_id, &pass_list);
164 } 160 }
165 161
166 void QueuePassAsFrame(std::unique_ptr<RenderPass> pass, 162 void QueuePassAsFrame(std::unique_ptr<RenderPass> pass,
167 const LocalSurfaceId& local_surface_id, 163 const LocalSurfaceId& local_surface_id,
168 SurfaceFactory* factory) { 164 CompositorFrameSinkSupport* support) {
169 CompositorFrame child_frame; 165 CompositorFrame child_frame;
170 child_frame.render_pass_list.push_back(std::move(pass)); 166 child_frame.render_pass_list.push_back(std::move(pass));
171 167
172 factory->SubmitCompositorFrame(local_surface_id, std::move(child_frame), 168 support->SubmitCompositorFrame(local_surface_id, std::move(child_frame));
173 SurfaceFactory::DrawCallback());
174 } 169 }
175 170
176 protected: 171 protected:
177 LocalSurfaceId root_local_surface_id_; 172 LocalSurfaceId root_local_surface_id_;
178 Surface* root_surface_; 173 Surface* root_surface_;
179 LocalSurfaceIdAllocator allocator_; 174 LocalSurfaceIdAllocator allocator_;
180 EmptySurfaceFactoryClient empty_child_client_; 175 CompositorFrameSinkSupport child_support_;
181 SurfaceFactory child_factory_;
182 LocalSurfaceIdAllocator child_allocator_; 176 LocalSurfaceIdAllocator child_allocator_;
183 }; 177 };
184 178
185 // Tests that a very simple frame containing only two solid color quads makes it 179 // Tests that a very simple frame containing only two solid color quads makes it
186 // through the aggregator correctly. 180 // through the aggregator correctly.
187 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleFrame) { 181 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleFrame) {
188 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorRED), 182 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorRED),
189 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 183 test::Quad::SolidColorQuad(SK_ColorBLUE)};
190 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; 184 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
191 185
192 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 186 SubmitCompositorFrame(&support_, passes, arraysize(passes),
193 root_local_surface_id_); 187 root_local_surface_id_);
194 188
195 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 189 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
196 SurfaceId ids[] = {root_surface_id}; 190 SurfaceId ids[] = {root_surface_id};
197 191
198 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids)); 192 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids));
199 193
200 // Check that WillDrawSurface was called. 194 // Check that WillDrawSurface was called.
201 EXPECT_EQ(gfx::Rect(SurfaceSize()), empty_client_.last_damage_rect_); 195 EXPECT_EQ(gfx::Rect(SurfaceSize()), empty_client_.last_damage_rect());
202 EXPECT_EQ(root_local_surface_id_, empty_client_.last_local_surface_id_); 196 EXPECT_EQ(root_local_surface_id_, empty_client_.last_local_surface_id());
203 } 197 }
204 198
205 TEST_F(SurfaceAggregatorValidSurfaceTest, OpacityCopied) { 199 TEST_F(SurfaceAggregatorValidSurfaceTest, OpacityCopied) {
206 SurfaceFactory embedded_factory(kArbitraryChildFrameSinkId1, &manager_, 200 CompositorFrameSinkSupport embedded_support(
207 &empty_client_); 201 nullptr, &manager_, kArbitraryFrameSinkId1, is_root,
202 handles_frame_sink_id_invalidation, needs_sync_points);
208 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId(); 203 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId();
209 SurfaceId embedded_surface_id(embedded_factory.frame_sink_id(), 204 SurfaceId embedded_surface_id(embedded_support.frame_sink_id(),
210 embedded_local_surface_id); 205 embedded_local_surface_id);
211 206
212 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN), 207 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
213 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 208 test::Quad::SolidColorQuad(SK_ColorBLUE)};
214 test::Pass embedded_passes[] = { 209 test::Pass embedded_passes[] = {
215 test::Pass(embedded_quads, arraysize(embedded_quads))}; 210 test::Pass(embedded_quads, arraysize(embedded_quads))};
216 211
217 SubmitCompositorFrame(&embedded_factory, embedded_passes, 212 SubmitCompositorFrame(&embedded_support, embedded_passes,
218 arraysize(embedded_passes), embedded_local_surface_id); 213 arraysize(embedded_passes), embedded_local_surface_id);
219 214
220 test::Quad quads[] = { 215 test::Quad quads[] = {
221 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), .5f)}; 216 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), .5f)};
222 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; 217 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
223 218
224 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 219 SubmitCompositorFrame(&support_, passes, arraysize(passes),
225 root_local_surface_id_); 220 root_local_surface_id_);
226 221
227 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 222 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
228 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 223 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
229 224
230 RenderPassList& render_pass_list(aggregated_frame.render_pass_list); 225 RenderPassList& render_pass_list(aggregated_frame.render_pass_list);
231 ASSERT_EQ(2u, render_pass_list.size()); 226 ASSERT_EQ(2u, render_pass_list.size());
232 SharedQuadStateList& shared_quad_state_list( 227 SharedQuadStateList& shared_quad_state_list(
233 render_pass_list[0]->shared_quad_state_list); 228 render_pass_list[0]->shared_quad_state_list);
234 ASSERT_EQ(2u, shared_quad_state_list.size()); 229 ASSERT_EQ(2u, shared_quad_state_list.size());
235 EXPECT_EQ(1.f, shared_quad_state_list.ElementAt(0)->opacity); 230 EXPECT_EQ(1.f, shared_quad_state_list.ElementAt(0)->opacity);
236 EXPECT_EQ(1.f, shared_quad_state_list.ElementAt(1)->opacity); 231 EXPECT_EQ(1.f, shared_quad_state_list.ElementAt(1)->opacity);
237 232
238 SharedQuadStateList& shared_quad_state_list2( 233 SharedQuadStateList& shared_quad_state_list2(
239 render_pass_list[1]->shared_quad_state_list); 234 render_pass_list[1]->shared_quad_state_list);
240 ASSERT_EQ(1u, shared_quad_state_list2.size()); 235 ASSERT_EQ(1u, shared_quad_state_list2.size());
241 EXPECT_EQ(.5f, shared_quad_state_list2.ElementAt(0)->opacity); 236 EXPECT_EQ(.5f, shared_quad_state_list2.ElementAt(0)->opacity);
242 237
243 embedded_factory.EvictSurface(); 238 embedded_support.EvictFrame();
244 } 239 }
245 240
246 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSimpleFrame) { 241 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSimpleFrame) {
247 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE), 242 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE),
248 test::Quad::SolidColorQuad(SK_ColorLTGRAY)}, 243 test::Quad::SolidColorQuad(SK_ColorLTGRAY)},
249 {test::Quad::SolidColorQuad(SK_ColorGRAY), 244 {test::Quad::SolidColorQuad(SK_ColorGRAY),
250 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}}; 245 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}};
251 test::Pass passes[] = {test::Pass(quads[0], arraysize(quads[0]), 1), 246 test::Pass passes[] = {test::Pass(quads[0], arraysize(quads[0]), 1),
252 test::Pass(quads[1], arraysize(quads[1]), 2)}; 247 test::Pass(quads[1], arraysize(quads[1]), 2)};
253 248
254 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 249 SubmitCompositorFrame(&support_, passes, arraysize(passes),
255 root_local_surface_id_); 250 root_local_surface_id_);
256 251
257 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 252 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
258 SurfaceId ids[] = {root_surface_id}; 253 SurfaceId ids[] = {root_surface_id};
259 254
260 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids)); 255 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids));
261 } 256 }
262 257
263 // Ensure that the render pass ID map properly keeps and deletes entries. 258 // Ensure that the render pass ID map properly keeps and deletes entries.
264 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassDeallocation) { 259 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassDeallocation) {
265 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE), 260 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE),
266 test::Quad::SolidColorQuad(SK_ColorLTGRAY)}, 261 test::Quad::SolidColorQuad(SK_ColorLTGRAY)},
267 {test::Quad::SolidColorQuad(SK_ColorGRAY), 262 {test::Quad::SolidColorQuad(SK_ColorGRAY),
268 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}}; 263 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}};
269 test::Pass passes[] = {test::Pass(quads[0], arraysize(quads[0]), 2), 264 test::Pass passes[] = {test::Pass(quads[0], arraysize(quads[0]), 2),
270 test::Pass(quads[1], arraysize(quads[1]), 1)}; 265 test::Pass(quads[1], arraysize(quads[1]), 1)};
271 266
272 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 267 SubmitCompositorFrame(&support_, passes, arraysize(passes),
273 root_local_surface_id_); 268 root_local_surface_id_);
274 269
275 SurfaceId surface_id(factory_.frame_sink_id(), root_local_surface_id_); 270 SurfaceId surface_id(support_.frame_sink_id(), root_local_surface_id_);
276 271
277 CompositorFrame aggregated_frame; 272 CompositorFrame aggregated_frame;
278 aggregated_frame = aggregator_.Aggregate(surface_id); 273 aggregated_frame = aggregator_.Aggregate(surface_id);
279 auto id0 = aggregated_frame.render_pass_list[0]->id; 274 auto id0 = aggregated_frame.render_pass_list[0]->id;
280 auto id1 = aggregated_frame.render_pass_list[1]->id; 275 auto id1 = aggregated_frame.render_pass_list[1]->id;
281 EXPECT_NE(id1, id0); 276 EXPECT_NE(id1, id0);
282 277
283 // Aggregated RenderPass ids should remain the same between frames. 278 // Aggregated RenderPass ids should remain the same between frames.
284 aggregated_frame = aggregator_.Aggregate(surface_id); 279 aggregated_frame = aggregator_.Aggregate(surface_id);
285 EXPECT_EQ(id0, aggregated_frame.render_pass_list[0]->id); 280 EXPECT_EQ(id0, aggregated_frame.render_pass_list[0]->id);
286 EXPECT_EQ(id1, aggregated_frame.render_pass_list[1]->id); 281 EXPECT_EQ(id1, aggregated_frame.render_pass_list[1]->id);
287 282
288 test::Pass passes2[] = {test::Pass(quads[0], arraysize(quads[0]), 3), 283 test::Pass passes2[] = {test::Pass(quads[0], arraysize(quads[0]), 3),
289 test::Pass(quads[1], arraysize(quads[1]), 1)}; 284 test::Pass(quads[1], arraysize(quads[1]), 1)};
290 285
291 SubmitCompositorFrame(&factory_, passes2, arraysize(passes2), 286 SubmitCompositorFrame(&support_, passes2, arraysize(passes2),
292 root_local_surface_id_); 287 root_local_surface_id_);
293 288
294 // The RenderPass that still exists should keep the same ID. 289 // The RenderPass that still exists should keep the same ID.
295 aggregated_frame = aggregator_.Aggregate(surface_id); 290 aggregated_frame = aggregator_.Aggregate(surface_id);
296 auto id2 = aggregated_frame.render_pass_list[0]->id; 291 auto id2 = aggregated_frame.render_pass_list[0]->id;
297 EXPECT_NE(id2, id1); 292 EXPECT_NE(id2, id1);
298 EXPECT_NE(id2, id0); 293 EXPECT_NE(id2, id0);
299 EXPECT_EQ(id1, aggregated_frame.render_pass_list[1]->id); 294 EXPECT_EQ(id1, aggregated_frame.render_pass_list[1]->id);
300 295
301 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 296 SubmitCompositorFrame(&support_, passes, arraysize(passes),
302 root_local_surface_id_); 297 root_local_surface_id_);
303 298
304 // |id1| didn't exist in the previous frame, so it should be 299 // |id1| didn't exist in the previous frame, so it should be
305 // mapped to a new ID. 300 // mapped to a new ID.
306 aggregated_frame = aggregator_.Aggregate(surface_id); 301 aggregated_frame = aggregator_.Aggregate(surface_id);
307 auto id3 = aggregated_frame.render_pass_list[0]->id; 302 auto id3 = aggregated_frame.render_pass_list[0]->id;
308 EXPECT_NE(id3, id2); 303 EXPECT_NE(id3, id2);
309 EXPECT_NE(id3, id1); 304 EXPECT_NE(id3, id1);
310 EXPECT_NE(id3, id0); 305 EXPECT_NE(id3, id0);
311 EXPECT_EQ(id1, aggregated_frame.render_pass_list[1]->id); 306 EXPECT_EQ(id1, aggregated_frame.render_pass_list[1]->id);
312 } 307 }
313 308
314 // This tests very simple embedding. root_surface has a frame containing a few 309 // This tests very simple embedding. root_surface has a frame containing a few
315 // solid color quads and a surface quad referencing embedded_surface. 310 // solid color quads and a surface quad referencing embedded_surface.
316 // embedded_surface has a frame containing only a solid color quad. The solid 311 // embedded_surface has a frame containing only a solid color quad. The solid
317 // color quad should be aggregated into the final frame. 312 // color quad should be aggregated into the final frame.
318 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleSurfaceReference) { 313 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleSurfaceReference) {
319 SurfaceFactory embedded_factory(kArbitraryChildFrameSinkId1, &manager_, 314 CompositorFrameSinkSupport embedded_support(
320 &empty_client_); 315 nullptr, &manager_, kArbitraryFrameSinkId1, is_root,
316 handles_frame_sink_id_invalidation, needs_sync_points);
321 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId(); 317 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId();
322 SurfaceId embedded_surface_id(embedded_factory.frame_sink_id(), 318 SurfaceId embedded_surface_id(embedded_support.frame_sink_id(),
323 embedded_local_surface_id); 319 embedded_local_surface_id);
324 320
325 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 321 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
326 test::Pass embedded_passes[] = { 322 test::Pass embedded_passes[] = {
327 test::Pass(embedded_quads, arraysize(embedded_quads))}; 323 test::Pass(embedded_quads, arraysize(embedded_quads))};
328 324
329 SubmitCompositorFrame(&embedded_factory, embedded_passes, 325 SubmitCompositorFrame(&embedded_support, embedded_passes,
330 arraysize(embedded_passes), embedded_local_surface_id); 326 arraysize(embedded_passes), embedded_local_surface_id);
331 327
332 test::Quad root_quads[] = { 328 test::Quad root_quads[] = {
333 test::Quad::SolidColorQuad(SK_ColorWHITE), 329 test::Quad::SolidColorQuad(SK_ColorWHITE),
334 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f), 330 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f),
335 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 331 test::Quad::SolidColorQuad(SK_ColorBLACK)};
336 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 332 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
337 333
338 SubmitCompositorFrame(&factory_, root_passes, arraysize(root_passes), 334 SubmitCompositorFrame(&support_, root_passes, arraysize(root_passes),
339 root_local_surface_id_); 335 root_local_surface_id_);
340 336
341 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE), 337 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
342 test::Quad::SolidColorQuad(SK_ColorGREEN), 338 test::Quad::SolidColorQuad(SK_ColorGREEN),
343 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 339 test::Quad::SolidColorQuad(SK_ColorBLACK)};
344 test::Pass expected_passes[] = { 340 test::Pass expected_passes[] = {
345 test::Pass(expected_quads, arraysize(expected_quads))}; 341 test::Pass(expected_quads, arraysize(expected_quads))};
346 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 342 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
347 SurfaceId ids[] = {root_surface_id, embedded_surface_id}; 343 SurfaceId ids[] = {root_surface_id, embedded_surface_id};
348 AggregateAndVerify( 344 AggregateAndVerify(
349 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 345 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
350 346
351 embedded_factory.EvictSurface(); 347 embedded_support.EvictFrame();
352 } 348 }
353 349
354 // This test verifies that in the absence of a primary Surface, 350 // This test verifies that in the absence of a primary Surface,
355 // SurfaceAggregator will embed a fallback Surface, if available. If the primary 351 // SurfaceAggregator will embed a fallback Surface, if available. If the primary
356 // Surface is available, though, the fallback will not be used. 352 // Surface is available, though, the fallback will not be used.
357 TEST_F(SurfaceAggregatorValidSurfaceTest, FallbackSurfaceReference) { 353 TEST_F(SurfaceAggregatorValidSurfaceTest, FallbackSurfaceReference) {
358 SurfaceFactory primary_child_factory(kArbitraryChildFrameSinkId1, &manager_, 354 CompositorFrameSinkSupport primary_child_support(
359 &empty_client_); 355 nullptr, &manager_, kArbitraryFrameSinkId1, is_root_child,
356 handles_frame_sink_id_invalidation, needs_sync_points);
360 LocalSurfaceId primary_child_local_surface_id = allocator_.GenerateId(); 357 LocalSurfaceId primary_child_local_surface_id = allocator_.GenerateId();
361 SurfaceId primary_child_surface_id(primary_child_factory.frame_sink_id(), 358 SurfaceId primary_child_surface_id(primary_child_support.frame_sink_id(),
362 primary_child_local_surface_id); 359 primary_child_local_surface_id);
363 360
364 SurfaceFactory fallback_child_factory(kArbitraryChildFrameSinkId2, &manager_, 361 CompositorFrameSinkSupport fallback_child_support(
365 &empty_client_); 362 nullptr, &manager_, kArbitraryFrameSinkId2, is_root_child,
363 handles_frame_sink_id_invalidation, needs_sync_points);
366 LocalSurfaceId fallback_child_local_surface_id = allocator_.GenerateId(); 364 LocalSurfaceId fallback_child_local_surface_id = allocator_.GenerateId();
367 SurfaceId fallback_child_surface_id(fallback_child_factory.frame_sink_id(), 365 SurfaceId fallback_child_surface_id(fallback_child_support.frame_sink_id(),
368 fallback_child_local_surface_id); 366 fallback_child_local_surface_id);
369 367
370 test::Quad fallback_child_quads[] = {test::Quad::SolidColorQuad(SK_ColorRED)}; 368 test::Quad fallback_child_quads[] = {test::Quad::SolidColorQuad(SK_ColorRED)};
371 test::Pass fallback_child_passes[] = { 369 test::Pass fallback_child_passes[] = {
372 test::Pass(fallback_child_quads, arraysize(fallback_child_quads))}; 370 test::Pass(fallback_child_quads, arraysize(fallback_child_quads))};
373 371
374 // Submit a CompositorFrame to the fallback Surface containing a red 372 // Submit a CompositorFrame to the fallback Surface containing a red
375 // SolidColorDrawQuad. 373 // SolidColorDrawQuad.
376 SubmitCompositorFrame(&fallback_child_factory, fallback_child_passes, 374 SubmitCompositorFrame(&fallback_child_support, fallback_child_passes,
377 arraysize(fallback_child_passes), 375 arraysize(fallback_child_passes),
378 fallback_child_local_surface_id); 376 fallback_child_local_surface_id);
379 377
380 // Try to embed |primary_child_surface_id| and if unavailabe, embed 378 // Try to embed |primary_child_surface_id| and if unavailabe, embed
381 // |fallback_child_surface_id|. 379 // |fallback_child_surface_id|.
382 test::Quad root_quads[] = {test::Quad::SurfaceQuad( 380 test::Quad root_quads[] = {test::Quad::SurfaceQuad(
383 primary_child_surface_id, fallback_child_surface_id, 1.f)}; 381 primary_child_surface_id, fallback_child_surface_id, 1.f)};
384 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 382 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
385 383
386 SubmitCompositorFrame(&factory_, root_passes, arraysize(root_passes), 384 SubmitCompositorFrame(&support_, root_passes, arraysize(root_passes),
387 root_local_surface_id_); 385 root_local_surface_id_);
388 386
389 // There is no CompositorFrame submitted to |primary_child_surface_id| and so 387 // There is no CompositorFrame submitted to |primary_child_surface_id| and so
390 // |fallback_child_surface_id| will be embedded and we should see a red 388 // |fallback_child_surface_id| will be embedded and we should see a red
391 // SolidColorDrawQuad. 389 // SolidColorDrawQuad.
392 test::Quad expected_quads1[] = {test::Quad::SolidColorQuad(SK_ColorRED)}; 390 test::Quad expected_quads1[] = {test::Quad::SolidColorQuad(SK_ColorRED)};
393 test::Pass expected_passes1[] = { 391 test::Pass expected_passes1[] = {
394 test::Pass(expected_quads1, arraysize(expected_quads1))}; 392 test::Pass(expected_quads1, arraysize(expected_quads1))};
395 393
396 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 394 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
397 SurfaceId ids[] = {root_surface_id, primary_child_surface_id, 395 SurfaceId ids[] = {root_surface_id, primary_child_surface_id,
398 fallback_child_surface_id}; 396 fallback_child_surface_id};
399 AggregateAndVerify(expected_passes1, arraysize(expected_passes1), ids, 397 AggregateAndVerify(expected_passes1, arraysize(expected_passes1), ids,
400 arraysize(ids)); 398 arraysize(ids));
401 399
402 test::Quad primary_child_quads[] = { 400 test::Quad primary_child_quads[] = {
403 test::Quad::SolidColorQuad(SK_ColorGREEN)}; 401 test::Quad::SolidColorQuad(SK_ColorGREEN)};
404 test::Pass primary_child_passes[] = { 402 test::Pass primary_child_passes[] = {
405 test::Pass(primary_child_quads, arraysize(primary_child_quads))}; 403 test::Pass(primary_child_quads, arraysize(primary_child_quads))};
406 404
407 // Submit a CompositorFrame to the primary Surface containing a green 405 // Submit a CompositorFrame to the primary Surface containing a green
408 // SolidColorDrawQuad. 406 // SolidColorDrawQuad.
409 SubmitCompositorFrame(&primary_child_factory, primary_child_passes, 407 SubmitCompositorFrame(&primary_child_support, primary_child_passes,
410 arraysize(primary_child_passes), 408 arraysize(primary_child_passes),
411 primary_child_local_surface_id); 409 primary_child_local_surface_id);
412 410
413 // Now that the primary Surface has a CompositorFrame, we expect 411 // Now that the primary Surface has a CompositorFrame, we expect
414 // SurfaceAggregator to embed the primary Surface, and drop the fallback 412 // SurfaceAggregator to embed the primary Surface, and drop the fallback
415 // Surface. 413 // Surface.
416 test::Quad expected_quads2[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 414 test::Quad expected_quads2[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
417 test::Pass expected_passes2[] = { 415 test::Pass expected_passes2[] = {
418 test::Pass(expected_quads2, arraysize(expected_quads2))}; 416 test::Pass(expected_quads2, arraysize(expected_quads2))};
419 AggregateAndVerify(expected_passes2, arraysize(expected_passes2), ids, 417 AggregateAndVerify(expected_passes2, arraysize(expected_passes2), ids,
420 arraysize(ids)); 418 arraysize(ids));
421 419
422 primary_child_factory.EvictSurface(); 420 primary_child_support.EvictFrame();
423 fallback_child_factory.EvictSurface(); 421 fallback_child_support.EvictFrame();
424 } 422 }
425 423
426 // This test verifies that in the presence of both primary Surface and fallback 424 // This test verifies that in the presence of both primary Surface and fallback
427 // Surface, the fallback will not be used. 425 // Surface, the fallback will not be used.
428 TEST_F(SurfaceAggregatorValidSurfaceTest, FallbackSurfaceReferenceWithPrimary) { 426 TEST_F(SurfaceAggregatorValidSurfaceTest, FallbackSurfaceReferenceWithPrimary) {
429 SurfaceFactory primary_child_factory(kArbitraryChildFrameSinkId1, &manager_, 427 CompositorFrameSinkSupport primary_child_support(
430 &empty_client_); 428 nullptr, &manager_, kArbitraryFrameSinkId1, is_root_child,
429 handles_frame_sink_id_invalidation, needs_sync_points);
431 LocalSurfaceId primary_child_local_surface_id = allocator_.GenerateId(); 430 LocalSurfaceId primary_child_local_surface_id = allocator_.GenerateId();
432 SurfaceId primary_child_surface_id(primary_child_factory.frame_sink_id(), 431 SurfaceId primary_child_surface_id(primary_child_support.frame_sink_id(),
433 primary_child_local_surface_id); 432 primary_child_local_surface_id);
434 test::Quad primary_child_quads[] = { 433 test::Quad primary_child_quads[] = {
435 test::Quad::SolidColorQuad(SK_ColorGREEN)}; 434 test::Quad::SolidColorQuad(SK_ColorGREEN)};
436 test::Pass primary_child_passes[] = { 435 test::Pass primary_child_passes[] = {
437 test::Pass(primary_child_quads, arraysize(primary_child_quads))}; 436 test::Pass(primary_child_quads, arraysize(primary_child_quads))};
438 437
439 // Submit a CompositorFrame to the primary Surface containing a green 438 // Submit a CompositorFrame to the primary Surface containing a green
440 // SolidColorDrawQuad. 439 // SolidColorDrawQuad.
441 SubmitCompositorFrame(&primary_child_factory, primary_child_passes, 440 SubmitCompositorFrame(&primary_child_support, primary_child_passes,
442 arraysize(primary_child_passes), 441 arraysize(primary_child_passes),
443 primary_child_local_surface_id); 442 primary_child_local_surface_id);
444 443
445 SurfaceFactory fallback_child_factory(kArbitraryChildFrameSinkId2, &manager_, 444 CompositorFrameSinkSupport fallback_child_support(
446 &empty_client_); 445 nullptr, &manager_, kArbitraryFrameSinkId2, is_root_child,
446 handles_frame_sink_id_invalidation, needs_sync_points);
447 LocalSurfaceId fallback_child_local_surface_id = allocator_.GenerateId(); 447 LocalSurfaceId fallback_child_local_surface_id = allocator_.GenerateId();
448 SurfaceId fallback_child_surface_id(fallback_child_factory.frame_sink_id(), 448 SurfaceId fallback_child_surface_id(fallback_child_support.frame_sink_id(),
449 fallback_child_local_surface_id); 449 fallback_child_local_surface_id);
450 450
451 test::Quad fallback_child_quads[] = {test::Quad::SolidColorQuad(SK_ColorRED)}; 451 test::Quad fallback_child_quads[] = {test::Quad::SolidColorQuad(SK_ColorRED)};
452 test::Pass fallback_child_passes[] = { 452 test::Pass fallback_child_passes[] = {
453 test::Pass(fallback_child_quads, arraysize(fallback_child_quads))}; 453 test::Pass(fallback_child_quads, arraysize(fallback_child_quads))};
454 454
455 // Submit a CompositorFrame to the fallback Surface containing a red 455 // Submit a CompositorFrame to the fallback Surface containing a red
456 // SolidColorDrawQuad. 456 // SolidColorDrawQuad.
457 SubmitCompositorFrame(&fallback_child_factory, fallback_child_passes, 457 SubmitCompositorFrame(&fallback_child_support, fallback_child_passes,
458 arraysize(fallback_child_passes), 458 arraysize(fallback_child_passes),
459 fallback_child_local_surface_id); 459 fallback_child_local_surface_id);
460 460
461 // Try to embed |primary_child_surface_id| and if unavailabe, embed 461 // Try to embed |primary_child_surface_id| and if unavailabe, embed
462 // |fallback_child_surface_id|. 462 // |fallback_child_surface_id|.
463 test::Quad root_quads[] = {test::Quad::SurfaceQuad( 463 test::Quad root_quads[] = {test::Quad::SurfaceQuad(
464 primary_child_surface_id, fallback_child_surface_id, 1.f)}; 464 primary_child_surface_id, fallback_child_surface_id, 1.f)};
465 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 465 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
466 466
467 SubmitCompositorFrame(&factory_, root_passes, arraysize(root_passes), 467 SubmitCompositorFrame(&support_, root_passes, arraysize(root_passes),
468 root_local_surface_id_); 468 root_local_surface_id_);
469 469
470 // The CompositorFrame is submitted to |primary_child_surface_id|, so 470 // The CompositorFrame is submitted to |primary_child_surface_id|, so
471 // |fallback_child_surface_id| will not be used and we should see a green 471 // |fallback_child_surface_id| will not be used and we should see a green
472 // SolidColorDrawQuad. 472 // SolidColorDrawQuad.
473 test::Quad expected_quads1[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 473 test::Quad expected_quads1[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
474 test::Pass expected_passes1[] = { 474 test::Pass expected_passes1[] = {
475 test::Pass(expected_quads1, arraysize(expected_quads1))}; 475 test::Pass(expected_quads1, arraysize(expected_quads1))};
476 476
477 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 477 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
478 SurfaceId ids[] = {root_surface_id, primary_child_surface_id, 478 SurfaceId ids[] = {root_surface_id, primary_child_surface_id,
479 fallback_child_surface_id}; 479 fallback_child_surface_id};
480 AggregateAndVerify(expected_passes1, arraysize(expected_passes1), ids, 480 AggregateAndVerify(expected_passes1, arraysize(expected_passes1), ids,
481 arraysize(ids)); 481 arraysize(ids));
482 482
483 primary_child_factory.EvictSurface(); 483 primary_child_support.EvictFrame();
484 fallback_child_factory.EvictSurface(); 484 fallback_child_support.EvictFrame();
485 } 485 }
486 486
487 TEST_F(SurfaceAggregatorValidSurfaceTest, CopyRequest) { 487 TEST_F(SurfaceAggregatorValidSurfaceTest, CopyRequest) {
488 SurfaceFactory embedded_factory(kArbitraryChildFrameSinkId1, &manager_, 488 CompositorFrameSinkSupport embedded_support(
489 &empty_client_); 489 nullptr, &manager_, kArbitraryFrameSinkId1, is_root_child,
490 handles_frame_sink_id_invalidation, needs_sync_points);
490 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId(); 491 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId();
491 SurfaceId embedded_surface_id(embedded_factory.frame_sink_id(), 492 SurfaceId embedded_surface_id(embedded_support.frame_sink_id(),
492 embedded_local_surface_id); 493 embedded_local_surface_id);
493 494
494 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 495 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
495 test::Pass embedded_passes[] = { 496 test::Pass embedded_passes[] = {
496 test::Pass(embedded_quads, arraysize(embedded_quads))}; 497 test::Pass(embedded_quads, arraysize(embedded_quads))};
497 498
498 SubmitCompositorFrame(&embedded_factory, embedded_passes, 499 SubmitCompositorFrame(&embedded_support, embedded_passes,
499 arraysize(embedded_passes), embedded_local_surface_id); 500 arraysize(embedded_passes), embedded_local_surface_id);
500 std::unique_ptr<CopyOutputRequest> copy_request( 501 std::unique_ptr<CopyOutputRequest> copy_request(
501 CopyOutputRequest::CreateEmptyRequest()); 502 CopyOutputRequest::CreateEmptyRequest());
502 CopyOutputRequest* copy_request_ptr = copy_request.get(); 503 CopyOutputRequest* copy_request_ptr = copy_request.get();
503 embedded_factory.RequestCopyOfSurface(std::move(copy_request)); 504 embedded_support.RequestCopyOfSurface(std::move(copy_request));
504 505
505 test::Quad root_quads[] = { 506 test::Quad root_quads[] = {
506 test::Quad::SolidColorQuad(SK_ColorWHITE), 507 test::Quad::SolidColorQuad(SK_ColorWHITE),
507 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f), 508 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f),
508 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 509 test::Quad::SolidColorQuad(SK_ColorBLACK)};
509 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 510 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
510 511
511 SubmitCompositorFrame(&factory_, root_passes, arraysize(root_passes), 512 SubmitCompositorFrame(&support_, root_passes, arraysize(root_passes),
512 root_local_surface_id_); 513 root_local_surface_id_);
513 514
514 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 515 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
515 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 516 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
516 517
517 test::Quad expected_quads[] = { 518 test::Quad expected_quads[] = {
518 test::Quad::SolidColorQuad(SK_ColorWHITE), 519 test::Quad::SolidColorQuad(SK_ColorWHITE),
519 test::Quad::RenderPassQuad(aggregated_frame.render_pass_list[0]->id), 520 test::Quad::RenderPassQuad(aggregated_frame.render_pass_list[0]->id),
520 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 521 test::Quad::SolidColorQuad(SK_ColorBLACK)};
521 test::Pass expected_passes[] = { 522 test::Pass expected_passes[] = {
522 test::Pass(embedded_quads, arraysize(embedded_quads)), 523 test::Pass(embedded_quads, arraysize(embedded_quads)),
523 test::Pass(expected_quads, arraysize(expected_quads))}; 524 test::Pass(expected_quads, arraysize(expected_quads))};
524 TestPassesMatchExpectations(expected_passes, arraysize(expected_passes), 525 TestPassesMatchExpectations(expected_passes, arraysize(expected_passes),
525 &aggregated_frame.render_pass_list); 526 &aggregated_frame.render_pass_list);
526 ASSERT_EQ(2u, aggregated_frame.render_pass_list.size()); 527 ASSERT_EQ(2u, aggregated_frame.render_pass_list.size());
527 ASSERT_EQ(1u, aggregated_frame.render_pass_list[0]->copy_requests.size()); 528 ASSERT_EQ(1u, aggregated_frame.render_pass_list[0]->copy_requests.size());
528 DCHECK_EQ(copy_request_ptr, 529 DCHECK_EQ(copy_request_ptr,
529 aggregated_frame.render_pass_list[0]->copy_requests[0].get()); 530 aggregated_frame.render_pass_list[0]->copy_requests[0].get());
530 531
531 SurfaceId surface_ids[] = {root_surface_id, embedded_surface_id}; 532 SurfaceId surface_ids[] = {root_surface_id, embedded_surface_id};
532 EXPECT_EQ(arraysize(surface_ids), 533 EXPECT_EQ(arraysize(surface_ids),
533 aggregator_.previous_contained_surfaces().size()); 534 aggregator_.previous_contained_surfaces().size());
534 for (size_t i = 0; i < arraysize(surface_ids); i++) { 535 for (size_t i = 0; i < arraysize(surface_ids); i++) {
535 EXPECT_TRUE( 536 EXPECT_TRUE(
536 aggregator_.previous_contained_surfaces().find(surface_ids[i]) != 537 aggregator_.previous_contained_surfaces().find(surface_ids[i]) !=
537 aggregator_.previous_contained_surfaces().end()); 538 aggregator_.previous_contained_surfaces().end());
538 } 539 }
539 540
540 embedded_factory.EvictSurface(); 541 embedded_support.EvictFrame();
541 } 542 }
542 543
543 // Root surface may contain copy requests. 544 // Root surface may contain copy requests.
544 TEST_F(SurfaceAggregatorValidSurfaceTest, RootCopyRequest) { 545 TEST_F(SurfaceAggregatorValidSurfaceTest, RootCopyRequest) {
545 SurfaceFactory embedded_factory(kArbitraryChildFrameSinkId1, &manager_, 546 CompositorFrameSinkSupport embedded_support(
546 &empty_client_); 547 nullptr, &manager_, kArbitraryFrameSinkId2, is_root_child,
548 handles_frame_sink_id_invalidation, needs_sync_points);
547 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId(); 549 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId();
548 SurfaceId embedded_surface_id(embedded_factory.frame_sink_id(), 550 SurfaceId embedded_surface_id(embedded_support.frame_sink_id(),
549 embedded_local_surface_id); 551 embedded_local_surface_id);
550 552
551 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 553 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
552 test::Pass embedded_passes[] = { 554 test::Pass embedded_passes[] = {
553 test::Pass(embedded_quads, arraysize(embedded_quads))}; 555 test::Pass(embedded_quads, arraysize(embedded_quads))};
554 556
555 SubmitCompositorFrame(&embedded_factory, embedded_passes, 557 SubmitCompositorFrame(&embedded_support, embedded_passes,
556 arraysize(embedded_passes), embedded_local_surface_id); 558 arraysize(embedded_passes), embedded_local_surface_id);
557 std::unique_ptr<CopyOutputRequest> copy_request( 559 std::unique_ptr<CopyOutputRequest> copy_request(
558 CopyOutputRequest::CreateEmptyRequest()); 560 CopyOutputRequest::CreateEmptyRequest());
559 CopyOutputRequest* copy_request_ptr = copy_request.get(); 561 CopyOutputRequest* copy_request_ptr = copy_request.get();
560 std::unique_ptr<CopyOutputRequest> copy_request2( 562 std::unique_ptr<CopyOutputRequest> copy_request2(
561 CopyOutputRequest::CreateEmptyRequest()); 563 CopyOutputRequest::CreateEmptyRequest());
562 CopyOutputRequest* copy_request2_ptr = copy_request2.get(); 564 CopyOutputRequest* copy_request2_ptr = copy_request2.get();
563 565
564 test::Quad root_quads[] = { 566 test::Quad root_quads[] = {
565 test::Quad::SolidColorQuad(SK_ColorWHITE), 567 test::Quad::SolidColorQuad(SK_ColorWHITE),
566 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f), 568 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f),
567 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 569 test::Quad::SolidColorQuad(SK_ColorBLACK)};
568 test::Quad root_quads2[] = {test::Quad::SolidColorQuad(SK_ColorRED)}; 570 test::Quad root_quads2[] = {test::Quad::SolidColorQuad(SK_ColorRED)};
569 test::Pass root_passes[] = { 571 test::Pass root_passes[] = {
570 test::Pass(root_quads, arraysize(root_quads), 1), 572 test::Pass(root_quads, arraysize(root_quads), 1),
571 test::Pass(root_quads2, arraysize(root_quads2), 2)}; 573 test::Pass(root_quads2, arraysize(root_quads2), 2)};
572 { 574 {
573 CompositorFrame frame; 575 CompositorFrame frame;
574 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes, 576 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes,
575 arraysize(root_passes)); 577 arraysize(root_passes));
576 frame.render_pass_list[0]->copy_requests.push_back(std::move(copy_request)); 578 frame.render_pass_list[0]->copy_requests.push_back(std::move(copy_request));
577 frame.render_pass_list[1]->copy_requests.push_back( 579 frame.render_pass_list[1]->copy_requests.push_back(
578 std::move(copy_request2)); 580 std::move(copy_request2));
579 581
580 factory_.SubmitCompositorFrame(root_local_surface_id_, std::move(frame), 582 support_.SubmitCompositorFrame(root_local_surface_id_, std::move(frame));
581 SurfaceFactory::DrawCallback());
582 } 583 }
583 584
584 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 585 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
585 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 586 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
586 587
587 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE), 588 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
588 test::Quad::SolidColorQuad(SK_ColorGREEN), 589 test::Quad::SolidColorQuad(SK_ColorGREEN),
589 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 590 test::Quad::SolidColorQuad(SK_ColorBLACK)};
590 test::Pass expected_passes[] = { 591 test::Pass expected_passes[] = {
591 test::Pass(expected_quads, arraysize(expected_quads)), 592 test::Pass(expected_quads, arraysize(expected_quads)),
592 test::Pass(root_quads2, arraysize(root_quads2))}; 593 test::Pass(root_quads2, arraysize(root_quads2))};
593 TestPassesMatchExpectations(expected_passes, arraysize(expected_passes), 594 TestPassesMatchExpectations(expected_passes, arraysize(expected_passes),
594 &aggregated_frame.render_pass_list); 595 &aggregated_frame.render_pass_list);
(...skipping 15 matching lines...) Expand all
610 } 611 }
611 612
612 // Ensure copy requests have been removed from root surface. 613 // Ensure copy requests have been removed from root surface.
613 const CompositorFrame& original_frame = 614 const CompositorFrame& original_frame =
614 manager_.GetSurfaceForId(root_surface_id)->GetActiveFrame(); 615 manager_.GetSurfaceForId(root_surface_id)->GetActiveFrame();
615 const RenderPassList& original_pass_list = original_frame.render_pass_list; 616 const RenderPassList& original_pass_list = original_frame.render_pass_list;
616 ASSERT_EQ(2u, original_pass_list.size()); 617 ASSERT_EQ(2u, original_pass_list.size());
617 DCHECK(original_pass_list[0]->copy_requests.empty()); 618 DCHECK(original_pass_list[0]->copy_requests.empty());
618 DCHECK(original_pass_list[1]->copy_requests.empty()); 619 DCHECK(original_pass_list[1]->copy_requests.empty());
619 620
620 embedded_factory.EvictSurface(); 621 embedded_support.EvictFrame();
621 } 622 }
622 623
623 TEST_F(SurfaceAggregatorValidSurfaceTest, UnreferencedSurface) { 624 TEST_F(SurfaceAggregatorValidSurfaceTest, UnreferencedSurface) {
624 SurfaceFactory embedded_factory(kArbitraryChildFrameSinkId1, &manager_, 625 CompositorFrameSinkSupport embedded_support(
625 &empty_client_); 626 nullptr, &manager_, kArbitraryFrameSinkId1, is_root_child,
626 SurfaceFactory parent_factory(kArbitraryRootFrameSinkId, &manager_, 627 handles_frame_sink_id_invalidation, needs_sync_points);
627 &empty_client_); 628 CompositorFrameSinkSupport parent_support(
629 nullptr, &manager_, kArbitraryFrameSinkId2, is_root,
630 handles_frame_sink_id_invalidation, needs_sync_points);
628 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId(); 631 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId();
629 SurfaceId embedded_surface_id(embedded_factory.frame_sink_id(), 632 SurfaceId embedded_surface_id(embedded_support.frame_sink_id(),
630 embedded_local_surface_id); 633 embedded_local_surface_id);
631 SurfaceId nonexistent_surface_id(factory_.frame_sink_id(), 634 SurfaceId nonexistent_surface_id(support_.frame_sink_id(),
632 allocator_.GenerateId()); 635 allocator_.GenerateId());
633 636
634 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 637 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
635 test::Pass embedded_passes[] = { 638 test::Pass embedded_passes[] = {
636 test::Pass(embedded_quads, arraysize(embedded_quads))}; 639 test::Pass(embedded_quads, arraysize(embedded_quads))};
637 640
638 SubmitCompositorFrame(&embedded_factory, embedded_passes, 641 SubmitCompositorFrame(&embedded_support, embedded_passes,
639 arraysize(embedded_passes), embedded_local_surface_id); 642 arraysize(embedded_passes), embedded_local_surface_id);
640 std::unique_ptr<CopyOutputRequest> copy_request( 643 std::unique_ptr<CopyOutputRequest> copy_request(
641 CopyOutputRequest::CreateEmptyRequest()); 644 CopyOutputRequest::CreateEmptyRequest());
642 CopyOutputRequest* copy_request_ptr = copy_request.get(); 645 CopyOutputRequest* copy_request_ptr = copy_request.get();
643 embedded_factory.RequestCopyOfSurface(std::move(copy_request)); 646 embedded_support.RequestCopyOfSurface(std::move(copy_request));
644 647
645 LocalSurfaceId parent_local_surface_id = allocator_.GenerateId(); 648 LocalSurfaceId parent_local_surface_id = allocator_.GenerateId();
646 SurfaceId parent_surface_id(parent_factory.frame_sink_id(), 649 SurfaceId parent_surface_id(parent_support.frame_sink_id(),
647 parent_local_surface_id); 650 parent_local_surface_id);
648 651
649 test::Quad parent_quads[] = { 652 test::Quad parent_quads[] = {
650 test::Quad::SolidColorQuad(SK_ColorGRAY), 653 test::Quad::SolidColorQuad(SK_ColorGRAY),
651 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f), 654 test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f),
652 test::Quad::SolidColorQuad(SK_ColorLTGRAY)}; 655 test::Quad::SolidColorQuad(SK_ColorLTGRAY)};
653 test::Pass parent_passes[] = { 656 test::Pass parent_passes[] = {
654 test::Pass(parent_quads, arraysize(parent_quads))}; 657 test::Pass(parent_quads, arraysize(parent_quads))};
655 658
656 { 659 {
657 CompositorFrame frame; 660 CompositorFrame frame;
658 661
659 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), parent_passes, 662 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), parent_passes,
660 arraysize(parent_passes)); 663 arraysize(parent_passes));
661 664
662 frame.metadata.referenced_surfaces.push_back(embedded_surface_id); 665 frame.metadata.referenced_surfaces.push_back(embedded_surface_id);
663 666
664 parent_factory.SubmitCompositorFrame(parent_local_surface_id, 667 parent_support.SubmitCompositorFrame(parent_local_surface_id,
665 std::move(frame), 668 std::move(frame));
666 SurfaceFactory::DrawCallback());
667 } 669 }
668 670
669 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE), 671 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
670 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 672 test::Quad::SolidColorQuad(SK_ColorBLACK)};
671 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 673 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
672 674
673 { 675 {
674 CompositorFrame frame; 676 CompositorFrame frame;
675 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes, 677 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes,
676 arraysize(root_passes)); 678 arraysize(root_passes));
677 679
678 frame.metadata.referenced_surfaces.push_back(parent_surface_id); 680 frame.metadata.referenced_surfaces.push_back(parent_surface_id);
679 // Reference to Surface ID of a Surface that doesn't exist should be 681 // Reference to Surface ID of a Surface that doesn't exist should be
680 // included in previous_contained_surfaces, but otherwise ignored. 682 // included in previous_contained_surfaces, but otherwise ignored.
681 frame.metadata.referenced_surfaces.push_back(nonexistent_surface_id); 683 frame.metadata.referenced_surfaces.push_back(nonexistent_surface_id);
682 684
683 factory_.SubmitCompositorFrame(root_local_surface_id_, std::move(frame), 685 support_.SubmitCompositorFrame(root_local_surface_id_, std::move(frame));
684 SurfaceFactory::DrawCallback());
685 } 686 }
686 687
687 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 688 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
688 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 689 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
689 690
690 // First pass should come from surface that had a copy request but was not 691 // First pass should come from surface that had a copy request but was not
691 // referenced directly. The second pass comes from the root surface. 692 // referenced directly. The second pass comes from the root surface.
692 // parent_quad should be ignored because it is neither referenced through a 693 // parent_quad should be ignored because it is neither referenced through a
693 // SurfaceDrawQuad nor has a copy request on it. 694 // SurfaceDrawQuad nor has a copy request on it.
694 test::Pass expected_passes[] = { 695 test::Pass expected_passes[] = {
695 test::Pass(embedded_quads, arraysize(embedded_quads)), 696 test::Pass(embedded_quads, arraysize(embedded_quads)),
696 test::Pass(root_quads, arraysize(root_quads))}; 697 test::Pass(root_quads, arraysize(root_quads))};
697 TestPassesMatchExpectations(expected_passes, arraysize(expected_passes), 698 TestPassesMatchExpectations(expected_passes, arraysize(expected_passes),
698 &aggregated_frame.render_pass_list); 699 &aggregated_frame.render_pass_list);
699 ASSERT_EQ(2u, aggregated_frame.render_pass_list.size()); 700 ASSERT_EQ(2u, aggregated_frame.render_pass_list.size());
700 ASSERT_EQ(1u, aggregated_frame.render_pass_list[0]->copy_requests.size()); 701 ASSERT_EQ(1u, aggregated_frame.render_pass_list[0]->copy_requests.size());
701 DCHECK_EQ(copy_request_ptr, 702 DCHECK_EQ(copy_request_ptr,
702 aggregated_frame.render_pass_list[0]->copy_requests[0].get()); 703 aggregated_frame.render_pass_list[0]->copy_requests[0].get());
703 704
704 SurfaceId surface_ids[] = { 705 SurfaceId surface_ids[] = {
705 SurfaceId(factory_.frame_sink_id(), root_local_surface_id_), 706 SurfaceId(support_.frame_sink_id(), root_local_surface_id_),
706 parent_surface_id, embedded_surface_id, nonexistent_surface_id}; 707 parent_surface_id, embedded_surface_id, nonexistent_surface_id};
707 EXPECT_EQ(arraysize(surface_ids), 708 EXPECT_EQ(arraysize(surface_ids),
708 aggregator_.previous_contained_surfaces().size()); 709 aggregator_.previous_contained_surfaces().size());
709 for (size_t i = 0; i < arraysize(surface_ids); i++) { 710 for (size_t i = 0; i < arraysize(surface_ids); i++) {
710 EXPECT_TRUE( 711 EXPECT_TRUE(
711 aggregator_.previous_contained_surfaces().find(surface_ids[i]) != 712 aggregator_.previous_contained_surfaces().find(surface_ids[i]) !=
712 aggregator_.previous_contained_surfaces().end()); 713 aggregator_.previous_contained_surfaces().end());
713 } 714 }
714 715
715 embedded_factory.EvictSurface(); 716 embedded_support.EvictFrame();
716 parent_factory.EvictSurface(); 717 parent_support.EvictFrame();
717 } 718 }
718 719
719 // This tests referencing a surface that has multiple render passes. 720 // This tests referencing a surface that has multiple render passes.
720 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) { 721 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) {
721 LocalSurfaceId embedded_local_surface_id = child_allocator_.GenerateId(); 722 LocalSurfaceId embedded_local_surface_id = child_allocator_.GenerateId();
722 SurfaceId embedded_surface_id(child_factory_.frame_sink_id(), 723 SurfaceId embedded_surface_id(child_support_.frame_sink_id(),
723 embedded_local_surface_id); 724 embedded_local_surface_id);
724 725
725 int pass_ids[] = {1, 2, 3}; 726 int pass_ids[] = {1, 2, 3};
726 727
727 test::Quad embedded_quads[][2] = { 728 test::Quad embedded_quads[][2] = {
728 {test::Quad::SolidColorQuad(1), test::Quad::SolidColorQuad(2)}, 729 {test::Quad::SolidColorQuad(1), test::Quad::SolidColorQuad(2)},
729 {test::Quad::SolidColorQuad(3), test::Quad::RenderPassQuad(pass_ids[0])}, 730 {test::Quad::SolidColorQuad(3), test::Quad::RenderPassQuad(pass_ids[0])},
730 {test::Quad::SolidColorQuad(4), test::Quad::RenderPassQuad(pass_ids[1])}}; 731 {test::Quad::SolidColorQuad(4), test::Quad::RenderPassQuad(pass_ids[1])}};
731 test::Pass embedded_passes[] = { 732 test::Pass embedded_passes[] = {
732 test::Pass(embedded_quads[0], arraysize(embedded_quads[0]), pass_ids[0]), 733 test::Pass(embedded_quads[0], arraysize(embedded_quads[0]), pass_ids[0]),
733 test::Pass(embedded_quads[1], arraysize(embedded_quads[1]), pass_ids[1]), 734 test::Pass(embedded_quads[1], arraysize(embedded_quads[1]), pass_ids[1]),
734 test::Pass(embedded_quads[2], arraysize(embedded_quads[2]), pass_ids[2])}; 735 test::Pass(embedded_quads[2], arraysize(embedded_quads[2]), pass_ids[2])};
735 736
736 SubmitCompositorFrame(&child_factory_, embedded_passes, 737 SubmitCompositorFrame(&child_support_, embedded_passes,
737 arraysize(embedded_passes), embedded_local_surface_id); 738 arraysize(embedded_passes), embedded_local_surface_id);
738 739
739 test::Quad root_quads[][2] = { 740 test::Quad root_quads[][2] = {
740 {test::Quad::SolidColorQuad(5), test::Quad::SolidColorQuad(6)}, 741 {test::Quad::SolidColorQuad(5), test::Quad::SolidColorQuad(6)},
741 {test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f), 742 {test::Quad::SurfaceQuad(embedded_surface_id, InvalidSurfaceId(), 1.f),
742 test::Quad::RenderPassQuad(pass_ids[0])}, 743 test::Quad::RenderPassQuad(pass_ids[0])},
743 {test::Quad::SolidColorQuad(7), test::Quad::RenderPassQuad(pass_ids[1])}}; 744 {test::Quad::SolidColorQuad(7), test::Quad::RenderPassQuad(pass_ids[1])}};
744 test::Pass root_passes[] = { 745 test::Pass root_passes[] = {
745 test::Pass(root_quads[0], arraysize(root_quads[0]), pass_ids[0]), 746 test::Pass(root_quads[0], arraysize(root_quads[0]), pass_ids[0]),
746 test::Pass(root_quads[1], arraysize(root_quads[1]), pass_ids[1]), 747 test::Pass(root_quads[1], arraysize(root_quads[1]), pass_ids[1]),
747 test::Pass(root_quads[2], arraysize(root_quads[2]), pass_ids[2])}; 748 test::Pass(root_quads[2], arraysize(root_quads[2]), pass_ids[2])};
748 749
749 SubmitCompositorFrame(&factory_, root_passes, arraysize(root_passes), 750 SubmitCompositorFrame(&support_, root_passes, arraysize(root_passes),
750 root_local_surface_id_); 751 root_local_surface_id_);
751 752
752 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 753 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
753 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 754 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
754 755
755 const RenderPassList& aggregated_pass_list = 756 const RenderPassList& aggregated_pass_list =
756 aggregated_frame.render_pass_list; 757 aggregated_frame.render_pass_list;
757 758
758 ASSERT_EQ(5u, aggregated_pass_list.size()); 759 ASSERT_EQ(5u, aggregated_pass_list.size());
759 int actual_pass_ids[] = { 760 int actual_pass_ids[] = {
760 aggregated_pass_list[0]->id, aggregated_pass_list[1]->id, 761 aggregated_pass_list[0]->id, aggregated_pass_list[1]->id,
761 aggregated_pass_list[2]->id, aggregated_pass_list[3]->id, 762 aggregated_pass_list[2]->id, aggregated_pass_list[3]->id,
762 aggregated_pass_list[4]->id}; 763 aggregated_pass_list[4]->id};
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 855
855 // Tests an invalid surface reference in a frame. The surface quad should just 856 // Tests an invalid surface reference in a frame. The surface quad should just
856 // be dropped. 857 // be dropped.
857 TEST_F(SurfaceAggregatorValidSurfaceTest, InvalidSurfaceReference) { 858 TEST_F(SurfaceAggregatorValidSurfaceTest, InvalidSurfaceReference) {
858 test::Quad quads[] = { 859 test::Quad quads[] = {
859 test::Quad::SolidColorQuad(SK_ColorGREEN), 860 test::Quad::SolidColorQuad(SK_ColorGREEN),
860 test::Quad::SurfaceQuad(InvalidSurfaceId(), InvalidSurfaceId(), 1.f), 861 test::Quad::SurfaceQuad(InvalidSurfaceId(), InvalidSurfaceId(), 1.f),
861 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 862 test::Quad::SolidColorQuad(SK_ColorBLUE)};
862 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; 863 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
863 864
864 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 865 SubmitCompositorFrame(&support_, passes, arraysize(passes),
865 root_local_surface_id_); 866 root_local_surface_id_);
866 867
867 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN), 868 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
868 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 869 test::Quad::SolidColorQuad(SK_ColorBLUE)};
869 test::Pass expected_passes[] = { 870 test::Pass expected_passes[] = {
870 test::Pass(expected_quads, arraysize(expected_quads))}; 871 test::Pass(expected_quads, arraysize(expected_quads))};
871 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 872 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
872 SurfaceId ids[] = {root_surface_id, InvalidSurfaceId()}; 873 SurfaceId ids[] = {root_surface_id, InvalidSurfaceId()};
873 874
874 AggregateAndVerify( 875 AggregateAndVerify(
875 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 876 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
876 } 877 }
877 878
878 // Tests a reference to a valid surface with no submitted frame. This quad 879 // Tests a reference to a valid surface with no submitted frame. This quad
879 // should also just be dropped. 880 // should also just be dropped.
880 TEST_F(SurfaceAggregatorValidSurfaceTest, ValidSurfaceReferenceWithNoFrame) { 881 TEST_F(SurfaceAggregatorValidSurfaceTest, ValidSurfaceReferenceWithNoFrame) {
881 LocalSurfaceId empty_local_surface_id = allocator_.GenerateId(); 882 LocalSurfaceId empty_local_surface_id = allocator_.GenerateId();
882 SurfaceId surface_with_no_frame_id(factory_.frame_sink_id(), 883 SurfaceId surface_with_no_frame_id(support_.frame_sink_id(),
883 empty_local_surface_id); 884 empty_local_surface_id);
884 885
885 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN), 886 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
886 test::Quad::SurfaceQuad(surface_with_no_frame_id, 887 test::Quad::SurfaceQuad(surface_with_no_frame_id,
887 InvalidSurfaceId(), 1.f), 888 InvalidSurfaceId(), 1.f),
888 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 889 test::Quad::SolidColorQuad(SK_ColorBLUE)};
889 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; 890 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
890 891
891 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 892 SubmitCompositorFrame(&support_, passes, arraysize(passes),
892 root_local_surface_id_); 893 root_local_surface_id_);
893 894
894 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN), 895 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
895 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 896 test::Quad::SolidColorQuad(SK_ColorBLUE)};
896 test::Pass expected_passes[] = { 897 test::Pass expected_passes[] = {
897 test::Pass(expected_quads, arraysize(expected_quads))}; 898 test::Pass(expected_quads, arraysize(expected_quads))};
898 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 899 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
899 SurfaceId ids[] = {root_surface_id, surface_with_no_frame_id}; 900 SurfaceId ids[] = {root_surface_id, surface_with_no_frame_id};
900 AggregateAndVerify( 901 AggregateAndVerify(
901 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 902 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
902 } 903 }
903 904
904 // Tests a surface quad referencing itself, generating a trivial cycle. 905 // Tests a surface quad referencing itself, generating a trivial cycle.
905 // The quad creating the cycle should be dropped from the final frame. 906 // The quad creating the cycle should be dropped from the final frame.
906 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleCyclicalReference) { 907 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleCyclicalReference) {
907 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 908 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
908 test::Quad quads[] = { 909 test::Quad quads[] = {
909 test::Quad::SurfaceQuad(root_surface_id, InvalidSurfaceId(), 1.f), 910 test::Quad::SurfaceQuad(root_surface_id, InvalidSurfaceId(), 1.f),
910 test::Quad::SolidColorQuad(SK_ColorYELLOW)}; 911 test::Quad::SolidColorQuad(SK_ColorYELLOW)};
911 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; 912 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
912 913
913 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 914 SubmitCompositorFrame(&support_, passes, arraysize(passes),
914 root_local_surface_id_); 915 root_local_surface_id_);
915 916
916 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorYELLOW)}; 917 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorYELLOW)};
917 test::Pass expected_passes[] = { 918 test::Pass expected_passes[] = {
918 test::Pass(expected_quads, arraysize(expected_quads))}; 919 test::Pass(expected_quads, arraysize(expected_quads))};
919 SurfaceId ids[] = {root_surface_id}; 920 SurfaceId ids[] = {root_surface_id};
920 AggregateAndVerify( 921 AggregateAndVerify(
921 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 922 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
922 } 923 }
923 924
924 // Tests a more complex cycle with one intermediate surface. 925 // Tests a more complex cycle with one intermediate surface.
925 TEST_F(SurfaceAggregatorValidSurfaceTest, TwoSurfaceCyclicalReference) { 926 TEST_F(SurfaceAggregatorValidSurfaceTest, TwoSurfaceCyclicalReference) {
926 LocalSurfaceId child_local_surface_id = allocator_.GenerateId(); 927 LocalSurfaceId child_local_surface_id = allocator_.GenerateId();
927 SurfaceId child_surface_id(child_factory_.frame_sink_id(), 928 SurfaceId child_surface_id(child_support_.frame_sink_id(),
928 child_local_surface_id); 929 child_local_surface_id);
929 930
930 test::Quad parent_quads[] = { 931 test::Quad parent_quads[] = {
931 test::Quad::SolidColorQuad(SK_ColorBLUE), 932 test::Quad::SolidColorQuad(SK_ColorBLUE),
932 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f), 933 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f),
933 test::Quad::SolidColorQuad(SK_ColorCYAN)}; 934 test::Quad::SolidColorQuad(SK_ColorCYAN)};
934 test::Pass parent_passes[] = { 935 test::Pass parent_passes[] = {
935 test::Pass(parent_quads, arraysize(parent_quads))}; 936 test::Pass(parent_quads, arraysize(parent_quads))};
936 937
937 SubmitCompositorFrame(&factory_, parent_passes, arraysize(parent_passes), 938 SubmitCompositorFrame(&support_, parent_passes, arraysize(parent_passes),
938 root_local_surface_id_); 939 root_local_surface_id_);
939 940
940 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 941 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
941 test::Quad child_quads[] = { 942 test::Quad child_quads[] = {
942 test::Quad::SolidColorQuad(SK_ColorGREEN), 943 test::Quad::SolidColorQuad(SK_ColorGREEN),
943 test::Quad::SurfaceQuad(root_surface_id, InvalidSurfaceId(), 1.f), 944 test::Quad::SurfaceQuad(root_surface_id, InvalidSurfaceId(), 1.f),
944 test::Quad::SolidColorQuad(SK_ColorMAGENTA)}; 945 test::Quad::SolidColorQuad(SK_ColorMAGENTA)};
945 test::Pass child_passes[] = {test::Pass(child_quads, arraysize(child_quads))}; 946 test::Pass child_passes[] = {test::Pass(child_quads, arraysize(child_quads))};
946 947
947 SubmitCompositorFrame(&child_factory_, child_passes, arraysize(child_passes), 948 SubmitCompositorFrame(&child_support_, child_passes, arraysize(child_passes),
948 child_local_surface_id); 949 child_local_surface_id);
949 950
950 // The child surface's reference to the root_surface_ will be dropped, so 951 // The child surface's reference to the root_surface_ will be dropped, so
951 // we'll end up with: 952 // we'll end up with:
952 // SK_ColorBLUE from the parent 953 // SK_ColorBLUE from the parent
953 // SK_ColorGREEN from the child 954 // SK_ColorGREEN from the child
954 // SK_ColorMAGENTA from the child 955 // SK_ColorMAGENTA from the child
955 // SK_ColorCYAN from the parent 956 // SK_ColorCYAN from the parent
956 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorBLUE), 957 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorBLUE),
957 test::Quad::SolidColorQuad(SK_ColorGREEN), 958 test::Quad::SolidColorQuad(SK_ColorGREEN),
958 test::Quad::SolidColorQuad(SK_ColorMAGENTA), 959 test::Quad::SolidColorQuad(SK_ColorMAGENTA),
959 test::Quad::SolidColorQuad(SK_ColorCYAN)}; 960 test::Quad::SolidColorQuad(SK_ColorCYAN)};
960 test::Pass expected_passes[] = { 961 test::Pass expected_passes[] = {
961 test::Pass(expected_quads, arraysize(expected_quads))}; 962 test::Pass(expected_quads, arraysize(expected_quads))};
962 SurfaceId ids[] = {root_surface_id, child_surface_id}; 963 SurfaceId ids[] = {root_surface_id, child_surface_id};
963 AggregateAndVerify( 964 AggregateAndVerify(
964 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 965 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
965 } 966 }
966 967
967 // Tests that we map render pass IDs from different surfaces into a unified 968 // Tests that we map render pass IDs from different surfaces into a unified
968 // namespace and update RenderPassDrawQuad's id references to match. 969 // namespace and update RenderPassDrawQuad's id references to match.
969 TEST_F(SurfaceAggregatorValidSurfaceTest, RenderPassIdMapping) { 970 TEST_F(SurfaceAggregatorValidSurfaceTest, RenderPassIdMapping) {
970 LocalSurfaceId child_local_surface_id = allocator_.GenerateId(); 971 LocalSurfaceId child_local_surface_id = allocator_.GenerateId();
971 SurfaceId child_surface_id(child_factory_.frame_sink_id(), 972 SurfaceId child_surface_id(child_support_.frame_sink_id(),
972 child_local_surface_id); 973 child_local_surface_id);
973 974
974 int child_pass_id[] = {1, 2}; 975 int child_pass_id[] = {1, 2};
975 test::Quad child_quad[][1] = {{test::Quad::SolidColorQuad(SK_ColorGREEN)}, 976 test::Quad child_quad[][1] = {{test::Quad::SolidColorQuad(SK_ColorGREEN)},
976 {test::Quad::RenderPassQuad(child_pass_id[0])}}; 977 {test::Quad::RenderPassQuad(child_pass_id[0])}};
977 test::Pass surface_passes[] = { 978 test::Pass surface_passes[] = {
978 test::Pass(child_quad[0], arraysize(child_quad[0]), child_pass_id[0]), 979 test::Pass(child_quad[0], arraysize(child_quad[0]), child_pass_id[0]),
979 test::Pass(child_quad[1], arraysize(child_quad[1]), child_pass_id[1])}; 980 test::Pass(child_quad[1], arraysize(child_quad[1]), child_pass_id[1])};
980 981
981 SubmitCompositorFrame(&child_factory_, surface_passes, 982 SubmitCompositorFrame(&child_support_, surface_passes,
982 arraysize(surface_passes), child_local_surface_id); 983 arraysize(surface_passes), child_local_surface_id);
983 984
984 // Pass IDs from the parent surface may collide with ones from the child. 985 // Pass IDs from the parent surface may collide with ones from the child.
985 int parent_pass_id[] = {3, 2}; 986 int parent_pass_id[] = {3, 2};
986 test::Quad parent_quad[][1] = { 987 test::Quad parent_quad[][1] = {
987 {test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)}, 988 {test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)},
988 {test::Quad::RenderPassQuad(parent_pass_id[0])}}; 989 {test::Quad::RenderPassQuad(parent_pass_id[0])}};
989 test::Pass parent_passes[] = { 990 test::Pass parent_passes[] = {
990 test::Pass(parent_quad[0], arraysize(parent_quad[0]), parent_pass_id[0]), 991 test::Pass(parent_quad[0], arraysize(parent_quad[0]), parent_pass_id[0]),
991 test::Pass(parent_quad[1], arraysize(parent_quad[1]), parent_pass_id[1])}; 992 test::Pass(parent_quad[1], arraysize(parent_quad[1]), parent_pass_id[1])};
992 993
993 SubmitCompositorFrame(&factory_, parent_passes, arraysize(parent_passes), 994 SubmitCompositorFrame(&support_, parent_passes, arraysize(parent_passes),
994 root_local_surface_id_); 995 root_local_surface_id_);
995 996
996 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 997 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
997 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 998 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
998 999
999 const RenderPassList& aggregated_pass_list = 1000 const RenderPassList& aggregated_pass_list =
1000 aggregated_frame.render_pass_list; 1001 aggregated_frame.render_pass_list;
1001 1002
1002 ASSERT_EQ(3u, aggregated_pass_list.size()); 1003 ASSERT_EQ(3u, aggregated_pass_list.size());
1003 int actual_pass_ids[] = {aggregated_pass_list[0]->id, 1004 int actual_pass_ids[] = {aggregated_pass_list[0]->id,
1004 aggregated_pass_list[1]->id, 1005 aggregated_pass_list[1]->id,
1005 aggregated_pass_list[2]->id}; 1006 aggregated_pass_list[2]->id};
1006 // Make sure the aggregated frame's pass IDs are all unique. 1007 // Make sure the aggregated frame's pass IDs are all unique.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateSharedQuadStateProperties) { 1079 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateSharedQuadStateProperties) {
1079 const SkBlendMode blend_modes[] = { 1080 const SkBlendMode blend_modes[] = {
1080 SkBlendMode::kClear, // 0 1081 SkBlendMode::kClear, // 0
1081 SkBlendMode::kSrc, // 1 1082 SkBlendMode::kSrc, // 1
1082 SkBlendMode::kDst, // 2 1083 SkBlendMode::kDst, // 2
1083 SkBlendMode::kSrcOver, // 3 1084 SkBlendMode::kSrcOver, // 3
1084 SkBlendMode::kDstOver, // 4 1085 SkBlendMode::kDstOver, // 4
1085 SkBlendMode::kSrcIn, // 5 1086 SkBlendMode::kSrcIn, // 5
1086 SkBlendMode::kDstIn, // 6 1087 SkBlendMode::kDstIn, // 6
1087 }; 1088 };
1088 1089 CompositorFrameSinkSupport grandchild_support(
1089 SurfaceFactory grandchild_factory(FrameSinkId(2, 2), &manager_, 1090 nullptr, &manager_, kArbitraryFrameSinkId1, is_root_child,
1090 &empty_client_); 1091 handles_frame_sink_id_invalidation, needs_sync_points);
1091 SurfaceFactory child_one_factory(FrameSinkId(3, 3), &manager_, 1092 CompositorFrameSinkSupport child_one_support(
1092 &empty_client_); 1093 nullptr, &manager_, kArbitraryFrameSinkId2, is_root_child,
1093 SurfaceFactory child_two_factory(FrameSinkId(4, 4), &manager_, 1094 handles_frame_sink_id_invalidation, needs_sync_points);
1094 &empty_client_); 1095 CompositorFrameSinkSupport child_two_support(
1096 nullptr, &manager_, kArbitraryFrameSinkId3, is_root_child,
1097 handles_frame_sink_id_invalidation, needs_sync_points);
1095 int pass_id = 1; 1098 int pass_id = 1;
1096 LocalSurfaceId grandchild_local_surface_id = allocator_.GenerateId(); 1099 LocalSurfaceId grandchild_local_surface_id = allocator_.GenerateId();
1097 SurfaceId grandchild_surface_id(grandchild_factory.frame_sink_id(), 1100 SurfaceId grandchild_surface_id(grandchild_support.frame_sink_id(),
1098 grandchild_local_surface_id); 1101 grandchild_local_surface_id);
1099 grandchild_factory.SubmitCompositorFrame(grandchild_local_surface_id, 1102 grandchild_support.SubmitCompositorFrame(grandchild_local_surface_id,
1100 CompositorFrame(), 1103 CompositorFrame());
1101 SurfaceFactory::DrawCallback());
1102 std::unique_ptr<RenderPass> grandchild_pass = RenderPass::Create(); 1104 std::unique_ptr<RenderPass> grandchild_pass = RenderPass::Create();
1103 gfx::Rect output_rect(SurfaceSize()); 1105 gfx::Rect output_rect(SurfaceSize());
1104 gfx::Rect damage_rect(SurfaceSize()); 1106 gfx::Rect damage_rect(SurfaceSize());
1105 gfx::Transform transform_to_root_target; 1107 gfx::Transform transform_to_root_target;
1106 grandchild_pass->SetNew(pass_id, output_rect, damage_rect, 1108 grandchild_pass->SetNew(pass_id, output_rect, damage_rect,
1107 transform_to_root_target); 1109 transform_to_root_target);
1108 AddSolidColorQuadWithBlendMode( 1110 AddSolidColorQuadWithBlendMode(
1109 SurfaceSize(), grandchild_pass.get(), blend_modes[2]); 1111 SurfaceSize(), grandchild_pass.get(), blend_modes[2]);
1110 QueuePassAsFrame(std::move(grandchild_pass), grandchild_local_surface_id, 1112 QueuePassAsFrame(std::move(grandchild_pass), grandchild_local_surface_id,
1111 &grandchild_factory); 1113 &grandchild_support);
1112 1114
1113 LocalSurfaceId child_one_local_surface_id = allocator_.GenerateId(); 1115 LocalSurfaceId child_one_local_surface_id = allocator_.GenerateId();
1114 SurfaceId child_one_surface_id(child_one_factory.frame_sink_id(), 1116 SurfaceId child_one_surface_id(child_one_support.frame_sink_id(),
1115 child_one_local_surface_id); 1117 child_one_local_surface_id);
1116 child_one_factory.SubmitCompositorFrame(child_one_local_surface_id, 1118 child_one_support.SubmitCompositorFrame(child_one_local_surface_id,
1117 CompositorFrame(), 1119 CompositorFrame());
1118 SurfaceFactory::DrawCallback());
1119 1120
1120 std::unique_ptr<RenderPass> child_one_pass = RenderPass::Create(); 1121 std::unique_ptr<RenderPass> child_one_pass = RenderPass::Create();
1121 child_one_pass->SetNew(pass_id, output_rect, damage_rect, 1122 child_one_pass->SetNew(pass_id, output_rect, damage_rect,
1122 transform_to_root_target); 1123 transform_to_root_target);
1123 AddSolidColorQuadWithBlendMode( 1124 AddSolidColorQuadWithBlendMode(
1124 SurfaceSize(), child_one_pass.get(), blend_modes[1]); 1125 SurfaceSize(), child_one_pass.get(), blend_modes[1]);
1125 SurfaceDrawQuad* grandchild_surface_quad = 1126 SurfaceDrawQuad* grandchild_surface_quad =
1126 child_one_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 1127 child_one_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
1127 grandchild_surface_quad->SetNew( 1128 grandchild_surface_quad->SetNew(
1128 child_one_pass->shared_quad_state_list.back(), gfx::Rect(SurfaceSize()), 1129 child_one_pass->shared_quad_state_list.back(), gfx::Rect(SurfaceSize()),
1129 gfx::Rect(SurfaceSize()), grandchild_surface_id, 1130 gfx::Rect(SurfaceSize()), grandchild_surface_id,
1130 SurfaceDrawQuadType::PRIMARY, nullptr); 1131 SurfaceDrawQuadType::PRIMARY, nullptr);
1131 AddSolidColorQuadWithBlendMode( 1132 AddSolidColorQuadWithBlendMode(
1132 SurfaceSize(), child_one_pass.get(), blend_modes[3]); 1133 SurfaceSize(), child_one_pass.get(), blend_modes[3]);
1133 QueuePassAsFrame(std::move(child_one_pass), child_one_local_surface_id, 1134 QueuePassAsFrame(std::move(child_one_pass), child_one_local_surface_id,
1134 &child_one_factory); 1135 &child_one_support);
1135 1136
1136 LocalSurfaceId child_two_local_surface_id = allocator_.GenerateId(); 1137 LocalSurfaceId child_two_local_surface_id = allocator_.GenerateId();
1137 SurfaceId child_two_surface_id(child_two_factory.frame_sink_id(), 1138 SurfaceId child_two_surface_id(child_two_support.frame_sink_id(),
1138 child_two_local_surface_id); 1139 child_two_local_surface_id);
1139 child_two_factory.SubmitCompositorFrame(child_two_local_surface_id, 1140 child_two_support.SubmitCompositorFrame(child_two_local_surface_id,
1140 CompositorFrame(), 1141 CompositorFrame());
1141 SurfaceFactory::DrawCallback());
1142 1142
1143 std::unique_ptr<RenderPass> child_two_pass = RenderPass::Create(); 1143 std::unique_ptr<RenderPass> child_two_pass = RenderPass::Create();
1144 child_two_pass->SetNew(pass_id, output_rect, damage_rect, 1144 child_two_pass->SetNew(pass_id, output_rect, damage_rect,
1145 transform_to_root_target); 1145 transform_to_root_target);
1146 AddSolidColorQuadWithBlendMode( 1146 AddSolidColorQuadWithBlendMode(
1147 SurfaceSize(), child_two_pass.get(), blend_modes[5]); 1147 SurfaceSize(), child_two_pass.get(), blend_modes[5]);
1148 QueuePassAsFrame(std::move(child_two_pass), child_two_local_surface_id, 1148 QueuePassAsFrame(std::move(child_two_pass), child_two_local_surface_id,
1149 &child_two_factory); 1149 &child_two_support);
1150 1150
1151 std::unique_ptr<RenderPass> root_pass = RenderPass::Create(); 1151 std::unique_ptr<RenderPass> root_pass = RenderPass::Create();
1152 root_pass->SetNew(pass_id, output_rect, damage_rect, 1152 root_pass->SetNew(pass_id, output_rect, damage_rect,
1153 transform_to_root_target); 1153 transform_to_root_target);
1154 1154
1155 AddSolidColorQuadWithBlendMode( 1155 AddSolidColorQuadWithBlendMode(
1156 SurfaceSize(), root_pass.get(), blend_modes[0]); 1156 SurfaceSize(), root_pass.get(), blend_modes[0]);
1157 SurfaceDrawQuad* child_one_surface_quad = 1157 SurfaceDrawQuad* child_one_surface_quad =
1158 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 1158 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
1159 child_one_surface_quad->SetNew(root_pass->shared_quad_state_list.back(), 1159 child_one_surface_quad->SetNew(root_pass->shared_quad_state_list.back(),
1160 gfx::Rect(SurfaceSize()), 1160 gfx::Rect(SurfaceSize()),
1161 gfx::Rect(SurfaceSize()), child_one_surface_id, 1161 gfx::Rect(SurfaceSize()), child_one_surface_id,
1162 SurfaceDrawQuadType::PRIMARY, nullptr); 1162 SurfaceDrawQuadType::PRIMARY, nullptr);
1163 AddSolidColorQuadWithBlendMode( 1163 AddSolidColorQuadWithBlendMode(
1164 SurfaceSize(), root_pass.get(), blend_modes[4]); 1164 SurfaceSize(), root_pass.get(), blend_modes[4]);
1165 SurfaceDrawQuad* child_two_surface_quad = 1165 SurfaceDrawQuad* child_two_surface_quad =
1166 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 1166 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
1167 child_two_surface_quad->SetNew(root_pass->shared_quad_state_list.back(), 1167 child_two_surface_quad->SetNew(root_pass->shared_quad_state_list.back(),
1168 gfx::Rect(SurfaceSize()), 1168 gfx::Rect(SurfaceSize()),
1169 gfx::Rect(SurfaceSize()), child_two_surface_id, 1169 gfx::Rect(SurfaceSize()), child_two_surface_id,
1170 SurfaceDrawQuadType::PRIMARY, nullptr); 1170 SurfaceDrawQuadType::PRIMARY, nullptr);
1171 AddSolidColorQuadWithBlendMode( 1171 AddSolidColorQuadWithBlendMode(
1172 SurfaceSize(), root_pass.get(), blend_modes[6]); 1172 SurfaceSize(), root_pass.get(), blend_modes[6]);
1173 1173
1174 QueuePassAsFrame(std::move(root_pass), root_local_surface_id_, &factory_); 1174 QueuePassAsFrame(std::move(root_pass), root_local_surface_id_, &support_);
1175 1175
1176 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 1176 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
1177 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1177 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1178 1178
1179 const RenderPassList& aggregated_pass_list = 1179 const RenderPassList& aggregated_pass_list =
1180 aggregated_frame.render_pass_list; 1180 aggregated_frame.render_pass_list;
1181 1181
1182 ASSERT_EQ(1u, aggregated_pass_list.size()); 1182 ASSERT_EQ(1u, aggregated_pass_list.size());
1183 1183
1184 const QuadList& aggregated_quad_list = aggregated_pass_list[0]->quad_list; 1184 const QuadList& aggregated_quad_list = aggregated_pass_list[0]->quad_list;
1185 1185
1186 ASSERT_EQ(7u, aggregated_quad_list.size()); 1186 ASSERT_EQ(7u, aggregated_quad_list.size());
1187 1187
1188 for (auto iter = aggregated_quad_list.cbegin(); 1188 for (auto iter = aggregated_quad_list.cbegin();
1189 iter != aggregated_quad_list.cend(); 1189 iter != aggregated_quad_list.cend();
1190 ++iter) { 1190 ++iter) {
1191 EXPECT_EQ(blend_modes[iter.index()], iter->shared_quad_state->blend_mode) 1191 EXPECT_EQ(blend_modes[iter.index()], iter->shared_quad_state->blend_mode)
1192 << iter.index(); 1192 << iter.index();
1193 } 1193 }
1194 1194
1195 grandchild_factory.EvictSurface(); 1195 grandchild_support.EvictFrame();
1196 child_one_factory.EvictSurface(); 1196 child_one_support.EvictFrame();
1197 child_two_factory.EvictSurface(); 1197 child_two_support.EvictFrame();
1198 } 1198 }
1199 1199
1200 // This tests that when aggregating a frame with multiple render passes that we 1200 // This tests that when aggregating a frame with multiple render passes that we
1201 // map the transforms for the root pass but do not modify the transform on child 1201 // map the transforms for the root pass but do not modify the transform on child
1202 // passes. 1202 // passes.
1203 // 1203 //
1204 // The root surface has one pass with a surface quad transformed by +10 in the y 1204 // The root surface has one pass with a surface quad transformed by +10 in the y
1205 // direction. 1205 // direction.
1206 // 1206 //
1207 // The middle surface has one pass with a surface quad scaled by 2 in the x 1207 // The middle surface has one pass with a surface quad scaled by 2 in the x
1208 // and 3 in the y directions. 1208 // and 3 in the y directions.
1209 // 1209 //
1210 // The child surface has two passes. The first pass has a quad with a transform 1210 // The child surface has two passes. The first pass has a quad with a transform
1211 // of +5 in the x direction. The second pass has a reference to the first pass' 1211 // of +5 in the x direction. The second pass has a reference to the first pass'
1212 // pass id and a transform of +8 in the x direction. 1212 // pass id and a transform of +8 in the x direction.
1213 // 1213 //
1214 // After aggregation, the child surface's root pass quad should have all 1214 // After aggregation, the child surface's root pass quad should have all
1215 // transforms concatenated for a total transform of +23 x, +10 y. The 1215 // transforms concatenated for a total transform of +23 x, +10 y. The
1216 // contributing render pass' transform in the aggregate frame should not be 1216 // contributing render pass' transform in the aggregate frame should not be
1217 // affected. 1217 // affected.
1218 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateMultiplePassWithTransform) { 1218 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateMultiplePassWithTransform) {
1219 SurfaceFactory middle_factory(kArbitraryMiddleFrameSinkId, &manager_, 1219 CompositorFrameSinkSupport middle_support(
1220 &empty_client_); 1220 nullptr, &manager_, kArbitraryMiddleFrameSinkId, is_root_child,
1221 handles_frame_sink_id_invalidation, needs_sync_points);
1221 // Innermost child surface. 1222 // Innermost child surface.
1222 LocalSurfaceId child_local_surface_id = allocator_.GenerateId(); 1223 LocalSurfaceId child_local_surface_id = allocator_.GenerateId();
1223 SurfaceId child_surface_id(child_factory_.frame_sink_id(), 1224 SurfaceId child_surface_id(child_support_.frame_sink_id(),
1224 child_local_surface_id); 1225 child_local_surface_id);
1225 { 1226 {
1226 int child_pass_id[] = {1, 2}; 1227 int child_pass_id[] = {1, 2};
1227 test::Quad child_quads[][1] = { 1228 test::Quad child_quads[][1] = {
1228 {test::Quad::SolidColorQuad(SK_ColorGREEN)}, 1229 {test::Quad::SolidColorQuad(SK_ColorGREEN)},
1229 {test::Quad::RenderPassQuad(child_pass_id[0])}, 1230 {test::Quad::RenderPassQuad(child_pass_id[0])},
1230 }; 1231 };
1231 test::Pass child_passes[] = { 1232 test::Pass child_passes[] = {
1232 test::Pass(child_quads[0], arraysize(child_quads[0]), child_pass_id[0]), 1233 test::Pass(child_quads[0], arraysize(child_quads[0]), child_pass_id[0]),
1233 test::Pass(child_quads[1], arraysize(child_quads[1]), 1234 test::Pass(child_quads[1], arraysize(child_quads[1]),
1234 child_pass_id[1])}; 1235 child_pass_id[1])};
1235 1236
1236 CompositorFrame child_frame; 1237 CompositorFrame child_frame;
1237 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1238 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1238 child_passes, arraysize(child_passes)); 1239 child_passes, arraysize(child_passes));
1239 1240
1240 RenderPass* child_nonroot_pass = child_frame.render_pass_list[0].get(); 1241 RenderPass* child_nonroot_pass = child_frame.render_pass_list[0].get();
1241 child_nonroot_pass->transform_to_root_target.Translate(8, 0); 1242 child_nonroot_pass->transform_to_root_target.Translate(8, 0);
1242 SharedQuadState* child_nonroot_pass_sqs = 1243 SharedQuadState* child_nonroot_pass_sqs =
1243 child_nonroot_pass->shared_quad_state_list.front(); 1244 child_nonroot_pass->shared_quad_state_list.front();
1244 child_nonroot_pass_sqs->quad_to_target_transform.Translate(5, 0); 1245 child_nonroot_pass_sqs->quad_to_target_transform.Translate(5, 0);
1245 1246
1246 RenderPass* child_root_pass = child_frame.render_pass_list[1].get(); 1247 RenderPass* child_root_pass = child_frame.render_pass_list[1].get();
1247 SharedQuadState* child_root_pass_sqs = 1248 SharedQuadState* child_root_pass_sqs =
1248 child_root_pass->shared_quad_state_list.front(); 1249 child_root_pass->shared_quad_state_list.front();
1249 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0); 1250 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0);
1250 child_root_pass_sqs->is_clipped = true; 1251 child_root_pass_sqs->is_clipped = true;
1251 child_root_pass_sqs->clip_rect = gfx::Rect(0, 0, 5, 5); 1252 child_root_pass_sqs->clip_rect = gfx::Rect(0, 0, 5, 5);
1252 1253
1253 child_factory_.SubmitCompositorFrame(child_local_surface_id, 1254 child_support_.SubmitCompositorFrame(child_local_surface_id,
1254 std::move(child_frame), 1255 std::move(child_frame));
1255 SurfaceFactory::DrawCallback());
1256 } 1256 }
1257 1257
1258 // Middle child surface. 1258 // Middle child surface.
1259 LocalSurfaceId middle_local_surface_id = allocator_.GenerateId(); 1259 LocalSurfaceId middle_local_surface_id = allocator_.GenerateId();
1260 SurfaceId middle_surface_id(middle_factory.frame_sink_id(), 1260 SurfaceId middle_surface_id(middle_support.frame_sink_id(),
1261 middle_local_surface_id); 1261 middle_local_surface_id);
1262 { 1262 {
1263 test::Quad middle_quads[] = { 1263 test::Quad middle_quads[] = {
1264 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)}; 1264 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)};
1265 test::Pass middle_passes[] = { 1265 test::Pass middle_passes[] = {
1266 test::Pass(middle_quads, arraysize(middle_quads)), 1266 test::Pass(middle_quads, arraysize(middle_quads)),
1267 }; 1267 };
1268 1268
1269 CompositorFrame middle_frame; 1269 CompositorFrame middle_frame;
1270 AddPasses(&middle_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1270 AddPasses(&middle_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1271 middle_passes, arraysize(middle_passes)); 1271 middle_passes, arraysize(middle_passes));
1272 1272
1273 RenderPass* middle_root_pass = middle_frame.render_pass_list[0].get(); 1273 RenderPass* middle_root_pass = middle_frame.render_pass_list[0].get();
1274 middle_root_pass->quad_list.ElementAt(0)->visible_rect = 1274 middle_root_pass->quad_list.ElementAt(0)->visible_rect =
1275 gfx::Rect(0, 1, 100, 7); 1275 gfx::Rect(0, 1, 100, 7);
1276 SharedQuadState* middle_root_pass_sqs = 1276 SharedQuadState* middle_root_pass_sqs =
1277 middle_root_pass->shared_quad_state_list.front(); 1277 middle_root_pass->shared_quad_state_list.front();
1278 middle_root_pass_sqs->quad_to_target_transform.Scale(2, 3); 1278 middle_root_pass_sqs->quad_to_target_transform.Scale(2, 3);
1279 1279
1280 middle_factory.SubmitCompositorFrame(middle_local_surface_id, 1280 middle_support.SubmitCompositorFrame(middle_local_surface_id,
1281 std::move(middle_frame), 1281 std::move(middle_frame));
1282 SurfaceFactory::DrawCallback());
1283 } 1282 }
1284 1283
1285 // Root surface. 1284 // Root surface.
1286 test::Quad secondary_quads[] = { 1285 test::Quad secondary_quads[] = {
1287 test::Quad::SolidColorQuad(1), 1286 test::Quad::SolidColorQuad(1),
1288 test::Quad::SurfaceQuad(middle_surface_id, InvalidSurfaceId(), 1.f)}; 1287 test::Quad::SurfaceQuad(middle_surface_id, InvalidSurfaceId(), 1.f)};
1289 test::Quad root_quads[] = {test::Quad::SolidColorQuad(1)}; 1288 test::Quad root_quads[] = {test::Quad::SolidColorQuad(1)};
1290 test::Pass root_passes[] = { 1289 test::Pass root_passes[] = {
1291 test::Pass(secondary_quads, arraysize(secondary_quads)), 1290 test::Pass(secondary_quads, arraysize(secondary_quads)),
1292 test::Pass(root_quads, arraysize(root_quads))}; 1291 test::Pass(root_quads, arraysize(root_quads))};
1293 1292
1294 CompositorFrame root_frame; 1293 CompositorFrame root_frame;
1295 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes, 1294 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes,
1296 arraysize(root_passes)); 1295 arraysize(root_passes));
1297 1296
1298 root_frame.render_pass_list[0] 1297 root_frame.render_pass_list[0]
1299 ->shared_quad_state_list.front() 1298 ->shared_quad_state_list.front()
1300 ->quad_to_target_transform.Translate(0, 7); 1299 ->quad_to_target_transform.Translate(0, 7);
1301 root_frame.render_pass_list[0] 1300 root_frame.render_pass_list[0]
1302 ->shared_quad_state_list.ElementAt(1) 1301 ->shared_quad_state_list.ElementAt(1)
1303 ->quad_to_target_transform.Translate(0, 10); 1302 ->quad_to_target_transform.Translate(0, 10);
1304 root_frame.render_pass_list[0]->quad_list.ElementAt(1)->visible_rect = 1303 root_frame.render_pass_list[0]->quad_list.ElementAt(1)->visible_rect =
1305 gfx::Rect(0, 0, 8, 100); 1304 gfx::Rect(0, 0, 8, 100);
1306 1305
1307 root_frame.render_pass_list[0]->transform_to_root_target.Translate(10, 5); 1306 root_frame.render_pass_list[0]->transform_to_root_target.Translate(10, 5);
1308 1307
1309 factory_.SubmitCompositorFrame(root_local_surface_id_, std::move(root_frame), 1308 support_.SubmitCompositorFrame(root_local_surface_id_, std::move(root_frame));
1310 SurfaceFactory::DrawCallback());
1311 1309
1312 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 1310 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
1313 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1311 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1314 1312
1315 const RenderPassList& aggregated_pass_list = 1313 const RenderPassList& aggregated_pass_list =
1316 aggregated_frame.render_pass_list; 1314 aggregated_frame.render_pass_list;
1317 1315
1318 ASSERT_EQ(3u, aggregated_pass_list.size()); 1316 ASSERT_EQ(3u, aggregated_pass_list.size());
1319 1317
1320 ASSERT_EQ(1u, aggregated_pass_list[0]->shared_quad_state_list.size()); 1318 ASSERT_EQ(1u, aggregated_pass_list[0]->shared_quad_state_list.size());
1321 1319
1322 // The first pass should have one shared quad state for the one solid color 1320 // The first pass should have one shared quad state for the one solid color
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 aggregated_pass_list[1]->shared_quad_state_list.ElementAt(1)->is_clipped); 1373 aggregated_pass_list[1]->shared_quad_state_list.ElementAt(1)->is_clipped);
1376 1374
1377 // The second quad in the root pass is aggregated from the child, so its 1375 // The second quad in the root pass is aggregated from the child, so its
1378 // clip rect must be transformed by the child's translation/scale and 1376 // clip rect must be transformed by the child's translation/scale and
1379 // clipped be the visible_rects for both children. 1377 // clipped be the visible_rects for both children.
1380 EXPECT_EQ(gfx::Rect(0, 13, 8, 12).ToString(), 1378 EXPECT_EQ(gfx::Rect(0, 13, 8, 12).ToString(),
1381 aggregated_pass_list[1] 1379 aggregated_pass_list[1]
1382 ->shared_quad_state_list.ElementAt(1) 1380 ->shared_quad_state_list.ElementAt(1)
1383 ->clip_rect.ToString()); 1381 ->clip_rect.ToString());
1384 1382
1385 middle_factory.EvictSurface(); 1383 middle_support.EvictFrame();
1386 } 1384 }
1387 1385
1388 // Tests that damage rects are aggregated correctly when surfaces change. 1386 // Tests that damage rects are aggregated correctly when surfaces change.
1389 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) { 1387 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) {
1390 SurfaceFactory parent_factory(kArbitraryMiddleFrameSinkId, &manager_, 1388 CompositorFrameSinkSupport parent_support(
1391 &empty_client_); 1389 nullptr, &manager_, kArbitraryMiddleFrameSinkId, is_root_child,
1390 handles_frame_sink_id_invalidation, needs_sync_points);
1392 test::Quad child_quads[] = {test::Quad::RenderPassQuad(1)}; 1391 test::Quad child_quads[] = {test::Quad::RenderPassQuad(1)};
1393 test::Pass child_passes[] = { 1392 test::Pass child_passes[] = {
1394 test::Pass(child_quads, arraysize(child_quads), 1)}; 1393 test::Pass(child_quads, arraysize(child_quads), 1)};
1395 1394
1396 CompositorFrame child_frame; 1395 CompositorFrame child_frame;
1397 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1396 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1398 child_passes, arraysize(child_passes)); 1397 child_passes, arraysize(child_passes));
1399 1398
1400 RenderPass* child_root_pass = child_frame.render_pass_list[0].get(); 1399 RenderPass* child_root_pass = child_frame.render_pass_list[0].get();
1401 SharedQuadState* child_root_pass_sqs = 1400 SharedQuadState* child_root_pass_sqs =
1402 child_root_pass->shared_quad_state_list.front(); 1401 child_root_pass->shared_quad_state_list.front();
1403 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0); 1402 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0);
1404 1403
1405 LocalSurfaceId child_local_surface_id = allocator_.GenerateId(); 1404 LocalSurfaceId child_local_surface_id = allocator_.GenerateId();
1406 SurfaceId child_surface_id(child_factory_.frame_sink_id(), 1405 SurfaceId child_surface_id(child_support_.frame_sink_id(),
1407 child_local_surface_id); 1406 child_local_surface_id);
1408 child_factory_.SubmitCompositorFrame(child_local_surface_id, 1407 child_support_.SubmitCompositorFrame(child_local_surface_id,
1409 std::move(child_frame), 1408 std::move(child_frame));
1410 SurfaceFactory::DrawCallback());
1411 1409
1412 test::Quad parent_surface_quads[] = { 1410 test::Quad parent_surface_quads[] = {
1413 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)}; 1411 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)};
1414 test::Pass parent_surface_passes[] = { 1412 test::Pass parent_surface_passes[] = {
1415 test::Pass(parent_surface_quads, arraysize(parent_surface_quads), 1)}; 1413 test::Pass(parent_surface_quads, arraysize(parent_surface_quads), 1)};
1416 1414
1417 // Parent surface is only used to test if the transform is applied correctly 1415 // Parent surface is only used to test if the transform is applied correctly
1418 // to the child surface's damage. 1416 // to the child surface's damage.
1419 CompositorFrame parent_surface_frame; 1417 CompositorFrame parent_surface_frame;
1420 AddPasses(&parent_surface_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1418 AddPasses(&parent_surface_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1421 parent_surface_passes, arraysize(parent_surface_passes)); 1419 parent_surface_passes, arraysize(parent_surface_passes));
1422 1420
1423 LocalSurfaceId parent_local_surface_id = allocator_.GenerateId(); 1421 LocalSurfaceId parent_local_surface_id = allocator_.GenerateId();
1424 SurfaceId parent_surface_id(parent_factory.frame_sink_id(), 1422 SurfaceId parent_surface_id(parent_support.frame_sink_id(),
1425 parent_local_surface_id); 1423 parent_local_surface_id);
1426 parent_factory.SubmitCompositorFrame(parent_local_surface_id, 1424 parent_support.SubmitCompositorFrame(parent_local_surface_id,
1427 std::move(parent_surface_frame), 1425 std::move(parent_surface_frame));
1428 SurfaceFactory::DrawCallback());
1429 1426
1430 test::Quad root_surface_quads[] = { 1427 test::Quad root_surface_quads[] = {
1431 test::Quad::SurfaceQuad(parent_surface_id, InvalidSurfaceId(), 1.f)}; 1428 test::Quad::SurfaceQuad(parent_surface_id, InvalidSurfaceId(), 1.f)};
1432 test::Quad root_render_pass_quads[] = {test::Quad::RenderPassQuad(1)}; 1429 test::Quad root_render_pass_quads[] = {test::Quad::RenderPassQuad(1)};
1433 1430
1434 test::Pass root_passes[] = { 1431 test::Pass root_passes[] = {
1435 test::Pass(root_surface_quads, arraysize(root_surface_quads), 1), 1432 test::Pass(root_surface_quads, arraysize(root_surface_quads), 1),
1436 test::Pass(root_render_pass_quads, arraysize(root_render_pass_quads), 2)}; 1433 test::Pass(root_render_pass_quads, arraysize(root_render_pass_quads), 2)};
1437 1434
1438 CompositorFrame root_frame; 1435 CompositorFrame root_frame;
1439 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes, 1436 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes,
1440 arraysize(root_passes)); 1437 arraysize(root_passes));
1441 1438
1442 root_frame.render_pass_list[0] 1439 root_frame.render_pass_list[0]
1443 ->shared_quad_state_list.front() 1440 ->shared_quad_state_list.front()
1444 ->quad_to_target_transform.Translate(0, 10); 1441 ->quad_to_target_transform.Translate(0, 10);
1445 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(5, 5, 10, 10); 1442 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(5, 5, 10, 10);
1446 root_frame.render_pass_list[1]->damage_rect = gfx::Rect(5, 5, 100, 100); 1443 root_frame.render_pass_list[1]->damage_rect = gfx::Rect(5, 5, 100, 100);
1447 1444
1448 factory_.SubmitCompositorFrame(root_local_surface_id_, std::move(root_frame), 1445 support_.SubmitCompositorFrame(root_local_surface_id_, std::move(root_frame));
1449 SurfaceFactory::DrawCallback());
1450 1446
1451 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 1447 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
1452 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1448 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1453 1449
1454 const RenderPassList& aggregated_pass_list = 1450 const RenderPassList& aggregated_pass_list =
1455 aggregated_frame.render_pass_list; 1451 aggregated_frame.render_pass_list;
1456 1452
1457 ASSERT_EQ(2u, aggregated_pass_list.size()); 1453 ASSERT_EQ(2u, aggregated_pass_list.size());
1458 1454
1459 // Damage rect for first aggregation should contain entire root surface. 1455 // Damage rect for first aggregation should contain entire root surface.
1460 EXPECT_TRUE( 1456 EXPECT_TRUE(
1461 aggregated_pass_list[1]->damage_rect.Contains(gfx::Rect(SurfaceSize()))); 1457 aggregated_pass_list[1]->damage_rect.Contains(gfx::Rect(SurfaceSize())));
1462 1458
1463 { 1459 {
1464 CompositorFrame child_frame; 1460 CompositorFrame child_frame;
1465 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1461 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1466 child_passes, arraysize(child_passes)); 1462 child_passes, arraysize(child_passes));
1467 1463
1468 RenderPass* child_root_pass = child_frame.render_pass_list[0].get(); 1464 RenderPass* child_root_pass = child_frame.render_pass_list[0].get();
1469 SharedQuadState* child_root_pass_sqs = 1465 SharedQuadState* child_root_pass_sqs =
1470 child_root_pass->shared_quad_state_list.front(); 1466 child_root_pass->shared_quad_state_list.front();
1471 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0); 1467 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0);
1472 child_root_pass->damage_rect = gfx::Rect(10, 10, 10, 10); 1468 child_root_pass->damage_rect = gfx::Rect(10, 10, 10, 10);
1473 1469
1474 child_factory_.SubmitCompositorFrame(child_local_surface_id, 1470 child_support_.SubmitCompositorFrame(child_local_surface_id,
1475 std::move(child_frame), 1471 std::move(child_frame));
1476 SurfaceFactory::DrawCallback());
1477 1472
1478 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 1473 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
1479 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1474 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1480 1475
1481 const RenderPassList& aggregated_pass_list = 1476 const RenderPassList& aggregated_pass_list =
1482 aggregated_frame.render_pass_list; 1477 aggregated_frame.render_pass_list;
1483 1478
1484 ASSERT_EQ(2u, aggregated_pass_list.size()); 1479 ASSERT_EQ(2u, aggregated_pass_list.size());
1485 1480
1486 // Outer surface didn't change, so transformed inner damage rect should be 1481 // Outer surface didn't change, so transformed inner damage rect should be
1487 // used. 1482 // used.
1488 EXPECT_EQ(gfx::Rect(10, 20, 10, 10).ToString(), 1483 EXPECT_EQ(gfx::Rect(10, 20, 10, 10).ToString(),
1489 aggregated_pass_list[1]->damage_rect.ToString()); 1484 aggregated_pass_list[1]->damage_rect.ToString());
1490 } 1485 }
1491 1486
1492 { 1487 {
1493 CompositorFrame root_frame; 1488 CompositorFrame root_frame;
1494 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1489 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1495 root_passes, arraysize(root_passes)); 1490 root_passes, arraysize(root_passes));
1496 1491
1497 root_frame.render_pass_list[0] 1492 root_frame.render_pass_list[0]
1498 ->shared_quad_state_list.front() 1493 ->shared_quad_state_list.front()
1499 ->quad_to_target_transform.Translate(0, 10); 1494 ->quad_to_target_transform.Translate(0, 10);
1500 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(0, 0, 1, 1); 1495 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(0, 0, 1, 1);
1501 1496
1502 factory_.SubmitCompositorFrame(root_local_surface_id_, 1497 support_.SubmitCompositorFrame(root_local_surface_id_,
1503 std::move(root_frame), 1498 std::move(root_frame));
1504 SurfaceFactory::DrawCallback());
1505 } 1499 }
1506 1500
1507 { 1501 {
1508 CompositorFrame root_frame; 1502 CompositorFrame root_frame;
1509 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1503 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1510 root_passes, arraysize(root_passes)); 1504 root_passes, arraysize(root_passes));
1511 1505
1512 root_frame.render_pass_list[0] 1506 root_frame.render_pass_list[0]
1513 ->shared_quad_state_list.front() 1507 ->shared_quad_state_list.front()
1514 ->quad_to_target_transform.Translate(0, 10); 1508 ->quad_to_target_transform.Translate(0, 10);
1515 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(1, 1, 1, 1); 1509 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(1, 1, 1, 1);
1516 1510
1517 factory_.SubmitCompositorFrame(root_local_surface_id_, 1511 support_.SubmitCompositorFrame(root_local_surface_id_,
1518 std::move(root_frame), 1512 std::move(root_frame));
1519 SurfaceFactory::DrawCallback());
1520 1513
1521 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 1514 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
1522 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1515 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1523 1516
1524 const RenderPassList& aggregated_pass_list = 1517 const RenderPassList& aggregated_pass_list =
1525 aggregated_frame.render_pass_list; 1518 aggregated_frame.render_pass_list;
1526 1519
1527 ASSERT_EQ(2u, aggregated_pass_list.size()); 1520 ASSERT_EQ(2u, aggregated_pass_list.size());
1528 1521
1529 // The root surface was enqueued without being aggregated once, so it should 1522 // The root surface was enqueued without being aggregated once, so it should
1530 // be treated as completely damaged. 1523 // be treated as completely damaged.
1531 EXPECT_TRUE(aggregated_pass_list[1]->damage_rect.Contains( 1524 EXPECT_TRUE(aggregated_pass_list[1]->damage_rect.Contains(
1532 gfx::Rect(SurfaceSize()))); 1525 gfx::Rect(SurfaceSize())));
1533 } 1526 }
1534 1527
1535 // No Surface changed, so no damage should be given. 1528 // No Surface changed, so no damage should be given.
1536 { 1529 {
1537 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 1530 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
1538 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1531 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1539 1532
1540 const RenderPassList& aggregated_pass_list = 1533 const RenderPassList& aggregated_pass_list =
1541 aggregated_frame.render_pass_list; 1534 aggregated_frame.render_pass_list;
1542 1535
1543 ASSERT_EQ(2u, aggregated_pass_list.size()); 1536 ASSERT_EQ(2u, aggregated_pass_list.size());
1544 1537
1545 EXPECT_TRUE(aggregated_pass_list[1]->damage_rect.IsEmpty()); 1538 EXPECT_TRUE(aggregated_pass_list[1]->damage_rect.IsEmpty());
1546 } 1539 }
1547 1540
1548 // SetFullDamageRectForSurface should cause the entire output to be 1541 // SetFullDamageRectForSurface should cause the entire output to be
1549 // marked as damaged. 1542 // marked as damaged.
1550 { 1543 {
1551 aggregator_.SetFullDamageForSurface(root_surface_id); 1544 aggregator_.SetFullDamageForSurface(root_surface_id);
1552 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1545 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1553 1546
1554 const RenderPassList& aggregated_pass_list = 1547 const RenderPassList& aggregated_pass_list =
1555 aggregated_frame.render_pass_list; 1548 aggregated_frame.render_pass_list;
1556 1549
1557 ASSERT_EQ(2u, aggregated_pass_list.size()); 1550 ASSERT_EQ(2u, aggregated_pass_list.size());
1558 1551
1559 EXPECT_TRUE(aggregated_pass_list[1]->damage_rect.Contains( 1552 EXPECT_TRUE(aggregated_pass_list[1]->damage_rect.Contains(
1560 gfx::Rect(SurfaceSize()))); 1553 gfx::Rect(SurfaceSize())));
1561 } 1554 }
1562 1555
1563 parent_factory.EvictSurface(); 1556 parent_support.EvictFrame();
1564 } 1557 }
1565 1558
1566 // Check that damage is correctly calculated for surfaces. 1559 // Check that damage is correctly calculated for surfaces.
1567 TEST_F(SurfaceAggregatorValidSurfaceTest, SwitchSurfaceDamage) { 1560 TEST_F(SurfaceAggregatorValidSurfaceTest, SwitchSurfaceDamage) {
1568 test::Quad root_render_pass_quads[] = {test::Quad::SolidColorQuad(1)}; 1561 test::Quad root_render_pass_quads[] = {test::Quad::SolidColorQuad(1)};
1569 1562
1570 test::Pass root_passes[] = { 1563 test::Pass root_passes[] = {
1571 test::Pass(root_render_pass_quads, arraysize(root_render_pass_quads), 2)}; 1564 test::Pass(root_render_pass_quads, arraysize(root_render_pass_quads), 2)};
1572 1565
1573 CompositorFrame root_frame; 1566 CompositorFrame root_frame;
1574 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes, 1567 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes,
1575 arraysize(root_passes)); 1568 arraysize(root_passes));
1576 1569
1577 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(5, 5, 100, 100); 1570 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(5, 5, 100, 100);
1578 1571
1579 factory_.SubmitCompositorFrame(root_local_surface_id_, std::move(root_frame), 1572 support_.SubmitCompositorFrame(root_local_surface_id_, std::move(root_frame));
1580 SurfaceFactory::DrawCallback());
1581 1573
1582 { 1574 {
1583 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 1575 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
1584 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1576 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1585 1577
1586 const RenderPassList& aggregated_pass_list = 1578 const RenderPassList& aggregated_pass_list =
1587 aggregated_frame.render_pass_list; 1579 aggregated_frame.render_pass_list;
1588 1580
1589 ASSERT_EQ(1u, aggregated_pass_list.size()); 1581 ASSERT_EQ(1u, aggregated_pass_list.size());
1590 1582
1591 // Damage rect for first aggregation should contain entire root surface. 1583 // Damage rect for first aggregation should contain entire root surface.
1592 EXPECT_TRUE(aggregated_pass_list[0]->damage_rect.Contains( 1584 EXPECT_TRUE(aggregated_pass_list[0]->damage_rect.Contains(
1593 gfx::Rect(SurfaceSize()))); 1585 gfx::Rect(SurfaceSize())));
1594 } 1586 }
1595 1587
1596 LocalSurfaceId second_root_local_surface_id = allocator_.GenerateId(); 1588 LocalSurfaceId second_root_local_surface_id = allocator_.GenerateId();
1597 SurfaceId second_root_surface_id(factory_.frame_sink_id(), 1589 SurfaceId second_root_surface_id(support_.frame_sink_id(),
1598 second_root_local_surface_id); 1590 second_root_local_surface_id);
1599 { 1591 {
1600 test::Quad root_render_pass_quads[] = {test::Quad::SolidColorQuad(1)}; 1592 test::Quad root_render_pass_quads[] = {test::Quad::SolidColorQuad(1)};
1601 1593
1602 test::Pass root_passes[] = {test::Pass( 1594 test::Pass root_passes[] = {test::Pass(
1603 root_render_pass_quads, arraysize(root_render_pass_quads), 2)}; 1595 root_render_pass_quads, arraysize(root_render_pass_quads), 2)};
1604 1596
1605 CompositorFrame root_frame; 1597 CompositorFrame root_frame;
1606 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1598 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1607 root_passes, arraysize(root_passes)); 1599 root_passes, arraysize(root_passes));
1608 1600
1609 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(1, 2, 3, 4); 1601 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(1, 2, 3, 4);
1610 1602
1611 factory_.SubmitCompositorFrame(second_root_local_surface_id, 1603 support_.SubmitCompositorFrame(second_root_local_surface_id,
1612 std::move(root_frame), 1604 std::move(root_frame));
1613 SurfaceFactory::DrawCallback());
1614 } 1605 }
1615 { 1606 {
1616 CompositorFrame aggregated_frame = 1607 CompositorFrame aggregated_frame =
1617 aggregator_.Aggregate(second_root_surface_id); 1608 aggregator_.Aggregate(second_root_surface_id);
1618 1609
1619 const RenderPassList& aggregated_pass_list = 1610 const RenderPassList& aggregated_pass_list =
1620 aggregated_frame.render_pass_list; 1611 aggregated_frame.render_pass_list;
1621 1612
1622 ASSERT_EQ(1u, aggregated_pass_list.size()); 1613 ASSERT_EQ(1u, aggregated_pass_list.size());
1623 1614
(...skipping 16 matching lines...) Expand all
1640 class SurfaceAggregatorPartialSwapTest 1631 class SurfaceAggregatorPartialSwapTest
1641 : public SurfaceAggregatorValidSurfaceTest { 1632 : public SurfaceAggregatorValidSurfaceTest {
1642 public: 1633 public:
1643 SurfaceAggregatorPartialSwapTest() 1634 SurfaceAggregatorPartialSwapTest()
1644 : SurfaceAggregatorValidSurfaceTest(true) {} 1635 : SurfaceAggregatorValidSurfaceTest(true) {}
1645 }; 1636 };
1646 1637
1647 // Tests that quads outside the damage rect are ignored. 1638 // Tests that quads outside the damage rect are ignored.
1648 TEST_F(SurfaceAggregatorPartialSwapTest, IgnoreOutside) { 1639 TEST_F(SurfaceAggregatorPartialSwapTest, IgnoreOutside) {
1649 LocalSurfaceId child_local_surface_id = allocator_.GenerateId(); 1640 LocalSurfaceId child_local_surface_id = allocator_.GenerateId();
1650 SurfaceId child_surface_id(child_factory_.frame_sink_id(), 1641 SurfaceId child_surface_id(child_support_.frame_sink_id(),
1651 child_local_surface_id); 1642 child_local_surface_id);
1652 // The child surface has three quads, one with a visible rect of 13,13 4x4 and 1643 // The child surface has three quads, one with a visible rect of 13,13 4x4 and
1653 // the other other with a visible rect of 10,10 2x2 (relative to root target 1644 // the other other with a visible rect of 10,10 2x2 (relative to root target
1654 // space), and one with a non-invertible transform. 1645 // space), and one with a non-invertible transform.
1655 { 1646 {
1656 int child_pass_id = 1; 1647 int child_pass_id = 1;
1657 test::Quad child_quads1[] = {test::Quad::RenderPassQuad(child_pass_id)}; 1648 test::Quad child_quads1[] = {test::Quad::RenderPassQuad(child_pass_id)};
1658 test::Quad child_quads2[] = {test::Quad::RenderPassQuad(child_pass_id)}; 1649 test::Quad child_quads2[] = {test::Quad::RenderPassQuad(child_pass_id)};
1659 test::Quad child_quads3[] = {test::Quad::RenderPassQuad(child_pass_id)}; 1650 test::Quad child_quads3[] = {test::Quad::RenderPassQuad(child_pass_id)};
1660 test::Pass child_passes[] = { 1651 test::Pass child_passes[] = {
(...skipping 17 matching lines...) Expand all
1678 1669
1679 SharedQuadState* child_noninvertible_sqs = 1670 SharedQuadState* child_noninvertible_sqs =
1680 child_pass_list[2]->shared_quad_state_list.ElementAt(0u); 1671 child_pass_list[2]->shared_quad_state_list.ElementAt(0u);
1681 child_noninvertible_sqs->quad_to_target_transform.matrix().setDouble(0, 0, 1672 child_noninvertible_sqs->quad_to_target_transform.matrix().setDouble(0, 0,
1682 0.0); 1673 0.0);
1683 EXPECT_FALSE( 1674 EXPECT_FALSE(
1684 child_noninvertible_sqs->quad_to_target_transform.IsInvertible()); 1675 child_noninvertible_sqs->quad_to_target_transform.IsInvertible());
1685 child_pass_list[2]->quad_list.ElementAt(0)->visible_rect = 1676 child_pass_list[2]->quad_list.ElementAt(0)->visible_rect =
1686 gfx::Rect(0, 0, 2, 2); 1677 gfx::Rect(0, 0, 2, 2);
1687 1678
1688 SubmitPassListAsFrame(&child_factory_, child_local_surface_id, 1679 SubmitPassListAsFrame(&child_support_, child_local_surface_id,
1689 &child_pass_list); 1680 &child_pass_list);
1690 } 1681 }
1691 1682
1692 { 1683 {
1693 test::Quad root_quads[] = { 1684 test::Quad root_quads[] = {
1694 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)}; 1685 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)};
1695 1686
1696 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 1687 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
1697 1688
1698 RenderPassList root_pass_list; 1689 RenderPassList root_pass_list;
1699 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes, 1690 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes,
1700 arraysize(root_passes)); 1691 arraysize(root_passes));
1701 1692
1702 RenderPass* root_pass = root_pass_list[0].get(); 1693 RenderPass* root_pass = root_pass_list[0].get();
1703 root_pass->shared_quad_state_list.front() 1694 root_pass->shared_quad_state_list.front()
1704 ->quad_to_target_transform.Translate(10, 10); 1695 ->quad_to_target_transform.Translate(10, 10);
1705 root_pass->damage_rect = gfx::Rect(0, 0, 1, 1); 1696 root_pass->damage_rect = gfx::Rect(0, 0, 1, 1);
1706 1697
1707 SubmitPassListAsFrame(&factory_, root_local_surface_id_, &root_pass_list); 1698 SubmitPassListAsFrame(&support_, root_local_surface_id_, &root_pass_list);
1708 } 1699 }
1709 1700
1710 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_surface_id_); 1701 SurfaceId root_surface_id(support_.frame_sink_id(), root_local_surface_id_);
1711 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1702 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1712 1703
1713 const RenderPassList& aggregated_pass_list = 1704 const RenderPassList& aggregated_pass_list =
1714 aggregated_frame.render_pass_list; 1705 aggregated_frame.render_pass_list;
1715 1706
1716 ASSERT_EQ(3u, aggregated_pass_list.size()); 1707 ASSERT_EQ(3u, aggregated_pass_list.size());
1717 1708
1718 // Damage rect for first aggregation should contain entire root surface. 1709 // Damage rect for first aggregation should contain entire root surface.
1719 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[2]->damage_rect); 1710 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[2]->damage_rect);
1720 EXPECT_EQ(1u, aggregated_pass_list[0]->quad_list.size()); 1711 EXPECT_EQ(1u, aggregated_pass_list[0]->quad_list.size());
1721 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); 1712 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size());
1722 EXPECT_EQ(1u, aggregated_pass_list[2]->quad_list.size()); 1713 EXPECT_EQ(1u, aggregated_pass_list[2]->quad_list.size());
1723 1714
1724 // Create a root surface with a smaller damage rect. 1715 // Create a root surface with a smaller damage rect.
1725 { 1716 {
1726 test::Quad root_quads[] = { 1717 test::Quad root_quads[] = {
1727 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)}; 1718 test::Quad::SurfaceQuad(child_surface_id, InvalidSurfaceId(), 1.f)};
1728 1719
1729 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 1720 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
1730 1721
1731 RenderPassList root_pass_list; 1722 RenderPassList root_pass_list;
1732 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes, 1723 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes,
1733 arraysize(root_passes)); 1724 arraysize(root_passes));
1734 1725
1735 RenderPass* root_pass = root_pass_list[0].get(); 1726 RenderPass* root_pass = root_pass_list[0].get();
1736 root_pass->shared_quad_state_list.front() 1727 root_pass->shared_quad_state_list.front()
1737 ->quad_to_target_transform.Translate(10, 10); 1728 ->quad_to_target_transform.Translate(10, 10);
1738 root_pass->damage_rect = gfx::Rect(10, 10, 2, 2); 1729 root_pass->damage_rect = gfx::Rect(10, 10, 2, 2);
1739 SubmitPassListAsFrame(&factory_, root_local_surface_id_, &root_pass_list); 1730 SubmitPassListAsFrame(&support_, root_local_surface_id_, &root_pass_list);
1740 } 1731 }
1741 1732
1742 { 1733 {
1743 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1734 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1744 1735
1745 const RenderPassList& aggregated_pass_list = 1736 const RenderPassList& aggregated_pass_list =
1746 aggregated_frame.render_pass_list; 1737 aggregated_frame.render_pass_list;
1747 1738
1748 ASSERT_EQ(3u, aggregated_pass_list.size()); 1739 ASSERT_EQ(3u, aggregated_pass_list.size());
1749 1740
(...skipping 29 matching lines...) Expand all
1779 child_sqs->quad_to_target_transform.Scale(2, 2); 1770 child_sqs->quad_to_target_transform.Scale(2, 2);
1780 1771
1781 child_pass_list[1]->quad_list.ElementAt(0)->visible_rect = 1772 child_pass_list[1]->quad_list.ElementAt(0)->visible_rect =
1782 gfx::Rect(0, 0, 2, 2); 1773 gfx::Rect(0, 0, 2, 2);
1783 1774
1784 RenderPass* child_root_pass = child_pass_list[1].get(); 1775 RenderPass* child_root_pass = child_pass_list[1].get();
1785 1776
1786 child_root_pass->copy_requests.push_back( 1777 child_root_pass->copy_requests.push_back(
1787 CopyOutputRequest::CreateEmptyRequest()); 1778 CopyOutputRequest::CreateEmptyRequest());
1788 child_root_pass->damage_rect = gfx::Rect(); 1779 child_root_pass->damage_rect = gfx::Rect();
1789 SubmitPassListAsFrame(&child_factory_, child_local_surface_id, 1780 SubmitPassListAsFrame(&child_support_, child_local_surface_id,
1790 &child_pass_list); 1781 &child_pass_list);
1791 } 1782 }
1792 1783
1793 { 1784 {
1794 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1785 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1795 1786
1796 const RenderPassList& aggregated_pass_list = 1787 const RenderPassList& aggregated_pass_list =
1797 aggregated_frame.render_pass_list; 1788 aggregated_frame.render_pass_list;
1798 1789
1799 // Output frame should have no damage, but all quads included. 1790 // Output frame should have no damage, but all quads included.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 RenderPassList root_pass_list; 1830 RenderPassList root_pass_list;
1840 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes, 1831 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes,
1841 arraysize(root_passes)); 1832 arraysize(root_passes));
1842 1833
1843 RenderPass* filter_pass = root_pass_list[1].get(); 1834 RenderPass* filter_pass = root_pass_list[1].get();
1844 filter_pass->shared_quad_state_list.front() 1835 filter_pass->shared_quad_state_list.front()
1845 ->quad_to_target_transform.Translate(10, 10); 1836 ->quad_to_target_transform.Translate(10, 10);
1846 RenderPass* root_pass = root_pass_list[2].get(); 1837 RenderPass* root_pass = root_pass_list[2].get();
1847 filter_pass->filters.Append(FilterOperation::CreateBlurFilter(2)); 1838 filter_pass->filters.Append(FilterOperation::CreateBlurFilter(2));
1848 root_pass->damage_rect = gfx::Rect(10, 10, 2, 2); 1839 root_pass->damage_rect = gfx::Rect(10, 10, 2, 2);
1849 SubmitPassListAsFrame(&factory_, root_local_surface_id_, &root_pass_list); 1840 SubmitPassListAsFrame(&support_, root_local_surface_id_, &root_pass_list);
1850 } 1841 }
1851 1842
1852 { 1843 {
1853 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1844 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1854 1845
1855 const RenderPassList& aggregated_pass_list = 1846 const RenderPassList& aggregated_pass_list =
1856 aggregated_frame.render_pass_list; 1847 aggregated_frame.render_pass_list;
1857 1848
1858 ASSERT_EQ(4u, aggregated_pass_list.size()); 1849 ASSERT_EQ(4u, aggregated_pass_list.size());
1859 1850
(...skipping 27 matching lines...) Expand all
1887 RenderPassList root_pass_list; 1878 RenderPassList root_pass_list;
1888 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes, 1879 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes,
1889 arraysize(root_passes)); 1880 arraysize(root_passes));
1890 1881
1891 RenderPass* pass = root_pass_list[0].get(); 1882 RenderPass* pass = root_pass_list[0].get();
1892 RenderPass* root_pass = root_pass_list[1].get(); 1883 RenderPass* root_pass = root_pass_list[1].get();
1893 root_pass->shared_quad_state_list.ElementAt(1) 1884 root_pass->shared_quad_state_list.ElementAt(1)
1894 ->quad_to_target_transform.Translate(10, 10); 1885 ->quad_to_target_transform.Translate(10, 10);
1895 pass->background_filters.Append(FilterOperation::CreateBlurFilter(2)); 1886 pass->background_filters.Append(FilterOperation::CreateBlurFilter(2));
1896 root_pass->damage_rect = gfx::Rect(10, 10, 2, 2); 1887 root_pass->damage_rect = gfx::Rect(10, 10, 2, 2);
1897 SubmitPassListAsFrame(&factory_, root_local_surface_id_, &root_pass_list); 1888 SubmitPassListAsFrame(&support_, root_local_surface_id_, &root_pass_list);
1898 } 1889 }
1899 1890
1900 { 1891 {
1901 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1892 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1902 1893
1903 const RenderPassList& aggregated_pass_list = 1894 const RenderPassList& aggregated_pass_list =
1904 aggregated_frame.render_pass_list; 1895 aggregated_frame.render_pass_list;
1905 1896
1906 ASSERT_EQ(3u, aggregated_pass_list.size()); 1897 ASSERT_EQ(3u, aggregated_pass_list.size());
1907 1898
(...skipping 23 matching lines...) Expand all
1931 aggregator_->set_output_is_secure(true); 1922 aggregator_->set_output_is_secure(true);
1932 } 1923 }
1933 1924
1934 protected: 1925 protected:
1935 SurfaceManager manager_; 1926 SurfaceManager manager_;
1936 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; 1927 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_;
1937 std::unique_ptr<ResourceProvider> resource_provider_; 1928 std::unique_ptr<ResourceProvider> resource_provider_;
1938 std::unique_ptr<SurfaceAggregator> aggregator_; 1929 std::unique_ptr<SurfaceAggregator> aggregator_;
1939 }; 1930 };
1940 1931
1941 class ResourceTrackingSurfaceFactoryClient : public SurfaceFactoryClient {
1942 public:
1943 ResourceTrackingSurfaceFactoryClient() {}
1944 ~ResourceTrackingSurfaceFactoryClient() override {}
1945
1946 void ReturnResources(const ReturnedResourceArray& resources) override {
1947 returned_resources_ = resources;
1948 }
1949
1950 ReturnedResourceArray returned_resources() const {
1951 return returned_resources_;
1952 }
1953
1954 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {}
1955
1956 private:
1957 ReturnedResourceArray returned_resources_;
1958
1959 DISALLOW_COPY_AND_ASSIGN(ResourceTrackingSurfaceFactoryClient);
1960 };
1961
1962 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, 1932 void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
1963 size_t num_resource_ids, 1933 size_t num_resource_ids,
1964 bool valid, 1934 bool valid,
1965 SurfaceId child_id, 1935 SurfaceId child_id,
1966 SurfaceFactory* factory, 1936 CompositorFrameSinkSupport* support,
1967 SurfaceId surface_id) { 1937 SurfaceId surface_id) {
1968 CompositorFrame frame; 1938 CompositorFrame frame;
1969 std::unique_ptr<RenderPass> pass = RenderPass::Create(); 1939 std::unique_ptr<RenderPass> pass = RenderPass::Create();
1970 pass->id = 1; 1940 pass->id = 1;
1971 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 1941 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
1972 sqs->opacity = 1.f; 1942 sqs->opacity = 1.f;
1973 if (child_id.is_valid()) { 1943 if (child_id.is_valid()) {
1974 SurfaceDrawQuad* surface_quad = 1944 SurfaceDrawQuad* surface_quad =
1975 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 1945 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
1976 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), 1946 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1),
(...skipping 18 matching lines...) Expand all
1995 const float vertex_opacity[4] = {0.f, 0.f, 1.f, 1.f}; 1965 const float vertex_opacity[4] = {0.f, 0.f, 1.f, 1.f};
1996 bool flipped = false; 1966 bool flipped = false;
1997 bool nearest_neighbor = false; 1967 bool nearest_neighbor = false;
1998 bool secure_output_only = true; 1968 bool secure_output_only = true;
1999 quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, 1969 quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending,
2000 resource_ids[i], gfx::Size(), premultiplied_alpha, uv_top_left, 1970 resource_ids[i], gfx::Size(), premultiplied_alpha, uv_top_left,
2001 uv_bottom_right, background_color, vertex_opacity, flipped, 1971 uv_bottom_right, background_color, vertex_opacity, flipped,
2002 nearest_neighbor, secure_output_only); 1972 nearest_neighbor, secure_output_only);
2003 } 1973 }
2004 frame.render_pass_list.push_back(std::move(pass)); 1974 frame.render_pass_list.push_back(std::move(pass));
2005 factory->SubmitCompositorFrame(surface_id.local_surface_id(), 1975 support->SubmitCompositorFrame(surface_id.local_surface_id(),
2006 std::move(frame), 1976 std::move(frame));
2007 SurfaceFactory::DrawCallback());
2008 } 1977 }
2009 1978
2010 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { 1979 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) {
2011 ResourceTrackingSurfaceFactoryClient client; 1980 EmptyCompositorFrameSinkSupportClient client;
2012 SurfaceFactory factory(kArbitraryRootFrameSinkId, &manager_, &client); 1981 CompositorFrameSinkSupport support(
1982 &client, &manager_, kArbitraryRootFrameSinkId, is_root,
1983 handles_frame_sink_id_invalidation, needs_sync_points);
2013 LocalSurfaceId local_surface_id(7u, base::UnguessableToken::Create()); 1984 LocalSurfaceId local_surface_id(7u, base::UnguessableToken::Create());
2014 SurfaceId surface_id(factory.frame_sink_id(), local_surface_id); 1985 SurfaceId surface_id(support.frame_sink_id(), local_surface_id);
2015 1986
2016 ResourceId ids[] = {11, 12, 13}; 1987 ResourceId ids[] = {11, 12, 13};
2017 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), 1988 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(),
2018 &factory, surface_id); 1989 &support, surface_id);
2019 1990
2020 CompositorFrame frame = aggregator_->Aggregate(surface_id); 1991 CompositorFrame frame = aggregator_->Aggregate(surface_id);
2021 1992
2022 // Nothing should be available to be returned yet. 1993 // Nothing should be available to be returned yet.
2023 EXPECT_TRUE(client.returned_resources().empty()); 1994 EXPECT_TRUE(client.returned_resources().empty());
2024 1995
2025 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, 1996 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &support,
2026 surface_id); 1997 surface_id);
2027 1998
2028 frame = aggregator_->Aggregate(surface_id); 1999 frame = aggregator_->Aggregate(surface_id);
2029 2000
2030 ASSERT_EQ(3u, client.returned_resources().size()); 2001 ASSERT_EQ(3u, client.returned_resources().size());
2031 ResourceId returned_ids[3]; 2002 ResourceId returned_ids[3];
2032 for (size_t i = 0; i < 3; ++i) { 2003 for (size_t i = 0; i < 3; ++i) {
2033 returned_ids[i] = client.returned_resources()[i].id; 2004 returned_ids[i] = client.returned_resources()[i].id;
2034 } 2005 }
2035 EXPECT_THAT(returned_ids, 2006 EXPECT_THAT(returned_ids,
2036 testing::WhenSorted(testing::ElementsAreArray(ids))); 2007 testing::WhenSorted(testing::ElementsAreArray(ids)));
2037 2008
2038 factory.EvictSurface(); 2009 support.EvictFrame();
2039 } 2010 }
2040 2011
2041 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { 2012 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) {
2042 ResourceTrackingSurfaceFactoryClient client; 2013 EmptyCompositorFrameSinkSupportClient client;
2043 SurfaceFactory factory(kArbitraryRootFrameSinkId, &manager_, &client); 2014 CompositorFrameSinkSupport support(
2015 &client, &manager_, kArbitraryRootFrameSinkId, is_root,
2016 handles_frame_sink_id_invalidation, needs_sync_points);
2044 LocalSurfaceId local_surface_id(7u, base::UnguessableToken::Create()); 2017 LocalSurfaceId local_surface_id(7u, base::UnguessableToken::Create());
2045 SurfaceId surface_id(factory.frame_sink_id(), local_surface_id); 2018 SurfaceId surface_id(support.frame_sink_id(), local_surface_id);
2046 2019
2047 CompositorFrame frame; 2020 CompositorFrame frame;
2048 std::unique_ptr<RenderPass> pass = RenderPass::Create(); 2021 std::unique_ptr<RenderPass> pass = RenderPass::Create();
2049 pass->id = 1; 2022 pass->id = 1;
2050 TransferableResource resource; 2023 TransferableResource resource;
2051 resource.id = 11; 2024 resource.id = 11;
2052 // ResourceProvider is software but resource is not, so it should be 2025 // ResourceProvider is software but resource is not, so it should be
2053 // ignored. 2026 // ignored.
2054 resource.is_software = false; 2027 resource.is_software = false;
2055 frame.resource_list.push_back(resource); 2028 frame.resource_list.push_back(resource);
2056 frame.render_pass_list.push_back(std::move(pass)); 2029 frame.render_pass_list.push_back(std::move(pass));
2057 factory.SubmitCompositorFrame(local_surface_id, std::move(frame), 2030 support.SubmitCompositorFrame(local_surface_id, std::move(frame));
2058 SurfaceFactory::DrawCallback());
2059 2031
2060 CompositorFrame returned_frame = aggregator_->Aggregate(surface_id); 2032 CompositorFrame returned_frame = aggregator_->Aggregate(surface_id);
2061 2033
2062 // Nothing should be available to be returned yet. 2034 // Nothing should be available to be returned yet.
2063 EXPECT_TRUE(client.returned_resources().empty()); 2035 EXPECT_TRUE(client.returned_resources().empty());
2064 2036
2065 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &factory, 2037 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &support,
2066 surface_id); 2038 surface_id);
2067 ASSERT_EQ(1u, client.returned_resources().size()); 2039 ASSERT_EQ(1u, client.returned_resources().size());
2068 EXPECT_EQ(11u, client.returned_resources()[0].id); 2040 EXPECT_EQ(11u, client.returned_resources()[0].id);
2069 2041
2070 factory.EvictSurface(); 2042 support.EvictFrame();
2071 } 2043 }
2072 2044
2073 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { 2045 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) {
2074 ResourceTrackingSurfaceFactoryClient client; 2046 EmptyCompositorFrameSinkSupportClient client;
2075 SurfaceFactory factory1(FrameSinkId(1, 1), &manager_, &client); 2047 CompositorFrameSinkSupport support1(
2076 SurfaceFactory factory2(FrameSinkId(2, 2), &manager_, &client); 2048 &client, &manager_, FrameSinkId(1, 1), is_root_child,
2049 handles_frame_sink_id_invalidation, needs_sync_points);
2050 CompositorFrameSinkSupport support2(
2051 &client, &manager_, FrameSinkId(2, 2), is_root_child,
2052 handles_frame_sink_id_invalidation, needs_sync_points);
2077 LocalSurfaceId local_frame1_id(7u, base::UnguessableToken::Create()); 2053 LocalSurfaceId local_frame1_id(7u, base::UnguessableToken::Create());
2078 SurfaceId surface1_id(factory1.frame_sink_id(), local_frame1_id); 2054 SurfaceId surface1_id(support1.frame_sink_id(), local_frame1_id);
2079 2055
2080 LocalSurfaceId local_frame2_id(8u, base::UnguessableToken::Create()); 2056 LocalSurfaceId local_frame2_id(8u, base::UnguessableToken::Create());
2081 SurfaceId surface2_id(factory2.frame_sink_id(), local_frame2_id); 2057 SurfaceId surface2_id(support2.frame_sink_id(), local_frame2_id);
2082 2058
2083 ResourceId ids[] = {11, 12, 13}; 2059 ResourceId ids[] = {11, 12, 13};
2084 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), 2060 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(),
2085 &factory1, surface1_id); 2061 &support1, surface1_id);
2086 ResourceId ids2[] = {14, 15, 16}; 2062 ResourceId ids2[] = {14, 15, 16};
2087 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), 2063 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(),
2088 &factory2, surface2_id); 2064 &support2, surface2_id);
2089 2065
2090 CompositorFrame frame = aggregator_->Aggregate(surface1_id); 2066 CompositorFrame frame = aggregator_->Aggregate(surface1_id);
2091 2067
2092 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &factory1, 2068 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &support1,
2093 surface1_id); 2069 surface1_id);
2094 2070
2095 // Nothing should be available to be returned yet. 2071 // Nothing should be available to be returned yet.
2096 EXPECT_TRUE(client.returned_resources().empty()); 2072 EXPECT_TRUE(client.returned_resources().empty());
2097 2073
2098 frame = aggregator_->Aggregate(surface2_id); 2074 frame = aggregator_->Aggregate(surface2_id);
2099 2075
2100 // surface1_id wasn't referenced, so its resources should be returned. 2076 // surface1_id wasn't referenced, so its resources should be returned.
2101 ASSERT_EQ(3u, client.returned_resources().size()); 2077 ASSERT_EQ(3u, client.returned_resources().size());
2102 ResourceId returned_ids[3]; 2078 ResourceId returned_ids[3];
2103 for (size_t i = 0; i < 3; ++i) { 2079 for (size_t i = 0; i < 3; ++i) {
2104 returned_ids[i] = client.returned_resources()[i].id; 2080 returned_ids[i] = client.returned_resources()[i].id;
2105 } 2081 }
2106 EXPECT_THAT(returned_ids, 2082 EXPECT_THAT(returned_ids,
2107 testing::WhenSorted(testing::ElementsAreArray(ids))); 2083 testing::WhenSorted(testing::ElementsAreArray(ids)));
2108 EXPECT_EQ(3u, resource_provider_->num_resources()); 2084 EXPECT_EQ(3u, resource_provider_->num_resources());
2109 2085
2110 factory1.EvictSurface(); 2086 support1.EvictFrame();
2111 factory2.EvictSurface(); 2087 support2.EvictFrame();
2112 } 2088 }
2113 2089
2114 // Ensure that aggregator completely ignores Surfaces that reference invalid 2090 // Ensure that aggregator completely ignores Surfaces that reference invalid
2115 // resources. 2091 // resources.
2116 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { 2092 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) {
2117 ResourceTrackingSurfaceFactoryClient client; 2093 CompositorFrameSinkSupport root_support(
2118 SurfaceFactory root_factory(kArbitraryRootFrameSinkId, &manager_, &client); 2094 nullptr, &manager_, kArbitraryRootFrameSinkId, is_root,
2119 SurfaceFactory middle_factory(kArbitraryMiddleFrameSinkId, &manager_, 2095 handles_frame_sink_id_invalidation, needs_sync_points);
2120 &client); 2096 CompositorFrameSinkSupport middle_support(
2121 SurfaceFactory child_factory(kArbitraryChildFrameSinkId1, &manager_, &client); 2097 nullptr, &manager_, kArbitraryMiddleFrameSinkId, is_root_child,
2098 handles_frame_sink_id_invalidation, needs_sync_points);
2099 CompositorFrameSinkSupport child_support(
2100 nullptr, &manager_, kArbitraryFrameSinkId1, is_root_child,
2101 handles_frame_sink_id_invalidation, needs_sync_points);
2122 LocalSurfaceId root_local_surface_id(7u, kArbitraryToken); 2102 LocalSurfaceId root_local_surface_id(7u, kArbitraryToken);
2123 SurfaceId root_surface_id(root_factory.frame_sink_id(), 2103 SurfaceId root_surface_id(root_support.frame_sink_id(),
2124 root_local_surface_id); 2104 root_local_surface_id);
2125 LocalSurfaceId middle_local_surface_id(8u, kArbitraryToken); 2105 LocalSurfaceId middle_local_surface_id(8u, kArbitraryToken);
2126 SurfaceId middle_surface_id(middle_factory.frame_sink_id(), 2106 SurfaceId middle_surface_id(middle_support.frame_sink_id(),
2127 middle_local_surface_id); 2107 middle_local_surface_id);
2128 LocalSurfaceId child_local_surface_id(9u, kArbitraryToken); 2108 LocalSurfaceId child_local_surface_id(9u, kArbitraryToken);
2129 SurfaceId child_surface_id(child_factory.frame_sink_id(), 2109 SurfaceId child_surface_id(child_support.frame_sink_id(),
2130 child_local_surface_id); 2110 child_local_surface_id);
2131 2111
2132 ResourceId ids[] = {14, 15, 16}; 2112 ResourceId ids[] = {14, 15, 16};
2133 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), 2113 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(),
2134 &child_factory, child_surface_id); 2114 &child_support, child_surface_id);
2135 2115
2136 ResourceId ids2[] = {17, 18, 19}; 2116 ResourceId ids2[] = {17, 18, 19};
2137 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, 2117 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false,
2138 child_surface_id, &middle_factory, 2118 child_surface_id, &middle_support,
2139 middle_surface_id); 2119 middle_surface_id);
2140 2120
2141 ResourceId ids3[] = {20, 21, 22}; 2121 ResourceId ids3[] = {20, 21, 22};
2142 SubmitCompositorFrameWithResources(ids3, arraysize(ids3), true, 2122 SubmitCompositorFrameWithResources(ids3, arraysize(ids3), true,
2143 middle_surface_id, &root_factory, 2123 middle_surface_id, &root_support,
2144 root_surface_id); 2124 root_surface_id);
2145 2125
2146 CompositorFrame frame; 2126 CompositorFrame frame;
2147 frame = aggregator_->Aggregate(root_surface_id); 2127 frame = aggregator_->Aggregate(root_surface_id);
2148 2128
2149 RenderPassList* pass_list = &frame.render_pass_list; 2129 RenderPassList* pass_list = &frame.render_pass_list;
2150 ASSERT_EQ(1u, pass_list->size()); 2130 ASSERT_EQ(1u, pass_list->size());
2151 EXPECT_EQ(1u, pass_list->back()->shared_quad_state_list.size()); 2131 EXPECT_EQ(1u, pass_list->back()->shared_quad_state_list.size());
2152 EXPECT_EQ(3u, pass_list->back()->quad_list.size()); 2132 EXPECT_EQ(3u, pass_list->back()->quad_list.size());
2153 SubmitCompositorFrameWithResources(ids2, arraysize(ids), true, 2133 SubmitCompositorFrameWithResources(ids2, arraysize(ids), true,
2154 child_surface_id, &middle_factory, 2134 child_surface_id, &middle_support,
2155 middle_surface_id); 2135 middle_surface_id);
2156 2136
2157 frame = aggregator_->Aggregate(root_surface_id); 2137 frame = aggregator_->Aggregate(root_surface_id);
2158 2138
2159 pass_list = &frame.render_pass_list; 2139 pass_list = &frame.render_pass_list;
2160 ASSERT_EQ(1u, pass_list->size()); 2140 ASSERT_EQ(1u, pass_list->size());
2161 EXPECT_EQ(3u, pass_list->back()->shared_quad_state_list.size()); 2141 EXPECT_EQ(3u, pass_list->back()->shared_quad_state_list.size());
2162 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); 2142 EXPECT_EQ(9u, pass_list->back()->quad_list.size());
2163 2143
2164 root_factory.EvictSurface(); 2144 root_support.EvictFrame();
2165 middle_factory.EvictSurface(); 2145 middle_support.EvictFrame();
2166 child_factory.EvictSurface(); 2146 child_support.EvictFrame();
2167 } 2147 }
2168 2148
2169 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { 2149 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) {
2170 ResourceTrackingSurfaceFactoryClient client; 2150 CompositorFrameSinkSupport support1(
2171 SurfaceFactory factory1(FrameSinkId(1, 1), &manager_, &client); 2151 nullptr, &manager_, FrameSinkId(1, 1), is_root_child,
2172 SurfaceFactory factory2(FrameSinkId(2, 2), &manager_, &client); 2152 handles_frame_sink_id_invalidation, needs_sync_points);
2153 CompositorFrameSinkSupport support2(
2154 nullptr, &manager_, FrameSinkId(2, 2), is_root_child,
2155 handles_frame_sink_id_invalidation, needs_sync_points);
2173 LocalSurfaceId local_frame1_id(7u, base::UnguessableToken::Create()); 2156 LocalSurfaceId local_frame1_id(7u, base::UnguessableToken::Create());
2174 SurfaceId surface1_id(factory1.frame_sink_id(), local_frame1_id); 2157 SurfaceId surface1_id(support1.frame_sink_id(), local_frame1_id);
2175 2158
2176 LocalSurfaceId local_frame2_id(8u, base::UnguessableToken::Create()); 2159 LocalSurfaceId local_frame2_id(8u, base::UnguessableToken::Create());
2177 SurfaceId surface2_id(factory2.frame_sink_id(), local_frame2_id); 2160 SurfaceId surface2_id(support2.frame_sink_id(), local_frame2_id);
2178 2161
2179 ResourceId ids[] = {11, 12, 13}; 2162 ResourceId ids[] = {11, 12, 13};
2180 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), 2163 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(),
2181 &factory1, surface1_id); 2164 &support1, surface1_id);
2182 2165
2183 CompositorFrame frame = aggregator_->Aggregate(surface1_id); 2166 CompositorFrame frame = aggregator_->Aggregate(surface1_id);
2184 2167
2185 RenderPass* render_pass = frame.render_pass_list.back().get(); 2168 RenderPass* render_pass = frame.render_pass_list.back().get();
2186 2169
2187 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, render_pass->quad_list.back()->material); 2170 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, render_pass->quad_list.back()->material);
2188 2171
2189 { 2172 {
2190 std::unique_ptr<RenderPass> pass = RenderPass::Create(); 2173 std::unique_ptr<RenderPass> pass = RenderPass::Create();
2191 pass->id = 1; 2174 pass->id = 1;
2192 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 2175 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
2193 sqs->opacity = 1.f; 2176 sqs->opacity = 1.f;
2194 SurfaceDrawQuad* surface_quad = 2177 SurfaceDrawQuad* surface_quad =
2195 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 2178 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
2196 2179
2197 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), 2180 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1),
2198 surface1_id, SurfaceDrawQuadType::PRIMARY, nullptr); 2181 surface1_id, SurfaceDrawQuadType::PRIMARY, nullptr);
2199 pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest()); 2182 pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest());
2200 2183
2201 CompositorFrame frame; 2184 CompositorFrame frame;
2202 frame.render_pass_list.push_back(std::move(pass)); 2185 frame.render_pass_list.push_back(std::move(pass));
2203 2186
2204 factory2.SubmitCompositorFrame(local_frame2_id, std::move(frame), 2187 support2.SubmitCompositorFrame(local_frame2_id, std::move(frame));
2205 SurfaceFactory::DrawCallback());
2206 } 2188 }
2207 2189
2208 frame = aggregator_->Aggregate(surface2_id); 2190 frame = aggregator_->Aggregate(surface2_id);
2209 EXPECT_EQ(1u, frame.render_pass_list.size()); 2191 EXPECT_EQ(1u, frame.render_pass_list.size());
2210 render_pass = frame.render_pass_list.front().get(); 2192 render_pass = frame.render_pass_list.front().get();
2211 2193
2212 // Parent has copy request, so texture should not be drawn. 2194 // Parent has copy request, so texture should not be drawn.
2213 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); 2195 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material);
2214 2196
2215 frame = aggregator_->Aggregate(surface2_id); 2197 frame = aggregator_->Aggregate(surface2_id);
2216 EXPECT_EQ(1u, frame.render_pass_list.size()); 2198 EXPECT_EQ(1u, frame.render_pass_list.size());
2217 render_pass = frame.render_pass_list.front().get(); 2199 render_pass = frame.render_pass_list.front().get();
2218 2200
2219 // Copy request has been executed earlier, so texture should be drawn. 2201 // Copy request has been executed earlier, so texture should be drawn.
2220 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, 2202 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT,
2221 render_pass->quad_list.front()->material); 2203 render_pass->quad_list.front()->material);
2222 2204
2223 aggregator_->set_output_is_secure(false); 2205 aggregator_->set_output_is_secure(false);
2224 2206
2225 frame = aggregator_->Aggregate(surface2_id); 2207 frame = aggregator_->Aggregate(surface2_id);
2226 render_pass = frame.render_pass_list.back().get(); 2208 render_pass = frame.render_pass_list.back().get();
2227 2209
2228 // Output is insecure, so texture should be drawn. 2210 // Output is insecure, so texture should be drawn.
2229 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); 2211 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material);
2230 2212
2231 factory1.EvictSurface(); 2213 support1.EvictFrame();
2232 factory2.EvictSurface(); 2214 support2.EvictFrame();
2233 } 2215 }
2234 2216
2235 // Ensure that the render passes have correct color spaces. 2217 // Ensure that the render passes have correct color spaces.
2236 TEST_F(SurfaceAggregatorValidSurfaceTest, ColorSpaceTest) { 2218 TEST_F(SurfaceAggregatorValidSurfaceTest, ColorSpaceTest) {
2237 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE), 2219 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE),
2238 test::Quad::SolidColorQuad(SK_ColorLTGRAY)}, 2220 test::Quad::SolidColorQuad(SK_ColorLTGRAY)},
2239 {test::Quad::SolidColorQuad(SK_ColorGRAY), 2221 {test::Quad::SolidColorQuad(SK_ColorGRAY),
2240 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}}; 2222 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}};
2241 test::Pass passes[] = {test::Pass(quads[0], arraysize(quads[0]), 2), 2223 test::Pass passes[] = {test::Pass(quads[0], arraysize(quads[0]), 2),
2242 test::Pass(quads[1], arraysize(quads[1]), 1)}; 2224 test::Pass(quads[1], arraysize(quads[1]), 1)};
2243 gfx::ColorSpace color_space1 = gfx::ColorSpace::CreateXYZD50(); 2225 gfx::ColorSpace color_space1 = gfx::ColorSpace::CreateXYZD50();
2244 gfx::ColorSpace color_space2 = gfx::ColorSpace::CreateSRGB(); 2226 gfx::ColorSpace color_space2 = gfx::ColorSpace::CreateSRGB();
2245 gfx::ColorSpace color_space3 = gfx::ColorSpace::CreateSCRGBLinear(); 2227 gfx::ColorSpace color_space3 = gfx::ColorSpace::CreateSCRGBLinear();
2246 2228
2247 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 2229 SubmitCompositorFrame(&support_, passes, arraysize(passes),
2248 root_local_surface_id_); 2230 root_local_surface_id_);
2249 2231
2250 SurfaceId surface_id(factory_.frame_sink_id(), root_local_surface_id_); 2232 SurfaceId surface_id(support_.frame_sink_id(), root_local_surface_id_);
2251 2233
2252 CompositorFrame aggregated_frame; 2234 CompositorFrame aggregated_frame;
2253 aggregator_.SetOutputColorSpace(color_space1, color_space1); 2235 aggregator_.SetOutputColorSpace(color_space1, color_space1);
2254 aggregated_frame = aggregator_.Aggregate(surface_id); 2236 aggregated_frame = aggregator_.Aggregate(surface_id);
2255 EXPECT_EQ(2u, aggregated_frame.render_pass_list.size()); 2237 EXPECT_EQ(2u, aggregated_frame.render_pass_list.size());
2256 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[0]->color_space); 2238 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[0]->color_space);
2257 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[1]->color_space); 2239 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[1]->color_space);
2258 2240
2259 aggregator_.SetOutputColorSpace(color_space2, color_space2); 2241 aggregator_.SetOutputColorSpace(color_space2, color_space2);
2260 aggregated_frame = aggregator_.Aggregate(surface_id); 2242 aggregated_frame = aggregator_.Aggregate(surface_id);
2261 EXPECT_EQ(2u, aggregated_frame.render_pass_list.size()); 2243 EXPECT_EQ(2u, aggregated_frame.render_pass_list.size());
2262 EXPECT_EQ(color_space2, aggregated_frame.render_pass_list[0]->color_space); 2244 EXPECT_EQ(color_space2, aggregated_frame.render_pass_list[0]->color_space);
2263 EXPECT_EQ(color_space2, aggregated_frame.render_pass_list[1]->color_space); 2245 EXPECT_EQ(color_space2, aggregated_frame.render_pass_list[1]->color_space);
2264 2246
2265 aggregator_.SetOutputColorSpace(color_space1, color_space3); 2247 aggregator_.SetOutputColorSpace(color_space1, color_space3);
2266 aggregated_frame = aggregator_.Aggregate(surface_id); 2248 aggregated_frame = aggregator_.Aggregate(surface_id);
2267 EXPECT_EQ(3u, aggregated_frame.render_pass_list.size()); 2249 EXPECT_EQ(3u, aggregated_frame.render_pass_list.size());
2268 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[0]->color_space); 2250 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[0]->color_space);
2269 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[1]->color_space); 2251 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[1]->color_space);
2270 EXPECT_EQ(color_space3, aggregated_frame.render_pass_list[2]->color_space); 2252 EXPECT_EQ(color_space3, aggregated_frame.render_pass_list[2]->color_space);
2271 } 2253 }
2272 2254
2273 } // namespace 2255 } // namespace
2274 } // namespace cc 2256 } // namespace cc
2275 2257
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698