Chromium Code Reviews| 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 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "cc/output/compositor_frame.h" | 15 #include "cc/output/compositor_frame.h" |
| 16 #include "cc/output/copy_output_request.h" | 16 #include "cc/output/copy_output_request.h" |
| 17 #include "cc/output/copy_output_result.h" | 17 #include "cc/output/copy_output_result.h" |
| 18 #include "cc/resources/resource_provider.h" | 18 #include "cc/resources/resource_provider.h" |
| 19 #include "cc/surfaces/framesink_manager_client.h" | |
| 19 #include "cc/surfaces/surface.h" | 20 #include "cc/surfaces/surface.h" |
| 20 #include "cc/surfaces/surface_factory_client.h" | 21 #include "cc/surfaces/surface_factory_client.h" |
| 21 #include "cc/surfaces/surface_info.h" | 22 #include "cc/surfaces/surface_info.h" |
| 22 #include "cc/surfaces/surface_manager.h" | 23 #include "cc/surfaces/surface_manager.h" |
| 24 #include "cc/surfaces/surface_resource_holder_client.h" | |
| 23 #include "cc/test/scheduler_test_common.h" | 25 #include "cc/test/scheduler_test_common.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "ui/gfx/geometry/size.h" | 27 #include "ui/gfx/geometry/size.h" |
| 26 | 28 |
| 27 namespace cc { | 29 namespace cc { |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); | 32 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
| 31 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2); | 33 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2); |
| 32 static const base::UnguessableToken kArbitraryToken = | 34 static const base::UnguessableToken kArbitraryToken = |
| 33 base::UnguessableToken::Create(); | 35 base::UnguessableToken::Create(); |
| 34 static auto kArbitrarySourceId1 = | 36 static auto kArbitrarySourceId1 = |
| 35 base::UnguessableToken::Deserialize(0xdead, 0xbeef); | 37 base::UnguessableToken::Deserialize(0xdead, 0xbeef); |
| 36 static auto kArbitrarySourceId2 = | 38 static auto kArbitrarySourceId2 = |
| 37 base::UnguessableToken::Deserialize(0xdead, 0xbee0); | 39 base::UnguessableToken::Deserialize(0xdead, 0xbee0); |
| 38 | 40 |
| 39 class TestSurfaceFactoryClient : public SurfaceFactoryClient { | 41 class TestClient : public SurfaceFactoryClient, |
|
danakj
2017/04/21 15:06:48
also suggest splitting this up. It looks like this
Alex Z.
2017/04/21 18:14:36
I created StubSurfaceFactoryClient and FakeSurface
| |
| 42 public SurfaceResourceHolderClient, | |
| 43 public FrameSinkManagerClient { | |
| 40 public: | 44 public: |
| 41 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {} | 45 TestClient() {} |
| 42 ~TestSurfaceFactoryClient() override {} | 46 ~TestClient() override {} |
| 47 | |
| 48 void ReferencedSurfacesChanged( | |
| 49 const LocalSurfaceId& local_surface_id, | |
| 50 const std::vector<SurfaceId>* active_referenced_surfaces) override {} | |
| 43 | 51 |
| 44 void ReturnResources(const ReturnedResourceArray& resources) override { | 52 void ReturnResources(const ReturnedResourceArray& resources) override { |
| 45 returned_resources_.insert( | 53 returned_resources_.insert(returned_resources_.end(), resources.begin(), |
| 46 returned_resources_.end(), resources.begin(), resources.end()); | 54 resources.end()); |
| 47 } | 55 } |
| 48 | 56 |
| 49 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override { | 57 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} |
| 50 begin_frame_source_ = begin_frame_source; | |
| 51 } | |
| 52 | 58 |
| 53 const ReturnedResourceArray& returned_resources() const { | 59 const ReturnedResourceArray& returned_resources() const { |
| 54 return returned_resources_; | 60 return returned_resources_; |
| 55 } | 61 } |
| 56 | 62 |
| 57 void clear_returned_resources() { returned_resources_.clear(); } | 63 void clear_returned_resources() { returned_resources_.clear(); } |
| 58 | 64 |
| 59 BeginFrameSource* begin_frame_source() const { return begin_frame_source_; } | |
| 60 | |
| 61 private: | 65 private: |
| 62 ReturnedResourceArray returned_resources_; | 66 ReturnedResourceArray returned_resources_; |
| 63 BeginFrameSource* begin_frame_source_; | |
| 64 | 67 |
| 65 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); | 68 DISALLOW_COPY_AND_ASSIGN(TestClient); |
| 66 }; | 69 }; |
| 67 | 70 |
| 68 gpu::SyncToken GenTestSyncToken(int id) { | 71 gpu::SyncToken GenTestSyncToken(int id) { |
| 69 gpu::SyncToken token; | 72 gpu::SyncToken token; |
| 70 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, | 73 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, |
| 71 gpu::CommandBufferId::FromUnsafeValue(id), 1); | 74 gpu::CommandBufferId::FromUnsafeValue(id), 1); |
| 72 return token; | 75 return token; |
| 73 } | 76 } |
| 74 | 77 |
| 75 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { | 78 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { |
| 76 public: | 79 public: |
| 77 SurfaceFactoryTest() | 80 SurfaceFactoryTest() |
| 78 : factory_( | 81 : factory_(new SurfaceFactory(kArbitraryFrameSinkId, |
| 79 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), | 82 &manager_, |
| 83 &client_, | |
| 84 &client_)), | |
| 80 local_surface_id_(3, kArbitraryToken), | 85 local_surface_id_(3, kArbitraryToken), |
| 81 frame_sync_token_(GenTestSyncToken(4)), | 86 frame_sync_token_(GenTestSyncToken(4)), |
| 82 consumer_sync_token_(GenTestSyncToken(5)) { | 87 consumer_sync_token_(GenTestSyncToken(5)) { |
| 83 manager_.AddObserver(this); | 88 manager_.AddObserver(this); |
| 84 } | 89 } |
| 85 | 90 |
| 86 const SurfaceId& last_created_surface_id() const { | 91 const SurfaceId& last_created_surface_id() const { |
| 87 return last_created_surface_id_; | 92 return last_created_surface_id_; |
| 88 } | 93 } |
| 89 | 94 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 } | 155 } |
| 151 | 156 |
| 152 void RefCurrentFrameResources() { | 157 void RefCurrentFrameResources() { |
| 153 Surface* surface = manager_.GetSurfaceForId( | 158 Surface* surface = manager_.GetSurfaceForId( |
| 154 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); | 159 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); |
| 155 factory_->RefResources(surface->GetActiveFrame().resource_list); | 160 factory_->RefResources(surface->GetActiveFrame().resource_list); |
| 156 } | 161 } |
| 157 | 162 |
| 158 protected: | 163 protected: |
| 159 SurfaceManager manager_; | 164 SurfaceManager manager_; |
| 160 TestSurfaceFactoryClient client_; | 165 TestClient client_; |
| 161 std::unique_ptr<SurfaceFactory> factory_; | 166 std::unique_ptr<SurfaceFactory> factory_; |
| 162 LocalSurfaceId local_surface_id_; | 167 LocalSurfaceId local_surface_id_; |
| 163 SurfaceId last_created_surface_id_; | 168 SurfaceId last_created_surface_id_; |
| 164 SurfaceInfo last_surface_info_; | 169 SurfaceInfo last_surface_info_; |
| 165 | 170 |
| 166 // This is the sync token submitted with the frame. It should never be | 171 // This is the sync token submitted with the frame. It should never be |
| 167 // returned to the client. | 172 // returned to the client. |
| 168 const gpu::SyncToken frame_sync_token_; | 173 const gpu::SyncToken frame_sync_token_; |
| 169 | 174 |
| 170 // This is the sync token returned by the consumer. It should always be | 175 // This is the sync token returned by the consumer. It should always be |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 EXPECT_EQ(0u, execute_count); | 592 EXPECT_EQ(0u, execute_count); |
| 588 | 593 |
| 589 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); | 594 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
| 590 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id)); | 595 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id)); |
| 591 EXPECT_FALSE(client_.returned_resources().empty()); | 596 EXPECT_FALSE(client_.returned_resources().empty()); |
| 592 } | 597 } |
| 593 | 598 |
| 594 TEST_F(SurfaceFactoryTest, DestroySequence) { | 599 TEST_F(SurfaceFactoryTest, DestroySequence) { |
| 595 LocalSurfaceId local_surface_id2(5, kArbitraryToken); | 600 LocalSurfaceId local_surface_id2(5, kArbitraryToken); |
| 596 std::unique_ptr<SurfaceFactory> factory2( | 601 std::unique_ptr<SurfaceFactory> factory2( |
| 597 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); | 602 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_, &client_)); |
| 598 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); | 603 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); |
| 599 factory2->SubmitCompositorFrame(local_surface_id2, CompositorFrame(), | 604 factory2->SubmitCompositorFrame(local_surface_id2, CompositorFrame(), |
| 600 SurfaceFactory::DrawCallback(), | 605 SurfaceFactory::DrawCallback(), |
| 601 SurfaceFactory::WillDrawCallback()); | 606 SurfaceFactory::WillDrawCallback()); |
| 602 | 607 |
| 603 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); | 608 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); |
| 604 | 609 |
| 605 // Check that waiting before the sequence is satisfied works. | 610 // Check that waiting before the sequence is satisfied works. |
| 606 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 611 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
| 607 SurfaceSequence(kArbitraryFrameSinkId, 4)); | 612 SurfaceSequence(kArbitraryFrameSinkId, 4)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 | 652 |
| 648 // Verify that the invalidated namespace caused the unsatisfied sequence | 653 // Verify that the invalidated namespace caused the unsatisfied sequence |
| 649 // to be ignored. | 654 // to be ignored. |
| 650 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 655 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
| 651 } | 656 } |
| 652 | 657 |
| 653 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 658 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
| 654 LocalSurfaceId local_surface_id2(5, kArbitraryToken); | 659 LocalSurfaceId local_surface_id2(5, kArbitraryToken); |
| 655 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); | 660 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); |
| 656 std::unique_ptr<SurfaceFactory> factory2( | 661 std::unique_ptr<SurfaceFactory> factory2( |
| 657 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); | 662 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_, &client_)); |
| 658 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); | 663 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); |
| 659 // Give id2 a frame that references local_surface_id_. | 664 // Give id2 a frame that references local_surface_id_. |
| 660 { | 665 { |
| 661 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 666 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 662 CompositorFrame frame; | 667 CompositorFrame frame; |
| 663 frame.render_pass_list.push_back(std::move(render_pass)); | 668 frame.render_pass_list.push_back(std::move(render_pass)); |
| 664 frame.metadata.referenced_surfaces.push_back( | 669 frame.metadata.referenced_surfaces.push_back( |
| 665 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); | 670 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); |
| 666 factory2->SubmitCompositorFrame(local_surface_id2, std::move(frame), | 671 factory2->SubmitCompositorFrame(local_surface_id2, std::move(frame), |
| 667 SurfaceFactory::DrawCallback(), | 672 SurfaceFactory::DrawCallback(), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 SurfaceFactory::DrawCallback(), | 778 SurfaceFactory::DrawCallback(), |
| 774 SurfaceFactory::WillDrawCallback()); | 779 SurfaceFactory::WillDrawCallback()); |
| 775 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_surface_id_); | 780 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_surface_id_); |
| 776 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); | 781 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); |
| 777 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); | 782 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); |
| 778 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); | 783 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); |
| 779 } | 784 } |
| 780 | 785 |
| 781 } // namespace | 786 } // namespace |
| 782 } // namespace cc | 787 } // namespace cc |
| OLD | NEW |