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

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

Issue 1144523003: Rename cc::ResourceProvider::ResourceId to cc::ResourceId and move it to its own file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/surfaces/surface_aggregator_unittest.cc ('k') | cc/surfaces/surface_resource_holder.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 "base/bind.h" 5 #include "base/bind.h"
6 #include "cc/output/compositor_frame.h" 6 #include "cc/output/compositor_frame.h"
7 #include "cc/output/delegated_frame_data.h" 7 #include "cc/output/delegated_frame_data.h"
8 #include "cc/resources/resource_provider.h"
8 #include "cc/surfaces/surface.h" 9 #include "cc/surfaces/surface.h"
9 #include "cc/surfaces/surface_factory.h" 10 #include "cc/surfaces/surface_factory.h"
10 #include "cc/surfaces/surface_factory_client.h" 11 #include "cc/surfaces/surface_factory_client.h"
11 #include "cc/surfaces/surface_manager.h" 12 #include "cc/surfaces/surface_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/geometry/size.h" 14 #include "ui/gfx/geometry/size.h"
14 15
15 namespace cc { 16 namespace cc {
16 namespace { 17 namespace {
17 18
(...skipping 23 matching lines...) Expand all
41 public: 42 public:
42 SurfaceFactoryTest() : factory_(&manager_, &client_), surface_id_(3) { 43 SurfaceFactoryTest() : factory_(&manager_, &client_), surface_id_(3) {
43 factory_.Create(surface_id_); 44 factory_.Create(surface_id_);
44 } 45 }
45 46
46 ~SurfaceFactoryTest() override { 47 ~SurfaceFactoryTest() override {
47 if (!surface_id_.is_null()) 48 if (!surface_id_.is_null())
48 factory_.Destroy(surface_id_); 49 factory_.Destroy(surface_id_);
49 } 50 }
50 51
51 void SubmitFrameWithResources(ResourceProvider::ResourceId* resource_ids, 52 void SubmitFrameWithResources(ResourceId* resource_ids,
52 size_t num_resource_ids) { 53 size_t num_resource_ids) {
53 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 54 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
54 for (size_t i = 0u; i < num_resource_ids; ++i) { 55 for (size_t i = 0u; i < num_resource_ids; ++i) {
55 TransferableResource resource; 56 TransferableResource resource;
56 resource.id = resource_ids[i]; 57 resource.id = resource_ids[i];
57 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 58 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
58 frame_data->resource_list.push_back(resource); 59 frame_data->resource_list.push_back(resource);
59 } 60 }
60 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 61 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
61 frame->delegated_frame_data = frame_data.Pass(); 62 frame->delegated_frame_data = frame_data.Pass();
62 factory_.SubmitFrame(surface_id_, frame.Pass(), 63 factory_.SubmitFrame(surface_id_, frame.Pass(),
63 SurfaceFactory::DrawCallback()); 64 SurfaceFactory::DrawCallback());
64 } 65 }
65 66
66 void UnrefResources(ResourceProvider::ResourceId* ids_to_unref, 67 void UnrefResources(ResourceId* ids_to_unref,
67 int* counts_to_unref, 68 int* counts_to_unref,
68 size_t num_ids_to_unref) { 69 size_t num_ids_to_unref) {
69 ReturnedResourceArray unref_array; 70 ReturnedResourceArray unref_array;
70 for (size_t i = 0; i < num_ids_to_unref; ++i) { 71 for (size_t i = 0; i < num_ids_to_unref; ++i) {
71 ReturnedResource resource; 72 ReturnedResource resource;
72 resource.id = ids_to_unref[i]; 73 resource.id = ids_to_unref[i];
73 resource.count = counts_to_unref[i]; 74 resource.count = counts_to_unref[i];
74 unref_array.push_back(resource); 75 unref_array.push_back(resource);
75 } 76 }
76 factory_.UnrefResources(unref_array); 77 factory_.UnrefResources(unref_array);
77 } 78 }
78 79
79 void CheckReturnedResourcesMatchExpected( 80 void CheckReturnedResourcesMatchExpected(ResourceId* expected_returned_ids,
80 ResourceProvider::ResourceId* expected_returned_ids, 81 int* expected_returned_counts,
81 int* expected_returned_counts, 82 size_t expected_resources) {
82 size_t expected_resources) {
83 const ReturnedResourceArray& actual_resources = 83 const ReturnedResourceArray& actual_resources =
84 client_.returned_resources(); 84 client_.returned_resources();
85 ASSERT_EQ(expected_resources, actual_resources.size()); 85 ASSERT_EQ(expected_resources, actual_resources.size());
86 for (size_t i = 0; i < expected_resources; ++i) { 86 for (size_t i = 0; i < expected_resources; ++i) {
87 ReturnedResource resource = actual_resources[i]; 87 ReturnedResource resource = actual_resources[i];
88 EXPECT_EQ(expected_returned_ids[i], resource.id); 88 EXPECT_EQ(expected_returned_ids[i], resource.id);
89 EXPECT_EQ(expected_returned_counts[i], resource.count); 89 EXPECT_EQ(expected_returned_counts[i], resource.count);
90 } 90 }
91 client_.clear_returned_resources(); 91 client_.clear_returned_resources();
92 } 92 }
93 93
94 void RefCurrentFrameResources() { 94 void RefCurrentFrameResources() {
95 Surface* surface = manager_.GetSurfaceForId(surface_id_); 95 Surface* surface = manager_.GetSurfaceForId(surface_id_);
96 factory_.RefResources( 96 factory_.RefResources(
97 surface->GetEligibleFrame()->delegated_frame_data->resource_list); 97 surface->GetEligibleFrame()->delegated_frame_data->resource_list);
98 } 98 }
99 99
100 protected: 100 protected:
101 SurfaceManager manager_; 101 SurfaceManager manager_;
102 TestSurfaceFactoryClient client_; 102 TestSurfaceFactoryClient client_;
103 SurfaceFactory factory_; 103 SurfaceFactory factory_;
104 SurfaceId surface_id_; 104 SurfaceId surface_id_;
105 }; 105 };
106 106
107 // Tests submitting a frame with resources followed by one with no resources 107 // Tests submitting a frame with resources followed by one with no resources
108 // with no resource provider action in between. 108 // with no resource provider action in between.
109 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) { 109 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) {
110 ResourceProvider::ResourceId first_frame_ids[] = {1, 2, 3}; 110 ResourceId first_frame_ids[] = {1, 2, 3};
111 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids)); 111 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids));
112 112
113 // All of the resources submitted in the first frame are still in use at this 113 // All of the resources submitted in the first frame are still in use at this
114 // time by virtue of being in the pending frame, so none can be returned to 114 // time by virtue of being in the pending frame, so none can be returned to
115 // the client yet. 115 // the client yet.
116 EXPECT_EQ(0u, client_.returned_resources().size()); 116 EXPECT_EQ(0u, client_.returned_resources().size());
117 client_.clear_returned_resources(); 117 client_.clear_returned_resources();
118 118
119 // The second frame references no resources and thus should make all resources 119 // The second frame references no resources and thus should make all resources
120 // available to be returned. 120 // available to be returned.
121 SubmitFrameWithResources(NULL, 0); 121 SubmitFrameWithResources(NULL, 0);
122 122
123 ResourceProvider::ResourceId expected_returned_ids[] = {1, 2, 3}; 123 ResourceId expected_returned_ids[] = {1, 2, 3};
124 int expected_returned_counts[] = {1, 1, 1}; 124 int expected_returned_counts[] = {1, 1, 1};
125 CheckReturnedResourcesMatchExpected(expected_returned_ids, 125 CheckReturnedResourcesMatchExpected(expected_returned_ids,
126 expected_returned_counts, 126 expected_returned_counts,
127 arraysize(expected_returned_counts)); 127 arraysize(expected_returned_counts));
128 } 128 }
129 129
130 // Tests submitting a frame with resources followed by one with no resources 130 // Tests submitting a frame with resources followed by one with no resources
131 // with the resource provider holding everything alive. 131 // with the resource provider holding everything alive.
132 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimpleWithProviderHoldingAlive) { 132 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimpleWithProviderHoldingAlive) {
133 ResourceProvider::ResourceId first_frame_ids[] = {1, 2, 3}; 133 ResourceId first_frame_ids[] = {1, 2, 3};
134 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids)); 134 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids));
135 135
136 // All of the resources submitted in the first frame are still in use at this 136 // All of the resources submitted in the first frame are still in use at this
137 // time by virtue of being in the pending frame, so none can be returned to 137 // time by virtue of being in the pending frame, so none can be returned to
138 // the client yet. 138 // the client yet.
139 EXPECT_EQ(0u, client_.returned_resources().size()); 139 EXPECT_EQ(0u, client_.returned_resources().size());
140 client_.clear_returned_resources(); 140 client_.clear_returned_resources();
141 141
142 // Hold on to everything. 142 // Hold on to everything.
143 RefCurrentFrameResources(); 143 RefCurrentFrameResources();
144 144
145 // The second frame references no resources and thus should make all resources 145 // The second frame references no resources and thus should make all resources
146 // available to be returned as soon as the resource provider releases them. 146 // available to be returned as soon as the resource provider releases them.
147 SubmitFrameWithResources(NULL, 0); 147 SubmitFrameWithResources(NULL, 0);
148 148
149 EXPECT_EQ(0u, client_.returned_resources().size()); 149 EXPECT_EQ(0u, client_.returned_resources().size());
150 client_.clear_returned_resources(); 150 client_.clear_returned_resources();
151 151
152 int release_counts[] = {1, 1, 1}; 152 int release_counts[] = {1, 1, 1};
153 UnrefResources(first_frame_ids, release_counts, arraysize(first_frame_ids)); 153 UnrefResources(first_frame_ids, release_counts, arraysize(first_frame_ids));
154 154
155 ResourceProvider::ResourceId expected_returned_ids[] = {1, 2, 3}; 155 ResourceId expected_returned_ids[] = {1, 2, 3};
156 int expected_returned_counts[] = {1, 1, 1}; 156 int expected_returned_counts[] = {1, 1, 1};
157 CheckReturnedResourcesMatchExpected(expected_returned_ids, 157 CheckReturnedResourcesMatchExpected(expected_returned_ids,
158 expected_returned_counts, 158 expected_returned_counts,
159 arraysize(expected_returned_counts)); 159 arraysize(expected_returned_counts));
160 } 160 }
161 161
162 // Tests referencing a resource, unref'ing it to zero, then using it again 162 // Tests referencing a resource, unref'ing it to zero, then using it again
163 // before returning it to the client. 163 // before returning it to the client.
164 TEST_F(SurfaceFactoryTest, ResourceReusedBeforeReturn) { 164 TEST_F(SurfaceFactoryTest, ResourceReusedBeforeReturn) {
165 ResourceProvider::ResourceId first_frame_ids[] = {7}; 165 ResourceId first_frame_ids[] = {7};
166 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids)); 166 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids));
167 167
168 // This removes all references to resource id 7. 168 // This removes all references to resource id 7.
169 SubmitFrameWithResources(NULL, 0); 169 SubmitFrameWithResources(NULL, 0);
170 170
171 // This references id 7 again. 171 // This references id 7 again.
172 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids)); 172 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids));
173 173
174 // This removes it again. 174 // This removes it again.
175 SubmitFrameWithResources(NULL, 0); 175 SubmitFrameWithResources(NULL, 0);
176 176
177 // Now it should be returned. 177 // Now it should be returned.
178 // We don't care how many entries are in the returned array for 7, so long as 178 // We don't care how many entries are in the returned array for 7, so long as
179 // the total returned count matches the submitted count. 179 // the total returned count matches the submitted count.
180 const ReturnedResourceArray& returned = client_.returned_resources(); 180 const ReturnedResourceArray& returned = client_.returned_resources();
181 size_t return_count = 0; 181 size_t return_count = 0;
182 for (size_t i = 0; i < returned.size(); ++i) { 182 for (size_t i = 0; i < returned.size(); ++i) {
183 EXPECT_EQ(7u, returned[i].id); 183 EXPECT_EQ(7u, returned[i].id);
184 return_count += returned[i].count; 184 return_count += returned[i].count;
185 } 185 }
186 EXPECT_EQ(2u, return_count); 186 EXPECT_EQ(2u, return_count);
187 } 187 }
188 188
189 // Tests having resources referenced multiple times, as if referenced by 189 // Tests having resources referenced multiple times, as if referenced by
190 // multiple providers. 190 // multiple providers.
191 TEST_F(SurfaceFactoryTest, ResourceRefMultipleTimes) { 191 TEST_F(SurfaceFactoryTest, ResourceRefMultipleTimes) {
192 ResourceProvider::ResourceId first_frame_ids[] = {3, 4}; 192 ResourceId first_frame_ids[] = {3, 4};
193 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids)); 193 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids));
194 194
195 // Ref resources from the first frame twice. 195 // Ref resources from the first frame twice.
196 RefCurrentFrameResources(); 196 RefCurrentFrameResources();
197 RefCurrentFrameResources(); 197 RefCurrentFrameResources();
198 198
199 ResourceProvider::ResourceId second_frame_ids[] = {4, 5}; 199 ResourceId second_frame_ids[] = {4, 5};
200 SubmitFrameWithResources(second_frame_ids, arraysize(second_frame_ids)); 200 SubmitFrameWithResources(second_frame_ids, arraysize(second_frame_ids));
201 201
202 // Ref resources from the second frame 3 times. 202 // Ref resources from the second frame 3 times.
203 RefCurrentFrameResources(); 203 RefCurrentFrameResources();
204 RefCurrentFrameResources(); 204 RefCurrentFrameResources();
205 RefCurrentFrameResources(); 205 RefCurrentFrameResources();
206 206
207 // Submit a frame with no resources to remove all current frame refs from 207 // Submit a frame with no resources to remove all current frame refs from
208 // submitted resources. 208 // submitted resources.
209 SubmitFrameWithResources(NULL, 0); 209 SubmitFrameWithResources(NULL, 0);
210 210
211 EXPECT_EQ(0u, client_.returned_resources().size()); 211 EXPECT_EQ(0u, client_.returned_resources().size());
212 client_.clear_returned_resources(); 212 client_.clear_returned_resources();
213 213
214 // Expected current refs: 214 // Expected current refs:
215 // 3 -> 2 215 // 3 -> 2
216 // 4 -> 2 + 3 = 5 216 // 4 -> 2 + 3 = 5
217 // 5 -> 3 217 // 5 -> 3
218 { 218 {
219 SCOPED_TRACE("unref all 3"); 219 SCOPED_TRACE("unref all 3");
220 ResourceProvider::ResourceId ids_to_unref[] = {3, 4, 5}; 220 ResourceId ids_to_unref[] = {3, 4, 5};
221 int counts[] = {1, 1, 1}; 221 int counts[] = {1, 1, 1};
222 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 222 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
223 223
224 EXPECT_EQ(0u, client_.returned_resources().size()); 224 EXPECT_EQ(0u, client_.returned_resources().size());
225 client_.clear_returned_resources(); 225 client_.clear_returned_resources();
226 226
227 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 227 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
228 228
229 ResourceProvider::ResourceId expected_returned_ids[] = {3}; 229 ResourceId expected_returned_ids[] = {3};
230 int expected_returned_counts[] = {1}; 230 int expected_returned_counts[] = {1};
231 CheckReturnedResourcesMatchExpected(expected_returned_ids, 231 CheckReturnedResourcesMatchExpected(expected_returned_ids,
232 expected_returned_counts, 232 expected_returned_counts,
233 arraysize(expected_returned_counts)); 233 arraysize(expected_returned_counts));
234 } 234 }
235 235
236 // Expected refs remaining: 236 // Expected refs remaining:
237 // 4 -> 3 237 // 4 -> 3
238 // 5 -> 1 238 // 5 -> 1
239 { 239 {
240 SCOPED_TRACE("unref 4 and 5"); 240 SCOPED_TRACE("unref 4 and 5");
241 ResourceProvider::ResourceId ids_to_unref[] = {4, 5}; 241 ResourceId ids_to_unref[] = {4, 5};
242 int counts[] = {1, 1}; 242 int counts[] = {1, 1};
243 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 243 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
244 244
245 ResourceProvider::ResourceId expected_returned_ids[] = {5}; 245 ResourceId expected_returned_ids[] = {5};
246 int expected_returned_counts[] = {1}; 246 int expected_returned_counts[] = {1};
247 CheckReturnedResourcesMatchExpected(expected_returned_ids, 247 CheckReturnedResourcesMatchExpected(expected_returned_ids,
248 expected_returned_counts, 248 expected_returned_counts,
249 arraysize(expected_returned_counts)); 249 arraysize(expected_returned_counts));
250 } 250 }
251 251
252 // Now, just 2 refs remaining on resource 4. Unref both at once and make sure 252 // Now, just 2 refs remaining on resource 4. Unref both at once and make sure
253 // the returned count is correct. 253 // the returned count is correct.
254 { 254 {
255 SCOPED_TRACE("unref only 4"); 255 SCOPED_TRACE("unref only 4");
256 ResourceProvider::ResourceId ids_to_unref[] = {4}; 256 ResourceId ids_to_unref[] = {4};
257 int counts[] = {2}; 257 int counts[] = {2};
258 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 258 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
259 259
260 ResourceProvider::ResourceId expected_returned_ids[] = {4}; 260 ResourceId expected_returned_ids[] = {4};
261 int expected_returned_counts[] = {2}; 261 int expected_returned_counts[] = {2};
262 CheckReturnedResourcesMatchExpected(expected_returned_ids, 262 CheckReturnedResourcesMatchExpected(expected_returned_ids,
263 expected_returned_counts, 263 expected_returned_counts,
264 arraysize(expected_returned_counts)); 264 arraysize(expected_returned_counts));
265 } 265 }
266 } 266 }
267 267
268 TEST_F(SurfaceFactoryTest, ResourceLifetime) { 268 TEST_F(SurfaceFactoryTest, ResourceLifetime) {
269 ResourceProvider::ResourceId first_frame_ids[] = {1, 2, 3}; 269 ResourceId first_frame_ids[] = {1, 2, 3};
270 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids)); 270 SubmitFrameWithResources(first_frame_ids, arraysize(first_frame_ids));
271 271
272 // All of the resources submitted in the first frame are still in use at this 272 // All of the resources submitted in the first frame are still in use at this
273 // time by virtue of being in the pending frame, so none can be returned to 273 // time by virtue of being in the pending frame, so none can be returned to
274 // the client yet. 274 // the client yet.
275 EXPECT_EQ(0u, client_.returned_resources().size()); 275 EXPECT_EQ(0u, client_.returned_resources().size());
276 client_.clear_returned_resources(); 276 client_.clear_returned_resources();
277 277
278 // The second frame references some of the same resources, but some different 278 // The second frame references some of the same resources, but some different
279 // ones. We expect to receive back resource 1 with a count of 1 since it was 279 // ones. We expect to receive back resource 1 with a count of 1 since it was
280 // only referenced by the first frame. 280 // only referenced by the first frame.
281 ResourceProvider::ResourceId second_frame_ids[] = {2, 3, 4}; 281 ResourceId second_frame_ids[] = {2, 3, 4};
282 SubmitFrameWithResources(second_frame_ids, arraysize(second_frame_ids)); 282 SubmitFrameWithResources(second_frame_ids, arraysize(second_frame_ids));
283 283
284 { 284 {
285 SCOPED_TRACE("second frame"); 285 SCOPED_TRACE("second frame");
286 ResourceProvider::ResourceId expected_returned_ids[] = {1}; 286 ResourceId expected_returned_ids[] = {1};
287 int expected_returned_counts[] = {1}; 287 int expected_returned_counts[] = {1};
288 CheckReturnedResourcesMatchExpected(expected_returned_ids, 288 CheckReturnedResourcesMatchExpected(expected_returned_ids,
289 expected_returned_counts, 289 expected_returned_counts,
290 arraysize(expected_returned_counts)); 290 arraysize(expected_returned_counts));
291 } 291 }
292 292
293 // The third frame references a disjoint set of resources, so we expect to 293 // The third frame references a disjoint set of resources, so we expect to
294 // receive back all resources from the first and second frames. Resource IDs 2 294 // receive back all resources from the first and second frames. Resource IDs 2
295 // and 3 will have counts of 2, since they were used in both frames, and 295 // and 3 will have counts of 2, since they were used in both frames, and
296 // resource ID 4 will have a count of 1. 296 // resource ID 4 will have a count of 1.
297 ResourceProvider::ResourceId third_frame_ids[] = {10, 11, 12, 13}; 297 ResourceId third_frame_ids[] = {10, 11, 12, 13};
298 SubmitFrameWithResources(third_frame_ids, arraysize(third_frame_ids)); 298 SubmitFrameWithResources(third_frame_ids, arraysize(third_frame_ids));
299 299
300 { 300 {
301 SCOPED_TRACE("third frame"); 301 SCOPED_TRACE("third frame");
302 ResourceProvider::ResourceId expected_returned_ids[] = {2, 3, 4}; 302 ResourceId expected_returned_ids[] = {2, 3, 4};
303 int expected_returned_counts[] = {2, 2, 1}; 303 int expected_returned_counts[] = {2, 2, 1};
304 CheckReturnedResourcesMatchExpected(expected_returned_ids, 304 CheckReturnedResourcesMatchExpected(expected_returned_ids,
305 expected_returned_counts, 305 expected_returned_counts,
306 arraysize(expected_returned_counts)); 306 arraysize(expected_returned_counts));
307 } 307 }
308 308
309 // Simulate a ResourceProvider taking a ref on all of the resources. 309 // Simulate a ResourceProvider taking a ref on all of the resources.
310 RefCurrentFrameResources(); 310 RefCurrentFrameResources();
311 311
312 ResourceProvider::ResourceId fourth_frame_ids[] = {12, 13}; 312 ResourceId fourth_frame_ids[] = {12, 13};
313 SubmitFrameWithResources(fourth_frame_ids, arraysize(fourth_frame_ids)); 313 SubmitFrameWithResources(fourth_frame_ids, arraysize(fourth_frame_ids));
314 314
315 EXPECT_EQ(0u, client_.returned_resources().size()); 315 EXPECT_EQ(0u, client_.returned_resources().size());
316 316
317 RefCurrentFrameResources(); 317 RefCurrentFrameResources();
318 318
319 // All resources are still being used by the external reference, so none can 319 // All resources are still being used by the external reference, so none can
320 // be returned to the client. 320 // be returned to the client.
321 EXPECT_EQ(0u, client_.returned_resources().size()); 321 EXPECT_EQ(0u, client_.returned_resources().size());
322 322
323 // Release resources associated with the first RefCurrentFrameResources() call 323 // Release resources associated with the first RefCurrentFrameResources() call
324 // first. 324 // first.
325 { 325 {
326 ResourceProvider::ResourceId ids_to_unref[] = {10, 11, 12, 13}; 326 ResourceId ids_to_unref[] = {10, 11, 12, 13};
327 int counts[] = {1, 1, 1, 1}; 327 int counts[] = {1, 1, 1, 1};
328 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 328 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
329 } 329 }
330 330
331 { 331 {
332 SCOPED_TRACE("fourth frame, first unref"); 332 SCOPED_TRACE("fourth frame, first unref");
333 ResourceProvider::ResourceId expected_returned_ids[] = {10, 11}; 333 ResourceId expected_returned_ids[] = {10, 11};
334 int expected_returned_counts[] = {1, 1}; 334 int expected_returned_counts[] = {1, 1};
335 CheckReturnedResourcesMatchExpected(expected_returned_ids, 335 CheckReturnedResourcesMatchExpected(expected_returned_ids,
336 expected_returned_counts, 336 expected_returned_counts,
337 arraysize(expected_returned_counts)); 337 arraysize(expected_returned_counts));
338 } 338 }
339 339
340 { 340 {
341 ResourceProvider::ResourceId ids_to_unref[] = {12, 13}; 341 ResourceId ids_to_unref[] = {12, 13};
342 int counts[] = {1, 1}; 342 int counts[] = {1, 1};
343 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref)); 343 UnrefResources(ids_to_unref, counts, arraysize(ids_to_unref));
344 } 344 }
345 345
346 // Resources 12 and 13 are still in use by the current frame, so they 346 // Resources 12 and 13 are still in use by the current frame, so they
347 // shouldn't be available to be returned. 347 // shouldn't be available to be returned.
348 EXPECT_EQ(0u, client_.returned_resources().size()); 348 EXPECT_EQ(0u, client_.returned_resources().size());
349 349
350 // If we submit an empty frame, however, they should become available. 350 // If we submit an empty frame, however, they should become available.
351 SubmitFrameWithResources(NULL, 0u); 351 SubmitFrameWithResources(NULL, 0u);
352 352
353 { 353 {
354 SCOPED_TRACE("fourth frame, second unref"); 354 SCOPED_TRACE("fourth frame, second unref");
355 ResourceProvider::ResourceId expected_returned_ids[] = {12, 13}; 355 ResourceId expected_returned_ids[] = {12, 13};
356 int expected_returned_counts[] = {2, 2}; 356 int expected_returned_counts[] = {2, 2};
357 CheckReturnedResourcesMatchExpected(expected_returned_ids, 357 CheckReturnedResourcesMatchExpected(expected_returned_ids,
358 expected_returned_counts, 358 expected_returned_counts,
359 arraysize(expected_returned_counts)); 359 arraysize(expected_returned_counts));
360 } 360 }
361 } 361 }
362 362
363 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 363 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
364 SurfaceId surface_id(6); 364 SurfaceId surface_id(6);
365 factory_.Create(surface_id); 365 factory_.Create(surface_id);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 factory_.Create(id2); 429 factory_.Create(id2);
430 DCHECK(manager_.GetSurfaceForId(id2)); 430 DCHECK(manager_.GetSurfaceForId(id2));
431 manager_.GetSurfaceForId(id2) 431 manager_.GetSurfaceForId(id2)
432 ->AddDestructionDependency(SurfaceSequence(0, 6)); 432 ->AddDestructionDependency(SurfaceSequence(0, 6));
433 factory_.Destroy(id2); 433 factory_.Destroy(id2);
434 DCHECK(!manager_.GetSurfaceForId(id2)); 434 DCHECK(!manager_.GetSurfaceForId(id2));
435 } 435 }
436 436
437 } // namespace 437 } // namespace
438 } // namespace cc 438 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_aggregator_unittest.cc ('k') | cc/surfaces/surface_resource_holder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698