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 } |
250 } | 281 } |
251 | 282 |
252 //////////////////////////////////////////////////////////////////////////////// | 283 //////////////////////////////////////////////////////////////////////////////// |
253 DEF_GPUTEST(ResourceCache, reporter, factory) { | 284 DEF_GPUTEST(ResourceCache, reporter, factory) { |
254 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 285 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
255 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 286 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
256 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 287 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
257 continue; | 288 continue; |
258 } | 289 } |
259 GrContext* context = factory->get(glType); | 290 GrContext* context = factory->get(glType); |
(...skipping 10 matching lines...) Expand all Loading... |
270 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info
)); | 301 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, info
)); |
271 | 302 |
272 test_cache(reporter, context, surface->getCanvas()); | 303 test_cache(reporter, context, surface->getCanvas()); |
273 test_purge_invalidated(reporter, context); | 304 test_purge_invalidated(reporter, context); |
274 test_cache_delete_on_destruction(reporter, context); | 305 test_cache_delete_on_destruction(reporter, context); |
275 test_resource_size_changed(reporter, context); | 306 test_resource_size_changed(reporter, context); |
276 } | 307 } |
277 } | 308 } |
278 | 309 |
279 #endif | 310 #endif |
OLD | NEW |