Index: tests/CachedDecodingPixelRefTest.cpp |
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp |
index 2d8a0e70737a66c376987caf9c2adb055026f054..af1df1093c3469dc082195a1cd60a5a1ffd54a3f 100644 |
--- a/tests/CachedDecodingPixelRefTest.cpp |
+++ b/tests/CachedDecodingPixelRefTest.cpp |
@@ -12,8 +12,8 @@ |
#include "SkForceLinking.h" |
#include "SkImageDecoder.h" |
#include "SkImagePriv.h" |
-#include "SkLazyCachingPixelRef.h" |
#include "SkLazyPixelRef.h" |
+#include "SkCachingPixelRef.h" |
#include "SkScaledImageCache.h" |
#include "SkStream.h" |
@@ -109,15 +109,13 @@ static void compare_bitmaps(skiatest::Reporter* reporter, |
} |
-typedef void(*CompareEncodedToOriginal)(skiatest::Reporter* reporter, |
- SkData* encoded, |
- const SkBitmap& original, |
- bool pixelPerfect); |
+typedef bool (*InstallEncoded)(SkData* encoded, SkBitmap* dst); |
+ |
/** |
- this function tests three differently encoded images against the |
- original bitmap */ |
+ This function tests three differently encoded images against the |
+ original bitmap */ |
static void test_three_encodings(skiatest::Reporter* reporter, |
- CompareEncodedToOriginal comp) { |
+ InstallEncoded install) { |
SkBitmap original; |
make_test_image(&original); |
REPORTER_ASSERT(reporter, !original.empty()); |
@@ -134,146 +132,67 @@ static void test_three_encodings(skiatest::Reporter* reporter, |
SkImageEncoder::Type type = types[i]; |
SkAutoDataUnref encoded(create_data_from_bitmap(original, type)); |
REPORTER_ASSERT(reporter, encoded.get() != NULL); |
- if (NULL != encoded.get()) { |
- bool comparePixels = (SkImageEncoder::kPNG_Type == type); |
- comp(reporter, encoded, original, comparePixels); |
+ if (NULL == encoded.get()) { |
+ continue; |
+ } |
+ SkBitmap lazy; |
+ bool installSuccess = install(encoded.get(), &lazy); |
+ REPORTER_ASSERT(reporter, installSuccess); |
+ if (!installSuccess) { |
+ continue; |
} |
+ REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
+ { |
+ SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
+ REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); |
+ if (NULL == lazy.getPixels()) { |
+ continue; |
+ } |
+ } |
+ // pixels should be gone! |
+ REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
+ { |
+ SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
+ REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); |
+ if (NULL == lazy.getPixels()) { |
+ continue; |
+ } |
+ } |
+ bool comparePixels = (SkImageEncoder::kPNG_Type == type); |
+ compare_bitmaps(reporter, original, lazy, comparePixels); |
} |
} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
/** |
* This checks to see that a SkLazyPixelRef works as advertised. |
*/ |
-static void compare_with_skLazyPixelRef(skiatest::Reporter* reporter, |
- SkData* encoded, |
- const SkBitmap& original, |
- bool comparePixels) { |
- SkBitmap lazy; |
+bool install_skLazyPixelRef(SkData* encoded, SkBitmap* dst) { |
static const SkBitmapFactory::DecodeProc decoder = |
&(SkImageDecoder::DecodeMemoryToTarget); |
- bool success = simple_bitmap_factory(decoder, encoded, &lazy); |
- REPORTER_ASSERT(reporter, success); |
- |
- 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()); |
- } |
- compare_bitmaps(reporter, original, lazy, comparePixels); |
+ return simple_bitmap_factory(decoder, encoded, dst); |
} |
DEF_TEST(LazyPixelRef, reporter) { |
- test_three_encodings(reporter, compare_with_skLazyPixelRef); |
+ test_three_encodings(reporter, install_skLazyPixelRef); |
} |
- |
- |
+//////////////////////////////////////////////////////////////////////////////// |
/** |
- * This checks to see that a SkLazyCachedPixelRef works as advertised. |
+ * This checks to see that a SkCachingPixelRef works as advertised. |
*/ |
- |
-static void compare_with_skLazyCachedPixelRef(skiatest::Reporter* reporter, |
- SkData* encoded, |
- const SkBitmap& original, |
- bool comparePixels) { |
- SkBitmap lazy; |
- static const SkBitmapFactory::DecodeProc decoder = |
- &(SkImageDecoder::DecodeMemoryToTarget); |
- bool success = SkLazyCachingPixelRef::Install(decoder, encoded, &lazy); |
- REPORTER_ASSERT(reporter, success); |
- |
- 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()); |
- } |
- compare_bitmaps(reporter, original, lazy, comparePixels); |
+bool install_skCachingPixelRef(SkData* encoded, SkBitmap* dst) { |
+ return SkCachingPixelRef::Install( |
+ SkNEW_ARGS(SkDecodingImageGenerator, (encoded)), dst); |
} |
-DEF_TEST(LazyCachedPixelRef, reporter) { |
- test_three_encodings(reporter, compare_with_skLazyCachedPixelRef); |
-} |
- |
-class TestPixelRef : public SkCachingPixelRef { |
-public: |
- TestPixelRef(int x) : fX(x) { } |
- virtual ~TestPixelRef() { } |
- static bool Install(SkBitmap* destination, int x) { |
- SkAutoTUnref<TestPixelRef> ref(SkNEW_ARGS(TestPixelRef, (x))); |
- return ref->configure(destination) && destination->setPixelRef(ref); |
- } |
- SK_DECLARE_UNFLATTENABLE_OBJECT() |
-protected: |
- virtual bool onDecodeInfo(SkImageInfo* info) SK_OVERRIDE { |
- if (fX == 0) { |
- return false; |
- } |
- SkASSERT(info); |
- info->fWidth = 10; |
- info->fHeight = 10; |
- info->fColorType = kRGBA_8888_SkColorType; |
- info->fAlphaType = kOpaque_SkAlphaType; |
- return true; |
- } |
- virtual bool onDecodePixels(const SkImageInfo& info, |
- void* pixels, |
- size_t rowBytes) SK_OVERRIDE { |
- return false; |
- } |
-private: |
- int fX; // controls where the failure happens |
- typedef SkCachingPixelRef INHERITED; |
-}; |
- |
DEF_TEST(CachingPixelRef, reporter) { |
- SkBitmap lazy; |
- // test the error handling |
- REPORTER_ASSERT(reporter, !TestPixelRef::Install(&lazy, 0)); |
- // onDecodeInfo should succeed, allowing installation |
- REPORTER_ASSERT(reporter, TestPixelRef::Install(&lazy, 1)); |
- SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
- // onDecodePixels should fail, so getting pixels will fail. |
- REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
+ test_three_encodings(reporter, install_skCachingPixelRef); |
} |
-static void compare_with_SkDecodingImageGenerator(skiatest::Reporter* reporter, |
- SkData* encoded, |
- const SkBitmap& original, |
- bool comparePixels) { |
- |
- SkBitmap lazy; |
- bool success = SkDecodingImageGenerator::Install(encoded, &lazy); |
- REPORTER_ASSERT(reporter, success); |
- if (!success) { |
- return; |
- } |
- |
- REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
- { |
- SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
- REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); |
- if (NULL == lazy.getPixels()) { |
- return; |
- } |
- } |
- // pixels should be gone! |
- REPORTER_ASSERT(reporter, NULL == lazy.getPixels()); |
- { |
- SkAutoLockPixels autoLockPixels(lazy); // now pixels are good. |
- REPORTER_ASSERT(reporter, NULL != lazy.getPixels()); |
- } |
- compare_bitmaps(reporter, original, lazy, comparePixels); |
-} |
+//////////////////////////////////////////////////////////////////////////////// |
+/** |
+ * This checks to see that a SkDecodingImageGenerator works as advertised. |
+ */ |
DEF_TEST(DecodingImageGenerator, reporter) { |
- test_three_encodings(reporter, compare_with_SkDecodingImageGenerator); |
+ test_three_encodings(reporter, SkDecodingImageGenerator::Install); |
} |