Reland r5963 with two fixes:
Missing ref in GrSweepGradient::TestCreate.
Must reset() the sampler in setup_drawstate_aaclip() to avoid hitting a (dubious) assert.
git-svn-id: http://skia.googlecode.com/svn/trunk@5964 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index a09b57f..02bfdbd 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -548,25 +548,14 @@
}
GrSamplerState* sampler = grPaint->colorSampler(kShaderTextureIdx);
- GrCustomStage* stage = shader->asNewCustomStage(dev->context(), sampler);
-
- if (NULL != stage) {
- sampler->setCustomStage(stage)->unref();
- SkMatrix localM;
- if (shader->getLocalMatrix(&localM)) {
- SkMatrix inverse;
- if (localM.invert(&inverse)) {
- sampler->matrix()->preConcat(inverse);
- }
- }
+ if (shader->asNewCustomStage(dev->context(), sampler)) {
return true;
}
SkBitmap bitmap;
- SkMatrix* matrix = sampler->matrix();
+ SkMatrix matrix;
SkShader::TileMode tileModes[2];
- SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, matrix,
- tileModes);
+ SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, &matrix, tileModes);
if (SkShader::kNone_BitmapType == bmptype) {
SkShader::GradientInfo info;
@@ -600,23 +589,21 @@
return false;
}
- sampler->reset();
- sampler->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture, params)))->unref();
-
- // since our texture coords will be in local space, we wack the texture
+ // since our texture coords will be in local space, we whack the texture
// matrix to map them back into 0...1 before we load it
SkMatrix localM;
if (shader->getLocalMatrix(&localM)) {
SkMatrix inverse;
if (localM.invert(&inverse)) {
- matrix->preConcat(inverse);
+ matrix.preConcat(inverse);
}
}
if (SkShader::kDefault_BitmapType == bmptype) {
GrScalar sx = SkFloatToScalar(1.f / bitmap.width());
GrScalar sy = SkFloatToScalar(1.f / bitmap.height());
- matrix->postScale(sx, sy);
+ matrix.postScale(sx, sy);
}
+ sampler->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture, params)), matrix)->unref();
return true;
}
@@ -876,13 +863,11 @@
if (!isNormalBlur) {
context->setIdentityMatrix();
GrPaint paint;
- paint.reset();
- paint.colorSampler(0)->matrix()->setIDiv(pathTexture->width(),
- pathTexture->height());
+ GrMatrix matrix;
+ matrix.setIDiv(pathTexture->width(), pathTexture->height());
// Blend pathTexture over blurTexture.
context->setRenderTarget(blurTexture->asRenderTarget());
- paint.colorSampler(0)->setCustomStage(SkNEW_ARGS
- (GrSingleTextureEffect, (pathTexture)))->unref();
+ paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (pathTexture)), matrix)->unref();
if (SkMaskFilter::kInner_BlurType == blurType) {
// inner: dst = dst * src
paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff);
@@ -907,13 +892,13 @@
static const int MASK_IDX = GrPaint::kMaxCoverageStages - 1;
// we assume the last mask index is available for use
GrAssert(!grp->isCoverageStageEnabled(MASK_IDX));
+
+ GrMatrix matrix;
+ matrix.setTranslate(-finalRect.fLeft, -finalRect.fTop);
+ matrix.postIDiv(blurTexture->width(), blurTexture->height());
+
grp->coverageSampler(MASK_IDX)->reset();
- grp->coverageSampler(MASK_IDX)->setCustomStage(
- SkNEW_ARGS(GrSingleTextureEffect, (blurTexture)))->unref();
- grp->coverageSampler(MASK_IDX)->matrix()->setTranslate(-finalRect.fLeft,
- -finalRect.fTop);
- grp->coverageSampler(MASK_IDX)->matrix()->postIDiv(blurTexture->width(),
- blurTexture->height());
+ grp->coverageSampler(MASK_IDX)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (blurTexture)), matrix)->unref();
context->drawRect(*grp, finalRect);
return true;
}
@@ -964,19 +949,18 @@
static const int MASK_IDX = GrPaint::kMaxCoverageStages - 1;
// we assume the last mask index is available for use
GrAssert(!grp->isCoverageStageEnabled(MASK_IDX));
- grp->coverageSampler(MASK_IDX)->reset();
- grp->coverageSampler(MASK_IDX)->setCustomStage(
- SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
+
+ GrMatrix m;
+ m.setTranslate(-dstM.fBounds.fLeft*SK_Scalar1, -dstM.fBounds.fTop*SK_Scalar1);
+ m.postIDiv(texture->width(), texture->height());
+
+ grp->coverageSampler(MASK_IDX)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture)), m)->unref();
GrRect d;
d.setLTRB(GrIntToScalar(dstM.fBounds.fLeft),
GrIntToScalar(dstM.fBounds.fTop),
GrIntToScalar(dstM.fBounds.fRight),
GrIntToScalar(dstM.fBounds.fBottom));
- GrMatrix* m = grp->coverageSampler(MASK_IDX)->matrix();
- m->setTranslate(-dstM.fBounds.fLeft*SK_Scalar1,
- -dstM.fBounds.fTop*SK_Scalar1);
- m->postIDiv(texture->width(), texture->height());
context->drawRect(*grp, d);
return true;
}
@@ -1385,8 +1369,6 @@
GrSamplerState* sampler = grPaint->colorSampler(kBitmapTextureIdx);
- sampler->matrix()->reset();
-
GrTexture* texture;
SkAutoCachedTexture act(this, bitmap, ¶ms, &texture);
if (NULL == texture) {
@@ -1469,8 +1451,7 @@
GrMatrix sampleM;
sampleM.setIDiv(srcTexture->width(), srcTexture->height());
GrPaint paint;
- paint.colorSampler(0)->reset(sampleM);
- paint.colorSampler(0)->setCustomStage(stage);
+ paint.colorSampler(0)->setCustomStage(stage, sampleM);
context->drawRect(paint, rect);
}