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

Unified Diff: tests/ResourceCacheTest.cpp

Issue 106563002: Delete all invalidated resources with same key (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Rebase Created 6 years, 11 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/gpu/GrResourceCache.cpp ('k') | no next file » | 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 1bb6766b2c1f160a245cd9b3baa3a5e3166e816e..fe4c2d6a0298ffe79224071411bf99a97038dfa3 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -10,6 +10,7 @@
// This is a GPU test
#if SK_SUPPORT_GPU
#include "GrContextFactory.h"
+#include "GrResourceCache.h"
#include "SkGpuDevice.h"
static const int gWidth = 640;
@@ -58,6 +59,79 @@ static void test_cache(skiatest::Reporter* reporter,
context->setTextureCacheLimits(oldMaxNum, oldMaxBytes);
}
+class TestResource : public GrResource {
+public:
+ SK_DECLARE_INST_COUNT(TestResource);
+ explicit TestResource(GrGpu* gpu)
+ : INHERITED(gpu, false)
+ , fCache(NULL)
+ , fToDelete(NULL) {
+ ++fAlive;
+ }
+
+ ~TestResource() {
+ --fAlive;
+ if (NULL != fToDelete) {
+ // Breaks our little 2-element cycle below.
+ fToDelete->setDeleteWhenDestroyed(NULL, NULL);
+ fCache->deleteResource(fToDelete->getCacheEntry());
+ }
+ this->release();
+ }
+
+ size_t sizeInBytes() const SK_OVERRIDE { return 100; }
+
+ static int alive() { return fAlive; }
+
+ void setDeleteWhenDestroyed(GrResourceCache* cache, TestResource* resource) {
+ fCache = cache;
+ fToDelete = resource;
+ }
+
+private:
+ GrResourceCache* fCache;
+ TestResource* fToDelete;
+ static int fAlive;
+
+ typedef GrResource INHERITED;
+};
+SK_DEFINE_INST_COUNT(TestResource);
+int TestResource::fAlive = 0;
+
+static void test_purge_invalidated(skiatest::Reporter* reporter, GrContext* context) {
+ GrCacheID::Domain domain = GrCacheID::GenerateDomain();
+ GrCacheID::Key keyData;
+ keyData.fData64[0] = 5;
+ keyData.fData64[1] = 18;
+ GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
+ GrResourceKey key(GrCacheID(domain, keyData), t, 0);
+
+ GrResourceCache cache(5, 30000);
+
+ // Add two resources with the same key that delete each other from the cache when destroyed.
+ TestResource* a = new TestResource(context->getGpu());
+ TestResource* b = new TestResource(context->getGpu());
+ cache.addResource(key, a);
+ cache.addResource(key, b);
+ // Circle back.
+ a->setDeleteWhenDestroyed(&cache, b);
+ b->setDeleteWhenDestroyed(&cache, a);
+ a->unref();
+ b->unref();
+
+ // Add a third independent resource also with the same key.
+ GrResource* r = new TestResource(context->getGpu());
+ cache.addResource(key, r);
+ r->unref();
+
+ // Invalidate all three, all three should be purged and destroyed.
+ REPORTER_ASSERT(reporter, 3 == TestResource::alive());
+ const GrResourceInvalidatedMessage msg = { key };
+ SkMessageBus<GrResourceInvalidatedMessage>::Post(msg);
+ cache.purgeAsNeeded();
+ REPORTER_ASSERT(reporter, 0 == TestResource::alive());
+}
+
////////////////////////////////////////////////////////////////////////////////
static void TestResourceCache(skiatest::Reporter* reporter, GrContextFactory* factory) {
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
@@ -81,6 +155,7 @@ static void TestResourceCache(skiatest::Reporter* reporter, GrContextFactory* fa
SkCanvas canvas(device.get());
test_cache(reporter, context, &canvas);
+ test_purge_invalidated(reporter, context);
}
}
« no previous file with comments | « src/gpu/GrResourceCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698