| Index: tests/ResourceCacheTest.cpp
|
| diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
|
| index 784ae7e94db5efc40bdd0f03bcb2bdfb3f211412..288c7f2ec7a5fa202c84897bcc265d2717d3fc22 100644
|
| --- a/tests/ResourceCacheTest.cpp
|
| +++ b/tests/ResourceCacheTest.cpp
|
| @@ -247,26 +247,50 @@ public:
|
| * For example, textures have width, height, ... */
|
| enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty };
|
|
|
| - TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle)
|
| - : INHERITED(gpu, lifeCycle)
|
| + TestResource(GrGpu* gpu, size_t size, SkBudgeted budgeted)
|
| + : INHERITED(gpu, budgeted)
|
| , fToDelete(nullptr)
|
| , fSize(size)
|
| - , fProperty(kA_SimulatedProperty) {
|
| + , fProperty(kA_SimulatedProperty)
|
| + , fIsBorrowed(false) {
|
| + ++fNumAlive;
|
| + this->registerWithCache();
|
| + }
|
| +
|
| + enum BorrowedConstructor { kBorrowedConstructor };
|
| +
|
| + TestResource(GrGpu* gpu, size_t size, SkBudgeted budgeted, BorrowedConstructor)
|
| + : INHERITED(gpu, budgeted)
|
| + , fToDelete(nullptr)
|
| + , fSize(size)
|
| + , fProperty(kA_SimulatedProperty)
|
| + , fIsBorrowed(true) {
|
| ++fNumAlive;
|
| this->registerWithCache();
|
| }
|
|
|
| - TestResource(GrGpu* gpu, GrGpuResource::LifeCycle lifeCycle)
|
| - : INHERITED(gpu, lifeCycle)
|
| + TestResource(GrGpu* gpu, SkBudgeted budgeted)
|
| + : INHERITED(gpu, budgeted)
|
| , fToDelete(nullptr)
|
| , fSize(kDefaultSize)
|
| - , fProperty(kA_SimulatedProperty) {
|
| + , fProperty(kA_SimulatedProperty)
|
| + , fIsBorrowed(false) {
|
| + ++fNumAlive;
|
| + this->registerWithCache();
|
| + }
|
| +
|
| + TestResource(GrGpu* gpu, SkBudgeted budgeted, BorrowedConstructor)
|
| + : INHERITED(gpu, budgeted)
|
| + , fToDelete(nullptr)
|
| + , fSize(kDefaultSize)
|
| + , fProperty(kA_SimulatedProperty)
|
| + , fIsBorrowed(true) {
|
| ++fNumAlive;
|
| this->registerWithCache();
|
| }
|
|
|
| TestResource(GrGpu* gpu)
|
| - : INHERITED(gpu, kCached_LifeCycle)
|
| + : INHERITED(gpu, SkBudgeted::kYes)
|
| , fToDelete(nullptr)
|
| , fSize(kDefaultSize)
|
| , fProperty(kA_SimulatedProperty) {
|
| @@ -274,7 +298,8 @@ public:
|
| this->registerWithCache();
|
| }
|
|
|
| - static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, bool cached = true) {
|
| + static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property,
|
| + SkBudgeted cached = SkBudgeted::kYes) {
|
| return new TestResource(gpu, property, cached, kScratchConstructor);
|
| }
|
|
|
| @@ -306,14 +331,18 @@ public:
|
| return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaDataCnt);
|
| }
|
|
|
| +protected:
|
| + bool refsWrappedResources() const { return fIsBorrowed; }
|
| +
|
| private:
|
| static const int kScratchKeyFieldCnt = 6;
|
|
|
| - TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchConstructor)
|
| - : INHERITED(gpu, cached ? kCached_LifeCycle : kUncached_LifeCycle)
|
| + TestResource(GrGpu* gpu, SimulatedProperty property, SkBudgeted budgeted, ScratchConstructor)
|
| + : INHERITED(gpu, budgeted)
|
| , fToDelete(nullptr)
|
| , fSize(kDefaultSize)
|
| - , fProperty(property) {
|
| + , fProperty(property)
|
| + , fIsBorrowed(false) {
|
| GrScratchKey scratchKey;
|
| ComputeScratchKey(fProperty, &scratchKey);
|
| this->setScratchKey(scratchKey);
|
| @@ -327,6 +356,7 @@ private:
|
| size_t fSize;
|
| static int fNumAlive;
|
| SimulatedProperty fProperty;
|
| + bool fIsBorrowed;
|
| typedef GrGpuResource INHERITED;
|
| };
|
| int TestResource::fNumAlive = 0;
|
| @@ -421,10 +451,11 @@ static void test_budgeting(skiatest::Reporter* reporter) {
|
| TestResource* unique = new TestResource(context->getGpu());
|
| unique->setSize(11);
|
| unique->resourcePriv().setUniqueKey(uniqueKey);
|
| - TestResource* wrapped = new TestResource(context->getGpu(), GrGpuResource::kBorrowed_LifeCycle);
|
| + TestResource* wrapped = new TestResource(context->getGpu(), SkBudgeted::kNo,
|
| + TestResource::kBorrowedConstructor);
|
| wrapped->setSize(12);
|
| TestResource* unbudgeted =
|
| - new TestResource(context->getGpu(), GrGpuResource::kUncached_LifeCycle);
|
| + new TestResource(context->getGpu(), SkBudgeted::kNo);
|
| unbudgeted->setSize(13);
|
|
|
| // Make sure we can't add a unique key to the wrapped resource
|
| @@ -459,7 +490,8 @@ static void test_budgeting(skiatest::Reporter* reporter) {
|
| unbudgeted->gpuMemorySize() == cache->getResourceBytes());
|
|
|
| // Now try freeing the budgeted resources first
|
| - wrapped = new TestResource(context->getGpu(), GrGpuResource::kBorrowed_LifeCycle);
|
| + wrapped = new TestResource(context->getGpu(), SkBudgeted::kNo,
|
| + TestResource::kBorrowedConstructor);
|
| scratch->setSize(12);
|
| unique->unref();
|
| cache->purgeAllUnlocked();
|
| @@ -522,7 +554,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
|
| REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
|
|
| size_t large = 2 * cache->getResourceBytes();
|
| - unbudgeted = new TestResource(context->getGpu(), large, GrGpuResource::kUncached_LifeCycle);
|
| + unbudgeted = new TestResource(context->getGpu(), large, SkBudgeted::kNo);
|
| REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
| REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
|
| REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
| @@ -534,7 +566,8 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
|
| REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
| REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
|
|
| - wrapped = new TestResource(context->getGpu(), large, GrGpuResource::kBorrowed_LifeCycle);
|
| + wrapped = new TestResource(context->getGpu(), large, SkBudgeted::kNo,
|
| + TestResource::kBorrowedConstructor);
|
| REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
| REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
|
| REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
| @@ -560,8 +593,8 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter);
|
| GrContext* context = mock.context();
|
| GrResourceCache* cache = mock.cache();
|
|
|
| - TestResource* resource =
|
| - TestResource::CreateScratch(context->getGpu(), TestResource::kA_SimulatedProperty, false);
|
| + TestResource* resource = TestResource::CreateScratch(
|
| + context->getGpu(), TestResource::kA_SimulatedProperty, SkBudgeted::kNo);
|
| GrScratchKey key;
|
| TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
|
|
|
|
|