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

Unified Diff: tests/MaskCacheTest.cpp

Issue 592843003: Add SkCachedData and use it for SkMipMap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use explicit runtime flag to recognize Discardable, to allow clients to subclass Created 6 years, 3 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
« src/core/SkCachedData.cpp ('K') | « src/core/SkResourceCache.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/MaskCacheTest.cpp
diff --git a/tests/MaskCacheTest.cpp b/tests/MaskCacheTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..746e182c3561deef9d44940c4033ef2a5b84a856
--- /dev/null
+++ b/tests/MaskCacheTest.cpp
@@ -0,0 +1,71 @@
+/*
+ * 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 "SkMaskCache.h"
+#include "SkResourceCache.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));
+ bool isLocked = (data->data() != NULL);
+ REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked));
+}
+
+DEF_TEST(MaskCache, reporter) {
+
+ SkResourceCache cache(1024);
+
+ SkScalar sigma = 2;
+ SkRect r = SkRect::MakeWH(10, 10);
+ SkMask mask;
+
+ SkCachedData* data = SkMaskCache::FindAndLock(sigma, r, &mask, &cache);
+ REPORTER_ASSERT(reporter, NULL == data);
+
+ size_t size = 100;
+ data = cache.newCachedData(size);
+ 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);
+
+ memset(data->writable_data(), 0x80, size); // just to use writable_data()
+ mask.fBounds.setXYWH(1, 2, 3, 4);
+ SkMaskCache::Add(sigma, r, mask, data, &cache);
+ check_data(reporter, data, 2, kInCache, kLocked);
+
+ data->unref();
+ check_data(reporter, data, 1, kInCache, kUnlocked);
+
+ sk_bzero(&mask, sizeof(mask));
+ data = SkMaskCache::FindAndLock(sigma, r, &mask, &cache);
+ check_data(reporter, data, 2, kInCache, kLocked);
+
+ REPORTER_ASSERT(reporter, data);
+ REPORTER_ASSERT(reporter, data->size() == size);
+ REPORTER_ASSERT(reporter, mask.fBounds.top() == 2);
+ REPORTER_ASSERT(reporter, data->data() == (const void*)mask.fImage);
+
+ cache.purgeAll();
+ check_data(reporter, data, 1, kNotInCache, kLocked);
+ data->unref();
+}
+
« src/core/SkCachedData.cpp ('K') | « src/core/SkResourceCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698