tomhudson@google.com | 7fab52d | 2012-05-31 19:40:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 GrGradientEffects_DEFINED |
| 9 | #define GrGradientEffects_DEFINED |
| 10 | |
| 11 | #include "GrCustomStage.h" |
| 12 | #include "GrTypes.h" |
| 13 | #include "GrScalar.h" |
| 14 | |
tomhudson@google.com | 898e7b5 | 2012-06-01 20:42:15 +0000 | [diff] [blame] | 15 | /* |
| 16 | * The intepretation of the texture matrix depends on the sample mode. The |
| 17 | * texture matrix is applied both when the texture coordinates are explicit |
| 18 | * and when vertex positions are used as texture coordinates. In the latter |
| 19 | * case the texture matrix is applied to the pre-view-matrix position |
| 20 | * values. |
| 21 | * |
| 22 | * Normal SampleMode |
| 23 | * The post-matrix texture coordinates are in normalize space with (0,0) at |
| 24 | * the top-left and (1,1) at the bottom right. |
| 25 | * RadialGradient |
| 26 | * The matrix specifies the radial gradient parameters. |
| 27 | * (0,0) in the post-matrix space is center of the radial gradient. |
| 28 | * Radial2Gradient |
| 29 | * Matrix transforms to space where first circle is centered at the |
| 30 | * origin. The second circle will be centered (x, 0) where x may be |
| 31 | * 0 and is provided by setRadial2Params. The post-matrix space is |
| 32 | * normalized such that 1 is the second radius - first radius. |
| 33 | * SweepGradient |
| 34 | * The angle from the origin of texture coordinates in post-matrix space |
| 35 | * determines the gradient value. |
| 36 | */ |
| 37 | |
tomhudson@google.com | 7fab52d | 2012-05-31 19:40:13 +0000 | [diff] [blame] | 38 | class GrGLRadialGradient; |
| 39 | |
| 40 | class GrRadialGradient : public GrCustomStage { |
| 41 | |
| 42 | public: |
| 43 | |
| 44 | GrRadialGradient(); |
| 45 | virtual ~GrRadialGradient(); |
| 46 | |
| 47 | static const char* Name() { return "Radial Gradient"; } |
| 48 | virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; |
| 49 | virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE; |
| 50 | |
| 51 | typedef GrGLRadialGradient GLProgramStage; |
| 52 | |
| 53 | private: |
| 54 | |
| 55 | typedef GrCustomStage INHERITED; |
| 56 | }; |
| 57 | |
| 58 | class GrGLRadial2Gradient; |
| 59 | |
| 60 | class GrRadial2Gradient : public GrCustomStage { |
| 61 | |
| 62 | public: |
| 63 | |
| 64 | GrRadial2Gradient(GrScalar center, GrScalar radius, bool posRoot); |
| 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 |
| 72 | // of quadratic) equation. |
| 73 | bool isDegenerate() const { return GR_Scalar1 == fCenterX1; } |
| 74 | GrScalar center() const { return fCenterX1; } |
| 75 | GrScalar radius() const { return fRadius0; } |
| 76 | bool isPosRoot() const { return SkToBool(fPosRoot); } |
| 77 | |
| 78 | typedef GrGLRadial2Gradient GLProgramStage; |
| 79 | |
| 80 | private: |
| 81 | |
| 82 | // @{ |
| 83 | // Cache of values - these can change arbitrarily, EXCEPT |
| 84 | // we shouldn't change between degenerate and non-degenerate?! |
| 85 | |
| 86 | GrScalar fCenterX1; |
| 87 | GrScalar fRadius0; |
| 88 | SkBool8 fPosRoot; |
| 89 | |
| 90 | // @} |
| 91 | |
| 92 | typedef GrCustomStage INHERITED; |
| 93 | }; |
| 94 | |
| 95 | class GrGLSweepGradient; |
| 96 | |
| 97 | class GrSweepGradient : public GrCustomStage { |
| 98 | |
| 99 | public: |
| 100 | |
| 101 | GrSweepGradient(); |
| 102 | virtual ~GrSweepGradient(); |
| 103 | |
| 104 | static const char* Name() { return "Sweep Gradient"; } |
| 105 | virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE; |
| 106 | virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE; |
| 107 | |
| 108 | typedef GrGLSweepGradient GLProgramStage; |
| 109 | |
| 110 | protected: |
| 111 | |
| 112 | typedef GrCustomStage INHERITED; |
| 113 | }; |
| 114 | |
| 115 | #endif |
| 116 | |