| 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" | 11 #include "GrContextFactory.h" |
| 12 #include "GrLayerCache.h" | 12 #include "GrLayerCache.h" |
| 13 #include "SkPictureRecorder.h" | 13 #include "SkPictureRecorder.h" |
| 14 #include "Test.h" | 14 #include "Test.h" |
| 15 | 15 |
| 16 class TestingAccess { | 16 class TestingAccess { |
| 17 public: | 17 public: |
| 18 static int NumLayers(GrLayerCache* cache) { | 18 static unsigned NumLayers(GrLayerCache* cache) { |
| 19 return cache->numLayers(); | 19 return cache->numLayers(); |
| 20 } | 20 } |
| 21 static void Purge(GrLayerCache* cache, uint32_t pictureID) { | 21 static void Purge(GrLayerCache* cache, uint32_t pictureID) { |
| 22 cache->purge(pictureID); | 22 cache->purge(pictureID); |
| 23 } | 23 } |
| 24 static int Uses(GrCachedLayer* layer) { | 24 static int Uses(GrCachedLayer* layer) { |
| 25 return layer->uses(); | 25 return layer->uses(); |
| 26 } | 26 } |
| 27 static GrCachedLayer* Find(GrLayerCache* cache, uint32_t pictureID, | 27 static GrCachedLayer* Find(GrLayerCache* cache, uint32_t pictureID, |
| 28 const SkMatrix& initialMat, const int* key, int k
eySize) { | 28 const SkMatrix& initialMat, |
| 29 const unsigned* key, int keySize) { |
| 29 return cache->findLayer(pictureID, initialMat, key, keySize); | 30 return cache->findLayer(pictureID, initialMat, key, keySize); |
| 30 } | 31 } |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 // Add several layers to the cache | 34 // Add several layers to the cache |
| 34 static void create_layers(skiatest::Reporter* reporter, | 35 static void create_layers(skiatest::Reporter* reporter, |
| 35 GrLayerCache* cache, | 36 GrLayerCache* cache, |
| 36 const SkPicture& picture, | 37 const SkPicture& picture, |
| 37 int numToAdd, | 38 unsigned numToAdd, |
| 38 int idOffset) { | 39 unsigned idOffset) { |
| 39 | 40 |
| 40 for (int i = 0; i < numToAdd; ++i) { | 41 for (unsigned i = 0; i < numToAdd; ++i) { |
| 41 int indices[1] = { idOffset+i+1 }; | 42 unsigned indices[1] = { idOffset+i+1 }; |
| 42 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), | 43 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), |
| 43 idOffset+i+1, idOffset+i
+2, | 44 idOffset+i+1, idOffset+i
+2, |
| 44 SkIRect::MakeEmpty(), | 45 SkIRect::MakeEmpty(), |
| 45 SkMatrix::I(), | 46 SkMatrix::I(), |
| 46 indices, 1, | 47 indices, 1, |
| 47 NULL); | 48 NULL); |
| 48 REPORTER_ASSERT(reporter, layer); | 49 REPORTER_ASSERT(reporter, layer); |
| 49 GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkM
atrix::I(), | 50 GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkM
atrix::I(), |
| 50 indices, 1); | 51 indices, 1); |
| 51 REPORTER_ASSERT(reporter, temp == layer); | 52 REPORTER_ASSERT(reporter, temp == layer); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 110 } |
| 110 | 111 |
| 111 SkPictureRecorder recorder; | 112 SkPictureRecorder recorder; |
| 112 recorder.beginRecording(1, 1); | 113 recorder.beginRecording(1, 1); |
| 113 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 114 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
| 114 | 115 |
| 115 GrLayerCache cache(context); | 116 GrLayerCache cache(context); |
| 116 | 117 |
| 117 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); | 118 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
| 118 | 119 |
| 119 for (int i = 0; i < kInitialNumLayers; ++i) { | 120 for (unsigned i = 0; i < kInitialNumLayers; ++i) { |
| 120 int indices[1] = { i + 1 }; | 121 unsigned indices[1] = { i + 1 }; |
| 121 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | 122 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), |
| 122 indices, 1); | 123 indices, 1); |
| 123 REPORTER_ASSERT(reporter, layer); | 124 REPORTER_ASSERT(reporter, layer); |
| 124 | 125 |
| 125 lock_layer(reporter, &cache, layer); | 126 lock_layer(reporter, &cache, layer); |
| 126 | 127 |
| 127 // The first 4 layers should be in the atlas (and thus have non-empt
y | 128 // The first 4 layers should be in the atlas (and thus have non-empt
y |
| 128 // rects) | 129 // rects) |
| 129 if (i < 4) { | 130 if (i < 4) { |
| 130 REPORTER_ASSERT(reporter, layer->isAtlased()); | 131 REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 131 } else { | 132 } else { |
| 132 // The 5th layer couldn't fit in the atlas | 133 // The 5th layer couldn't fit in the atlas |
| 133 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 134 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 134 } | 135 } |
| 135 } | 136 } |
| 136 | 137 |
| 137 // Unlock the textures | 138 // Unlock the textures |
| 138 for (int i = 0; i < kInitialNumLayers; ++i) { | 139 for (unsigned i = 0; i < kInitialNumLayers; ++i) { |
| 139 int indices[1] = { i+1 }; | 140 unsigned indices[1] = { i+1 }; |
| 140 | 141 |
| 141 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | 142 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), |
| 142 indices, 1); | 143 indices, 1); |
| 143 REPORTER_ASSERT(reporter, layer); | 144 REPORTER_ASSERT(reporter, layer); |
| 144 cache.removeUse(layer); | 145 cache.removeUse(layer); |
| 145 } | 146 } |
| 146 | 147 |
| 147 for (int i = 0; i < kInitialNumLayers; ++i) { | 148 for (unsigned i = 0; i < kInitialNumLayers; ++i) { |
| 148 int indices[1] = { i+1 }; | 149 unsigned indices[1] = { i+1 }; |
| 149 | 150 |
| 150 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | 151 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), |
| 151 indices, 1); | 152 indices, 1); |
| 152 REPORTER_ASSERT(reporter, layer); | 153 REPORTER_ASSERT(reporter, layer); |
| 153 | 154 |
| 154 // All the layers should be unlocked | 155 // All the layers should be unlocked |
| 155 REPORTER_ASSERT(reporter, !layer->locked()); | 156 REPORTER_ASSERT(reporter, !layer->locked()); |
| 156 | 157 |
| 157 // When hoisted layers aren't cached they are aggressively removed | 158 // When hoisted layers aren't cached they are aggressively removed |
| 158 // from the atlas | 159 // from the atlas |
| 159 #if GR_CACHE_HOISTED_LAYERS | 160 #if GR_CACHE_HOISTED_LAYERS |
| 160 // The first 4 layers should still be in the atlas. | 161 // The first 4 layers should still be in the atlas. |
| 161 if (i < 4) { | 162 if (i < 4) { |
| 162 REPORTER_ASSERT(reporter, layer->texture()); | 163 REPORTER_ASSERT(reporter, layer->texture()); |
| 163 REPORTER_ASSERT(reporter, layer->isAtlased()); | 164 REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 164 } else { | 165 } else { |
| 165 #endif | 166 #endif |
| 166 // The final layer should not be atlased. | 167 // The final layer should not be atlased. |
| 167 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 168 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
| 168 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 169 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 169 #if GR_CACHE_HOISTED_LAYERS | 170 #if GR_CACHE_HOISTED_LAYERS |
| 170 } | 171 } |
| 171 #endif | 172 #endif |
| 172 } | 173 } |
| 173 | 174 |
| 174 { | 175 { |
| 175 int indices[1] = { kInitialNumLayers+1 }; | 176 unsigned indices[1] = { kInitialNumLayers+1 }; |
| 176 | 177 |
| 177 // Add an additional layer. Since all the layers are unlocked this | 178 // Add an additional layer. Since all the layers are unlocked this |
| 178 // will force out the first atlased layer | 179 // will force out the first atlased layer |
| 179 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); | 180 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); |
| 180 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | 181 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), |
| 181 indices, 1); | 182 indices, 1); |
| 182 REPORTER_ASSERT(reporter, layer); | 183 REPORTER_ASSERT(reporter, layer); |
| 183 | 184 |
| 184 lock_layer(reporter, &cache, layer); | 185 lock_layer(reporter, &cache, layer); |
| 185 cache.removeUse(layer); | 186 cache.removeUse(layer); |
| 186 } | 187 } |
| 187 | 188 |
| 188 for (int i = 0; i < kInitialNumLayers+1; ++i) { | 189 for (unsigned i = 0; i < kInitialNumLayers+1; ++i) { |
| 189 int indices[1] = { i+1 }; | 190 unsigned indices[1] = { i+1 }; |
| 190 | 191 |
| 191 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), | 192 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID
(), SkMatrix::I(), |
| 192 indices, 1); | 193 indices, 1); |
| 193 #if GR_CACHE_HOISTED_LAYERS | 194 #if GR_CACHE_HOISTED_LAYERS |
| 194 // 3 old layers plus the new one should be in the atlas. | 195 // 3 old layers plus the new one should be in the atlas. |
| 195 if (1 == i || 2 == i || 3 == i || 5 == i) { | 196 if (1 == i || 2 == i || 3 == i || 5 == i) { |
| 196 REPORTER_ASSERT(reporter, layer); | 197 REPORTER_ASSERT(reporter, layer); |
| 197 REPORTER_ASSERT(reporter, !layer->locked()); | 198 REPORTER_ASSERT(reporter, !layer->locked()); |
| 198 REPORTER_ASSERT(reporter, layer->texture()); | 199 REPORTER_ASSERT(reporter, layer->texture()); |
| 199 REPORTER_ASSERT(reporter, layer->isAtlased()); | 200 REPORTER_ASSERT(reporter, layer->isAtlased()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 240 |
| 240 picture.reset(NULL); | 241 picture.reset(NULL); |
| 241 cache.processDeletedPictures(); | 242 cache.processDeletedPictures(); |
| 242 | 243 |
| 243 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | 244 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
| 244 // TODO: add VRAM/resource cache check here | 245 // TODO: add VRAM/resource cache check here |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 | 248 |
| 248 #endif | 249 #endif |
| OLD | NEW |