aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar senorblanco <senorblanco@chromium.org>2014-07-30 11:26:46 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-30 11:26:46 -0700
commit55b6d8be997a447ef9ce0f029697677a940bfc24 (patch)
treea33ca4d5ed0622f293b81c850b9f42ee02da7cab /src/gpu
parent78697816b0a345c614071070eaa895d71f598e22 (diff)
Implement a persistent uniqueID-based cache for SkImageFilter.
Add a unique ID to SkImageFilter, and use it as part of a persistent cache of image-filtered results. This is used for caching frame-to-frame coherent filters. We also keep track of which filter subtrees do not reference the src input, and use a GenID of zero for the src input in that case. That way, subtrees which are not dependent on the filter input can be cached independently of it. This gives approximately a 4X speedup on letmespellitoutforyou.com/samples/svg/filter_terrain.svg on Z620 and Nexus10. The cache key consists of the uniqueID of the filter, the clip bounds, the CTM and the genID of the input bitmap. Since this does not yet handle the case where the input primitives (and part of the resulting filter tree) are unchanged, we have to keep around the external cache for that painting case. When the work to cache unchanging input primitives is done, the old cache can be removed, and the new UniqueIDCache will be renamed to Cache. R=bsalomon@google.com, mtklein@google.com Author: senorblanco@chromium.org Review URL: https://codereview.chromium.org/414483003
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/SkGpuDevice.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 0abf9d84b5..2853805a5b 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -41,6 +41,8 @@
#include "SkXfermode.h"
#include "SkErrorInternals.h"
+enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 };
+
#define CACHE_COMPATIBLE_DEVICE_TEXTURES 1
#if 0
@@ -1425,8 +1427,9 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
SkMatrix matrix(*draw.fMatrix);
matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
- SkImageFilter::Cache* cache = SkImageFilter::Cache::Create();
- SkAutoUnref aur(cache);
+ SkAutoTUnref<SkImageFilter::UniqueIDCache> cache(getImageFilterCache());
+ // This cache is transient, and is freed (along with all its contained
+ // textures) when it goes out of scope.
SkImageFilter::Context ctx(matrix, clipBounds, cache);
if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filteredBitmap,
&offset)) {
@@ -1535,8 +1538,9 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
SkMatrix matrix(*draw.fMatrix);
matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height());
- SkImageFilter::Cache* cache = SkImageFilter::Cache::Create();
- SkAutoUnref aur(cache);
+ // This cache is transient, and is freed (along with all its contained
+ // textures) when it goes out of scope.
+ SkAutoTUnref<SkImageFilter::UniqueIDCache> cache(getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache);
if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredBitmap,
&offset)) {
@@ -2060,3 +2064,9 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* pi
return true;
}
+
+SkImageFilter::UniqueIDCache* SkGpuDevice::getImageFilterCache() {
+ // We always return a transient cache, so it is freed after each
+ // filter traversal.
+ return SkImageFilter::UniqueIDCache::Create(kDefaultImageFilterCacheSize);
+}