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

Unified Diff: src/core/SkPictureImageGenerator.cpp

Issue 1396323007: API to support native scaling by image-generator (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: mark test image as opaque, so jpeg has a chance of encoding it Created 5 years 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
« no previous file with comments | « src/core/SkImageGenerator.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureImageGenerator.cpp
diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp
index 556015d99e375c6b5889bb35425742b56a485554..39caa55d0cff42403efd47434b8b53d9f33de855 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,47 @@ bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels,
return true;
}
+bool SkPictureImageGenerator::onComputeScaledDimensions(SkScalar scale,
+ SupportedSizes* sizes) {
+ SkASSERT(scale > 0 && scale <= 1);
+ const int w = this->getInfo().width();
+ const int h = this->getInfo().height();
+ const int sw = SkScalarRoundToInt(scale * w);
+ const int sh = SkScalarRoundToInt(scale * 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);
« no previous file with comments | « src/core/SkImageGenerator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698