aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-10-22 13:20:20 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-10-22 13:20:20 -0700
commitc9b5f8b1522e72449d704d30ed6aee4fc6211ee8 (patch)
tree2076a03c9e01fe3146e64755f54684abd3ea9497 /src
parent6ae30fbbafe9aa9596922ac96ecaae0278b7be65 (diff)
tunnel down texture-size-constraint to imagefilters
Diffstat (limited to 'src')
-rw-r--r--src/core/SkCanvas.cpp6
-rw-r--r--src/core/SkImageFilter.cpp31
-rw-r--r--src/core/SkLocalMatrixImageFilter.cpp5
-rw-r--r--src/effects/SkBlurImageFilter.cpp4
-rw-r--r--src/effects/SkBlurMaskFilter.cpp3
-rw-r--r--src/effects/SkComposeImageFilter.cpp4
-rw-r--r--src/effects/SkGpuBlurUtils.cpp7
-rw-r--r--src/effects/SkGpuBlurUtils.h5
-rw-r--r--src/effects/SkMorphologyImageFilter.cpp17
-rw-r--r--src/gpu/GrLayerHoister.cpp2
-rw-r--r--src/gpu/SkGpuDevice.cpp4
-rw-r--r--src/image/SkImage.cpp3
-rw-r--r--src/image/SkImage_Gpu.cpp7
13 files changed, 70 insertions, 28 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 6914963cb9..6dd8d04721 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1308,7 +1308,8 @@ void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y()));
SkIRect clipBounds = SkIRect::MakeWH(srcDev->width(), srcDev->height());
SkAutoTUnref<SkImageFilter::Cache> cache(dstDev->getImageFilterCache());
- SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
+ SkImageFilter::Context ctx(matrix, clipBounds, cache.get(),
+ SkImageFilter::kApprox_SizeConstraint);
if (filter->filterImage(&proxy, src, ctx, &dst, &offset)) {
SkPaint tmpUnfiltered(*paint);
tmpUnfiltered.setImageFilter(nullptr);
@@ -1359,7 +1360,8 @@ void SkCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint*
matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y()));
const SkIRect clipBounds = bitmap.bounds();
SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageFilterCache());
- SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
+ SkImageFilter::Context ctx(matrix, clipBounds, cache.get(),
+ SkImageFilter::kApprox_SizeConstraint);
if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) {
SkPaint tmpUnfiltered(*paint);
tmpUnfiltered.setImageFilter(nullptr);
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index d7af4e65d0..fef88fdf37 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -263,10 +263,21 @@ bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src,
}
bool SkImageFilter::filterInput(int index, Proxy* proxy, const SkBitmap& src,
- const Context& context,
- SkBitmap* result, SkIPoint* offset) const {
+ const Context& origCtx,
+ SkBitmap* result, SkIPoint* offset,
+ bool relaxSizeConstraint) const {
SkImageFilter* input = this->getInput(index);
- return !input || input->filterImage(proxy, src, context, result, offset);
+ if (!input) {
+ return true;
+ }
+
+ SizeConstraint constraint = origCtx.sizeConstraint();
+ if (relaxSizeConstraint && (kExact_SizeConstraint == constraint)) {
+ constraint = kApprox_SizeConstraint;
+ }
+ Context ctx(origCtx.ctm(), origCtx.clipBounds(), origCtx.cache(), constraint);
+
+ return input->filterImage(proxy, src, ctx, result, offset);
}
bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm,
@@ -347,7 +358,8 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont
desc.fHeight = bounds.height();
desc.fConfig = kRGBA_8888_GrPixelConfig;
- SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
+ SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(desc,
+ GrTextureProvider::FromImageFilter(ctx.sizeConstraint())));
if (!dst) {
return false;
}
@@ -466,8 +478,9 @@ void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
}
bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy,
- const SkBitmap& src, const Context& ctx,
- SkBitmap* result, SkIPoint* offset) const {
+ const SkBitmap& src, const Context& origCtx,
+ SkBitmap* result, SkIPoint* offset,
+ bool relaxSizeConstraint) const {
SkImageFilter* input = this->getInput(index);
if (!input) {
return true;
@@ -477,6 +490,12 @@ bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy,
// called are restored before we return to the caller.
GrContext* context = src.getTexture()->getContext();
+ SizeConstraint constraint = origCtx.sizeConstraint();
+ if (relaxSizeConstraint && (kExact_SizeConstraint == constraint)) {
+ constraint = kApprox_SizeConstraint;
+ }
+ Context ctx(origCtx.ctm(), origCtx.clipBounds(), origCtx.cache(), constraint);
+
if (input->canFilterImageGPU()) {
return input->filterImageGPU(proxy, src, ctx, result, offset);
} else {
diff --git a/src/core/SkLocalMatrixImageFilter.cpp b/src/core/SkLocalMatrixImageFilter.cpp
index 10d63ede66..e4fc0ceb00 100644
--- a/src/core/SkLocalMatrixImageFilter.cpp
+++ b/src/core/SkLocalMatrixImageFilter.cpp
@@ -40,8 +40,9 @@ void SkLocalMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
bool SkLocalMatrixImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
- Context localCtx(SkMatrix::Concat(ctx.ctm(), fLocalM), ctx.clipBounds(), ctx.cache());
- return this->filterInput(0, proxy, src, localCtx, result, offset);
+ Context localCtx(SkMatrix::Concat(ctx.ctm(), fLocalM), ctx.clipBounds(), ctx.cache(),
+ ctx.sizeConstraint());
+ return this->filterInput(0, proxy, src, localCtx, result, offset, false);
}
bool SkLocalMatrixImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& matrix,
diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp
index 8398f48b7f..c77a444da5 100644
--- a/src/effects/SkBlurImageFilter.cpp
+++ b/src/effects/SkBlurImageFilter.cpp
@@ -212,13 +212,15 @@ bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
offset->fX = rect.fLeft;
offset->fY = rect.fTop;
rect.offset(-srcOffset);
+ auto constraint = GrTextureProvider::FromImageFilter(ctx.sizeConstraint());
SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(),
source,
false,
SkRect::Make(rect),
true,
sigma.x(),
- sigma.y()));
+ sigma.y(),
+ constraint));
if (!tex) {
return false;
}
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index d0ff7a228f..3d32d8d259 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -1234,7 +1234,8 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
// gaussianBlur. Otherwise, we need to save it for later compositing.
bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle);
*result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOverwriteSrc,
- clipRect, false, xformedSigma, xformedSigma);
+ clipRect, false, xformedSigma, xformedSigma,
+ GrTextureProvider::kApprox_SizeConstraint);
if (nullptr == *result) {
return false;
}
diff --git a/src/effects/SkComposeImageFilter.cpp b/src/effects/SkComposeImageFilter.cpp
index 6361cdcc6c..1be03a3370 100644
--- a/src/effects/SkComposeImageFilter.cpp
+++ b/src/effects/SkComposeImageFilter.cpp
@@ -35,8 +35,8 @@ bool SkComposeImageFilter::onFilterImage(Proxy* proxy,
SkMatrix outerMatrix(ctx.ctm());
outerMatrix.postTranslate(SkIntToScalar(-innerOffset.x()), SkIntToScalar(-innerOffset.y()));
- Context outerContext(outerMatrix, ctx.clipBounds(), ctx.cache());
- if (!this->filterInput(0, proxy, tmp, outerContext, result, &outerOffset)) {
+ Context outerContext(outerMatrix, ctx.clipBounds(), ctx.cache(), ctx.sizeConstraint());
+ if (!this->filterInput(0, proxy, tmp, outerContext, result, &outerOffset, false)) {
return false;
}
diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp
index f0c10c2871..3437ab0d01 100644
--- a/src/effects/SkGpuBlurUtils.cpp
+++ b/src/effects/SkGpuBlurUtils.cpp
@@ -146,7 +146,8 @@ GrTexture* GaussianBlur(GrContext* context,
const SkRect& rect,
bool cropToRect,
float sigmaX,
- float sigmaY) {
+ float sigmaY,
+ GrTextureProvider::SizeConstraint constraint) {
SkASSERT(context);
SkIRect clearRect;
@@ -179,12 +180,12 @@ GrTexture* GaussianBlur(GrContext* context,
GrTexture* tempTexture;
SkAutoTUnref<GrTexture> temp1, temp2;
- temp1.reset(context->textureProvider()->createApproxTexture(desc));
+ temp1.reset(context->textureProvider()->createTexture(desc, constraint));
dstTexture = temp1.get();
if (canClobberSrc) {
tempTexture = srcTexture;
} else {
- temp2.reset(context->textureProvider()->createApproxTexture(desc));
+ temp2.reset(context->textureProvider()->createTexture(desc, constraint));
tempTexture = temp2.get();
}
diff --git a/src/effects/SkGpuBlurUtils.h b/src/effects/SkGpuBlurUtils.h
index 98be8130e2..357a0d729c 100644
--- a/src/effects/SkGpuBlurUtils.h
+++ b/src/effects/SkGpuBlurUtils.h
@@ -9,6 +9,8 @@
#define SkGpuBlurUtils_DEFINED
#if SK_SUPPORT_GPU
+#include "GrTextureProvider.h"
+
class GrTexture;
class GrContext;
#endif
@@ -38,7 +40,8 @@ namespace SkGpuBlurUtils {
const SkRect& rect,
bool cropToRect,
float sigmaX,
- float sigmaY);
+ float sigmaY,
+ GrTextureProvider::SizeConstraint);
#endif
};
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 4e08d9dd73..546e6f5d93 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -547,7 +547,8 @@ bool apply_morphology(const SkBitmap& input,
const SkIRect& rect,
GrMorphologyEffect::MorphologyType morphType,
SkISize radius,
- SkBitmap* dst) {
+ SkBitmap* dst,
+ GrTextureProvider::SizeConstraint constraint) {
SkAutoTUnref<GrTexture> srcTexture(SkRef(input.getTexture()));
SkASSERT(srcTexture);
GrContext* context = srcTexture->getContext();
@@ -565,7 +566,14 @@ bool apply_morphology(const SkBitmap& input,
SkIRect srcRect = rect;
if (radius.fWidth > 0) {
- GrTexture* scratch = context->textureProvider()->createApproxTexture(desc);
+ GrTextureProvider::SizeConstraint horiConstraint = constraint;
+ if (radius.fHeight > 0) {
+ // Optimization: we will fall through and allocate the "real" texture after this one
+ // so ours can be approximate (likely faster to allocate)
+ horiConstraint = GrTextureProvider::kApprox_SizeConstraint;
+ }
+
+ GrTexture* scratch = context->textureProvider()->createTexture(desc, horiConstraint);
if (nullptr == scratch) {
return false;
}
@@ -589,7 +597,7 @@ bool apply_morphology(const SkBitmap& input,
srcRect = dstRect;
}
if (radius.fHeight > 0) {
- GrTexture* scratch = context->textureProvider()->createApproxTexture(desc);
+ GrTexture* scratch = context->textureProvider()->createTexture(desc, constraint);
if (nullptr == scratch) {
return false;
}
@@ -647,7 +655,8 @@ bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDilate_MorphologyType
: GrMorphologyEffect::kErode_MorphologyType;
- if (!apply_morphology(input, srcBounds, type, SkISize::Make(width, height), result)) {
+ if (!apply_morphology(input, srcBounds, type, SkISize::Make(width, height), result,
+ GrTextureProvider::FromImageFilter(ctx.sizeConstraint()))) {
return false;
}
offset->fX = bounds.left();
diff --git a/src/gpu/GrLayerHoister.cpp b/src/gpu/GrLayerHoister.cpp
index 5bddc036df..2bf1abb5fd 100644
--- a/src/gpu/GrLayerHoister.cpp
+++ b/src/gpu/GrLayerHoister.cpp
@@ -311,7 +311,7 @@ void GrLayerHoister::FilterLayer(GrContext* context,
// This cache is transient, and is freed (along with all its contained
// textures) when it goes out of scope.
SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefaultCacheSize));
- SkImageFilter::Context filterContext(totMat, clipBounds, cache);
+ SkImageFilter::Context filterContext(totMat, clipBounds, cache, SkImageFilter::kApprox_SizeConstraint);
SkImageFilter::DeviceProxy proxy(device);
const SkBitmap src = wrap_texture(layer->texture());
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index fceacfc913..cdbda58e62 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1433,7 +1433,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
SkAutoTUnref<SkImageFilter::Cache> 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);
+ SkImageFilter::Context ctx(matrix, clipBounds, cache, SkImageFilter::kApprox_SizeConstraint);
if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredBitmap,
&offset)) {
texture = (GrTexture*) filteredBitmap.getTexture();
@@ -1553,7 +1553,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
// This cache is transient, and is freed (along with all its contained
// textures) when it goes out of scope.
SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
- SkImageFilter::Context ctx(matrix, clipBounds, cache);
+ SkImageFilter::Context ctx(matrix, clipBounds, cache, SkImageFilter::kApprox_SizeConstraint);
if (this->filterTexture(fContext, devTex, device->width(), device->height(),
filter, ctx, &filteredBitmap, &offset)) {
devTex = filteredBitmap.getTexture();
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 3ad80043da..b96f7d16ab 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -116,7 +116,8 @@ SkImage* SkImage_Base::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResu
if (forceResultToOriginalSize) {
const SkIRect clipBounds = srcBounds;
SkRasterImageFilterProxy proxy;
- SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cache::Get());
+ SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cache::Get(),
+ SkImageFilter::kExact_SizeConstraint);
SkBitmap dst;
if (filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) {
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index b1f78513ec..e5f3aeea25 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -24,7 +24,10 @@ SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
, fAlphaType(at)
, fBudgeted(budgeted)
, fAddedRasterVersionToCache(false)
- {}
+{
+ SkASSERT(tex->width() == w);
+ SkASSERT(tex->height() == h);
+}
SkImage_Gpu::~SkImage_Gpu() {
if (fAddedRasterVersionToCache.load()) {
@@ -236,7 +239,7 @@ SkImage* SkImage_Gpu::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResul
const SkIRect clipBounds = srcBounds;
SkGpuImageFilterProxy proxy(fTexture->getContext());
SkAutoTUnref<SkImageFilter::Cache> cache(SkGpuDevice::NewImageFilterCache());
- SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, cache);
+ SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, cache, SkImageFilter::kExact_SizeConstraint);
SkBitmap dst;
if (!filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) {