Revert of https://codereview.chromium.org/106563002/
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 10 Jan 2014 17:58:47 +0000 (17:58 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 10 Jan 2014 17:58:47 +0000 (17:58 +0000)
Reason for revert: There's a threading issue I don't quite understand yet.  Objects are being deleted after we check they're deleted.  Will try again.

R=kkinnunen@nvidia.com, kkinnunen@nvidia.com
TBR=kkinnunen@nvidia.com, kkinnunen@nvidia.com
NOTREECHECKS=true
NOTRY=true

Author: mtklein@google.com

Review URL: https://codereview.chromium.org/134363002

git-svn-id: http://skia.googlecode.com/svn/trunk@13023 2bbb7eff-a529-9590-31e7-b0007b416f81

src/gpu/GrResourceCache.cpp
tests/ResourceCacheTest.cpp

index 5e8c2c2..5cf3f82 100644 (file)
@@ -312,8 +312,8 @@ void GrResourceCache::purgeInvalidated() {
         //
         // This is complicated and confusing.  May try this in the future.  For
         // now, these resources are just LRU'd as if we never got the message.
-        GrResourceEntry* entry;
-        while ((entry= fCache.find(invalidated[i].key, GrTFindUnreffedFunctor()))) {
+        GrResourceEntry* entry = fCache.find(invalidated[i].key, GrTFindUnreffedFunctor());
+        if (entry) {
             this->deleteResource(entry);
         }
     }
index fe4c2d6..1bb6766 100644 (file)
@@ -10,7 +10,6 @@
 // This is a GPU test
 #if SK_SUPPORT_GPU
 #include "GrContextFactory.h"
-#include "GrResourceCache.h"
 #include "SkGpuDevice.h"
 
 static const int gWidth = 640;
@@ -59,79 +58,6 @@ 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) {
@@ -155,7 +81,6 @@ static void TestResourceCache(skiatest::Reporter* reporter, GrContextFactory* fa
         SkCanvas canvas(device.get());
 
         test_cache(reporter, context, &canvas);
-        test_purge_invalidated(reporter, context);
     }
 }