| Index: tests/ResourceCacheTest.cpp
|
| diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
|
| index ee8d7c7eea7bbe39cdba373b7e9fa1d42b75c4fd..f9ba18fcdd79680fd71a5422f16c07b0bf36aec4 100644
|
| --- a/tests/ResourceCacheTest.cpp
|
| +++ b/tests/ResourceCacheTest.cpp
|
| @@ -250,7 +250,8 @@ public:
|
| : INHERITED(gpu, lifeCycle)
|
| , fToDelete(nullptr)
|
| , fSize(size)
|
| - , fProperty(kA_SimulatedProperty) {
|
| + , fProperty(kA_SimulatedProperty)
|
| + , fReuseable(true) {
|
| ++fNumAlive;
|
| this->registerWithCache();
|
| }
|
| @@ -259,7 +260,8 @@ public:
|
| : INHERITED(gpu, lifeCycle)
|
| , fToDelete(nullptr)
|
| , fSize(kDefaultSize)
|
| - , fProperty(kA_SimulatedProperty) {
|
| + , fProperty(kA_SimulatedProperty)
|
| + , fReuseable(true) {
|
| ++fNumAlive;
|
| this->registerWithCache();
|
| }
|
| @@ -268,13 +270,15 @@ public:
|
| : INHERITED(gpu, kCached_LifeCycle)
|
| , fToDelete(nullptr)
|
| , fSize(kDefaultSize)
|
| - , fProperty(kA_SimulatedProperty) {
|
| + , fProperty(kA_SimulatedProperty)
|
| + , fReuseable(true) {
|
| ++fNumAlive;
|
| this->registerWithCache();
|
| }
|
|
|
| - static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, bool cached = true) {
|
| - return new TestResource(gpu, property, cached, kScratchConstructor);
|
| + static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, bool cached = true,
|
| + bool reuseable = true) {
|
| + return new TestResource(gpu, property, cached, kScratchConstructor, reuseable);
|
| }
|
|
|
| ~TestResource() {
|
| @@ -308,11 +312,13 @@ public:
|
| private:
|
| static const int kScratchKeyFieldCnt = 6;
|
|
|
| - TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchConstructor)
|
| + TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchConstructor,
|
| + bool reuseable)
|
| : INHERITED(gpu, cached ? kCached_LifeCycle : kUncached_LifeCycle)
|
| , fToDelete(nullptr)
|
| , fSize(kDefaultSize)
|
| - , fProperty(property) {
|
| + , fProperty(property)
|
| + , fReuseable(reuseable) {
|
| GrScratchKey scratchKey;
|
| ComputeScratchKey(fProperty, &scratchKey);
|
| this->setScratchKey(scratchKey);
|
| @@ -321,11 +327,13 @@ private:
|
| }
|
|
|
| size_t onGpuMemorySize() const override { return fSize; }
|
| + bool reuseable() const override { return fReuseable; }
|
|
|
| TestResource* fToDelete;
|
| size_t fSize;
|
| static int fNumAlive;
|
| SimulatedProperty fProperty;
|
| + bool fReuseable;
|
| typedef GrGpuResource INHERITED;
|
| };
|
| int TestResource::fNumAlive = 0;
|
| @@ -1188,6 +1196,23 @@ static void test_flush(skiatest::Reporter* reporter) {
|
| REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
| }
|
|
|
| +static void test_reuseable_resources(skiatest::Reporter* reporter) {
|
| + Mock mock(1000, 1000);
|
| + GrContext* context = mock.context();
|
| + TestResource* scratch = TestResource::CreateScratch(context->getGpu(),
|
| + TestResource::kB_SimulatedProperty, true, true);
|
| + scratch->unref();
|
| + REPORTER_ASSERT(reporter, TestResource::NumAlive() == 1);
|
| + scratch = TestResource::CreateScratch(context->getGpu(),
|
| + TestResource::kB_SimulatedProperty, false, true);
|
| + scratch->unref();
|
| + REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2);
|
| + scratch = TestResource::CreateScratch(context->getGpu(),
|
| + TestResource::kB_SimulatedProperty, false, false);
|
| + scratch->unref();
|
| + REPORTER_ASSERT(reporter, TestResource::NumAlive() == 2);
|
| +}
|
| +
|
| static void test_large_resource_count(skiatest::Reporter* reporter) {
|
| // Set the cache size to double the resource count because we're going to create 2x that number
|
| // resources, using two different key domains. Add a little slop to the bytes because we resize
|
| @@ -1309,6 +1334,7 @@ DEF_GPUTEST(ResourceCacheMisc, reporter, factory) {
|
| test_resource_size_changed(reporter);
|
| test_timestamp_wrap(reporter);
|
| test_flush(reporter);
|
| + test_reuseable_resources(reporter);
|
| test_large_resource_count(reporter);
|
| test_custom_data(reporter);
|
| test_abandoned(reporter);
|
|
|