aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-11-13 13:33:28 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-13 13:33:28 -0800
commitf21dab95405979a4aff9f6a741c818304a67f220 (patch)
tree9dba5c1c7bb95c5197d7708ef3fa057fe91e6c4f /tests
parent66a450f21a3da174b7eed89a1d5fc8591e8b6ee6 (diff)
Revert of Replace GrResourceCache with GrResourceCache2. (patchset #6 id:100001 of https://codereview.chromium.org/716143004/)
Reason for revert: Breaking stuff Original issue's description: > Replace GrResourceCache with GrResourceCache2. > > BUG=skia:2889 > > Committed: https://skia.googlesource.com/skia/+/66a450f21a3da174b7eed89a1d5fc8591e8b6ee6 TBR=robertphillips@google.com NOTREECHECKS=true NOTRY=true BUG=skia:2889 Review URL: https://codereview.chromium.org/715333003
Diffstat (limited to 'tests')
-rw-r--r--tests/ResourceCacheTest.cpp254
-rw-r--r--tests/SurfaceTest.cpp29
2 files changed, 138 insertions, 145 deletions
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 6f51d30766..7cebddb0cc 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -10,10 +10,9 @@
#include "GrContext.h"
#include "GrContextFactory.h"
#include "GrGpu.h"
+#include "GrResourceCache.h"
#include "GrResourceCache2.h"
#include "SkCanvas.h"
-#include "SkGr.h"
-#include "SkMessageBus.h"
#include "SkSurface.h"
#include "Test.h"
@@ -68,6 +67,7 @@ public:
SK_DECLARE_INST_COUNT(TestResource);
TestResource(GrGpu* gpu)
: INHERITED(gpu, false)
+ , fCache(NULL)
, fToDelete(NULL)
, fSize(kDefaultSize) {
++fNumAlive;
@@ -76,6 +76,7 @@ public:
TestResource(GrGpu* gpu, const GrResourceKey& scratchKey)
: INHERITED(gpu, false)
+ , fCache(NULL)
, fToDelete(NULL)
, fSize(kDefaultSize) {
this->setScratchKey(scratchKey);
@@ -85,7 +86,11 @@ public:
~TestResource() {
--fNumAlive;
- SkSafeUnref(fToDelete);
+ if (fToDelete) {
+ // Breaks our little 2-element cycle below.
+ fToDelete->setDeleteWhenDestroyed(NULL, NULL);
+ fCache->deleteResource(fToDelete->cacheAccess().getCacheEntry());
+ }
this->release();
}
@@ -96,13 +101,15 @@ public:
static int NumAlive() { return fNumAlive; }
- void setUnrefWhenDestroyed(TestResource* resource) {
- SkRefCnt_SafeAssign(fToDelete, resource);
+ void setDeleteWhenDestroyed(GrResourceCache* cache, TestResource* resource) {
+ fCache = cache;
+ fToDelete = resource;
}
private:
size_t onGpuMemorySize() const SK_OVERRIDE { return fSize; }
+ GrResourceCache* fCache;
TestResource* fToDelete;
size_t fSize;
static int fNumAlive;
@@ -111,61 +118,6 @@ private:
};
int TestResource::fNumAlive = 0;
-static void test_no_key(skiatest::Reporter* reporter) {
- SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
- REPORTER_ASSERT(reporter, SkToBool(context));
- if (NULL == context) {
- return;
- }
- context->setResourceCacheLimits(10, 30000);
- GrResourceCache2* cache2 = context->getResourceCache2();
- cache2->purgeAllUnlocked();
- SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
-
- // Create a bunch of resources with no keys
- TestResource* a = new TestResource(context->getGpu());
- TestResource* b = new TestResource(context->getGpu());
- TestResource* c = new TestResource(context->getGpu());
- TestResource* d = new TestResource(context->getGpu());
- a->setSize(11);
- b->setSize(12);
- c->setSize(13);
- d->setSize(14);
-
- REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
- REPORTER_ASSERT(reporter, 4 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() + c->gpuMemorySize() +
- d->gpuMemorySize() == cache2->getResourceBytes());
-
- // Should be safe to purge without deleting the resources since we still have refs.
- cache2->purgeAllUnlocked();
- REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive());
-
- // Since the resources have neither content nor scratch keys, delete immediately upon unref.
-
- a->unref();
- REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive());
- REPORTER_ASSERT(reporter, 3 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, b->gpuMemorySize() + c->gpuMemorySize() + d->gpuMemorySize() ==
- cache2->getResourceBytes());
-
- c->unref();
- REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
- REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, b->gpuMemorySize() + d->gpuMemorySize() ==
- cache2->getResourceBytes());
-
- d->unref();
- REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
- REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, b->gpuMemorySize() == cache2->getResourceBytes());
-
- b->unref();
- REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
- REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
-}
-
static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
REPORTER_ASSERT(reporter, SkToBool(context));
@@ -173,9 +125,10 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
return;
}
context->setResourceCacheLimits(5, 30000);
- GrResourceCache2* cache2 = context->getResourceCache2();
- cache2->purgeAllUnlocked();
- SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
+ GrResourceCache* cache = context->getResourceCache();
+ SkDEBUGCODE(GrResourceCache2* cache2 = context->getResourceCache2();)
+ cache->purgeAllUnlocked();
+ SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes());
GrCacheID::Key keyData;
memset(&keyData, 0, sizeof(keyData));
@@ -189,16 +142,30 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
a->setSize(11);
b->setSize(12);
// Scratch resources are registered with GrResourceCache2 just by existing. There are 2.
- REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));)
- REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
+
+ REPORTER_ASSERT(reporter, cache->addResource(scratchKey, a));
+
+ SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));)
+
+ // Can't add the same resource twice.
+ REPORTER_ASSERT(reporter, !cache->addResource(scratchKey, a));
+ REPORTER_ASSERT(reporter, 1 == cache->getCachedResourceCount());
+ REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache->getCachedResourceBytes());
+ SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));)
+
+ // Add a second with the same key.
+ REPORTER_ASSERT(reporter, cache->addResource(scratchKey, b));
+ REPORTER_ASSERT(reporter, 2 == cache->getCachedResourceCount());
REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
- cache2->getResourceBytes());
+ cache->getCachedResourceBytes());
+ REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
+ SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));)
// Our refs mean that the resources are non purgable.
- cache2->purgeAllUnlocked();
+ cache->purgeAllUnlocked();
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
- REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
+ REPORTER_ASSERT(reporter, 2 == cache->getCachedResourceCount());
// Unref but don't purge
a->unref();
@@ -207,9 +174,9 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
SkDEBUGCODE(REPORTER_ASSERT(reporter, 2 == cache2->countScratchEntriesForKey(scratchKey));)
// Purge again. This time resources should be purgable.
- cache2->purgeAllUnlocked();
+ cache->purgeAllUnlocked();
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
- REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
+ REPORTER_ASSERT(reporter, 0 == cache->getCachedResourceCount());
SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache2->countScratchEntriesForKey(scratchKey));)
}
@@ -220,9 +187,9 @@ static void test_duplicate_content_key(skiatest::Reporter* reporter) {
return;
}
context->setResourceCacheLimits(5, 30000);
- GrResourceCache2* cache2 = context->getResourceCache2();
- cache2->purgeAllUnlocked();
- SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
+ GrResourceCache* cache = context->getResourceCache();
+ cache->purgeAllUnlocked();
+ SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes());
GrCacheID::Domain domain = GrCacheID::GenerateDomain();
GrCacheID::Key keyData;
@@ -230,42 +197,30 @@ static void test_duplicate_content_key(skiatest::Reporter* reporter) {
GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
GrResourceKey key(GrCacheID(domain, keyData), t, 0);
+
// Create two resources that we will attempt to register with the same content key.
TestResource* a = new TestResource(context->getGpu());
TestResource* b = new TestResource(context->getGpu());
a->setSize(11);
b->setSize(12);
-
- // Can't set the same content key on two resources.
- REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key));
- REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key));
-
- // Still have two resources because b is still reffed.
- REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, a->gpuMemorySize() + b->gpuMemorySize() ==
- cache2->getResourceBytes());
+ REPORTER_ASSERT(reporter, cache->addResource(key, a));
+ // Can't add the same or another resource with the same key.
+ REPORTER_ASSERT(reporter, !cache->addResource(key, a));
+ REPORTER_ASSERT(reporter, !cache->addResource(key, b));
+ REPORTER_ASSERT(reporter, 1 == cache->getCachedResourceCount());
+ REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache->getCachedResourceBytes());
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
b->unref();
- // Now b should be gone.
- REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache2->getResourceBytes());
- REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
-
- cache2->purgeAllUnlocked();
- REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache2->getResourceBytes());
+ cache->purgeAllUnlocked();
+ a->setSize(10);
+ REPORTER_ASSERT(reporter, 1 == cache->getCachedResourceCount());
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
- // Drop the ref on a but it isn't immediately purged as it still has a valid scratch key.
a->unref();
- REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, a->gpuMemorySize() == cache2->getResourceBytes());
- REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
-
- cache2->purgeAllUnlocked();
- REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
+ cache->purgeAllUnlocked();
+ REPORTER_ASSERT(reporter, 0 == cache->getCachedResourceCount());
+ REPORTER_ASSERT(reporter, 0 == cache->getCachedResourceBytes());
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
}
@@ -290,17 +245,18 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
GrResourceKey key3(GrCacheID(domain, keyData), t, 0);
context->setResourceCacheLimits(5, 30000);
+ GrResourceCache* cache = context->getResourceCache();
GrResourceCache2* cache2 = context->getResourceCache2();
- cache2->purgeAllUnlocked();
- SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
+ cache->purgeAllUnlocked();
+ SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes());
// Add three resources to the cache.
TestResource* a = new TestResource(context->getGpu());
TestResource* b = new TestResource(context->getGpu());
TestResource* c = new TestResource(context->getGpu());
- a->cacheAccess().setContentKey(key1);
- b->cacheAccess().setContentKey(key2);
- c->cacheAccess().setContentKey(key3);
+ cache->addResource(key1, a);
+ cache->addResource(key2, b);
+ cache->addResource(key3, c);
a->unref();
b->unref();
c->unref();
@@ -315,8 +271,8 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
SkMessageBus<GrResourceInvalidatedMessage>::Post(msg1);
const GrResourceInvalidatedMessage msg2 = { key2 };
SkMessageBus<GrResourceInvalidatedMessage>::Post(msg2);
+ cache->purgeAsNeeded();
#if 0 // Disabled until reimplemented in GrResourceCache2.
- cache2->purgeAsNeeded();
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
REPORTER_ASSERT(reporter, !cache2->hasContentKey(key2));
@@ -326,19 +282,14 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
// Invalidate the third.
const GrResourceInvalidatedMessage msg3 = { key3 };
SkMessageBus<GrResourceInvalidatedMessage>::Post(msg3);
+ cache->purgeAsNeeded();
#if 0 // Disabled until reimplemented in GrResourceCache2.
- cache2->purgeAsNeeded();
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
REPORTER_ASSERT(reporter, !cache2->hasContentKey(key3));
#endif
-
- cache2->purgeAllUnlocked();
- REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
- REPORTER_ASSERT(reporter, 0 == cache2->getResourceCount());
- REPORTER_ASSERT(reporter, 0 == cache2->getResourceBytes());
}
-static void test_cache_chained_purge(skiatest::Reporter* reporter) {
+static void test_cache_delete_on_destruction(skiatest::Reporter* reporter) {
SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
REPORTER_ASSERT(reporter, SkToBool(context));
if (NULL == context) {
@@ -358,34 +309,44 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) {
{
context->setResourceCacheLimits(3, 30000);
- GrResourceCache2* cache2 = context->getResourceCache2();
- cache2->purgeAllUnlocked();
- SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
+ GrResourceCache* cache = context->getResourceCache();
+ cache->purgeAllUnlocked();
+ SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes());
TestResource* a = new TestResource(context->getGpu());
TestResource* b = new TestResource(context->getGpu());
- a->cacheAccess().setContentKey(key1);
- b->cacheAccess().setContentKey(key2);
-
- // Make a cycle
- a->setUnrefWhenDestroyed(b);
- b->setUnrefWhenDestroyed(a);
+ cache->addResource(key1, a);
+ cache->addResource(key2, b);
- REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
+ a->setDeleteWhenDestroyed(cache, b);
+ b->setDeleteWhenDestroyed(cache, a);
a->unref();
b->unref();
REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
- cache2->purgeAllUnlocked();
- REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
+ cache->purgeAllUnlocked();
+ REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
+ }
+ {
+ context->setResourceCacheLimits(3, 30000);
+ GrResourceCache* cache = context->getResourceCache();
+ cache->purgeAllUnlocked();
+ SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes());
- // Break the cycle
- a->setUnrefWhenDestroyed(NULL);
- REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
+ TestResource* a = new TestResource(context->getGpu());
+ TestResource* b = new TestResource(context->getGpu());
+ cache->addResource(key1, a);
+ cache->addResource(key2, b);
+
+ a->setDeleteWhenDestroyed(cache, b);
+ b->setDeleteWhenDestroyed(cache, a);
- cache2->purgeAllUnlocked();
+ a->unref();
+ b->unref();
+
+ cache->deleteResource(a->cacheAccess().getCacheEntry());
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
}
}
@@ -413,20 +374,23 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) {
// Test changing resources sizes (both increase & decrease).
{
context->setResourceCacheLimits(3, 30000);
+ GrResourceCache* cache = context->getResourceCache();
GrResourceCache2* cache2 = context->getResourceCache2();
- cache2->purgeAllUnlocked();
- SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
+ cache->purgeAllUnlocked();
+ SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes());
TestResource* a = new TestResource(context->getGpu());
- a->cacheAccess().setContentKey(key1);
+ a->setSize(100); // Test didChangeGpuMemorySize() when not in the cache.
+ cache->addResource(key1, a);
a->unref();
TestResource* b = new TestResource(context->getGpu());
- b->cacheAccess().setContentKey(key2);
+ b->setSize(100);
+ cache->addResource(key2, b);
b->unref();
- REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes());
- REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
+ REPORTER_ASSERT(reporter, 200 == cache->getCachedResourceBytes());
+ REPORTER_ASSERT(reporter, 2 == cache->getCachedResourceCount());
{
SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2->findAndRefContentResource(key2)));
find2->setSize(200);
@@ -434,29 +398,30 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) {
find1->setSize(50);
}
- REPORTER_ASSERT(reporter, 250 == cache2->getResourceBytes());
- REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
+ REPORTER_ASSERT(reporter, 250 == cache->getCachedResourceBytes());
+ REPORTER_ASSERT(reporter, 2 == cache->getCachedResourceCount());
}
// Test increasing a resources size beyond the cache budget.
{
context->setResourceCacheLimits(2, 300);
+ GrResourceCache* cache = context->getResourceCache();
GrResourceCache2* cache2 = context->getResourceCache2();
- cache2->purgeAllUnlocked();
- SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceBytes());
+ cache->purgeAllUnlocked();
+ SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedResourceBytes());
TestResource* a = new TestResource(context->getGpu());
a->setSize(100);
- a->cacheAccess().setContentKey(key1);
+ cache->addResource(key1, a);
a->unref();
TestResource* b = new TestResource(context->getGpu());
b->setSize(100);
- b->cacheAccess().setContentKey(key2);
+ cache->addResource(key2, b);
b->unref();
- REPORTER_ASSERT(reporter, 200 == cache2->getResourceBytes());
- REPORTER_ASSERT(reporter, 2 == cache2->getResourceCount());
+ REPORTER_ASSERT(reporter, 200 == cache->getCachedResourceBytes());
+ REPORTER_ASSERT(reporter, 2 == cache->getCachedResourceCount());
{
SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache2->findAndRefContentResource(key2)));
@@ -464,8 +429,8 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) {
}
REPORTER_ASSERT(reporter, !cache2->hasContentKey(key1));
- REPORTER_ASSERT(reporter, 201 == cache2->getResourceBytes());
- REPORTER_ASSERT(reporter, 1 == cache2->getResourceCount());
+ REPORTER_ASSERT(reporter, 201 == cache->getCachedResourceBytes());
+ REPORTER_ASSERT(reporter, 1 == cache->getCachedResourceCount());
}
}
@@ -491,11 +456,10 @@ DEF_GPUTEST(ResourceCache, reporter, factory) {
}
// The below tests create their own mock contexts.
- test_no_key(reporter);
test_duplicate_content_key(reporter);
test_duplicate_scratch_key(reporter);
test_purge_invalidated(reporter);
- test_cache_chained_purge(reporter);
+ test_cache_delete_on_destruction(reporter);
test_resource_size_changed(reporter);
}
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 1913fcb146..69c8b845ec 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -321,6 +321,33 @@ static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter
}
#if SK_SUPPORT_GPU
+static void TestSurfaceInCache(skiatest::Reporter* reporter,
+ SurfaceType surfaceType,
+ GrContext* context) {
+ context->freeGpuResources();
+ int resourceCount;
+
+ context->getResourceCacheUsage(&resourceCount, NULL);
+ REPORTER_ASSERT(reporter, 0 == resourceCount);
+ SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
+ // Note: the stencil buffer is always cached, so kGpu_SurfaceType uses
+ // one cached resource, and kGpuScratch_SurfaceType uses two.
+ int expectedCachedResources = surfaceType == kGpuScratch_SurfaceType ? 2 : 1;
+ context->getResourceCacheUsage(&resourceCount, NULL);
+ REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount);
+
+ // Verify that all the cached resources are locked in cache.
+ context->freeGpuResources();
+ context->getResourceCacheUsage(&resourceCount, NULL);
+ REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount);
+
+ // Verify that all the cached resources are unlocked upon surface release
+ surface.reset(0);
+ context->freeGpuResources();
+ context->getResourceCacheUsage(&resourceCount, NULL);
+ REPORTER_ASSERT(reporter, 0 == resourceCount);
+}
+
static void Test_crbug263329(skiatest::Reporter* reporter,
SurfaceType surfaceType,
GrContext* context) {
@@ -426,6 +453,8 @@ DEF_GPUTEST(Surface, reporter, factory) {
}
GrContext* context = factory->get(glCtxType);
if (context) {
+ TestSurfaceInCache(reporter, kGpu_SurfaceType, context);
+ TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context);
Test_crbug263329(reporter, kGpu_SurfaceType, context);
Test_crbug263329(reporter, kGpuScratch_SurfaceType, context);
TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context);