robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #if SK_SUPPORT_GPU |
| 9 | |
| 10 | #include "GrContext.h" |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 11 | #include "GrLayerCache.h" |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 12 | #include "GrResourceCache.h" |
Robert Phillips | cfaeec4 | 2014-07-13 12:00:50 -0400 | [diff] [blame] | 13 | #include "SkPictureRecorder.h" |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 14 | #include "Test.h" |
| 15 | |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 16 | class TestingAccess { |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 17 | public: |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 18 | static int NumPlots() { |
| 19 | return GrLayerCache::kNumPlotsX * GrLayerCache::kNumPlotsY; |
| 20 | } |
| 21 | static SkISize PlotSize() { |
| 22 | return SkISize::Make(GrLayerCache::kAtlasTextureWidth / GrLayerCache::kNumPlotsX, |
| 23 | GrLayerCache::kAtlasTextureHeight / GrLayerCache::kNumPlotsY); |
| 24 | } |
| 25 | |
| 26 | static GrTexture* GetBackingTexture(GrLayerCache* cache) { |
| 27 | return cache->fAtlas->getTextureOrNull(); |
| 28 | } |
| 29 | |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 30 | static int NumLayers(GrLayerCache* cache) { |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 31 | return cache->numLayers(); |
| 32 | } |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 33 | static void Purge(GrLayerCache* cache, uint32_t pictureID) { |
| 34 | cache->purge(pictureID); |
| 35 | } |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 36 | static int Uses(GrCachedLayer* layer) { |
| 37 | return layer->uses(); |
| 38 | } |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 39 | static GrCachedLayer* Find(GrLayerCache* cache, uint32_t pictureID, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 40 | const SkMatrix& initialMat, |
| 41 | const int* key, int keySize) { |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 42 | return cache->findLayer(pictureID, initialMat, key, keySize); |
| 43 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | // Add several layers to the cache |
| 47 | static void create_layers(skiatest::Reporter* reporter, |
| 48 | GrLayerCache* cache, |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 49 | const SkPicture& picture, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 50 | int numToAdd, |
| 51 | int idOffset) { |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 52 | |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 53 | for (int i = 0; i < numToAdd; ++i) { |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 54 | int key[1] = { idOffset+i+1 }; |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 55 | GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), |
| 56 | idOffset+i+1, idOffset+i+2, |
robertphillips | 3aac6e0 | 2014-10-20 08:52:40 -0700 | [diff] [blame] | 57 | SkIRect::MakeEmpty(), |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 58 | SkIRect::MakeEmpty(), |
robertphillips | 4aa6dfc | 2014-09-17 07:50:47 -0700 | [diff] [blame] | 59 | SkMatrix::I(), |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 60 | key, 1, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 61 | nullptr); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 62 | REPORTER_ASSERT(reporter, layer); |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 63 | GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkMatrix::I(), |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 64 | key, 1); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 65 | REPORTER_ASSERT(reporter, temp == layer); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 66 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 68 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 69 | REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 70 | REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); |
| 71 | REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, nullptr == layer->texture()); |
| 73 | REPORTER_ASSERT(reporter, nullptr == layer->paint()); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 74 | REPORTER_ASSERT(reporter, !layer->isAtlased()); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 75 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 76 | } |
| 77 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 78 | static void lock_layer(skiatest::Reporter* reporter, |
| 79 | GrLayerCache* cache, |
| 80 | GrCachedLayer* layer) { |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 81 | // Make each layer big enough to consume one whole plot in the atlas |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 82 | GrSurfaceDesc desc; |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 83 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 84 | desc.fWidth = TestingAccess::PlotSize().fWidth; |
| 85 | desc.fHeight = TestingAccess::PlotSize().fHeight; |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 86 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 87 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 88 | bool needsRerendering; |
| 89 | bool inAtlas = cache->tryToAtlas(layer, desc, &needsRerendering); |
| 90 | if (!inAtlas) { |
| 91 | cache->lock(layer, desc, &needsRerendering); |
| 92 | } |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 93 | REPORTER_ASSERT(reporter, needsRerendering); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 94 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 95 | cache->lock(layer, desc, &needsRerendering); |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 96 | REPORTER_ASSERT(reporter, !needsRerendering); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 97 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 98 | REPORTER_ASSERT(reporter, layer->texture()); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 99 | REPORTER_ASSERT(reporter, layer->locked()); |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 100 | |
| 101 | cache->addUse(layer); |
| 102 | |
| 103 | REPORTER_ASSERT(reporter, 1 == TestingAccess::Uses(layer)); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 104 | } |
| 105 | |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 106 | // This test case exercises the public API of the GrLayerCache class. |
| 107 | // In particular it checks its interaction with the resource cache (w.r.t. |
| 108 | // locking & unlocking textures). |
| 109 | // TODO: need to add checks on VRAM usage! |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame^] | 110 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, ctxInfo) { |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 111 | // Add one more layer than can fit in the atlas |
| 112 | static const int kInitialNumLayers = TestingAccess::NumPlots() + 1; |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 113 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 114 | #if GR_CACHE_STATS |
| 115 | GrResourceCache::Stats stats; |
| 116 | #endif |
| 117 | |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 118 | sk_sp<SkPicture> picture; |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 119 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 120 | { |
| 121 | SkPictureRecorder recorder; |
| 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()); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 126 | picture = recorder.finishRecordingAsPicture(); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 127 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 128 | |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame^] | 129 | GrResourceCache* resourceCache = ctxInfo.fGrContext->getResourceCache(); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 130 | |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame^] | 131 | GrLayerCache cache(ctxInfo.fGrContext); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 132 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 133 | create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 134 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 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); |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 140 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 141 | lock_layer(reporter, &cache, layer); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 142 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 143 | #if GR_CACHE_STATS |
| 144 | resourceCache->getStats(&stats); |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 145 | #endif |
| 146 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 147 | // The first 4 layers should be in the atlas (and thus have non-empty rects) |
| 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 |
| 159 | } |
| 160 | } |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 161 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 162 | // Unlock the textures |
| 163 | for (int i = 0; i < kInitialNumLayers; ++i) { |
| 164 | int key[1] = { i+1 }; |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 165 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 166 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 167 | key, 1); |
| 168 | REPORTER_ASSERT(reporter, layer); |
| 169 | cache.removeUse(layer); |
| 170 | } |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 171 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 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 |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 192 | #if GR_CACHE_HOISTED_LAYERS |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 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 { |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 198 | #endif |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 199 | // The final layer should not be atlased. |
| 200 | REPORTER_ASSERT(reporter, nullptr == layer->texture()); |
| 201 | REPORTER_ASSERT(reporter, !layer->isAtlased()); |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 202 | #if GR_CACHE_HOISTED_LAYERS |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 203 | } |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 204 | #endif |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 205 | } |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 206 | |
| 207 | // Let go of the backing texture |
| 208 | cache.end(); |
| 209 | REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache)); |
| 210 | |
| 211 | #if GR_CACHE_STATS |
| 212 | resourceCache->getStats(&stats); |
| 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); |
| 267 | } |
| 268 | #endif |
| 269 | } |
| 270 | |
| 271 | //-------------------------------------------------------------------- |
| 272 | // Free them all SkGpuDevice-style. This will not free up the |
| 273 | // atlas' texture but will eliminate all the layers. |
| 274 | TestingAccess::Purge(&cache, picture->uniqueID()); |
| 275 | |
| 276 | REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
| 277 | |
| 278 | #if GR_CACHE_STATS |
| 279 | resourceCache->getStats(&stats); |
| 280 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 281 | // Atlas isn't purgeable |
| 282 | REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
| 283 | REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
| 284 | #endif |
| 285 | |
| 286 | //-------------------------------------------------------------------- |
| 287 | // Test out the GrContext-style purge. This should remove all the layers |
| 288 | // and the atlas. |
| 289 | // Re-create the layers |
| 290 | create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
| 291 | |
| 292 | // Free them again GrContext-style. This should free up everything. |
| 293 | cache.freeAll(); |
| 294 | |
| 295 | REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
| 296 | |
| 297 | REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache)); |
| 298 | |
| 299 | #if GR_CACHE_STATS |
| 300 | resourceCache->getStats(&stats); |
| 301 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 302 | REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); |
| 303 | #endif |
| 304 | |
| 305 | // Purge the resource cache ... |
| 306 | resourceCache->purgeAllUnlocked(); |
| 307 | |
| 308 | #if GR_CACHE_STATS |
| 309 | resourceCache->getStats(&stats); |
| 310 | REPORTER_ASSERT(reporter, 0 == stats.fTotal); |
| 311 | #endif |
| 312 | |
| 313 | // and try to re-attach to the backing texture. This should fail |
| 314 | cache.begin(); |
| 315 | REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache)); |
| 316 | |
| 317 | //-------------------------------------------------------------------- |
| 318 | // Test out the MessageBus-style purge. This will not free the atlas |
| 319 | // but should eliminate the free-floating layers. |
| 320 | create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
| 321 | |
| 322 | // Allocate/use the layers |
| 323 | for (int i = 0; i < kInitialNumLayers; ++i) { |
| 324 | int key[1] = { i + 1 }; |
| 325 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 326 | key, 1); |
| 327 | REPORTER_ASSERT(reporter, layer); |
| 328 | |
| 329 | lock_layer(reporter, &cache, layer); |
| 330 | } |
| 331 | |
| 332 | #if GR_CACHE_STATS |
| 333 | resourceCache->getStats(&stats); |
| 334 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 335 | REPORTER_ASSERT(reporter, 2 == stats.fNumNonPurgeable); |
| 336 | #endif |
| 337 | |
| 338 | // Unlock the textures |
| 339 | for (int i = 0; i < kInitialNumLayers; ++i) { |
| 340 | int key[1] = { i+1 }; |
| 341 | |
| 342 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 343 | key, 1); |
| 344 | REPORTER_ASSERT(reporter, layer); |
| 345 | cache.removeUse(layer); |
| 346 | } |
| 347 | |
| 348 | picture.reset(nullptr); |
| 349 | cache.processDeletedPictures(); |
| 350 | |
| 351 | REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
| 352 | |
| 353 | #if GR_CACHE_STATS |
| 354 | resourceCache->getStats(&stats); |
| 355 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 356 | REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
| 357 | REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
| 358 | #endif |
| 359 | |
| 360 | cache.end(); |
| 361 | |
| 362 | #if GR_CACHE_STATS |
| 363 | resourceCache->getStats(&stats); |
| 364 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 365 | REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); |
| 366 | #endif |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | #endif |