diff options
author | rileya@google.com <rileya@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-31 20:38:06 +0000 |
---|---|---|
committer | rileya@google.com <rileya@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-31 20:38:06 +0000 |
commit | 98e8b6de04e4c20451fbe3353645e3e384a76550 (patch) | |
tree | 9624d661efd1ee633ce4d28f1e762ef625c6cf71 /src/effects | |
parent | c41149e6d8b587bb851f9a0d9b2f7bec7f9596c4 (diff) |
Remove old constructors from GrGradientEffect subclasses, and moved their declarations into source files.
Review URL: https://codereview.appspot.com/6449067
git-svn-id: http://skia.googlecode.com/svn/trunk@4870 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/gradients/SkGradientShader.cpp | 6 | ||||
-rw-r--r-- | src/effects/gradients/SkGradientShaderPriv.h | 3 | ||||
-rw-r--r-- | src/effects/gradients/SkLinearGradient.cpp | 58 | ||||
-rw-r--r-- | src/effects/gradients/SkLinearGradient.h | 24 | ||||
-rw-r--r-- | src/effects/gradients/SkRadialGradient.cpp | 67 | ||||
-rw-r--r-- | src/effects/gradients/SkRadialGradient.h | 23 | ||||
-rw-r--r-- | src/effects/gradients/SkSweepGradient.cpp | 59 | ||||
-rw-r--r-- | src/effects/gradients/SkSweepGradient.h | 23 | ||||
-rw-r--r-- | src/effects/gradients/SkTwoPointConicalGradient.cpp | 133 | ||||
-rw-r--r-- | src/effects/gradients/SkTwoPointConicalGradient.h | 40 | ||||
-rw-r--r-- | src/effects/gradients/SkTwoPointRadialGradient.cpp | 129 | ||||
-rw-r--r-- | src/effects/gradients/SkTwoPointRadialGradient.h | 40 |
12 files changed, 247 insertions, 358 deletions
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index f0eb7fb583..0dfb186e75 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -689,12 +689,6 @@ void GrGLGradientStage::emitColorLookup(GrGLShaderBuilder* builder, ///////////////////////////////////////////////////////////////////// -GrGradientEffect::GrGradientEffect(GrTexture* texture) - : fTexture (texture) - , fUseTexture(true) { - SkSafeRef(fTexture); -} - GrGradientEffect::GrGradientEffect(GrContext* ctx, const SkGradientShaderBase& shader, GrSamplerState* sampler) diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h index 93b8c8358f..af15ecdff3 100644 --- a/src/effects/gradients/SkGradientShaderPriv.h +++ b/src/effects/gradients/SkGradientShaderPriv.h @@ -222,9 +222,6 @@ class GrProgramStageFactory; class GrGradientEffect : public GrCustomStage { public: - // FIXME: This constructor is only used in GrGpuGL_unittest.cpp, and should - // be removed once an alternative testing setup has been devised. - GrGradientEffect(GrTexture* texture); GrGradientEffect(GrContext* ctx, const SkGradientShaderBase& shader, GrSamplerState* sampler); diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index 49e93459f2..9d4ee6dddf 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -312,16 +312,6 @@ SkShader::GradientType SkLinearGradient::asAGradient(GradientInfo* info) const { return kLinear_GradientType; } -GrCustomStage* SkLinearGradient::asNewCustomStage(GrContext* context, - GrSamplerState* sampler) const { - SkASSERT(NULL != context && NULL != sampler); - sampler->matrix()->preConcat(fPtsToUnit); - sampler->textureParams()->setTileModeX(fTileMode); - sampler->textureParams()->setTileModeY(kClamp_TileMode); - sampler->textureParams()->setBilerp(true); - return SkNEW_ARGS(GrLinearGradient, (context, *this, sampler)); -} - static void dither_memset16(uint16_t dst[], uint16_t value, uint16_t other, int count) { if (reinterpret_cast<uintptr_t>(dst) & 2) { @@ -506,6 +496,30 @@ private: typedef GrGLGradientStage INHERITED; }; +///////////////////////////////////////////////////////////////////// + +class GrLinearGradient : public GrGradientEffect { +public: + + GrLinearGradient(GrContext* ctx, const SkLinearGradient& shader, + GrSamplerState* sampler) + : INHERITED(ctx, shader, sampler) { } + virtual ~GrLinearGradient() { } + + static const char* Name() { return "Linear Gradient"; } + const GrProgramStageFactory& getFactory() const SK_OVERRIDE { + return GrTProgramStageFactory<GrLinearGradient>::getInstance(); + } + + typedef GrGLLinearGradient GLProgramStage; + +private: + + typedef GrGradientEffect INHERITED; +}; + +///////////////////////////////////////////////////////////////////// + void GrGLLinearGradient::emitFS(GrGLShaderBuilder* builder, const char* outputColor, const char* inputColor, @@ -517,21 +531,13 @@ void GrGLLinearGradient::emitFS(GrGLShaderBuilder* builder, ///////////////////////////////////////////////////////////////////// -GrLinearGradient::GrLinearGradient(GrTexture* texture) - : INHERITED(texture) { -} - -GrLinearGradient::GrLinearGradient(GrContext* ctx, - const SkLinearGradient& shader, - GrSamplerState* sampler) - : INHERITED(ctx, shader, sampler) { -} - -GrLinearGradient::~GrLinearGradient() { - -} - -const GrProgramStageFactory& GrLinearGradient::getFactory() const { - return GrTProgramStageFactory<GrLinearGradient>::getInstance(); +GrCustomStage* SkLinearGradient::asNewCustomStage(GrContext* context, + GrSamplerState* sampler) const { + SkASSERT(NULL != context && NULL != sampler); + sampler->matrix()->preConcat(fPtsToUnit); + sampler->textureParams()->setTileModeX(fTileMode); + sampler->textureParams()->setTileModeY(kClamp_TileMode); + sampler->textureParams()->setBilerp(true); + return SkNEW_ARGS(GrLinearGradient, (context, *this, sampler)); } diff --git a/src/effects/gradients/SkLinearGradient.h b/src/effects/gradients/SkLinearGradient.h index c4b1b4672d..705c37c348 100644 --- a/src/effects/gradients/SkLinearGradient.h +++ b/src/effects/gradients/SkLinearGradient.h @@ -37,29 +37,5 @@ private: const SkPoint fEnd; }; -/////////////////////////////////////////////////////////////////////////////// - -class GrGLLinearGradient; - -class GrLinearGradient : public GrGradientEffect { - -public: - - GrLinearGradient(GrTexture* texture); - GrLinearGradient(GrContext* ctx, const SkLinearGradient& shader, - GrSamplerState* sampler); - virtual ~GrLinearGradient(); - - static const char* Name() { return "Linear Gradient"; } - virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; - - typedef GrGLLinearGradient GLProgramStage; - -private: - - typedef GrGradientEffect INHERITED; -}; - - #endif diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp index 3a0583bf01..be2e46f0ca 100644 --- a/src/effects/gradients/SkRadialGradient.cpp +++ b/src/effects/gradients/SkRadialGradient.cpp @@ -150,6 +150,8 @@ void shadeSpan16_radial_repeat(SkScalar sfx, SkScalar sdx, } +///////////////////////////////////////////////////////////////////// + SkRadialGradient::SkRadialGradient(const SkPoint& center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int colorCount, SkShader::TileMode mode, SkUnitMapper* mapper) @@ -245,16 +247,6 @@ SkShader::GradientType SkRadialGradient::asAGradient(GradientInfo* info) const { return kRadial_GradientType; } -GrCustomStage* SkRadialGradient::asNewCustomStage(GrContext* context, - GrSamplerState* sampler) const { - SkASSERT(NULL != context && NULL != sampler); - sampler->matrix()->preConcat(fPtsToUnit); - sampler->textureParams()->setTileModeX(fTileMode); - sampler->textureParams()->setTileModeY(kClamp_TileMode); - sampler->textureParams()->setBilerp(true); - return SkNEW_ARGS(GrRadialGradient, (context, *this, sampler)); -} - SkRadialGradient::SkRadialGradient(SkFlattenableReadBuffer& buffer) : INHERITED(buffer), fCenter(buffer.readPoint()), @@ -480,7 +472,6 @@ void SkRadialGradient::shadeSpan(int x, int y, ///////////////////////////////////////////////////////////////////// class GrGLRadialGradient : public GrGLGradientStage { - public: GrGLRadialGradient(const GrProgramStageFactory& factory, @@ -502,6 +493,33 @@ private: }; +///////////////////////////////////////////////////////////////////// + +class GrRadialGradient : public GrGradientEffect { +public: + + GrRadialGradient(GrContext* ctx, + const SkRadialGradient& shader, + GrSamplerState* sampler) + : INHERITED(ctx, shader, sampler) { + } + + virtual ~GrRadialGradient() { } + + static const char* Name() { return "Radial Gradient"; } + virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE { + return GrTProgramStageFactory<GrRadialGradient>::getInstance(); + } + + typedef GrGLRadialGradient GLProgramStage; + +private: + + typedef GrGradientEffect INHERITED; +}; + +///////////////////////////////////////////////////////////////////// + void GrGLRadialGradient::emitFS(GrGLShaderBuilder* builder, const char* outputColor, const char* inputColor, @@ -511,26 +529,15 @@ void GrGLRadialGradient::emitFS(GrGLShaderBuilder* builder, this->emitColorLookup(builder, t.c_str(), outputColor, samplerName); } - ///////////////////////////////////////////////////////////////////// - -GrRadialGradient::GrRadialGradient(GrTexture* texture) - : INHERITED(texture) { - -} - -GrRadialGradient::GrRadialGradient(GrContext* ctx, - const SkRadialGradient& shader, - GrSamplerState* sampler) - : INHERITED(ctx, shader, sampler) { -} - -GrRadialGradient::~GrRadialGradient() { - -} - -const GrProgramStageFactory& GrRadialGradient::getFactory() const { - return GrTProgramStageFactory<GrRadialGradient>::getInstance(); +GrCustomStage* SkRadialGradient::asNewCustomStage(GrContext* context, + GrSamplerState* sampler) const { + SkASSERT(NULL != context && NULL != sampler); + sampler->matrix()->preConcat(fPtsToUnit); + sampler->textureParams()->setTileModeX(fTileMode); + sampler->textureParams()->setTileModeY(kClamp_TileMode); + sampler->textureParams()->setBilerp(true); + return SkNEW_ARGS(GrRadialGradient, (context, *this, sampler)); } diff --git a/src/effects/gradients/SkRadialGradient.h b/src/effects/gradients/SkRadialGradient.h index 0b7e30c2d4..23a35f7fd2 100644 --- a/src/effects/gradients/SkRadialGradient.h +++ b/src/effects/gradients/SkRadialGradient.h @@ -39,28 +39,5 @@ private: const SkScalar fRadius; }; -/////////////////////////////////////////////////////////////////////////////// - -class GrGLRadialGradient; - -class GrRadialGradient : public GrGradientEffect { - -public: - - GrRadialGradient(GrTexture* texture); - GrRadialGradient(GrContext* ctx, const SkRadialGradient& shader, - GrSamplerState* sampler); - virtual ~GrRadialGradient(); - - static const char* Name() { return "Radial Gradient"; } - virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; - - typedef GrGLRadialGradient GLProgramStage; - -private: - - typedef GrGradientEffect INHERITED; -}; - #endif diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp index 963485cdf1..b4e013a0a1 100644 --- a/src/effects/gradients/SkSweepGradient.cpp +++ b/src/effects/gradients/SkSweepGradient.cpp @@ -39,15 +39,6 @@ SkShader::GradientType SkSweepGradient::asAGradient(GradientInfo* info) const { return kSweep_GradientType; } -GrCustomStage* SkSweepGradient::asNewCustomStage(GrContext* context, - GrSamplerState* sampler) const { - sampler->matrix()->preConcat(fPtsToUnit); - sampler->textureParams()->setTileModeX(fTileMode); - sampler->textureParams()->setTileModeY(kClamp_TileMode); - sampler->textureParams()->setBilerp(true); - return SkNEW_ARGS(GrSweepGradient, (context, *this, sampler)); -} - SkSweepGradient::SkSweepGradient(SkFlattenableReadBuffer& buffer) : INHERITED(buffer), fCenter(buffer.readPoint()) { @@ -390,7 +381,6 @@ void SkSweepGradient::shadeSpan16(int x, int y, uint16_t* SK_RESTRICT dstC, ///////////////////////////////////////////////////////////////////// class GrGLSweepGradient : public GrGLGradientStage { - public: GrGLSweepGradient(const GrProgramStageFactory& factory, @@ -412,6 +402,31 @@ private: }; +///////////////////////////////////////////////////////////////////// + +class GrSweepGradient : public GrGradientEffect { +public: + + GrSweepGradient(GrContext* ctx, + const SkSweepGradient& shader, + GrSamplerState* sampler) + : INHERITED(ctx, shader, sampler) { } + virtual ~GrSweepGradient() { } + + static const char* Name() { return "Sweep Gradient"; } + virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE { + return GrTProgramStageFactory<GrSweepGradient>::getInstance(); + } + + typedef GrGLSweepGradient GLProgramStage; + +protected: + + typedef GrGradientEffect INHERITED; +}; + +///////////////////////////////////////////////////////////////////// + void GrGLSweepGradient::emitFS(GrGLShaderBuilder* builder, const char* outputColor, const char* inputColor, @@ -424,22 +439,12 @@ void GrGLSweepGradient::emitFS(GrGLShaderBuilder* builder, ///////////////////////////////////////////////////////////////////// -GrSweepGradient::GrSweepGradient(GrTexture* texture) - : INHERITED(texture) { - -} - -GrSweepGradient::GrSweepGradient(GrContext* ctx, - const SkSweepGradient& shader, - GrSamplerState* sampler) - : INHERITED(ctx, shader, sampler) { -} - -GrSweepGradient::~GrSweepGradient() { - -} - -const GrProgramStageFactory& GrSweepGradient::getFactory() const { - return GrTProgramStageFactory<GrSweepGradient>::getInstance(); +GrCustomStage* SkSweepGradient::asNewCustomStage(GrContext* context, + GrSamplerState* sampler) const { + sampler->matrix()->preConcat(fPtsToUnit); + sampler->textureParams()->setTileModeX(fTileMode); + sampler->textureParams()->setTileModeY(kClamp_TileMode); + sampler->textureParams()->setBilerp(true); + return SkNEW_ARGS(GrSweepGradient, (context, *this, sampler)); } diff --git a/src/effects/gradients/SkSweepGradient.h b/src/effects/gradients/SkSweepGradient.h index 9a6c4eee6d..2b9dfeb675 100644 --- a/src/effects/gradients/SkSweepGradient.h +++ b/src/effects/gradients/SkSweepGradient.h @@ -38,28 +38,5 @@ private: const SkPoint fCenter; }; -/////////////////////////////////////////////////////////////////////////////// - -class GrGLSweepGradient; - -class GrSweepGradient : public GrGradientEffect { - -public: - - GrSweepGradient(GrTexture* texture); - GrSweepGradient(GrContext* ctx, const SkSweepGradient& shader, - GrSamplerState* sampler); - virtual ~GrSweepGradient(); - - static const char* Name() { return "Sweep Gradient"; } - virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; - - typedef GrGLSweepGradient GLProgramStage; - -protected: - - typedef GrGradientEffect INHERITED; -}; - #endif diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index feef3b9e1e..ae20caeb50 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -163,6 +163,8 @@ void SkTwoPointConicalGradient::init() { fPtsToUnit.reset(); } +///////////////////////////////////////////////////////////////////// + SkTwoPointConicalGradient::SkTwoPointConicalGradient( const SkPoint& start, SkScalar startRadius, const SkPoint& end, SkScalar endRadius, @@ -292,25 +294,6 @@ SkShader::GradientType SkTwoPointConicalGradient::asAGradient( return kConical_GradientType; } -GrCustomStage* SkTwoPointConicalGradient::asNewCustomStage( - GrContext* context, GrSamplerState* sampler) const { - SkASSERT(NULL != context && NULL != sampler); - SkPoint diff = fCenter2 - fCenter1; - SkScalar diffLen = diff.length(); - if (0 != diffLen) { - SkScalar invDiffLen = SkScalarInvert(diffLen); - sampler->matrix()->setSinCos(-SkScalarMul(invDiffLen, diff.fY), - SkScalarMul(invDiffLen, diff.fX)); - } else { - sampler->matrix()->reset(); - } - sampler->matrix()->preTranslate(-fCenter1.fX, -fCenter1.fY); - sampler->textureParams()->setTileModeX(fTileMode); - sampler->textureParams()->setTileModeY(kClamp_TileMode); - sampler->textureParams()->setBilerp(true); - return SkNEW_ARGS(GrConical2Gradient, (context, *this, sampler)); -} - SkTwoPointConicalGradient::SkTwoPointConicalGradient( SkFlattenableReadBuffer& buffer) : INHERITED(buffer), @@ -337,7 +320,6 @@ typedef GrGLUniformManager::UniformHandle UniformHandle; static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle; class GrGLConical2Gradient : public GrGLGradientStage { - public: GrGLConical2Gradient(const GrProgramStageFactory& factory, @@ -356,9 +338,7 @@ public: const GrRenderTarget*, int stageNum) SK_OVERRIDE; - static StageKey GenKey(const GrCustomStage& s) { - return (static_cast<const GrConical2Gradient&>(s).isDegenerate()); - } + static StageKey GenKey(const GrCustomStage& s); protected: @@ -385,6 +365,57 @@ private: }; +///////////////////////////////////////////////////////////////////// + +class GrConical2Gradient : public GrGradientEffect { +public: + + GrConical2Gradient(GrContext* ctx, const SkTwoPointConicalGradient& shader, + GrSamplerState* sampler) + : INHERITED(ctx, shader, sampler) + , fCenterX1(shader.getCenterX1()) + , fRadius0(shader.getStartRadius()) + , fDiffRadius(shader.getDiffRadius()) { } + + virtual ~GrConical2Gradient() { } + + static const char* Name() { return "Two-Point Conical Gradient"; } + virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE { + return GrTProgramStageFactory<GrConical2Gradient>::getInstance(); + } + virtual bool isEqual(const GrCustomStage& sBase) const SK_OVERRIDE { + const GrConical2Gradient& s = static_cast<const GrConical2Gradient&>(sBase); + return (INHERITED::isEqual(sBase) && + this->fCenterX1 == s.fCenterX1 && + this->fRadius0 == s.fRadius0 && + this->fDiffRadius == s.fDiffRadius); + } + + // The radial gradient parameters can collapse to a linear (instead of quadratic) equation. + bool isDegenerate() const { return SkScalarAbs(fDiffRadius) == SkScalarAbs(fCenterX1); } + GrScalar center() const { return fCenterX1; } + GrScalar diffRadius() const { return fDiffRadius; } + GrScalar radius() const { return fRadius0; } + + typedef GrGLConical2Gradient GLProgramStage; + +private: + + // @{ + // Cache of values - these can change arbitrarily, EXCEPT + // we shouldn't change between degenerate and non-degenerate?! + + GrScalar fCenterX1; + GrScalar fRadius0; + GrScalar fDiffRadius; + + // @} + + typedef GrGradientEffect INHERITED; +}; + +///////////////////////////////////////////////////////////////////// + GrGLConical2Gradient::GrGLConical2Gradient( const GrProgramStageFactory& factory, const GrCustomStage& baseData) @@ -603,44 +634,28 @@ void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, } } - -///////////////////////////////////////////////////////////////////// - -GrConical2Gradient::GrConical2Gradient(GrTexture* texture, - GrScalar center, - GrScalar radius, - GrScalar diffRadius) - : INHERITED(texture) - , fCenterX1 (center) - , fRadius0 (radius) - , fDiffRadius (diffRadius) { - -} - -GrConical2Gradient::GrConical2Gradient(GrContext* ctx, - const SkTwoPointConicalGradient& shader, - GrSamplerState* sampler) - : INHERITED(ctx, shader, sampler) - , fCenterX1(shader.getCenterX1()) - , fRadius0(shader.getStartRadius()) - , fDiffRadius(shader.getDiffRadius()) { +GrCustomStage::StageKey GrGLConical2Gradient::GenKey(const GrCustomStage& s) { + return (static_cast<const GrConical2Gradient&>(s).isDegenerate()); } -GrConical2Gradient::~GrConical2Gradient() { - -} - - -const GrProgramStageFactory& GrConical2Gradient::getFactory() const { - return GrTProgramStageFactory<GrConical2Gradient>::getInstance(); -} +///////////////////////////////////////////////////////////////////// -bool GrConical2Gradient::isEqual(const GrCustomStage& sBase) const { - const GrConical2Gradient& s = static_cast<const GrConical2Gradient&>(sBase); - return (INHERITED::isEqual(sBase) && - this->fCenterX1 == s.fCenterX1 && - this->fRadius0 == s.fRadius0 && - this->fDiffRadius == s.fDiffRadius); +GrCustomStage* SkTwoPointConicalGradient::asNewCustomStage( + GrContext* context, GrSamplerState* sampler) const { + SkASSERT(NULL != context && NULL != sampler); + SkPoint diff = fCenter2 - fCenter1; + SkScalar diffLen = diff.length(); + if (0 != diffLen) { + SkScalar invDiffLen = SkScalarInvert(diffLen); + sampler->matrix()->setSinCos(-SkScalarMul(invDiffLen, diff.fY), + SkScalarMul(invDiffLen, diff.fX)); + } else { + sampler->matrix()->reset(); + } + sampler->matrix()->preTranslate(-fCenter1.fX, -fCenter1.fY); + sampler->textureParams()->setTileModeX(fTileMode); + sampler->textureParams()->setTileModeY(kClamp_TileMode); + sampler->textureParams()->setBilerp(true); + return SkNEW_ARGS(GrConical2Gradient, (context, *this, sampler)); } - diff --git a/src/effects/gradients/SkTwoPointConicalGradient.h b/src/effects/gradients/SkTwoPointConicalGradient.h index 733ae522c9..45ed15b8b1 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.h +++ b/src/effects/gradients/SkTwoPointConicalGradient.h @@ -82,45 +82,5 @@ private: const SkScalar fRadius2; }; -/////////////////////////////////////////////////////////////////////////////// - -class GrGLConical2Gradient; - -class GrConical2Gradient : public GrGradientEffect { - -public: - - GrConical2Gradient(GrTexture* texture, GrScalar center, GrScalar radius, GrScalar diffRadius); - GrConical2Gradient(GrContext* ctx, const SkTwoPointConicalGradient& shader, - GrSamplerState* sampler); - virtual ~GrConical2Gradient(); - - static const char* Name() { return "Two-Point Conical Gradient"; } - virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; - virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE; - - // The radial gradient parameters can collapse to a linear (instead of quadratic) equation. - bool isDegenerate() const { return SkScalarAbs(fDiffRadius) == SkScalarAbs(fCenterX1); } - GrScalar center() const { return fCenterX1; } - GrScalar diffRadius() const { return fDiffRadius; } - GrScalar radius() const { return fRadius0; } - - typedef GrGLConical2Gradient GLProgramStage; - -private: - - // @{ - // Cache of values - these can change arbitrarily, EXCEPT - // we shouldn't change between degenerate and non-degenerate?! - - GrScalar fCenterX1; - GrScalar fRadius0; - GrScalar fDiffRadius; - - // @} - - typedef GrGradientEffect INHERITED; -}; - #endif diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp index ed21d75180..582c435bf2 100644 --- a/src/effects/gradients/SkTwoPointRadialGradient.cpp +++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp @@ -165,6 +165,8 @@ void shadeSpan_twopoint_repeat(SkScalar fx, SkScalar dx, } } +///////////////////////////////////////////////////////////////////// + SkTwoPointRadialGradient::SkTwoPointRadialGradient( const SkPoint& start, SkScalar startRadius, const SkPoint& end, SkScalar endRadius, @@ -220,24 +222,6 @@ SkShader::GradientType SkTwoPointRadialGradient::asAGradient( return kRadial2_GradientType; } -GrCustomStage* SkTwoPointRadialGradient::asNewCustomStage( - GrContext* context, GrSamplerState* sampler) const { - SkASSERT(NULL != context && NULL != sampler); - SkScalar diffLen = fDiff.length(); - if (0 != diffLen) { - SkScalar invDiffLen = SkScalarInvert(diffLen); - sampler->matrix()->setSinCos(-SkScalarMul(invDiffLen, fDiff.fY), - SkScalarMul(invDiffLen, fDiff.fX)); - } else { - sampler->matrix()->reset(); - } - sampler->matrix()->preConcat(fPtsToUnit); - sampler->textureParams()->setTileModeX(fTileMode); - sampler->textureParams()->setTileModeY(kClamp_TileMode); - sampler->textureParams()->setBilerp(true); - return SkNEW_ARGS(GrRadial2Gradient, (context, *this, sampler)); -} - void SkTwoPointRadialGradient::shadeSpan(int x, int y, SkPMColor* dstCParam, int count) { SkASSERT(count > 0); @@ -387,9 +371,7 @@ public: const GrRenderTarget*, int stageNum) SK_OVERRIDE; - static StageKey GenKey(const GrCustomStage& s) { - return (static_cast<const GrRadial2Gradient&>(s).isDegenerate()); - } + static StageKey GenKey(const GrCustomStage& s); protected: @@ -416,6 +398,56 @@ private: }; +///////////////////////////////////////////////////////////////////// + +class GrRadial2Gradient : public GrGradientEffect { +public: + + GrRadial2Gradient(GrContext* ctx, const SkTwoPointRadialGradient& shader, + GrSamplerState* sampler) + : INHERITED(ctx, shader, sampler) + , fCenterX1(shader.getCenterX1()) + , fRadius0(shader.getStartRadius()) + , fPosRoot(shader.getDiffRadius() < 0) { } + virtual ~GrRadial2Gradient() { } + + static const char* Name() { return "Two-Point Radial Gradient"; } + virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE { + return GrTProgramStageFactory<GrRadial2Gradient>::getInstance(); + } + virtual bool isEqual(const GrCustomStage& sBase) const SK_OVERRIDE { + const GrRadial2Gradient& s = static_cast<const GrRadial2Gradient&>(sBase); + return (INHERITED::isEqual(sBase) && + this->fCenterX1 == s.fCenterX1 && + this->fRadius0 == s.fRadius0 && + this->fPosRoot == s.fPosRoot); + } + + // The radial gradient parameters can collapse to a linear (instead of quadratic) equation. + bool isDegenerate() const { return GR_Scalar1 == fCenterX1; } + GrScalar center() const { return fCenterX1; } + GrScalar radius() const { return fRadius0; } + bool isPosRoot() const { return SkToBool(fPosRoot); } + + typedef GrGLRadial2Gradient GLProgramStage; + +private: + + // @{ + // Cache of values - these can change arbitrarily, EXCEPT + // we shouldn't change between degenerate and non-degenerate?! + + GrScalar fCenterX1; + GrScalar fRadius0; + SkBool8 fPosRoot; + + // @} + + typedef GrGradientEffect INHERITED; +}; + +///////////////////////////////////////////////////////////////////// + GrGLRadial2Gradient::GrGLRadial2Gradient( const GrProgramStageFactory& factory, const GrCustomStage& baseData) @@ -574,44 +606,27 @@ void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, } } - -///////////////////////////////////////////////////////////////////// - -GrRadial2Gradient::GrRadial2Gradient(GrTexture* texture, - GrScalar center, - GrScalar radius, - bool posRoot) - : INHERITED(texture) - , fCenterX1 (center) - , fRadius0 (radius) - , fPosRoot (posRoot) { - -} - -GrRadial2Gradient::GrRadial2Gradient(GrContext* ctx, - const SkTwoPointRadialGradient& shader, - GrSamplerState* sampler) - : INHERITED(ctx, shader, sampler) - , fCenterX1(shader.getCenterX1()) - , fRadius0(shader.getStartRadius()) - , fPosRoot(shader.getDiffRadius() < 0) { +GrCustomStage::StageKey GrGLRadial2Gradient::GenKey(const GrCustomStage& s) { + return (static_cast<const GrRadial2Gradient&>(s).isDegenerate()); } +///////////////////////////////////////////////////////////////////// -GrRadial2Gradient::~GrRadial2Gradient() { - -} - - -const GrProgramStageFactory& GrRadial2Gradient::getFactory() const { - return GrTProgramStageFactory<GrRadial2Gradient>::getInstance(); -} - -bool GrRadial2Gradient::isEqual(const GrCustomStage& sBase) const { - const GrRadial2Gradient& s = static_cast<const GrRadial2Gradient&>(sBase); - return (INHERITED::isEqual(sBase) && - this->fCenterX1 == s.fCenterX1 && - this->fRadius0 == s.fRadius0 && - this->fPosRoot == s.fPosRoot); +GrCustomStage* SkTwoPointRadialGradient::asNewCustomStage( + GrContext* context, GrSamplerState* sampler) const { + SkASSERT(NULL != context && NULL != sampler); + SkScalar diffLen = fDiff.length(); + if (0 != diffLen) { + SkScalar invDiffLen = SkScalarInvert(diffLen); + sampler->matrix()->setSinCos(-SkScalarMul(invDiffLen, fDiff.fY), + SkScalarMul(invDiffLen, fDiff.fX)); + } else { + sampler->matrix()->reset(); + } + sampler->matrix()->preConcat(fPtsToUnit); + sampler->textureParams()->setTileModeX(fTileMode); + sampler->textureParams()->setTileModeY(kClamp_TileMode); + sampler->textureParams()->setBilerp(true); + return SkNEW_ARGS(GrRadial2Gradient, (context, *this, sampler)); } diff --git a/src/effects/gradients/SkTwoPointRadialGradient.h b/src/effects/gradients/SkTwoPointRadialGradient.h index bf94c3cc14..a6036f176f 100644 --- a/src/effects/gradients/SkTwoPointRadialGradient.h +++ b/src/effects/gradients/SkTwoPointRadialGradient.h @@ -54,45 +54,5 @@ private: void init(); }; -/////////////////////////////////////////////////////////////////////////////// - -class GrGLRadial2Gradient; - -class GrRadial2Gradient : public GrGradientEffect { - -public: - - GrRadial2Gradient(GrTexture* texture, GrScalar center, GrScalar radius, bool posRoot); - GrRadial2Gradient(GrContext* ctx, const SkTwoPointRadialGradient& shader, - GrSamplerState* sampler); - virtual ~GrRadial2Gradient(); - - static const char* Name() { return "Two-Point Radial Gradient"; } - virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; - virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE; - - // The radial gradient parameters can collapse to a linear (instead of quadratic) equation. - bool isDegenerate() const { return GR_Scalar1 == fCenterX1; } - GrScalar center() const { return fCenterX1; } - GrScalar radius() const { return fRadius0; } - bool isPosRoot() const { return SkToBool(fPosRoot); } - - typedef GrGLRadial2Gradient GLProgramStage; - -private: - - // @{ - // Cache of values - these can change arbitrarily, EXCEPT - // we shouldn't change between degenerate and non-degenerate?! - - GrScalar fCenterX1; - GrScalar fRadius0; - SkBool8 fPosRoot; - - // @} - - typedef GrGradientEffect INHERITED; -}; - #endif |