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

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

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: rebase Created 4 years, 1 month 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>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 protected: 74 protected:
75 SurfaceManager manager_; 75 SurfaceManager manager_;
76 EmptySurfaceFactoryClient empty_client_; 76 EmptySurfaceFactoryClient empty_client_;
77 SurfaceFactory factory_; 77 SurfaceFactory factory_;
78 SurfaceAggregator aggregator_; 78 SurfaceAggregator aggregator_;
79 }; 79 };
80 80
81 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { 81 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) {
82 LocalFrameId local_frame_id(7, 0); 82 LocalFrameId local_frame_id(7, 0);
83 SurfaceId one_id(kArbitraryFrameSinkId, local_frame_id); 83 SurfaceId one_id(kArbitraryFrameSinkId, local_frame_id);
84 factory_.Create(local_frame_id); 84 factory_.SubmitCompositorFrame(local_frame_id, CompositorFrame(),
85 SurfaceFactory::DrawCallback());
85 86
86 CompositorFrame frame = aggregator_.Aggregate(one_id); 87 CompositorFrame frame = aggregator_.Aggregate(one_id);
87 EXPECT_TRUE(frame.render_pass_list.empty()); 88 EXPECT_TRUE(frame.render_pass_list.empty());
88
89 factory_.Destroy(local_frame_id);
90 } 89 }
91 90
92 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { 91 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest {
93 public: 92 public:
94 explicit SurfaceAggregatorValidSurfaceTest(bool use_damage_rect) 93 explicit SurfaceAggregatorValidSurfaceTest(bool use_damage_rect)
95 : SurfaceAggregatorTest(use_damage_rect), 94 : SurfaceAggregatorTest(use_damage_rect),
96 child_factory_(kArbitraryChildFrameSinkId, 95 child_factory_(kArbitraryChildFrameSinkId,
97 &manager_, 96 &manager_,
98 &empty_child_client_) {} 97 &empty_child_client_) {}
99 SurfaceAggregatorValidSurfaceTest() 98 SurfaceAggregatorValidSurfaceTest()
100 : SurfaceAggregatorValidSurfaceTest(false) {} 99 : SurfaceAggregatorValidSurfaceTest(false) {}
101 100
102 void SetUp() override { 101 void SetUp() override {
103 SurfaceAggregatorTest::SetUp(); 102 SurfaceAggregatorTest::SetUp();
104 root_local_frame_id_ = allocator_.GenerateId(); 103 root_local_frame_id_ = allocator_.GenerateId();
105 factory_.Create(root_local_frame_id_);
106 root_surface_ = manager_.GetSurfaceForId( 104 root_surface_ = manager_.GetSurfaceForId(
107 SurfaceId(factory_.frame_sink_id(), root_local_frame_id_)); 105 SurfaceId(factory_.frame_sink_id(), root_local_frame_id_));
108 } 106 }
109 107
110 void TearDown() override { 108 void TearDown() override {
111 factory_.Destroy(root_local_frame_id_);
112 SurfaceAggregatorTest::TearDown(); 109 SurfaceAggregatorTest::TearDown();
113 } 110 }
114 111
115 void AggregateAndVerify(test::Pass* expected_passes, 112 void AggregateAndVerify(test::Pass* expected_passes,
116 size_t expected_pass_count, 113 size_t expected_pass_count,
117 SurfaceId* surface_ids, 114 SurfaceId* surface_ids,
118 size_t expected_surface_count) { 115 size_t expected_surface_count) {
119 CompositorFrame aggregated_frame = aggregator_.Aggregate( 116 CompositorFrame aggregated_frame = aggregator_.Aggregate(
120 SurfaceId(factory_.frame_sink_id(), root_local_frame_id_)); 117 SurfaceId(factory_.frame_sink_id(), root_local_frame_id_));
121 118
(...skipping 28 matching lines...) Expand all
150 void SubmitCompositorFrame(SurfaceFactory* factory, 147 void SubmitCompositorFrame(SurfaceFactory* factory,
151 test::Pass* passes, 148 test::Pass* passes,
152 size_t pass_count, 149 size_t pass_count,
153 const LocalFrameId& local_frame_id) { 150 const LocalFrameId& local_frame_id) {
154 RenderPassList pass_list; 151 RenderPassList pass_list;
155 AddPasses(&pass_list, gfx::Rect(SurfaceSize()), passes, pass_count); 152 AddPasses(&pass_list, gfx::Rect(SurfaceSize()), passes, pass_count);
156 SubmitPassListAsFrame(factory, local_frame_id, &pass_list); 153 SubmitPassListAsFrame(factory, local_frame_id, &pass_list);
157 } 154 }
158 155
159 void QueuePassAsFrame(std::unique_ptr<RenderPass> pass, 156 void QueuePassAsFrame(std::unique_ptr<RenderPass> pass,
160 const LocalFrameId& local_frame_id) { 157 const LocalFrameId& local_frame_id,
158 SurfaceFactory& factory) {
161 CompositorFrame child_frame; 159 CompositorFrame child_frame;
162 child_frame.render_pass_list.push_back(std::move(pass)); 160 child_frame.render_pass_list.push_back(std::move(pass));
163 161
164 factory_.SubmitCompositorFrame(local_frame_id, std::move(child_frame), 162 factory.SubmitCompositorFrame(local_frame_id, std::move(child_frame),
165 SurfaceFactory::DrawCallback()); 163 SurfaceFactory::DrawCallback());
166 } 164 }
167 165
168 protected: 166 protected:
169 LocalFrameId root_local_frame_id_; 167 LocalFrameId root_local_frame_id_;
170 Surface* root_surface_; 168 Surface* root_surface_;
171 SurfaceIdAllocator allocator_; 169 SurfaceIdAllocator allocator_;
172 EmptySurfaceFactoryClient empty_child_client_; 170 EmptySurfaceFactoryClient empty_child_client_;
173 SurfaceFactory child_factory_; 171 SurfaceFactory child_factory_;
174 SurfaceIdAllocator child_allocator_; 172 SurfaceIdAllocator child_allocator_;
175 }; 173 };
(...skipping 12 matching lines...) Expand all
188 SurfaceId ids[] = {root_surface_id}; 186 SurfaceId ids[] = {root_surface_id};
189 187
190 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids)); 188 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids));
191 189
192 // Check that WillDrawSurface was called. 190 // Check that WillDrawSurface was called.
193 EXPECT_EQ(gfx::Rect(SurfaceSize()), empty_client_.last_damage_rect_); 191 EXPECT_EQ(gfx::Rect(SurfaceSize()), empty_client_.last_damage_rect_);
194 EXPECT_EQ(root_local_frame_id_, empty_client_.last_local_frame_id_); 192 EXPECT_EQ(root_local_frame_id_, empty_client_.last_local_frame_id_);
195 } 193 }
196 194
197 TEST_F(SurfaceAggregatorValidSurfaceTest, OpacityCopied) { 195 TEST_F(SurfaceAggregatorValidSurfaceTest, OpacityCopied) {
196 SurfaceFactory embedded_factory(kArbitraryFrameSinkId, &manager_,
197 &empty_client_);
198 LocalFrameId embedded_local_frame_id = allocator_.GenerateId(); 198 LocalFrameId embedded_local_frame_id = allocator_.GenerateId();
199 SurfaceId embedded_surface_id(factory_.frame_sink_id(), 199 SurfaceId embedded_surface_id(factory_.frame_sink_id(),
200 embedded_local_frame_id); 200 embedded_local_frame_id);
201 factory_.Create(embedded_local_frame_id);
202 201
203 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN), 202 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
204 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 203 test::Quad::SolidColorQuad(SK_ColorBLUE)};
205 test::Pass embedded_passes[] = { 204 test::Pass embedded_passes[] = {
206 test::Pass(embedded_quads, arraysize(embedded_quads))}; 205 test::Pass(embedded_quads, arraysize(embedded_quads))};
207 206
208 SubmitCompositorFrame(&factory_, embedded_passes, arraysize(embedded_passes), 207 SubmitCompositorFrame(&embedded_factory, embedded_passes,
209 embedded_local_frame_id); 208 arraysize(embedded_passes), embedded_local_frame_id);
210 209
211 test::Quad quads[] = {test::Quad::SurfaceQuad(embedded_surface_id, .5f)}; 210 test::Quad quads[] = {test::Quad::SurfaceQuad(embedded_surface_id, .5f)};
212 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; 211 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
213 212
214 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 213 SubmitCompositorFrame(&factory_, passes, arraysize(passes),
215 root_local_frame_id_); 214 root_local_frame_id_);
216 215
217 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_); 216 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_);
218 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 217 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
219 218
220 RenderPassList& render_pass_list(aggregated_frame.render_pass_list); 219 RenderPassList& render_pass_list(aggregated_frame.render_pass_list);
221 ASSERT_EQ(2u, render_pass_list.size()); 220 ASSERT_EQ(2u, render_pass_list.size());
222 SharedQuadStateList& shared_quad_state_list( 221 SharedQuadStateList& shared_quad_state_list(
223 render_pass_list[0]->shared_quad_state_list); 222 render_pass_list[0]->shared_quad_state_list);
224 ASSERT_EQ(2u, shared_quad_state_list.size()); 223 ASSERT_EQ(2u, shared_quad_state_list.size());
225 EXPECT_EQ(1.f, shared_quad_state_list.ElementAt(0)->opacity); 224 EXPECT_EQ(1.f, shared_quad_state_list.ElementAt(0)->opacity);
226 EXPECT_EQ(1.f, shared_quad_state_list.ElementAt(1)->opacity); 225 EXPECT_EQ(1.f, shared_quad_state_list.ElementAt(1)->opacity);
227 226
228 SharedQuadStateList& shared_quad_state_list2( 227 SharedQuadStateList& shared_quad_state_list2(
229 render_pass_list[1]->shared_quad_state_list); 228 render_pass_list[1]->shared_quad_state_list);
230 ASSERT_EQ(1u, shared_quad_state_list2.size()); 229 ASSERT_EQ(1u, shared_quad_state_list2.size());
231 EXPECT_EQ(.5f, shared_quad_state_list2.ElementAt(0)->opacity); 230 EXPECT_EQ(.5f, shared_quad_state_list2.ElementAt(0)->opacity);
232
233 factory_.Destroy(embedded_local_frame_id);
234 } 231 }
235 232
236 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSimpleFrame) { 233 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSimpleFrame) {
237 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE), 234 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE),
238 test::Quad::SolidColorQuad(SK_ColorLTGRAY)}, 235 test::Quad::SolidColorQuad(SK_ColorLTGRAY)},
239 {test::Quad::SolidColorQuad(SK_ColorGRAY), 236 {test::Quad::SolidColorQuad(SK_ColorGRAY),
240 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}}; 237 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}};
241 test::Pass passes[] = { 238 test::Pass passes[] = {
242 test::Pass(quads[0], arraysize(quads[0]), RenderPassId(1, 1)), 239 test::Pass(quads[0], arraysize(quads[0]), RenderPassId(1, 1)),
243 test::Pass(quads[1], arraysize(quads[1]), RenderPassId(1, 2))}; 240 test::Pass(quads[1], arraysize(quads[1]), RenderPassId(1, 2))};
244 241
245 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 242 SubmitCompositorFrame(&factory_, passes, arraysize(passes),
246 root_local_frame_id_); 243 root_local_frame_id_);
247 244
248 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_); 245 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_);
249 SurfaceId ids[] = {root_surface_id}; 246 SurfaceId ids[] = {root_surface_id};
250 247
251 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids)); 248 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids));
252 } 249 }
253 250
254 // This tests very simple embedding. root_surface has a frame containing a few 251 // This tests very simple embedding. root_surface has a frame containing a few
255 // solid color quads and a surface quad referencing embedded_surface. 252 // solid color quads and a surface quad referencing embedded_surface.
256 // embedded_surface has a frame containing only a solid color quad. The solid 253 // embedded_surface has a frame containing only a solid color quad. The solid
257 // color quad should be aggregated into the final frame. 254 // color quad should be aggregated into the final frame.
258 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleSurfaceReference) { 255 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleSurfaceReference) {
256 SurfaceFactory embedded_factory(kArbitraryFrameSinkId, &manager_,
257 &empty_client_);
259 LocalFrameId embedded_local_frame_id = allocator_.GenerateId(); 258 LocalFrameId embedded_local_frame_id = allocator_.GenerateId();
260 SurfaceId embedded_surface_id(factory_.frame_sink_id(), 259 SurfaceId embedded_surface_id(factory_.frame_sink_id(),
261 embedded_local_frame_id); 260 embedded_local_frame_id);
262 factory_.Create(embedded_local_frame_id);
263 261
264 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 262 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
265 test::Pass embedded_passes[] = { 263 test::Pass embedded_passes[] = {
266 test::Pass(embedded_quads, arraysize(embedded_quads))}; 264 test::Pass(embedded_quads, arraysize(embedded_quads))};
267 265
268 SubmitCompositorFrame(&factory_, embedded_passes, arraysize(embedded_passes), 266 SubmitCompositorFrame(&embedded_factory, embedded_passes,
269 embedded_local_frame_id); 267 arraysize(embedded_passes), embedded_local_frame_id);
270 268
271 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE), 269 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
272 test::Quad::SurfaceQuad(embedded_surface_id, 1.f), 270 test::Quad::SurfaceQuad(embedded_surface_id, 1.f),
273 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 271 test::Quad::SolidColorQuad(SK_ColorBLACK)};
274 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 272 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
275 273
276 SubmitCompositorFrame(&factory_, root_passes, arraysize(root_passes), 274 SubmitCompositorFrame(&factory_, root_passes, arraysize(root_passes),
277 root_local_frame_id_); 275 root_local_frame_id_);
278 276
279 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE), 277 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
280 test::Quad::SolidColorQuad(SK_ColorGREEN), 278 test::Quad::SolidColorQuad(SK_ColorGREEN),
281 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 279 test::Quad::SolidColorQuad(SK_ColorBLACK)};
282 test::Pass expected_passes[] = { 280 test::Pass expected_passes[] = {
283 test::Pass(expected_quads, arraysize(expected_quads))}; 281 test::Pass(expected_quads, arraysize(expected_quads))};
284 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_); 282 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_);
285 SurfaceId ids[] = {root_surface_id, embedded_surface_id}; 283 SurfaceId ids[] = {root_surface_id, embedded_surface_id};
286 AggregateAndVerify( 284 AggregateAndVerify(
287 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 285 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
288
289 factory_.Destroy(embedded_local_frame_id);
290 } 286 }
291 287
292 TEST_F(SurfaceAggregatorValidSurfaceTest, CopyRequest) { 288 TEST_F(SurfaceAggregatorValidSurfaceTest, CopyRequest) {
289 SurfaceFactory embedded_factory(kArbitraryFrameSinkId, &manager_,
290 &empty_client_);
293 LocalFrameId embedded_local_frame_id = allocator_.GenerateId(); 291 LocalFrameId embedded_local_frame_id = allocator_.GenerateId();
294 SurfaceId embedded_surface_id(factory_.frame_sink_id(), 292 SurfaceId embedded_surface_id(factory_.frame_sink_id(),
295 embedded_local_frame_id); 293 embedded_local_frame_id);
296 factory_.Create(embedded_local_frame_id);
297 294
298 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 295 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
299 test::Pass embedded_passes[] = { 296 test::Pass embedded_passes[] = {
300 test::Pass(embedded_quads, arraysize(embedded_quads))}; 297 test::Pass(embedded_quads, arraysize(embedded_quads))};
301 298
302 SubmitCompositorFrame(&factory_, embedded_passes, arraysize(embedded_passes), 299 SubmitCompositorFrame(&embedded_factory, embedded_passes,
303 embedded_local_frame_id); 300 arraysize(embedded_passes), embedded_local_frame_id);
304 std::unique_ptr<CopyOutputRequest> copy_request( 301 std::unique_ptr<CopyOutputRequest> copy_request(
305 CopyOutputRequest::CreateEmptyRequest()); 302 CopyOutputRequest::CreateEmptyRequest());
306 CopyOutputRequest* copy_request_ptr = copy_request.get(); 303 CopyOutputRequest* copy_request_ptr = copy_request.get();
307 factory_.RequestCopyOfSurface(embedded_local_frame_id, 304 embedded_factory.RequestCopyOfSurface(embedded_local_frame_id,
308 std::move(copy_request)); 305 std::move(copy_request));
309 306
310 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE), 307 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
311 test::Quad::SurfaceQuad(embedded_surface_id, 1.f), 308 test::Quad::SurfaceQuad(embedded_surface_id, 1.f),
312 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 309 test::Quad::SolidColorQuad(SK_ColorBLACK)};
313 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 310 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
314 311
315 SubmitCompositorFrame(&factory_, root_passes, arraysize(root_passes), 312 SubmitCompositorFrame(&factory_, root_passes, arraysize(root_passes),
316 root_local_frame_id_); 313 root_local_frame_id_);
317 314
318 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_); 315 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_);
(...skipping 15 matching lines...) Expand all
334 331
335 SurfaceId surface_ids[] = {root_surface_id, embedded_surface_id}; 332 SurfaceId surface_ids[] = {root_surface_id, embedded_surface_id};
336 EXPECT_EQ(arraysize(surface_ids), 333 EXPECT_EQ(arraysize(surface_ids),
337 aggregator_.previous_contained_surfaces().size()); 334 aggregator_.previous_contained_surfaces().size());
338 for (size_t i = 0; i < arraysize(surface_ids); i++) { 335 for (size_t i = 0; i < arraysize(surface_ids); i++) {
339 EXPECT_TRUE( 336 EXPECT_TRUE(
340 aggregator_.previous_contained_surfaces().find(surface_ids[i]) != 337 aggregator_.previous_contained_surfaces().find(surface_ids[i]) !=
341 aggregator_.previous_contained_surfaces().end()); 338 aggregator_.previous_contained_surfaces().end());
342 } 339 }
343 340
344 factory_.Destroy(embedded_local_frame_id);
345 } 341 }
346 342
347 // Root surface may contain copy requests. 343 // Root surface may contain copy requests.
348 TEST_F(SurfaceAggregatorValidSurfaceTest, RootCopyRequest) { 344 TEST_F(SurfaceAggregatorValidSurfaceTest, RootCopyRequest) {
345 SurfaceFactory embedded_factory(kArbitraryFrameSinkId, &manager_,
346 &empty_client_);
349 LocalFrameId embedded_local_frame_id = allocator_.GenerateId(); 347 LocalFrameId embedded_local_frame_id = allocator_.GenerateId();
350 SurfaceId embedded_surface_id(factory_.frame_sink_id(), 348 SurfaceId embedded_surface_id(factory_.frame_sink_id(),
351 embedded_local_frame_id); 349 embedded_local_frame_id);
352 factory_.Create(embedded_local_frame_id);
353 350
354 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 351 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
355 test::Pass embedded_passes[] = { 352 test::Pass embedded_passes[] = {
356 test::Pass(embedded_quads, arraysize(embedded_quads))}; 353 test::Pass(embedded_quads, arraysize(embedded_quads))};
357 354
358 SubmitCompositorFrame(&factory_, embedded_passes, arraysize(embedded_passes), 355 SubmitCompositorFrame(&embedded_factory, embedded_passes,
359 embedded_local_frame_id); 356 arraysize(embedded_passes), embedded_local_frame_id);
360 std::unique_ptr<CopyOutputRequest> copy_request( 357 std::unique_ptr<CopyOutputRequest> copy_request(
361 CopyOutputRequest::CreateEmptyRequest()); 358 CopyOutputRequest::CreateEmptyRequest());
362 CopyOutputRequest* copy_request_ptr = copy_request.get(); 359 CopyOutputRequest* copy_request_ptr = copy_request.get();
363 std::unique_ptr<CopyOutputRequest> copy_request2( 360 std::unique_ptr<CopyOutputRequest> copy_request2(
364 CopyOutputRequest::CreateEmptyRequest()); 361 CopyOutputRequest::CreateEmptyRequest());
365 CopyOutputRequest* copy_request2_ptr = copy_request2.get(); 362 CopyOutputRequest* copy_request2_ptr = copy_request2.get();
366 363
367 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE), 364 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
368 test::Quad::SurfaceQuad(embedded_surface_id, 1.f), 365 test::Quad::SurfaceQuad(embedded_surface_id, 1.f),
369 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 366 test::Quad::SolidColorQuad(SK_ColorBLACK)};
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 aggregator_.previous_contained_surfaces().end()); 408 aggregator_.previous_contained_surfaces().end());
412 } 409 }
413 410
414 // Ensure copy requests have been removed from root surface. 411 // Ensure copy requests have been removed from root surface.
415 const CompositorFrame& original_frame = 412 const CompositorFrame& original_frame =
416 manager_.GetSurfaceForId(root_surface_id)->GetEligibleFrame(); 413 manager_.GetSurfaceForId(root_surface_id)->GetEligibleFrame();
417 const RenderPassList& original_pass_list = original_frame.render_pass_list; 414 const RenderPassList& original_pass_list = original_frame.render_pass_list;
418 ASSERT_EQ(2u, original_pass_list.size()); 415 ASSERT_EQ(2u, original_pass_list.size());
419 DCHECK(original_pass_list[0]->copy_requests.empty()); 416 DCHECK(original_pass_list[0]->copy_requests.empty());
420 DCHECK(original_pass_list[1]->copy_requests.empty()); 417 DCHECK(original_pass_list[1]->copy_requests.empty());
421
422 factory_.Destroy(embedded_local_frame_id);
423 } 418 }
424 419
425 TEST_F(SurfaceAggregatorValidSurfaceTest, UnreferencedSurface) { 420 TEST_F(SurfaceAggregatorValidSurfaceTest, UnreferencedSurface) {
421 SurfaceFactory embedded_factory(kArbitraryFrameSinkId, &manager_,
422 &empty_client_);
426 LocalFrameId embedded_local_frame_id = allocator_.GenerateId(); 423 LocalFrameId embedded_local_frame_id = allocator_.GenerateId();
427 SurfaceId embedded_surface_id(factory_.frame_sink_id(), 424 SurfaceId embedded_surface_id(factory_.frame_sink_id(),
428 embedded_local_frame_id); 425 embedded_local_frame_id);
429 SurfaceId nonexistent_surface_id(factory_.frame_sink_id(), 426 SurfaceId nonexistent_surface_id(factory_.frame_sink_id(),
430 allocator_.GenerateId()); 427 allocator_.GenerateId());
431 factory_.Create(embedded_local_frame_id);
432 428
433 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 429 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
434 test::Pass embedded_passes[] = { 430 test::Pass embedded_passes[] = {
435 test::Pass(embedded_quads, arraysize(embedded_quads))}; 431 test::Pass(embedded_quads, arraysize(embedded_quads))};
436 432
437 SubmitCompositorFrame(&factory_, embedded_passes, arraysize(embedded_passes), 433 SubmitCompositorFrame(&embedded_factory, embedded_passes,
438 embedded_local_frame_id); 434 arraysize(embedded_passes), embedded_local_frame_id);
439 std::unique_ptr<CopyOutputRequest> copy_request( 435 std::unique_ptr<CopyOutputRequest> copy_request(
440 CopyOutputRequest::CreateEmptyRequest()); 436 CopyOutputRequest::CreateEmptyRequest());
441 CopyOutputRequest* copy_request_ptr = copy_request.get(); 437 CopyOutputRequest* copy_request_ptr = copy_request.get();
442 factory_.RequestCopyOfSurface(embedded_local_frame_id, 438 embedded_factory.RequestCopyOfSurface(embedded_local_frame_id,
443 std::move(copy_request)); 439 std::move(copy_request));
444 440
445 LocalFrameId parent_local_frame_id = allocator_.GenerateId(); 441 LocalFrameId parent_local_frame_id = allocator_.GenerateId();
442 SurfaceFactory parent_factory(kArbitraryFrameSinkId, &manager_,
443 &empty_client_);
446 SurfaceId parent_surface_id(factory_.frame_sink_id(), parent_local_frame_id); 444 SurfaceId parent_surface_id(factory_.frame_sink_id(), parent_local_frame_id);
447 factory_.Create(parent_local_frame_id);
448 445
449 test::Quad parent_quads[] = { 446 test::Quad parent_quads[] = {
450 test::Quad::SolidColorQuad(SK_ColorWHITE), 447 test::Quad::SolidColorQuad(SK_ColorWHITE),
451 test::Quad::SurfaceQuad(embedded_surface_id, 1.f), 448 test::Quad::SurfaceQuad(embedded_surface_id, 1.f),
452 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 449 test::Quad::SolidColorQuad(SK_ColorBLACK)};
453 test::Pass parent_passes[] = { 450 test::Pass parent_passes[] = {
454 test::Pass(parent_quads, arraysize(parent_quads))}; 451 test::Pass(parent_quads, arraysize(parent_quads))};
455 452
456 { 453 {
457 CompositorFrame frame; 454 CompositorFrame frame;
458 455
459 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), parent_passes, 456 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), parent_passes,
460 arraysize(parent_passes)); 457 arraysize(parent_passes));
461 458
462 frame.metadata.referenced_surfaces.push_back(embedded_surface_id); 459 frame.metadata.referenced_surfaces.push_back(embedded_surface_id);
463 460
464 factory_.SubmitCompositorFrame(parent_local_frame_id, std::move(frame), 461 parent_factory.SubmitCompositorFrame(parent_local_frame_id,
465 SurfaceFactory::DrawCallback()); 462 std::move(frame),
463 SurfaceFactory::DrawCallback());
466 } 464 }
467 465
468 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE), 466 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
469 test::Quad::SolidColorQuad(SK_ColorBLACK)}; 467 test::Quad::SolidColorQuad(SK_ColorBLACK)};
470 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 468 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
471 469
472 { 470 {
473 CompositorFrame frame; 471 CompositorFrame frame;
474 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes, 472 AddPasses(&frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes,
475 arraysize(root_passes)); 473 arraysize(root_passes));
(...skipping 27 matching lines...) Expand all
503 SurfaceId surface_ids[] = { 501 SurfaceId surface_ids[] = {
504 SurfaceId(factory_.frame_sink_id(), root_local_frame_id_), 502 SurfaceId(factory_.frame_sink_id(), root_local_frame_id_),
505 parent_surface_id, embedded_surface_id, nonexistent_surface_id}; 503 parent_surface_id, embedded_surface_id, nonexistent_surface_id};
506 EXPECT_EQ(arraysize(surface_ids), 504 EXPECT_EQ(arraysize(surface_ids),
507 aggregator_.previous_contained_surfaces().size()); 505 aggregator_.previous_contained_surfaces().size());
508 for (size_t i = 0; i < arraysize(surface_ids); i++) { 506 for (size_t i = 0; i < arraysize(surface_ids); i++) {
509 EXPECT_TRUE( 507 EXPECT_TRUE(
510 aggregator_.previous_contained_surfaces().find(surface_ids[i]) != 508 aggregator_.previous_contained_surfaces().find(surface_ids[i]) !=
511 aggregator_.previous_contained_surfaces().end()); 509 aggregator_.previous_contained_surfaces().end());
512 } 510 }
513
514 factory_.Destroy(parent_local_frame_id);
515 factory_.Destroy(embedded_local_frame_id);
516 } 511 }
517 512
518 // This tests referencing a surface that has multiple render passes. 513 // This tests referencing a surface that has multiple render passes.
519 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) { 514 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) {
520 LocalFrameId embedded_local_frame_id = child_allocator_.GenerateId(); 515 LocalFrameId embedded_local_frame_id = child_allocator_.GenerateId();
521 SurfaceId embedded_surface_id(child_factory_.frame_sink_id(), 516 SurfaceId embedded_surface_id(child_factory_.frame_sink_id(),
522 embedded_local_frame_id); 517 embedded_local_frame_id);
523 child_factory_.Create(embedded_local_frame_id);
524 518
525 RenderPassId pass_ids[] = {RenderPassId(1, 1), RenderPassId(1, 2), 519 RenderPassId pass_ids[] = {RenderPassId(1, 1), RenderPassId(1, 2),
526 RenderPassId(1, 3)}; 520 RenderPassId(1, 3)};
527 521
528 test::Quad embedded_quads[][2] = { 522 test::Quad embedded_quads[][2] = {
529 {test::Quad::SolidColorQuad(1), test::Quad::SolidColorQuad(2)}, 523 {test::Quad::SolidColorQuad(1), test::Quad::SolidColorQuad(2)},
530 {test::Quad::SolidColorQuad(3), test::Quad::RenderPassQuad(pass_ids[0])}, 524 {test::Quad::SolidColorQuad(3), test::Quad::RenderPassQuad(pass_ids[0])},
531 {test::Quad::SolidColorQuad(4), test::Quad::RenderPassQuad(pass_ids[1])}}; 525 {test::Quad::SolidColorQuad(4), test::Quad::RenderPassQuad(pass_ids[1])}};
532 test::Pass embedded_passes[] = { 526 test::Pass embedded_passes[] = {
533 test::Pass(embedded_quads[0], arraysize(embedded_quads[0]), pass_ids[0]), 527 test::Pass(embedded_quads[0], arraysize(embedded_quads[0]), pass_ids[0]),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 // The last quad in the last pass will reference the second pass from the 638 // The last quad in the last pass will reference the second pass from the
645 // root surface, which after aggregating is the fourth pass in the overall 639 // root surface, which after aggregating is the fourth pass in the overall
646 // list. 640 // list.
647 ASSERT_EQ(DrawQuad::RENDER_PASS, 641 ASSERT_EQ(DrawQuad::RENDER_PASS,
648 fifth_pass_quad_list.ElementAt(1)->material); 642 fifth_pass_quad_list.ElementAt(1)->material);
649 const RenderPassDrawQuad* fifth_pass_render_pass_draw_quad = 643 const RenderPassDrawQuad* fifth_pass_render_pass_draw_quad =
650 RenderPassDrawQuad::MaterialCast(fifth_pass_quad_list.ElementAt(1)); 644 RenderPassDrawQuad::MaterialCast(fifth_pass_quad_list.ElementAt(1));
651 EXPECT_EQ(actual_pass_ids[3], 645 EXPECT_EQ(actual_pass_ids[3],
652 fifth_pass_render_pass_draw_quad->render_pass_id); 646 fifth_pass_render_pass_draw_quad->render_pass_id);
653 } 647 }
654 child_factory_.Destroy(embedded_local_frame_id);
655 } 648 }
656 649
657 // Tests an invalid surface reference in a frame. The surface quad should just 650 // Tests an invalid surface reference in a frame. The surface quad should just
658 // be dropped. 651 // be dropped.
659 TEST_F(SurfaceAggregatorValidSurfaceTest, InvalidSurfaceReference) { 652 TEST_F(SurfaceAggregatorValidSurfaceTest, InvalidSurfaceReference) {
660 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN), 653 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
661 test::Quad::SurfaceQuad(InvalidSurfaceId(), 1.f), 654 test::Quad::SurfaceQuad(InvalidSurfaceId(), 1.f),
662 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 655 test::Quad::SolidColorQuad(SK_ColorBLUE)};
663 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; 656 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
664 657
(...skipping 10 matching lines...) Expand all
675 AggregateAndVerify( 668 AggregateAndVerify(
676 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 669 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
677 } 670 }
678 671
679 // Tests a reference to a valid surface with no submitted frame. This quad 672 // Tests a reference to a valid surface with no submitted frame. This quad
680 // should also just be dropped. 673 // should also just be dropped.
681 TEST_F(SurfaceAggregatorValidSurfaceTest, ValidSurfaceReferenceWithNoFrame) { 674 TEST_F(SurfaceAggregatorValidSurfaceTest, ValidSurfaceReferenceWithNoFrame) {
682 LocalFrameId empty_local_frame_id = allocator_.GenerateId(); 675 LocalFrameId empty_local_frame_id = allocator_.GenerateId();
683 SurfaceId surface_with_no_frame_id(factory_.frame_sink_id(), 676 SurfaceId surface_with_no_frame_id(factory_.frame_sink_id(),
684 empty_local_frame_id); 677 empty_local_frame_id);
685 factory_.Create(empty_local_frame_id);
686 678
687 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN), 679 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
688 test::Quad::SurfaceQuad(surface_with_no_frame_id, 1.f), 680 test::Quad::SurfaceQuad(surface_with_no_frame_id, 1.f),
689 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 681 test::Quad::SolidColorQuad(SK_ColorBLUE)};
690 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; 682 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
691 683
692 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 684 SubmitCompositorFrame(&factory_, passes, arraysize(passes),
693 root_local_frame_id_); 685 root_local_frame_id_);
694 686
695 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN), 687 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
696 test::Quad::SolidColorQuad(SK_ColorBLUE)}; 688 test::Quad::SolidColorQuad(SK_ColorBLUE)};
697 test::Pass expected_passes[] = { 689 test::Pass expected_passes[] = {
698 test::Pass(expected_quads, arraysize(expected_quads))}; 690 test::Pass(expected_quads, arraysize(expected_quads))};
699 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_); 691 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_);
700 SurfaceId ids[] = {root_surface_id, surface_with_no_frame_id}; 692 SurfaceId ids[] = {root_surface_id, surface_with_no_frame_id};
701 AggregateAndVerify( 693 AggregateAndVerify(
702 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 694 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
703 factory_.Destroy(empty_local_frame_id);
704 } 695 }
705 696
706 // Tests a surface quad referencing itself, generating a trivial cycle. 697 // Tests a surface quad referencing itself, generating a trivial cycle.
707 // The quad creating the cycle should be dropped from the final frame. 698 // The quad creating the cycle should be dropped from the final frame.
708 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleCyclicalReference) { 699 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleCyclicalReference) {
709 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_); 700 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_);
710 test::Quad quads[] = {test::Quad::SurfaceQuad(root_surface_id, 1.f), 701 test::Quad quads[] = {test::Quad::SurfaceQuad(root_surface_id, 1.f),
711 test::Quad::SolidColorQuad(SK_ColorYELLOW)}; 702 test::Quad::SolidColorQuad(SK_ColorYELLOW)};
712 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; 703 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
713 704
714 SubmitCompositorFrame(&factory_, passes, arraysize(passes), 705 SubmitCompositorFrame(&factory_, passes, arraysize(passes),
715 root_local_frame_id_); 706 root_local_frame_id_);
716 707
717 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorYELLOW)}; 708 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorYELLOW)};
718 test::Pass expected_passes[] = { 709 test::Pass expected_passes[] = {
719 test::Pass(expected_quads, arraysize(expected_quads))}; 710 test::Pass(expected_quads, arraysize(expected_quads))};
720 SurfaceId ids[] = {root_surface_id}; 711 SurfaceId ids[] = {root_surface_id};
721 AggregateAndVerify( 712 AggregateAndVerify(
722 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 713 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
723 } 714 }
724 715
725 // Tests a more complex cycle with one intermediate surface. 716 // Tests a more complex cycle with one intermediate surface.
726 TEST_F(SurfaceAggregatorValidSurfaceTest, TwoSurfaceCyclicalReference) { 717 TEST_F(SurfaceAggregatorValidSurfaceTest, TwoSurfaceCyclicalReference) {
718 SurfaceFactory child_factory(kArbitraryFrameSinkId, &manager_,
719 &empty_client_);
727 LocalFrameId child_local_frame_id = allocator_.GenerateId(); 720 LocalFrameId child_local_frame_id = allocator_.GenerateId();
728 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id); 721 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id);
729 factory_.Create(child_local_frame_id);
730 722
731 test::Quad parent_quads[] = {test::Quad::SolidColorQuad(SK_ColorBLUE), 723 test::Quad parent_quads[] = {test::Quad::SolidColorQuad(SK_ColorBLUE),
732 test::Quad::SurfaceQuad(child_surface_id, 1.f), 724 test::Quad::SurfaceQuad(child_surface_id, 1.f),
733 test::Quad::SolidColorQuad(SK_ColorCYAN)}; 725 test::Quad::SolidColorQuad(SK_ColorCYAN)};
734 test::Pass parent_passes[] = { 726 test::Pass parent_passes[] = {
735 test::Pass(parent_quads, arraysize(parent_quads))}; 727 test::Pass(parent_quads, arraysize(parent_quads))};
736 728
737 SubmitCompositorFrame(&factory_, parent_passes, arraysize(parent_passes), 729 SubmitCompositorFrame(&factory_, parent_passes, arraysize(parent_passes),
738 root_local_frame_id_); 730 root_local_frame_id_);
739 731
740 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_); 732 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_);
741 test::Quad child_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN), 733 test::Quad child_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
742 test::Quad::SurfaceQuad(root_surface_id, 1.f), 734 test::Quad::SurfaceQuad(root_surface_id, 1.f),
743 test::Quad::SolidColorQuad(SK_ColorMAGENTA)}; 735 test::Quad::SolidColorQuad(SK_ColorMAGENTA)};
744 test::Pass child_passes[] = {test::Pass(child_quads, arraysize(child_quads))}; 736 test::Pass child_passes[] = {test::Pass(child_quads, arraysize(child_quads))};
745 737
746 SubmitCompositorFrame(&factory_, child_passes, arraysize(child_passes), 738 SubmitCompositorFrame(&child_factory, child_passes, arraysize(child_passes),
747 child_local_frame_id); 739 child_local_frame_id);
748 740
749 // The child surface's reference to the root_surface_ will be dropped, so 741 // The child surface's reference to the root_surface_ will be dropped, so
750 // we'll end up with: 742 // we'll end up with:
751 // SK_ColorBLUE from the parent 743 // SK_ColorBLUE from the parent
752 // SK_ColorGREEN from the child 744 // SK_ColorGREEN from the child
753 // SK_ColorMAGENTA from the child 745 // SK_ColorMAGENTA from the child
754 // SK_ColorCYAN from the parent 746 // SK_ColorCYAN from the parent
755 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorBLUE), 747 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorBLUE),
756 test::Quad::SolidColorQuad(SK_ColorGREEN), 748 test::Quad::SolidColorQuad(SK_ColorGREEN),
757 test::Quad::SolidColorQuad(SK_ColorMAGENTA), 749 test::Quad::SolidColorQuad(SK_ColorMAGENTA),
758 test::Quad::SolidColorQuad(SK_ColorCYAN)}; 750 test::Quad::SolidColorQuad(SK_ColorCYAN)};
759 test::Pass expected_passes[] = { 751 test::Pass expected_passes[] = {
760 test::Pass(expected_quads, arraysize(expected_quads))}; 752 test::Pass(expected_quads, arraysize(expected_quads))};
761 SurfaceId ids[] = {root_surface_id, child_surface_id}; 753 SurfaceId ids[] = {root_surface_id, child_surface_id};
762 AggregateAndVerify( 754 AggregateAndVerify(
763 expected_passes, arraysize(expected_passes), ids, arraysize(ids)); 755 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
764 factory_.Destroy(child_local_frame_id);
765 } 756 }
766 757
767 // Tests that we map render pass IDs from different surfaces into a unified 758 // Tests that we map render pass IDs from different surfaces into a unified
768 // namespace and update RenderPassDrawQuad's id references to match. 759 // namespace and update RenderPassDrawQuad's id references to match.
769 TEST_F(SurfaceAggregatorValidSurfaceTest, RenderPassIdMapping) { 760 TEST_F(SurfaceAggregatorValidSurfaceTest, RenderPassIdMapping) {
761 SurfaceFactory child_factory(kArbitraryFrameSinkId, &manager_,
762 &empty_client_);
770 LocalFrameId child_local_frame_id = allocator_.GenerateId(); 763 LocalFrameId child_local_frame_id = allocator_.GenerateId();
771 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id); 764 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id);
772 factory_.Create(child_local_frame_id);
773 765
774 RenderPassId child_pass_id[] = {RenderPassId(1, 1), RenderPassId(1, 2)}; 766 RenderPassId child_pass_id[] = {RenderPassId(1, 1), RenderPassId(1, 2)};
775 test::Quad child_quad[][1] = {{test::Quad::SolidColorQuad(SK_ColorGREEN)}, 767 test::Quad child_quad[][1] = {{test::Quad::SolidColorQuad(SK_ColorGREEN)},
776 {test::Quad::RenderPassQuad(child_pass_id[0])}}; 768 {test::Quad::RenderPassQuad(child_pass_id[0])}};
777 test::Pass surface_passes[] = { 769 test::Pass surface_passes[] = {
778 test::Pass(child_quad[0], arraysize(child_quad[0]), child_pass_id[0]), 770 test::Pass(child_quad[0], arraysize(child_quad[0]), child_pass_id[0]),
779 test::Pass(child_quad[1], arraysize(child_quad[1]), child_pass_id[1])}; 771 test::Pass(child_quad[1], arraysize(child_quad[1]), child_pass_id[1])};
780 772
781 SubmitCompositorFrame(&factory_, surface_passes, arraysize(surface_passes), 773 SubmitCompositorFrame(&child_factory, surface_passes,
782 child_local_frame_id); 774 arraysize(surface_passes), child_local_frame_id);
783 775
784 // Pass IDs from the parent surface may collide with ones from the child. 776 // Pass IDs from the parent surface may collide with ones from the child.
785 RenderPassId parent_pass_id[] = {RenderPassId(2, 1), RenderPassId(1, 2)}; 777 RenderPassId parent_pass_id[] = {RenderPassId(2, 1), RenderPassId(1, 2)};
786 test::Quad parent_quad[][1] = { 778 test::Quad parent_quad[][1] = {
787 {test::Quad::SurfaceQuad(child_surface_id, 1.f)}, 779 {test::Quad::SurfaceQuad(child_surface_id, 1.f)},
788 {test::Quad::RenderPassQuad(parent_pass_id[0])}}; 780 {test::Quad::RenderPassQuad(parent_pass_id[0])}};
789 test::Pass parent_passes[] = { 781 test::Pass parent_passes[] = {
790 test::Pass(parent_quad[0], arraysize(parent_quad[0]), parent_pass_id[0]), 782 test::Pass(parent_quad[0], arraysize(parent_quad[0]), parent_pass_id[0]),
791 test::Pass(parent_quad[1], arraysize(parent_quad[1]), parent_pass_id[1])}; 783 test::Pass(parent_quad[1], arraysize(parent_quad[1]), parent_pass_id[1])};
792 784
(...skipping 23 matching lines...) Expand all
816 aggregated_pass_list[2]->quad_list.front()}; 808 aggregated_pass_list[2]->quad_list.front()};
817 ASSERT_EQ(render_pass_quads[0]->material, DrawQuad::RENDER_PASS); 809 ASSERT_EQ(render_pass_quads[0]->material, DrawQuad::RENDER_PASS);
818 EXPECT_EQ( 810 EXPECT_EQ(
819 actual_pass_ids[0], 811 actual_pass_ids[0],
820 RenderPassDrawQuad::MaterialCast(render_pass_quads[0])->render_pass_id); 812 RenderPassDrawQuad::MaterialCast(render_pass_quads[0])->render_pass_id);
821 813
822 ASSERT_EQ(render_pass_quads[1]->material, DrawQuad::RENDER_PASS); 814 ASSERT_EQ(render_pass_quads[1]->material, DrawQuad::RENDER_PASS);
823 EXPECT_EQ( 815 EXPECT_EQ(
824 actual_pass_ids[1], 816 actual_pass_ids[1],
825 RenderPassDrawQuad::MaterialCast(render_pass_quads[1])->render_pass_id); 817 RenderPassDrawQuad::MaterialCast(render_pass_quads[1])->render_pass_id);
826 factory_.Destroy(child_local_frame_id);
827 } 818 }
828 819
829 void AddSolidColorQuadWithBlendMode(const gfx::Size& size, 820 void AddSolidColorQuadWithBlendMode(const gfx::Size& size,
830 RenderPass* pass, 821 RenderPass* pass,
831 const SkXfermode::Mode blend_mode) { 822 const SkXfermode::Mode blend_mode) {
832 const gfx::Transform layer_to_target_transform; 823 const gfx::Transform layer_to_target_transform;
833 const gfx::Size layer_bounds(size); 824 const gfx::Size layer_bounds(size);
834 const gfx::Rect visible_layer_rect(size); 825 const gfx::Rect visible_layer_rect(size);
835 const gfx::Rect clip_rect(size); 826 const gfx::Rect clip_rect(size);
836 827
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateSharedQuadStateProperties) { 870 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateSharedQuadStateProperties) {
880 const SkXfermode::Mode blend_modes[] = {SkXfermode::kClear_Mode, // 0 871 const SkXfermode::Mode blend_modes[] = {SkXfermode::kClear_Mode, // 0
881 SkXfermode::kSrc_Mode, // 1 872 SkXfermode::kSrc_Mode, // 1
882 SkXfermode::kDst_Mode, // 2 873 SkXfermode::kDst_Mode, // 2
883 SkXfermode::kSrcOver_Mode, // 3 874 SkXfermode::kSrcOver_Mode, // 3
884 SkXfermode::kDstOver_Mode, // 4 875 SkXfermode::kDstOver_Mode, // 4
885 SkXfermode::kSrcIn_Mode, // 5 876 SkXfermode::kSrcIn_Mode, // 5
886 SkXfermode::kDstIn_Mode, // 6 877 SkXfermode::kDstIn_Mode, // 6
887 }; 878 };
888 879
880 SurfaceFactory grandchild_factory(kArbitraryFrameSinkId, &manager_,
881 &empty_client_);
882 SurfaceFactory child_one_factory(kArbitraryFrameSinkId, &manager_,
883 &empty_client_);
884 SurfaceFactory child_two_factory(kArbitraryFrameSinkId, &manager_,
885 &empty_client_);
889 RenderPassId pass_id(1, 1); 886 RenderPassId pass_id(1, 1);
890 LocalFrameId grandchild_local_frame_id = allocator_.GenerateId(); 887 LocalFrameId grandchild_local_frame_id = allocator_.GenerateId();
891 SurfaceId grandchild_surface_id(factory_.frame_sink_id(), 888 SurfaceId grandchild_surface_id(factory_.frame_sink_id(),
892 grandchild_local_frame_id); 889 grandchild_local_frame_id);
893 factory_.Create(grandchild_local_frame_id); 890 grandchild_factory.SubmitCompositorFrame(grandchild_local_frame_id,
891 CompositorFrame(),
892 SurfaceFactory::DrawCallback());
894 std::unique_ptr<RenderPass> grandchild_pass = RenderPass::Create(); 893 std::unique_ptr<RenderPass> grandchild_pass = RenderPass::Create();
895 gfx::Rect output_rect(SurfaceSize()); 894 gfx::Rect output_rect(SurfaceSize());
896 gfx::Rect damage_rect(SurfaceSize()); 895 gfx::Rect damage_rect(SurfaceSize());
897 gfx::Transform transform_to_root_target; 896 gfx::Transform transform_to_root_target;
898 grandchild_pass->SetNew( 897 grandchild_pass->SetNew(
899 pass_id, output_rect, damage_rect, transform_to_root_target); 898 pass_id, output_rect, damage_rect, transform_to_root_target);
900 AddSolidColorQuadWithBlendMode( 899 AddSolidColorQuadWithBlendMode(
901 SurfaceSize(), grandchild_pass.get(), blend_modes[2]); 900 SurfaceSize(), grandchild_pass.get(), blend_modes[2]);
902 QueuePassAsFrame(std::move(grandchild_pass), grandchild_local_frame_id); 901 QueuePassAsFrame(std::move(grandchild_pass), grandchild_local_frame_id,
902 grandchild_factory);
903 903
904 LocalFrameId child_one_local_frame_id = allocator_.GenerateId(); 904 LocalFrameId child_one_local_frame_id = allocator_.GenerateId();
905 SurfaceId child_one_surface_id(factory_.frame_sink_id(), 905 SurfaceId child_one_surface_id(factory_.frame_sink_id(),
906 child_one_local_frame_id); 906 child_one_local_frame_id);
907 factory_.Create(child_one_local_frame_id); 907 child_one_factory.SubmitCompositorFrame(child_one_local_frame_id,
908 CompositorFrame(),
909 SurfaceFactory::DrawCallback());
908 910
909 std::unique_ptr<RenderPass> child_one_pass = RenderPass::Create(); 911 std::unique_ptr<RenderPass> child_one_pass = RenderPass::Create();
910 child_one_pass->SetNew( 912 child_one_pass->SetNew(
911 pass_id, output_rect, damage_rect, transform_to_root_target); 913 pass_id, output_rect, damage_rect, transform_to_root_target);
912 AddSolidColorQuadWithBlendMode( 914 AddSolidColorQuadWithBlendMode(
913 SurfaceSize(), child_one_pass.get(), blend_modes[1]); 915 SurfaceSize(), child_one_pass.get(), blend_modes[1]);
914 SurfaceDrawQuad* grandchild_surface_quad = 916 SurfaceDrawQuad* grandchild_surface_quad =
915 child_one_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 917 child_one_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
916 grandchild_surface_quad->SetNew(child_one_pass->shared_quad_state_list.back(), 918 grandchild_surface_quad->SetNew(child_one_pass->shared_quad_state_list.back(),
917 gfx::Rect(SurfaceSize()), 919 gfx::Rect(SurfaceSize()),
918 gfx::Rect(SurfaceSize()), 920 gfx::Rect(SurfaceSize()),
919 grandchild_surface_id); 921 grandchild_surface_id);
920 AddSolidColorQuadWithBlendMode( 922 AddSolidColorQuadWithBlendMode(
921 SurfaceSize(), child_one_pass.get(), blend_modes[3]); 923 SurfaceSize(), child_one_pass.get(), blend_modes[3]);
922 QueuePassAsFrame(std::move(child_one_pass), child_one_local_frame_id); 924 QueuePassAsFrame(std::move(child_one_pass), child_one_local_frame_id,
925 child_one_factory);
923 926
924 LocalFrameId child_two_local_frame_id = allocator_.GenerateId(); 927 LocalFrameId child_two_local_frame_id = allocator_.GenerateId();
925 SurfaceId child_two_surface_id(factory_.frame_sink_id(), 928 SurfaceId child_two_surface_id(factory_.frame_sink_id(),
926 child_two_local_frame_id); 929 child_two_local_frame_id);
927 factory_.Create(child_two_local_frame_id); 930 child_two_factory.SubmitCompositorFrame(child_two_local_frame_id,
931 CompositorFrame(),
932 SurfaceFactory::DrawCallback());
928 933
929 std::unique_ptr<RenderPass> child_two_pass = RenderPass::Create(); 934 std::unique_ptr<RenderPass> child_two_pass = RenderPass::Create();
930 child_two_pass->SetNew( 935 child_two_pass->SetNew(
931 pass_id, output_rect, damage_rect, transform_to_root_target); 936 pass_id, output_rect, damage_rect, transform_to_root_target);
932 AddSolidColorQuadWithBlendMode( 937 AddSolidColorQuadWithBlendMode(
933 SurfaceSize(), child_two_pass.get(), blend_modes[5]); 938 SurfaceSize(), child_two_pass.get(), blend_modes[5]);
934 QueuePassAsFrame(std::move(child_two_pass), child_two_local_frame_id); 939 QueuePassAsFrame(std::move(child_two_pass), child_two_local_frame_id,
940 child_two_factory);
935 941
936 std::unique_ptr<RenderPass> root_pass = RenderPass::Create(); 942 std::unique_ptr<RenderPass> root_pass = RenderPass::Create();
937 root_pass->SetNew( 943 root_pass->SetNew(
938 pass_id, output_rect, damage_rect, transform_to_root_target); 944 pass_id, output_rect, damage_rect, transform_to_root_target);
939 945
940 AddSolidColorQuadWithBlendMode( 946 AddSolidColorQuadWithBlendMode(
941 SurfaceSize(), root_pass.get(), blend_modes[0]); 947 SurfaceSize(), root_pass.get(), blend_modes[0]);
942 SurfaceDrawQuad* child_one_surface_quad = 948 SurfaceDrawQuad* child_one_surface_quad =
943 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 949 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
944 child_one_surface_quad->SetNew(root_pass->shared_quad_state_list.back(), 950 child_one_surface_quad->SetNew(root_pass->shared_quad_state_list.back(),
945 gfx::Rect(SurfaceSize()), 951 gfx::Rect(SurfaceSize()),
946 gfx::Rect(SurfaceSize()), 952 gfx::Rect(SurfaceSize()),
947 child_one_surface_id); 953 child_one_surface_id);
948 AddSolidColorQuadWithBlendMode( 954 AddSolidColorQuadWithBlendMode(
949 SurfaceSize(), root_pass.get(), blend_modes[4]); 955 SurfaceSize(), root_pass.get(), blend_modes[4]);
950 SurfaceDrawQuad* child_two_surface_quad = 956 SurfaceDrawQuad* child_two_surface_quad =
951 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 957 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
952 child_two_surface_quad->SetNew(root_pass->shared_quad_state_list.back(), 958 child_two_surface_quad->SetNew(root_pass->shared_quad_state_list.back(),
953 gfx::Rect(SurfaceSize()), 959 gfx::Rect(SurfaceSize()),
954 gfx::Rect(SurfaceSize()), 960 gfx::Rect(SurfaceSize()),
955 child_two_surface_id); 961 child_two_surface_id);
956 AddSolidColorQuadWithBlendMode( 962 AddSolidColorQuadWithBlendMode(
957 SurfaceSize(), root_pass.get(), blend_modes[6]); 963 SurfaceSize(), root_pass.get(), blend_modes[6]);
958 964
959 QueuePassAsFrame(std::move(root_pass), root_local_frame_id_); 965 QueuePassAsFrame(std::move(root_pass), root_local_frame_id_, factory_);
960 966
961 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_); 967 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_);
962 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 968 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
963 969
964 const RenderPassList& aggregated_pass_list = 970 const RenderPassList& aggregated_pass_list =
965 aggregated_frame.render_pass_list; 971 aggregated_frame.render_pass_list;
966 972
967 ASSERT_EQ(1u, aggregated_pass_list.size()); 973 ASSERT_EQ(1u, aggregated_pass_list.size());
968 974
969 const QuadList& aggregated_quad_list = aggregated_pass_list[0]->quad_list; 975 const QuadList& aggregated_quad_list = aggregated_pass_list[0]->quad_list;
970 976
971 ASSERT_EQ(7u, aggregated_quad_list.size()); 977 ASSERT_EQ(7u, aggregated_quad_list.size());
972 978
973 for (auto iter = aggregated_quad_list.cbegin(); 979 for (auto iter = aggregated_quad_list.cbegin();
974 iter != aggregated_quad_list.cend(); 980 iter != aggregated_quad_list.cend();
975 ++iter) { 981 ++iter) {
976 EXPECT_EQ(blend_modes[iter.index()], iter->shared_quad_state->blend_mode) 982 EXPECT_EQ(blend_modes[iter.index()], iter->shared_quad_state->blend_mode)
977 << iter.index(); 983 << iter.index();
978 } 984 }
979 factory_.Destroy(child_one_local_frame_id);
980 factory_.Destroy(child_two_local_frame_id);
981 factory_.Destroy(grandchild_local_frame_id);
982 } 985 }
983 986
984 // This tests that when aggregating a frame with multiple render passes that we 987 // This tests that when aggregating a frame with multiple render passes that we
985 // map the transforms for the root pass but do not modify the transform on child 988 // map the transforms for the root pass but do not modify the transform on child
986 // passes. 989 // passes.
987 // 990 //
988 // The root surface has one pass with a surface quad transformed by +10 in the y 991 // The root surface has one pass with a surface quad transformed by +10 in the y
989 // direction. 992 // direction.
990 // 993 //
991 // The middle surface has one pass with a surface quad scaled by 2 in the x 994 // The middle surface has one pass with a surface quad scaled by 2 in the x
992 // and 3 in the y directions. 995 // and 3 in the y directions.
993 // 996 //
994 // The child surface has two passes. The first pass has a quad with a transform 997 // The child surface has two passes. The first pass has a quad with a transform
995 // of +5 in the x direction. The second pass has a reference to the first pass' 998 // of +5 in the x direction. The second pass has a reference to the first pass'
996 // pass id and a transform of +8 in the x direction. 999 // pass id and a transform of +8 in the x direction.
997 // 1000 //
998 // After aggregation, the child surface's root pass quad should have all 1001 // After aggregation, the child surface's root pass quad should have all
999 // transforms concatenated for a total transform of +23 x, +10 y. The 1002 // transforms concatenated for a total transform of +23 x, +10 y. The
1000 // contributing render pass' transform in the aggregate frame should not be 1003 // contributing render pass' transform in the aggregate frame should not be
1001 // affected. 1004 // affected.
1002 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateMultiplePassWithTransform) { 1005 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateMultiplePassWithTransform) {
1003 // Innermost child surface. 1006 // Innermost child surface.
1007 SurfaceFactory child_factory(kArbitraryFrameSinkId, &manager_,
1008 &empty_client_);
1004 LocalFrameId child_local_frame_id = allocator_.GenerateId(); 1009 LocalFrameId child_local_frame_id = allocator_.GenerateId();
1005 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id); 1010 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id);
1006 factory_.Create(child_local_frame_id);
1007 { 1011 {
1008 RenderPassId child_pass_id[] = {RenderPassId(1, 1), RenderPassId(1, 2)}; 1012 RenderPassId child_pass_id[] = {RenderPassId(1, 1), RenderPassId(1, 2)};
1009 test::Quad child_quads[][1] = { 1013 test::Quad child_quads[][1] = {
1010 {test::Quad::SolidColorQuad(SK_ColorGREEN)}, 1014 {test::Quad::SolidColorQuad(SK_ColorGREEN)},
1011 {test::Quad::RenderPassQuad(child_pass_id[0])}, 1015 {test::Quad::RenderPassQuad(child_pass_id[0])},
1012 }; 1016 };
1013 test::Pass child_passes[] = { 1017 test::Pass child_passes[] = {
1014 test::Pass(child_quads[0], arraysize(child_quads[0]), child_pass_id[0]), 1018 test::Pass(child_quads[0], arraysize(child_quads[0]), child_pass_id[0]),
1015 test::Pass(child_quads[1], arraysize(child_quads[1]), 1019 test::Pass(child_quads[1], arraysize(child_quads[1]),
1016 child_pass_id[1])}; 1020 child_pass_id[1])};
1017 1021
1018 CompositorFrame child_frame; 1022 CompositorFrame child_frame;
1019 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1023 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1020 child_passes, arraysize(child_passes)); 1024 child_passes, arraysize(child_passes));
1021 1025
1022 RenderPass* child_nonroot_pass = child_frame.render_pass_list[0].get(); 1026 RenderPass* child_nonroot_pass = child_frame.render_pass_list[0].get();
1023 child_nonroot_pass->transform_to_root_target.Translate(8, 0); 1027 child_nonroot_pass->transform_to_root_target.Translate(8, 0);
1024 SharedQuadState* child_nonroot_pass_sqs = 1028 SharedQuadState* child_nonroot_pass_sqs =
1025 child_nonroot_pass->shared_quad_state_list.front(); 1029 child_nonroot_pass->shared_quad_state_list.front();
1026 child_nonroot_pass_sqs->quad_to_target_transform.Translate(5, 0); 1030 child_nonroot_pass_sqs->quad_to_target_transform.Translate(5, 0);
1027 1031
1028 RenderPass* child_root_pass = child_frame.render_pass_list[1].get(); 1032 RenderPass* child_root_pass = child_frame.render_pass_list[1].get();
1029 SharedQuadState* child_root_pass_sqs = 1033 SharedQuadState* child_root_pass_sqs =
1030 child_root_pass->shared_quad_state_list.front(); 1034 child_root_pass->shared_quad_state_list.front();
1031 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0); 1035 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0);
1032 child_root_pass_sqs->is_clipped = true; 1036 child_root_pass_sqs->is_clipped = true;
1033 child_root_pass_sqs->clip_rect = gfx::Rect(0, 0, 5, 5); 1037 child_root_pass_sqs->clip_rect = gfx::Rect(0, 0, 5, 5);
1034 1038
1035 factory_.SubmitCompositorFrame(child_local_frame_id, std::move(child_frame), 1039 child_factory.SubmitCompositorFrame(child_local_frame_id,
1036 SurfaceFactory::DrawCallback()); 1040 std::move(child_frame),
1041 SurfaceFactory::DrawCallback());
1037 } 1042 }
1038 1043
1039 // Middle child surface. 1044 // Middle child surface.
1045 SurfaceFactory middle_factory(kArbitraryFrameSinkId, &manager_,
1046 &empty_client_);
1040 LocalFrameId middle_local_frame_id = allocator_.GenerateId(); 1047 LocalFrameId middle_local_frame_id = allocator_.GenerateId();
1041 SurfaceId middle_surface_id(factory_.frame_sink_id(), middle_local_frame_id); 1048 SurfaceId middle_surface_id(factory_.frame_sink_id(), middle_local_frame_id);
1042 factory_.Create(middle_local_frame_id);
1043 { 1049 {
1044 test::Quad middle_quads[] = { 1050 test::Quad middle_quads[] = {
1045 test::Quad::SurfaceQuad(child_surface_id, 1.f)}; 1051 test::Quad::SurfaceQuad(child_surface_id, 1.f)};
1046 test::Pass middle_passes[] = { 1052 test::Pass middle_passes[] = {
1047 test::Pass(middle_quads, arraysize(middle_quads)), 1053 test::Pass(middle_quads, arraysize(middle_quads)),
1048 }; 1054 };
1049 1055
1050 CompositorFrame middle_frame; 1056 CompositorFrame middle_frame;
1051 AddPasses(&middle_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1057 AddPasses(&middle_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1052 middle_passes, arraysize(middle_passes)); 1058 middle_passes, arraysize(middle_passes));
1053 1059
1054 RenderPass* middle_root_pass = middle_frame.render_pass_list[0].get(); 1060 RenderPass* middle_root_pass = middle_frame.render_pass_list[0].get();
1055 middle_root_pass->quad_list.ElementAt(0)->visible_rect = 1061 middle_root_pass->quad_list.ElementAt(0)->visible_rect =
1056 gfx::Rect(0, 1, 100, 7); 1062 gfx::Rect(0, 1, 100, 7);
1057 SharedQuadState* middle_root_pass_sqs = 1063 SharedQuadState* middle_root_pass_sqs =
1058 middle_root_pass->shared_quad_state_list.front(); 1064 middle_root_pass->shared_quad_state_list.front();
1059 middle_root_pass_sqs->quad_to_target_transform.Scale(2, 3); 1065 middle_root_pass_sqs->quad_to_target_transform.Scale(2, 3);
1060 1066
1061 factory_.SubmitCompositorFrame(middle_local_frame_id, 1067 middle_factory.SubmitCompositorFrame(middle_local_frame_id,
1062 std::move(middle_frame), 1068 std::move(middle_frame),
1063 SurfaceFactory::DrawCallback()); 1069 SurfaceFactory::DrawCallback());
1064 } 1070 }
1065 1071
1066 // Root surface. 1072 // Root surface.
1067 test::Quad secondary_quads[] = { 1073 test::Quad secondary_quads[] = {
1068 test::Quad::SolidColorQuad(1), 1074 test::Quad::SolidColorQuad(1),
1069 test::Quad::SurfaceQuad(middle_surface_id, 1.f)}; 1075 test::Quad::SurfaceQuad(middle_surface_id, 1.f)};
1070 test::Quad root_quads[] = {test::Quad::SolidColorQuad(1)}; 1076 test::Quad root_quads[] = {test::Quad::SolidColorQuad(1)};
1071 test::Pass root_passes[] = { 1077 test::Pass root_passes[] = {
1072 test::Pass(secondary_quads, arraysize(secondary_quads)), 1078 test::Pass(secondary_quads, arraysize(secondary_quads)),
1073 test::Pass(root_quads, arraysize(root_quads))}; 1079 test::Pass(root_quads, arraysize(root_quads))};
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 EXPECT_TRUE( 1161 EXPECT_TRUE(
1156 aggregated_pass_list[1]->shared_quad_state_list.ElementAt(1)->is_clipped); 1162 aggregated_pass_list[1]->shared_quad_state_list.ElementAt(1)->is_clipped);
1157 1163
1158 // The second quad in the root pass is aggregated from the child, so its 1164 // The second quad in the root pass is aggregated from the child, so its
1159 // clip rect must be transformed by the child's translation/scale and 1165 // clip rect must be transformed by the child's translation/scale and
1160 // clipped be the visible_rects for both children. 1166 // clipped be the visible_rects for both children.
1161 EXPECT_EQ(gfx::Rect(0, 13, 8, 12).ToString(), 1167 EXPECT_EQ(gfx::Rect(0, 13, 8, 12).ToString(),
1162 aggregated_pass_list[1] 1168 aggregated_pass_list[1]
1163 ->shared_quad_state_list.ElementAt(1) 1169 ->shared_quad_state_list.ElementAt(1)
1164 ->clip_rect.ToString()); 1170 ->clip_rect.ToString());
1165
1166 factory_.Destroy(middle_local_frame_id);
1167 factory_.Destroy(child_local_frame_id);
1168 } 1171 }
1169 1172
1170 // Tests that damage rects are aggregated correctly when surfaces change. 1173 // Tests that damage rects are aggregated correctly when surfaces change.
1171 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) { 1174 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) {
1175 SurfaceFactory child_factory(kArbitraryFrameSinkId, &manager_,
1176 &empty_client_);
1177 SurfaceFactory parent_factory(kArbitraryFrameSinkId, &manager_,
1178 &empty_client_);
1172 test::Quad child_quads[] = {test::Quad::RenderPassQuad(RenderPassId(1, 1))}; 1179 test::Quad child_quads[] = {test::Quad::RenderPassQuad(RenderPassId(1, 1))};
1173 test::Pass child_passes[] = { 1180 test::Pass child_passes[] = {
1174 test::Pass(child_quads, arraysize(child_quads), RenderPassId(1, 1))}; 1181 test::Pass(child_quads, arraysize(child_quads), RenderPassId(1, 1))};
1175 1182
1176 CompositorFrame child_frame; 1183 CompositorFrame child_frame;
1177 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1184 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1178 child_passes, arraysize(child_passes)); 1185 child_passes, arraysize(child_passes));
1179 1186
1180 RenderPass* child_root_pass = child_frame.render_pass_list[0].get(); 1187 RenderPass* child_root_pass = child_frame.render_pass_list[0].get();
1181 SharedQuadState* child_root_pass_sqs = 1188 SharedQuadState* child_root_pass_sqs =
1182 child_root_pass->shared_quad_state_list.front(); 1189 child_root_pass->shared_quad_state_list.front();
1183 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0); 1190 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0);
1184 1191
1185 LocalFrameId child_local_frame_id = allocator_.GenerateId(); 1192 LocalFrameId child_local_frame_id = allocator_.GenerateId();
1186 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id); 1193 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id);
1187 factory_.Create(child_local_frame_id); 1194 child_factory.SubmitCompositorFrame(child_local_frame_id,
1188 factory_.SubmitCompositorFrame(child_local_frame_id, std::move(child_frame), 1195 std::move(child_frame),
1189 SurfaceFactory::DrawCallback()); 1196 SurfaceFactory::DrawCallback());
1190 1197
1191 test::Quad parent_surface_quads[] = { 1198 test::Quad parent_surface_quads[] = {
1192 test::Quad::SurfaceQuad(child_surface_id, 1.f)}; 1199 test::Quad::SurfaceQuad(child_surface_id, 1.f)};
1193 test::Pass parent_surface_passes[] = { 1200 test::Pass parent_surface_passes[] = {
1194 test::Pass(parent_surface_quads, arraysize(parent_surface_quads), 1201 test::Pass(parent_surface_quads, arraysize(parent_surface_quads),
1195 RenderPassId(1, 1))}; 1202 RenderPassId(1, 1))};
1196 1203
1197 // Parent surface is only used to test if the transform is applied correctly 1204 // Parent surface is only used to test if the transform is applied correctly
1198 // to the child surface's damage. 1205 // to the child surface's damage.
1199 CompositorFrame parent_surface_frame; 1206 CompositorFrame parent_surface_frame;
1200 AddPasses(&parent_surface_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1207 AddPasses(&parent_surface_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1201 parent_surface_passes, arraysize(parent_surface_passes)); 1208 parent_surface_passes, arraysize(parent_surface_passes));
1202 1209
1203 LocalFrameId parent_local_frame_id = allocator_.GenerateId(); 1210 LocalFrameId parent_local_frame_id = allocator_.GenerateId();
1204 SurfaceId parent_surface_id(factory_.frame_sink_id(), parent_local_frame_id); 1211 SurfaceId parent_surface_id(factory_.frame_sink_id(), parent_local_frame_id);
1205 factory_.Create(parent_local_frame_id); 1212 parent_factory.SubmitCompositorFrame(parent_local_frame_id,
1206 factory_.SubmitCompositorFrame(parent_local_frame_id, 1213 std::move(parent_surface_frame),
1207 std::move(parent_surface_frame), 1214 SurfaceFactory::DrawCallback());
1208 SurfaceFactory::DrawCallback());
1209 1215
1210 test::Quad root_surface_quads[] = { 1216 test::Quad root_surface_quads[] = {
1211 test::Quad::SurfaceQuad(parent_surface_id, 1.f)}; 1217 test::Quad::SurfaceQuad(parent_surface_id, 1.f)};
1212 test::Quad root_render_pass_quads[] = { 1218 test::Quad root_render_pass_quads[] = {
1213 test::Quad::RenderPassQuad(RenderPassId(1, 1))}; 1219 test::Quad::RenderPassQuad(RenderPassId(1, 1))};
1214 1220
1215 test::Pass root_passes[] = { 1221 test::Pass root_passes[] = {
1216 test::Pass(root_surface_quads, arraysize(root_surface_quads), 1222 test::Pass(root_surface_quads, arraysize(root_surface_quads),
1217 RenderPassId(1, 1)), 1223 RenderPassId(1, 1)),
1218 test::Pass(root_render_pass_quads, arraysize(root_render_pass_quads), 1224 test::Pass(root_render_pass_quads, arraysize(root_render_pass_quads),
(...skipping 28 matching lines...) Expand all
1247 CompositorFrame child_frame; 1253 CompositorFrame child_frame;
1248 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1254 AddPasses(&child_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1249 child_passes, arraysize(child_passes)); 1255 child_passes, arraysize(child_passes));
1250 1256
1251 RenderPass* child_root_pass = child_frame.render_pass_list[0].get(); 1257 RenderPass* child_root_pass = child_frame.render_pass_list[0].get();
1252 SharedQuadState* child_root_pass_sqs = 1258 SharedQuadState* child_root_pass_sqs =
1253 child_root_pass->shared_quad_state_list.front(); 1259 child_root_pass->shared_quad_state_list.front();
1254 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0); 1260 child_root_pass_sqs->quad_to_target_transform.Translate(8, 0);
1255 child_root_pass->damage_rect = gfx::Rect(10, 10, 10, 10); 1261 child_root_pass->damage_rect = gfx::Rect(10, 10, 10, 10);
1256 1262
1257 factory_.SubmitCompositorFrame(child_local_frame_id, std::move(child_frame), 1263 child_factory.SubmitCompositorFrame(child_local_frame_id,
1258 SurfaceFactory::DrawCallback()); 1264 std::move(child_frame),
1265 SurfaceFactory::DrawCallback());
1259 1266
1260 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_); 1267 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id_);
1261 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1268 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1262 1269
1263 const RenderPassList& aggregated_pass_list = 1270 const RenderPassList& aggregated_pass_list =
1264 aggregated_frame.render_pass_list; 1271 aggregated_frame.render_pass_list;
1265 1272
1266 ASSERT_EQ(2u, aggregated_pass_list.size()); 1273 ASSERT_EQ(2u, aggregated_pass_list.size());
1267 1274
1268 // Outer surface didn't change, so transformed inner damage rect should be 1275 // Outer surface didn't change, so transformed inner damage rect should be
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1339 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1333 1340
1334 const RenderPassList& aggregated_pass_list = 1341 const RenderPassList& aggregated_pass_list =
1335 aggregated_frame.render_pass_list; 1342 aggregated_frame.render_pass_list;
1336 1343
1337 ASSERT_EQ(2u, aggregated_pass_list.size()); 1344 ASSERT_EQ(2u, aggregated_pass_list.size());
1338 1345
1339 EXPECT_TRUE(aggregated_pass_list[1]->damage_rect.Contains( 1346 EXPECT_TRUE(aggregated_pass_list[1]->damage_rect.Contains(
1340 gfx::Rect(SurfaceSize()))); 1347 gfx::Rect(SurfaceSize())));
1341 } 1348 }
1342
1343 factory_.Destroy(child_local_frame_id);
1344 } 1349 }
1345 1350
1346 // Check that damage is correctly calculated for surfaces with 1351 // Check that damage is correctly calculated for surfaces with
1347 // SetPreviousFrameSurface. 1352 // SetPreviousFrameSurface.
1348 TEST_F(SurfaceAggregatorValidSurfaceTest, SwitchSurfaceDamage) { 1353 TEST_F(SurfaceAggregatorValidSurfaceTest, SwitchSurfaceDamage) {
1354 SurfaceFactory factory2(kArbitraryFrameSinkId, &manager_, &empty_client_);
1349 test::Quad root_render_pass_quads[] = {test::Quad::SolidColorQuad(1)}; 1355 test::Quad root_render_pass_quads[] = {test::Quad::SolidColorQuad(1)};
1350 1356
1351 test::Pass root_passes[] = {test::Pass(root_render_pass_quads, 1357 test::Pass root_passes[] = {test::Pass(root_render_pass_quads,
1352 arraysize(root_render_pass_quads), 1358 arraysize(root_render_pass_quads),
1353 RenderPassId(2, 1))}; 1359 RenderPassId(2, 1))};
1354 1360
1355 CompositorFrame root_frame; 1361 CompositorFrame root_frame;
1356 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes, 1362 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), root_passes,
1357 arraysize(root_passes)); 1363 arraysize(root_passes));
1358 1364
(...skipping 25 matching lines...) Expand all
1384 test::Pass root_passes[] = {test::Pass(root_render_pass_quads, 1390 test::Pass root_passes[] = {test::Pass(root_render_pass_quads,
1385 arraysize(root_render_pass_quads), 1391 arraysize(root_render_pass_quads),
1386 RenderPassId(2, 1))}; 1392 RenderPassId(2, 1))};
1387 1393
1388 CompositorFrame root_frame; 1394 CompositorFrame root_frame;
1389 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()), 1395 AddPasses(&root_frame.render_pass_list, gfx::Rect(SurfaceSize()),
1390 root_passes, arraysize(root_passes)); 1396 root_passes, arraysize(root_passes));
1391 1397
1392 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(1, 2, 3, 4); 1398 root_frame.render_pass_list[0]->damage_rect = gfx::Rect(1, 2, 3, 4);
1393 1399
1394 factory_.Create(second_root_local_frame_id); 1400 factory2.SubmitCompositorFrame(second_root_local_frame_id,
1395 factory_.SubmitCompositorFrame(second_root_local_frame_id,
1396 std::move(root_frame), 1401 std::move(root_frame),
1397 SurfaceFactory::DrawCallback()); 1402 SurfaceFactory::DrawCallback());
1398 factory_.SetPreviousFrameSurface(second_root_local_frame_id, 1403 factory2.SetPreviousFrameSurface(second_root_local_frame_id,
1399 root_local_frame_id_); 1404 root_local_frame_id_);
1400 } 1405 }
1401 { 1406 {
1402 CompositorFrame aggregated_frame = 1407 CompositorFrame aggregated_frame =
1403 aggregator_.Aggregate(second_root_surface_id); 1408 aggregator_.Aggregate(second_root_surface_id);
1404 1409
1405 const RenderPassList& aggregated_pass_list = 1410 const RenderPassList& aggregated_pass_list =
1406 aggregated_frame.render_pass_list; 1411 aggregated_frame.render_pass_list;
1407 1412
1408 ASSERT_EQ(1u, aggregated_pass_list.size()); 1413 ASSERT_EQ(1u, aggregated_pass_list.size());
1409 1414
1410 // Frame from SetPreviousFrameSurface was aggregated last, so damage rect 1415 // Frame from SetPreviousFrameSurface was aggregated last, so damage rect
1411 // from new surface should be used. 1416 // from new surface should be used.
1412 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), aggregated_pass_list[0]->damage_rect); 1417 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), aggregated_pass_list[0]->damage_rect);
1413 } 1418 }
1414 { 1419 {
1415 CompositorFrame aggregated_frame = 1420 CompositorFrame aggregated_frame =
1416 aggregator_.Aggregate(second_root_surface_id); 1421 aggregator_.Aggregate(second_root_surface_id);
1417 1422
1418 const RenderPassList& aggregated_pass_list = 1423 const RenderPassList& aggregated_pass_list =
1419 aggregated_frame.render_pass_list; 1424 aggregated_frame.render_pass_list;
1420 1425
1421 ASSERT_EQ(1u, aggregated_pass_list.size()); 1426 ASSERT_EQ(1u, aggregated_pass_list.size());
1422 1427
1423 // No new frame, so no new damage. 1428 // No new frame, so no new damage.
1424 EXPECT_TRUE(aggregated_pass_list[0]->damage_rect.IsEmpty()); 1429 EXPECT_TRUE(aggregated_pass_list[0]->damage_rect.IsEmpty());
1425 } 1430 }
1426 factory_.Destroy(second_root_local_frame_id);
1427 } 1431 }
1428 1432
1429 class SurfaceAggregatorPartialSwapTest 1433 class SurfaceAggregatorPartialSwapTest
1430 : public SurfaceAggregatorValidSurfaceTest { 1434 : public SurfaceAggregatorValidSurfaceTest {
1431 public: 1435 public:
1432 SurfaceAggregatorPartialSwapTest() 1436 SurfaceAggregatorPartialSwapTest()
1433 : SurfaceAggregatorValidSurfaceTest(true) {} 1437 : SurfaceAggregatorValidSurfaceTest(true) {}
1434 }; 1438 };
1435 1439
1436 // Tests that quads outside the damage rect are ignored. 1440 // Tests that quads outside the damage rect are ignored.
1437 TEST_F(SurfaceAggregatorPartialSwapTest, IgnoreOutside) { 1441 TEST_F(SurfaceAggregatorPartialSwapTest, IgnoreOutside) {
1442 SurfaceFactory child_factory(kArbitraryFrameSinkId, &manager_,
1443 &empty_client_);
1438 LocalFrameId child_local_frame_id = allocator_.GenerateId(); 1444 LocalFrameId child_local_frame_id = allocator_.GenerateId();
1439 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id); 1445 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id);
1440 factory_.Create(child_local_frame_id);
1441 // The child surface has three quads, one with a visible rect of 13,13 4x4 and 1446 // The child surface has three quads, one with a visible rect of 13,13 4x4 and
1442 // the other other with a visible rect of 10,10 2x2 (relative to root target 1447 // the other other with a visible rect of 10,10 2x2 (relative to root target
1443 // space), and one with a non-invertible transform. 1448 // space), and one with a non-invertible transform.
1444 { 1449 {
1445 RenderPassId child_pass_id = RenderPassId(1, 1); 1450 RenderPassId child_pass_id = RenderPassId(1, 1);
1446 test::Quad child_quads1[] = {test::Quad::RenderPassQuad(child_pass_id)}; 1451 test::Quad child_quads1[] = {test::Quad::RenderPassQuad(child_pass_id)};
1447 test::Quad child_quads2[] = {test::Quad::RenderPassQuad(child_pass_id)}; 1452 test::Quad child_quads2[] = {test::Quad::RenderPassQuad(child_pass_id)};
1448 test::Quad child_quads3[] = {test::Quad::RenderPassQuad(child_pass_id)}; 1453 test::Quad child_quads3[] = {test::Quad::RenderPassQuad(child_pass_id)};
1449 test::Pass child_passes[] = { 1454 test::Pass child_passes[] = {
1450 test::Pass(child_quads1, arraysize(child_quads1), child_pass_id), 1455 test::Pass(child_quads1, arraysize(child_quads1), child_pass_id),
(...skipping 16 matching lines...) Expand all
1467 1472
1468 SharedQuadState* child_noninvertible_sqs = 1473 SharedQuadState* child_noninvertible_sqs =
1469 child_pass_list[2]->shared_quad_state_list.ElementAt(0u); 1474 child_pass_list[2]->shared_quad_state_list.ElementAt(0u);
1470 child_noninvertible_sqs->quad_to_target_transform.matrix().setDouble(0, 0, 1475 child_noninvertible_sqs->quad_to_target_transform.matrix().setDouble(0, 0,
1471 0.0); 1476 0.0);
1472 EXPECT_FALSE( 1477 EXPECT_FALSE(
1473 child_noninvertible_sqs->quad_to_target_transform.IsInvertible()); 1478 child_noninvertible_sqs->quad_to_target_transform.IsInvertible());
1474 child_pass_list[2]->quad_list.ElementAt(0)->visible_rect = 1479 child_pass_list[2]->quad_list.ElementAt(0)->visible_rect =
1475 gfx::Rect(0, 0, 2, 2); 1480 gfx::Rect(0, 0, 2, 2);
1476 1481
1477 SubmitPassListAsFrame(&factory_, child_local_frame_id, &child_pass_list); 1482 SubmitPassListAsFrame(&child_factory, child_local_frame_id,
1483 &child_pass_list);
1478 } 1484 }
1479 1485
1480 { 1486 {
1481 test::Quad root_quads[] = {test::Quad::SurfaceQuad(child_surface_id, 1.f)}; 1487 test::Quad root_quads[] = {test::Quad::SurfaceQuad(child_surface_id, 1.f)};
1482 1488
1483 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; 1489 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
1484 1490
1485 RenderPassList root_pass_list; 1491 RenderPassList root_pass_list;
1486 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes, 1492 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes,
1487 arraysize(root_passes)); 1493 arraysize(root_passes));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 child_sqs->quad_to_target_transform.Scale(2, 2); 1571 child_sqs->quad_to_target_transform.Scale(2, 2);
1566 1572
1567 child_pass_list[1]->quad_list.ElementAt(0)->visible_rect = 1573 child_pass_list[1]->quad_list.ElementAt(0)->visible_rect =
1568 gfx::Rect(0, 0, 2, 2); 1574 gfx::Rect(0, 0, 2, 2);
1569 1575
1570 RenderPass* child_root_pass = child_pass_list[1].get(); 1576 RenderPass* child_root_pass = child_pass_list[1].get();
1571 1577
1572 child_root_pass->copy_requests.push_back( 1578 child_root_pass->copy_requests.push_back(
1573 CopyOutputRequest::CreateEmptyRequest()); 1579 CopyOutputRequest::CreateEmptyRequest());
1574 child_root_pass->damage_rect = gfx::Rect(); 1580 child_root_pass->damage_rect = gfx::Rect();
1575 SubmitPassListAsFrame(&factory_, child_local_frame_id, &child_pass_list); 1581 SubmitPassListAsFrame(&child_factory, child_local_frame_id,
1582 &child_pass_list);
1576 } 1583 }
1577 1584
1578 { 1585 {
1579 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id); 1586 CompositorFrame aggregated_frame = aggregator_.Aggregate(root_surface_id);
1580 1587
1581 const RenderPassList& aggregated_pass_list = 1588 const RenderPassList& aggregated_pass_list =
1582 aggregated_frame.render_pass_list; 1589 aggregated_frame.render_pass_list;
1583 1590
1584 // Output frame should have no damage, but all quads included. 1591 // Output frame should have no damage, but all quads included.
1585 ASSERT_EQ(3u, aggregated_pass_list.size()); 1592 ASSERT_EQ(3u, aggregated_pass_list.size());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 EXPECT_EQ(0u, aggregated_pass_list[0]->quad_list.size()); 1699 EXPECT_EQ(0u, aggregated_pass_list[0]->quad_list.size());
1693 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[1]->damage_rect); 1700 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[1]->damage_rect);
1694 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); 1701 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size());
1695 1702
1696 // First render pass draw quad is outside damage rect, so shouldn't be 1703 // First render pass draw quad is outside damage rect, so shouldn't be
1697 // drawn. SurfaceDrawQuad is after background filter, so corresponding 1704 // drawn. SurfaceDrawQuad is after background filter, so corresponding
1698 // RenderPassDrawQuad should be drawn. 1705 // RenderPassDrawQuad should be drawn.
1699 EXPECT_EQ(gfx::Rect(10, 10, 2, 2), aggregated_pass_list[2]->damage_rect); 1706 EXPECT_EQ(gfx::Rect(10, 10, 2, 2), aggregated_pass_list[2]->damage_rect);
1700 EXPECT_EQ(1u, aggregated_pass_list[2]->quad_list.size()); 1707 EXPECT_EQ(1u, aggregated_pass_list[2]->quad_list.size());
1701 } 1708 }
1702
1703 factory_.Destroy(child_local_frame_id);
1704 } 1709 }
1705 1710
1706 class SurfaceAggregatorWithResourcesTest : public testing::Test { 1711 class SurfaceAggregatorWithResourcesTest : public testing::Test {
1707 public: 1712 public:
1708 void SetUp() override { 1713 void SetUp() override {
1709 shared_bitmap_manager_.reset(new TestSharedBitmapManager); 1714 shared_bitmap_manager_.reset(new TestSharedBitmapManager);
1710 resource_provider_ = 1715 resource_provider_ =
1711 FakeResourceProvider::Create(nullptr, shared_bitmap_manager_.get()); 1716 FakeResourceProvider::Create(nullptr, shared_bitmap_manager_.get());
1712 1717
1713 aggregator_.reset( 1718 aggregator_.reset(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 frame.render_pass_list.push_back(std::move(pass)); 1793 frame.render_pass_list.push_back(std::move(pass));
1789 factory->SubmitCompositorFrame(surface_id.local_frame_id(), std::move(frame), 1794 factory->SubmitCompositorFrame(surface_id.local_frame_id(), std::move(frame),
1790 SurfaceFactory::DrawCallback()); 1795 SurfaceFactory::DrawCallback());
1791 } 1796 }
1792 1797
1793 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { 1798 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) {
1794 ResourceTrackingSurfaceFactoryClient client; 1799 ResourceTrackingSurfaceFactoryClient client;
1795 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); 1800 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client);
1796 LocalFrameId local_frame_id(7u, 0); 1801 LocalFrameId local_frame_id(7u, 0);
1797 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); 1802 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id);
1798 factory.Create(local_frame_id);
1799 1803
1800 ResourceId ids[] = {11, 12, 13}; 1804 ResourceId ids[] = {11, 12, 13};
1801 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), 1805 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(),
1802 &factory, surface_id); 1806 &factory, surface_id);
1803 1807
1804 CompositorFrame frame = aggregator_->Aggregate(surface_id); 1808 CompositorFrame frame = aggregator_->Aggregate(surface_id);
1805 1809
1806 // Nothing should be available to be returned yet. 1810 // Nothing should be available to be returned yet.
1807 EXPECT_TRUE(client.returned_resources().empty()); 1811 EXPECT_TRUE(client.returned_resources().empty());
1808 1812
1809 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, 1813 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory,
1810 surface_id); 1814 surface_id);
1811 1815
1812 frame = aggregator_->Aggregate(surface_id); 1816 frame = aggregator_->Aggregate(surface_id);
1813 1817
1814 ASSERT_EQ(3u, client.returned_resources().size()); 1818 ASSERT_EQ(3u, client.returned_resources().size());
1815 ResourceId returned_ids[3]; 1819 ResourceId returned_ids[3];
1816 for (size_t i = 0; i < 3; ++i) { 1820 for (size_t i = 0; i < 3; ++i) {
1817 returned_ids[i] = client.returned_resources()[i].id; 1821 returned_ids[i] = client.returned_resources()[i].id;
1818 } 1822 }
1819 EXPECT_THAT(returned_ids, 1823 EXPECT_THAT(returned_ids,
1820 testing::WhenSorted(testing::ElementsAreArray(ids))); 1824 testing::WhenSorted(testing::ElementsAreArray(ids)));
1821 factory.Destroy(local_frame_id);
1822 } 1825 }
1823 1826
1824 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { 1827 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) {
1825 ResourceTrackingSurfaceFactoryClient client; 1828 ResourceTrackingSurfaceFactoryClient client;
1826 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); 1829 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client);
1827 LocalFrameId local_frame_id(7u, 0); 1830 LocalFrameId local_frame_id(7u, 0);
1828 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); 1831 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id);
1829 factory.Create(local_frame_id);
1830 1832
1831 CompositorFrame frame; 1833 CompositorFrame frame;
1832 std::unique_ptr<RenderPass> pass = RenderPass::Create(); 1834 std::unique_ptr<RenderPass> pass = RenderPass::Create();
1833 pass->id = RenderPassId(1, 1); 1835 pass->id = RenderPassId(1, 1);
1834 TransferableResource resource; 1836 TransferableResource resource;
1835 resource.id = 11; 1837 resource.id = 11;
1836 // ResourceProvider is software but resource is not, so it should be 1838 // ResourceProvider is software but resource is not, so it should be
1837 // ignored. 1839 // ignored.
1838 resource.is_software = false; 1840 resource.is_software = false;
1839 frame.resource_list.push_back(resource); 1841 frame.resource_list.push_back(resource);
1840 frame.render_pass_list.push_back(std::move(pass)); 1842 frame.render_pass_list.push_back(std::move(pass));
1841 factory.SubmitCompositorFrame(local_frame_id, std::move(frame), 1843 factory.SubmitCompositorFrame(local_frame_id, std::move(frame),
1842 SurfaceFactory::DrawCallback()); 1844 SurfaceFactory::DrawCallback());
1843 1845
1844 CompositorFrame returned_frame = aggregator_->Aggregate(surface_id); 1846 CompositorFrame returned_frame = aggregator_->Aggregate(surface_id);
1845 1847
1846 // Nothing should be available to be returned yet. 1848 // Nothing should be available to be returned yet.
1847 EXPECT_TRUE(client.returned_resources().empty()); 1849 EXPECT_TRUE(client.returned_resources().empty());
1848 1850
1849 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &factory, 1851 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &factory,
1850 surface_id); 1852 surface_id);
1851 ASSERT_EQ(1u, client.returned_resources().size()); 1853 ASSERT_EQ(1u, client.returned_resources().size());
1852 EXPECT_EQ(11u, client.returned_resources()[0].id); 1854 EXPECT_EQ(11u, client.returned_resources()[0].id);
1853
1854 factory.Destroy(local_frame_id);
1855 } 1855 }
1856 1856
1857 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { 1857 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) {
1858 ResourceTrackingSurfaceFactoryClient client; 1858 ResourceTrackingSurfaceFactoryClient client;
1859 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); 1859 SurfaceFactory factory1(kArbitraryFrameSinkId, &manager_, &client);
1860 SurfaceFactory factory2(kArbitraryFrameSinkId, &manager_, &client);
1860 LocalFrameId local_frame1_id(7u, 0); 1861 LocalFrameId local_frame1_id(7u, 0);
1861 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); 1862 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id);
1862 factory.Create(local_frame1_id);
1863 1863
1864 LocalFrameId local_frame2_id(8u, 0); 1864 LocalFrameId local_frame2_id(8u, 0);
1865 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); 1865 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id);
1866 factory.Create(local_frame2_id);
1867 1866
1868 ResourceId ids[] = {11, 12, 13}; 1867 ResourceId ids[] = {11, 12, 13};
1869 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), 1868 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(),
1870 &factory, surface1_id); 1869 &factory1, surface1_id);
1871 ResourceId ids2[] = {14, 15, 16}; 1870 ResourceId ids2[] = {14, 15, 16};
1872 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), 1871 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(),
1873 &factory, surface2_id); 1872 &factory2, surface2_id);
1874 1873
1875 CompositorFrame frame = aggregator_->Aggregate(surface1_id); 1874 CompositorFrame frame = aggregator_->Aggregate(surface1_id);
1876 1875
1877 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &factory, 1876 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &factory1,
1878 surface1_id); 1877 surface1_id);
1879 1878
1880 // Nothing should be available to be returned yet. 1879 // Nothing should be available to be returned yet.
1881 EXPECT_TRUE(client.returned_resources().empty()); 1880 EXPECT_TRUE(client.returned_resources().empty());
1882 1881
1883 frame = aggregator_->Aggregate(surface2_id); 1882 frame = aggregator_->Aggregate(surface2_id);
1884 1883
1885 // surface1_id wasn't referenced, so its resources should be returned. 1884 // surface1_id wasn't referenced, so its resources should be returned.
1886 ASSERT_EQ(3u, client.returned_resources().size()); 1885 ASSERT_EQ(3u, client.returned_resources().size());
1887 ResourceId returned_ids[3]; 1886 ResourceId returned_ids[3];
1888 for (size_t i = 0; i < 3; ++i) { 1887 for (size_t i = 0; i < 3; ++i) {
1889 returned_ids[i] = client.returned_resources()[i].id; 1888 returned_ids[i] = client.returned_resources()[i].id;
1890 } 1889 }
1891 EXPECT_THAT(returned_ids, 1890 EXPECT_THAT(returned_ids,
1892 testing::WhenSorted(testing::ElementsAreArray(ids))); 1891 testing::WhenSorted(testing::ElementsAreArray(ids)));
1893 EXPECT_EQ(3u, resource_provider_->num_resources()); 1892 EXPECT_EQ(3u, resource_provider_->num_resources());
1894 factory.Destroy(local_frame1_id);
1895 factory.Destroy(local_frame2_id);
1896 } 1893 }
1897 1894
1898 // Ensure that aggregator completely ignores Surfaces that reference invalid 1895 // Ensure that aggregator completely ignores Surfaces that reference invalid
1899 // resources. 1896 // resources.
1900 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { 1897 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) {
1901 ResourceTrackingSurfaceFactoryClient client; 1898 ResourceTrackingSurfaceFactoryClient client;
1902 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); 1899 SurfaceFactory root_factory(kArbitraryFrameSinkId, &manager_, &client);
1900 SurfaceFactory middle_factory(kArbitraryFrameSinkId, &manager_, &client);
1901 SurfaceFactory child_factory(kArbitraryFrameSinkId, &manager_, &client);
1903 LocalFrameId root_local_frame_id(7u, 1); 1902 LocalFrameId root_local_frame_id(7u, 1);
1904 SurfaceId root_surface_id(kArbitraryFrameSinkId, root_local_frame_id); 1903 SurfaceId root_surface_id(kArbitraryFrameSinkId, root_local_frame_id);
1905 factory.Create(root_local_frame_id);
1906 LocalFrameId middle_local_frame_id(8u, 1); 1904 LocalFrameId middle_local_frame_id(8u, 1);
1907 SurfaceId middle_surface_id(kArbitraryFrameSinkId, middle_local_frame_id); 1905 SurfaceId middle_surface_id(kArbitraryFrameSinkId, middle_local_frame_id);
1908 factory.Create(middle_local_frame_id);
1909 LocalFrameId child_local_frame_id(9u, 1); 1906 LocalFrameId child_local_frame_id(9u, 1);
1910 SurfaceId child_surface_id(kArbitraryFrameSinkId, child_local_frame_id); 1907 SurfaceId child_surface_id(kArbitraryFrameSinkId, child_local_frame_id);
1911 factory.Create(child_local_frame_id);
1912 1908
1913 ResourceId ids[] = {14, 15, 16}; 1909 ResourceId ids[] = {14, 15, 16};
1914 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), 1910 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(),
1915 &factory, child_surface_id); 1911 &child_factory, child_surface_id);
1916 1912
1917 ResourceId ids2[] = {17, 18, 19}; 1913 ResourceId ids2[] = {17, 18, 19};
1918 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, 1914 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false,
1919 child_surface_id, &factory, 1915 child_surface_id, &middle_factory,
1920 middle_surface_id); 1916 middle_surface_id);
1921 1917
1922 ResourceId ids3[] = {20, 21, 22}; 1918 ResourceId ids3[] = {20, 21, 22};
1923 SubmitCompositorFrameWithResources(ids3, arraysize(ids3), true, 1919 SubmitCompositorFrameWithResources(ids3, arraysize(ids3), true,
1924 middle_surface_id, &factory, 1920 middle_surface_id, &root_factory,
1925 root_surface_id); 1921 root_surface_id);
1926 1922
1927 CompositorFrame frame; 1923 CompositorFrame frame;
1928 frame = aggregator_->Aggregate(root_surface_id); 1924 frame = aggregator_->Aggregate(root_surface_id);
1929 1925
1930 RenderPassList* pass_list = &frame.render_pass_list; 1926 RenderPassList* pass_list = &frame.render_pass_list;
1931 ASSERT_EQ(1u, pass_list->size()); 1927 ASSERT_EQ(1u, pass_list->size());
1932 EXPECT_EQ(1u, pass_list->back()->shared_quad_state_list.size()); 1928 EXPECT_EQ(1u, pass_list->back()->shared_quad_state_list.size());
1933 EXPECT_EQ(3u, pass_list->back()->quad_list.size()); 1929 EXPECT_EQ(3u, pass_list->back()->quad_list.size());
1934 SubmitCompositorFrameWithResources(ids2, arraysize(ids), true, 1930 SubmitCompositorFrameWithResources(ids2, arraysize(ids), true,
1935 child_surface_id, &factory, 1931 child_surface_id, &middle_factory,
1936 middle_surface_id); 1932 middle_surface_id);
1937 1933
1938 frame = aggregator_->Aggregate(root_surface_id); 1934 frame = aggregator_->Aggregate(root_surface_id);
1939 1935
1940 pass_list = &frame.render_pass_list; 1936 pass_list = &frame.render_pass_list;
1941 ASSERT_EQ(1u, pass_list->size()); 1937 ASSERT_EQ(1u, pass_list->size());
1942 EXPECT_EQ(3u, pass_list->back()->shared_quad_state_list.size()); 1938 EXPECT_EQ(3u, pass_list->back()->shared_quad_state_list.size());
1943 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); 1939 EXPECT_EQ(9u, pass_list->back()->quad_list.size());
1944
1945 factory.Destroy(root_local_frame_id);
1946 factory.Destroy(child_local_frame_id);
1947 factory.Destroy(middle_local_frame_id);
1948 } 1940 }
1949 1941
1950 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { 1942 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) {
1951 ResourceTrackingSurfaceFactoryClient client; 1943 ResourceTrackingSurfaceFactoryClient client;
1952 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); 1944 SurfaceFactory factory1(kArbitraryFrameSinkId, &manager_, &client);
1945 SurfaceFactory factory2(kArbitraryFrameSinkId, &manager_, &client);
1953 LocalFrameId local_frame1_id(7u, 0); 1946 LocalFrameId local_frame1_id(7u, 0);
1954 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); 1947 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id);
1955 factory.Create(local_frame1_id);
1956 1948
1957 LocalFrameId local_frame2_id(8u, 0); 1949 LocalFrameId local_frame2_id(8u, 0);
1958 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); 1950 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id);
1959 factory.Create(local_frame2_id);
1960 1951
1961 ResourceId ids[] = {11, 12, 13}; 1952 ResourceId ids[] = {11, 12, 13};
1962 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), 1953 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(),
1963 &factory, surface1_id); 1954 &factory1, surface1_id);
1964 1955
1965 CompositorFrame frame = aggregator_->Aggregate(surface1_id); 1956 CompositorFrame frame = aggregator_->Aggregate(surface1_id);
1966 1957
1967 RenderPass* render_pass = frame.render_pass_list.back().get(); 1958 RenderPass* render_pass = frame.render_pass_list.back().get();
1968 1959
1969 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, render_pass->quad_list.back()->material); 1960 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, render_pass->quad_list.back()->material);
1970 1961
1971 { 1962 {
1972 std::unique_ptr<RenderPass> pass = RenderPass::Create(); 1963 std::unique_ptr<RenderPass> pass = RenderPass::Create();
1973 pass->id = RenderPassId(1, 1); 1964 pass->id = RenderPassId(1, 1);
1974 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 1965 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
1975 sqs->opacity = 1.f; 1966 sqs->opacity = 1.f;
1976 SurfaceDrawQuad* surface_quad = 1967 SurfaceDrawQuad* surface_quad =
1977 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 1968 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
1969
1978 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), 1970 surface_quad->SetNew(sqs, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1),
1979 surface1_id); 1971 surface1_id);
1980 pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest()); 1972 pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest());
1981 1973
1982 CompositorFrame frame; 1974 CompositorFrame frame;
1983 frame.render_pass_list.push_back(std::move(pass)); 1975 frame.render_pass_list.push_back(std::move(pass));
1984 1976
1985 factory.SubmitCompositorFrame(local_frame2_id, std::move(frame), 1977 factory2.SubmitCompositorFrame(local_frame2_id, std::move(frame),
1986 SurfaceFactory::DrawCallback()); 1978 SurfaceFactory::DrawCallback());
1987 } 1979 }
1988 1980
1989 frame = aggregator_->Aggregate(surface2_id); 1981 frame = aggregator_->Aggregate(surface2_id);
1990 EXPECT_EQ(1u, frame.render_pass_list.size()); 1982 EXPECT_EQ(1u, frame.render_pass_list.size());
1991 render_pass = frame.render_pass_list.front().get(); 1983 render_pass = frame.render_pass_list.front().get();
1992 1984
1993 // Parent has copy request, so texture should not be drawn. 1985 // Parent has copy request, so texture should not be drawn.
1994 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); 1986 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material);
1995 1987
1996 frame = aggregator_->Aggregate(surface2_id); 1988 frame = aggregator_->Aggregate(surface2_id);
1997 EXPECT_EQ(1u, frame.render_pass_list.size()); 1989 EXPECT_EQ(1u, frame.render_pass_list.size());
1998 render_pass = frame.render_pass_list.front().get(); 1990 render_pass = frame.render_pass_list.front().get();
1999 1991
2000 // Copy request has been executed earlier, so texture should be drawn. 1992 // Copy request has been executed earlier, so texture should be drawn.
2001 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, 1993 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT,
2002 render_pass->quad_list.front()->material); 1994 render_pass->quad_list.front()->material);
2003 1995
2004 aggregator_->set_output_is_secure(false); 1996 aggregator_->set_output_is_secure(false);
2005 1997
2006 frame = aggregator_->Aggregate(surface2_id); 1998 frame = aggregator_->Aggregate(surface2_id);
2007 render_pass = frame.render_pass_list.back().get(); 1999 render_pass = frame.render_pass_list.back().get();
2008 2000
2009 // Output is insecure, so texture should be drawn. 2001 // Output is insecure, so texture should be drawn.
2010 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); 2002 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material);
2011
2012 factory.Destroy(local_frame1_id);
2013 factory.Destroy(local_frame2_id);
2014 } 2003 }
2015 2004
2016 } // namespace 2005 } // namespace
2017 } // namespace cc 2006 } // namespace cc
2018 2007
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698