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

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

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

Powered by Google App Engine
This is Rietveld 408576698