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 18 matching lines...) Expand all Loading... |
29 // Add several layers to the cache | 29 // Add several layers to the cache |
30 static void create_layers(skiatest::Reporter* reporter, | 30 static void create_layers(skiatest::Reporter* reporter, |
31 GrLayerCache* cache, | 31 GrLayerCache* cache, |
32 const SkPicture& picture, | 32 const SkPicture& picture, |
33 int numToAdd, | 33 int numToAdd, |
34 int idOffset) { | 34 int idOffset) { |
35 | 35 |
36 for (int i = 0; i < numToAdd; ++i) { | 36 for (int i = 0; i < numToAdd; ++i) { |
37 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), | 37 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), |
38 idOffset+i+1, idOffset+i
+2, | 38 idOffset+i+1, idOffset+i
+2, |
| 39 SkIRect::MakeEmpty(), |
39 SkMatrix::I(), | 40 SkMatrix::I(), |
40 NULL); | 41 NULL); |
41 REPORTER_ASSERT(reporter, layer); | 42 REPORTER_ASSERT(reporter, layer); |
42 GrCachedLayer* temp = cache->findLayer(picture.uniqueID(), idOffset+i+1, | 43 GrCachedLayer* temp = cache->findLayer(picture.uniqueID(), idOffset + i
+ 1, |
43 SkMatrix::I()); | 44 SkIRect::MakeEmpty(), SkMatrix::I
()); |
44 REPORTER_ASSERT(reporter, temp == layer); | 45 REPORTER_ASSERT(reporter, temp == layer); |
45 | 46 |
46 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset +
i + 1); | 47 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset +
i + 1); |
47 | 48 |
48 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); | 49 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); |
49 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); | 50 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); |
50 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); | 51 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); |
51 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 52 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
52 REPORTER_ASSERT(reporter, NULL == layer->paint()); | 53 REPORTER_ASSERT(reporter, NULL == layer->paint()); |
53 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 54 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 102 |
102 SkPictureRecorder recorder; | 103 SkPictureRecorder recorder; |
103 recorder.beginRecording(1, 1); | 104 recorder.beginRecording(1, 1); |
104 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 105 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
105 | 106 |
106 GrLayerCache cache(context); | 107 GrLayerCache cache(context); |
107 | 108 |
108 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); | 109 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
109 | 110 |
110 for (int i = 0; i < kInitialNumLayers; ++i) { | 111 for (int i = 0; i < kInitialNumLayers; ++i) { |
111 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); | 112 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, |
| 113 SkIRect::MakeEmpty(), SkMatri
x::I()); |
112 REPORTER_ASSERT(reporter, layer); | 114 REPORTER_ASSERT(reporter, layer); |
113 | 115 |
114 lock_layer(reporter, &cache, layer); | 116 lock_layer(reporter, &cache, layer); |
115 | 117 |
116 // The first 4 layers should be in the atlas (and thus have non-empt
y | 118 // The first 4 layers should be in the atlas (and thus have non-empt
y |
117 // rects) | 119 // rects) |
118 if (i < 4) { | 120 if (i < 4) { |
119 REPORTER_ASSERT(reporter, layer->isAtlased()); | 121 REPORTER_ASSERT(reporter, layer->isAtlased()); |
120 } else { | 122 } else { |
121 // The 5th layer couldn't fit in the atlas | 123 // The 5th layer couldn't fit in the atlas |
122 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 124 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
123 } | 125 } |
124 } | 126 } |
125 | 127 |
126 // Unlock the textures | 128 // Unlock the textures |
127 for (int i = 0; i < kInitialNumLayers; ++i) { | 129 for (int i = 0; i < kInitialNumLayers; ++i) { |
128 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); | 130 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, |
| 131 SkIRect::MakeEmpty(), SkMatri
x::I()); |
129 REPORTER_ASSERT(reporter, layer); | 132 REPORTER_ASSERT(reporter, layer); |
130 cache.removeUse(layer); | 133 cache.removeUse(layer); |
131 } | 134 } |
132 | 135 |
133 for (int i = 0; i < kInitialNumLayers; ++i) { | 136 for (int i = 0; i < kInitialNumLayers; ++i) { |
134 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); | 137 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, |
| 138 SkIRect::MakeEmpty(), SkMatri
x::I()); |
135 REPORTER_ASSERT(reporter, layer); | 139 REPORTER_ASSERT(reporter, layer); |
136 | 140 |
137 // All the layers should be unlocked | 141 // All the layers should be unlocked |
138 REPORTER_ASSERT(reporter, !layer->locked()); | 142 REPORTER_ASSERT(reporter, !layer->locked()); |
139 | 143 |
140 // The first 4 layers should still be in the atlas. | 144 // The first 4 layers should still be in the atlas. |
141 if (i < 4) { | 145 if (i < 4) { |
142 REPORTER_ASSERT(reporter, layer->texture()); | 146 REPORTER_ASSERT(reporter, layer->texture()); |
143 REPORTER_ASSERT(reporter, layer->isAtlased()); | 147 REPORTER_ASSERT(reporter, layer->isAtlased()); |
144 } else { | 148 } else { |
145 // The final layer should not be atlased. | 149 // The final layer should not be atlased. |
146 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 150 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
147 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 151 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
148 } | 152 } |
149 } | 153 } |
150 | 154 |
151 { | 155 { |
152 // Add an additional layer. Since all the layers are unlocked this | 156 // Add an additional layer. Since all the layers are unlocked this |
153 // will force out the first atlased layer | 157 // will force out the first atlased layer |
154 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); | 158 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); |
155 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), | 159 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), |
156 kInitialNumLayers+1, SkMatrix
::I()); | 160 kInitialNumLayers+1, |
| 161 SkIRect::MakeEmpty(), SkMatri
x::I()); |
157 REPORTER_ASSERT(reporter, layer); | 162 REPORTER_ASSERT(reporter, layer); |
158 | 163 |
159 lock_layer(reporter, &cache, layer); | 164 lock_layer(reporter, &cache, layer); |
160 cache.removeUse(layer); | 165 cache.removeUse(layer); |
161 } | 166 } |
162 | 167 |
163 for (int i = 0; i < kInitialNumLayers+1; ++i) { | 168 for (int i = 0; i < kInitialNumLayers+1; ++i) { |
164 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); | 169 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i + 1, |
| 170 SkIRect::MakeEmpty(), SkMatri
x::I()); |
165 // 3 old layers plus the new one should be in the atlas. | 171 // 3 old layers plus the new one should be in the atlas. |
166 if (1 == i || 2 == i || 3 == i || 5 == i) { | 172 if (1 == i || 2 == i || 3 == i || 5 == i) { |
167 REPORTER_ASSERT(reporter, layer); | 173 REPORTER_ASSERT(reporter, layer); |
168 REPORTER_ASSERT(reporter, !layer->locked()); | 174 REPORTER_ASSERT(reporter, !layer->locked()); |
169 REPORTER_ASSERT(reporter, layer->texture()); | 175 REPORTER_ASSERT(reporter, layer->texture()); |
170 REPORTER_ASSERT(reporter, layer->isAtlased()); | 176 REPORTER_ASSERT(reporter, layer->isAtlased()); |
171 } else if (4 == i) { | 177 } else if (4 == i) { |
172 // The one that was never atlased should still be around | 178 // The one that was never atlased should still be around |
173 REPORTER_ASSERT(reporter, layer); | 179 REPORTER_ASSERT(reporter, layer); |
174 | 180 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 213 |
208 picture.reset(NULL); | 214 picture.reset(NULL); |
209 cache.processDeletedPictures(); | 215 cache.processDeletedPictures(); |
210 | 216 |
211 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | 217 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
212 // TODO: add VRAM/resource cache check here | 218 // TODO: add VRAM/resource cache check here |
213 } | 219 } |
214 } | 220 } |
215 | 221 |
216 #endif | 222 #endif |
OLD | NEW |