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

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

Issue 23004010: Pull out Effect Shaders in GPU Path Renderer (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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/GrPathUtils.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
(Empty)
1 /*
2 * Copyright 2013 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 GrBezierEffect_DEFINED
9 #define GrBezierEffect_DEFINED
10
11 #include "GrEffect.h"
12 #include "GrDrawTargetCaps.h"
13
14 enum GrBezierEdgeType {
15 kFillAA_GrBezierEdgeType,
16 kHairAA_GrBezierEdgeType,
17 kFillNoAA_GrBezierEdgeType,
18 };
19
20 static inline bool GrBezierEdgeTypeIsFill(const GrBezierEdgeType edgeType) {
21 return (kHairAA_GrBezierEdgeType != edgeType);
22 }
23
24 static inline bool GrBezierEdgeTypeIsAA(const GrBezierEdgeType edgeType) {
25 return (kFillNoAA_GrBezierEdgeType != edgeType);
26 }
27
28 /**
29 * Shader is based off of Loop-Blinn Quadratic GPU Rendering
30 * The output of this effect is a hairline edge for conics.
31 * Conics specified by implicit equation K^2 - LM.
32 * K, L, and M, are the first three values of the vertex attribute,
33 * the fourth value is not used. Distance is calculated using a
34 * first order approximation from the taylor series.
35 * Coverage for AA is max(0, 1-distance).
36 *
37 * Test were also run using a second order distance approximation.
38 * There were two versions of the second order approx. The first version
39 * is of roughly the form:
40 * f(q) = |f(p)| - ||f'(p)||*||q-p|| - ||f''(p)||*||q-p||^2.
41 * The second is similar:
42 * f(q) = |f(p)| + ||f'(p)||*||q-p|| + ||f''(p)||*||q-p||^2.
43 * The exact version of the equations can be found in the paper
44 * "Distance Approximations for Rasterizing Implicit Curves" by Gabriel Taubin
45 *
46 * In both versions we solve the quadratic for ||q-p||.
47 * Version 1:
48 * gFM is magnitude of first partials and gFM2 is magnitude of 2nd partials (as derived from paper)
49 * builder->fsCodeAppend("\t\tedgeAlpha = (sqrt(gFM*gFM+4.0*func*gF2M) - gFM)/(2 .0*gF2M);\n");
50 * Version 2:
51 * builder->fsCodeAppend("\t\tedgeAlpha = (gFM - sqrt(gFM*gFM-4.0*func*gF2M))/(2 .0*gF2M);\n");
52 *
53 * Also note that 2nd partials of k,l,m are zero
54 *
55 * When comparing the two second order approximations to the first order approxi mations,
56 * the following results were found. Version 1 tends to underestimate the distan ces, thus it
57 * basically increases all the error that we were already seeing in the first or der
58 * approx. So this version is not the one to use. Version 2 has the opposite eff ect
59 * and tends to overestimate the distances. This is much closer to what we are
60 * looking for. It is able to render ellipses (even thin ones) without the need to chop.
61 * However, it can not handle thin hyperbolas well and thus would still rely on
62 * chopping to tighten the clipping. Another side effect of the overestimating i s
63 * that the curves become much thinner and "ropey". If all that was ever rendere d
64 * were "not too thin" curves and ellipses then 2nd order may have an advantage since
65 * only one geometry would need to be rendered. However no benches were run comp aring
66 * chopped first order and non chopped 2nd order.
67 */
68 class GrGLConicEffect;
69
70 class GrConicEffect : public GrEffect {
71 public:
72 static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTarg etCaps& caps) {
73 GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (edgeType));
74 GR_CREATE_STATIC_EFFECT(gConicHairAA, GrConicEffect, (edgeType));
75 GR_CREATE_STATIC_EFFECT(gConicFillNoAA, GrConicEffect, (edgeType));
76 if (kFillAA_GrBezierEdgeType == edgeType) {
77 if (!caps.shaderDerivativeSupport()) {
78 return NULL;
79 }
80 gConicFillAA->ref();
81 return gConicFillAA;
82 } else if (kHairAA_GrBezierEdgeType == edgeType) {
83 if (!caps.shaderDerivativeSupport()) {
84 return NULL;
85 }
86 gConicHairAA->ref();
87 return gConicHairAA;
88 } else {
89 gConicFillNoAA->ref();
90 return gConicFillNoAA;
91 }
92 }
93
94 virtual ~GrConicEffect();
95
96 static const char* Name() { return "Conic"; }
97
98 inline bool isAntiAliased() const { return GrBezierEdgeTypeIsAA(fEdgeType); }
99 inline bool isFilled() const { return GrBezierEdgeTypeIsFill(fEdgeType); }
100 inline GrBezierEdgeType getEdgeType() const { return fEdgeType; }
101
102 typedef GrGLConicEffect GLEffect;
103
104 virtual void getConstantColorComponents(GrColor* color,
105 uint32_t* validFlags) const SK_OVERR IDE {
106 *validFlags = 0;
107 }
108
109 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
110
111 private:
112 GrConicEffect(GrBezierEdgeType);
113
114 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
115
116 GrBezierEdgeType fEdgeType;
117
118 GR_DECLARE_EFFECT_TEST;
119
120 typedef GrEffect INHERITED;
121 };
122
123 ///////////////////////////////////////////////////////////////////////////////
124 /**
125 * The output of this effect is a hairline edge for quadratics.
126 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first
127 * two components of the vertex attribute. At the three control points that defi ne
128 * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively.
129 * Coverage for AA is min(0, 1-distance). 3rd & 4th cimponent unused.
130 * Requires shader derivative instruction support.
131 */
132 class GrGLQuadEffect;
133
134 class GrQuadEffect : public GrEffect {
135 public:
136 static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTarg etCaps& caps) {
137 GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrBezierEdge Type));
138 GR_CREATE_STATIC_EFFECT(gQuadHairAA, GrQuadEffect, (kHairAA_GrBezierEdge Type));
139 GR_CREATE_STATIC_EFFECT(gQuadFillNoAA, GrQuadEffect, (kFillNoAA_GrBezier EdgeType));
140 if (kFillAA_GrBezierEdgeType == edgeType) {
141 if (!caps.shaderDerivativeSupport()) {
142 return NULL;
143 }
144 gQuadFillAA->ref();
145 return gQuadFillAA;
146 } else if (kHairAA_GrBezierEdgeType == edgeType) {
147 if (!caps.shaderDerivativeSupport()) {
148 return NULL;
149 }
150 gQuadHairAA->ref();
151 return gQuadHairAA;
152 } else {
153 gQuadFillNoAA->ref();
154 return gQuadFillNoAA;
155 }
156 }
157
158 virtual ~GrQuadEffect();
159
160 static const char* Name() { return "Quad"; }
161
162 inline bool isAntiAliased() const { return GrBezierEdgeTypeIsAA(fEdgeType); }
163 inline bool isFilled() const { return GrBezierEdgeTypeIsFill(fEdgeType); }
164 inline GrBezierEdgeType getEdgeType() const { return fEdgeType; }
165
166 typedef GrGLQuadEffect GLEffect;
167
168 virtual void getConstantColorComponents(GrColor* color,
169 uint32_t* validFlags) const SK_OVERR IDE {
170 *validFlags = 0;
171 }
172
173 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
174
175 private:
176 GrQuadEffect(GrBezierEdgeType);
177
178 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
179
180 GrBezierEdgeType fEdgeType;
181
182 GR_DECLARE_EFFECT_TEST;
183
184 typedef GrEffect INHERITED;
185 };
186
187 //////////////////////////////////////////////////////////////////////////////
188 /**
189 * Shader is based off of "Resolution Independent Curve Rendering using
190 * Programmable Graphics Hardware" by Loop and Blinn.
191 * The output of this effect is a hairline edge for non rational cubics.
192 * Cubics are specified by implicit equation K^3 - LM.
193 * K, L, and M, are the first three values of the vertex attribute,
194 * the fourth value is not used. Distance is calculated using a
195 * first order approximation from the taylor series.
196 * Coverage for AA is max(0, 1-distance).
197 */
198 class GrGLCubicEffect;
199
200 class GrCubicEffect : public GrEffect {
201 public:
202 static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTarg etCaps& caps) {
203 GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrBezierEd geType));
204 GR_CREATE_STATIC_EFFECT(gCubicHairAA, GrCubicEffect, (kHairAA_GrBezierEd geType));
205 GR_CREATE_STATIC_EFFECT(gCubicFillNoAA, GrCubicEffect, (kFillNoAA_GrBezi erEdgeType));
206 if (kFillAA_GrBezierEdgeType == edgeType) {
207 if (!caps.shaderDerivativeSupport()) {
208 return NULL;
209 }
210 gCubicFillAA->ref();
211 return gCubicFillAA;
212 } else if (kHairAA_GrBezierEdgeType == edgeType) {
213 if (!caps.shaderDerivativeSupport()) {
214 return NULL;
215 }
216 gCubicHairAA->ref();
217 return gCubicHairAA;
218 } else {
219 gCubicFillNoAA->ref();
220 return gCubicFillNoAA;
221 }
222 }
223
224 virtual ~GrCubicEffect();
225
226 static const char* Name() { return "Cubic"; }
227
228 inline bool isAntiAliased() const { return GrBezierEdgeTypeIsAA(fEdgeType); }
229 inline bool isFilled() const { return GrBezierEdgeTypeIsFill(fEdgeType); }
230 inline GrBezierEdgeType getEdgeType() const { return fEdgeType; }
231
232 typedef GrGLCubicEffect GLEffect;
233
234 virtual void getConstantColorComponents(GrColor* color,
235 uint32_t* validFlags) const SK_OVERR IDE {
236 *validFlags = 0;
237 }
238
239 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
240
241 private:
242 GrCubicEffect(GrBezierEdgeType);
243
244 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
245
246 GrBezierEdgeType fEdgeType;
247
248 GR_DECLARE_EFFECT_TEST;
249
250 typedef GrEffect INHERITED;
251 };
252
253 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrPathUtils.cpp ('k') | src/gpu/effects/GrBezierEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698