Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Unified Diff: tests/ResourceCacheTest.cpp

Issue 1862043002: Refactor to separate backend object lifecycle and GpuResource budget decision (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix unrelated GrBuffer::onGpuMemorySize() lack of override keyword compile error Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | tools/gpu/GrTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ResourceCacheTest.cpp
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 0ac64edd0758ce104e3354eb8017a8446d4309a0..a733d39afe0ff4bd1621c4c4dd12feb374b9cb6d 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);
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | tools/gpu/GrTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698