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 28 matching lines...) Expand all Loading... |
39 int idOffset) { | 39 int idOffset) { |
40 | 40 |
41 for (int i = 0; i < numToAdd; ++i) { | 41 for (int i = 0; i < numToAdd; ++i) { |
42 int indices[1] = { idOffset+i+1 }; | 42 int indices[1] = { idOffset+i+1 }; |
43 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), | 43 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), |
44 idOffset+i+1, idOffset+i
+2, | 44 idOffset+i+1, idOffset+i
+2, |
45 SkIRect::MakeEmpty(), | 45 SkIRect::MakeEmpty(), |
46 SkIRect::MakeEmpty(), | 46 SkIRect::MakeEmpty(), |
47 SkMatrix::I(), | 47 SkMatrix::I(), |
48 indices, 1, | 48 indices, 1, |
49 NULL); | 49 nullptr); |
50 REPORTER_ASSERT(reporter, layer); | 50 REPORTER_ASSERT(reporter, layer); |
51 GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkM
atrix::I(), | 51 GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkM
atrix::I(), |
52 indices, 1); | 52 indices, 1); |
53 REPORTER_ASSERT(reporter, temp == layer); | 53 REPORTER_ASSERT(reporter, temp == layer); |
54 | 54 |
55 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset +
i + 1); | 55 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset +
i + 1); |
56 | 56 |
57 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); | 57 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); |
58 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); | 58 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); |
59 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); | 59 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); |
60 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 60 REPORTER_ASSERT(reporter, nullptr == layer->texture()); |
61 REPORTER_ASSERT(reporter, NULL == layer->paint()); | 61 REPORTER_ASSERT(reporter, nullptr == layer->paint()); |
62 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 62 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 static void lock_layer(skiatest::Reporter* reporter, | 66 static void lock_layer(skiatest::Reporter* reporter, |
67 GrLayerCache* cache, | 67 GrLayerCache* cache, |
68 GrCachedLayer* layer) { | 68 GrCachedLayer* layer) { |
69 // Make the layer 512x512 (so it can be atlased) | 69 // Make the layer 512x512 (so it can be atlased) |
70 GrSurfaceDesc desc; | 70 GrSurfaceDesc desc; |
71 desc.fWidth = 512; | 71 desc.fWidth = 512; |
(...skipping 27 matching lines...) Expand all Loading... |
99 | 99 |
100 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 100 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
101 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type) i; | 101 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type) i; |
102 | 102 |
103 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | 103 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
104 continue; | 104 continue; |
105 } | 105 } |
106 | 106 |
107 GrContext* context = factory->get(glCtxType); | 107 GrContext* context = factory->get(glCtxType); |
108 | 108 |
109 if (NULL == context) { | 109 if (nullptr == context) { |
110 continue; | 110 continue; |
111 } | 111 } |
112 | 112 |
113 SkPictureRecorder recorder; | 113 SkPictureRecorder recorder; |
114 SkCanvas* c = recorder.beginRecording(1, 1); | 114 SkCanvas* c = recorder.beginRecording(1, 1); |
115 // Draw something, anything, to prevent an empty-picture optimizatio
n, | 115 // Draw something, anything, to prevent an empty-picture optimizatio
n, |
116 // which is a singleton and never purged. | 116 // which is a singleton and never purged. |
117 c->drawRect(SkRect::MakeWH(1,1), SkPaint()); | 117 c->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
118 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 118 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
119 | 119 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // When hoisted layers aren't cached they are aggressively removed | 162 // When hoisted layers aren't cached they are aggressively removed |
163 // from the atlas | 163 // from the atlas |
164 #if GR_CACHE_HOISTED_LAYERS | 164 #if GR_CACHE_HOISTED_LAYERS |
165 // The first 4 layers should still be in the atlas. | 165 // The first 4 layers should still be in the atlas. |
166 if (i < 4) { | 166 if (i < 4) { |
167 REPORTER_ASSERT(reporter, layer->texture()); | 167 REPORTER_ASSERT(reporter, layer->texture()); |
168 REPORTER_ASSERT(reporter, layer->isAtlased()); | 168 REPORTER_ASSERT(reporter, layer->isAtlased()); |
169 } else { | 169 } else { |
170 #endif | 170 #endif |
171 // The final layer should not be atlased. | 171 // The final layer should not be atlased. |
172 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 172 REPORTER_ASSERT(reporter, nullptr == layer->texture()); |
173 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 173 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
174 #if GR_CACHE_HOISTED_LAYERS | 174 #if GR_CACHE_HOISTED_LAYERS |
175 } | 175 } |
176 #endif | 176 #endif |
177 } | 177 } |
178 | 178 |
179 { | 179 { |
180 int indices[1] = { kInitialNumLayers+1 }; | 180 int indices[1] = { kInitialNumLayers+1 }; |
181 | 181 |
182 // Add an additional layer. Since all the layers are unlocked this | 182 // Add an additional layer. Since all the layers are unlocked this |
(...skipping 17 matching lines...) Expand all Loading... |
200 if (1 == i || 2 == i || 3 == i || 5 == i) { | 200 if (1 == i || 2 == i || 3 == i || 5 == i) { |
201 REPORTER_ASSERT(reporter, layer); | 201 REPORTER_ASSERT(reporter, layer); |
202 REPORTER_ASSERT(reporter, !layer->locked()); | 202 REPORTER_ASSERT(reporter, !layer->locked()); |
203 REPORTER_ASSERT(reporter, layer->texture()); | 203 REPORTER_ASSERT(reporter, layer->texture()); |
204 REPORTER_ASSERT(reporter, layer->isAtlased()); | 204 REPORTER_ASSERT(reporter, layer->isAtlased()); |
205 } else if (4 == i) { | 205 } else if (4 == i) { |
206 #endif | 206 #endif |
207 // The one that was never atlased should still be around | 207 // The one that was never atlased should still be around |
208 REPORTER_ASSERT(reporter, layer); | 208 REPORTER_ASSERT(reporter, layer); |
209 | 209 |
210 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 210 REPORTER_ASSERT(reporter, nullptr == layer->texture()); |
211 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 211 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
212 #if GR_CACHE_HOISTED_LAYERS | 212 #if GR_CACHE_HOISTED_LAYERS |
213 } else { | 213 } else { |
214 // The one bumped out of the atlas (i.e., 0) should be gone | 214 // The one bumped out of the atlas (i.e., 0) should be gone |
215 REPORTER_ASSERT(reporter, NULL == layer); | 215 REPORTER_ASSERT(reporter, nullptr == layer); |
216 } | 216 } |
217 #endif | 217 #endif |
218 } | 218 } |
219 | 219 |
220 //-------------------------------------------------------------------- | 220 //-------------------------------------------------------------------- |
221 // Free them all SkGpuDevice-style. This will not free up the | 221 // Free them all SkGpuDevice-style. This will not free up the |
222 // atlas' texture but will eliminate all the layers. | 222 // atlas' texture but will eliminate all the layers. |
223 TestingAccess::Purge(&cache, picture->uniqueID()); | 223 TestingAccess::Purge(&cache, picture->uniqueID()); |
224 | 224 |
225 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | 225 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
226 // TODO: add VRAM/resource cache check here | 226 // TODO: add VRAM/resource cache check here |
227 | 227 |
228 //-------------------------------------------------------------------- | 228 //-------------------------------------------------------------------- |
229 // Test out the GrContext-style purge. This should remove all the layers | 229 // Test out the GrContext-style purge. This should remove all the layers |
230 // and the atlas. | 230 // and the atlas. |
231 // Re-create the layers | 231 // Re-create the layers |
232 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); | 232 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
233 | 233 |
234 // Free them again GrContext-style. This should free up everything. | 234 // Free them again GrContext-style. This should free up everything. |
235 cache.freeAll(); | 235 cache.freeAll(); |
236 | 236 |
237 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | 237 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
238 // TODO: add VRAM/resource cache check here | 238 // TODO: add VRAM/resource cache check here |
239 | 239 |
240 //-------------------------------------------------------------------- | 240 //-------------------------------------------------------------------- |
241 // Test out the MessageBus-style purge. This will not free the atlas | 241 // Test out the MessageBus-style purge. This will not free the atlas |
242 // but should eliminate the free-floating layers. | 242 // but should eliminate the free-floating layers. |
243 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); | 243 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
244 | 244 |
245 picture.reset(NULL); | 245 picture.reset(nullptr); |
246 cache.processDeletedPictures(); | 246 cache.processDeletedPictures(); |
247 | 247 |
248 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | 248 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
249 // TODO: add VRAM/resource cache check here | 249 // TODO: add VRAM/resource cache check here |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 #endif | 253 #endif |
OLD | NEW |