aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-10-03 13:23:30 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-03 13:23:31 -0700
commit37c5a815d8ea33247968212ef4cc83394ceee1bc (patch)
tree549847a55767b6deea8428b66068e82b43af13c0 /tests
parent9e96aa07dbf1210fd35ae8e0c54d4d9822544e89 (diff)
Speculative revert to diagnose crash in chrome. Revert "Add SkCachedData and use it for SkMipMap"
Diffstat (limited to 'tests')
-rw-r--r--tests/CachedDataTest.cpp95
-rw-r--r--tests/MipMapTest.cpp2
-rw-r--r--tests/SkResourceCacheTest.cpp51
3 files changed, 1 insertions, 147 deletions
diff --git a/tests/CachedDataTest.cpp b/tests/CachedDataTest.cpp
deleted file mode 100644
index f65a46b770..0000000000
--- a/tests/CachedDataTest.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkCachedData.h"
-#include "SkDiscardableMemoryPool.h"
-#include "Test.h"
-
-enum LockedState {
- kUnlocked,
- kLocked,
-};
-
-enum CachedState {
- kNotInCache,
- kInCache,
-};
-
-static void check_data(skiatest::Reporter* reporter, SkCachedData* data,
- int refcnt, CachedState cacheState, LockedState lockedState) {
- REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt);
- REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cacheState));
- REPORTER_ASSERT(reporter, data->testing_only_isLocked() == (lockedState == kLocked));
-}
-
-static SkCachedData* make_data(size_t size, SkDiscardableMemoryPool* pool) {
- if (pool) {
- SkDiscardableMemory* dm = pool->create(size);
- // the pool "can" return null, but it shouldn't in these controlled conditions
- SK_ALWAYSBREAK(dm);
- return SkNEW_ARGS(SkCachedData, (size, dm));
- } else {
- return SkNEW_ARGS(SkCachedData, (sk_malloc_throw(size), size));
- }
-}
-
-// returns with the data locked by client and cache
-static SkCachedData* test_locking(skiatest::Reporter* reporter,
- size_t size, SkDiscardableMemoryPool* pool) {
- SkCachedData* data = make_data(size, pool);
-
- memset(data->writable_data(), 0x80, size); // just to use writable_data()
-
- check_data(reporter, data, 1, kNotInCache, kLocked);
-
- data->ref();
- check_data(reporter, data, 2, kNotInCache, kLocked);
- data->unref();
- check_data(reporter, data, 1, kNotInCache, kLocked);
-
- data->attachToCacheAndRef();
- check_data(reporter, data, 2, kInCache, kLocked);
-
- data->unref();
- check_data(reporter, data, 1, kInCache, kUnlocked);
-
- data->ref();
- check_data(reporter, data, 2, kInCache, kLocked);
-
- return data;
-}
-
-/*
- * SkCachedData behaves differently (regarding its locked/unlocked state) depending on
- * when it is in the cache or not. Being in the cache is signaled by calling attachToCacheAndRef()
- * instead of ref(). (and balanced by detachFromCacheAndUnref).
- *
- * Thus, among other things, we test the end-of-life behavior when the client is the last owner
- * and when the cache is.
- */
-DEF_TEST(CachedData, reporter) {
- SkAutoTUnref<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Create(1000));
-
- for (int useDiscardable = 0; useDiscardable <= 1; ++useDiscardable) {
- const size_t size = 100;
-
- // test with client as last owner
- SkCachedData* data = test_locking(reporter, size, useDiscardable ? pool.get() : NULL);
- check_data(reporter, data, 2, kInCache, kLocked);
- data->detachFromCacheAndUnref();
- check_data(reporter, data, 1, kNotInCache, kLocked);
- data->unref();
-
- // test with cache as last owner
- data = test_locking(reporter, size, useDiscardable ? pool.get() : NULL);
- check_data(reporter, data, 2, kInCache, kLocked);
- data->unref();
- check_data(reporter, data, 1, kInCache, kUnlocked);
- data->detachFromCacheAndUnref();
- }
-}
-
diff --git a/tests/MipMapTest.cpp b/tests/MipMapTest.cpp
index c8396effa6..33f467244b 100644
--- a/tests/MipMapTest.cpp
+++ b/tests/MipMapTest.cpp
@@ -25,7 +25,7 @@ DEF_TEST(MipMap, reporter) {
for (int i = 0; i < 500; ++i) {
make_bitmap(&bm, rand);
- SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, NULL));
+ SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm));
REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1, NULL));
REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1 * 2, NULL));
diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp
index 0e941758ee..f13476a5a3 100644
--- a/tests/SkResourceCacheTest.cpp
+++ b/tests/SkResourceCacheTest.cpp
@@ -121,55 +121,6 @@ DEF_TEST(BitmapCache_add_rect, reporter) {
REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache));
}
-#include "SkMipMap.h"
-
-enum LockedState {
- kNotLocked,
- kLocked,
-};
-
-enum CachedState {
- kNotInCache,
- kInCache,
-};
-
-static void check_data(skiatest::Reporter* reporter, const SkCachedData* data,
- int refcnt, CachedState cacheState, LockedState lockedState) {
- REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt);
- REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cacheState));
- bool isLocked = (data->data() != NULL);
- REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked));
-}
-
-static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cache) {
- cache->purgeAll();
-
- SkBitmap src;
- src.allocN32Pixels(5, 5);
- src.setImmutable();
-
- const SkMipMap* mipmap = SkMipMapCache::FindAndRef(src, cache);
- REPORTER_ASSERT(reporter, NULL == mipmap);
-
- mipmap = SkMipMapCache::AddAndRef(src, cache);
- REPORTER_ASSERT(reporter, mipmap);
- check_data(reporter, mipmap, 2, kInCache, kLocked);
-
- mipmap->unref();
- // tricky, since technically after this I'm no longer an owner, but since the cache is
- // local, I know it won't get purged behind my back
- check_data(reporter, mipmap, 1, kInCache, kNotLocked);
-
- // find us again
- mipmap = SkMipMapCache::FindAndRef(src, cache);
- check_data(reporter, mipmap, 2, kInCache, kLocked);
-
- cache->purgeAll();
- check_data(reporter, mipmap, 1, kNotInCache, kLocked);
-
- mipmap->unref();
-}
-
DEF_TEST(BitmapCache_discarded_bitmap, reporter) {
SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardableFactory();
SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator();
@@ -214,6 +165,4 @@ DEF_TEST(BitmapCache_discarded_bitmap, reporter) {
// We can add the bitmap back to the cache and find it again.
REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedBitmap.getGenerationID(), rect, cachedBitmap, cache));
REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedBitmap.getGenerationID(), rect, &bm, cache));
-
- test_mipmapcache(reporter, cache);
}