diff options
author | Mike Reed <reed@google.com> | 2017-04-13 15:13:36 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-13 19:53:12 +0000 |
commit | c756c7acfeddb65f8eaa3f59714d5de93368ec30 (patch) | |
tree | 8a5cd5fa65cb3fa65c61aa15ac429a129fa05614 /tests/ImageGeneratorTest.cpp | |
parent | d2ca59a1cd39f81d4fb05be253bc3803daa23210 (diff) |
make picture-imagegenerator more robust on requested infos
This new unittest would assert before this fix.
Bug: skia:6501
Change-Id: I351ad03f29bccc054f72bfcb838174830dbd008c
Reviewed-on: https://skia-review.googlesource.com/13413
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Diffstat (limited to 'tests/ImageGeneratorTest.cpp')
-rw-r--r-- | tests/ImageGeneratorTest.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/ImageGeneratorTest.cpp b/tests/ImageGeneratorTest.cpp index b64459624b..d79b434e35 100644 --- a/tests/ImageGeneratorTest.cpp +++ b/tests/ImageGeneratorTest.cpp @@ -69,3 +69,42 @@ DEF_TEST(ImageGenerator, reporter) { test_imagegenerator_factory(reporter); } } + +#include "SkAutoMalloc.h" +#include "SkPictureRecorder.h" + +static sk_sp<SkPicture> make_picture() { + SkPictureRecorder recorder; + recorder.beginRecording(100, 100)->drawColor(SK_ColorRED); + return recorder.finishRecordingAsPicture(); +} + +DEF_TEST(PictureImageGenerator, reporter) { + const struct { + SkColorType fColorType; + SkAlphaType fAlphaType; + bool fExpectSuccess; + } recs[] = { + { kRGBA_8888_SkColorType, kPremul_SkAlphaType, kRGBA_8888_SkColorType == kN32_SkColorType }, + { kBGRA_8888_SkColorType, kPremul_SkAlphaType, kBGRA_8888_SkColorType == kN32_SkColorType }, + { kRGBA_F16_SkColorType, kPremul_SkAlphaType, true }, + + { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, false }, + { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, false }, + { kRGBA_F16_SkColorType, kUnpremul_SkAlphaType, false }, + }; + + auto colorspace = SkColorSpace::MakeSRGB(); + auto picture = make_picture(); + auto gen = SkImageGenerator::MakeFromPicture({100, 100}, picture, nullptr, nullptr, + SkImage::BitDepth::kU8, colorspace); + + // worst case for all requests + SkAutoMalloc storage(100 * 100 * SkColorTypeBytesPerPixel(kRGBA_F16_SkColorType)); + + for (const auto& rec : recs) { + SkImageInfo info = SkImageInfo::Make(100, 100, rec.fColorType, rec.fAlphaType, colorspace); + bool success = gen->getPixels(info, storage.get(), info.minRowBytes()); + REPORTER_ASSERT(reporter, success == rec.fExpectSuccess); + } +} |