diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-11 18:57:00 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-11 18:57:00 +0000 |
commit | f7efa502d62af80bd15b03e1131603fb6577c3df (patch) | |
tree | 13963631336d0186acad91eed297ae3f83224c3b /include/core | |
parent | cae54f1f211e3c293ef9afb968067d06ca0ea23d (diff) |
Implement intra-frame cacheing in image filters.
When image filters are processed within Skia, they simply do
a blind recursion. This has the side-effect of turning the
DAG into a tree. I.e., nodes visited more than once during
the traversal will be processed more than once.
This change implements a very simple cacheing scheme: a
cache is created before traversing the DAG, and handed
into the processing traversal. Before recursing into a child
in SkImageFilter::filterImage(), the cache is checked for a
hit, and early-out is performed. Otherwise, the node is
processed, and its result bitmap and location (offset) are
cached, but only if it contains two or more children and
thus will be visited again during the traversal.
Currently, the child count is approximated with the
refcount. This is good enough in most cases (and exactly
correct for the Chrome use case). We could add an exact
child count to the image filter, but this will require
violating the immutability of image filters slightly in
order to bump the child count as nodes are connected. I
leave it up to the reviewer to decide which is better.
R=reed@google.com
Author: senorblanco@chromium.org
Review URL: https://codereview.chromium.org/230653005
git-svn-id: http://skia.googlecode.com/svn/trunk@14160 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkImageFilter.h | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h index 0f52b69b84..7a65f53788 100644 --- a/include/core/SkImageFilter.h +++ b/include/core/SkImageFilter.h @@ -16,7 +16,6 @@ class SkBitmap; class SkColorFilter; class SkBaseDevice; struct SkIPoint; -class SkShader; class GrEffectRef; class GrTexture; @@ -49,16 +48,28 @@ public: uint32_t fFlags; }; + class Cache : public SkRefCnt { + public: + // By default, we cache only image filters with 2 or more children. + static Cache* Create(int minChildren = 2); + virtual ~Cache() {} + virtual bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) = 0; + virtual void set(const SkImageFilter* key, + const SkBitmap& result, const SkIPoint& offset) = 0; + }; + class Context { public: - Context(const SkMatrix& ctm, const SkIRect& clipBounds) : - fCTM(ctm), fClipBounds(clipBounds) { + Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache) : + fCTM(ctm), fClipBounds(clipBounds), fCache(cache) { } const SkMatrix& ctm() const { return fCTM; } const SkIRect& clipBounds() const { return fClipBounds; } + Cache* cache() const { return fCache; } private: SkMatrix fCTM; SkIRect fClipBounds; + Cache* fCache; }; class Proxy { |