| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 // Add several layers to the cache | 26 // Add several layers to the cache |
| 27 static void create_layers(skiatest::Reporter* reporter, | 27 static void create_layers(skiatest::Reporter* reporter, |
| 28 GrLayerCache* cache, | 28 GrLayerCache* cache, |
| 29 const SkPicture& picture, | 29 const SkPicture& picture, |
| 30 int numToAdd, | 30 int numToAdd, |
| 31 int idOffset) { | 31 int idOffset) { |
| 32 | 32 |
| 33 for (int i = 0; i < numToAdd; ++i) { | 33 for (int i = 0; i < numToAdd; ++i) { |
| 34 GrCachedLayer* layer = cache->findLayerOrCreate(&picture, idOffset+i); | 34 GrCachedLayer* layer = cache->findLayerOrCreate(&picture, |
| 35 idOffset+i+1, idOffset+i
+2, |
| 36 SkMatrix::I()); |
| 35 REPORTER_ASSERT(reporter, NULL != layer); | 37 REPORTER_ASSERT(reporter, NULL != layer); |
| 36 GrCachedLayer* temp = cache->findLayer(&picture, idOffset+i); | 38 GrCachedLayer* temp = cache->findLayer(&picture, idOffset+i+1, idOffset+
i+2, SkMatrix::I()); |
| 37 REPORTER_ASSERT(reporter, temp == layer); | 39 REPORTER_ASSERT(reporter, temp == layer); |
| 38 | 40 |
| 39 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset +
i + 1); | 41 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset +
i + 1); |
| 40 | 42 |
| 41 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); | 43 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); |
| 42 REPORTER_ASSERT(reporter, layer->layerID() == idOffset + i); | 44 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); |
| 45 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); |
| 46 REPORTER_ASSERT(reporter, layer->ctm() == SkMatrix::I()); |
| 43 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 47 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
| 44 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 48 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 45 } | 49 } |
| 46 | 50 |
| 47 cache->trackPicture(&picture); | 51 cache->trackPicture(&picture); |
| 48 } | 52 } |
| 49 | 53 |
| 50 static void lock_layer(skiatest::Reporter* reporter, | 54 static void lock_layer(skiatest::Reporter* reporter, |
| 51 GrLayerCache* cache, | 55 GrLayerCache* cache, |
| 52 GrCachedLayer* layer) { | 56 GrCachedLayer* layer) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 92 |
| 89 SkPictureRecorder recorder; | 93 SkPictureRecorder recorder; |
| 90 recorder.beginRecording(1, 1); | 94 recorder.beginRecording(1, 1); |
| 91 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 95 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
| 92 | 96 |
| 93 GrLayerCache cache(context); | 97 GrLayerCache cache(context); |
| 94 | 98 |
| 95 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); | 99 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
| 96 | 100 |
| 97 for (int i = 0; i < kInitialNumLayers; ++i) { | 101 for (int i = 0; i < kInitialNumLayers; ++i) { |
| 98 GrCachedLayer* layer = cache.findLayer(picture, i); | 102 GrCachedLayer* layer = cache.findLayer(picture, i+1, i+2, SkMatrix::
I()); |
| 99 REPORTER_ASSERT(reporter, NULL != layer); | 103 REPORTER_ASSERT(reporter, NULL != layer); |
| 100 | 104 |
| 101 lock_layer(reporter, &cache, layer); | 105 lock_layer(reporter, &cache, layer); |
| 102 | 106 |
| 103 // The first 4 layers should be in the atlas (and thus have non-empt
y | 107 // The first 4 layers should be in the atlas (and thus have non-empt
y |
| 104 // rects) | 108 // rects) |
| 105 if (i < 4) { | 109 if (i < 4) { |
| 106 REPORTER_ASSERT(reporter, layer->isAtlased()); | 110 REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 107 } else { | 111 } else { |
| 108 // The 5th layer couldn't fit in the atlas | 112 // The 5th layer couldn't fit in the atlas |
| 109 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 113 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 110 } | 114 } |
| 111 } | 115 } |
| 112 | 116 |
| 113 // Unlock the textures | 117 // Unlock the textures |
| 114 for (int i = 0; i < kInitialNumLayers; ++i) { | 118 for (int i = 0; i < kInitialNumLayers; ++i) { |
| 115 GrCachedLayer* layer = cache.findLayer(picture, i); | 119 GrCachedLayer* layer = cache.findLayer(picture, i+1, i+2, SkMatrix::
I()); |
| 116 REPORTER_ASSERT(reporter, NULL != layer); | 120 REPORTER_ASSERT(reporter, NULL != layer); |
| 117 | 121 |
| 118 cache.unlock(layer); | 122 cache.unlock(layer); |
| 119 } | 123 } |
| 120 | 124 |
| 121 for (int i = 0; i < kInitialNumLayers; ++i) { | 125 for (int i = 0; i < kInitialNumLayers; ++i) { |
| 122 GrCachedLayer* layer = cache.findLayer(picture, i); | 126 GrCachedLayer* layer = cache.findLayer(picture, i+1, i+2, SkMatrix::
I()); |
| 123 REPORTER_ASSERT(reporter, NULL != layer); | 127 REPORTER_ASSERT(reporter, NULL != layer); |
| 124 | 128 |
| 125 REPORTER_ASSERT(reporter, !layer->locked()); | 129 REPORTER_ASSERT(reporter, !layer->locked()); |
| 126 // The first 4 layers should still be in the atlas. | 130 // The first 4 layers should still be in the atlas. |
| 127 if (i < 4) { | 131 if (i < 4) { |
| 128 REPORTER_ASSERT(reporter, NULL != layer->texture()); | 132 REPORTER_ASSERT(reporter, NULL != layer->texture()); |
| 129 REPORTER_ASSERT(reporter, layer->isAtlased()); | 133 REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 130 } else { | 134 } else { |
| 131 // The final layer should be unlocked. | 135 // The final layer should be unlocked. |
| 132 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 136 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
| 133 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 137 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
| 134 } | 138 } |
| 135 } | 139 } |
| 136 | 140 |
| 137 { | 141 { |
| 138 // Add an additional layer. Since all the layers are unlocked this | 142 // Add an additional layer. Since all the layers are unlocked this |
| 139 // will force out the first atlased layer | 143 // will force out the first atlased layer |
| 140 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); | 144 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); |
| 141 GrCachedLayer* layer = cache.findLayer(picture, kInitialNumLayers); | 145 GrCachedLayer* layer = cache.findLayer(picture, |
| 146 kInitialNumLayers+1, kInitial
NumLayers+2, |
| 147 SkMatrix::I()); |
| 142 REPORTER_ASSERT(reporter, NULL != layer); | 148 REPORTER_ASSERT(reporter, NULL != layer); |
| 143 | 149 |
| 144 lock_layer(reporter, &cache, layer); | 150 lock_layer(reporter, &cache, layer); |
| 145 cache.unlock(layer); | 151 cache.unlock(layer); |
| 146 } | 152 } |
| 147 | 153 |
| 148 for (int i = 0; i < kInitialNumLayers+1; ++i) { | 154 for (int i = 0; i < kInitialNumLayers+1; ++i) { |
| 149 GrCachedLayer* layer = cache.findLayer(picture, i); | 155 GrCachedLayer* layer = cache.findLayer(picture, i+1, i+2, SkMatrix::
I()); |
| 150 // 3 old layers plus the new one should be in the atlas. | 156 // 3 old layers plus the new one should be in the atlas. |
| 151 if (1 == i || 2 == i || 3 == i || 5 == i) { | 157 if (1 == i || 2 == i || 3 == i || 5 == i) { |
| 152 REPORTER_ASSERT(reporter, NULL != layer); | 158 REPORTER_ASSERT(reporter, NULL != layer); |
| 153 REPORTER_ASSERT(reporter, !layer->locked()); | 159 REPORTER_ASSERT(reporter, !layer->locked()); |
| 154 REPORTER_ASSERT(reporter, NULL != layer->texture()); | 160 REPORTER_ASSERT(reporter, NULL != layer->texture()); |
| 155 REPORTER_ASSERT(reporter, layer->isAtlased()); | 161 REPORTER_ASSERT(reporter, layer->isAtlased()); |
| 156 } else if (4 == i) { | 162 } else if (4 == i) { |
| 157 // The one that was never atlased should still be around | 163 // The one that was never atlased should still be around |
| 158 REPORTER_ASSERT(reporter, NULL != layer); | 164 REPORTER_ASSERT(reporter, NULL != layer); |
| 159 | 165 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 198 |
| 193 picture.reset(NULL); | 199 picture.reset(NULL); |
| 194 cache.processDeletedPictures(); | 200 cache.processDeletedPictures(); |
| 195 | 201 |
| 196 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | 202 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
| 197 // TODO: add VRAM/resource cache check here | 203 // TODO: add VRAM/resource cache check here |
| 198 } | 204 } |
| 199 } | 205 } |
| 200 | 206 |
| 201 #endif | 207 #endif |
| OLD | NEW |