| OLD | NEW |
| 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 "GrGeometryProcessor.h" |
| 14 #include "GrTypesPriv.h" | 14 #include "GrTypesPriv.h" |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Shader is based off of Loop-Blinn Quadratic GPU Rendering | 17 * Shader is based off of Loop-Blinn Quadratic GPU Rendering |
| 18 * The output of this effect is a hairline edge for conics. | 18 * The output of this effect is a hairline edge for conics. |
| 19 * Conics specified by implicit equation K^2 - LM. | 19 * Conics specified by implicit equation K^2 - LM. |
| 20 * 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, |
| 21 * the fourth value is not used. Distance is calculated using a | 21 * the fourth value is not used. Distance is calculated using a |
| 22 * first order approximation from the taylor series. | 22 * first order approximation from the taylor series. |
| 23 * Coverage for AA is max(0, 1-distance). | 23 * Coverage for AA is max(0, 1-distance). |
| (...skipping 24 matching lines...) Expand all Loading... |
| 48 * looking for. It is able to render ellipses (even thin ones) without the need
to chop. | 48 * looking for. It is able to render ellipses (even thin ones) without the need
to chop. |
| 49 * However, it can not handle thin hyperbolas well and thus would still rely on | 49 * However, it can not handle thin hyperbolas well and thus would still rely on |
| 50 * 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 |
| 51 * 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 |
| 52 * 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 |
| 53 * 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 |
| 54 * chopped first order and non chopped 2nd order. | 54 * chopped first order and non chopped 2nd order. |
| 55 */ | 55 */ |
| 56 class GrGLConicEffect; | 56 class GrGLConicEffect; |
| 57 | 57 |
| 58 class GrConicEffect : public GrVertexEffect { | 58 class GrConicEffect : public GrGeometryProcessor { |
| 59 public: | 59 public: |
| 60 static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetC
aps& caps) { | 60 static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetC
aps& caps) { |
| 61 GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (kFillAA_GrEffectEd
geType)); | 61 GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (kFillAA_GrEffectEd
geType)); |
| 62 GR_CREATE_STATIC_EFFECT(gConicHairAA, GrConicEffect, (kHairlineAA_GrEffe
ctEdgeType)); | 62 GR_CREATE_STATIC_EFFECT(gConicHairAA, GrConicEffect, (kHairlineAA_GrEffe
ctEdgeType)); |
| 63 GR_CREATE_STATIC_EFFECT(gConicFillBW, GrConicEffect, (kFillBW_GrEffectEd
geType)); | 63 GR_CREATE_STATIC_EFFECT(gConicFillBW, GrConicEffect, (kFillBW_GrEffectEd
geType)); |
| 64 switch (edgeType) { | 64 switch (edgeType) { |
| 65 case kFillAA_GrEffectEdgeType: | 65 case kFillAA_GrEffectEdgeType: |
| 66 if (!caps.shaderDerivativeSupport()) { | 66 if (!caps.shaderDerivativeSupport()) { |
| 67 return NULL; | 67 return NULL; |
| 68 } | 68 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 return gConicFillBW; | 79 return gConicFillBW; |
| 80 default: | 80 default: |
| 81 return NULL; | 81 return NULL; |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 virtual ~GrConicEffect(); | 85 virtual ~GrConicEffect(); |
| 86 | 86 |
| 87 static const char* Name() { return "Conic"; } | 87 static const char* Name() { return "Conic"; } |
| 88 | 88 |
| 89 inline const GrShaderVar& inConicCoeffs() const { return fInConicCoeffs; } |
| 89 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType);
} | 90 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType);
} |
| 90 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } | 91 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } |
| 91 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 92 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
| 92 | 93 |
| 93 typedef GrGLConicEffect GLEffect; | 94 typedef GrGLConicEffect GLEffect; |
| 94 | 95 |
| 95 virtual void getConstantColorComponents(GrColor* color, | 96 virtual void getConstantColorComponents(GrColor* color, |
| 96 uint32_t* validFlags) const SK_OVERR
IDE { | 97 uint32_t* validFlags) const SK_OVERR
IDE { |
| 97 *validFlags = 0; | 98 *validFlags = 0; |
| 98 } | 99 } |
| 99 | 100 |
| 100 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 101 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 101 | 102 |
| 102 private: | 103 private: |
| 103 GrConicEffect(GrEffectEdgeType); | 104 GrConicEffect(GrEffectEdgeType); |
| 104 | 105 |
| 105 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 106 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 106 | 107 |
| 107 GrEffectEdgeType fEdgeType; | 108 GrEffectEdgeType fEdgeType; |
| 109 const GrShaderVar& fInConicCoeffs; |
| 108 | 110 |
| 109 GR_DECLARE_EFFECT_TEST; | 111 GR_DECLARE_EFFECT_TEST; |
| 110 | 112 |
| 111 typedef GrVertexEffect INHERITED; | 113 typedef GrGeometryProcessor INHERITED; |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 /////////////////////////////////////////////////////////////////////////////// | 116 /////////////////////////////////////////////////////////////////////////////// |
| 115 /** | 117 /** |
| 116 * The output of this effect is a hairline edge for quadratics. | 118 * The output of this effect is a hairline edge for quadratics. |
| 117 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first | 119 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
| 118 * two components of the vertex attribute. At the three control points that defi
ne | 120 * two components of the vertex attribute. At the three control points that defi
ne |
| 119 * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively. | 121 * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively. |
| 120 * Coverage for AA is min(0, 1-distance). 3rd & 4th cimponent unused. | 122 * Coverage for AA is min(0, 1-distance). 3rd & 4th cimponent unused. |
| 121 * Requires shader derivative instruction support. | 123 * Requires shader derivative instruction support. |
| 122 */ | 124 */ |
| 123 class GrGLQuadEffect; | 125 class GrGLQuadEffect; |
| 124 | 126 |
| 125 class GrQuadEffect : public GrVertexEffect { | 127 class GrQuadEffect : public GrGeometryProcessor { |
| 126 public: | 128 public: |
| 127 static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetC
aps& caps) { | 129 static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetC
aps& caps) { |
| 128 GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrEffectEdge
Type)); | 130 GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrEffectEdge
Type)); |
| 129 GR_CREATE_STATIC_EFFECT(gQuadHairAA, GrQuadEffect, (kHairlineAA_GrEffect
EdgeType)); | 131 GR_CREATE_STATIC_EFFECT(gQuadHairAA, GrQuadEffect, (kHairlineAA_GrEffect
EdgeType)); |
| 130 GR_CREATE_STATIC_EFFECT(gQuadFillBW, GrQuadEffect, (kFillBW_GrEffectEdge
Type)); | 132 GR_CREATE_STATIC_EFFECT(gQuadFillBW, GrQuadEffect, (kFillBW_GrEffectEdge
Type)); |
| 131 switch (edgeType) { | 133 switch (edgeType) { |
| 132 case kFillAA_GrEffectEdgeType: | 134 case kFillAA_GrEffectEdgeType: |
| 133 if (!caps.shaderDerivativeSupport()) { | 135 if (!caps.shaderDerivativeSupport()) { |
| 134 return NULL; | 136 return NULL; |
| 135 } | 137 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 146 return gQuadFillBW; | 148 return gQuadFillBW; |
| 147 default: | 149 default: |
| 148 return NULL; | 150 return NULL; |
| 149 } | 151 } |
| 150 } | 152 } |
| 151 | 153 |
| 152 virtual ~GrQuadEffect(); | 154 virtual ~GrQuadEffect(); |
| 153 | 155 |
| 154 static const char* Name() { return "Quad"; } | 156 static const char* Name() { return "Quad"; } |
| 155 | 157 |
| 158 inline const GrShaderVar& inHairQuadEdge() const { return fInHairQuadEdge; } |
| 156 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType);
} | 159 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType);
} |
| 157 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } | 160 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } |
| 158 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 161 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
| 159 | 162 |
| 160 typedef GrGLQuadEffect GLEffect; | 163 typedef GrGLQuadEffect GLEffect; |
| 161 | 164 |
| 162 virtual void getConstantColorComponents(GrColor* color, | 165 virtual void getConstantColorComponents(GrColor* color, |
| 163 uint32_t* validFlags) const SK_OVERR
IDE { | 166 uint32_t* validFlags) const SK_OVERR
IDE { |
| 164 *validFlags = 0; | 167 *validFlags = 0; |
| 165 } | 168 } |
| 166 | 169 |
| 167 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 170 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 168 | 171 |
| 169 private: | 172 private: |
| 170 GrQuadEffect(GrEffectEdgeType); | 173 GrQuadEffect(GrEffectEdgeType); |
| 171 | 174 |
| 172 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 175 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 173 | 176 |
| 174 GrEffectEdgeType fEdgeType; | 177 GrEffectEdgeType fEdgeType; |
| 178 const GrShaderVar& fInHairQuadEdge; |
| 175 | 179 |
| 176 GR_DECLARE_EFFECT_TEST; | 180 GR_DECLARE_EFFECT_TEST; |
| 177 | 181 |
| 178 typedef GrVertexEffect INHERITED; | 182 typedef GrGeometryProcessor INHERITED; |
| 179 }; | 183 }; |
| 180 | 184 |
| 181 ////////////////////////////////////////////////////////////////////////////// | 185 ////////////////////////////////////////////////////////////////////////////// |
| 182 /** | 186 /** |
| 183 * Shader is based off of "Resolution Independent Curve Rendering using | 187 * Shader is based off of "Resolution Independent Curve Rendering using |
| 184 * Programmable Graphics Hardware" by Loop and Blinn. | 188 * Programmable Graphics Hardware" by Loop and Blinn. |
| 185 * The output of this effect is a hairline edge for non rational cubics. | 189 * The output of this effect is a hairline edge for non rational cubics. |
| 186 * Cubics are specified by implicit equation K^3 - LM. | 190 * Cubics are specified by implicit equation K^3 - LM. |
| 187 * K, L, and M, are the first three values of the vertex attribute, | 191 * K, L, and M, are the first three values of the vertex attribute, |
| 188 * the fourth value is not used. Distance is calculated using a | 192 * the fourth value is not used. Distance is calculated using a |
| 189 * first order approximation from the taylor series. | 193 * first order approximation from the taylor series. |
| 190 * Coverage for AA is max(0, 1-distance). | 194 * Coverage for AA is max(0, 1-distance). |
| 191 */ | 195 */ |
| 192 class GrGLCubicEffect; | 196 class GrGLCubicEffect; |
| 193 | 197 |
| 194 class GrCubicEffect : public GrVertexEffect { | 198 class GrCubicEffect : public GrGeometryProcessor { |
| 195 public: | 199 public: |
| 196 static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetC
aps& caps) { | 200 static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetC
aps& caps) { |
| 197 GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrEffectEd
geType)); | 201 GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrEffectEd
geType)); |
| 198 GR_CREATE_STATIC_EFFECT(gCubicHairAA, GrCubicEffect, (kHairlineAA_GrEffe
ctEdgeType)); | 202 GR_CREATE_STATIC_EFFECT(gCubicHairAA, GrCubicEffect, (kHairlineAA_GrEffe
ctEdgeType)); |
| 199 GR_CREATE_STATIC_EFFECT(gCubicFillBW, GrCubicEffect, (kFillBW_GrEffectEd
geType)); | 203 GR_CREATE_STATIC_EFFECT(gCubicFillBW, GrCubicEffect, (kFillBW_GrEffectEd
geType)); |
| 200 switch (edgeType) { | 204 switch (edgeType) { |
| 201 case kFillAA_GrEffectEdgeType: | 205 case kFillAA_GrEffectEdgeType: |
| 202 if (!caps.shaderDerivativeSupport()) { | 206 if (!caps.shaderDerivativeSupport()) { |
| 203 return NULL; | 207 return NULL; |
| 204 } | 208 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 215 return gCubicFillBW; | 219 return gCubicFillBW; |
| 216 default: | 220 default: |
| 217 return NULL; | 221 return NULL; |
| 218 } | 222 } |
| 219 } | 223 } |
| 220 | 224 |
| 221 virtual ~GrCubicEffect(); | 225 virtual ~GrCubicEffect(); |
| 222 | 226 |
| 223 static const char* Name() { return "Cubic"; } | 227 static const char* Name() { return "Cubic"; } |
| 224 | 228 |
| 229 inline const GrShaderVar& inCubicCoeffs() const { return fInCubicCoeffs; } |
| 225 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType);
} | 230 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType);
} |
| 226 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } | 231 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } |
| 227 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 232 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
| 228 | 233 |
| 229 typedef GrGLCubicEffect GLEffect; | 234 typedef GrGLCubicEffect GLEffect; |
| 230 | 235 |
| 231 virtual void getConstantColorComponents(GrColor* color, | 236 virtual void getConstantColorComponents(GrColor* color, |
| 232 uint32_t* validFlags) const SK_OVERR
IDE { | 237 uint32_t* validFlags) const SK_OVERR
IDE { |
| 233 *validFlags = 0; | 238 *validFlags = 0; |
| 234 } | 239 } |
| 235 | 240 |
| 236 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 241 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 237 | 242 |
| 238 private: | 243 private: |
| 239 GrCubicEffect(GrEffectEdgeType); | 244 GrCubicEffect(GrEffectEdgeType); |
| 240 | 245 |
| 241 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 246 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 242 | 247 |
| 243 GrEffectEdgeType fEdgeType; | 248 GrEffectEdgeType fEdgeType; |
| 249 const GrShaderVar& fInCubicCoeffs; |
| 244 | 250 |
| 245 GR_DECLARE_EFFECT_TEST; | 251 GR_DECLARE_EFFECT_TEST; |
| 246 | 252 |
| 247 typedef GrVertexEffect INHERITED; | 253 typedef GrGeometryProcessor INHERITED; |
| 248 }; | 254 }; |
| 249 | 255 |
| 250 #endif | 256 #endif |
| OLD | NEW |