OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrContextFactory.h" | 10 #include "GrContextFactory.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 | 51 |
52 // we should never go over the size limit | 52 // we should never go over the size limit |
53 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); | 53 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); |
54 } | 54 } |
55 | 55 |
56 context->setTextureCacheLimits(oldMaxNum, oldMaxBytes); | 56 context->setTextureCacheLimits(oldMaxNum, oldMaxBytes); |
57 } | 57 } |
58 | 58 |
59 class TestResource : public GrCacheable { | 59 class TestResource : public GrCacheable { |
60 public: | 60 public: |
61 SK_DECLARE_INST_COUNT(TestResource); | 61 SK_DECLARE_INST_COUNT(TestResource); |
robertphillips
2014/04/29 13:46:25
TestResouce(size_t size = kDefaultSize) ?
| |
62 TestResource() | 62 TestResource() |
63 : fCache(NULL) | 63 : fCache(NULL) |
64 , fToDelete(NULL) { | 64 , fToDelete(NULL) |
65 , fSize(100) { | |
65 ++fAlive; | 66 ++fAlive; |
66 } | 67 } |
67 | 68 |
68 ~TestResource() { | 69 ~TestResource() { |
69 --fAlive; | 70 --fAlive; |
70 if (NULL != fToDelete) { | 71 if (NULL != fToDelete) { |
71 // Breaks our little 2-element cycle below. | 72 // Breaks our little 2-element cycle below. |
72 fToDelete->setDeleteWhenDestroyed(NULL, NULL); | 73 fToDelete->setDeleteWhenDestroyed(NULL, NULL); |
73 fCache->deleteResource(fToDelete->getCacheEntry()); | 74 fCache->deleteResource(fToDelete->getCacheEntry()); |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
77 size_t gpuMemorySize() const SK_OVERRIDE { return 100; } | 78 void setSize(size_t size) { |
79 fSize = size; | |
80 this->didChangeGpuMemorySize(); | |
81 } | |
82 | |
83 size_t gpuMemorySize() const SK_OVERRIDE { return fSize; } | |
78 | 84 |
79 bool isValidOnGpu() const SK_OVERRIDE { return true; } | 85 bool isValidOnGpu() const SK_OVERRIDE { return true; } |
80 | 86 |
81 static int alive() { return fAlive; } | 87 static int alive() { return fAlive; } |
82 | 88 |
83 void setDeleteWhenDestroyed(GrResourceCache* cache, TestResource* resource) { | 89 void setDeleteWhenDestroyed(GrResourceCache* cache, TestResource* resource) { |
84 fCache = cache; | 90 fCache = cache; |
85 fToDelete = resource; | 91 fToDelete = resource; |
86 } | 92 } |
87 | 93 |
88 private: | 94 private: |
89 GrResourceCache* fCache; | 95 GrResourceCache* fCache; |
90 TestResource* fToDelete; | 96 TestResource* fToDelete; |
97 size_t fSize; | |
91 static int fAlive; | 98 static int fAlive; |
92 | 99 |
93 typedef GrCacheable INHERITED; | 100 typedef GrCacheable INHERITED; |
94 }; | 101 }; |
95 int TestResource::fAlive = 0; | 102 int TestResource::fAlive = 0; |
96 | 103 |
97 static void test_purge_invalidated(skiatest::Reporter* reporter, GrContext* cont ext) { | 104 static void test_purge_invalidated(skiatest::Reporter* reporter, GrContext* cont ext) { |
98 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); | 105 GrCacheID::Domain domain = GrCacheID::GenerateDomain(); |
99 GrCacheID::Key keyData; | 106 GrCacheID::Key keyData; |
100 keyData.fData64[0] = 5; | 107 keyData.fData64[0] = 5; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 174 |
168 a->unref(); | 175 a->unref(); |
169 b->unref(); | 176 b->unref(); |
170 | 177 |
171 cache.deleteResource(a->getCacheEntry()); | 178 cache.deleteResource(a->getCacheEntry()); |
172 | 179 |
173 REPORTER_ASSERT(reporter, 0 == TestResource::alive()); | 180 REPORTER_ASSERT(reporter, 0 == TestResource::alive()); |
174 } | 181 } |
175 } | 182 } |
176 | 183 |
184 static void test_resource_size_changed(skiatest::Reporter* reporter, | |
185 GrContext* context) { | |
robertphillips
2014/04/29 13:46:25
rm '\' ?
| |
186 GrCacheID::Domain domain = GrCacheID::GenerateDomain();\ | |
187 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType(); | |
188 | |
189 GrCacheID::Key key1Data; | |
190 key1Data.fData64[0] = 0; | |
191 key1Data.fData64[1] = 0; | |
192 GrResourceKey key1(GrCacheID(domain, key1Data), t, 0); | |
193 | |
194 GrCacheID::Key key2Data; | |
195 key2Data.fData64[0] = 1; | |
196 key2Data.fData64[1] = 0; | |
197 GrResourceKey key2(GrCacheID(domain, key2Data), t, 0); | |
198 | |
robertphillips
2014/04/29 13:46:25
// Test changing resources sizes when they are non
| |
199 { | |
200 GrResourceCache cache(3, 300); | |
201 | |
202 TestResource* a = new TestResource(); | |
203 a->setSize(100); | |
204 cache.addResource(key1, a); | |
205 a->unref(); | |
206 | |
207 TestResource* b = new TestResource(); | |
208 b->setSize(100); | |
209 cache.addResource(key2, b); | |
210 b->unref(); | |
211 | |
212 REPORTER_ASSERT(reporter, 200 == cache.getCachedResourceBytes()); | |
213 REPORTER_ASSERT(reporter, 2 == cache.getCachedResourceCount()); | |
214 | |
215 static_cast<TestResource*>(cache.find(key2))->setSize(200); | |
216 static_cast<TestResource*>(cache.find(key1))->setSize(50); | |
217 | |
218 REPORTER_ASSERT(reporter, 250 == cache.getCachedResourceBytes()); | |
219 REPORTER_ASSERT(reporter, 2 == cache.getCachedResourceCount()); | |
220 } | |
robertphillips
2014/04/29 13:46:25
// Test changing resource size of exclusively held
| |
221 { | |
222 GrResourceCache cache(3, 300); | |
223 | |
224 TestResource* a = new TestResource(); | |
225 a->setSize(100); | |
226 cache.addResource(key1, a); | |
227 a->unref(); | |
228 | |
229 TestResource* b = new TestResource(); | |
230 b->setSize(100); | |
231 cache.addResource(key2, b); | |
232 b->unref(); | |
233 | |
234 REPORTER_ASSERT(reporter, 200 == cache.getCachedResourceBytes()); | |
235 REPORTER_ASSERT(reporter, 2 == cache.getCachedResourceCount()); | |
236 | |
237 static_cast<TestResource*>(cache.find(key2))->setSize(201); | |
robertphillips
2014/04/29 13:46:25
What am I missing that makes key1 exclusively held
Chris Dalton
2014/04/30 16:47:39
I should have put a comment :) This is testing tha
robertphillips
2014/04/30 17:31:49
Ah okay - that needs a comment! :)
| |
238 REPORTER_ASSERT(reporter, NULL == cache.find(key1)); | |
239 | |
240 REPORTER_ASSERT(reporter, 201 == cache.getCachedResourceBytes()); | |
241 REPORTER_ASSERT(reporter, 1 == cache.getCachedResourceCount()); | |
robertphillips
2014/04/29 13:46:25
Is there a way to check the detached size here? If
| |
242 } | |
243 } | |
244 | |
177 //////////////////////////////////////////////////////////////////////////////// | 245 //////////////////////////////////////////////////////////////////////////////// |
178 DEF_GPUTEST(ResourceCache, reporter, factory) { | 246 DEF_GPUTEST(ResourceCache, reporter, factory) { |
179 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 247 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
180 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); | 248 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); |
181 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 249 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
182 continue; | 250 continue; |
183 } | 251 } |
184 GrContext* context = factory->get(glType); | 252 GrContext* context = factory->get(glType); |
185 if (NULL == context) { | 253 if (NULL == context) { |
186 continue; | 254 continue; |
187 } | 255 } |
188 | 256 |
189 GrTextureDesc desc; | 257 GrTextureDesc desc; |
190 desc.fConfig = kSkia8888_GrPixelConfig; | 258 desc.fConfig = kSkia8888_GrPixelConfig; |
191 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 259 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
192 desc.fWidth = gWidth; | 260 desc.fWidth = gWidth; |
193 desc.fHeight = gHeight; | 261 desc.fHeight = gHeight; |
194 | 262 |
195 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NUL L, 0)); | 263 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NUL L, 0)); |
196 SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, (context, textu re.get()))); | 264 SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, (context, textu re.get()))); |
197 SkCanvas canvas(device.get()); | 265 SkCanvas canvas(device.get()); |
198 | 266 |
199 test_cache(reporter, context, &canvas); | 267 test_cache(reporter, context, &canvas); |
200 test_purge_invalidated(reporter, context); | 268 test_purge_invalidated(reporter, context); |
201 test_cache_delete_on_destruction(reporter, context); | 269 test_cache_delete_on_destruction(reporter, context); |
270 test_resource_size_changed(reporter, context); | |
202 } | 271 } |
203 } | 272 } |
204 | 273 |
205 #endif | 274 #endif |
OLD | NEW |