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/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index f18b08e..9fb5176 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -444,9 +444,11 @@
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, center.fY,
colors, stops, colorCount));
GrSamplerState sampler;
- GrCustomStage* stage = shader->asNewCustomStage(context, &sampler);
- GrAssert(NULL != stage);
- return stage;
+ shader->asNewCustomStage(context, &sampler);
+ GrAssert(NULL != sampler.getCustomStage());
+ // const_cast and ref is a hack! Will remove when asNewCustomStage returns GrCustomStage*
+ sampler.getCustomStage()->ref();
+ return const_cast<GrCustomStage*>(sampler.getCustomStage());
}
/////////////////////////////////////////////////////////////////////
@@ -463,18 +465,29 @@
/////////////////////////////////////////////////////////////////////
-GrCustomStage* SkSweepGradient::asNewCustomStage(GrContext* context,
- GrSamplerState* sampler) const {
- sampler->matrix()->preConcat(fPtsToUnit);
- return SkNEW_ARGS(GrSweepGradient, (context, *this));
+bool SkSweepGradient::asNewCustomStage(GrContext* context, GrSamplerState* sampler) const {
+ SkAutoTUnref<GrCustomStage> stage(SkNEW_ARGS(GrSweepGradient, (context, *this)));
+
+
+ SkMatrix matrix;
+ if (this->getLocalMatrix(&matrix)) {
+ if (!matrix.invert(&matrix)) {
+ return false;
+ }
+ matrix.postConcat(fPtsToUnit);
+ sampler->setCustomStage(stage, matrix);
+ } else {
+ sampler->setCustomStage(stage, fPtsToUnit);
+ }
+
+ return true;
}
#else
-GrCustomStage* SkSweepGradient::asNewCustomStage(GrContext* context,
- GrSamplerState* sampler) const {
+bool SkSweepGradient::asNewCustomStage(GrContext*, GrSamplerState*) const {
SkDEBUGFAIL("Should not call in GPU-less build");
- return NULL;
+ return false;
}
#endif