diff options
author | msarett <msarett@google.com> | 2016-02-17 10:02:29 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-17 10:02:29 -0800 |
commit | 8715d47e247bf890ee78af0774ae7e8698146b67 (patch) | |
tree | aa8b25a8353ccd96e6eccb08f22457a1d89846e0 /tests | |
parent | feec878e850850cb0a092a765e3af0f5a3fa2a42 (diff) |
Make SkPicture/SkImageGenerator default to SkCodec
Remove reference to SkImageDecoder from SkPicture. Make the default
InstallPixelRefProc passed to CreateFromStream use
SkImageGenerator::NewFromEncoded instead.
Make SkImageGenerator::NewFromEncoded create an SkCodecImageGenerator.
Remove the old version that used SkImageDecoder.
Remove all versions of lazy_decode_bitmap/LazyDecodeBitmap. The default
now behaves lazily.
Update all clients to use the default.
Move SkImageDecoderGenerator into KtxTest.cpp, and use it directly.
This is a rebased version of:
https://codereview.chromium.org/1671193002/
TBR=reed@google.com
BUG=skia:4691
BUG=skia:4290
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1699183004
Review URL: https://codereview.chromium.org/1699183004
Diffstat (limited to 'tests')
-rw-r--r-- | tests/KtxTest.cpp | 5 | ||||
-rw-r--r-- | tests/PictureTest.cpp | 34 |
2 files changed, 36 insertions, 3 deletions
diff --git a/tests/KtxTest.cpp b/tests/KtxTest.cpp index 84d162c0f8..99bae83329 100644 --- a/tests/KtxTest.cpp +++ b/tests/KtxTest.cpp @@ -143,6 +143,9 @@ DEF_TEST(KtxReadUnpremul, reporter) { } } +// For KtxReexportPKM, below. Defined in SkImageDecoder_ktx.cpp +extern SkImageGenerator* decoder_image_generator(SkData*); + /** * Finally, make sure that if we get ETC1 data from a PKM file that we can then * accurately write it out into a KTX file (i.e. transferring the ETC1 data from @@ -160,7 +163,7 @@ DEF_TEST(KtxReexportPKM, reporter) { } bool installDiscardablePixelRefSuccess = - SkDEPRECATED_InstallDiscardablePixelRef(fileData, &etcBitmap); + SkDEPRECATED_InstallDiscardablePixelRef(decoder_image_generator(fileData), &etcBitmap); if (!installDiscardablePixelRefSuccess) { ERRORF(reporter, "failed to create discardable pixelRef from KTX file"); return; diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index 3d05a824a2..448e079958 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -17,6 +17,7 @@ #include "SkImageEncoder.h" #include "SkImageGenerator.h" #include "SkLayerInfo.h" +#include "SkMD5.h" #include "SkPaint.h" #include "SkPicture.h" #include "SkPictureRecorder.h" @@ -871,7 +872,18 @@ static void assert_one_parse_error_cb(SkError error, void* context) { SkGetLastErrorString()); } -static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) { +static void md5(const SkBitmap& bm, SkMD5::Digest* digest) { + SkAutoLockPixels autoLockPixels(bm); + SkASSERT(bm.getPixels()); + SkMD5 md5; + size_t rowLen = bm.info().bytesPerPixel() * bm.width(); + for (int y = 0; y < bm.height(); ++y) { + md5.update(static_cast<uint8_t*>(bm.getAddr(0, y)), rowLen); + } + md5.finish(*digest); +} + +DEF_TEST(Picture_EncodedData, reporter) { // Create a bitmap that will be encoded. SkBitmap original; make_bm(&original, 100, 100, SK_ColorBLUE, true); @@ -891,6 +903,7 @@ static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) { SkAutoDataUnref picture1(serialized_picture_from_bitmap(original)); SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm)); REPORTER_ASSERT(reporter, picture1->equals(picture2)); + // Now test that a parse error was generated when trying to create a new SkPicture without // providing a function to decode the bitmap. ErrorContext context; @@ -903,6 +916,24 @@ static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr); SkClearLastError(); SkSetErrorCallback(nullptr, nullptr); + + // Test that using the version of CreateFromStream that just takes a stream also decodes the + // bitmap. Drawing this picture should look exactly like the original bitmap. + SkMD5::Digest referenceDigest; + md5(original, &referenceDigest); + + SkBitmap dst; + dst.allocPixels(original.info()); + dst.eraseColor(SK_ColorRED); + SkCanvas canvas(dst); + + pictureStream.rewind(); + pictureFromStream.reset(SkPicture::CreateFromStream(&pictureStream)); + canvas.drawPicture(pictureFromStream.get()); + + SkMD5::Digest digest2; + md5(dst, &digest2); + REPORTER_ASSERT(reporter, referenceDigest == digest2); } static void test_clip_bound_opt(skiatest::Reporter* reporter) { @@ -1174,7 +1205,6 @@ DEF_TEST(Picture, reporter) { test_has_text(reporter); test_images_are_found_by_willPlayBackBitmaps(reporter); test_analysis(reporter); - test_bitmap_with_encoded_data(reporter); test_clip_bound_opt(reporter); test_clip_expansion(reporter); test_hierarchical(reporter); |