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>
diff --git a/tests/ImageGeneratorTest.cpp b/tests/ImageGeneratorTest.cpp
index b644596..d79b434 100644
--- a/tests/ImageGeneratorTest.cpp
+++ b/tests/ImageGeneratorTest.cpp
@@ -69,3 +69,42 @@
         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);
+    }
+}