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 | |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 8 | // Disabling this test since it is for the layer hoister which is current disabled. |
| 9 | // The test fails when we add a discard to a newly created render target. |
| 10 | #if 0 |
| 11 | |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 12 | #include "GrContext.h" |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 13 | #include "GrLayerCache.h" |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 14 | #include "GrResourceCache.h" |
Robert Phillips | cfaeec4 | 2014-07-13 12:00:50 -0400 | [diff] [blame] | 15 | #include "SkPictureRecorder.h" |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 16 | #include "Test.h" |
| 17 | |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 18 | class TestingAccess { |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 19 | public: |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 20 | static int NumPlots() { |
| 21 | return GrLayerCache::kNumPlotsX * GrLayerCache::kNumPlotsY; |
| 22 | } |
| 23 | static SkISize PlotSize() { |
| 24 | return SkISize::Make(GrLayerCache::kAtlasTextureWidth / GrLayerCache::kNumPlotsX, |
| 25 | GrLayerCache::kAtlasTextureHeight / GrLayerCache::kNumPlotsY); |
| 26 | } |
| 27 | |
| 28 | static GrTexture* GetBackingTexture(GrLayerCache* cache) { |
| 29 | return cache->fAtlas->getTextureOrNull(); |
| 30 | } |
| 31 | |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 32 | static int NumLayers(GrLayerCache* cache) { |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 33 | return cache->numLayers(); |
| 34 | } |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 35 | static void Purge(GrLayerCache* cache, uint32_t pictureID) { |
| 36 | cache->purge(pictureID); |
| 37 | } |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 38 | static int Uses(GrCachedLayer* layer) { |
| 39 | return layer->uses(); |
| 40 | } |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 41 | static GrCachedLayer* Find(GrLayerCache* cache, uint32_t pictureID, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 42 | const SkMatrix& initialMat, |
| 43 | const int* key, int keySize) { |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 44 | return cache->findLayer(pictureID, initialMat, key, keySize); |
| 45 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | // Add several layers to the cache |
| 49 | static void create_layers(skiatest::Reporter* reporter, |
| 50 | GrLayerCache* cache, |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 51 | const SkPicture& picture, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 52 | int numToAdd, |
| 53 | int idOffset) { |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 54 | |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 55 | for (int i = 0; i < numToAdd; ++i) { |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 56 | int key[1] = { idOffset+i+1 }; |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 57 | GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), |
| 58 | idOffset+i+1, idOffset+i+2, |
robertphillips | 3aac6e0 | 2014-10-20 08:52:40 -0700 | [diff] [blame] | 59 | SkIRect::MakeEmpty(), |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 60 | SkIRect::MakeEmpty(), |
robertphillips | 4aa6dfc | 2014-09-17 07:50:47 -0700 | [diff] [blame] | 61 | SkMatrix::I(), |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 62 | key, 1, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 63 | nullptr); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, layer); |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 65 | GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkMatrix::I(), |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 66 | key, 1); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, temp == layer); |
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, TestingAccess::NumLayers(cache) == idOffset + i + 1); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 70 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); |
| 73 | REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); |
robertphillips | b451134 | 2016-05-03 09:37:08 -0700 | [diff] [blame] | 74 | REPORTER_ASSERT(reporter, !layer->texture()); |
| 75 | REPORTER_ASSERT(reporter, !layer->paint()); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 76 | REPORTER_ASSERT(reporter, !layer->isAtlased()); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 77 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 78 | } |
| 79 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 80 | static void lock_layer(skiatest::Reporter* reporter, |
| 81 | GrLayerCache* cache, |
| 82 | GrCachedLayer* layer) { |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 83 | // Make each layer big enough to consume one whole plot in the atlas |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 84 | GrSurfaceDesc desc; |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 85 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 86 | desc.fWidth = TestingAccess::PlotSize().fWidth; |
| 87 | desc.fHeight = TestingAccess::PlotSize().fHeight; |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 88 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 89 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 90 | bool needsRerendering; |
| 91 | bool inAtlas = cache->tryToAtlas(layer, desc, &needsRerendering); |
| 92 | if (!inAtlas) { |
| 93 | cache->lock(layer, desc, &needsRerendering); |
| 94 | } |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 95 | REPORTER_ASSERT(reporter, needsRerendering); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 96 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 97 | cache->lock(layer, desc, &needsRerendering); |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 98 | REPORTER_ASSERT(reporter, !needsRerendering); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 99 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 100 | REPORTER_ASSERT(reporter, layer->texture()); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 101 | REPORTER_ASSERT(reporter, layer->locked()); |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 102 | |
| 103 | cache->addUse(layer); |
| 104 | |
| 105 | REPORTER_ASSERT(reporter, 1 == TestingAccess::Uses(layer)); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 106 | } |
| 107 | |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 108 | // This test case exercises the public API of the GrLayerCache class. |
| 109 | // In particular it checks its interaction with the resource cache (w.r.t. |
| 110 | // locking & unlocking textures). |
| 111 | // TODO: need to add checks on VRAM usage! |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 112 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, ctxInfo) { |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 113 | // Add one more layer than can fit in the atlas |
| 114 | static const int kInitialNumLayers = TestingAccess::NumPlots() + 1; |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 115 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 116 | #if GR_CACHE_STATS |
| 117 | GrResourceCache::Stats stats; |
| 118 | #endif |
| 119 | |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 120 | sk_sp<SkPicture> picture; |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 121 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 122 | { |
| 123 | SkPictureRecorder recorder; |
| 124 | SkCanvas* c = recorder.beginRecording(1, 1); |
| 125 | // Draw something, anything, to prevent an empty-picture optimization, |
| 126 | // which is a singleton and never purged. |
| 127 | c->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 128 | picture = recorder.finishRecordingAsPicture(); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 129 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 130 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 131 | GrResourceCache* resourceCache = ctxInfo.grContext()->getResourceCache(); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 132 | |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 133 | GrLayerCache cache(ctxInfo.grContext()); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 134 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 135 | create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 136 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 137 | for (int i = 0; i < kInitialNumLayers; ++i) { |
| 138 | int key[1] = { i + 1 }; |
| 139 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 140 | key, 1); |
| 141 | REPORTER_ASSERT(reporter, layer); |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 142 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 143 | lock_layer(reporter, &cache, layer); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 144 | |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 145 | #if GR_CACHE_STATS |
| 146 | resourceCache->getStats(&stats); |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 147 | #endif |
| 148 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 149 | // The first 4 layers should be in the atlas (and thus have non-empty rects) |
| 150 | if (i < TestingAccess::NumPlots()) { |
| 151 | REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 152 | #if GR_CACHE_STATS |
| 153 | REPORTER_ASSERT(reporter, 1 == stats.fTotal); |
| 154 | #endif |
| 155 | } else { |
| 156 | // The 5th layer couldn't fit in the atlas |
| 157 | REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 158 | #if GR_CACHE_STATS |
| 159 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 160 | #endif |
| 161 | } |
| 162 | } |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 163 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 164 | // Unlock the textures |
| 165 | for (int i = 0; i < kInitialNumLayers; ++i) { |
| 166 | int key[1] = { i+1 }; |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 167 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 168 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 169 | key, 1); |
| 170 | REPORTER_ASSERT(reporter, layer); |
| 171 | cache.removeUse(layer); |
| 172 | } |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 173 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 174 | #if GR_CACHE_STATS |
| 175 | resourceCache->getStats(&stats); |
| 176 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 177 | // The floating layer is purgeable the cache is not |
| 178 | REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
| 179 | REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
| 180 | #endif |
| 181 | |
| 182 | for (int i = 0; i < kInitialNumLayers; ++i) { |
| 183 | int key[1] = { i+1 }; |
| 184 | |
| 185 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 186 | key, 1); |
| 187 | REPORTER_ASSERT(reporter, layer); |
| 188 | |
| 189 | // All the layers should be unlocked |
| 190 | REPORTER_ASSERT(reporter, !layer->locked()); |
| 191 | |
| 192 | // When hoisted layers aren't cached they are aggressively removed |
| 193 | // from the atlas |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 194 | #if GR_CACHE_HOISTED_LAYERS |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 195 | // The first 4 layers should still be in the atlas. |
| 196 | if (i < 4) { |
| 197 | REPORTER_ASSERT(reporter, layer->texture()); |
| 198 | REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 199 | } else { |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 200 | #endif |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 201 | // The final layer should not be atlased. |
robertphillips | b451134 | 2016-05-03 09:37:08 -0700 | [diff] [blame] | 202 | REPORTER_ASSERT(reporter, !layer->texture()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 203 | REPORTER_ASSERT(reporter, !layer->isAtlased()); |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 204 | #if GR_CACHE_HOISTED_LAYERS |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 205 | } |
robertphillips | 60029a5 | 2015-11-09 13:51:06 -0800 | [diff] [blame] | 206 | #endif |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 207 | } |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 208 | |
| 209 | // Let go of the backing texture |
| 210 | cache.end(); |
| 211 | REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache)); |
| 212 | |
| 213 | #if GR_CACHE_STATS |
| 214 | resourceCache->getStats(&stats); |
| 215 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 216 | // Now both the floater and the atlas are purgeable |
| 217 | REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); |
| 218 | #endif |
| 219 | |
| 220 | // re-attach to the backing texture |
| 221 | cache.begin(); |
| 222 | REPORTER_ASSERT(reporter, TestingAccess::GetBackingTexture(&cache)); |
| 223 | |
| 224 | #if GR_CACHE_STATS |
| 225 | resourceCache->getStats(&stats); |
| 226 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 227 | // The atlas is restored to being non-purgeable |
| 228 | REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
| 229 | REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
| 230 | #endif |
| 231 | |
| 232 | { |
| 233 | int key[1] = { kInitialNumLayers+1 }; |
| 234 | |
| 235 | // Add an additional layer. Since all the layers are unlocked this |
| 236 | // will force out the first atlased layer |
| 237 | create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); |
| 238 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 239 | key, 1); |
| 240 | REPORTER_ASSERT(reporter, layer); |
| 241 | |
| 242 | lock_layer(reporter, &cache, layer); |
| 243 | cache.removeUse(layer); |
| 244 | } |
| 245 | |
| 246 | for (int i = 0; i < kInitialNumLayers+1; ++i) { |
| 247 | int key[1] = { i+1 }; |
| 248 | |
| 249 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 250 | key, 1); |
| 251 | #if GR_CACHE_HOISTED_LAYERS |
| 252 | // 3 old layers plus the new one should be in the atlas. |
| 253 | if (1 == i || 2 == i || 3 == i || 5 == i) { |
| 254 | REPORTER_ASSERT(reporter, layer); |
| 255 | REPORTER_ASSERT(reporter, !layer->locked()); |
| 256 | REPORTER_ASSERT(reporter, layer->texture()); |
| 257 | REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 258 | } else if (4 == i) { |
| 259 | #endif |
| 260 | // The one that was never atlased should still be around |
| 261 | REPORTER_ASSERT(reporter, layer); |
| 262 | |
robertphillips | b451134 | 2016-05-03 09:37:08 -0700 | [diff] [blame] | 263 | REPORTER_ASSERT(reporter, !layer->texture()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 264 | REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 265 | #if GR_CACHE_HOISTED_LAYERS |
| 266 | } else { |
| 267 | // The one bumped out of the atlas (i.e., 0) should be gone |
| 268 | REPORTER_ASSERT(reporter, nullptr == layer); |
| 269 | } |
| 270 | #endif |
| 271 | } |
| 272 | |
| 273 | //-------------------------------------------------------------------- |
| 274 | // Free them all SkGpuDevice-style. This will not free up the |
| 275 | // atlas' texture but will eliminate all the layers. |
| 276 | TestingAccess::Purge(&cache, picture->uniqueID()); |
| 277 | |
| 278 | REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
| 279 | |
| 280 | #if GR_CACHE_STATS |
| 281 | resourceCache->getStats(&stats); |
| 282 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 283 | // Atlas isn't purgeable |
| 284 | REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
| 285 | REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
| 286 | #endif |
| 287 | |
| 288 | //-------------------------------------------------------------------- |
| 289 | // Test out the GrContext-style purge. This should remove all the layers |
| 290 | // and the atlas. |
| 291 | // Re-create the layers |
| 292 | create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
| 293 | |
| 294 | // Free them again GrContext-style. This should free up everything. |
| 295 | cache.freeAll(); |
| 296 | |
| 297 | REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
| 298 | |
| 299 | REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache)); |
| 300 | |
| 301 | #if GR_CACHE_STATS |
| 302 | resourceCache->getStats(&stats); |
| 303 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 304 | REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); |
| 305 | #endif |
| 306 | |
| 307 | // Purge the resource cache ... |
| 308 | resourceCache->purgeAllUnlocked(); |
| 309 | |
| 310 | #if GR_CACHE_STATS |
| 311 | resourceCache->getStats(&stats); |
| 312 | REPORTER_ASSERT(reporter, 0 == stats.fTotal); |
| 313 | #endif |
| 314 | |
| 315 | // and try to re-attach to the backing texture. This should fail |
| 316 | cache.begin(); |
| 317 | REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache)); |
| 318 | |
| 319 | //-------------------------------------------------------------------- |
| 320 | // Test out the MessageBus-style purge. This will not free the atlas |
| 321 | // but should eliminate the free-floating layers. |
| 322 | create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
| 323 | |
| 324 | // Allocate/use the layers |
| 325 | for (int i = 0; i < kInitialNumLayers; ++i) { |
| 326 | int key[1] = { i + 1 }; |
| 327 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 328 | key, 1); |
| 329 | REPORTER_ASSERT(reporter, layer); |
| 330 | |
| 331 | lock_layer(reporter, &cache, layer); |
| 332 | } |
| 333 | |
| 334 | #if GR_CACHE_STATS |
| 335 | resourceCache->getStats(&stats); |
| 336 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 337 | REPORTER_ASSERT(reporter, 2 == stats.fNumNonPurgeable); |
| 338 | #endif |
| 339 | |
| 340 | // Unlock the textures |
| 341 | for (int i = 0; i < kInitialNumLayers; ++i) { |
| 342 | int key[1] = { i+1 }; |
| 343 | |
| 344 | GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(), |
| 345 | key, 1); |
| 346 | REPORTER_ASSERT(reporter, layer); |
| 347 | cache.removeUse(layer); |
| 348 | } |
| 349 | |
| 350 | picture.reset(nullptr); |
| 351 | cache.processDeletedPictures(); |
| 352 | |
| 353 | REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
| 354 | |
| 355 | #if GR_CACHE_STATS |
| 356 | resourceCache->getStats(&stats); |
| 357 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 358 | REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable); |
| 359 | REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable); |
| 360 | #endif |
| 361 | |
| 362 | cache.end(); |
| 363 | |
| 364 | #if GR_CACHE_STATS |
| 365 | resourceCache->getStats(&stats); |
| 366 | REPORTER_ASSERT(reporter, 2 == stats.fTotal); |
| 367 | REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable); |
| 368 | #endif |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | #endif |