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

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

Issue 2824053003: Split SurfaceFactoryClient Into Four Interfaces (Closed)
Patch Set: Address Nit Created 3 years, 8 months 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_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/frame_sink_manager_client.h"
19 #include "cc/surfaces/surface.h" 20 #include "cc/surfaces/surface.h"
21 #include "cc/surfaces/surface_aggregator_client.h"
20 #include "cc/surfaces/surface_factory_client.h" 22 #include "cc/surfaces/surface_factory_client.h"
21 #include "cc/surfaces/surface_info.h" 23 #include "cc/surfaces/surface_info.h"
22 #include "cc/surfaces/surface_manager.h" 24 #include "cc/surfaces/surface_manager.h"
25 #include "cc/surfaces/surface_resource_holder_client.h"
23 #include "cc/test/scheduler_test_common.h" 26 #include "cc/test/scheduler_test_common.h"
24 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/gfx/geometry/size.h" 28 #include "ui/gfx/geometry/size.h"
26 29
27 namespace cc { 30 namespace cc {
28 namespace { 31 namespace {
29 32
30 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); 33 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1);
31 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2); 34 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2);
32 static const base::UnguessableToken kArbitraryToken = 35 static const base::UnguessableToken kArbitraryToken =
33 base::UnguessableToken::Create(); 36 base::UnguessableToken::Create();
34 static auto kArbitrarySourceId1 = 37 static auto kArbitrarySourceId1 =
35 base::UnguessableToken::Deserialize(0xdead, 0xbeef); 38 base::UnguessableToken::Deserialize(0xdead, 0xbeef);
36 static auto kArbitrarySourceId2 = 39 static auto kArbitrarySourceId2 =
37 base::UnguessableToken::Deserialize(0xdead, 0xbee0); 40 base::UnguessableToken::Deserialize(0xdead, 0xbee0);
38 41
39 class TestSurfaceFactoryClient : public SurfaceFactoryClient { 42 class TestClient : public SurfaceFactoryClient,
43 public SurfaceResourceHolderClient,
44 public SurfaceAggregatorClient,
45 public FrameSinkManagerClient {
40 public: 46 public:
41 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {} 47 TestClient() {}
42 ~TestSurfaceFactoryClient() override {} 48 ~TestClient() override {}
49
50 void ReferencedSurfacesChanged(
51 const LocalSurfaceId& local_surface_id,
52 const std::vector<SurfaceId>* active_referenced_surfaces) override {}
43 53
44 void ReturnResources(const ReturnedResourceArray& resources) override { 54 void ReturnResources(const ReturnedResourceArray& resources) override {
45 returned_resources_.insert( 55 returned_resources_.insert(returned_resources_.end(), resources.begin(),
46 returned_resources_.end(), resources.begin(), resources.end()); 56 resources.end());
47 } 57 }
48 58
49 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override { 59 void WillDrawSurface(const LocalSurfaceId& local_surface_id,
50 begin_frame_source_ = begin_frame_source; 60 const gfx::Rect& damage_rect) override {}
51 } 61
62 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {}
52 63
53 const ReturnedResourceArray& returned_resources() const { 64 const ReturnedResourceArray& returned_resources() const {
54 return returned_resources_; 65 return returned_resources_;
55 } 66 }
56 67
57 void clear_returned_resources() { returned_resources_.clear(); } 68 void clear_returned_resources() { returned_resources_.clear(); }
58 69
59 BeginFrameSource* begin_frame_source() const { return begin_frame_source_; }
60
61 private: 70 private:
62 ReturnedResourceArray returned_resources_; 71 ReturnedResourceArray returned_resources_;
63 BeginFrameSource* begin_frame_source_;
64 72
65 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); 73 DISALLOW_COPY_AND_ASSIGN(TestClient);
66 }; 74 };
67 75
68 gpu::SyncToken GenTestSyncToken(int id) { 76 gpu::SyncToken GenTestSyncToken(int id) {
69 gpu::SyncToken token; 77 gpu::SyncToken token;
70 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, 78 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0,
71 gpu::CommandBufferId::FromUnsafeValue(id), 1); 79 gpu::CommandBufferId::FromUnsafeValue(id), 1);
72 return token; 80 return token;
73 } 81 }
74 82
75 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { 83 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver {
76 public: 84 public:
77 SurfaceFactoryTest() 85 SurfaceFactoryTest()
78 : factory_( 86 : factory_(new SurfaceFactory(kArbitraryFrameSinkId,
79 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), 87 &manager_,
88 &client_,
89 &client_,
90 &client_)),
80 local_surface_id_(3, kArbitraryToken), 91 local_surface_id_(3, kArbitraryToken),
81 frame_sync_token_(GenTestSyncToken(4)), 92 frame_sync_token_(GenTestSyncToken(4)),
82 consumer_sync_token_(GenTestSyncToken(5)) { 93 consumer_sync_token_(GenTestSyncToken(5)) {
83 manager_.AddObserver(this); 94 manager_.AddObserver(this);
84 } 95 }
85 96
86 const SurfaceId& last_created_surface_id() const { 97 const SurfaceId& last_created_surface_id() const {
87 return last_created_surface_id_; 98 return last_created_surface_id_;
88 } 99 }
89 100
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 160 }
150 161
151 void RefCurrentFrameResources() { 162 void RefCurrentFrameResources() {
152 Surface* surface = manager_.GetSurfaceForId( 163 Surface* surface = manager_.GetSurfaceForId(
153 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); 164 SurfaceId(factory_->frame_sink_id(), local_surface_id_));
154 factory_->RefResources(surface->GetActiveFrame().resource_list); 165 factory_->RefResources(surface->GetActiveFrame().resource_list);
155 } 166 }
156 167
157 protected: 168 protected:
158 SurfaceManager manager_; 169 SurfaceManager manager_;
159 TestSurfaceFactoryClient client_; 170 TestClient client_;
160 std::unique_ptr<SurfaceFactory> factory_; 171 std::unique_ptr<SurfaceFactory> factory_;
161 LocalSurfaceId local_surface_id_; 172 LocalSurfaceId local_surface_id_;
162 SurfaceId last_created_surface_id_; 173 SurfaceId last_created_surface_id_;
163 SurfaceInfo last_surface_info_; 174 SurfaceInfo last_surface_info_;
164 175
165 // This is the sync token submitted with the frame. It should never be 176 // This is the sync token submitted with the frame. It should never be
166 // returned to the client. 177 // returned to the client.
167 const gpu::SyncToken frame_sync_token_; 178 const gpu::SyncToken frame_sync_token_;
168 179
169 // This is the sync token returned by the consumer. It should always be 180 // This is the sync token returned by the consumer. It should always be
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 EXPECT_TRUE(client_.returned_resources().empty()); 590 EXPECT_TRUE(client_.returned_resources().empty());
580 EXPECT_EQ(0u, execute_count); 591 EXPECT_EQ(0u, execute_count);
581 592
582 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); 593 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4));
583 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id)); 594 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id));
584 EXPECT_FALSE(client_.returned_resources().empty()); 595 EXPECT_FALSE(client_.returned_resources().empty());
585 } 596 }
586 597
587 TEST_F(SurfaceFactoryTest, DestroySequence) { 598 TEST_F(SurfaceFactoryTest, DestroySequence) {
588 LocalSurfaceId local_surface_id2(5, kArbitraryToken); 599 LocalSurfaceId local_surface_id2(5, kArbitraryToken);
589 std::unique_ptr<SurfaceFactory> factory2( 600 std::unique_ptr<SurfaceFactory> factory2(new SurfaceFactory(
590 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); 601 kArbitraryFrameSinkId, &manager_, &client_, &client_, &client_));
591 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); 602 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2);
592 factory2->SubmitCompositorFrame(local_surface_id2, CompositorFrame(), 603 factory2->SubmitCompositorFrame(local_surface_id2, CompositorFrame(),
593 SurfaceFactory::DrawCallback()); 604 SurfaceFactory::DrawCallback());
594 605
595 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); 606 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId);
596 607
597 // Check that waiting before the sequence is satisfied works. 608 // Check that waiting before the sequence is satisfied works.
598 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 609 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
599 SurfaceSequence(kArbitraryFrameSinkId, 4)); 610 SurfaceSequence(kArbitraryFrameSinkId, 4));
600 factory2->EvictSurface(); 611 factory2->EvictSurface();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 manager_.InvalidateFrameSinkId(frame_sink_id); 647 manager_.InvalidateFrameSinkId(frame_sink_id);
637 648
638 // Verify that the invalidated namespace caused the unsatisfied sequence 649 // Verify that the invalidated namespace caused the unsatisfied sequence
639 // to be ignored. 650 // to be ignored.
640 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 651 EXPECT_FALSE(manager_.GetSurfaceForId(id));
641 } 652 }
642 653
643 TEST_F(SurfaceFactoryTest, DestroyCycle) { 654 TEST_F(SurfaceFactoryTest, DestroyCycle) {
644 LocalSurfaceId local_surface_id2(5, kArbitraryToken); 655 LocalSurfaceId local_surface_id2(5, kArbitraryToken);
645 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); 656 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2);
646 std::unique_ptr<SurfaceFactory> factory2( 657 std::unique_ptr<SurfaceFactory> factory2(new SurfaceFactory(
647 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); 658 kArbitraryFrameSinkId, &manager_, &client_, &client_, &client_));
648 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); 659 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId);
649 // Give id2 a frame that references local_surface_id_. 660 // Give id2 a frame that references local_surface_id_.
650 { 661 {
651 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 662 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
652 CompositorFrame frame; 663 CompositorFrame frame;
653 frame.render_pass_list.push_back(std::move(render_pass)); 664 frame.render_pass_list.push_back(std::move(render_pass));
654 frame.metadata.referenced_surfaces.push_back( 665 frame.metadata.referenced_surfaces.push_back(
655 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); 666 SurfaceId(factory_->frame_sink_id(), local_surface_id_));
656 factory2->SubmitCompositorFrame(local_surface_id2, std::move(frame), 667 factory2->SubmitCompositorFrame(local_surface_id2, std::move(frame),
657 SurfaceFactory::DrawCallback()); 668 SurfaceFactory::DrawCallback());
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame), 770 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame),
760 SurfaceFactory::DrawCallback()); 771 SurfaceFactory::DrawCallback());
761 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_surface_id_); 772 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_surface_id_);
762 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); 773 EXPECT_EQ(expected_surface_id, last_surface_info_.id());
763 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); 774 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor());
764 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); 775 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels());
765 } 776 }
766 777
767 } // namespace 778 } // namespace
768 } // namespace cc 779 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698