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 "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 240 |
241 REPORTER_ASSERT(reporter, 200 == cache.getCachedResourceBytes()); | 241 REPORTER_ASSERT(reporter, 200 == cache.getCachedResourceBytes()); |
242 REPORTER_ASSERT(reporter, 2 == cache.getCachedResourceCount()); | 242 REPORTER_ASSERT(reporter, 2 == cache.getCachedResourceCount()); |
243 | 243 |
244 static_cast<TestResource*>(cache.find(key2))->setSize(201); | 244 static_cast<TestResource*>(cache.find(key2))->setSize(201); |
245 REPORTER_ASSERT(reporter, NULL == cache.find(key1)); | 245 REPORTER_ASSERT(reporter, NULL == cache.find(key1)); |
246 | 246 |
247 REPORTER_ASSERT(reporter, 201 == cache.getCachedResourceBytes()); | 247 REPORTER_ASSERT(reporter, 201 == cache.getCachedResourceBytes()); |
248 REPORTER_ASSERT(reporter, 1 == cache.getCachedResourceCount()); | 248 REPORTER_ASSERT(reporter, 1 == cache.getCachedResourceCount()); |
249 } | 249 } |
250 | |
251 // Test changing the size of an exclusively-held resource. | |
252 { | |
253 GrResourceCache cache(2, 300); | |
254 | |
255 TestResource* a = new TestResource(context->getGpu(), 100); | |
256 cache.addResource(key1, a); | |
257 cache.makeExclusive(a->getCacheEntry()); | |
258 | |
259 TestResource* b = new TestResource(context->getGpu(), 100); | |
260 cache.addResource(key2, b); | |
261 b->unref(); | |
262 | |
263 REPORTER_ASSERT(reporter, 200 == cache.getCachedResourceBytes()); | |
264 REPORTER_ASSERT(reporter, 2 == cache.getCachedResourceCount()); | |
265 REPORTER_ASSERT(reporter, NULL == cache.find(key1)); | |
266 | |
267 a->setSize(200); | |
268 | |
269 REPORTER_ASSERT(reporter, 300 == cache.getCachedResourceBytes()); | |
270 REPORTER_ASSERT(reporter, 2 == cache.getCachedResourceCount()); | |
271 // Internal resource cache validation will test the detached size (debug
mode only). | |
272 | |
273 cache.makeNonExclusive(a->getCacheEntry()); | |
274 a->unref(); | |
275 | |
276 REPORTER_ASSERT(reporter, 300 == cache.getCachedResourceBytes()); | |
277 REPORTER_ASSERT(reporter, 2 == cache.getCachedResourceCount()); | |
278 REPORTER_ASSERT(reporter, cache.find(key1)); | |
279 // Internal resource cache validation will test the detached size (debug
mode only). | |
280 } | |
281 } | 250 } |
282 | 251 |
283 //////////////////////////////////////////////////////////////////////////////// | 252 //////////////////////////////////////////////////////////////////////////////// |
284 DEF_GPUTEST(ResourceCache, reporter, factory) { | 253 DEF_GPUTEST(ResourceCache, reporter, factory) { |
285 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 254 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
286 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 255 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
287 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 256 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
288 continue; | 257 continue; |
289 } | 258 } |
290 GrContext* context = factory->get(glType); | 259 GrContext* context = factory->get(glType); |
(...skipping 10 matching lines...) Expand all Loading... |
301 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info
)); | 270 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info
)); |
302 | 271 |
303 test_cache(reporter, context, surface->getCanvas()); | 272 test_cache(reporter, context, surface->getCanvas()); |
304 test_purge_invalidated(reporter, context); | 273 test_purge_invalidated(reporter, context); |
305 test_cache_delete_on_destruction(reporter, context); | 274 test_cache_delete_on_destruction(reporter, context); |
306 test_resource_size_changed(reporter, context); | 275 test_resource_size_changed(reporter, context); |
307 } | 276 } |
308 } | 277 } |
309 | 278 |
310 #endif | 279 #endif |
OLD | NEW |