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 static const int kNumLayers = 5; | 16 static const int kNumLayers = 5; |
17 | 17 |
18 class GetNumLayers { | 18 class TestingAccess { |
19 public: | 19 public: |
20 static int NumLayers(GrLayerCache* cache) { | 20 static int NumLayers(GrLayerCache* cache) { |
21 return cache->numLayers(); | 21 return cache->numLayers(); |
22 } | 22 } |
| 23 static void Purge(GrLayerCache* cache, uint32_t pictureID) { |
| 24 cache->purge(pictureID); |
| 25 } |
23 }; | 26 }; |
24 | 27 |
25 // Add several layers to the cache | 28 // Add several layers to the cache |
26 static void create_layers(skiatest::Reporter* reporter, | 29 static void create_layers(skiatest::Reporter* reporter, |
27 GrLayerCache* cache, | 30 GrLayerCache* cache, |
28 const SkPicture& picture) { | 31 const SkPicture& picture) { |
29 GrCachedLayer* layers[kNumLayers]; | 32 GrCachedLayer* layers[kNumLayers]; |
30 | 33 |
31 for (int i = 0; i < kNumLayers; ++i) { | 34 for (int i = 0; i < kNumLayers; ++i) { |
32 layers[i] = cache->findLayerOrCreate(&picture, i); | 35 layers[i] = cache->findLayerOrCreate(&picture, i); |
33 REPORTER_ASSERT(reporter, NULL != layers[i]); | 36 REPORTER_ASSERT(reporter, NULL != layers[i]); |
34 GrCachedLayer* layer = cache->findLayer(&picture, i); | 37 GrCachedLayer* layer = cache->findLayer(&picture, i); |
35 REPORTER_ASSERT(reporter, layer == layers[i]); | 38 REPORTER_ASSERT(reporter, layer == layers[i]); |
36 | 39 |
37 REPORTER_ASSERT(reporter, GetNumLayers::NumLayers(cache) == i+1); | 40 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == i + 1); |
38 | 41 |
39 REPORTER_ASSERT(reporter, picture.uniqueID() == layers[i]->pictureID()); | 42 REPORTER_ASSERT(reporter, picture.uniqueID() == layers[i]->pictureID()); |
40 REPORTER_ASSERT(reporter, layers[i]->layerID() == i); | 43 REPORTER_ASSERT(reporter, layers[i]->layerID() == i); |
41 REPORTER_ASSERT(reporter, NULL == layers[i]->texture()); | 44 REPORTER_ASSERT(reporter, NULL == layers[i]->texture()); |
42 REPORTER_ASSERT(reporter, !layers[i]->isAtlased()); | 45 REPORTER_ASSERT(reporter, !layers[i]->isAtlased()); |
43 } | 46 } |
44 | 47 |
| 48 cache->trackPicture(&picture); |
45 } | 49 } |
46 | 50 |
47 // This test case exercises the public API of the GrLayerCache class. | 51 // This test case exercises the public API of the GrLayerCache class. |
48 // In particular it checks its interaction with the resource cache (w.r.t. | 52 // In particular it checks its interaction with the resource cache (w.r.t. |
49 // locking & unlocking textures). | 53 // locking & unlocking textures). |
50 // TODO: need to add checks on VRAM usage! | 54 // TODO: need to add checks on VRAM usage! |
51 DEF_GPUTEST(GpuLayerCache, reporter, factory) { | 55 DEF_GPUTEST(GpuLayerCache, reporter, factory) { |
52 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 56 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
53 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type) i; | 57 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type) i; |
54 | 58 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 REPORTER_ASSERT(reporter, layer->isAtlased()); | 123 REPORTER_ASSERT(reporter, layer->isAtlased()); |
120 } else { | 124 } else { |
121 #endif | 125 #endif |
122 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 126 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
123 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 127 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
124 #if USE_ATLAS | 128 #if USE_ATLAS |
125 } | 129 } |
126 #endif | 130 #endif |
127 } | 131 } |
128 | 132 |
| 133 //-------------------------------------------------------------------- |
129 // Free them all SkGpuDevice-style. This will not free up the | 134 // Free them all SkGpuDevice-style. This will not free up the |
130 // atlas' texture but will eliminate all the layers. | 135 // atlas' texture but will eliminate all the layers. |
131 cache.purge(picture); | 136 TestingAccess::Purge(&cache, picture->uniqueID()); |
132 | 137 |
133 REPORTER_ASSERT(reporter, GetNumLayers::NumLayers(&cache) == 0); | 138 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
134 // TODO: add VRAM/resource cache check here | 139 // TODO: add VRAM/resource cache check here |
135 #if 0 | 140 |
| 141 //-------------------------------------------------------------------- |
| 142 // Test out the GrContext-style purge. This should remove all the layers |
| 143 // and the atlas. |
136 // Re-create the layers | 144 // Re-create the layers |
137 create_layers(reporter, &cache, picture); | 145 create_layers(reporter, &cache, *picture); |
138 | 146 |
139 // Free them again GrContext-style. This should free up everything. | 147 // Free them again GrContext-style. This should free up everything. |
140 cache.freeAll(); | 148 cache.freeAll(); |
141 | 149 |
142 REPORTER_ASSERT(reporter, GetNumLayers::NumLayers(&cache) == 0); | 150 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
143 // TODO: add VRAM/resource cache check here | 151 // TODO: add VRAM/resource cache check here |
144 #endif | 152 |
| 153 //-------------------------------------------------------------------- |
| 154 // Test out the MessageBus-style purge. This will not free the atlas |
| 155 // but should eliminate the free-floating layers. |
| 156 create_layers(reporter, &cache, *picture); |
| 157 |
| 158 picture.reset(NULL); |
| 159 cache.processDeletedPictures(); |
| 160 |
| 161 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
| 162 // TODO: add VRAM/resource cache check here |
145 } | 163 } |
146 } | 164 } |
147 | 165 |
148 #endif | 166 #endif |
OLD | NEW |