diff options
author | 2016-04-22 01:48:29 -0700 | |
---|---|---|
committer | 2016-04-22 01:48:29 -0700 | |
commit | 2e6055b3ea14a04fcde1ac1974a70bf00b1e295b (patch) | |
tree | 38513879d9f2840cb7d08f85365722016448f787 /tests | |
parent | cb61a6452fbf9b147dc9d3f31bf520efb0e2c7fd (diff) |
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ResourceCacheTest.cpp | 95 |
1 files changed, 51 insertions, 44 deletions
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 0ac64edd07..a733d39afe 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -249,35 +249,22 @@ 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, SkBudgeted budgeted = SkBudgeted::kYes, size_t size = kDefaultSize) + : INHERITED(gpu) , fToDelete(nullptr) , fSize(size) - , fProperty(kA_SimulatedProperty) { + , fProperty(kA_SimulatedProperty) + , fIsScratch(false) { ++fNumAlive; - this->registerWithCache(); + this->registerWithCache(budgeted); } - TestResource(GrGpu* gpu, GrGpuResource::LifeCycle lifeCycle) - : INHERITED(gpu, lifeCycle) - , fToDelete(nullptr) - , fSize(kDefaultSize) - , fProperty(kA_SimulatedProperty) { - ++fNumAlive; - this->registerWithCache(); - } - - TestResource(GrGpu* gpu) - : INHERITED(gpu, kCached_LifeCycle) - , fToDelete(nullptr) - , fSize(kDefaultSize) - , fProperty(kA_SimulatedProperty) { - ++fNumAlive; - this->registerWithCache(); + static TestResource* CreateScratch(GrGpu* gpu, SkBudgeted budgeted, + SimulatedProperty property) { + return new TestResource(gpu, budgeted, property, kScratchConstructor); } - - static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, bool cached = true) { - return new TestResource(gpu, property, cached, kScratchConstructor); + static TestResource* CreateWrapped(GrGpu* gpu, size_t size = kDefaultSize) { + return new TestResource(gpu, size); } ~TestResource() { @@ -307,20 +294,34 @@ public: static size_t ExpectedScratchKeySize() { return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaDataCnt); } - private: static const int kScratchKeyFieldCnt = 6; - TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchConstructor) - : INHERITED(gpu, cached ? kCached_LifeCycle : kUncached_LifeCycle) + TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, ScratchConstructor) + : INHERITED(gpu) , fToDelete(nullptr) , fSize(kDefaultSize) - , fProperty(property) { - GrScratchKey scratchKey; - ComputeScratchKey(fProperty, &scratchKey); - this->setScratchKey(scratchKey); + , fProperty(property) + , fIsScratch(true) { ++fNumAlive; - this->registerWithCache(); + this->registerWithCache(budgeted); + } + + // Constructor for simulating resources that wrap backend objects. + TestResource(GrGpu* gpu, size_t size) + : INHERITED(gpu) + , fToDelete(nullptr) + , fSize(size) + , fProperty(kA_SimulatedProperty) + , fIsScratch(false) { + ++fNumAlive; + this->registerWithCacheWrapped(); + } + + void computeScratchKey(GrScratchKey* key) const override { + if (fIsScratch) { + ComputeScratchKey(fProperty, key); + } } size_t onGpuMemorySize() const override { return fSize; } @@ -329,6 +330,7 @@ private: size_t fSize; static int fNumAlive; SimulatedProperty fProperty; + bool fIsScratch; typedef GrGpuResource INHERITED; }; int TestResource::fNumAlive = 0; @@ -418,15 +420,15 @@ static void test_budgeting(skiatest::Reporter* reporter) { // Create a scratch, a unique, and a wrapped resource TestResource* scratch = - TestResource::CreateScratch(context->getGpu(), TestResource::kB_SimulatedProperty); + TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty); scratch->setSize(10); TestResource* unique = new TestResource(context->getGpu()); unique->setSize(11); unique->resourcePriv().setUniqueKey(uniqueKey); - TestResource* wrapped = new TestResource(context->getGpu(), GrGpuResource::kBorrowed_LifeCycle); + TestResource* wrapped = TestResource::CreateWrapped(context->getGpu()); 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 @@ -461,7 +463,7 @@ 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 = TestResource::CreateWrapped(context->getGpu()); scratch->setSize(12); unique->unref(); cache->purgeAllUnlocked(); @@ -506,7 +508,9 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { TestResource* unbudgeted; // A large uncached or wrapped resource shouldn't evict anything. - scratch = TestResource::CreateScratch(context->getGpu(), TestResource::kB_SimulatedProperty); + scratch = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, + TestResource::kB_SimulatedProperty); + scratch->setSize(10); scratch->unref(); REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); @@ -524,7 +528,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(), SkBudgeted::kNo, large); REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); @@ -536,7 +540,7 @@ 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 = TestResource::CreateWrapped(context->getGpu(), large); REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); @@ -563,7 +567,8 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); GrResourceCache* cache = mock.cache(); TestResource* resource = - TestResource::CreateScratch(context->getGpu(), TestResource::kA_SimulatedProperty, false); + TestResource::CreateScratch(context->getGpu(), SkBudgeted::kNo, + TestResource::kA_SimulatedProperty); GrScratchKey key; TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); @@ -623,8 +628,10 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) { // Create two resources that have the same scratch key. TestResource* a = TestResource::CreateScratch(context->getGpu(), + SkBudgeted::kYes, TestResource::kB_SimulatedProperty); TestResource* b = TestResource::CreateScratch(context->getGpu(), + SkBudgeted::kYes, TestResource::kB_SimulatedProperty); a->setSize(11); b->setSize(12); @@ -667,9 +674,9 @@ static void test_remove_scratch_key(skiatest::Reporter* reporter) { GrResourceCache* cache = mock.cache(); // Create two resources that have the same scratch key. - TestResource* a = TestResource::CreateScratch(context->getGpu(), + TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty); - TestResource* b = TestResource::CreateScratch(context->getGpu(), + TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty); a->unref(); b->unref(); @@ -726,9 +733,9 @@ static void test_scratch_key_consistency(skiatest::Reporter* reporter) { GrResourceCache* cache = mock.cache(); // Create two resources that have the same scratch key. - TestResource* a = TestResource::CreateScratch(context->getGpu(), + TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty); - TestResource* b = TestResource::CreateScratch(context->getGpu(), + TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty); a->unref(); b->unref(); @@ -888,7 +895,7 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) { // Add three resources to the cache. Only c is usable as scratch. TestResource* a = new TestResource(context->getGpu()); TestResource* b = new TestResource(context->getGpu()); - TestResource* c = TestResource::CreateScratch(context->getGpu(), + TestResource* c = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kA_SimulatedProperty); a->resourcePriv().setUniqueKey(key1); b->resourcePriv().setUniqueKey(key2); |