Require matrix for custom stage to be set when custom stage is installed.
Review URL: https://codereview.appspot.com/6696044
git-svn-id: http://skia.googlecode.com/svn/trunk@5962 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index f18b08e..d8cbf9c 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -444,9 +444,10 @@
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*
+ return const_cast<GrCustomStage*>(sampler.getCustomStage());
}
/////////////////////////////////////////////////////////////////////
@@ -463,18 +464,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