}
class TestResource : public GrGpuResource {
- static const size_t kDefaultSize = 100;
enum ScratchConstructor { kScratchConstructor };
public:
+ static const size_t kDefaultSize = 100;
/** Property that distinctly categorizes the resource.
* For example, textures have width, height, ... */
REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key);
REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted());
- REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(key));
+ REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(key, TestResource::kDefaultSize, 0));
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount());
REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount());
REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes());
- resource = static_cast<TestResource*>(cache->findAndRefScratchResource(key));
+ resource = static_cast<TestResource*>(cache->findAndRefScratchResource(key, TestResource::kDefaultSize, 0));
REPORTER_ASSERT(reporter, resource);
REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key);
REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch());
GrScratchKey scratchKey1;
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1);
// Check for negative case consistency. (leaks upon test failure.)
- REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(scratchKey1));
+ REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(scratchKey1, TestResource::kDefaultSize, 0));
GrScratchKey scratchKey;
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey);
// Ensure that scratch key lookup is correct for negative case.
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey);
// (following leaks upon test failure).
- REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey) == NULL);
+ REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0) == NULL);
// Scratch resources are registered with GrResourceCache just by existing. There are 2.
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey);
// Find the first resource and remove its scratch key
GrGpuResource* find;
- find = cache->findAndRefScratchResource(scratchKey);
+ find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
find->resourcePriv().removeScratchKey();
// It's still alive, but not cached by scratch key anymore
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
// Repeat for the second resource.
- find = cache->findAndRefScratchResource(scratchKey);
+ find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
find->resourcePriv().removeScratchKey();
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));)
// Ensure that scratch key lookup is correct for negative case.
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey);
// (following leaks upon test failure).
- REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey) == NULL);
+ REPORTER_ASSERT(reporter, cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0) == NULL);
// Find the first resource with a scratch key and a copy of a scratch key.
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey);
- GrGpuResource* find = cache->findAndRefScratchResource(scratchKey);
+ GrGpuResource* find = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
REPORTER_ASSERT(reporter, find != NULL);
find->unref();
scratchKey2 = scratchKey;
- find = cache->findAndRefScratchResource(scratchKey2);
+ find = cache->findAndRefScratchResource(scratchKey2, TestResource::kDefaultSize, 0);
REPORTER_ASSERT(reporter, find != NULL);
REPORTER_ASSERT(reporter, find == a || find == b);
- GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2);
+ GrGpuResource* find2 = cache->findAndRefScratchResource(scratchKey2, TestResource::kDefaultSize, 0);
REPORTER_ASSERT(reporter, find2 != NULL);
REPORTER_ASSERT(reporter, find2 == a || find2 == b);
REPORTER_ASSERT(reporter, find2 != find);
// Make sure we actually get to c via it's scratch key, before we say goodbye.
GrScratchKey scratchKey;
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey);
- GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey);
+ GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
REPORTER_ASSERT(reporter, scratch == c);
SkSafeUnref(scratch);
// Get rid of c.
cache->purgeAllUnlocked();
- scratch = cache->findAndRefScratchResource(scratchKey);
+ scratch = cache->findAndRefScratchResource(scratchKey, TestResource::kDefaultSize, 0);
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
REPORTER_ASSERT(reporter, 0 == cache->getResourceBytes());