aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2016-11-16 14:45:34 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-16 20:24:48 +0000
commitca79535dcb36ab3691eadc8664b687f4cd8a56b5 (patch)
treebb3f354cff997f717ed27025897f7973b3a340fc /include
parentcb677668519d117c51a7ca78375fee577f8f2aa9 (diff)
External SkImageGenerator API
Introduce an SkImageGenerator API to support the implementation of externally-managed image decode and scale caches. BUG=skia:5806 R=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4720 Change-Id: Ibfe37af5471f78f28f88f9d5e80938882be1a344 Reviewed-on: https://skia-review.googlesource.com/4720 Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Mike Reed <reed@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkDevice.h5
-rw-r--r--include/core/SkImageGenerator.h40
2 files changed, 44 insertions, 1 deletions
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index d521fec5ca..b0aac41d0b 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -255,7 +255,6 @@ protected:
virtual GrContext* context() const { return nullptr; }
-protected:
virtual sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&);
virtual bool onPeekPixels(SkPixmap*) { return false; }
@@ -359,6 +358,10 @@ private:
*const_cast<SkImageInfo*>(&fInfo) = fInfo.makeWH(w, h);
}
+ bool drawExternallyScaledImage(const SkDraw& draw, const SkImage* image, const SkRect* src,
+ const SkRect& dst, const SkPaint& paint,
+ SkCanvas::SrcRectConstraint constraint);
+
SkIPoint fOrigin;
SkMetaData* fMetaData;
const SkImageInfo fInfo;
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index 5e7214c7d1..2e34bfe2ce 100644
--- a/include/core/SkImageGenerator.h
+++ b/include/core/SkImageGenerator.h
@@ -19,6 +19,7 @@ class GrTexture;
class GrTextureParams;
class SkBitmap;
class SkData;
+class SkImage;
class SkImageGenerator;
class SkMatrix;
class SkPaint;
@@ -199,6 +200,40 @@ public:
}
/**
+ * External generator API: provides efficient access to externally-managed image data.
+ *
+ * Skia calls accessScaledPixels() during rasterization, to gain temporary access to
+ * the external pixel data, packaged as a raster SkImage.
+ *
+ * @param srcRect the source rect in use for the current draw
+ * @param totalMatrix full matrix in effect (mapping srcRect -> device space)
+ * @param quality the SkFilterQuality requested for rasterization.
+ * @param rec out param, expected to be set when the call succeeds:
+ *
+ * - fImage wraps the external pixel data
+ * - fSrcRect is an adjusted srcRect
+ * - fQuality is the adjusted filter quality
+ *
+ * @return true on success, false otherwise (error or if this API is not supported;
+ * in this case Skia will fall back to its internal scaling and caching
+ * heuristics)
+ *
+ * Implementors can return pixmaps with a different size than requested, by adjusting the
+ * src rect. The contract is that Skia will observe the adjusted src rect, and will map it
+ * to the same dest as the original draw (the impl doesn't get to control the destination).
+ *
+ */
+
+ struct ScaledImageRec {
+ sk_sp<SkImage> fImage;
+ SkRect fSrcRect;
+ SkFilterQuality fQuality;
+ };
+
+ bool accessScaledImage(const SkRect& srcRect, const SkMatrix& totalMatrix,
+ SkFilterQuality quality, ScaledImageRec* rec);
+
+ /**
* 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
* the caller is still responsible for managing their ownership of the data.
@@ -263,6 +298,11 @@ protected:
return false;
}
+ virtual bool onAccessScaledImage(const SkRect&, const SkMatrix&, SkFilterQuality,
+ ScaledImageRec*) {
+ return false;
+ }
+
bool tryGenerateBitmap(SkBitmap* bm, const SkImageInfo* optionalInfo, SkBitmap::Allocator*);
private: