OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #if SK_SUPPORT_GPU | 8 #if SK_SUPPORT_GPU |
9 | 9 |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
11 #include "GrContextFactory.h" | |
12 #include "GrLayerCache.h" | 11 #include "GrLayerCache.h" |
13 #include "GrResourceCache.h" | 12 #include "GrResourceCache.h" |
14 #include "SkPictureRecorder.h" | 13 #include "SkPictureRecorder.h" |
15 #include "Test.h" | 14 #include "Test.h" |
16 | 15 |
17 class TestingAccess { | 16 class TestingAccess { |
18 public: | 17 public: |
19 static int NumPlots() { | 18 static int NumPlots() { |
20 return GrLayerCache::kNumPlotsX * GrLayerCache::kNumPlotsY; | 19 return GrLayerCache::kNumPlotsX * GrLayerCache::kNumPlotsY; |
21 } | 20 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 100 |
102 cache->addUse(layer); | 101 cache->addUse(layer); |
103 | 102 |
104 REPORTER_ASSERT(reporter, 1 == TestingAccess::Uses(layer)); | 103 REPORTER_ASSERT(reporter, 1 == TestingAccess::Uses(layer)); |
105 } | 104 } |
106 | 105 |
107 // This test case exercises the public API of the GrLayerCache class. | 106 // This test case exercises the public API of the GrLayerCache class. |
108 // In particular it checks its interaction with the resource cache (w.r.t. | 107 // In particular it checks its interaction with the resource cache (w.r.t. |
109 // locking & unlocking textures). | 108 // locking & unlocking textures). |
110 // TODO: need to add checks on VRAM usage! | 109 // TODO: need to add checks on VRAM usage! |
111 DEF_GPUTEST(GpuLayerCache, reporter, factory) { | 110 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, context) { |
112 // Add one more layer than can fit in the atlas | 111 // Add one more layer than can fit in the atlas |
113 static const int kInitialNumLayers = TestingAccess::NumPlots() + 1; | 112 static const int kInitialNumLayers = TestingAccess::NumPlots() + 1; |
114 | 113 |
115 #if GR_CACHE_STATS | 114 #if GR_CACHE_STATS |
116 GrResourceCache::Stats stats; | 115 GrResourceCache::Stats stats; |
117 #endif | 116 #endif |
118 | 117 |
119 for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 118 SkAutoTUnref<const SkPicture> picture; |
120 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type) i; | 119 |
121 | 120 { |
122 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | 121 SkPictureRecorder recorder; |
123 continue; | 122 SkCanvas* c = recorder.beginRecording(1, 1); |
| 123 // Draw something, anything, to prevent an empty-picture optimization, |
| 124 // which is a singleton and never purged. |
| 125 c->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
| 126 picture.reset(recorder.endRecording()); |
| 127 } |
| 128 |
| 129 GrResourceCache* resourceCache = context->getResourceCache(); |
| 130 |
| 131 GrLayerCache cache(context); |
| 132 |
| 133 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
| 134 |
| 135 for (int i = 0; i < kInitialNumLayers; ++i) { |
| 136 int key[1] = { i + 1 }; |
| 137 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(),
SkMatrix::I(), |
| 138 key, 1); |
| 139 REPORTER_ASSERT(reporter, layer); |
| 140 |
| 141 lock_layer(reporter, &cache, layer); |
| 142 |
| 143 #if GR_CACHE_STATS |
| 144 resourceCache->getStats(&stats); |
| 145 #endif |
| 146 |
| 147 // The first 4 layers should be in the atlas (and thus have non-empty re
cts) |
| 148 if (i < TestingAccess::NumPlots()) { |
| 149 REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 150 #if GR_CACHE_STATS |
| 151 REPORTER_ASSERT(reporter, 1 == stats.fTotal); |
| 152 #endif |
| 153 } else { |
| 154 // The 5th layer couldn't fit in the atlas |
| 155 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 156 #if GR_CACHE_STATS |
| 157 REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 158 #endif |
124 } | 159 } |
125 | 160 } |
126 GrContext* context = factory->get(glCtxType); | 161 |
127 | 162 // Unlock the textures |
128 if (nullptr == context) { | 163 for (int i = 0; i < kInitialNumLayers; ++i) { |
129 continue; | 164 int key[1] = { i+1 }; |
| 165 |
| 166 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(),
SkMatrix::I(), |
| 167 key, 1); |
| 168 REPORTER_ASSERT(reporter, layer); |
| 169 cache.removeUse(layer); |
| 170 } |
| 171 |
| 172 #if GR_CACHE_STATS |
| 173 resourceCache->getStats(&stats); |
| 174 REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 175 // The floating layer is purgeable the cache is not |
| 176 REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
| 177 REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
| 178 #endif |
| 179 |
| 180 for (int i = 0; i < kInitialNumLayers; ++i) { |
| 181 int key[1] = { i+1 }; |
| 182 |
| 183 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(),
SkMatrix::I(), |
| 184 key, 1); |
| 185 REPORTER_ASSERT(reporter, layer); |
| 186 |
| 187 // All the layers should be unlocked |
| 188 REPORTER_ASSERT(reporter, !layer->locked()); |
| 189 |
| 190 // When hoisted layers aren't cached they are aggressively removed |
| 191 // from the atlas |
| 192 #if GR_CACHE_HOISTED_LAYERS |
| 193 // The first 4 layers should still be in the atlas. |
| 194 if (i < 4) { |
| 195 REPORTER_ASSERT(reporter, layer->texture()); |
| 196 REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 197 } else { |
| 198 #endif |
| 199 // The final layer should not be atlased. |
| 200 REPORTER_ASSERT(reporter, nullptr == layer->texture()); |
| 201 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 202 #if GR_CACHE_HOISTED_LAYERS |
130 } | 203 } |
131 | 204 #endif |
132 SkAutoTUnref<const SkPicture> picture; | 205 } |
133 | 206 |
134 { | 207 // Let go of the backing texture |
135 SkPictureRecorder recorder; | 208 cache.end(); |
136 SkCanvas* c = recorder.beginRecording(1, 1); | 209 REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache
)); |
137 // Draw something, anything, to prevent an empty-picture optimiz
ation, | 210 |
138 // which is a singleton and never purged. | 211 #if GR_CACHE_STATS |
139 c->drawRect(SkRect::MakeWH(1,1), SkPaint()); | 212 resourceCache->getStats(&stats); |
140 picture.reset(recorder.endRecording()); | 213 REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 214 // Now both the floater and the atlas are purgeable |
| 215 REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); |
| 216 #endif |
| 217 |
| 218 // re-attach to the backing texture |
| 219 cache.begin(); |
| 220 REPORTER_ASSERT(reporter, TestingAccess::GetBackingTexture(&cache)); |
| 221 |
| 222 #if GR_CACHE_STATS |
| 223 resourceCache->getStats(&stats); |
| 224 REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 225 // The atlas is restored to being non-purgeable |
| 226 REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
| 227 REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
| 228 #endif |
| 229 |
| 230 { |
| 231 int key[1] = { kInitialNumLayers+1 }; |
| 232 |
| 233 // Add an additional layer. Since all the layers are unlocked this |
| 234 // will force out the first atlased layer |
| 235 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); |
| 236 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(),
SkMatrix::I(), |
| 237 key, 1); |
| 238 REPORTER_ASSERT(reporter, layer); |
| 239 |
| 240 lock_layer(reporter, &cache, layer); |
| 241 cache.removeUse(layer); |
| 242 } |
| 243 |
| 244 for (int i = 0; i < kInitialNumLayers+1; ++i) { |
| 245 int key[1] = { i+1 }; |
| 246 |
| 247 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(),
SkMatrix::I(), |
| 248 key, 1); |
| 249 #if GR_CACHE_HOISTED_LAYERS |
| 250 // 3 old layers plus the new one should be in the atlas. |
| 251 if (1 == i || 2 == i || 3 == i || 5 == i) { |
| 252 REPORTER_ASSERT(reporter, layer); |
| 253 REPORTER_ASSERT(reporter, !layer->locked()); |
| 254 REPORTER_ASSERT(reporter, layer->texture()); |
| 255 REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 256 } else if (4 == i) { |
| 257 #endif |
| 258 // The one that was never atlased should still be around |
| 259 REPORTER_ASSERT(reporter, layer); |
| 260 |
| 261 REPORTER_ASSERT(reporter, nullptr == layer->texture()); |
| 262 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 263 #if GR_CACHE_HOISTED_LAYERS |
| 264 } else { |
| 265 // The one bumped out of the atlas (i.e., 0) should be gone |
| 266 REPORTER_ASSERT(reporter, nullptr == layer); |
141 } | 267 } |
142 | 268 #endif |
143 GrResourceCache* resourceCache = context->getResourceCache(); | 269 } |
144 | 270 |
145 GrLayerCache cache(context); | 271 //-------------------------------------------------------------------- |
146 | 272 // Free them all SkGpuDevice-style. This will not free up the |
147 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); | 273 // atlas' texture but will eliminate all the layers. |
148 | 274 TestingAccess::Purge(&cache, picture->uniqueID()); |
149 for (int i = 0; i < kInitialNumLayers; ++i) { | 275 |
150 int key[1] = { i + 1 }; | 276 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
151 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | 277 |
152 key, 1); | 278 #if GR_CACHE_STATS |
153 REPORTER_ASSERT(reporter, layer); | 279 resourceCache->getStats(&stats); |
154 | 280 REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
155 lock_layer(reporter, &cache, layer); | 281 // Atlas isn't purgeable |
156 | 282 REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
157 #if GR_CACHE_STATS | 283 REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
158 resourceCache->getStats(&stats); | 284 #endif |
159 #endif | 285 |
160 | 286 //-------------------------------------------------------------------- |
161 // The first 4 layers should be in the atlas (and thus have non-empt
y rects) | 287 // Test out the GrContext-style purge. This should remove all the layers |
162 if (i < TestingAccess::NumPlots()) { | 288 // and the atlas. |
163 REPORTER_ASSERT(reporter, layer->isAtlased()); | 289 // Re-create the layers |
164 #if GR_CACHE_STATS | 290 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
165 REPORTER_ASSERT(reporter, 1 == stats.fTotal); | 291 |
166 #endif | 292 // Free them again GrContext-style. This should free up everything. |
167 } else { | 293 cache.freeAll(); |
168 // The 5th layer couldn't fit in the atlas | 294 |
169 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 295 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
170 #if GR_CACHE_STATS | 296 |
171 REPORTER_ASSERT(reporter, 2 == stats.fTotal); | 297 REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache
)); |
172 #endif | 298 |
173 } | 299 #if GR_CACHE_STATS |
174 } | 300 resourceCache->getStats(&stats); |
175 | 301 REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
176 // Unlock the textures | 302 REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); |
177 for (int i = 0; i < kInitialNumLayers; ++i) { | 303 #endif |
178 int key[1] = { i+1 }; | 304 |
179 | 305 // Purge the resource cache ... |
180 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | 306 resourceCache->purgeAllUnlocked(); |
181 key, 1); | 307 |
182 REPORTER_ASSERT(reporter, layer); | 308 #if GR_CACHE_STATS |
183 cache.removeUse(layer); | 309 resourceCache->getStats(&stats); |
184 } | 310 REPORTER_ASSERT(reporter, 0 == stats.fTotal); |
185 | 311 #endif |
186 #if GR_CACHE_STATS | 312 |
187 resourceCache->getStats(&stats); | 313 // and try to re-attach to the backing texture. This should fail |
188 REPORTER_ASSERT(reporter, 2 == stats.fTotal); | 314 cache.begin(); |
189 // The floating layer is purgeable the cache is not | 315 REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache
)); |
190 REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); | 316 |
191 REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); | 317 //-------------------------------------------------------------------- |
192 #endif | 318 // Test out the MessageBus-style purge. This will not free the atlas |
193 | 319 // but should eliminate the free-floating layers. |
194 for (int i = 0; i < kInitialNumLayers; ++i) { | 320 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
195 int key[1] = { i+1 }; | 321 |
196 | 322 // Allocate/use the layers |
197 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | 323 for (int i = 0; i < kInitialNumLayers; ++i) { |
198 key, 1); | 324 int key[1] = { i + 1 }; |
199 REPORTER_ASSERT(reporter, layer); | 325 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(),
SkMatrix::I(), |
200 | 326 key, 1); |
201 // All the layers should be unlocked | 327 REPORTER_ASSERT(reporter, layer); |
202 REPORTER_ASSERT(reporter, !layer->locked()); | 328 |
203 | 329 lock_layer(reporter, &cache, layer); |
204 // When hoisted layers aren't cached they are aggressively removed | 330 } |
205 // from the atlas | 331 |
206 #if GR_CACHE_HOISTED_LAYERS | 332 #if GR_CACHE_STATS |
207 // The first 4 layers should still be in the atlas. | 333 resourceCache->getStats(&stats); |
208 if (i < 4) { | 334 REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
209 REPORTER_ASSERT(reporter, layer->texture()); | 335 REPORTER_ASSERT(reporter, 2 == stats.fNumNonPurgeable); |
210 REPORTER_ASSERT(reporter, layer->isAtlased()); | 336 #endif |
211 } else { | 337 |
212 #endif | 338 // Unlock the textures |
213 // The final layer should not be atlased. | 339 for (int i = 0; i < kInitialNumLayers; ++i) { |
214 REPORTER_ASSERT(reporter, nullptr == layer->texture()); | 340 int key[1] = { i+1 }; |
215 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 341 |
216 #if GR_CACHE_HOISTED_LAYERS | 342 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(),
SkMatrix::I(), |
217 } | 343 key, 1); |
218 #endif | 344 REPORTER_ASSERT(reporter, layer); |
219 } | 345 cache.removeUse(layer); |
220 | 346 } |
221 // Let go of the backing texture | 347 |
222 cache.end(); | 348 picture.reset(nullptr); |
223 REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&c
ache)); | 349 cache.processDeletedPictures(); |
224 | 350 |
225 #if GR_CACHE_STATS | 351 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
226 resourceCache->getStats(&stats); | 352 |
227 REPORTER_ASSERT(reporter, 2 == stats.fTotal); | 353 #if GR_CACHE_STATS |
228 // Now both the floater and the atlas are purgeable | 354 resourceCache->getStats(&stats); |
229 REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); | 355 REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
230 #endif | 356 REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
231 | 357 REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
232 // re-attach to the backing texture | 358 #endif |
233 cache.begin(); | 359 |
234 REPORTER_ASSERT(reporter, TestingAccess::GetBackingTexture(&cache)); | 360 cache.end(); |
235 | 361 |
236 #if GR_CACHE_STATS | 362 #if GR_CACHE_STATS |
237 resourceCache->getStats(&stats); | 363 resourceCache->getStats(&stats); |
238 REPORTER_ASSERT(reporter, 2 == stats.fTotal); | 364 REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
239 // The atlas is restored to being non-purgeable | 365 REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); |
240 REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); | 366 #endif |
241 REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); | |
242 #endif | |
243 | |
244 { | |
245 int key[1] = { kInitialNumLayers+1 }; | |
246 | |
247 // Add an additional layer. Since all the layers are unlocked this | |
248 // will force out the first atlased layer | |
249 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); | |
250 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | |
251 key, 1); | |
252 REPORTER_ASSERT(reporter, layer); | |
253 | |
254 lock_layer(reporter, &cache, layer); | |
255 cache.removeUse(layer); | |
256 } | |
257 | |
258 for (int i = 0; i < kInitialNumLayers+1; ++i) { | |
259 int key[1] = { i+1 }; | |
260 | |
261 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | |
262 key, 1); | |
263 #if GR_CACHE_HOISTED_LAYERS | |
264 // 3 old layers plus the new one should be in the atlas. | |
265 if (1 == i || 2 == i || 3 == i || 5 == i) { | |
266 REPORTER_ASSERT(reporter, layer); | |
267 REPORTER_ASSERT(reporter, !layer->locked()); | |
268 REPORTER_ASSERT(reporter, layer->texture()); | |
269 REPORTER_ASSERT(reporter, layer->isAtlased()); | |
270 } else if (4 == i) { | |
271 #endif | |
272 // The one that was never atlased should still be around | |
273 REPORTER_ASSERT(reporter, layer); | |
274 | |
275 REPORTER_ASSERT(reporter, nullptr == layer->texture()); | |
276 REPORTER_ASSERT(reporter, !layer->isAtlased()); | |
277 #if GR_CACHE_HOISTED_LAYERS | |
278 } else { | |
279 // The one bumped out of the atlas (i.e., 0) should be gone | |
280 REPORTER_ASSERT(reporter, nullptr == layer); | |
281 } | |
282 #endif | |
283 } | |
284 | |
285 //-------------------------------------------------------------------- | |
286 // Free them all SkGpuDevice-style. This will not free up the | |
287 // atlas' texture but will eliminate all the layers. | |
288 TestingAccess::Purge(&cache, picture->uniqueID()); | |
289 | |
290 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | |
291 | |
292 #if GR_CACHE_STATS | |
293 resourceCache->getStats(&stats); | |
294 REPORTER_ASSERT(reporter, 2 == stats.fTotal); | |
295 // Atlas isn't purgeable | |
296 REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); | |
297 REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); | |
298 #endif | |
299 | |
300 //-------------------------------------------------------------------- | |
301 // Test out the GrContext-style purge. This should remove all the layers | |
302 // and the atlas. | |
303 // Re-create the layers | |
304 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); | |
305 | |
306 // Free them again GrContext-style. This should free up everything. | |
307 cache.freeAll(); | |
308 | |
309 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | |
310 | |
311 REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&c
ache)); | |
312 | |
313 #if GR_CACHE_STATS | |
314 resourceCache->getStats(&stats); | |
315 REPORTER_ASSERT(reporter, 2 == stats.fTotal); | |
316 REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); | |
317 #endif | |
318 | |
319 // Purge the resource cache ... | |
320 resourceCache->purgeAllUnlocked(); | |
321 | |
322 #if GR_CACHE_STATS | |
323 resourceCache->getStats(&stats); | |
324 REPORTER_ASSERT(reporter, 0 == stats.fTotal); | |
325 #endif | |
326 | |
327 // and try to re-attach to the backing texture. This should fail | |
328 cache.begin(); | |
329 REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&c
ache)); | |
330 | |
331 //-------------------------------------------------------------------- | |
332 // Test out the MessageBus-style purge. This will not free the atlas | |
333 // but should eliminate the free-floating layers. | |
334 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); | |
335 | |
336 // Allocate/use the layers | |
337 for (int i = 0; i < kInitialNumLayers; ++i) { | |
338 int key[1] = { i + 1 }; | |
339 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | |
340 key, 1); | |
341 REPORTER_ASSERT(reporter, layer); | |
342 | |
343 lock_layer(reporter, &cache, layer); | |
344 } | |
345 | |
346 #if GR_CACHE_STATS | |
347 resourceCache->getStats(&stats); | |
348 REPORTER_ASSERT(reporter, 2 == stats.fTotal); | |
349 REPORTER_ASSERT(reporter, 2 == stats.fNumNonPurgeable); | |
350 #endif | |
351 | |
352 // Unlock the textures | |
353 for (int i = 0; i < kInitialNumLayers; ++i) { | |
354 int key[1] = { i+1 }; | |
355 | |
356 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | |
357 key, 1); | |
358 REPORTER_ASSERT(reporter, layer); | |
359 cache.removeUse(layer); | |
360 } | |
361 | |
362 picture.reset(nullptr); | |
363 cache.processDeletedPictures(); | |
364 | |
365 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | |
366 | |
367 #if GR_CACHE_STATS | |
368 resourceCache->getStats(&stats); | |
369 REPORTER_ASSERT(reporter, 2 == stats.fTotal); | |
370 REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); | |
371 REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); | |
372 #endif | |
373 | |
374 cache.end(); | |
375 | |
376 #if GR_CACHE_STATS | |
377 resourceCache->getStats(&stats); | |
378 REPORTER_ASSERT(reporter, 2 == stats.fTotal); | |
379 REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); | |
380 #endif | |
381 } | |
382 } | 367 } |
383 | 368 |
384 #endif | 369 #endif |
OLD | NEW |