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

Unified Diff: tests/ResourceCacheTest.cpp

Issue 91453002: Speed up GrResourceCache add and lookup by using TDynamicHash (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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
« tests/DynamicHashTest.cpp ('K') | « tests/LListTest.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..0de67e7deaaf830cd09656fab628af3ad5a534b5 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -11,6 +11,7 @@
#if SK_SUPPORT_GPU
#include "GrContextFactory.h"
#include "SkGpuDevice.h"
+#include "GrResourceCache.h"
static const int gWidth = 640;
static const int gHeight = 480;
@@ -58,6 +59,131 @@ static void test_cache(skiatest::Reporter* reporter,
context->setTextureCacheLimits(oldMaxNum, oldMaxBytes);
}
+class TestResource : public GrResource {
+public:
+ SK_DECLARE_INST_COUNT(TestResource);
+ TestResource(GrGpu* gpu, int* cacheCount)
+ : INHERITED(gpu, false)
+ , fCache(NULL)
+ , fToDelete(NULL)
+ , fCacheCount(cacheCount) {
+ ++*fCacheCount;
+ }
+
+ ~TestResource() {
+ --*fCacheCount;
+
+ if (NULL != fToDelete) {
+ fToDelete->setDeletedResource(NULL, NULL);
+ fCache->deleteResource(fToDelete);
+ }
+ this->release();
+ }
+
+ void setDeletedResource(GrResourceCache* cache, TestResource* resource) {
+ fCache = cache;
+ fToDelete = resource;
+ }
+
+ virtual size_t sizeInBytes() const SK_OVERRIDE {
+ return 100;
+ }
+
+private:
+ GrResourceCache* fCache;
+ TestResource* fToDelete;
+ int* fCacheCount;
+
+ typedef GrResource INHERITED;
+};
+
+SK_DEFINE_INST_COUNT(TestResource);
+
+static void test_cache_delete_on_destruction(skiatest::Reporter* reporter,
+ GrContext* context) {
+ GrCacheID::Domain domain = GrCacheID::GenerateDomain();
+ GrCacheID::Key keyData;
+ keyData.fData64[0] = 5;
+ keyData.fData64[1] = 0;
+ GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
+
+ GrResourceKey key(GrCacheID(domain, keyData), t, 0);
+
+ {
+ int cacheCount = 0;
+ {
+ GrResourceCache cache(3, 30000);
+ TestResource* a = new TestResource(context->getGpu(), &cacheCount);
+ TestResource* b = new TestResource(context->getGpu(), &cacheCount);
+ cache.addResource(key, a);
+ cache.addResource(key, b);
+
+ a->setDeletedResource(&cache, b);
+ b->setDeletedResource(&cache, a);
+
+ a->unref();
+ b->unref();
+ REPORTER_ASSERT(reporter, cacheCount == 2);
+ }
+ REPORTER_ASSERT(reporter, cacheCount == 0);
+ }
+ {
+ int cacheCount = 0;
+ GrResourceCache cache(3, 30000);
+ TestResource* a = new TestResource(context->getGpu(), &cacheCount);
+ TestResource* b = new TestResource(context->getGpu(), &cacheCount);
+ cache.addResource(key, a);
+ cache.addResource(key, b);
+
+ a->setDeletedResource(&cache, b);
+ b->setDeletedResource(&cache, a);
+
+ a->unref();
+ b->unref();
+
+ cache.deleteResource(a);
+
+ REPORTER_ASSERT(reporter, cacheCount == 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);
+
+ {
+ int cacheCount = 0;
+ GrResourceCache cache(5, 30000);
+ TestResource* a = new TestResource(context->getGpu(), &cacheCount);
+ cache.addResource(key, a);
+ TestResource* b = new TestResource(context->getGpu(), &cacheCount);
+ cache.addResource(key, b);
+ a->setDeletedResource(&cache, b);
+ b->setDeletedResource(&cache, a);
+ a->unref();
+ b->unref();
+
+ GrResource* r = new TestResource(context->getGpu(), &cacheCount);
+ cache.addResource(key, r);
+ r->unref();
+
+
+ REPORTER_ASSERT(reporter, cacheCount == 3);
+ GrResourceInvalidatedMessage msg = { key };
+ SkMessageBus<GrResourceInvalidatedMessage>::Post(msg);
+ cache.purgeAsNeeded();
+
+ REPORTER_ASSERT(reporter, cacheCount == 0);
+ }
+}
+
+
+
////////////////////////////////////////////////////////////////////////////////
static void TestResourceCache(skiatest::Reporter* reporter, GrContextFactory* factory) {
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
@@ -81,6 +207,8 @@ static void TestResourceCache(skiatest::Reporter* reporter, GrContextFactory* fa
SkCanvas canvas(device.get());
test_cache(reporter, context, &canvas);
+ test_cache_delete_on_destruction(reporter, context);
+ test_purge_invalidated(reporter, context);
}
}
« tests/DynamicHashTest.cpp ('K') | « tests/LListTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698