diff options
author | halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-05 14:00:03 +0000 |
---|---|---|
committer | halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-05 14:00:03 +0000 |
commit | 36d08c5c90c7607cd559769f7a9c2b3364eeba85 (patch) | |
tree | 12dc40a8c539ae664a9d0231403a9c38aa12bf4f /tests/CachedDecodingPixelRefTest.cpp | |
parent | 0e9297c7bd59bae61f4db139a916a2c2bb576405 (diff) |
SkCachingPixelRef to use SkImageGenerator
- Remove SkLazyCachingPixelRef class.
- Refactor unit tests.
BUG=
R=reed@google.com, scroggo@google.com
Review URL: https://codereview.chromium.org/84083002
git-svn-id: http://skia.googlecode.com/svn/trunk@12505 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/CachedDecodingPixelRefTest.cpp')
-rw-r--r-- | tests/CachedDecodingPixelRefTest.cpp | 179 |
1 files changed, 49 insertions, 130 deletions
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp index 2d8a0e7073..af1df1093c 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); } |