GPU-based blur cleanup. Clean up some issues raised in code review:
- convolveRect() is too low-level; made it private and exposed convolveInX() and
convolveInY() instead
- added GrAutoTextureEntry to automatically unlock a texture entry
- the clipping and bounder checks were returning false from
drawWithGPUMaskFilter(), causing the software blur to kick in; return true
instead
- the Windows build was giving a spurious warning about reading an uninitialized
variable; rearrange the code to fix it
Review URL: http://codereview.appspot.com/4710042/
git-svn-id: http://skia.googlecode.com/svn/trunk@1842 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp
index 092b0ba..dc4bac8 100644
--- a/gpu/src/GrContext.cpp
+++ b/gpu/src/GrContext.cpp
@@ -1699,22 +1699,38 @@
}
}
-void GrContext::convolveRect(GrTexture* srcTexture,
- const SkRect& rect,
- float imageIncrement[2],
- const float* kernel,
- int kernelWidth) {
+void GrContext::convolveInX(GrTexture* texture,
+ const SkRect& rect,
+ const float* kernel,
+ int kernelWidth) {
+ float imageIncrement[2] = {1.0f / texture->width(), 0.0f};
+ convolve(texture, rect, imageIncrement, kernel, kernelWidth);
+}
+
+void GrContext::convolveInY(GrTexture* texture,
+ const SkRect& rect,
+ const float* kernel,
+ int kernelWidth) {
+ float imageIncrement[2] = {0.0f, 1.0f / texture->height()};
+ convolve(texture, rect, imageIncrement, kernel, kernelWidth);
+}
+
+void GrContext::convolve(GrTexture* texture,
+ const SkRect& rect,
+ float imageIncrement[2],
+ const float* kernel,
+ int kernelWidth) {
GrDrawTarget::AutoStateRestore asr(fGpu);
GrMatrix sampleM;
GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kClamp_WrapMode,
GrSamplerState::kConvolution_Filter);
sampler.setConvolutionParams(kernelWidth, kernel, imageIncrement);
- sampleM.setScale(GR_Scalar1 / srcTexture->width(),
- GR_Scalar1 / srcTexture->height());
+ sampleM.setScale(GR_Scalar1 / texture->width(),
+ GR_Scalar1 / texture->height());
sampler.setMatrix(sampleM);
fGpu->setSamplerState(0, sampler);
fGpu->setViewMatrix(GrMatrix::I());
- fGpu->setTexture(0, srcTexture);
+ fGpu->setTexture(0, texture);
fGpu->drawSimpleRect(rect, NULL, 1 << 0);
}