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