blob: cf6827f251184973079827992bab32c55facf6b2 [file] [log] [blame]
tomhudson@google.com7fab52d2012-05-31 19:40:13 +00001/*
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.com898e7b52012-06-01 20:42:15 +000015/*
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.com7fab52d2012-05-31 19:40:13 +000038class GrGLRadialGradient;
39
40class GrRadialGradient : public GrCustomStage {
41
42public:
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
53private:
54
55 typedef GrCustomStage INHERITED;
56};
57
58class GrGLRadial2Gradient;
59
60class GrRadial2Gradient : public GrCustomStage {
61
62public:
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
80private:
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
rileya@google.com3e332582012-07-03 13:43:35 +000095class GrGLConical2Gradient;
96
97class GrConical2Gradient : public GrCustomStage {
98
99public:
100
101 GrConical2Gradient(GrScalar center, GrScalar radius, GrScalar diffRadius);
102 virtual ~GrConical2Gradient();
103
104 static const char* Name() { return "Two-Point Conical Gradient"; }
105 virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE;
106 virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE;
107
108 // The radial gradient parameters can collapse to a linear (instead
109 // of quadratic) equation.
110 bool isDegenerate() const { return SkScalarAbs(fDiffRadius) ==
111 SkScalarAbs(fCenterX1); }
112 GrScalar center() const { return fCenterX1; }
113 GrScalar diffRadius() const { return fDiffRadius; }
114 GrScalar radius() const { return fRadius0; }
115
116 typedef GrGLConical2Gradient GLProgramStage;
117
118private:
119
120 // @{
121 // Cache of values - these can change arbitrarily, EXCEPT
122 // we shouldn't change between degenerate and non-degenerate?!
123
124 GrScalar fCenterX1;
125 GrScalar fRadius0;
126 GrScalar fDiffRadius;
127
128 // @}
129
130 typedef GrCustomStage INHERITED;
131};
132
tomhudson@google.com7fab52d2012-05-31 19:40:13 +0000133class GrGLSweepGradient;
134
135class GrSweepGradient : public GrCustomStage {
136
137public:
138
139 GrSweepGradient();
140 virtual ~GrSweepGradient();
141
142 static const char* Name() { return "Sweep Gradient"; }
143 virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE;
144 virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE;
145
146 typedef GrGLSweepGradient GLProgramStage;
147
148protected:
149
150 typedef GrCustomStage INHERITED;
151};
152
153#endif
154