diff options
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); + } +} |