Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: src/core/SkPictureImageGenerator.cpp

Issue 1487683004: Create an SkCodecImageGenerator (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,
+ SupportedSizes* sizes) {
+ const int w = this->getInfo().width();
+ const int h = this->getInfo().height();
+ const int sw = SkMin32(SkScalarRoundToInt(scale * w), w);
+ 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,
+ 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);

Powered by Google App Engine
This is Rietveld 408576698