| 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/surfaces/surface_factory.h" | 5 #include "cc/surfaces/surface_factory.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "cc/output/compositor_frame.h" | 14 #include "cc/output/compositor_frame.h" |
| 15 #include "cc/output/copy_output_request.h" | 15 #include "cc/output/copy_output_request.h" |
| 16 #include "cc/output/copy_output_result.h" | 16 #include "cc/output/copy_output_result.h" |
| 17 #include "cc/output/delegated_frame_data.h" | |
| 18 #include "cc/resources/resource_provider.h" | 17 #include "cc/resources/resource_provider.h" |
| 19 #include "cc/surfaces/surface.h" | 18 #include "cc/surfaces/surface.h" |
| 20 #include "cc/surfaces/surface_factory_client.h" | 19 #include "cc/surfaces/surface_factory_client.h" |
| 21 #include "cc/surfaces/surface_manager.h" | 20 #include "cc/surfaces/surface_manager.h" |
| 22 #include "cc/test/scheduler_test_common.h" | 21 #include "cc/test/scheduler_test_common.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "ui/gfx/geometry/size.h" | 23 #include "ui/gfx/geometry/size.h" |
| 25 | 24 |
| 26 namespace cc { | 25 namespace cc { |
| 27 namespace { | 26 namespace { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 92 } |
| 94 | 93 |
| 95 ~SurfaceFactoryTest() override { | 94 ~SurfaceFactoryTest() override { |
| 96 if (!local_frame_id_.is_null()) | 95 if (!local_frame_id_.is_null()) |
| 97 factory_->Destroy(local_frame_id_); | 96 factory_->Destroy(local_frame_id_); |
| 98 manager_.RemoveObserver(this); | 97 manager_.RemoveObserver(this); |
| 99 } | 98 } |
| 100 | 99 |
| 101 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 100 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
| 102 size_t num_resource_ids) { | 101 size_t num_resource_ids) { |
| 103 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 102 CompositorFrame frame; |
| 104 for (size_t i = 0u; i < num_resource_ids; ++i) { | 103 for (size_t i = 0u; i < num_resource_ids; ++i) { |
| 105 TransferableResource resource; | 104 TransferableResource resource; |
| 106 resource.id = resource_ids[i]; | 105 resource.id = resource_ids[i]; |
| 107 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 106 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 108 resource.mailbox_holder.sync_token = frame_sync_token_; | 107 resource.mailbox_holder.sync_token = frame_sync_token_; |
| 109 frame_data->resource_list.push_back(resource); | 108 frame.resource_list.push_back(resource); |
| 110 } | 109 } |
| 111 CompositorFrame frame; | |
| 112 frame.delegated_frame_data = std::move(frame_data); | |
| 113 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 110 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 114 SurfaceFactory::DrawCallback()); | 111 SurfaceFactory::DrawCallback()); |
| 115 EXPECT_EQ(last_created_surface_id_.local_frame_id(), local_frame_id_); | 112 EXPECT_EQ(last_created_surface_id_.local_frame_id(), local_frame_id_); |
| 116 } | 113 } |
| 117 | 114 |
| 118 void UnrefResources(ResourceId* ids_to_unref, | 115 void UnrefResources(ResourceId* ids_to_unref, |
| 119 int* counts_to_unref, | 116 int* counts_to_unref, |
| 120 size_t num_ids_to_unref) { | 117 size_t num_ids_to_unref) { |
| 121 ReturnedResourceArray unref_array; | 118 ReturnedResourceArray unref_array; |
| 122 for (size_t i = 0; i < num_ids_to_unref; ++i) { | 119 for (size_t i = 0; i < num_ids_to_unref; ++i) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 141 EXPECT_EQ(expected_sync_token, resource.sync_token); | 138 EXPECT_EQ(expected_sync_token, resource.sync_token); |
| 142 EXPECT_EQ(expected_returned_ids[i], resource.id); | 139 EXPECT_EQ(expected_returned_ids[i], resource.id); |
| 143 EXPECT_EQ(expected_returned_counts[i], resource.count); | 140 EXPECT_EQ(expected_returned_counts[i], resource.count); |
| 144 } | 141 } |
| 145 client_.clear_returned_resources(); | 142 client_.clear_returned_resources(); |
| 146 } | 143 } |
| 147 | 144 |
| 148 void RefCurrentFrameResources() { | 145 void RefCurrentFrameResources() { |
| 149 Surface* surface = manager_.GetSurfaceForId( | 146 Surface* surface = manager_.GetSurfaceForId( |
| 150 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); | 147 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); |
| 151 factory_->RefResources( | 148 factory_->RefResources(surface->GetEligibleFrame().resource_list); |
| 152 surface->GetEligibleFrame().delegated_frame_data->resource_list); | |
| 153 } | 149 } |
| 154 | 150 |
| 155 protected: | 151 protected: |
| 156 SurfaceManager manager_; | 152 SurfaceManager manager_; |
| 157 TestSurfaceFactoryClient client_; | 153 TestSurfaceFactoryClient client_; |
| 158 std::unique_ptr<SurfaceFactory> factory_; | 154 std::unique_ptr<SurfaceFactory> factory_; |
| 159 LocalFrameId local_frame_id_; | 155 LocalFrameId local_frame_id_; |
| 160 SurfaceId last_created_surface_id_; | 156 SurfaceId last_created_surface_id_; |
| 161 | 157 |
| 162 // This is the sync token submitted with the frame. It should never be | 158 // This is the sync token submitted with the frame. It should never be |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 431 } |
| 436 } | 432 } |
| 437 | 433 |
| 438 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 434 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
| 439 LocalFrameId local_frame_id(6, 0); | 435 LocalFrameId local_frame_id(6, 0); |
| 440 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); | 436 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); |
| 441 factory_->Create(local_frame_id); | 437 factory_->Create(local_frame_id); |
| 442 Surface* surface = manager_.GetSurfaceForId(surface_id); | 438 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 443 ASSERT_NE(nullptr, surface); | 439 ASSERT_NE(nullptr, surface); |
| 444 EXPECT_EQ(2, surface->frame_index()); | 440 EXPECT_EQ(2, surface->frame_index()); |
| 445 CompositorFrame frame; | |
| 446 frame.delegated_frame_data.reset(new DelegatedFrameData); | |
| 447 | 441 |
| 448 factory_->SubmitCompositorFrame(local_frame_id, std::move(frame), | 442 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), |
| 449 SurfaceFactory::DrawCallback()); | 443 SurfaceFactory::DrawCallback()); |
| 450 EXPECT_EQ(2, surface->frame_index()); | 444 EXPECT_EQ(2, surface->frame_index()); |
| 451 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); | 445 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); |
| 452 factory_->Destroy(local_frame_id); | 446 factory_->Destroy(local_frame_id); |
| 453 } | 447 } |
| 454 | 448 |
| 455 void CreateSurfaceDrawCallback(SurfaceFactory* factory, | 449 void CreateSurfaceDrawCallback(SurfaceFactory* factory, |
| 456 uint32_t* execute_count) { | 450 uint32_t* execute_count) { |
| 457 LocalFrameId new_id(7, 0); | 451 LocalFrameId new_id(7, 0); |
| 458 factory->Create(new_id); | 452 factory->Create(new_id); |
| 459 factory->Destroy(new_id); | 453 factory->Destroy(new_id); |
| 460 *execute_count += 1; | 454 *execute_count += 1; |
| 461 } | 455 } |
| 462 | 456 |
| 463 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { | 457 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { |
| 464 LocalFrameId local_frame_id(6, 0); | 458 LocalFrameId local_frame_id(6, 0); |
| 465 factory_->Create(local_frame_id); | 459 factory_->Create(local_frame_id); |
| 466 CompositorFrame frame; | |
| 467 frame.delegated_frame_data.reset(new DelegatedFrameData); | |
| 468 | 460 |
| 469 uint32_t execute_count = 0; | 461 uint32_t execute_count = 0; |
| 470 factory_->SubmitCompositorFrame( | 462 factory_->SubmitCompositorFrame( |
| 471 local_frame_id, std::move(frame), | 463 local_frame_id, CompositorFrame(), |
| 472 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), | 464 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), |
| 473 &execute_count)); | 465 &execute_count)); |
| 474 EXPECT_EQ(0u, execute_count); | 466 EXPECT_EQ(0u, execute_count); |
| 475 factory_->Destroy(local_frame_id); | 467 factory_->Destroy(local_frame_id); |
| 476 EXPECT_EQ(1u, execute_count); | 468 EXPECT_EQ(1u, execute_count); |
| 477 } | 469 } |
| 478 | 470 |
| 479 void DrawCallback(uint32_t* execute_count) { | 471 void DrawCallback(uint32_t* execute_count) { |
| 480 *execute_count += 1; | 472 *execute_count += 1; |
| 481 } | 473 } |
| 482 | 474 |
| 483 // Tests doing a DestroyAll before shutting down the factory; | 475 // Tests doing a DestroyAll before shutting down the factory; |
| 484 TEST_F(SurfaceFactoryTest, DestroyAll) { | 476 TEST_F(SurfaceFactoryTest, DestroyAll) { |
| 485 LocalFrameId id(7, 0); | 477 LocalFrameId id(7, 0); |
| 486 factory_->Create(id); | 478 factory_->Create(id); |
| 487 | 479 |
| 488 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | |
| 489 TransferableResource resource; | 480 TransferableResource resource; |
| 490 resource.id = 1; | 481 resource.id = 1; |
| 491 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 482 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 492 frame_data->resource_list.push_back(resource); | |
| 493 CompositorFrame frame; | 483 CompositorFrame frame; |
| 494 frame.delegated_frame_data = std::move(frame_data); | 484 frame.resource_list.push_back(resource); |
| 495 uint32_t execute_count = 0; | 485 uint32_t execute_count = 0; |
| 496 factory_->SubmitCompositorFrame(id, std::move(frame), | 486 factory_->SubmitCompositorFrame(id, std::move(frame), |
| 497 base::Bind(&DrawCallback, &execute_count)); | 487 base::Bind(&DrawCallback, &execute_count)); |
| 498 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); | 488 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); |
| 499 local_frame_id_ = LocalFrameId(); | 489 local_frame_id_ = LocalFrameId(); |
| 500 factory_->DestroyAll(); | 490 factory_->DestroyAll(); |
| 501 EXPECT_EQ(1u, execute_count); | 491 EXPECT_EQ(1u, execute_count); |
| 502 } | 492 } |
| 503 | 493 |
| 504 TEST_F(SurfaceFactoryTest, DestroySequence) { | 494 TEST_F(SurfaceFactoryTest, DestroySequence) { |
| 505 LocalFrameId local_frame_id2(5, 0); | 495 LocalFrameId local_frame_id2(5, 0); |
| 506 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); | 496 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); |
| 507 factory_->Create(local_frame_id2); | 497 factory_->Create(local_frame_id2); |
| 508 | 498 |
| 509 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); | 499 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); |
| 510 | 500 |
| 511 // Check that waiting before the sequence is satisfied works. | 501 // Check that waiting before the sequence is satisfied works. |
| 512 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 502 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 513 SurfaceSequence(kArbitraryFrameSinkId, 4)); | 503 SurfaceSequence(kArbitraryFrameSinkId, 4)); |
| 514 factory_->Destroy(local_frame_id2); | 504 factory_->Destroy(local_frame_id2); |
| 515 | 505 |
| 516 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | |
| 517 CompositorFrame frame; | 506 CompositorFrame frame; |
| 518 frame.metadata.satisfies_sequences.push_back(6); | 507 frame.metadata.satisfies_sequences.push_back(6); |
| 519 frame.metadata.satisfies_sequences.push_back(4); | 508 frame.metadata.satisfies_sequences.push_back(4); |
| 520 frame.delegated_frame_data = std::move(frame_data); | |
| 521 DCHECK(manager_.GetSurfaceForId(id2)); | 509 DCHECK(manager_.GetSurfaceForId(id2)); |
| 522 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 510 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 523 SurfaceFactory::DrawCallback()); | 511 SurfaceFactory::DrawCallback()); |
| 524 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); | 512 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); |
| 525 DCHECK(!manager_.GetSurfaceForId(id2)); | 513 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 526 | 514 |
| 527 // Check that waiting after the sequence is satisfied works. | 515 // Check that waiting after the sequence is satisfied works. |
| 528 factory_->Create(local_frame_id2); | 516 factory_->Create(local_frame_id2); |
| 529 DCHECK(manager_.GetSurfaceForId(id2)); | 517 DCHECK(manager_.GetSurfaceForId(id2)); |
| 530 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 518 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 factory_->Create(local_frame_id2); | 551 factory_->Create(local_frame_id2); |
| 564 | 552 |
| 565 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); | 553 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); |
| 566 | 554 |
| 567 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 555 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 568 SurfaceSequence(FrameSinkId(0, 0), 4)); | 556 SurfaceSequence(FrameSinkId(0, 0), 4)); |
| 569 | 557 |
| 570 // Give id2 a frame that references local_frame_id_. | 558 // Give id2 a frame that references local_frame_id_. |
| 571 { | 559 { |
| 572 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 560 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 573 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | |
| 574 frame_data->render_pass_list.push_back(std::move(render_pass)); | |
| 575 CompositorFrame frame; | 561 CompositorFrame frame; |
| 562 frame.render_pass_list.push_back(std::move(render_pass)); |
| 576 frame.metadata.referenced_surfaces.push_back( | 563 frame.metadata.referenced_surfaces.push_back( |
| 577 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); | 564 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); |
| 578 frame.delegated_frame_data = std::move(frame_data); | |
| 579 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), | 565 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), |
| 580 SurfaceFactory::DrawCallback()); | 566 SurfaceFactory::DrawCallback()); |
| 581 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2); | 567 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2); |
| 582 } | 568 } |
| 583 factory_->Destroy(local_frame_id2); | 569 factory_->Destroy(local_frame_id2); |
| 584 | 570 |
| 585 // Give local_frame_id_ a frame that references id2. | 571 // Give local_frame_id_ a frame that references id2. |
| 586 { | 572 { |
| 587 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 573 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 588 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | |
| 589 frame_data->render_pass_list.push_back(std::move(render_pass)); | |
| 590 CompositorFrame frame; | 574 CompositorFrame frame; |
| 575 frame.render_pass_list.push_back(std::move(render_pass)); |
| 591 frame.metadata.referenced_surfaces.push_back(id2); | 576 frame.metadata.referenced_surfaces.push_back(id2); |
| 592 frame.delegated_frame_data = std::move(frame_data); | |
| 593 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 577 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 594 SurfaceFactory::DrawCallback()); | 578 SurfaceFactory::DrawCallback()); |
| 595 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); | 579 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); |
| 596 } | 580 } |
| 597 factory_->Destroy(local_frame_id_); | 581 factory_->Destroy(local_frame_id_); |
| 598 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); | 582 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); |
| 599 // local_frame_id_ should be retained by reference from id2. | 583 // local_frame_id_ should be retained by reference from id2. |
| 600 EXPECT_TRUE(manager_.GetSurfaceForId( | 584 EXPECT_TRUE(manager_.GetSurfaceForId( |
| 601 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); | 585 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); |
| 602 | 586 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 615 } | 599 } |
| 616 | 600 |
| 617 void CopyRequestTestCallback(bool* called, | 601 void CopyRequestTestCallback(bool* called, |
| 618 std::unique_ptr<CopyOutputResult> result) { | 602 std::unique_ptr<CopyOutputResult> result) { |
| 619 *called = true; | 603 *called = true; |
| 620 } | 604 } |
| 621 | 605 |
| 622 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { | 606 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { |
| 623 { | 607 { |
| 624 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 608 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 625 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | |
| 626 frame_data->render_pass_list.push_back(std::move(render_pass)); | |
| 627 CompositorFrame frame; | 609 CompositorFrame frame; |
| 610 frame.render_pass_list.push_back(std::move(render_pass)); |
| 628 frame.metadata.referenced_surfaces.push_back( | 611 frame.metadata.referenced_surfaces.push_back( |
| 629 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); | 612 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); |
| 630 frame.delegated_frame_data = std::move(frame_data); | |
| 631 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 613 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 632 SurfaceFactory::DrawCallback()); | 614 SurfaceFactory::DrawCallback()); |
| 633 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); | 615 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); |
| 634 } | 616 } |
| 635 void* source1 = &source1; | 617 void* source1 = &source1; |
| 636 void* source2 = &source2; | 618 void* source2 = &source2; |
| 637 | 619 |
| 638 bool called1 = false; | 620 bool called1 = false; |
| 639 std::unique_ptr<CopyOutputRequest> request; | 621 std::unique_ptr<CopyOutputRequest> request; |
| 640 request = CopyOutputRequest::CreateRequest( | 622 request = CopyOutputRequest::CreateRequest( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 667 | 649 |
| 668 factory_->Destroy(local_frame_id_); | 650 factory_->Destroy(local_frame_id_); |
| 669 local_frame_id_ = LocalFrameId(); | 651 local_frame_id_ = LocalFrameId(); |
| 670 EXPECT_TRUE(called1); | 652 EXPECT_TRUE(called1); |
| 671 EXPECT_TRUE(called2); | 653 EXPECT_TRUE(called2); |
| 672 EXPECT_TRUE(called3); | 654 EXPECT_TRUE(called3); |
| 673 } | 655 } |
| 674 | 656 |
| 675 } // namespace | 657 } // namespace |
| 676 } // namespace cc | 658 } // namespace cc |
| OLD | NEW |