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

Side by Side Diff: cc/layers/surface_layer_unittest.cc

Issue 1996783002: Make cc::SurfaceId unguessable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Ben's comment Created 4 years, 7 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
« no previous file with comments | « cc/layers/surface_layer_impl_unittest.cc ('k') | cc/quads/draw_quad_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // Check that one surface can be referenced by multiple LayerTreeHosts, and 66 // Check that one surface can be referenced by multiple LayerTreeHosts, and
67 // each will create its own SurfaceSequence that's satisfied on destruction. 67 // each will create its own SurfaceSequence that's satisfied on destruction.
68 TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) { 68 TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) {
69 SurfaceSequence blank_change; // Receives sequence if commit doesn't happen. 69 SurfaceSequence blank_change; // Receives sequence if commit doesn't happen.
70 70
71 SurfaceId required_id; 71 SurfaceId required_id;
72 std::set<SurfaceSequence> required_seq; 72 std::set<SurfaceSequence> required_seq;
73 scoped_refptr<SurfaceLayer> layer(SurfaceLayer::Create( 73 scoped_refptr<SurfaceLayer> layer(SurfaceLayer::Create(
74 base::Bind(&SatisfyCallback, &blank_change), 74 base::Bind(&SatisfyCallback, &blank_change),
75 base::Bind(&RequireCallback, &required_id, &required_seq))); 75 base::Bind(&RequireCallback, &required_id, &required_seq)));
76 layer->SetSurfaceId(SurfaceId(1), 1.f, gfx::Size(1, 1)); 76 layer->SetSurfaceId(SurfaceId(0, 1, 0), 1.f, gfx::Size(1, 1));
77 layer_tree_host_->set_surface_id_namespace(1); 77 layer_tree_host_->set_surface_id_namespace(1);
78 layer_tree_host_->SetRootLayer(layer); 78 layer_tree_host_->SetRootLayer(layer);
79 79
80 std::unique_ptr<FakeLayerTreeHost> layer_tree_host2 = 80 std::unique_ptr<FakeLayerTreeHost> layer_tree_host2 =
81 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_); 81 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
82 scoped_refptr<SurfaceLayer> layer2(SurfaceLayer::Create( 82 scoped_refptr<SurfaceLayer> layer2(SurfaceLayer::Create(
83 base::Bind(&SatisfyCallback, &blank_change), 83 base::Bind(&SatisfyCallback, &blank_change),
84 base::Bind(&RequireCallback, &required_id, &required_seq))); 84 base::Bind(&RequireCallback, &required_id, &required_seq)));
85 layer2->SetSurfaceId(SurfaceId(1), 1.f, gfx::Size(1, 1)); 85 layer2->SetSurfaceId(SurfaceId(0, 1, 0), 1.f, gfx::Size(1, 1));
86 layer_tree_host2->set_surface_id_namespace(2); 86 layer_tree_host2->set_surface_id_namespace(2);
87 layer_tree_host2->SetRootLayer(layer2); 87 layer_tree_host2->SetRootLayer(layer2);
88 88
89 // Layers haven't been removed, so no sequence should be satisfied. 89 // Layers haven't been removed, so no sequence should be satisfied.
90 EXPECT_TRUE(blank_change.is_null()); 90 EXPECT_TRUE(blank_change.is_null());
91 91
92 SurfaceSequence expected1(1u, 1u); 92 SurfaceSequence expected1(1u, 1u);
93 SurfaceSequence expected2(2u, 1u); 93 SurfaceSequence expected2(2u, 1u);
94 94
95 layer_tree_host2->SetRootLayer(nullptr); 95 layer_tree_host2->SetRootLayer(nullptr);
96 layer_tree_host2.reset(); 96 layer_tree_host2.reset();
97 97
98 // Layer was removed so sequence from second LayerTreeHost should be 98 // Layer was removed so sequence from second LayerTreeHost should be
99 // satisfied. 99 // satisfied.
100 EXPECT_TRUE(blank_change == expected2); 100 EXPECT_TRUE(blank_change == expected2);
101 101
102 // Set of sequences that need to be satisfied should include sequences from 102 // Set of sequences that need to be satisfied should include sequences from
103 // both trees. 103 // both trees.
104 EXPECT_TRUE(required_id == SurfaceId(1)); 104 EXPECT_TRUE(required_id == SurfaceId(0, 1, 0));
105 EXPECT_EQ(2u, required_seq.size()); 105 EXPECT_EQ(2u, required_seq.size());
106 EXPECT_TRUE(required_seq.count(expected1)); 106 EXPECT_TRUE(required_seq.count(expected1));
107 EXPECT_TRUE(required_seq.count(expected2)); 107 EXPECT_TRUE(required_seq.count(expected2));
108 108
109 layer_tree_host_->SetRootLayer(nullptr); 109 layer_tree_host_->SetRootLayer(nullptr);
110 layer_tree_host_.reset(); 110 layer_tree_host_.reset();
111 111
112 // Layer was removed so sequence from first LayerTreeHost should be 112 // Layer was removed so sequence from first LayerTreeHost should be
113 // satisfied. 113 // satisfied.
114 EXPECT_TRUE(blank_change == expected1); 114 EXPECT_TRUE(blank_change == expected1);
115 115
116 // No more SurfaceSequences should have been generated that need to have be 116 // No more SurfaceSequences should have been generated that need to have be
117 // satisfied. 117 // satisfied.
118 EXPECT_EQ(2u, required_seq.size()); 118 EXPECT_EQ(2u, required_seq.size());
119 } 119 }
120 120
121 // Check that SurfaceSequence is sent through swap promise. 121 // Check that SurfaceSequence is sent through swap promise.
122 class SurfaceLayerSwapPromise : public LayerTreeTest { 122 class SurfaceLayerSwapPromise : public LayerTreeTest {
123 public: 123 public:
124 SurfaceLayerSwapPromise() 124 SurfaceLayerSwapPromise()
125 : commit_count_(0), sequence_was_satisfied_(false) {} 125 : commit_count_(0), sequence_was_satisfied_(false) {}
126 126
127 void BeginTest() override { 127 void BeginTest() override {
128 layer_tree_host()->set_surface_id_namespace(1); 128 layer_tree_host()->set_surface_id_namespace(1);
129 layer_ = SurfaceLayer::Create( 129 layer_ = SurfaceLayer::Create(
130 base::Bind(&SatisfyCallback, &satisfied_sequence_), 130 base::Bind(&SatisfyCallback, &satisfied_sequence_),
131 base::Bind(&RequireCallback, &required_id_, &required_set_)); 131 base::Bind(&RequireCallback, &required_id_, &required_set_));
132 layer_->SetSurfaceId(SurfaceId(1), 1.f, gfx::Size(1, 1)); 132 layer_->SetSurfaceId(SurfaceId(0, 1, 0), 1.f, gfx::Size(1, 1));
133 133
134 // Layer hasn't been added to tree so no SurfaceSequence generated yet. 134 // Layer hasn't been added to tree so no SurfaceSequence generated yet.
135 EXPECT_EQ(0u, required_set_.size()); 135 EXPECT_EQ(0u, required_set_.size());
136 136
137 layer_tree_host()->SetRootLayer(layer_); 137 layer_tree_host()->SetRootLayer(layer_);
138 138
139 // Should have SurfaceSequence from first tree. 139 // Should have SurfaceSequence from first tree.
140 SurfaceSequence expected(1u, 1u); 140 SurfaceSequence expected(1u, 1u);
141 EXPECT_TRUE(required_id_ == SurfaceId(1)); 141 EXPECT_TRUE(required_id_ == SurfaceId(0, 1, 0));
142 EXPECT_EQ(1u, required_set_.size()); 142 EXPECT_EQ(1u, required_set_.size());
143 EXPECT_TRUE(required_set_.count(expected)); 143 EXPECT_TRUE(required_set_.count(expected));
144 144
145 gfx::Size bounds(100, 100); 145 gfx::Size bounds(100, 100);
146 layer_tree_host()->SetViewportSize(bounds); 146 layer_tree_host()->SetViewportSize(bounds);
147 147
148 blank_layer_ = SolidColorLayer::Create(); 148 blank_layer_ = SolidColorLayer::Create();
149 blank_layer_->SetIsDrawable(true); 149 blank_layer_->SetIsDrawable(true);
150 blank_layer_->SetBounds(gfx::Size(10, 10)); 150 blank_layer_->SetBounds(gfx::Size(10, 10));
151 151
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // after the layer was removed from the tree, and only once. 201 // after the layer was removed from the tree, and only once.
202 EXPECT_EQ(1u, satisfied[0]); 202 EXPECT_EQ(1u, satisfied[0]);
203 EXPECT_LE(1, commit_count_); 203 EXPECT_LE(1, commit_count_);
204 EXPECT_FALSE(sequence_was_satisfied_); 204 EXPECT_FALSE(sequence_was_satisfied_);
205 sequence_was_satisfied_ = true; 205 sequence_was_satisfied_ = true;
206 EndTest(); 206 EndTest();
207 } 207 }
208 } 208 }
209 209
210 void AfterTest() override { 210 void AfterTest() override {
211 EXPECT_TRUE(required_id_ == SurfaceId(1)); 211 EXPECT_TRUE(required_id_ == SurfaceId(0, 1, 0));
212 EXPECT_EQ(1u, required_set_.size()); 212 EXPECT_EQ(1u, required_set_.size());
213 // Sequence should have been satisfied through Swap, not with the 213 // Sequence should have been satisfied through Swap, not with the
214 // callback. 214 // callback.
215 EXPECT_TRUE(satisfied_sequence_.is_null()); 215 EXPECT_TRUE(satisfied_sequence_.is_null());
216 } 216 }
217 }; 217 };
218 218
219 // TODO(jbauman): Reenable on single thread once http://crbug.com/421923 is 219 // TODO(jbauman): Reenable on single thread once http://crbug.com/421923 is
220 // fixed. 220 // fixed.
221 MULTI_THREAD_TEST_F(SurfaceLayerSwapPromiseWithDraw); 221 MULTI_THREAD_TEST_F(SurfaceLayerSwapPromiseWithDraw);
(...skipping 20 matching lines...) Expand all
242 case 2: 242 case 2:
243 layer_tree_host()->SetNeedsCommit(); 243 layer_tree_host()->SetNeedsCommit();
244 break; 244 break;
245 default: 245 default:
246 EndTest(); 246 EndTest();
247 break; 247 break;
248 } 248 }
249 } 249 }
250 250
251 void AfterTest() override { 251 void AfterTest() override {
252 EXPECT_TRUE(required_id_ == SurfaceId(1)); 252 EXPECT_TRUE(required_id_ == SurfaceId(0, 1, 0));
253 EXPECT_EQ(1u, required_set_.size()); 253 EXPECT_EQ(1u, required_set_.size());
254 // Sequence should have been satisfied with the callback. 254 // Sequence should have been satisfied with the callback.
255 EXPECT_TRUE(satisfied_sequence_ == SurfaceSequence(1u, 1u)); 255 EXPECT_TRUE(satisfied_sequence_ == SurfaceSequence(1u, 1u));
256 } 256 }
257 }; 257 };
258 258
259 MULTI_THREAD_TEST_F(SurfaceLayerSwapPromiseWithoutDraw); 259 MULTI_THREAD_TEST_F(SurfaceLayerSwapPromiseWithoutDraw);
260 260
261 } // namespace 261 } // namespace
262 } // namespace cc 262 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/surface_layer_impl_unittest.cc ('k') | cc/quads/draw_quad_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698