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/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 512eafb..0156acd 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -538,9 +538,11 @@
colors, stops, colorCount,
tm));
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());
}
/////////////////////////////////////////////////////////////////////
@@ -556,19 +558,29 @@
/////////////////////////////////////////////////////////////////////
-GrCustomStage* SkRadialGradient::asNewCustomStage(GrContext* context,
- GrSamplerState* sampler) const {
+bool SkRadialGradient::asNewCustomStage(GrContext* context, GrSamplerState* sampler) const {
SkASSERT(NULL != context && NULL != sampler);
- sampler->matrix()->preConcat(fPtsToUnit);
- return SkNEW_ARGS(GrRadialGradient, (context, *this, fTileMode));
+ SkAutoTUnref<GrCustomStage> stage(SkNEW_ARGS(GrRadialGradient, (context, *this, fTileMode)));
+
+ 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* SkRadialGradient::asNewCustomStage(GrContext* context,
- GrSamplerState* sampler) const {
+bool SkRadialGradient::asNewCustomStage(GrContext*, GrSamplerState*) const {
SkDEBUGFAIL("Should not call in GPU-less build");
- return NULL;
+ return false;
}
#endif