rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #ifndef SkTwoPointRadialGradient_DEFINED |
| 10 | #define SkTwoPointRadialGradient_DEFINED |
| 11 | |
| 12 | #include "SkGradientShaderPriv.h" |
| 13 | |
| 14 | class SkTwoPointRadialGradient : public SkGradientShaderBase { |
| 15 | public: |
| 16 | SkTwoPointRadialGradient(const SkPoint& start, SkScalar startRadius, |
| 17 | const SkPoint& end, SkScalar endRadius, |
| 18 | const SkColor colors[], const SkScalar pos[], |
| 19 | int colorCount, SkShader::TileMode mode, |
| 20 | SkUnitMapper* mapper); |
| 21 | |
| 22 | virtual BitmapType asABitmap(SkBitmap* bitmap, |
| 23 | SkMatrix* matrix, |
| 24 | TileMode* xy) const SK_OVERRIDE; |
| 25 | virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE; |
| 26 | virtual GrCustomStage* asNewCustomStage(GrContext* context, |
| 27 | GrSamplerState* sampler) const SK_OVERRIDE; |
| 28 | |
| 29 | virtual void shadeSpan(int x, int y, SkPMColor* dstCParam, |
| 30 | int count) SK_OVERRIDE; |
| 31 | virtual bool setContext(const SkBitmap& device, |
| 32 | const SkPaint& paint, |
| 33 | const SkMatrix& matrix) SK_OVERRIDE; |
| 34 | |
| 35 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointRadialGradient) |
| 36 | |
| 37 | protected: |
| 38 | SkTwoPointRadialGradient(SkFlattenableReadBuffer& buffer); |
| 39 | virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; |
| 40 | |
| 41 | private: |
| 42 | typedef SkGradientShaderBase INHERITED; |
| 43 | const SkPoint fCenter1; |
| 44 | const SkPoint fCenter2; |
| 45 | const SkScalar fRadius1; |
| 46 | const SkScalar fRadius2; |
| 47 | SkPoint fDiff; |
| 48 | SkScalar fStartRadius, fDiffRadius, fSr2D2, fA, fOneOverTwoA; |
| 49 | |
| 50 | void init(); |
| 51 | }; |
| 52 | |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 53 | /////////////////////////////////////////////////////////////////////////////// |
| 54 | |
| 55 | class GrGLRadial2Gradient; |
| 56 | |
| 57 | class GrRadial2Gradient : public GrGradientEffect { |
| 58 | |
| 59 | public: |
| 60 | |
| 61 | GrRadial2Gradient(GrTexture* texture, GrScalar center, GrScalar radius, bool posRoot); |
| 62 | GrRadial2Gradient(GrContext* ctx, const SkShader& shader, |
| 63 | GrSamplerState* sampler, SkScalar center, |
| 64 | SkScalar radius, SkScalar diffRadius); |
| 65 | virtual ~GrRadial2Gradient(); |
| 66 | |
| 67 | static const char* Name() { return "Two-Point Radial Gradient"; } |
| 68 | virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; |
| 69 | virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE; |
| 70 | |
| 71 | // The radial gradient parameters can collapse to a linear (instead of quadratic) equation. |
| 72 | bool isDegenerate() const { return GR_Scalar1 == fCenterX1; } |
| 73 | GrScalar center() const { return fCenterX1; } |
| 74 | GrScalar radius() const { return fRadius0; } |
| 75 | bool isPosRoot() const { return SkToBool(fPosRoot); } |
| 76 | |
| 77 | typedef GrGLRadial2Gradient GLProgramStage; |
| 78 | |
| 79 | private: |
| 80 | |
| 81 | // @{ |
| 82 | // Cache of values - these can change arbitrarily, EXCEPT |
| 83 | // we shouldn't change between degenerate and non-degenerate?! |
| 84 | |
| 85 | GrScalar fCenterX1; |
| 86 | GrScalar fRadius0; |
| 87 | SkBool8 fPosRoot; |
| 88 | |
| 89 | // @} |
| 90 | |
| 91 | typedef GrGradientEffect INHERITED; |
| 92 | }; |
| 93 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 94 | #endif |
| 95 | |