Chromium Code Reviews| Index: src/core/SkPictureImageGenerator.cpp |
| diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp |
| index 556015d99e375c6b5889bb35425742b56a485554..9c9927bf715fc3eb8a35d90ee149b389980fbc9b 100644 |
| --- a/src/core/SkPictureImageGenerator.cpp |
| +++ b/src/core/SkPictureImageGenerator.cpp |
| @@ -21,6 +21,9 @@ public: |
| protected: |
| bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], |
| int* ctableCount) override; |
| + bool onComputeScaledDimensions(SkScalar scale, SupportedSizes*) override; |
| + bool onGenerateScaledPixels(const SkISize&, const SkIPoint&, const SkPixmap&) override; |
| + |
| #if SK_SUPPORT_GPU |
| GrTexture* onGenerateTexture(GrContext*, const SkIRect*) override; |
| #endif |
| @@ -78,6 +81,46 @@ bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, |
| return true; |
| } |
| +bool SkPictureImageGenerator::onComputeScaledDimensions(SkScalar scale, |
|
msarett
2015/11/30 21:24:26
This can be implemented for SkCodec by:
SkISize s
reed1
2015/11/30 21:29:20
Ack.
That said, I think returning 2 sizes will be
|
| + SupportedSizes* sizes) { |
| + const int w = this->getInfo().width(); |
| + const int h = this->getInfo().height(); |
| + const int sw = SkMin32(SkScalarRoundToInt(scale * w), w); |
|
msarett
2015/11/30 21:24:26
Won't SkMin32 be unnecessary, since invalid scales
reed1
2015/11/30 21:29:19
Good catch.
|
| + const int sh = SkMin32(SkScalarRoundToInt(scale * h), h); |
| + if (sw > 0 && sh > 0) { |
| + sizes->fSizes[0].set(sw, sh); |
| + sizes->fSizes[1].set(sw, sh); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +bool SkPictureImageGenerator::onGenerateScaledPixels(const SkISize& scaledSize, |
|
msarett
2015/11/30 21:24:26
This can be implemented for SkCodec by:
codec->ge
reed1
2015/11/30 21:29:19
Acknowledged.
|
| + const SkIPoint& scaledOrigin, |
| + const SkPixmap& scaledPixels) { |
| + int w = scaledSize.width(); |
| + int h = scaledSize.height(); |
| + |
| + const SkScalar scaleX = SkIntToScalar(w) / this->getInfo().width(); |
| + const SkScalar scaleY = SkIntToScalar(h) / this->getInfo().height(); |
| + SkMatrix matrix = SkMatrix::MakeScale(scaleX, scaleY); |
| + matrix.postTranslate(-SkIntToScalar(scaledOrigin.x()), -SkIntToScalar(scaledOrigin.y())); |
| + |
| + SkBitmap bitmap; |
| + if (!bitmap.installPixels(scaledPixels.info(), scaledPixels.writable_addr(), |
| + scaledPixels.rowBytes())) { |
| + return false; |
| + } |
| + |
| + bitmap.eraseColor(SK_ColorTRANSPARENT); |
| + SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
| + matrix.preConcat(fMatrix); |
| + canvas.drawPicture(fPicture, &matrix, fPaint.getMaybeNull()); |
| + return true; |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| + |
| SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const SkPicture* picture, |
| const SkMatrix* matrix, const SkPaint* paint) { |
| return SkPictureImageGenerator::Create(size, picture, matrix, paint); |