aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ImageCacheTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-09 22:29:30 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-09 22:29:30 +0000
commite4eb122a61d7c29f1dd979a41d90524fd249db3f (patch)
tree6897bcca0f1b470d435f70f54cdd8c04a2bc29c4 /tests/ImageCacheTest.cpp
parentf309dbcf2a8084afc44774a675c68756993acbc3 (diff)
support scaledimagecache instantiable using discardablememory
Add this to your build/gyp system to use discardable instead of malloc+budget #define SK_USE_DISCARDABLE_SCALEDIMAGECACHE R=halcanary@google.com Review URL: https://codereview.chromium.org/105933003 git-svn-id: http://skia.googlecode.com/svn/trunk@12588 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/ImageCacheTest.cpp')
-rw-r--r--tests/ImageCacheTest.cpp60
1 files changed, 37 insertions, 23 deletions
diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp
index b8815a3217..69de629579 100644
--- a/tests/ImageCacheTest.cpp
+++ b/tests/ImageCacheTest.cpp
@@ -6,6 +6,7 @@
*/
#include "Test.h"
+#include "SkDiscardableMemory.h"
#include "SkScaledImageCache.h"
static void make_bm(SkBitmap* bm, int w, int h) {
@@ -13,27 +14,27 @@ static void make_bm(SkBitmap* bm, int w, int h) {
bm->allocPixels();
}
-static void TestImageCache(skiatest::Reporter* reporter) {
- static const int COUNT = 10;
- static const int DIM = 256;
- static const size_t defLimit = DIM * DIM * 4 * COUNT + 1024; // 1K slop
- SkScaledImageCache cache(defLimit);
- SkScaledImageCache::ID* id;
+static const int COUNT = 10;
+static const int DIM = 256;
+static void test_cache(skiatest::Reporter* reporter, SkScaledImageCache& cache,
+ bool testPurge) {
+ SkScaledImageCache::ID* id;
+
SkBitmap bm[COUNT];
-
+
SkScalar scale = 2;
for (int i = 0; i < COUNT; ++i) {
SkBitmap tmp;
-
+
make_bm(&bm[i], DIM, DIM);
id = cache.findAndLock(bm[i], scale, scale, &tmp);
REPORTER_ASSERT(reporter, NULL == id);
-
+
make_bm(&tmp, DIM, DIM);
id = cache.addAndLock(bm[i], scale, scale, tmp);
REPORTER_ASSERT(reporter, NULL != id);
-
+
SkBitmap tmp2;
SkScaledImageCache::ID* id2 = cache.findAndLock(bm[i], scale, scale,
&tmp2);
@@ -42,25 +43,38 @@ static void TestImageCache(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, tmp.width() == tmp2.width());
REPORTER_ASSERT(reporter, tmp.height() == tmp2.height());
cache.unlock(id2);
-
+
cache.unlock(id);
}
-
- // stress test, should trigger purges
- for (size_t i = 0; i < COUNT * 100; ++i) {
- scale += 1;
-
- SkBitmap tmp;
-
- make_bm(&tmp, DIM, DIM);
- id = cache.addAndLock(bm[0], scale, scale, tmp);
- REPORTER_ASSERT(reporter, NULL != id);
- cache.unlock(id);
+
+ if (testPurge) {
+ // stress test, should trigger purges
+ for (size_t i = 0; i < COUNT * 100; ++i) {
+ scale += 1;
+
+ SkBitmap tmp;
+
+ make_bm(&tmp, DIM, DIM);
+ id = cache.addAndLock(bm[0], scale, scale, tmp);
+ REPORTER_ASSERT(reporter, NULL != id);
+ cache.unlock(id);
+ }
}
-
cache.setByteLimit(0);
}
+static void TestImageCache(skiatest::Reporter* reporter) {
+ {
+ static const size_t defLimit = DIM * DIM * 4 * COUNT + 1024; // 1K slop
+ SkScaledImageCache cache(defLimit);
+ test_cache(reporter, cache, true);
+ }
+ {
+ SkScaledImageCache cache(SkDiscardableMemory::Create);
+ test_cache(reporter, cache, false);
+ }
+}
+
#include "TestClassDef.h"
DEFINE_TESTCLASS("ImageCache", TestImageCacheClass, TestImageCache)