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

Unified Diff: tests/ImageCacheTest.cpp

Issue 20005003: add scaledimagecache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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/core/SkScaledImageCache.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageCacheTest.cpp
diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..63b18e8a07b8cc4e02efde94ababdeb82db8e787
--- /dev/null
+++ b/tests/ImageCacheTest.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+#include "SkScaledImageCache.h"
+
+static void make_bm(SkBitmap* bm, int w, int h) {
+ bm->setConfig(SkBitmap::kARGB_8888_Config, w, 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;
+
+ SkBitmap bm[COUNT];
+
+ SkScalar scale = 2;
+ for (size_t 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);
+ REPORTER_ASSERT(reporter, id == id2);
+ REPORTER_ASSERT(reporter, tmp.pixelRef() == tmp2.pixelRef());
+ 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) {
+ SkBitmap tmp;
+
+ make_bm(&tmp, DIM, DIM);
+ id = cache.addAndLock(bm[0], scale, scale, tmp);
+ REPORTER_ASSERT(reporter, NULL != id);
+ cache.unlock(id);
+
+ scale += 1;
+ }
+
+ cache.setByteLimit(0);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("ImageCache", TestImageCacheClass, TestImageCache)
« no previous file with comments | « src/core/SkScaledImageCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698