aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-31 18:09:01 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-31 18:09:01 +0000
commitf94b3a4cebd4adab09c40ebe23c02a615e10c394 (patch)
treea611a0cb0e1db232fbe5a1af0312eea05428dce1 /src/effects
parentc1f6db86dcf478d3c067bfc3fd99174b23d81732 (diff)
Make SkShader store localM directly rather than as a separate alloc.
May cause very slight GM changes in gpu two pt radial/conical radients. Review URL: https://codereview.appspot.com/6821056 git-svn-id: http://skia.googlecode.com/svn/trunk@6221 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/gradients/SkLinearGradient.cpp16
-rw-r--r--src/effects/gradients/SkRadialGradient.cpp14
-rw-r--r--src/effects/gradients/SkSweepGradient.cpp15
-rw-r--r--src/effects/gradients/SkTwoPointConicalGradient.cpp25
-rw-r--r--src/effects/gradients/SkTwoPointRadialGradient.cpp26
5 files changed, 34 insertions, 62 deletions
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 524db76966..d9576565b5 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -569,20 +569,12 @@ void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
bool SkLinearGradient::asNewEffect(GrContext* context, GrEffectStage* stage) const {
SkASSERT(NULL != context && NULL != stage);
-
- SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrLinearGradient, (context, *this, fTileMode)));
-
SkMatrix matrix;
- if (this->getLocalMatrix(&matrix)) {
- if (!matrix.invert(&matrix)) {
- return false;
- }
- matrix.postConcat(fPtsToUnit);
- stage->setEffect(effect, matrix);
- } else {
- stage->setEffect(effect, fPtsToUnit);
+ if (!this->getLocalMatrix().invert(&matrix)) {
+ return false;
}
-
+ matrix.postConcat(fPtsToUnit);
+ stage->setEffect(SkNEW_ARGS(GrLinearGradient, (context, *this, fTileMode)), matrix)->unref();
return true;
}
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 4766af604b..a20ea35a1a 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -567,19 +567,13 @@ void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
bool SkRadialGradient::asNewEffect(GrContext* context, GrEffectStage* stage) const {
SkASSERT(NULL != context && NULL != stage);
- SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrRadialGradient, (context, *this, fTileMode)));
SkMatrix matrix;
- if (this->getLocalMatrix(&matrix)) {
- if (!matrix.invert(&matrix)) {
- return false;
- }
- matrix.postConcat(fPtsToUnit);
- stage->setEffect(effect, matrix);
- } else {
- stage->setEffect(effect, fPtsToUnit);
+ if (!this->getLocalMatrix().invert(&matrix)) {
+ return false;
}
-
+ matrix.postConcat(fPtsToUnit);
+ stage->setEffect(SkNEW_ARGS(GrRadialGradient, (context, *this, fTileMode)), matrix)->unref();
return true;
}
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index b64e15d0c1..a783e3757c 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -473,19 +473,12 @@ void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
/////////////////////////////////////////////////////////////////////
bool SkSweepGradient::asNewEffect(GrContext* context, GrEffectStage* stage) const {
- SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSweepGradient, (context, *this)));
-
SkMatrix matrix;
- if (this->getLocalMatrix(&matrix)) {
- if (!matrix.invert(&matrix)) {
- return false;
- }
- matrix.postConcat(fPtsToUnit);
- stage->setEffect(effect, matrix);
- } else {
- stage->setEffect(effect, fPtsToUnit);
+ if (!this->getLocalMatrix().invert(&matrix)) {
+ return false;
}
-
+ matrix.postConcat(fPtsToUnit);
+ stage->setEffect(SkNEW_ARGS(GrSweepGradient, (context, *this)), matrix)->unref();
return true;
}
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index acd0eeedfb..f93f660837 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -677,25 +677,22 @@ GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrEffectStage& s, const
bool SkTwoPointConicalGradient::asNewEffect(GrContext* context,
GrEffectStage* stage) const {
SkASSERT(NULL != context && NULL != stage);
-
+ SkASSERT(fPtsToUnit.isIdentity());
+ // invert the localM, translate to center1, rotate so center2 is on x axis.
SkMatrix matrix;
+ if (!this->getLocalMatrix().invert(&matrix)) {
+ return false;
+ }
+ matrix.postTranslate(-fCenter1.fX, -fCenter1.fY);
+
SkPoint diff = fCenter2 - fCenter1;
SkScalar diffLen = diff.length();
if (0 != diffLen) {
SkScalar invDiffLen = SkScalarInvert(diffLen);
- matrix.setSinCos(-SkScalarMul(invDiffLen, diff.fY),
- SkScalarMul(invDiffLen, diff.fX));
- } else {
- matrix.reset();
- }
- matrix.preTranslate(-fCenter1.fX, -fCenter1.fY);
-
- SkMatrix localM;
- if (this->getLocalMatrix(&localM)) {
- if (!localM.invert(&localM)) {
- return false;
- }
- matrix.preConcat(localM);
+ SkMatrix rot;
+ rot.setSinCos(-SkScalarMul(invDiffLen, diff.fY),
+ SkScalarMul(invDiffLen, diff.fX));
+ matrix.postConcat(rot);
}
stage->setEffect(SkNEW_ARGS(GrConical2Gradient, (context, *this, fTileMode)), matrix)->unref();
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp
index 9357b11685..659bce0099 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.cpp
+++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp
@@ -651,24 +651,20 @@ GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrEffectStage& s, const
bool SkTwoPointRadialGradient::asNewEffect(GrContext* context,
GrEffectStage* stage) const {
SkASSERT(NULL != context && NULL != stage);
- SkScalar diffLen = fDiff.length();
+ // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is on x axis.
SkMatrix matrix;
- if (0 != diffLen) {
- SkScalar invDiffLen = SkScalarInvert(diffLen);
- matrix.setSinCos(-SkScalarMul(invDiffLen, fDiff.fY),
- SkScalarMul(invDiffLen, fDiff.fX));
- } else {
- matrix.reset();
+ if (!this->getLocalMatrix().invert(&matrix)) {
+ return false;
}
+ matrix.postConcat(fPtsToUnit);
- matrix.preConcat(fPtsToUnit);
-
- SkMatrix localM;
- if (this->getLocalMatrix(&localM)) {
- if (!localM.invert(&localM)) {
- return false;
- }
- matrix.preConcat(localM);
+ SkScalar diffLen = fDiff.length();
+ if (0 != diffLen) {
+ SkScalar invDiffLen = SkScalarInvert(diffLen);
+ SkMatrix rot;
+ rot.setSinCos(-SkScalarMul(invDiffLen, fDiff.fY),
+ SkScalarMul(invDiffLen, fDiff.fX));
+ matrix.postConcat(rot);
}
stage->setEffect(SkNEW_ARGS(GrRadial2Gradient, (context, *this, fTileMode)), matrix)->unref();