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

Unified Diff: tests/CachedDecodingPixelRefTest.cpp

Issue 54203006: Break up SkLazyPixelRef functionally into class hierarchy. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 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/lazy/SkLazyCachingPixelRef.cpp ('K') | « src/lazy/SkLazyCachingPixelRef.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/CachedDecodingPixelRefTest.cpp
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp
index e3b249923eb98386d474734e395c38f4c55aa0fb..27eb695f811f0fad695bbd44cd3892a4863120b3 100644
--- a/tests/CachedDecodingPixelRefTest.cpp
+++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -12,9 +12,12 @@
#include "SkImageDecoder.h"
#include "SkImagePriv.h"
#include "SkLazyPixelRef.h"
+#include "SkLazyCachingPixelRef.h"
#include "SkScaledImageCache.h"
#include "SkStream.h"
+
#include "Test.h"
+#include "TestClassDef.h"
__SK_FORCE_IMAGE_DECODER_LINKING;
@@ -92,6 +95,7 @@ static void compare_bitmaps(skiatest::Reporter* reporter,
if (!pixelPerfect) {
return;
}
+
int pixelErrors = 0;
for (int y = 0; y < b2.height(); ++y) {
for (int x = 0; x < b2.width(); ++x) {
@@ -106,12 +110,9 @@ static void compare_bitmaps(skiatest::Reporter* reporter,
/**
* This checks to see that a SkLazyPixelRef works as advertized.
*/
-#include "TestClassDef.h"
DEF_TEST(CachedDecodingPixelRefTest, reporter) {
SkBitmap original;
make_test_image(&original);
- const size_t bitmapSize = original.getSize();
- const size_t oldByteLimit = SkScaledImageCache::GetByteLimit();
REPORTER_ASSERT(reporter, (!(original.empty())) && (!(original.isNull())));
static const SkImageEncoder::Type types[] = {
@@ -134,10 +135,67 @@ DEF_TEST(CachedDecodingPixelRefTest, reporter) {
REPORTER_ASSERT(reporter, success);
- size_t bytesUsed = SkScaledImageCache::GetBytesUsed();
+ REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
+ {
+ SkAutoLockPixels autoLockPixels(lazy); // now pixels are good.
+ REPORTER_ASSERT(reporter, NULL != lazy.getPixels());
+ }
+ // pixels should be gone!
+ REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
+ {
+ SkAutoLockPixels autoLockPixels(lazy); // now pixels are good.
+ REPORTER_ASSERT(reporter, NULL != lazy.getPixels());
+ }
+
+ bool comparePixels = (SkImageEncoder::kPNG_Type == type);
+ // Only PNG is pixel-perfect.
+ compare_bitmaps(reporter, original, lazy, comparePixels);
+ }
+}
+
+
+/**
+ * This checks to see that a SkLazyPixelRef works as advertized.
scroggo 2013/10/31 21:53:06 advertised.
hal.canary 2013/11/01 03:29:24 Done.
+ */
+DEF_TEST(LazyCachedPixelRefTest, reporter) {
scroggo 2013/10/31 21:53:06 Could these two tests share code?
hal.canary 2013/11/01 03:29:24 Done.
+ // By using a non-global cache, our unit tests won't collide with
+ // other unit tests. Unit tests can be run in separate threads.
+
+ // TODO(halcanary): Find a way to robustly test the global
+ // instance of SkScaledImageCache.
+ SkScaledImageCache cache(2000000, NULL);
+
+ SkBitmap original;
+ make_test_image(&original);
+ REPORTER_ASSERT(reporter, (!(original.empty())) && (!(original.isNull())));
+ const size_t bitmapSize = original.getSize();
+ const size_t oldByteLimit = cache.getByteLimit();
+
+ static const SkImageEncoder::Type types[] = {
+ SkImageEncoder::kPNG_Type,
+ SkImageEncoder::kJPEG_Type,
+ SkImageEncoder::kWEBP_Type
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(types); i++) {
+ SkImageEncoder::Type type = types[i];
+ SkAutoDataUnref encoded(create_data_from_bitmap(original, type));
+ REPORTER_ASSERT(reporter, encoded.get() != NULL);
+ if (NULL == encoded.get()) {
+ continue;
+ }
+ SkBitmap lazy;
+ static const SkBitmapFactory::DecodeProc decoder =
+ &(SkImageDecoder::DecodeMemoryToTarget);
+
+ bool success = SkLazyCachingPixelRef::Install(decoder, encoded,
+ &lazy, &cache);
+ REPORTER_ASSERT(reporter, success);
+
+ size_t bytesUsed = cache.getBytesUsed();
if (oldByteLimit < bitmapSize) {
- SkScaledImageCache::SetByteLimit(bitmapSize + oldByteLimit);
+ cache.setByteLimit(bitmapSize + oldByteLimit);
}
void* lazyPixels = NULL;
@@ -150,8 +208,8 @@ DEF_TEST(CachedDecodingPixelRefTest, reporter) {
// first time we lock pixels, we should get bump in the size
// of the cache by exactly bitmapSize.
REPORTER_ASSERT(reporter, bytesUsed + bitmapSize
- == SkScaledImageCache::GetBytesUsed());
- bytesUsed = SkScaledImageCache::GetBytesUsed();
+ == cache.getBytesUsed());
+ bytesUsed = cache.getBytesUsed();
}
// pixels should be gone!
REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
@@ -168,12 +226,14 @@ DEF_TEST(CachedDecodingPixelRefTest, reporter) {
compare_bitmaps(reporter, original, lazy, comparePixels);
// force the cache to clear by making it too small.
- SkScaledImageCache::SetByteLimit(bitmapSize / 2);
+ cache.setByteLimit(bitmapSize / 2);
+
compare_bitmaps(reporter, original, lazy, comparePixels);
// I'm pretty sure that the logic of the cache should mean
// that it will clear to zero, regardless of where it started.
- REPORTER_ASSERT(reporter, SkScaledImageCache::GetBytesUsed() == 0);
+ REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
+ REPORTER_ASSERT(reporter, cache.getBytesUsed() == 0);
// TODO(someone) - write a custom allocator that can verify
// that the memory where those pixels were cached really did
// get freed.
@@ -198,6 +258,6 @@ DEF_TEST(CachedDecodingPixelRefTest, reporter) {
// }
// restore cache size
- SkScaledImageCache::SetByteLimit(oldByteLimit);
+ cache.setByteLimit(oldByteLimit);
}
}
« src/lazy/SkLazyCachingPixelRef.cpp ('K') | « src/lazy/SkLazyCachingPixelRef.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698