| OLD | NEW |
| 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/output/compositor_frame.h" | 5 #include "cc/output/compositor_frame.h" |
| 6 #include "cc/output/delegated_frame_data.h" | 6 #include "cc/output/delegated_frame_data.h" |
| 7 #include "cc/quads/render_pass.h" | 7 #include "cc/quads/render_pass.h" |
| 8 #include "cc/quads/render_pass_draw_quad.h" | 8 #include "cc/quads/render_pass_draw_quad.h" |
| 9 #include "cc/quads/solid_color_draw_quad.h" | 9 #include "cc/quads/solid_color_draw_quad.h" |
| 10 #include "cc/quads/surface_draw_quad.h" | 10 #include "cc/quads/surface_draw_quad.h" |
| (...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 ReturnedResourceArray returned_resources() const { | 1313 ReturnedResourceArray returned_resources() const { |
| 1314 return returned_resources_; | 1314 return returned_resources_; |
| 1315 } | 1315 } |
| 1316 | 1316 |
| 1317 private: | 1317 private: |
| 1318 ReturnedResourceArray returned_resources_; | 1318 ReturnedResourceArray returned_resources_; |
| 1319 | 1319 |
| 1320 DISALLOW_COPY_AND_ASSIGN(ResourceTrackingSurfaceFactoryClient); | 1320 DISALLOW_COPY_AND_ASSIGN(ResourceTrackingSurfaceFactoryClient); |
| 1321 }; | 1321 }; |
| 1322 | 1322 |
| 1323 void SubmitFrameWithResources(ResourceProvider::ResourceId* resource_ids, | 1323 void SubmitFrameWithResources(ResourceId* resource_ids, |
| 1324 size_t num_resource_ids, | 1324 size_t num_resource_ids, |
| 1325 bool valid, | 1325 bool valid, |
| 1326 SurfaceId child_id, | 1326 SurfaceId child_id, |
| 1327 SurfaceFactory* factory, | 1327 SurfaceFactory* factory, |
| 1328 SurfaceId surface_id) { | 1328 SurfaceId surface_id) { |
| 1329 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 1329 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 1330 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 1330 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 1331 pass->id = RenderPassId(1, 1); | 1331 pass->id = RenderPassId(1, 1); |
| 1332 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 1332 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 1333 sqs->opacity = 1.f; | 1333 sqs->opacity = 1.f; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 factory->SubmitFrame(surface_id, frame.Pass(), | 1376 factory->SubmitFrame(surface_id, frame.Pass(), |
| 1377 SurfaceFactory::DrawCallback()); | 1377 SurfaceFactory::DrawCallback()); |
| 1378 } | 1378 } |
| 1379 | 1379 |
| 1380 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { | 1380 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { |
| 1381 ResourceTrackingSurfaceFactoryClient client; | 1381 ResourceTrackingSurfaceFactoryClient client; |
| 1382 SurfaceFactory factory(&manager_, &client); | 1382 SurfaceFactory factory(&manager_, &client); |
| 1383 SurfaceId surface_id(7u); | 1383 SurfaceId surface_id(7u); |
| 1384 factory.Create(surface_id); | 1384 factory.Create(surface_id); |
| 1385 | 1385 |
| 1386 ResourceProvider::ResourceId ids[] = {11, 12, 13}; | 1386 ResourceId ids[] = {11, 12, 13}; |
| 1387 SubmitFrameWithResources(ids, arraysize(ids), true, SurfaceId(), &factory, | 1387 SubmitFrameWithResources(ids, arraysize(ids), true, SurfaceId(), &factory, |
| 1388 surface_id); | 1388 surface_id); |
| 1389 | 1389 |
| 1390 scoped_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); | 1390 scoped_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); |
| 1391 | 1391 |
| 1392 // Nothing should be available to be returned yet. | 1392 // Nothing should be available to be returned yet. |
| 1393 EXPECT_TRUE(client.returned_resources().empty()); | 1393 EXPECT_TRUE(client.returned_resources().empty()); |
| 1394 | 1394 |
| 1395 SubmitFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, surface_id); | 1395 SubmitFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, surface_id); |
| 1396 | 1396 |
| 1397 frame = aggregator_->Aggregate(surface_id); | 1397 frame = aggregator_->Aggregate(surface_id); |
| 1398 | 1398 |
| 1399 ASSERT_EQ(3u, client.returned_resources().size()); | 1399 ASSERT_EQ(3u, client.returned_resources().size()); |
| 1400 ResourceProvider::ResourceId returned_ids[3]; | 1400 ResourceId returned_ids[3]; |
| 1401 for (size_t i = 0; i < 3; ++i) { | 1401 for (size_t i = 0; i < 3; ++i) { |
| 1402 returned_ids[i] = client.returned_resources()[i].id; | 1402 returned_ids[i] = client.returned_resources()[i].id; |
| 1403 } | 1403 } |
| 1404 EXPECT_THAT(returned_ids, | 1404 EXPECT_THAT(returned_ids, |
| 1405 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1405 testing::WhenSorted(testing::ElementsAreArray(ids))); |
| 1406 factory.Destroy(surface_id); | 1406 factory.Destroy(surface_id); |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { | 1409 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { |
| 1410 ResourceTrackingSurfaceFactoryClient client; | 1410 ResourceTrackingSurfaceFactoryClient client; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1440 } | 1440 } |
| 1441 | 1441 |
| 1442 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { | 1442 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { |
| 1443 ResourceTrackingSurfaceFactoryClient client; | 1443 ResourceTrackingSurfaceFactoryClient client; |
| 1444 SurfaceFactory factory(&manager_, &client); | 1444 SurfaceFactory factory(&manager_, &client); |
| 1445 SurfaceId surface_id(7u); | 1445 SurfaceId surface_id(7u); |
| 1446 factory.Create(surface_id); | 1446 factory.Create(surface_id); |
| 1447 SurfaceId surface_id2(8u); | 1447 SurfaceId surface_id2(8u); |
| 1448 factory.Create(surface_id2); | 1448 factory.Create(surface_id2); |
| 1449 | 1449 |
| 1450 ResourceProvider::ResourceId ids[] = {11, 12, 13}; | 1450 ResourceId ids[] = {11, 12, 13}; |
| 1451 SubmitFrameWithResources(ids, arraysize(ids), true, SurfaceId(), &factory, | 1451 SubmitFrameWithResources(ids, arraysize(ids), true, SurfaceId(), &factory, |
| 1452 surface_id); | 1452 surface_id); |
| 1453 ResourceProvider::ResourceId ids2[] = {14, 15, 16}; | 1453 ResourceId ids2[] = {14, 15, 16}; |
| 1454 SubmitFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), &factory, | 1454 SubmitFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), &factory, |
| 1455 surface_id2); | 1455 surface_id2); |
| 1456 | 1456 |
| 1457 scoped_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); | 1457 scoped_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); |
| 1458 | 1458 |
| 1459 SubmitFrameWithResources(NULL, 0, true, SurfaceId(), &factory, surface_id); | 1459 SubmitFrameWithResources(NULL, 0, true, SurfaceId(), &factory, surface_id); |
| 1460 | 1460 |
| 1461 // Nothing should be available to be returned yet. | 1461 // Nothing should be available to be returned yet. |
| 1462 EXPECT_TRUE(client.returned_resources().empty()); | 1462 EXPECT_TRUE(client.returned_resources().empty()); |
| 1463 | 1463 |
| 1464 frame = aggregator_->Aggregate(surface_id2); | 1464 frame = aggregator_->Aggregate(surface_id2); |
| 1465 | 1465 |
| 1466 // surface_id wasn't referenced, so its resources should be returned. | 1466 // surface_id wasn't referenced, so its resources should be returned. |
| 1467 ASSERT_EQ(3u, client.returned_resources().size()); | 1467 ASSERT_EQ(3u, client.returned_resources().size()); |
| 1468 ResourceProvider::ResourceId returned_ids[3]; | 1468 ResourceId returned_ids[3]; |
| 1469 for (size_t i = 0; i < 3; ++i) { | 1469 for (size_t i = 0; i < 3; ++i) { |
| 1470 returned_ids[i] = client.returned_resources()[i].id; | 1470 returned_ids[i] = client.returned_resources()[i].id; |
| 1471 } | 1471 } |
| 1472 EXPECT_THAT(returned_ids, | 1472 EXPECT_THAT(returned_ids, |
| 1473 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1473 testing::WhenSorted(testing::ElementsAreArray(ids))); |
| 1474 EXPECT_EQ(3u, resource_provider_->num_resources()); | 1474 EXPECT_EQ(3u, resource_provider_->num_resources()); |
| 1475 factory.Destroy(surface_id); | 1475 factory.Destroy(surface_id); |
| 1476 factory.Destroy(surface_id2); | 1476 factory.Destroy(surface_id2); |
| 1477 } | 1477 } |
| 1478 | 1478 |
| 1479 // Ensure that aggregator completely ignores Surfaces that reference invalid | 1479 // Ensure that aggregator completely ignores Surfaces that reference invalid |
| 1480 // resources. | 1480 // resources. |
| 1481 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { | 1481 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { |
| 1482 ResourceTrackingSurfaceFactoryClient client; | 1482 ResourceTrackingSurfaceFactoryClient client; |
| 1483 SurfaceFactory factory(&manager_, &client); | 1483 SurfaceFactory factory(&manager_, &client); |
| 1484 SurfaceId root_surface_id(7u); | 1484 SurfaceId root_surface_id(7u); |
| 1485 factory.Create(root_surface_id); | 1485 factory.Create(root_surface_id); |
| 1486 SurfaceId middle_surface_id(8u); | 1486 SurfaceId middle_surface_id(8u); |
| 1487 factory.Create(middle_surface_id); | 1487 factory.Create(middle_surface_id); |
| 1488 SurfaceId child_surface_id(9u); | 1488 SurfaceId child_surface_id(9u); |
| 1489 factory.Create(child_surface_id); | 1489 factory.Create(child_surface_id); |
| 1490 | 1490 |
| 1491 ResourceProvider::ResourceId ids[] = {14, 15, 16}; | 1491 ResourceId ids[] = {14, 15, 16}; |
| 1492 SubmitFrameWithResources(ids, arraysize(ids), true, SurfaceId(), &factory, | 1492 SubmitFrameWithResources(ids, arraysize(ids), true, SurfaceId(), &factory, |
| 1493 child_surface_id); | 1493 child_surface_id); |
| 1494 | 1494 |
| 1495 ResourceProvider::ResourceId ids2[] = {17, 18, 19}; | 1495 ResourceId ids2[] = {17, 18, 19}; |
| 1496 SubmitFrameWithResources(ids2, arraysize(ids2), false, child_surface_id, | 1496 SubmitFrameWithResources(ids2, arraysize(ids2), false, child_surface_id, |
| 1497 &factory, middle_surface_id); | 1497 &factory, middle_surface_id); |
| 1498 | 1498 |
| 1499 ResourceProvider::ResourceId ids3[] = {20, 21, 22}; | 1499 ResourceId ids3[] = {20, 21, 22}; |
| 1500 SubmitFrameWithResources(ids3, arraysize(ids3), true, middle_surface_id, | 1500 SubmitFrameWithResources(ids3, arraysize(ids3), true, middle_surface_id, |
| 1501 &factory, root_surface_id); | 1501 &factory, root_surface_id); |
| 1502 | 1502 |
| 1503 scoped_ptr<CompositorFrame> frame; | 1503 scoped_ptr<CompositorFrame> frame; |
| 1504 frame = aggregator_->Aggregate(root_surface_id); | 1504 frame = aggregator_->Aggregate(root_surface_id); |
| 1505 | 1505 |
| 1506 RenderPassList* pass_list = &frame->delegated_frame_data->render_pass_list; | 1506 RenderPassList* pass_list = &frame->delegated_frame_data->render_pass_list; |
| 1507 ASSERT_EQ(1u, pass_list->size()); | 1507 ASSERT_EQ(1u, pass_list->size()); |
| 1508 EXPECT_EQ(1u, pass_list->back()->shared_quad_state_list.size()); | 1508 EXPECT_EQ(1u, pass_list->back()->shared_quad_state_list.size()); |
| 1509 EXPECT_EQ(3u, pass_list->back()->quad_list.size()); | 1509 EXPECT_EQ(3u, pass_list->back()->quad_list.size()); |
| 1510 | 1510 |
| 1511 SubmitFrameWithResources(ids2, arraysize(ids), true, child_surface_id, | 1511 SubmitFrameWithResources(ids2, arraysize(ids), true, child_surface_id, |
| 1512 &factory, middle_surface_id); | 1512 &factory, middle_surface_id); |
| 1513 | 1513 |
| 1514 frame = aggregator_->Aggregate(root_surface_id); | 1514 frame = aggregator_->Aggregate(root_surface_id); |
| 1515 | 1515 |
| 1516 pass_list = &frame->delegated_frame_data->render_pass_list; | 1516 pass_list = &frame->delegated_frame_data->render_pass_list; |
| 1517 ASSERT_EQ(1u, pass_list->size()); | 1517 ASSERT_EQ(1u, pass_list->size()); |
| 1518 EXPECT_EQ(3u, pass_list->back()->shared_quad_state_list.size()); | 1518 EXPECT_EQ(3u, pass_list->back()->shared_quad_state_list.size()); |
| 1519 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 1519 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
| 1520 | 1520 |
| 1521 factory.Destroy(root_surface_id); | 1521 factory.Destroy(root_surface_id); |
| 1522 factory.Destroy(child_surface_id); | 1522 factory.Destroy(child_surface_id); |
| 1523 factory.Destroy(middle_surface_id); | 1523 factory.Destroy(middle_surface_id); |
| 1524 } | 1524 } |
| 1525 | 1525 |
| 1526 } // namespace | 1526 } // namespace |
| 1527 } // namespace cc | 1527 } // namespace cc |
| 1528 | 1528 |
| OLD | NEW |