Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: src/gpu/effects/GrBezierEffect.h

Issue 183893023: Unify edge type enums across GrEffect subclasses that clip rendering to a geometry. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: tot again Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | src/gpu/effects/GrBezierEffect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrBezierEffect_DEFINED 8 #ifndef GrBezierEffect_DEFINED
9 #define GrBezierEffect_DEFINED 9 #define GrBezierEffect_DEFINED
10 10
11 #include "GrDrawTargetCaps.h" 11 #include "GrDrawTargetCaps.h"
12 #include "GrEffect.h" 12 #include "GrEffect.h"
13 #include "GrVertexEffect.h" 13 #include "GrVertexEffect.h"
14 14 #include "GrTypesPriv.h"
15 enum GrBezierEdgeType {
16 kFillAA_GrBezierEdgeType,
17 kHairAA_GrBezierEdgeType,
18 kFillNoAA_GrBezierEdgeType,
19 };
20
21 static inline bool GrBezierEdgeTypeIsFill(const GrBezierEdgeType edgeType) {
22 return (kHairAA_GrBezierEdgeType != edgeType);
23 }
24
25 static inline bool GrBezierEdgeTypeIsAA(const GrBezierEdgeType edgeType) {
26 return (kFillNoAA_GrBezierEdgeType != edgeType);
27 }
28 15
29 /** 16 /**
30 * Shader is based off of Loop-Blinn Quadratic GPU Rendering 17 * Shader is based off of Loop-Blinn Quadratic GPU Rendering
31 * The output of this effect is a hairline edge for conics. 18 * The output of this effect is a hairline edge for conics.
32 * Conics specified by implicit equation K^2 - LM. 19 * Conics specified by implicit equation K^2 - LM.
33 * K, L, and M, are the first three values of the vertex attribute, 20 * K, L, and M, are the first three values of the vertex attribute,
34 * the fourth value is not used. Distance is calculated using a 21 * the fourth value is not used. Distance is calculated using a
35 * first order approximation from the taylor series. 22 * first order approximation from the taylor series.
36 * Coverage for AA is max(0, 1-distance). 23 * Coverage for AA is max(0, 1-distance).
37 * 24 *
(...skipping 25 matching lines...) Expand all
63 * chopping to tighten the clipping. Another side effect of the overestimating i s 50 * chopping to tighten the clipping. Another side effect of the overestimating i s
64 * that the curves become much thinner and "ropey". If all that was ever rendere d 51 * that the curves become much thinner and "ropey". If all that was ever rendere d
65 * were "not too thin" curves and ellipses then 2nd order may have an advantage since 52 * were "not too thin" curves and ellipses then 2nd order may have an advantage since
66 * only one geometry would need to be rendered. However no benches were run comp aring 53 * only one geometry would need to be rendered. However no benches were run comp aring
67 * chopped first order and non chopped 2nd order. 54 * chopped first order and non chopped 2nd order.
68 */ 55 */
69 class GrGLConicEffect; 56 class GrGLConicEffect;
70 57
71 class GrConicEffect : public GrVertexEffect { 58 class GrConicEffect : public GrVertexEffect {
72 public: 59 public:
73 static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTarg etCaps& caps) { 60 static GrEffectRef* Create(const GrEffectEdgeType edgeType, const GrDrawTarg etCaps& caps) {
74 GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (kFillAA_GrBezierEd geType)); 61 GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (kFillAA_GrEffectEd geType));
75 GR_CREATE_STATIC_EFFECT(gConicHairAA, GrConicEffect, (kHairAA_GrBezierEd geType)); 62 GR_CREATE_STATIC_EFFECT(gConicHairAA, GrConicEffect, (kHairlineAA_GrEffe ctEdgeType));
76 GR_CREATE_STATIC_EFFECT(gConicFillNoAA, GrConicEffect, (kFillNoAA_GrBezi erEdgeType)); 63 GR_CREATE_STATIC_EFFECT(gConicFillBW, GrConicEffect, (kFillBW_GrEffectEd geType));
77 if (kFillAA_GrBezierEdgeType == edgeType) { 64 switch (edgeType) {
78 if (!caps.shaderDerivativeSupport()) { 65 case kFillAA_GrEffectEdgeType:
66 if (!caps.shaderDerivativeSupport()) {
67 return NULL;
68 }
69 gConicFillAA->ref();
70 return gConicFillAA;
71 case kHairlineAA_GrEffectEdgeType:
72 if (!caps.shaderDerivativeSupport()) {
73 return NULL;
74 }
75 gConicHairAA->ref();
76 return gConicHairAA;
77 case kFillBW_GrEffectEdgeType:
78 gConicFillBW->ref();
79 return gConicFillBW;
80 default:
79 return NULL; 81 return NULL;
80 }
81 gConicFillAA->ref();
82 return gConicFillAA;
83 } else if (kHairAA_GrBezierEdgeType == edgeType) {
84 if (!caps.shaderDerivativeSupport()) {
85 return NULL;
86 }
87 gConicHairAA->ref();
88 return gConicHairAA;
89 } else {
90 gConicFillNoAA->ref();
91 return gConicFillNoAA;
92 } 82 }
93 } 83 }
94 84
95 virtual ~GrConicEffect(); 85 virtual ~GrConicEffect();
96 86
97 static const char* Name() { return "Conic"; } 87 static const char* Name() { return "Conic"; }
98 88
99 inline bool isAntiAliased() const { return GrBezierEdgeTypeIsAA(fEdgeType); } 89 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType); }
100 inline bool isFilled() const { return GrBezierEdgeTypeIsFill(fEdgeType); } 90 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); }
101 inline GrBezierEdgeType getEdgeType() const { return fEdgeType; } 91 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; }
102 92
103 typedef GrGLConicEffect GLEffect; 93 typedef GrGLConicEffect GLEffect;
104 94
105 virtual void getConstantColorComponents(GrColor* color, 95 virtual void getConstantColorComponents(GrColor* color,
106 uint32_t* validFlags) const SK_OVERR IDE { 96 uint32_t* validFlags) const SK_OVERR IDE {
107 *validFlags = 0; 97 *validFlags = 0;
108 } 98 }
109 99
110 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 100 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
111 101
112 private: 102 private:
113 GrConicEffect(GrBezierEdgeType); 103 GrConicEffect(GrEffectEdgeType);
114 104
115 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 105 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
116 106
117 GrBezierEdgeType fEdgeType; 107 GrEffectEdgeType fEdgeType;
118 108
119 GR_DECLARE_EFFECT_TEST; 109 GR_DECLARE_EFFECT_TEST;
120 110
121 typedef GrVertexEffect INHERITED; 111 typedef GrVertexEffect INHERITED;
122 }; 112 };
123 113
124 /////////////////////////////////////////////////////////////////////////////// 114 ///////////////////////////////////////////////////////////////////////////////
125 /** 115 /**
126 * The output of this effect is a hairline edge for quadratics. 116 * The output of this effect is a hairline edge for quadratics.
127 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first 117 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first
128 * two components of the vertex attribute. At the three control points that defi ne 118 * two components of the vertex attribute. At the three control points that defi ne
129 * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively. 119 * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively.
130 * Coverage for AA is min(0, 1-distance). 3rd & 4th cimponent unused. 120 * Coverage for AA is min(0, 1-distance). 3rd & 4th cimponent unused.
131 * Requires shader derivative instruction support. 121 * Requires shader derivative instruction support.
132 */ 122 */
133 class GrGLQuadEffect; 123 class GrGLQuadEffect;
134 124
135 class GrQuadEffect : public GrVertexEffect { 125 class GrQuadEffect : public GrVertexEffect {
136 public: 126 public:
137 static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTarg etCaps& caps) { 127 static GrEffectRef* Create(const GrEffectEdgeType edgeType, const GrDrawTarg etCaps& caps) {
138 GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrBezierEdge Type)); 128 GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrEffectEdge Type));
139 GR_CREATE_STATIC_EFFECT(gQuadHairAA, GrQuadEffect, (kHairAA_GrBezierEdge Type)); 129 GR_CREATE_STATIC_EFFECT(gQuadHairAA, GrQuadEffect, (kHairlineAA_GrEffect EdgeType));
140 GR_CREATE_STATIC_EFFECT(gQuadFillNoAA, GrQuadEffect, (kFillNoAA_GrBezier EdgeType)); 130 GR_CREATE_STATIC_EFFECT(gQuadFillBW, GrQuadEffect, (kFillBW_GrEffectEdge Type));
141 if (kFillAA_GrBezierEdgeType == edgeType) { 131 switch (edgeType) {
142 if (!caps.shaderDerivativeSupport()) { 132 case kFillAA_GrEffectEdgeType:
133 if (!caps.shaderDerivativeSupport()) {
134 return NULL;
135 }
136 gQuadFillAA->ref();
137 return gQuadFillAA;
138 case kHairlineAA_GrEffectEdgeType:
139 if (!caps.shaderDerivativeSupport()) {
140 return NULL;
141 }
142 gQuadHairAA->ref();
143 return gQuadHairAA;
144 case kFillBW_GrEffectEdgeType:
145 gQuadFillBW->ref();
146 return gQuadFillBW;
147 default:
143 return NULL; 148 return NULL;
144 }
145 gQuadFillAA->ref();
146 return gQuadFillAA;
147 } else if (kHairAA_GrBezierEdgeType == edgeType) {
148 if (!caps.shaderDerivativeSupport()) {
149 return NULL;
150 }
151 gQuadHairAA->ref();
152 return gQuadHairAA;
153 } else {
154 gQuadFillNoAA->ref();
155 return gQuadFillNoAA;
156 } 149 }
157 } 150 }
158 151
159 virtual ~GrQuadEffect(); 152 virtual ~GrQuadEffect();
160 153
161 static const char* Name() { return "Quad"; } 154 static const char* Name() { return "Quad"; }
162 155
163 inline bool isAntiAliased() const { return GrBezierEdgeTypeIsAA(fEdgeType); } 156 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType); }
164 inline bool isFilled() const { return GrBezierEdgeTypeIsFill(fEdgeType); } 157 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); }
165 inline GrBezierEdgeType getEdgeType() const { return fEdgeType; } 158 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; }
166 159
167 typedef GrGLQuadEffect GLEffect; 160 typedef GrGLQuadEffect GLEffect;
168 161
169 virtual void getConstantColorComponents(GrColor* color, 162 virtual void getConstantColorComponents(GrColor* color,
170 uint32_t* validFlags) const SK_OVERR IDE { 163 uint32_t* validFlags) const SK_OVERR IDE {
171 *validFlags = 0; 164 *validFlags = 0;
172 } 165 }
173 166
174 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 167 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
175 168
176 private: 169 private:
177 GrQuadEffect(GrBezierEdgeType); 170 GrQuadEffect(GrEffectEdgeType);
178 171
179 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 172 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
180 173
181 GrBezierEdgeType fEdgeType; 174 GrEffectEdgeType fEdgeType;
182 175
183 GR_DECLARE_EFFECT_TEST; 176 GR_DECLARE_EFFECT_TEST;
184 177
185 typedef GrVertexEffect INHERITED; 178 typedef GrVertexEffect INHERITED;
186 }; 179 };
187 180
188 ////////////////////////////////////////////////////////////////////////////// 181 //////////////////////////////////////////////////////////////////////////////
189 /** 182 /**
190 * Shader is based off of "Resolution Independent Curve Rendering using 183 * Shader is based off of "Resolution Independent Curve Rendering using
191 * Programmable Graphics Hardware" by Loop and Blinn. 184 * Programmable Graphics Hardware" by Loop and Blinn.
192 * The output of this effect is a hairline edge for non rational cubics. 185 * The output of this effect is a hairline edge for non rational cubics.
193 * Cubics are specified by implicit equation K^3 - LM. 186 * Cubics are specified by implicit equation K^3 - LM.
194 * K, L, and M, are the first three values of the vertex attribute, 187 * K, L, and M, are the first three values of the vertex attribute,
195 * the fourth value is not used. Distance is calculated using a 188 * the fourth value is not used. Distance is calculated using a
196 * first order approximation from the taylor series. 189 * first order approximation from the taylor series.
197 * Coverage for AA is max(0, 1-distance). 190 * Coverage for AA is max(0, 1-distance).
198 */ 191 */
199 class GrGLCubicEffect; 192 class GrGLCubicEffect;
200 193
201 class GrCubicEffect : public GrVertexEffect { 194 class GrCubicEffect : public GrVertexEffect {
202 public: 195 public:
203 static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTarg etCaps& caps) { 196 static GrEffectRef* Create(const GrEffectEdgeType edgeType, const GrDrawTarg etCaps& caps) {
204 GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrBezierEd geType)); 197 GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrEffectEd geType));
205 GR_CREATE_STATIC_EFFECT(gCubicHairAA, GrCubicEffect, (kHairAA_GrBezierEd geType)); 198 GR_CREATE_STATIC_EFFECT(gCubicHairAA, GrCubicEffect, (kHairlineAA_GrEffe ctEdgeType));
206 GR_CREATE_STATIC_EFFECT(gCubicFillNoAA, GrCubicEffect, (kFillNoAA_GrBezi erEdgeType)); 199 GR_CREATE_STATIC_EFFECT(gCubicFillBW, GrCubicEffect, (kFillBW_GrEffectEd geType));
207 if (kFillAA_GrBezierEdgeType == edgeType) { 200 switch (edgeType) {
208 if (!caps.shaderDerivativeSupport()) { 201 case kFillAA_GrEffectEdgeType:
202 if (!caps.shaderDerivativeSupport()) {
203 return NULL;
204 }
205 gCubicFillAA->ref();
206 return gCubicFillAA;
207 case kHairlineAA_GrEffectEdgeType:
208 if (!caps.shaderDerivativeSupport()) {
209 return NULL;
210 }
211 gCubicHairAA->ref();
212 return gCubicHairAA;
213 case kFillBW_GrEffectEdgeType:
214 gCubicFillBW->ref();
215 return gCubicFillBW;
216 default:
209 return NULL; 217 return NULL;
210 }
211 gCubicFillAA->ref();
212 return gCubicFillAA;
213 } else if (kHairAA_GrBezierEdgeType == edgeType) {
214 if (!caps.shaderDerivativeSupport()) {
215 return NULL;
216 }
217 gCubicHairAA->ref();
218 return gCubicHairAA;
219 } else {
220 gCubicFillNoAA->ref();
221 return gCubicFillNoAA;
222 } 218 }
223 } 219 }
224 220
225 virtual ~GrCubicEffect(); 221 virtual ~GrCubicEffect();
226 222
227 static const char* Name() { return "Cubic"; } 223 static const char* Name() { return "Cubic"; }
228 224
229 inline bool isAntiAliased() const { return GrBezierEdgeTypeIsAA(fEdgeType); } 225 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType); }
230 inline bool isFilled() const { return GrBezierEdgeTypeIsFill(fEdgeType); } 226 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); }
231 inline GrBezierEdgeType getEdgeType() const { return fEdgeType; } 227 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; }
232 228
233 typedef GrGLCubicEffect GLEffect; 229 typedef GrGLCubicEffect GLEffect;
234 230
235 virtual void getConstantColorComponents(GrColor* color, 231 virtual void getConstantColorComponents(GrColor* color,
236 uint32_t* validFlags) const SK_OVERR IDE { 232 uint32_t* validFlags) const SK_OVERR IDE {
237 *validFlags = 0; 233 *validFlags = 0;
238 } 234 }
239 235
240 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 236 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
241 237
242 private: 238 private:
243 GrCubicEffect(GrBezierEdgeType); 239 GrCubicEffect(GrEffectEdgeType);
244 240
245 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 241 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
246 242
247 GrBezierEdgeType fEdgeType; 243 GrEffectEdgeType fEdgeType;
248 244
249 GR_DECLARE_EFFECT_TEST; 245 GR_DECLARE_EFFECT_TEST;
250 246
251 typedef GrVertexEffect INHERITED; 247 typedef GrVertexEffect INHERITED;
252 }; 248 };
253 249
254 #endif 250 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | src/gpu/effects/GrBezierEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698