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/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index 322fba1..6104f66 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -33,7 +33,7 @@
GrDrawState* drawState = gpu->drawState();
GrAssert(drawState);
- static const int maskStage = GrPaint::kTotalStages+1;
+ static const int kMaskStage = GrPaint::kTotalStages+1;
GrMatrix mat;
mat.setIDiv(result->width(), result->height());
@@ -41,9 +41,8 @@
SkIntToScalar(-devBound.fTop));
mat.preConcat(drawState->getViewMatrix());
- drawState->sampler(maskStage)->reset(mat);
-
- drawState->createTextureEffect(maskStage, result);
+ drawState->sampler(kMaskStage)->reset();
+ drawState->createTextureEffect(kMaskStage, result, mat);
}
bool path_needs_SW_renderer(GrContext* context,
@@ -495,8 +494,7 @@
GrMatrix sampleM;
sampleM.setIDiv(texture->width(), texture->height());
- drawState->sampler(0)->reset(sampleM);
- drawState->createTextureEffect(0, texture);
+ drawState->createTextureEffect(0, texture, sampleM);
GrRect rect = GrRect::MakeWH(SkIntToScalar(target->width()),
SkIntToScalar(target->height()));
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index ee3a4e1..8b7d2d0 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -202,11 +202,10 @@
drawState->setRenderTarget(rt);
GrMatrix sampleM;
sampleM.setIDiv(texture->width(), texture->height());
- drawState->sampler(0)->reset(sampleM);
SkAutoTUnref<GrConvolutionEffect> conv(SkNEW_ARGS(GrConvolutionEffect,
(texture, direction, radius,
sigma)));
- drawState->sampler(0)->setCustomStage(conv);
+ drawState->sampler(0)->setCustomStage(conv, sampleM);
target->drawSimpleRect(rect, NULL);
}
@@ -313,9 +312,8 @@
// if filtering is not desired then we want to ensure all
// texels in the resampled image are copies of texels from
// the original.
- drawState->sampler(0)->reset();
GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering);
- drawState->createTextureEffect(0, clampedTexture, params);
+ drawState->createTextureEffect(0, clampedTexture, GrMatrix::I(), params);
static const GrVertexLayout layout =
GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);
@@ -1348,8 +1346,7 @@
matrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top);
}
matrix.postIDiv(src->width(), src->height());
- drawState->sampler(0)->reset(matrix);
- drawState->sampler(0)->setCustomStage(stage);
+ drawState->sampler(0)->setCustomStage(stage, matrix);
GrRect rect = GrRect::MakeWH(GrIntToScalar(width), GrIntToScalar(height));
fGpu->drawSimpleRect(rect, NULL);
// we want to read back from the scratch's origin
@@ -1449,8 +1446,7 @@
drawState->setRenderTarget(dst);
GrMatrix sampleM;
sampleM.setIDiv(src->width(), src->height());
- drawState->sampler(0)->reset(sampleM);
- drawState->createTextureEffect(0, src);
+ drawState->createTextureEffect(0, src, sampleM);
SkRect rect = SkRect::MakeXYWH(0, 0,
SK_Scalar1 * src->width(),
SK_Scalar1 * src->height());
@@ -1558,8 +1554,7 @@
drawState->setRenderTarget(target);
matrix.setIDiv(texture->width(), texture->height());
- drawState->sampler(0)->reset(matrix);
- drawState->sampler(0)->setCustomStage(stage);
+ drawState->sampler(0)->setCustomStage(stage, matrix);
fGpu->drawSimpleRect(GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)), NULL);
}
@@ -1813,14 +1808,15 @@
paint.reset();
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
- paint.colorSampler(0)->matrix()->setIDiv(srcTexture->width(),
- srcTexture->height());
+ GrMatrix matrix;
+ matrix.setIDiv(srcTexture->width(), srcTexture->height());
this->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect(srcRect);
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
- i < scaleFactorY ? 0.5f : 1.0f);
+ i < scaleFactorY ? 0.5f : 1.0f);
+
paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect,
- (srcTexture, true)))->unref();
+ (srcTexture, true)), matrix)->unref();
this->drawRectToRect(paint, dstRect, srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
@@ -1873,12 +1869,13 @@
clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
1, srcIRect.height());
this->clear(&clearRect, 0x0);
+ GrMatrix matrix;
// FIXME: This should be mitchell, not bilinear.
- paint.colorSampler(0)->matrix()->setIDiv(srcTexture->width(),
- srcTexture->height());
+ matrix.setIDiv(srcTexture->width(), srcTexture->height());
this->setRenderTarget(dstTexture->asRenderTarget());
paint.colorSampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect,
- (srcTexture, true)))->unref();
+ (srcTexture, true)),
+ matrix)->unref();
SkRect dstRect(srcRect);
scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
this->drawRectToRect(paint, dstRect, srcRect);
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index da81a76..cc11f6c 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -54,7 +54,7 @@
fDrawState->setViewMatrix(fViewMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (fRestoreMask & (1 << s)) {
- *fDrawState->sampler(s)->matrix() = fSamplerMatrices[s];
+ fDrawState->sampler(s)->setMatrixDeprecated(fSamplerMatrices[s]);
}
}
}
@@ -77,6 +77,7 @@
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
fRestoreMask |= (1 << s);
+ fSamplerMatrices[s] = drawState->sampler(s)->getMatrix();
drawState->sampler(s)->preConcatMatrix(preconcatMatrix);
}
}
@@ -89,7 +90,7 @@
fDrawState->setViewMatrix(fViewMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (fRestoreMask & (1 << s)) {
- *fDrawState->sampler(s)->matrix() = fSamplerMatrices[s];
+ fDrawState->sampler(s)->setMatrixDeprecated(fSamplerMatrices[s]);
}
}
}
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 69f0aea..f3d5e37 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -42,8 +42,9 @@
*
* Stages 0 through GrPaint::kTotalStages-1 are reserved for setting up
* the draw (i.e., textures and filter masks). Stages GrPaint::kTotalStages
- * through kNumStages-1 are earmarked for use by GrTextContext and
- * GrPathRenderer-derived classes.
+ * through kNumStages-2 are earmarked for use by GrTextContext and
+ * GrPathRenderer-derived classes. kNumStages-1 is earmarked for clipping
+ * by GrClipMaskManager.
*/
enum {
kNumStages = 5,
@@ -194,10 +195,17 @@
this->sampler(stage)->setCustomStage(
SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
}
- void createTextureEffect(int stage, GrTexture* texture, const GrTextureParams& params) {
+ void createTextureEffect(int stage, GrTexture* texture, const GrMatrix& matrix) {
GrAssert(!this->getSampler(stage).getCustomStage());
- this->sampler(stage)->setCustomStage(
- SkNEW_ARGS(GrSingleTextureEffect, (texture, params)))->unref();
+ GrCustomStage* customStage = SkNEW_ARGS(GrSingleTextureEffect, (texture));
+ this->sampler(stage)->setCustomStage(customStage, matrix)->unref();
+ }
+ void createTextureEffect(int stage, GrTexture* texture,
+ const GrMatrix& matrix,
+ const GrTextureParams& params) {
+ GrAssert(!this->getSampler(stage).getCustomStage());
+ GrCustomStage* customStage = SkNEW_ARGS(GrSingleTextureEffect, (texture, params));
+ this->sampler(stage)->setCustomStage(customStage, matrix)->unref();
}
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index c9944b9..59b9cb3 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -19,7 +19,6 @@
#include "SkPath.h"
enum {
-
kGlyphMaskStage = GrPaint::kTotalStages,
};
@@ -35,7 +34,7 @@
GrAssert(GrIsALIGN4(fCurrVertex));
GrAssert(fCurrTexture);
GrTextureParams params(SkShader::kRepeat_TileMode, false);
- drawState->createTextureEffect(kGlyphMaskStage, fCurrTexture, params);
+ drawState->createTextureEffect(kGlyphMaskStage, fCurrTexture, GrMatrix::I(), params);
if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
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);
}