Fix GPU blur cacheing bug. Sometimes, the texture cache serves us textures of
different sizes for srcTexture and dstTexture (this is fair; they're supposed
to be approximate). Code was assuming otherwise while downsampling; fix is to
reapply the scale on each downsample. (Yes, I could cache these reciprocals
if and when they prove to be a hot spot).
Also, use setIDiv(w,h) everywhere for conciseness.
Review URL: http://codereview.appspot.com/4798041/
git-svn-id: http://skia.googlecode.com/svn/trunk@1907 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index cc669fe..c4e0ebe 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -936,8 +936,7 @@
SkTSwap(srcTexture, dstTexture);
GrMatrix sampleM;
- sampleM.setScale(GR_Scalar1 / srcTexture->width(),
- GR_Scalar1 / srcTexture->height());
+ sampleM.setIDiv(srcTexture->width(), srcTexture->height());
GrPaint paint;
paint.reset();
paint.getTextureSampler(0)->setFilter(GrSamplerState::kBilinear_Filter);
@@ -955,6 +954,8 @@
}
GrAutoUnlockTextureEntry origLock(context, origEntry);
for (int i = 1; i < scaleFactor; i *= 2) {
+ sampleM.setIDiv(srcTexture->width(), srcTexture->height());
+ paint.getTextureSampler(0)->setMatrix(sampleM);
context->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect(srcRect);
scaleRect(&dstRect, 0.5f);
@@ -984,8 +985,7 @@
if (scaleFactor > 1) {
// FIXME: This should be mitchell, not bilinear.
paint.getTextureSampler(0)->setFilter(GrSamplerState::kBilinear_Filter);
- sampleM.setScale(GR_Scalar1 / srcTexture->width(),
- GR_Scalar1 / srcTexture->height());
+ sampleM.setIDiv(srcTexture->width(), srcTexture->height());
paint.getTextureSampler(0)->setMatrix(sampleM);
context->setRenderTarget(dstTexture->asRenderTarget());
// Clear out 2 pixel border for bicubic filtering.
@@ -1002,8 +1002,7 @@
if (blurType != SkMaskFilter::kNormal_BlurType) {
GrTexture* origTexture = origEntry->texture();
paint.getTextureSampler(0)->setFilter(GrSamplerState::kNearest_Filter);
- sampleM.setScale(GR_Scalar1 / origTexture->width(),
- GR_Scalar1 / origTexture->height());
+ sampleM.setIDiv(origTexture->width(), origTexture->height());
paint.getTextureSampler(0)->setMatrix(sampleM);
// Blend origTexture over srcTexture.
context->setRenderTarget(srcTexture->asRenderTarget());