From c756c7acfeddb65f8eaa3f59714d5de93368ec30 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Thu, 13 Apr 2017 15:13:36 -0400 Subject: 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 Reviewed-by: Matt Sarett --- tests/ImageGeneratorTest.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/ImageGeneratorTest.cpp') 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 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); + } +} -- cgit v1.2.3