This change allows external callers to substitute their own
SkImageFilter cache for the default intra-frame cache in Skia. This
allows the caller to perform inter-frame caching for example, by the
maintaining a persistent cache between frames and doing custom
invalidation.
R=reed@google.com
Review URL: https://codereview.chromium.org/
225903010
git-svn-id: http://skia.googlecode.com/svn/trunk@14181
2bbb7eff-a529-9590-31e7-
b0007b416f81
virtual bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) = 0;
virtual void set(const SkImageFilter* key,
const SkBitmap& result, const SkIPoint& offset) = 0;
+ virtual void remove(const SkImageFilter* key) = 0;
};
class Context {
SkBitmap* result, SkIPoint* offset) const;
#endif
+ /**
+ * Set an external cache to be used for all image filter processing. This
+ * will replace the default intra-frame cache.
+ */
+ static void SetExternalCache(Cache* cache);
+
+ /**
+ * Returns the currently-set external cache, or NULL if none is set.
+ */
+ static Cache* GetExternalCache();
+
SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
protected:
const SkMatrix& matrix,
const SkIRect& bounds) const;
-
private:
typedef SkFlattenable INHERITED;
int fInputCount;
SkMatrix matrix = *iter.fMatrix;
matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y()));
SkIRect clipBounds = SkIRect::MakeWH(srcDev->width(), srcDev->height());
- SkImageFilter::Cache* cache = SkImageFilter::Cache::Create();
- SkAutoUnref aur(cache);
+ SkImageFilter::Cache* cache = SkImageFilter::GetExternalCache();
+ SkAutoUnref aur(NULL);
+ if (!cache) {
+ cache = SkImageFilter::Cache::Create();
+ aur.reset(cache);
+ }
SkImageFilter::Context ctx(matrix, clipBounds, cache);
if (filter->filterImage(&proxy, src, ctx, &dst, &offset)) {
SkPaint tmpUnfiltered(*paint);
SkMatrix matrix = *iter.fMatrix;
matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y()));
SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
- SkImageFilter::Cache* cache = SkImageFilter::Cache::Create();
- SkAutoUnref aur(cache);
+ SkImageFilter::Cache* cache = SkImageFilter::GetExternalCache();
+ SkAutoUnref aur(NULL);
+ if (!cache) {
+ cache = SkImageFilter::Cache::Create();
+ aur.reset(cache);
+ }
SkImageFilter::Context ctx(matrix, clipBounds, cache);
if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) {
SkPaint tmpUnfiltered(*paint);
#include "SkGr.h"
#endif
+SkImageFilter::Cache* gExternalCache;
+
SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect)
: fInputCount(inputCount),
fInputs(new SkImageFilter*[inputCount]),
return false;
}
+void SkImageFilter::SetExternalCache(Cache* cache) {
+ SkRefCnt_SafeAssign(gExternalCache, cache);
+}
+
+SkImageFilter::Cache* SkImageFilter::GetExternalCache() {
+ return gExternalCache;
+}
+
#if SK_SUPPORT_GPU
void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
virtual ~CacheImpl();
bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
void set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& offset) SK_OVERRIDE;
+ void remove(const SkImageFilter* key) SK_OVERRIDE;
private:
typedef const SkImageFilter* Key;
struct Value {
return false;
}
+void CacheImpl::remove(const SkImageFilter* key) {
+ Value* v = fData.find(key);
+ if (v) {
+ fData.remove(key);
+ delete v;
+ }
+}
+
void CacheImpl::set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& offset) {
if (key->getRefCnt() >= fMinChildren) {
fData.add(new Value(key, result, offset));