commit-bot@chromium.org | aa64fbf | 2014-04-03 14:59:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkTwoPointConicalGradient_gpu_DEFINED |
commit-bot@chromium.org | 1cf21d2 | 2014-04-03 18:27:11 +0000 | [diff] [blame] | 9 | #define SkTwoPointConicalGradient_gpu_DEFINED |
commit-bot@chromium.org | aa64fbf | 2014-04-03 14:59:19 +0000 | [diff] [blame] | 10 | |
| 11 | #if SK_SUPPORT_GPU |
| 12 | |
| 13 | #include "SkGradientShaderPriv.h" |
| 14 | |
| 15 | class GrEffectRef; |
| 16 | class SkTwoPointConicalGradient; |
| 17 | class GrGL2PtConicalGradientEffect; |
| 18 | |
| 19 | class Gr2PtConicalGradientEffect : public GrGradientEffect { |
| 20 | public: |
| 21 | |
| 22 | static GrEffectRef* Create(GrContext* ctx, |
| 23 | const SkTwoPointConicalGradient& shader, |
| 24 | const SkMatrix& matrix, |
| 25 | SkShader::TileMode tm) { |
| 26 | AutoEffectUnref effect(SkNEW_ARGS(Gr2PtConicalGradientEffect, (ctx, shader, matrix, tm))); |
| 27 | return CreateEffectRef(effect); |
| 28 | } |
| 29 | |
| 30 | virtual ~Gr2PtConicalGradientEffect() { } |
| 31 | |
| 32 | static const char* Name() { return "Two-Point Conical Gradient"; } |
skia.committer@gmail.com | 221b911 | 2014-04-04 03:04:32 +0000 | [diff] [blame^] | 33 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
commit-bot@chromium.org | aa64fbf | 2014-04-03 14:59:19 +0000 | [diff] [blame] | 34 | |
| 35 | // The radial gradient parameters can collapse to a linear (instead of quadratic) equation. |
| 36 | bool isDegenerate() const { return SkScalarAbs(fDiffRadius) == SkScalarAbs(fCenterX1); } |
| 37 | SkScalar center() const { return fCenterX1; } |
| 38 | SkScalar diffRadius() const { return fDiffRadius; } |
| 39 | SkScalar radius() const { return fRadius0; } |
| 40 | |
| 41 | typedef GrGL2PtConicalGradientEffect GLEffect; |
| 42 | |
| 43 | private: |
| 44 | virtual bool onIsEqual(const GrEffect& sBase) const SK_OVERRIDE { |
| 45 | const Gr2PtConicalGradientEffect& s = CastEffect<Gr2PtConicalGradientEffect>(sBase); |
| 46 | return (INHERITED::onIsEqual(sBase) && |
| 47 | this->fCenterX1 == s.fCenterX1 && |
| 48 | this->fRadius0 == s.fRadius0 && |
| 49 | this->fDiffRadius == s.fDiffRadius); |
| 50 | } |
| 51 | |
| 52 | Gr2PtConicalGradientEffect(GrContext* ctx, |
| 53 | const SkTwoPointConicalGradient& shader, |
| 54 | const SkMatrix& matrix, |
| 55 | SkShader::TileMode tm); |
| 56 | |
| 57 | GR_DECLARE_EFFECT_TEST; |
| 58 | |
| 59 | // @{ |
| 60 | // Cache of values - these can change arbitrarily, EXCEPT |
| 61 | // we shouldn't change between degenerate and non-degenerate?! |
| 62 | |
| 63 | GrCoordTransform fBTransform; |
| 64 | SkScalar fCenterX1; |
| 65 | SkScalar fRadius0; |
| 66 | SkScalar fDiffRadius; |
| 67 | |
| 68 | // @} |
| 69 | |
| 70 | typedef GrGradientEffect INHERITED; |
| 71 | }; |
| 72 | #endif |
| 73 | #endif |