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

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

Issue 2824053003: Split SurfaceFactoryClient Into Four Interfaces (Closed)
Patch Set: Address Nits 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
« no previous file with comments | « cc/surfaces/surface_factory_client.h ('k') | cc/surfaces/surface_manager.h » ('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 "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"
25 #include "cc/test/fake_surface_resource_holder_client.h"
23 #include "cc/test/scheduler_test_common.h" 26 #include "cc/test/scheduler_test_common.h"
27 #include "cc/test/stub_surface_factory_client.h"
24 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/gfx/geometry/size.h" 29 #include "ui/gfx/geometry/size.h"
26 30
27 namespace cc { 31 namespace cc {
28 namespace { 32 namespace {
29 33
30 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); 34 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1);
31 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2); 35 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2);
32 static const base::UnguessableToken kArbitraryToken = 36 static const base::UnguessableToken kArbitraryToken =
33 base::UnguessableToken::Create(); 37 base::UnguessableToken::Create();
34 static auto kArbitrarySourceId1 = 38 static auto kArbitrarySourceId1 =
35 base::UnguessableToken::Deserialize(0xdead, 0xbeef); 39 base::UnguessableToken::Deserialize(0xdead, 0xbeef);
36 static auto kArbitrarySourceId2 = 40 static auto kArbitrarySourceId2 =
37 base::UnguessableToken::Deserialize(0xdead, 0xbee0); 41 base::UnguessableToken::Deserialize(0xdead, 0xbee0);
38 42
39 class TestSurfaceFactoryClient : public SurfaceFactoryClient {
40 public:
41 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {}
42 ~TestSurfaceFactoryClient() override {}
43
44 void ReturnResources(const ReturnedResourceArray& resources) override {
45 returned_resources_.insert(
46 returned_resources_.end(), resources.begin(), resources.end());
47 }
48
49 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {
50 begin_frame_source_ = begin_frame_source;
51 }
52
53 const ReturnedResourceArray& returned_resources() const {
54 return returned_resources_;
55 }
56
57 void clear_returned_resources() { returned_resources_.clear(); }
58
59 BeginFrameSource* begin_frame_source() const { return begin_frame_source_; }
60
61 private:
62 ReturnedResourceArray returned_resources_;
63 BeginFrameSource* begin_frame_source_;
64
65 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient);
66 };
67
68 gpu::SyncToken GenTestSyncToken(int id) { 43 gpu::SyncToken GenTestSyncToken(int id) {
69 gpu::SyncToken token; 44 gpu::SyncToken token;
70 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, 45 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0,
71 gpu::CommandBufferId::FromUnsafeValue(id), 1); 46 gpu::CommandBufferId::FromUnsafeValue(id), 1);
72 return token; 47 return token;
73 } 48 }
74 49
75 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { 50 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver {
76 public: 51 public:
77 SurfaceFactoryTest() 52 SurfaceFactoryTest()
78 : factory_( 53 : factory_(new SurfaceFactory(kArbitraryFrameSinkId,
79 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), 54 &manager_,
55 &stub_surface_factory_client_,
56 &fake_surface_resource_holder_client_)),
80 local_surface_id_(3, kArbitraryToken), 57 local_surface_id_(3, kArbitraryToken),
81 frame_sync_token_(GenTestSyncToken(4)), 58 frame_sync_token_(GenTestSyncToken(4)),
82 consumer_sync_token_(GenTestSyncToken(5)) { 59 consumer_sync_token_(GenTestSyncToken(5)) {
83 manager_.AddObserver(this); 60 manager_.AddObserver(this);
84 } 61 }
85 62
86 const SurfaceId& last_created_surface_id() const { 63 const SurfaceId& last_created_surface_id() const {
87 return last_created_surface_id_; 64 return last_created_surface_id_;
88 } 65 }
89 66
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 unref_array.push_back(resource); 108 unref_array.push_back(resource);
132 } 109 }
133 factory_->UnrefResources(unref_array); 110 factory_->UnrefResources(unref_array);
134 } 111 }
135 112
136 void CheckReturnedResourcesMatchExpected(ResourceId* expected_returned_ids, 113 void CheckReturnedResourcesMatchExpected(ResourceId* expected_returned_ids,
137 int* expected_returned_counts, 114 int* expected_returned_counts,
138 size_t expected_resources, 115 size_t expected_resources,
139 gpu::SyncToken expected_sync_token) { 116 gpu::SyncToken expected_sync_token) {
140 const ReturnedResourceArray& actual_resources = 117 const ReturnedResourceArray& actual_resources =
141 client_.returned_resources(); 118 fake_surface_resource_holder_client_.returned_resources();
142 ASSERT_EQ(expected_resources, actual_resources.size()); 119 ASSERT_EQ(expected_resources, actual_resources.size());
143 for (size_t i = 0; i < expected_resources; ++i) { 120 for (size_t i = 0; i < expected_resources; ++i) {
144 ReturnedResource resource = actual_resources[i]; 121 ReturnedResource resource = actual_resources[i];
145 EXPECT_EQ(expected_sync_token, resource.sync_token); 122 EXPECT_EQ(expected_sync_token, resource.sync_token);
146 EXPECT_EQ(expected_returned_ids[i], resource.id); 123 EXPECT_EQ(expected_returned_ids[i], resource.id);
147 EXPECT_EQ(expected_returned_counts[i], resource.count); 124 EXPECT_EQ(expected_returned_counts[i], resource.count);
148 } 125 }
149 client_.clear_returned_resources(); 126 fake_surface_resource_holder_client_.clear_returned_resources();
150 } 127 }
151 128
152 void RefCurrentFrameResources() { 129 void RefCurrentFrameResources() {
153 Surface* surface = manager_.GetSurfaceForId( 130 Surface* surface = manager_.GetSurfaceForId(
154 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); 131 SurfaceId(factory_->frame_sink_id(), local_surface_id_));
155 factory_->RefResources(surface->GetActiveFrame().resource_list); 132 factory_->RefResources(surface->GetActiveFrame().resource_list);
156 } 133 }
157 134
158 protected: 135 protected:
159 SurfaceManager manager_; 136 SurfaceManager manager_;
160 TestSurfaceFactoryClient client_; 137 StubSurfaceFactoryClient stub_surface_factory_client_;
138 FakeSurfaceResourceHolderClient fake_surface_resource_holder_client_;
161 std::unique_ptr<SurfaceFactory> factory_; 139 std::unique_ptr<SurfaceFactory> factory_;
162 LocalSurfaceId local_surface_id_; 140 LocalSurfaceId local_surface_id_;
163 SurfaceId last_created_surface_id_; 141 SurfaceId last_created_surface_id_;
164 SurfaceInfo last_surface_info_; 142 SurfaceInfo last_surface_info_;
165 143
166 // This is the sync token submitted with the frame. It should never be 144 // This is the sync token submitted with the frame. It should never be
167 // returned to the client. 145 // returned to the client.
168 const gpu::SyncToken frame_sync_token_; 146 const gpu::SyncToken frame_sync_token_;
169 147
170 // This is the sync token returned by the consumer. It should always be 148 // This is the sync token returned by the consumer. It should always be
171 // returned to the client. 149 // returned to the client.
172 const gpu::SyncToken consumer_sync_token_; 150 const gpu::SyncToken consumer_sync_token_;
173 }; 151 };
174 152
175 // Tests submitting a frame with resources followed by one with no resources 153 // Tests submitting a frame with resources followed by one with no resources
176 // with no resource provider action in between. 154 // with no resource provider action in between.
177 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) { 155 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) {
178 ResourceId first_frame_ids[] = {1, 2, 3}; 156 ResourceId first_frame_ids[] = {1, 2, 3};
179 SubmitCompositorFrameWithResources(first_frame_ids, 157 SubmitCompositorFrameWithResources(first_frame_ids,
180 arraysize(first_frame_ids)); 158 arraysize(first_frame_ids));
181 159
182 // All of the resources submitted in the first frame are still in use at this 160 // All of the resources submitted in the first frame are still in use at this
183 // time by virtue of being in the pending frame, so none can be returned to 161 // time by virtue of being in the pending frame, so none can be returned to
184 // the client yet. 162 // the client yet.
185 EXPECT_EQ(0u, client_.returned_resources().size()); 163 EXPECT_EQ(0u,
186 client_.clear_returned_resources(); 164 fake_surface_resource_holder_client_.returned_resources().size());
165 fake_surface_resource_holder_client_.clear_returned_resources();
187 166
188 // The second frame references no resources of first frame and thus should 167 // The second frame references no resources of first frame and thus should
189 // make all resources of first frame available to be returned. 168 // make all resources of first frame available to be returned.
190 SubmitCompositorFrameWithResources(NULL, 0); 169 SubmitCompositorFrameWithResources(NULL, 0);
191 170
192 ResourceId expected_returned_ids[] = {1, 2, 3}; 171 ResourceId expected_returned_ids[] = {1, 2, 3};
193 int expected_returned_counts[] = {1, 1, 1}; 172 int expected_returned_counts[] = {1, 1, 1};
194 // Resources were never consumed so no sync token should be set. 173 // Resources were never consumed so no sync token should be set.
195 CheckReturnedResourcesMatchExpected( 174 CheckReturnedResourcesMatchExpected(
196 expected_returned_ids, expected_returned_counts, 175 expected_returned_ids, expected_returned_counts,
197 arraysize(expected_returned_counts), gpu::SyncToken()); 176 arraysize(expected_returned_counts), gpu::SyncToken());
198 177
199 ResourceId third_frame_ids[] = {4, 5, 6}; 178 ResourceId third_frame_ids[] = {4, 5, 6};
200 SubmitCompositorFrameWithResources(third_frame_ids, 179 SubmitCompositorFrameWithResources(third_frame_ids,
201 arraysize(third_frame_ids)); 180 arraysize(third_frame_ids));
202 181
203 // All of the resources submitted in the third frame are still in use at this 182 // All of the resources submitted in the third frame are still in use at this
204 // time by virtue of being in the pending frame, so none can be returned to 183 // time by virtue of being in the pending frame, so none can be returned to
205 // the client yet. 184 // the client yet.
206 EXPECT_EQ(0u, client_.returned_resources().size()); 185 EXPECT_EQ(0u,
207 client_.clear_returned_resources(); 186 fake_surface_resource_holder_client_.returned_resources().size());
187 fake_surface_resource_holder_client_.clear_returned_resources();
208 188
209 // The forth frame references no resources of third frame and thus should 189 // The forth frame references no resources of third frame and thus should
210 // make all resources of third frame available to be returned. 190 // make all resources of third frame available to be returned.
211 ResourceId forth_frame_ids[] = {7, 8, 9}; 191 ResourceId forth_frame_ids[] = {7, 8, 9};
212 SubmitCompositorFrameWithResources(forth_frame_ids, 192 SubmitCompositorFrameWithResources(forth_frame_ids,
213 arraysize(forth_frame_ids)); 193 arraysize(forth_frame_ids));
214 194
215 ResourceId forth_expected_returned_ids[] = {4, 5, 6}; 195 ResourceId forth_expected_returned_ids[] = {4, 5, 6};
216 int forth_expected_returned_counts[] = {1, 1, 1}; 196 int forth_expected_returned_counts[] = {1, 1, 1};
217 // Resources were never consumed so no sync token should be set. 197 // Resources were never consumed so no sync token should be set.
218 CheckReturnedResourcesMatchExpected( 198 CheckReturnedResourcesMatchExpected(
219 forth_expected_returned_ids, forth_expected_returned_counts, 199 forth_expected_returned_ids, forth_expected_returned_counts,
220 arraysize(forth_expected_returned_counts), gpu::SyncToken()); 200 arraysize(forth_expected_returned_counts), gpu::SyncToken());
221 } 201 }
222 202
223 // Tests submitting a frame with resources followed by one with no resources 203 // Tests submitting a frame with resources followed by one with no resources
224 // with the resource provider holding everything alive. 204 // with the resource provider holding everything alive.
225 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimpleWithProviderHoldingAlive) { 205 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimpleWithProviderHoldingAlive) {
226 ResourceId first_frame_ids[] = {1, 2, 3}; 206 ResourceId first_frame_ids[] = {1, 2, 3};
227 SubmitCompositorFrameWithResources(first_frame_ids, 207 SubmitCompositorFrameWithResources(first_frame_ids,
228 arraysize(first_frame_ids)); 208 arraysize(first_frame_ids));
229 209
230 // All of the resources submitted in the first frame are still in use at this 210 // All of the resources submitted in the first frame are still in use at this
231 // time by virtue of being in the pending frame, so none can be returned to 211 // time by virtue of being in the pending frame, so none can be returned to
232 // the client yet. 212 // the client yet.
233 EXPECT_EQ(0u, client_.returned_resources().size()); 213 EXPECT_EQ(0u,
234 client_.clear_returned_resources(); 214 fake_surface_resource_holder_client_.returned_resources().size());
215 fake_surface_resource_holder_client_.clear_returned_resources();
235 216
236 // Hold on to everything. 217 // Hold on to everything.
237 RefCurrentFrameResources(); 218 RefCurrentFrameResources();
238 219
239 // The second frame references no resources and thus should make all resources 220 // The second frame references no resources and thus should make all resources
240 // available to be returned as soon as the resource provider releases them. 221 // available to be returned as soon as the resource provider releases them.
241 SubmitCompositorFrameWithResources(NULL, 0); 222 SubmitCompositorFrameWithResources(NULL, 0);
242 223
243 EXPECT_EQ(0u, client_.returned_resources().size()); 224 EXPECT_EQ(0u,
244 client_.clear_returned_resources(); 225 fake_surface_resource_holder_client_.returned_resources().size());
226 fake_surface_resource_holder_client_.clear_returned_resources();
245 227
246 int release_counts[] = {1, 1, 1}; 228 int release_counts[] = {1, 1, 1};
247 UnrefResources(first_frame_ids, release_counts, arraysize(first_frame_ids)); 229 UnrefResources(first_frame_ids, release_counts, arraysize(first_frame_ids));
248 230
249 ResourceId expected_returned_ids[] = {1, 2, 3}; 231 ResourceId expected_returned_ids[] = {1, 2, 3};
250 int expected_returned_counts[] = {1, 1, 1}; 232 int expected_returned_counts[] = {1, 1, 1};
251 CheckReturnedResourcesMatchExpected( 233 CheckReturnedResourcesMatchExpected(
252 expected_returned_ids, expected_returned_counts, 234 expected_returned_ids, expected_returned_counts,
253 arraysize(expected_returned_counts), consumer_sync_token_); 235 arraysize(expected_returned_counts), consumer_sync_token_);
254 } 236 }
(...skipping 11 matching lines...) Expand all
266 // This references id 7 again. 248 // This references id 7 again.
267 SubmitCompositorFrameWithResources(first_frame_ids, 249 SubmitCompositorFrameWithResources(first_frame_ids,
268 arraysize(first_frame_ids)); 250 arraysize(first_frame_ids));
269 251
270 // This removes it again. 252 // This removes it again.
271 SubmitCompositorFrameWithResources(NULL, 0); 253 SubmitCompositorFrameWithResources(NULL, 0);
272 254
273 // Now it should be returned. 255 // Now it should be returned.
274 // We don't care how many entries are in the returned array for 7, so long as 256 // We don't care how many entries are in the returned array for 7, so long as
275 // the total returned count matches the submitted count. 257 // the total returned count matches the submitted count.
276 const ReturnedResourceArray& returned = client_.returned_resources(); 258 const ReturnedResourceArray& returned =
259 fake_surface_resource_holder_client_.returned_resources();
277 size_t return_count = 0; 260 size_t return_count = 0;
278 for (size_t i = 0; i < returned.size(); ++i) { 261 for (size_t i = 0; i < returned.size(); ++i) {
279 EXPECT_EQ(7u, returned[i].id); 262 EXPECT_EQ(7u, returned[i].id);
280 return_count += returned[i].count; 263 return_count += returned[i].count;
281 } 264 }
282 EXPECT_EQ(2u, return_count); 265 EXPECT_EQ(2u, return_count);
283 } 266 }
284 267
285 // Tests having resources referenced multiple times, as if referenced by 268 // Tests having resources referenced multiple times, as if referenced by
286 // multiple providers. 269 // multiple providers.
(...skipping 12 matching lines...) Expand all
299 282
300 // Ref resources from the second frame 3 times. 283 // Ref resources from the second frame 3 times.
301 RefCurrentFrameResources(); 284 RefCurrentFrameResources();
302 RefCurrentFrameResources(); 285 RefCurrentFrameResources();
303 RefCurrentFrameResources(); 286 RefCurrentFrameResources();
304 287
305 // Submit a frame with no resources to remove all current frame refs from 288 // Submit a frame with no resources to remove all current frame refs from
306 // submitted resources. 289 // submitted resources.
307 SubmitCompositorFrameWithResources(NULL, 0); 290 SubmitCompositorFrameWithResources(NULL, 0);
308 291
309 EXPECT_EQ(0u, client_.returned_resources().size()); 292 EXPECT_EQ(0u,
310 client_.clear_returned_resources(); 293 fake_surface_resource_holder_client_.returned_resources().size());
294 fake_surface_resource_holder_client_.clear_returned_resources();
311 295
312 // Expected current refs: 296 // Expected current refs:
313 // 3 -> 2 297 // 3 -> 2
314 // 4 -> 2 + 3 = 5 298 // 4 -> 2 + 3 = 5
315 // 5 -> 3 299 // 5 -> 3
316 { 300 {
317 SCOPED_TRACE("unref all 3"); 301 SCOPED_TRACE("unref all 3");
318 ResourceId ids_to_unref[] = {3, 4, 5}; 302 ResourceId ids_to_unref[] = {3, 4, 5};
319 int counts[] = {1, 1, 1}; 303 int counts[] = {1, 1, 1};
320 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 304 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
321 305
322 EXPECT_EQ(0u, client_.returned_resources().size()); 306 EXPECT_EQ(0u,
323 client_.clear_returned_resources(); 307 fake_surface_resource_holder_client_.returned_resources().size());
308 fake_surface_resource_holder_client_.clear_returned_resources();
324 309
325 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 310 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
326 311
327 ResourceId expected_returned_ids[] = {3}; 312 ResourceId expected_returned_ids[] = {3};
328 int expected_returned_counts[] = {1}; 313 int expected_returned_counts[] = {1};
329 CheckReturnedResourcesMatchExpected( 314 CheckReturnedResourcesMatchExpected(
330 expected_returned_ids, expected_returned_counts, 315 expected_returned_ids, expected_returned_counts,
331 arraysize(expected_returned_counts), consumer_sync_token_); 316 arraysize(expected_returned_counts), consumer_sync_token_);
332 } 317 }
333 318
(...skipping 30 matching lines...) Expand all
364 } 349 }
365 350
366 TEST_F(SurfaceFactoryTest, ResourceLifetime) { 351 TEST_F(SurfaceFactoryTest, ResourceLifetime) {
367 ResourceId first_frame_ids[] = {1, 2, 3}; 352 ResourceId first_frame_ids[] = {1, 2, 3};
368 SubmitCompositorFrameWithResources(first_frame_ids, 353 SubmitCompositorFrameWithResources(first_frame_ids,
369 arraysize(first_frame_ids)); 354 arraysize(first_frame_ids));
370 355
371 // All of the resources submitted in the first frame are still in use at this 356 // All of the resources submitted in the first frame are still in use at this
372 // time by virtue of being in the pending frame, so none can be returned to 357 // time by virtue of being in the pending frame, so none can be returned to
373 // the client yet. 358 // the client yet.
374 EXPECT_EQ(0u, client_.returned_resources().size()); 359 EXPECT_EQ(0u,
375 client_.clear_returned_resources(); 360 fake_surface_resource_holder_client_.returned_resources().size());
361 fake_surface_resource_holder_client_.clear_returned_resources();
376 362
377 // The second frame references some of the same resources, but some different 363 // The second frame references some of the same resources, but some different
378 // ones. We expect to receive back resource 1 with a count of 1 since it was 364 // ones. We expect to receive back resource 1 with a count of 1 since it was
379 // only referenced by the first frame. 365 // only referenced by the first frame.
380 ResourceId second_frame_ids[] = {2, 3, 4}; 366 ResourceId second_frame_ids[] = {2, 3, 4};
381 SubmitCompositorFrameWithResources(second_frame_ids, 367 SubmitCompositorFrameWithResources(second_frame_ids,
382 arraysize(second_frame_ids)); 368 arraysize(second_frame_ids));
383 369
384 { 370 {
385 SCOPED_TRACE("second frame"); 371 SCOPED_TRACE("second frame");
(...skipping 21 matching lines...) Expand all
407 arraysize(expected_returned_counts), gpu::SyncToken()); 393 arraysize(expected_returned_counts), gpu::SyncToken());
408 } 394 }
409 395
410 // Simulate a ResourceProvider taking a ref on all of the resources. 396 // Simulate a ResourceProvider taking a ref on all of the resources.
411 RefCurrentFrameResources(); 397 RefCurrentFrameResources();
412 398
413 ResourceId fourth_frame_ids[] = {12, 13}; 399 ResourceId fourth_frame_ids[] = {12, 13};
414 SubmitCompositorFrameWithResources(fourth_frame_ids, 400 SubmitCompositorFrameWithResources(fourth_frame_ids,
415 arraysize(fourth_frame_ids)); 401 arraysize(fourth_frame_ids));
416 402
417 EXPECT_EQ(0u, client_.returned_resources().size()); 403 EXPECT_EQ(0u,
404 fake_surface_resource_holder_client_.returned_resources().size());
418 405
419 RefCurrentFrameResources(); 406 RefCurrentFrameResources();
420 407
421 // All resources are still being used by the external reference, so none can 408 // All resources are still being used by the external reference, so none can
422 // be returned to the client. 409 // be returned to the client.
423 EXPECT_EQ(0u, client_.returned_resources().size()); 410 EXPECT_EQ(0u,
411 fake_surface_resource_holder_client_.returned_resources().size());
424 412
425 // Release resources associated with the first RefCurrentFrameResources() call 413 // Release resources associated with the first RefCurrentFrameResources() call
426 // first. 414 // first.
427 { 415 {
428 ResourceId ids_to_unref[] = {10, 11, 12, 13}; 416 ResourceId ids_to_unref[] = {10, 11, 12, 13};
429 int counts[] = {1, 1, 1, 1}; 417 int counts[] = {1, 1, 1, 1};
430 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 418 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
431 } 419 }
432 420
433 { 421 {
434 SCOPED_TRACE("fourth frame, first unref"); 422 SCOPED_TRACE("fourth frame, first unref");
435 ResourceId expected_returned_ids[] = {10, 11}; 423 ResourceId expected_returned_ids[] = {10, 11};
436 int expected_returned_counts[] = {1, 1}; 424 int expected_returned_counts[] = {1, 1};
437 CheckReturnedResourcesMatchExpected( 425 CheckReturnedResourcesMatchExpected(
438 expected_returned_ids, expected_returned_counts, 426 expected_returned_ids, expected_returned_counts,
439 arraysize(expected_returned_counts), consumer_sync_token_); 427 arraysize(expected_returned_counts), consumer_sync_token_);
440 } 428 }
441 429
442 { 430 {
443 ResourceId ids_to_unref[] = {12, 13}; 431 ResourceId ids_to_unref[] = {12, 13};
444 int counts[] = {1, 1}; 432 int counts[] = {1, 1};
445 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 433 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
446 } 434 }
447 435
448 // Resources 12 and 13 are still in use by the current frame, so they 436 // Resources 12 and 13 are still in use by the current frame, so they
449 // shouldn't be available to be returned. 437 // shouldn't be available to be returned.
450 EXPECT_EQ(0u, client_.returned_resources().size()); 438 EXPECT_EQ(0u,
439 fake_surface_resource_holder_client_.returned_resources().size());
451 440
452 // If we submit an empty frame, however, they should become available. 441 // If we submit an empty frame, however, they should become available.
453 SubmitCompositorFrameWithResources(NULL, 0u); 442 SubmitCompositorFrameWithResources(NULL, 0u);
454 443
455 { 444 {
456 SCOPED_TRACE("fourth frame, second unref"); 445 SCOPED_TRACE("fourth frame, second unref");
457 ResourceId expected_returned_ids[] = {12, 13}; 446 ResourceId expected_returned_ids[] = {12, 13};
458 int expected_returned_counts[] = {2, 2}; 447 int expected_returned_counts[] = {2, 2};
459 CheckReturnedResourcesMatchExpected( 448 CheckReturnedResourcesMatchExpected(
460 expected_returned_ids, expected_returned_counts, 449 expected_returned_ids, expected_returned_counts,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 CompositorFrame frame; 502 CompositorFrame frame;
514 frame.resource_list.push_back(resource); 503 frame.resource_list.push_back(resource);
515 uint32_t execute_count = 0; 504 uint32_t execute_count = 0;
516 factory_->SubmitCompositorFrame(local_surface_id, std::move(frame), 505 factory_->SubmitCompositorFrame(local_surface_id, std::move(frame),
517 base::Bind(&DrawCallback, &execute_count), 506 base::Bind(&DrawCallback, &execute_count),
518 SurfaceFactory::WillDrawCallback()); 507 SurfaceFactory::WillDrawCallback());
519 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); 508 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id);
520 local_surface_id_ = LocalSurfaceId(); 509 local_surface_id_ = LocalSurfaceId();
521 510
522 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 511 EXPECT_TRUE(manager_.GetSurfaceForId(id));
523 EXPECT_TRUE(client_.returned_resources().empty()); 512 EXPECT_TRUE(
513 fake_surface_resource_holder_client_.returned_resources().empty());
524 factory_->EvictSurface(); 514 factory_->EvictSurface();
525 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 515 EXPECT_FALSE(manager_.GetSurfaceForId(id));
526 EXPECT_FALSE(client_.returned_resources().empty()); 516 EXPECT_FALSE(
517 fake_surface_resource_holder_client_.returned_resources().empty());
527 EXPECT_EQ(1u, execute_count); 518 EXPECT_EQ(1u, execute_count);
528 } 519 }
529 520
530 // Tests doing an EvictSurface which has unregistered dependency. 521 // Tests doing an EvictSurface which has unregistered dependency.
531 TEST_F(SurfaceFactoryTest, EvictSurfaceDependencyUnRegistered) { 522 TEST_F(SurfaceFactoryTest, EvictSurfaceDependencyUnRegistered) {
532 LocalSurfaceId local_surface_id(7, kArbitraryToken); 523 LocalSurfaceId local_surface_id(7, kArbitraryToken);
533 524
534 TransferableResource resource; 525 TransferableResource resource;
535 resource.id = 1; 526 resource.id = 1;
536 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 527 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
537 CompositorFrame frame; 528 CompositorFrame frame;
538 frame.resource_list.push_back(resource); 529 frame.resource_list.push_back(resource);
539 uint32_t execute_count = 0; 530 uint32_t execute_count = 0;
540 factory_->SubmitCompositorFrame(local_surface_id, std::move(frame), 531 factory_->SubmitCompositorFrame(local_surface_id, std::move(frame),
541 base::Bind(&DrawCallback, &execute_count), 532 base::Bind(&DrawCallback, &execute_count),
542 SurfaceFactory::WillDrawCallback()); 533 SurfaceFactory::WillDrawCallback());
543 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); 534 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id);
544 local_surface_id_ = LocalSurfaceId(); 535 local_surface_id_ = LocalSurfaceId();
545 536
546 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); 537 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id);
547 Surface* surface = manager_.GetSurfaceForId(surface_id); 538 Surface* surface = manager_.GetSurfaceForId(surface_id);
548 surface->AddDestructionDependency( 539 surface->AddDestructionDependency(
549 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); 540 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4));
550 541
551 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id)); 542 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id));
552 EXPECT_TRUE(client_.returned_resources().empty()); 543 EXPECT_TRUE(
544 fake_surface_resource_holder_client_.returned_resources().empty());
553 factory_->EvictSurface(); 545 factory_->EvictSurface();
554 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id)); 546 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id));
555 EXPECT_FALSE(client_.returned_resources().empty()); 547 EXPECT_FALSE(
548 fake_surface_resource_holder_client_.returned_resources().empty());
556 EXPECT_EQ(1u, execute_count); 549 EXPECT_EQ(1u, execute_count);
557 } 550 }
558 551
559 // Tests doing an EvictSurface which has registered dependency. 552 // Tests doing an EvictSurface which has registered dependency.
560 TEST_F(SurfaceFactoryTest, EvictSurfaceDependencyRegistered) { 553 TEST_F(SurfaceFactoryTest, EvictSurfaceDependencyRegistered) {
561 LocalSurfaceId local_surface_id(7, kArbitraryToken); 554 LocalSurfaceId local_surface_id(7, kArbitraryToken);
562 555
563 TransferableResource resource; 556 TransferableResource resource;
564 resource.id = 1; 557 resource.id = 1;
565 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 558 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
566 CompositorFrame frame; 559 CompositorFrame frame;
567 frame.resource_list.push_back(resource); 560 frame.resource_list.push_back(resource);
568 uint32_t execute_count = 0; 561 uint32_t execute_count = 0;
569 factory_->SubmitCompositorFrame(local_surface_id, std::move(frame), 562 factory_->SubmitCompositorFrame(local_surface_id, std::move(frame),
570 base::Bind(&DrawCallback, &execute_count), 563 base::Bind(&DrawCallback, &execute_count),
571 SurfaceFactory::WillDrawCallback()); 564 SurfaceFactory::WillDrawCallback());
572 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id); 565 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id);
573 local_surface_id_ = LocalSurfaceId(); 566 local_surface_id_ = LocalSurfaceId();
574 567
575 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); 568 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId);
576 569
577 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); 570 SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id);
578 Surface* surface = manager_.GetSurfaceForId(surface_id); 571 Surface* surface = manager_.GetSurfaceForId(surface_id);
579 surface->AddDestructionDependency( 572 surface->AddDestructionDependency(
580 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); 573 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4));
581 574
582 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id)); 575 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id));
583 EXPECT_TRUE(client_.returned_resources().empty()); 576 EXPECT_TRUE(
577 fake_surface_resource_holder_client_.returned_resources().empty());
584 factory_->EvictSurface(); 578 factory_->EvictSurface();
585 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id)); 579 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id));
586 EXPECT_TRUE(client_.returned_resources().empty()); 580 EXPECT_TRUE(
581 fake_surface_resource_holder_client_.returned_resources().empty());
587 EXPECT_EQ(0u, execute_count); 582 EXPECT_EQ(0u, execute_count);
588 583
589 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); 584 manager_.SatisfySequence(SurfaceSequence(kAnotherArbitraryFrameSinkId, 4));
590 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id)); 585 EXPECT_FALSE(manager_.GetSurfaceForId(surface_id));
591 EXPECT_FALSE(client_.returned_resources().empty()); 586 EXPECT_FALSE(
587 fake_surface_resource_holder_client_.returned_resources().empty());
592 } 588 }
593 589
594 TEST_F(SurfaceFactoryTest, DestroySequence) { 590 TEST_F(SurfaceFactoryTest, DestroySequence) {
595 LocalSurfaceId local_surface_id2(5, kArbitraryToken); 591 LocalSurfaceId local_surface_id2(5, kArbitraryToken);
596 std::unique_ptr<SurfaceFactory> factory2( 592 std::unique_ptr<SurfaceFactory> factory2(new SurfaceFactory(
597 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); 593 kArbitraryFrameSinkId, &manager_, &stub_surface_factory_client_,
594 &fake_surface_resource_holder_client_));
598 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); 595 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2);
599 factory2->SubmitCompositorFrame(local_surface_id2, CompositorFrame(), 596 factory2->SubmitCompositorFrame(local_surface_id2, CompositorFrame(),
600 SurfaceFactory::DrawCallback(), 597 SurfaceFactory::DrawCallback(),
601 SurfaceFactory::WillDrawCallback()); 598 SurfaceFactory::WillDrawCallback());
602 599
603 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); 600 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId);
604 601
605 // Check that waiting before the sequence is satisfied works. 602 // Check that waiting before the sequence is satisfied works.
606 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 603 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
607 SurfaceSequence(kArbitraryFrameSinkId, 4)); 604 SurfaceSequence(kArbitraryFrameSinkId, 4));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 manager_.InvalidateFrameSinkId(frame_sink_id); 643 manager_.InvalidateFrameSinkId(frame_sink_id);
647 644
648 // Verify that the invalidated namespace caused the unsatisfied sequence 645 // Verify that the invalidated namespace caused the unsatisfied sequence
649 // to be ignored. 646 // to be ignored.
650 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 647 EXPECT_FALSE(manager_.GetSurfaceForId(id));
651 } 648 }
652 649
653 TEST_F(SurfaceFactoryTest, DestroyCycle) { 650 TEST_F(SurfaceFactoryTest, DestroyCycle) {
654 LocalSurfaceId local_surface_id2(5, kArbitraryToken); 651 LocalSurfaceId local_surface_id2(5, kArbitraryToken);
655 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2); 652 SurfaceId id2(kArbitraryFrameSinkId, local_surface_id2);
656 std::unique_ptr<SurfaceFactory> factory2( 653 std::unique_ptr<SurfaceFactory> factory2(new SurfaceFactory(
657 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); 654 kArbitraryFrameSinkId, &manager_, &stub_surface_factory_client_,
655 &fake_surface_resource_holder_client_));
658 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); 656 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId);
659 // Give id2 a frame that references local_surface_id_. 657 // Give id2 a frame that references local_surface_id_.
660 { 658 {
661 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 659 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
662 CompositorFrame frame; 660 CompositorFrame frame;
663 frame.render_pass_list.push_back(std::move(render_pass)); 661 frame.render_pass_list.push_back(std::move(render_pass));
664 frame.metadata.referenced_surfaces.push_back( 662 frame.metadata.referenced_surfaces.push_back(
665 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); 663 SurfaceId(factory_->frame_sink_id(), local_surface_id_));
666 factory2->SubmitCompositorFrame(local_surface_id2, std::move(frame), 664 factory2->SubmitCompositorFrame(local_surface_id2, std::move(frame),
667 SurfaceFactory::DrawCallback(), 665 SurfaceFactory::DrawCallback(),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 SurfaceFactory::DrawCallback(), 771 SurfaceFactory::DrawCallback(),
774 SurfaceFactory::WillDrawCallback()); 772 SurfaceFactory::WillDrawCallback());
775 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_surface_id_); 773 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_surface_id_);
776 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); 774 EXPECT_EQ(expected_surface_id, last_surface_info_.id());
777 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); 775 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor());
778 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); 776 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels());
779 } 777 }
780 778
781 } // namespace 779 } // namespace
782 } // namespace cc 780 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_factory_client.h ('k') | cc/surfaces/surface_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698