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 class TestingAccess { | 16 class TestingAccess { |
17 public: | 17 public: |
18 static int NumLayers(GrLayerCache* cache) { | 18 static int NumLayers(GrLayerCache* cache) { |
19 return cache->numLayers(); | 19 return cache->numLayers(); |
20 } | 20 } |
21 static void Purge(GrLayerCache* cache, uint32_t pictureID) { | 21 static void Purge(GrLayerCache* cache, uint32_t pictureID) { |
22 cache->purge(pictureID); | 22 cache->purge(pictureID); |
23 } | 23 } |
| 24 static int Uses(GrCachedLayer* layer) { |
| 25 return layer->uses(); |
| 26 } |
24 }; | 27 }; |
25 | 28 |
26 // Add several layers to the cache | 29 // Add several layers to the cache |
27 static void create_layers(skiatest::Reporter* reporter, | 30 static void create_layers(skiatest::Reporter* reporter, |
28 GrLayerCache* cache, | 31 GrLayerCache* cache, |
29 const SkPicture& picture, | 32 const SkPicture& picture, |
30 int numToAdd, | 33 int numToAdd, |
31 int idOffset) { | 34 int idOffset) { |
32 | 35 |
33 for (int i = 0; i < numToAdd; ++i) { | 36 for (int i = 0; i < numToAdd; ++i) { |
(...skipping 29 matching lines...) Expand all Loading... |
63 desc.fConfig = kSkia8888_GrPixelConfig; | 66 desc.fConfig = kSkia8888_GrPixelConfig; |
64 | 67 |
65 bool needsRerendering = cache->lock(layer, desc, false); | 68 bool needsRerendering = cache->lock(layer, desc, false); |
66 REPORTER_ASSERT(reporter, needsRerendering); | 69 REPORTER_ASSERT(reporter, needsRerendering); |
67 | 70 |
68 needsRerendering = cache->lock(layer, desc, false); | 71 needsRerendering = cache->lock(layer, desc, false); |
69 REPORTER_ASSERT(reporter, !needsRerendering); | 72 REPORTER_ASSERT(reporter, !needsRerendering); |
70 | 73 |
71 REPORTER_ASSERT(reporter, layer->texture()); | 74 REPORTER_ASSERT(reporter, layer->texture()); |
72 REPORTER_ASSERT(reporter, layer->locked()); | 75 REPORTER_ASSERT(reporter, layer->locked()); |
| 76 |
| 77 cache->addUse(layer); |
| 78 |
| 79 REPORTER_ASSERT(reporter, 1 == TestingAccess::Uses(layer)); |
73 } | 80 } |
74 | 81 |
75 // This test case exercises the public API of the GrLayerCache class. | 82 // This test case exercises the public API of the GrLayerCache class. |
76 // In particular it checks its interaction with the resource cache (w.r.t. | 83 // In particular it checks its interaction with the resource cache (w.r.t. |
77 // locking & unlocking textures). | 84 // locking & unlocking textures). |
78 // TODO: need to add checks on VRAM usage! | 85 // TODO: need to add checks on VRAM usage! |
79 DEF_GPUTEST(GpuLayerCache, reporter, factory) { | 86 DEF_GPUTEST(GpuLayerCache, reporter, factory) { |
80 static const int kInitialNumLayers = 5; | 87 static const int kInitialNumLayers = 5; |
81 | 88 |
82 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 89 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
(...skipping 30 matching lines...) Expand all Loading... |
113 } else { | 120 } else { |
114 // The 5th layer couldn't fit in the atlas | 121 // The 5th layer couldn't fit in the atlas |
115 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 122 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
116 } | 123 } |
117 } | 124 } |
118 | 125 |
119 // Unlock the textures | 126 // Unlock the textures |
120 for (int i = 0; i < kInitialNumLayers; ++i) { | 127 for (int i = 0; i < kInitialNumLayers; ++i) { |
121 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); | 128 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); |
122 REPORTER_ASSERT(reporter, layer); | 129 REPORTER_ASSERT(reporter, layer); |
123 cache.unlock(layer); | 130 cache.removeUse(layer); |
124 } | 131 } |
125 | 132 |
126 for (int i = 0; i < kInitialNumLayers; ++i) { | 133 for (int i = 0; i < kInitialNumLayers; ++i) { |
127 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); | 134 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); |
128 REPORTER_ASSERT(reporter, layer); | 135 REPORTER_ASSERT(reporter, layer); |
129 | 136 |
| 137 // All the layers should be unlocked |
130 REPORTER_ASSERT(reporter, !layer->locked()); | 138 REPORTER_ASSERT(reporter, !layer->locked()); |
| 139 |
131 // The first 4 layers should still be in the atlas. | 140 // The first 4 layers should still be in the atlas. |
132 if (i < 4) { | 141 if (i < 4) { |
133 REPORTER_ASSERT(reporter, layer->texture()); | 142 REPORTER_ASSERT(reporter, layer->texture()); |
134 REPORTER_ASSERT(reporter, layer->isAtlased()); | 143 REPORTER_ASSERT(reporter, layer->isAtlased()); |
135 } else { | 144 } else { |
136 // The final layer should be unlocked. | 145 // The final layer should not be atlased. |
137 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 146 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
138 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 147 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
139 } | 148 } |
140 } | 149 } |
141 | 150 |
142 { | 151 { |
143 // Add an additional layer. Since all the layers are unlocked this | 152 // Add an additional layer. Since all the layers are unlocked this |
144 // will force out the first atlased layer | 153 // will force out the first atlased layer |
145 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); | 154 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); |
146 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), | 155 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), |
147 kInitialNumLayers+1, SkMatrix
::I()); | 156 kInitialNumLayers+1, SkMatrix
::I()); |
148 REPORTER_ASSERT(reporter, layer); | 157 REPORTER_ASSERT(reporter, layer); |
149 | 158 |
150 lock_layer(reporter, &cache, layer); | 159 lock_layer(reporter, &cache, layer); |
151 cache.unlock(layer); | 160 cache.removeUse(layer); |
152 } | 161 } |
153 | 162 |
154 for (int i = 0; i < kInitialNumLayers+1; ++i) { | 163 for (int i = 0; i < kInitialNumLayers+1; ++i) { |
155 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); | 164 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, SkM
atrix::I()); |
156 // 3 old layers plus the new one should be in the atlas. | 165 // 3 old layers plus the new one should be in the atlas. |
157 if (1 == i || 2 == i || 3 == i || 5 == i) { | 166 if (1 == i || 2 == i || 3 == i || 5 == i) { |
158 REPORTER_ASSERT(reporter, layer); | 167 REPORTER_ASSERT(reporter, layer); |
159 REPORTER_ASSERT(reporter, !layer->locked()); | 168 REPORTER_ASSERT(reporter, !layer->locked()); |
160 REPORTER_ASSERT(reporter, layer->texture()); | 169 REPORTER_ASSERT(reporter, layer->texture()); |
161 REPORTER_ASSERT(reporter, layer->isAtlased()); | 170 REPORTER_ASSERT(reporter, layer->isAtlased()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 207 |
199 picture.reset(NULL); | 208 picture.reset(NULL); |
200 cache.processDeletedPictures(); | 209 cache.processDeletedPictures(); |
201 | 210 |
202 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | 211 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
203 // TODO: add VRAM/resource cache check here | 212 // TODO: add VRAM/resource cache check here |
204 } | 213 } |
205 } | 214 } |
206 | 215 |
207 #endif | 216 #endif |
OLD | NEW |