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

Unified Diff: include/core/SkImageGenerator.h

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 | « gm/image.cpp ('k') | src/core/SkImageGenerator.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkImageGenerator.h
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index 3d508ddfb1c7ec7f1ceb34b9a12d3ce3d50f6060..66db5e4884275257947d18a5e2f27b3c17dbd483 100644
--- a/include/core/SkImageGenerator.h
+++ b/include/core/SkImageGenerator.h
@@ -152,6 +152,49 @@ public:
*/
GrTexture* generateTexture(GrContext*, const SkIRect* subset = nullptr);
+ struct SupportedSizes {
+ SkISize fSizes[2];
+ };
+
+ /**
+ * Some generators can efficiently scale their contents. If this is supported, the generator
+ * may only support certain scaled dimensions. Call this with the desired scale factor,
+ * and it will return true if scaling is supported, and in supportedSizes[] it will return
+ * the nearest supported dimensions.
+ *
+ * If no native scaling is supported, or scale is invalid (e.g. scale <= 0 || scale > 1)
+ * this will return false, and the supportedsizes will be undefined.
+ */
+ bool computeScaledDimensions(SkScalar scale, SupportedSizes*);
+
+ /**
+ * Scale the generator's pixels to fit into scaledSize.
+ * This routine also support retrieving only a subset of the pixels. That subset is specified
+ * by the following rectangle (in the scaled space):
+ *
+ * subset = SkIRect::MakeXYWH(subsetOrigin.x(), subsetOrigin.y(),
+ * subsetPixels.width(), subsetPixels.height())
+ *
+ * If subset is not contained inside the scaledSize, this returns false.
+ *
+ * whole = SkIRect::MakeWH(scaledSize.width(), scaledSize.height())
+ * if (!whole.contains(subset)) {
+ * return false;
+ * }
+ *
+ * If the requested colortype/alphatype in pixels is not supported,
+ * or the requested scaledSize is not supported, or the generator encounters an error,
+ * this returns false.
+ */
+ bool generateScaledPixels(const SkISize& scaledSize, const SkIPoint& subsetOrigin,
+ const SkPixmap& subsetPixels);
+
+ bool generateScaledPixels(const SkPixmap& scaledPixels) {
+ return this->generateScaledPixels(SkISize::Make(scaledPixels.width(),
+ scaledPixels.height()),
+ SkIPoint::Make(0, 0), scaledPixels);
+ }
+
/**
* If the default image decoder system can interpret the specified (encoded) data, then
* this returns a new ImageGenerator for it. Otherwise this returns NULL. Either way
@@ -199,6 +242,13 @@ protected:
return nullptr;
}
+ virtual bool onComputeScaledDimensions(SkScalar, SupportedSizes*) {
+ return false;
+ }
+ virtual bool onGenerateScaledPixels(const SkISize&, const SkIPoint&, const SkPixmap&) {
+ return false;
+ }
+
bool tryGenerateBitmap(SkBitmap* bm, const SkImageInfo* optionalInfo, SkBitmap::Allocator*);
private:
« no previous file with comments | « gm/image.cpp ('k') | src/core/SkImageGenerator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698