Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1325)

Unified Diff: src/effects/SkGpuBlurUtils.cpp

Issue 19775006: Implement crop rect for SkImageFilter (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Revert more unnecessary changes Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/effects/SkGpuBlurUtils.cpp
diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp
index 479648850c67b8e219e8bf5d06e05cde715fa27c..5b52ad3cea9748bb1b4a14127aa98cef63c2a100 100644
--- a/src/effects/SkGpuBlurUtils.cpp
+++ b/src/effects/SkGpuBlurUtils.cpp
@@ -11,6 +11,7 @@
#if SK_SUPPORT_GPU
#include "effects/GrConvolutionEffect.h"
+#include "effects/GrTextureDomainEffect.h"
#include "GrContext.h"
#endif
@@ -40,18 +41,29 @@ static float adjust_sigma(float sigma, int *scaleFactor, int *radius) {
static void convolve_gaussian(GrContext* context,
GrTexture* texture,
- const SkRect& rect,
+ const SkRect& srcRect,
+ const SkRect& dstRect,
float sigma,
int radius,
Gr1DKernelEffect::Direction direction) {
GrPaint paint;
+ paint.reset();
+ float cropRect[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
+ if (direction == Gr1DKernelEffect::kX_Direction) {
+ cropRect[0] = SkScalarToFloat(srcRect.left()) / texture->width();
+ cropRect[1] = SkScalarToFloat(srcRect.right()) / texture->width();
+ } else {
+ cropRect[2] = SkScalarToFloat(srcRect.top()) / texture->height();
+ cropRect[3] = SkScalarToFloat(srcRect.bottom()) / texture->height();
+ }
SkAutoTUnref<GrEffectRef> conv(GrConvolutionEffect::CreateGaussian(texture,
direction,
radius,
- sigma));
+ sigma,
+ cropRect));
paint.addColorEffect(conv);
- context->drawRect(paint, rect);
+ context->drawRectToRect(paint, dstRect, srcRect);
}
GrTexture* GaussianBlur(GrContext* context,
@@ -79,7 +91,7 @@ GrTexture* GaussianBlur(GrContext* context,
scale_rect(&srcRect, static_cast<float>(scaleFactorX),
static_cast<float>(scaleFactorY));
- GrContext::AutoClip acs(context, srcRect);
+ GrContext::AutoClip acs(context, SkRect::MakeWH(srcRect.width(), srcRect.height()));
GrAssert(kBGRA_8888_GrPixelConfig == srcTexture->config() ||
kRGBA_8888_GrPixelConfig == srcTexture->config() ||
@@ -104,10 +116,25 @@ GrTexture* GaussianBlur(GrContext* context,
matrix.setIDiv(srcTexture->width(), srcTexture->height());
context->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect(srcRect);
+ if (i == 1) {
+ dstRect.offset(-dstRect.fLeft, -dstRect.fTop);
+ SkRect domain;
+ matrix.mapRect(&domain, rect);
+ domain.inset(i < scaleFactorX ? SK_ScalarHalf / srcTexture->width() : 0.0f,
+ i < scaleFactorY ? SK_ScalarHalf / srcTexture->height() : 0.0f);
+ SkAutoTUnref<GrEffectRef> effect(GrTextureDomainEffect::Create(
+ srcTexture,
+ matrix,
+ domain,
+ GrTextureDomainEffect::kDecal_WrapMode,
+ true));
+ paint.addColorEffect(effect);
+ } else {
+ GrTextureParams params(SkShader::kClamp_TileMode, true);
+ paint.addColorTextureEffect(srcTexture, matrix, params);
+ }
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
- GrTextureParams params(SkShader::kClamp_TileMode, true);
- paint.addColorTextureEffect(srcTexture, matrix, params);
context->drawRectToRect(paint, dstRect, srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
@@ -126,9 +153,11 @@ GrTexture* GaussianBlur(GrContext* context,
context->clear(&clearRect, 0x0);
}
context->setRenderTarget(dstTexture->asRenderTarget());
- convolve_gaussian(context, srcTexture, srcRect, sigmaX, radiusX,
+ SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
+ convolve_gaussian(context, srcTexture, srcRect, dstRect, sigmaX, radiusX,
Gr1DKernelEffect::kX_Direction);
srcTexture = dstTexture;
+ srcRect = dstRect;
SkTSwap(dstTexture, tempTexture);
}
@@ -142,9 +171,11 @@ GrTexture* GaussianBlur(GrContext* context,
}
context->setRenderTarget(dstTexture->asRenderTarget());
- convolve_gaussian(context, srcTexture, srcRect, sigmaY, radiusY,
+ SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
+ convolve_gaussian(context, srcTexture, srcRect, dstRect, sigmaY, radiusY,
Gr1DKernelEffect::kY_Direction);
srcTexture = dstTexture;
+ srcRect = dstRect;
SkTSwap(dstTexture, tempTexture);
}

Powered by Google App Engine
This is Rietveld 408576698