aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image
diff options
context:
space:
mode:
authorGravatar brianosman <brianosman@google.com>2016-09-21 09:46:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-21 09:46:57 -0700
commit04a44d0fd45f5596c716e99e7a3bbcc03db0e05a (patch)
tree2dbd1b8dc623cdf1a72d4ed0e2f90851265be145 /src/image
parent3e8012e74f70bf49427a7422f9e5996c9882d4f3 (diff)
Add a transient image filter cache to SkImage::makeWithFilter & PDF
Added a bench for makeWithFilter (~23 ms -> ~6 ms median locally). Also fixed indentation. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2360663002 Review-Url: https://codereview.chromium.org/2360663002
Diffstat (limited to 'src/image')
-rw-r--r--src/image/SkImage.cpp66
1 files changed, 34 insertions, 32 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index b8a321cea1..6e65050a65 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -11,6 +11,7 @@
#include "SkData.h"
#include "SkImageEncoder.h"
#include "SkImageFilter.h"
+#include "SkImageFilterCache.h"
#include "SkImageGenerator.h"
#include "SkImagePriv.h"
#include "SkImageShader.h"
@@ -334,40 +335,41 @@ sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize&
sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
const SkIRect& clipBounds, SkIRect* outSubset,
SkIPoint* offset) const {
- if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) {
- return nullptr;
- }
- sk_sp<SkSpecialImage> srcSpecialImage = SkSpecialImage::MakeFromImage(
- subset, sk_ref_sp(const_cast<SkImage*>(this)));
- if (!srcSpecialImage) {
- return nullptr;
- }
-
- // FIXME: build a cache here.
- SkImageFilter::Context context(SkMatrix::I(), clipBounds, nullptr);
- sk_sp<SkSpecialImage> result =
- filter->filterImage(srcSpecialImage.get(), context, offset);
-
- if (!result) {
- return nullptr;
- }
-
- SkIRect fullSize = SkIRect::MakeWH(result->width(), result->height());
+ if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) {
+ return nullptr;
+ }
+ sk_sp<SkSpecialImage> srcSpecialImage = SkSpecialImage::MakeFromImage(
+ subset, sk_ref_sp(const_cast<SkImage*>(this)));
+ if (!srcSpecialImage) {
+ return nullptr;
+ }
+
+ SkAutoTUnref<SkImageFilterCache> cache(
+ SkImageFilterCache::Create(SkImageFilterCache::kDefaultTransientSize));
+ SkImageFilter::Context context(SkMatrix::I(), clipBounds, cache.get());
+ sk_sp<SkSpecialImage> result =
+ filter->filterImage(srcSpecialImage.get(), context, offset);
+
+ if (!result) {
+ return nullptr;
+ }
+
+ SkIRect fullSize = SkIRect::MakeWH(result->width(), result->height());
#if SK_SUPPORT_GPU
- if (result->isTextureBacked()) {
- GrContext* context = result->getContext();
- sk_sp<GrTexture> texture = result->asTextureRef(context);
- fullSize = SkIRect::MakeWH(texture->width(), texture->height());
- }
+ if (result->isTextureBacked()) {
+ GrContext* context = result->getContext();
+ sk_sp<GrTexture> texture = result->asTextureRef(context);
+ fullSize = SkIRect::MakeWH(texture->width(), texture->height());
+ }
#endif
- *outSubset = SkIRect::MakeWH(result->width(), result->height());
- if (!outSubset->intersect(clipBounds.makeOffset(-offset->x(), -offset->y()))) {
- return nullptr;
- }
- offset->fX += outSubset->x();
- offset->fY += outSubset->y();
- // This isn't really a "tight" subset, but includes any texture padding.
- return result->makeTightSubset(fullSize);
+ *outSubset = SkIRect::MakeWH(result->width(), result->height());
+ if (!outSubset->intersect(clipBounds.makeOffset(-offset->x(), -offset->y()))) {
+ return nullptr;
+ }
+ offset->fX += outSubset->x();
+ offset->fY += outSubset->y();
+ // This isn't really a "tight" subset, but includes any texture padding.
+ return result->makeTightSubset(fullSize);
}
bool SkImage::isLazyGenerated() const {