diff options
-rw-r--r-- | src/core/SkPictureImageGenerator.cpp | 16 | ||||
-rw-r--r-- | tests/ImageGeneratorTest.cpp | 39 |
2 files changed, 44 insertions, 11 deletions
diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp index a1d919af34..a960001e13 100644 --- a/src/core/SkPictureImageGenerator.cpp +++ b/src/core/SkPictureImageGenerator.cpp @@ -59,19 +59,13 @@ SkPictureImageGenerator::SkPictureImageGenerator(const SkImageInfo& info, sk_sp< bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount) { - if (ctable || ctableCount) { + // Rely on SkCanvas factory to know what configs can and cannot be drawn into. + auto canvas = SkCanvas::MakeRasterDirect(info, pixels, rowBytes); + if (!canvas) { return false; } - - SkBitmap bitmap; - if (!bitmap.installPixels(info, pixels, rowBytes)) { - return false; - } - - bitmap.eraseColor(SK_ColorTRANSPARENT); - SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); - canvas.drawPicture(fPicture.get(), &fMatrix, fPaint.getMaybeNull()); - + canvas->clear(0); + canvas->drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull()); return true; } 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); + } +} |