| 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 "GrProcessor.h" |
| 13 #include "GrGeometryProcessor.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. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 GrGeometryProcessor { | 58 class GrConicEffect : public GrGeometryProcessor { |
| 59 public: | 59 public: |
| 60 static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetC
aps& caps) { | 60 static GrGeometryProcessor* Create(const GrPrimitiveEdgeType edgeType, |
| 61 GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (kFillAA_GrEffectEd
geType)); | 61 const GrDrawTargetCaps& caps) { |
| 62 GR_CREATE_STATIC_EFFECT(gConicHairAA, GrConicEffect, (kHairlineAA_GrEffe
ctEdgeType)); | 62 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gConicFillAA, GrConicEffect, |
| 63 GR_CREATE_STATIC_EFFECT(gConicFillBW, GrConicEffect, (kFillBW_GrEffectEd
geType)); | 63 (kFillAA_GrProcessorEdgeType)); |
| 64 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gConicHairAA, GrConicEffect, |
| 65 (kHairlineAA_GrProcessorEdgeType)); |
| 66 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gConicFillBW, GrConicEffect, |
| 67 (kFillBW_GrProcessorEdgeType)); |
| 64 switch (edgeType) { | 68 switch (edgeType) { |
| 65 case kFillAA_GrEffectEdgeType: | 69 case kFillAA_GrProcessorEdgeType: |
| 66 if (!caps.shaderDerivativeSupport()) { | 70 if (!caps.shaderDerivativeSupport()) { |
| 67 return NULL; | 71 return NULL; |
| 68 } | 72 } |
| 69 gConicFillAA->ref(); | 73 gConicFillAA->ref(); |
| 70 return gConicFillAA; | 74 return gConicFillAA; |
| 71 case kHairlineAA_GrEffectEdgeType: | 75 case kHairlineAA_GrProcessorEdgeType: |
| 72 if (!caps.shaderDerivativeSupport()) { | 76 if (!caps.shaderDerivativeSupport()) { |
| 73 return NULL; | 77 return NULL; |
| 74 } | 78 } |
| 75 gConicHairAA->ref(); | 79 gConicHairAA->ref(); |
| 76 return gConicHairAA; | 80 return gConicHairAA; |
| 77 case kFillBW_GrEffectEdgeType: | 81 case kFillBW_GrProcessorEdgeType: |
| 78 gConicFillBW->ref(); | 82 gConicFillBW->ref(); |
| 79 return gConicFillBW; | 83 return gConicFillBW; |
| 80 default: | 84 default: |
| 81 return NULL; | 85 return NULL; |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 | 88 |
| 85 virtual ~GrConicEffect(); | 89 virtual ~GrConicEffect(); |
| 86 | 90 |
| 87 static const char* Name() { return "Conic"; } | 91 static const char* Name() { return "Conic"; } |
| 88 | 92 |
| 89 inline const GrShaderVar& inConicCoeffs() const { return fInConicCoeffs; } | 93 inline const GrShaderVar& inConicCoeffs() const { return fInConicCoeffs; } |
| 90 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType);
} | 94 inline bool isAntiAliased() const { return GrProcessorEdgeTypeIsAA(fEdgeType
); } |
| 91 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } | 95 inline bool isFilled() const { return GrProcessorEdgeTypeIsFill(fEdgeType);
} |
| 92 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 96 inline GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 93 | 97 |
| 94 typedef GrGLConicEffect GLEffect; | 98 typedef GrGLConicEffect GLProcessor; |
| 95 | 99 |
| 96 virtual void getConstantColorComponents(GrColor* color, | 100 virtual void getConstantColorComponents(GrColor* color, |
| 97 uint32_t* validFlags) const SK_OVERR
IDE { | 101 uint32_t* validFlags) const SK_OVERR
IDE { |
| 98 *validFlags = 0; | 102 *validFlags = 0; |
| 99 } | 103 } |
| 100 | 104 |
| 101 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 105 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR
IDE; |
| 102 | 106 |
| 103 private: | 107 private: |
| 104 GrConicEffect(GrEffectEdgeType); | 108 GrConicEffect(GrPrimitiveEdgeType); |
| 105 | 109 |
| 106 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 110 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE; |
| 107 | 111 |
| 108 GrEffectEdgeType fEdgeType; | 112 GrPrimitiveEdgeType fEdgeType; |
| 109 const GrShaderVar& fInConicCoeffs; | 113 const GrShaderVar& fInConicCoeffs; |
| 110 | 114 |
| 111 GR_DECLARE_EFFECT_TEST; | 115 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 112 | 116 |
| 113 typedef GrGeometryProcessor INHERITED; | 117 typedef GrGeometryProcessor INHERITED; |
| 114 }; | 118 }; |
| 115 | 119 |
| 116 /////////////////////////////////////////////////////////////////////////////// | 120 /////////////////////////////////////////////////////////////////////////////// |
| 117 /** | 121 /** |
| 118 * The output of this effect is a hairline edge for quadratics. | 122 * The output of this effect is a hairline edge for quadratics. |
| 119 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first | 123 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
| 120 * two components of the vertex attribute. At the three control points that defi
ne | 124 * two components of the vertex attribute. At the three control points that defi
ne |
| 121 * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively. | 125 * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively. |
| 122 * Coverage for AA is min(0, 1-distance). 3rd & 4th cimponent unused. | 126 * Coverage for AA is min(0, 1-distance). 3rd & 4th cimponent unused. |
| 123 * Requires shader derivative instruction support. | 127 * Requires shader derivative instruction support. |
| 124 */ | 128 */ |
| 125 class GrGLQuadEffect; | 129 class GrGLQuadEffect; |
| 126 | 130 |
| 127 class GrQuadEffect : public GrGeometryProcessor { | 131 class GrQuadEffect : public GrGeometryProcessor { |
| 128 public: | 132 public: |
| 129 static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetC
aps& caps) { | 133 static GrGeometryProcessor* Create(const GrPrimitiveEdgeType edgeType, |
| 130 GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrEffectEdge
Type)); | 134 const GrDrawTargetCaps& caps) { |
| 131 GR_CREATE_STATIC_EFFECT(gQuadHairAA, GrQuadEffect, (kHairlineAA_GrEffect
EdgeType)); | 135 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gQuadFillAA, GrQuadEffect, |
| 132 GR_CREATE_STATIC_EFFECT(gQuadFillBW, GrQuadEffect, (kFillBW_GrEffectEdge
Type)); | 136 (kFillAA_GrProcessorEdgeType)); |
| 137 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gQuadHairAA, GrQuadEffect, |
| 138 (kHairlineAA_GrProcessorEdgeType)); |
| 139 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gQuadFillBW, GrQuadEffect, |
| 140 (kFillBW_GrProcessorEdgeType)); |
| 133 switch (edgeType) { | 141 switch (edgeType) { |
| 134 case kFillAA_GrEffectEdgeType: | 142 case kFillAA_GrProcessorEdgeType: |
| 135 if (!caps.shaderDerivativeSupport()) { | 143 if (!caps.shaderDerivativeSupport()) { |
| 136 return NULL; | 144 return NULL; |
| 137 } | 145 } |
| 138 gQuadFillAA->ref(); | 146 gQuadFillAA->ref(); |
| 139 return gQuadFillAA; | 147 return gQuadFillAA; |
| 140 case kHairlineAA_GrEffectEdgeType: | 148 case kHairlineAA_GrProcessorEdgeType: |
| 141 if (!caps.shaderDerivativeSupport()) { | 149 if (!caps.shaderDerivativeSupport()) { |
| 142 return NULL; | 150 return NULL; |
| 143 } | 151 } |
| 144 gQuadHairAA->ref(); | 152 gQuadHairAA->ref(); |
| 145 return gQuadHairAA; | 153 return gQuadHairAA; |
| 146 case kFillBW_GrEffectEdgeType: | 154 case kFillBW_GrProcessorEdgeType: |
| 147 gQuadFillBW->ref(); | 155 gQuadFillBW->ref(); |
| 148 return gQuadFillBW; | 156 return gQuadFillBW; |
| 149 default: | 157 default: |
| 150 return NULL; | 158 return NULL; |
| 151 } | 159 } |
| 152 } | 160 } |
| 153 | 161 |
| 154 virtual ~GrQuadEffect(); | 162 virtual ~GrQuadEffect(); |
| 155 | 163 |
| 156 static const char* Name() { return "Quad"; } | 164 static const char* Name() { return "Quad"; } |
| 157 | 165 |
| 158 inline const GrShaderVar& inHairQuadEdge() const { return fInHairQuadEdge; } | 166 inline const GrShaderVar& inHairQuadEdge() const { return fInHairQuadEdge; } |
| 159 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType);
} | 167 inline bool isAntiAliased() const { return GrProcessorEdgeTypeIsAA(fEdgeType
); } |
| 160 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } | 168 inline bool isFilled() const { return GrProcessorEdgeTypeIsFill(fEdgeType);
} |
| 161 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 169 inline GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 162 | 170 |
| 163 typedef GrGLQuadEffect GLEffect; | 171 typedef GrGLQuadEffect GLProcessor; |
| 164 | 172 |
| 165 virtual void getConstantColorComponents(GrColor* color, | 173 virtual void getConstantColorComponents(GrColor* color, |
| 166 uint32_t* validFlags) const SK_OVERR
IDE { | 174 uint32_t* validFlags) const SK_OVERR
IDE { |
| 167 *validFlags = 0; | 175 *validFlags = 0; |
| 168 } | 176 } |
| 169 | 177 |
| 170 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 178 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR
IDE; |
| 171 | 179 |
| 172 private: | 180 private: |
| 173 GrQuadEffect(GrEffectEdgeType); | 181 GrQuadEffect(GrPrimitiveEdgeType); |
| 174 | 182 |
| 175 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 183 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE; |
| 176 | 184 |
| 177 GrEffectEdgeType fEdgeType; | 185 GrPrimitiveEdgeType fEdgeType; |
| 178 const GrShaderVar& fInHairQuadEdge; | 186 const GrShaderVar& fInHairQuadEdge; |
| 179 | 187 |
| 180 GR_DECLARE_EFFECT_TEST; | 188 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 181 | 189 |
| 182 typedef GrGeometryProcessor INHERITED; | 190 typedef GrGeometryProcessor INHERITED; |
| 183 }; | 191 }; |
| 184 | 192 |
| 185 ////////////////////////////////////////////////////////////////////////////// | 193 ////////////////////////////////////////////////////////////////////////////// |
| 186 /** | 194 /** |
| 187 * Shader is based off of "Resolution Independent Curve Rendering using | 195 * Shader is based off of "Resolution Independent Curve Rendering using |
| 188 * Programmable Graphics Hardware" by Loop and Blinn. | 196 * Programmable Graphics Hardware" by Loop and Blinn. |
| 189 * The output of this effect is a hairline edge for non rational cubics. | 197 * The output of this effect is a hairline edge for non rational cubics. |
| 190 * Cubics are specified by implicit equation K^3 - LM. | 198 * Cubics are specified by implicit equation K^3 - LM. |
| 191 * K, L, and M, are the first three values of the vertex attribute, | 199 * K, L, and M, are the first three values of the vertex attribute, |
| 192 * the fourth value is not used. Distance is calculated using a | 200 * the fourth value is not used. Distance is calculated using a |
| 193 * first order approximation from the taylor series. | 201 * first order approximation from the taylor series. |
| 194 * Coverage for AA is max(0, 1-distance). | 202 * Coverage for AA is max(0, 1-distance). |
| 195 */ | 203 */ |
| 196 class GrGLCubicEffect; | 204 class GrGLCubicEffect; |
| 197 | 205 |
| 198 class GrCubicEffect : public GrGeometryProcessor { | 206 class GrCubicEffect : public GrGeometryProcessor { |
| 199 public: | 207 public: |
| 200 static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetC
aps& caps) { | 208 static GrGeometryProcessor* Create(const GrPrimitiveEdgeType edgeType, |
| 201 GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrEffectEd
geType)); | 209 const GrDrawTargetCaps& caps) { |
| 202 GR_CREATE_STATIC_EFFECT(gCubicHairAA, GrCubicEffect, (kHairlineAA_GrEffe
ctEdgeType)); | 210 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gCubicFillAA, GrCubicEffect, |
| 203 GR_CREATE_STATIC_EFFECT(gCubicFillBW, GrCubicEffect, (kFillBW_GrEffectEd
geType)); | 211 (kFillAA_GrProcessorEdgeType)); |
| 212 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gCubicHairAA, GrCubicEffect, |
| 213 (kHairlineAA_GrProcessorEdgeType)); |
| 214 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gCubicFillBW, GrCubicEffect, |
| 215 (kFillBW_GrProcessorEdgeType)); |
| 204 switch (edgeType) { | 216 switch (edgeType) { |
| 205 case kFillAA_GrEffectEdgeType: | 217 case kFillAA_GrProcessorEdgeType: |
| 206 if (!caps.shaderDerivativeSupport()) { | 218 if (!caps.shaderDerivativeSupport()) { |
| 207 return NULL; | 219 return NULL; |
| 208 } | 220 } |
| 209 gCubicFillAA->ref(); | 221 gCubicFillAA->ref(); |
| 210 return gCubicFillAA; | 222 return gCubicFillAA; |
| 211 case kHairlineAA_GrEffectEdgeType: | 223 case kHairlineAA_GrProcessorEdgeType: |
| 212 if (!caps.shaderDerivativeSupport()) { | 224 if (!caps.shaderDerivativeSupport()) { |
| 213 return NULL; | 225 return NULL; |
| 214 } | 226 } |
| 215 gCubicHairAA->ref(); | 227 gCubicHairAA->ref(); |
| 216 return gCubicHairAA; | 228 return gCubicHairAA; |
| 217 case kFillBW_GrEffectEdgeType: | 229 case kFillBW_GrProcessorEdgeType: |
| 218 gCubicFillBW->ref(); | 230 gCubicFillBW->ref(); |
| 219 return gCubicFillBW; | 231 return gCubicFillBW; |
| 220 default: | 232 default: |
| 221 return NULL; | 233 return NULL; |
| 222 } | 234 } |
| 223 } | 235 } |
| 224 | 236 |
| 225 virtual ~GrCubicEffect(); | 237 virtual ~GrCubicEffect(); |
| 226 | 238 |
| 227 static const char* Name() { return "Cubic"; } | 239 static const char* Name() { return "Cubic"; } |
| 228 | 240 |
| 229 inline const GrShaderVar& inCubicCoeffs() const { return fInCubicCoeffs; } | 241 inline const GrShaderVar& inCubicCoeffs() const { return fInCubicCoeffs; } |
| 230 inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType);
} | 242 inline bool isAntiAliased() const { return GrProcessorEdgeTypeIsAA(fEdgeType
); } |
| 231 inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } | 243 inline bool isFilled() const { return GrProcessorEdgeTypeIsFill(fEdgeType);
} |
| 232 inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 244 inline GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 233 | 245 |
| 234 typedef GrGLCubicEffect GLEffect; | 246 typedef GrGLCubicEffect GLProcessor; |
| 235 | 247 |
| 236 virtual void getConstantColorComponents(GrColor* color, | 248 virtual void getConstantColorComponents(GrColor* color, |
| 237 uint32_t* validFlags) const SK_OVERR
IDE { | 249 uint32_t* validFlags) const SK_OVERR
IDE { |
| 238 *validFlags = 0; | 250 *validFlags = 0; |
| 239 } | 251 } |
| 240 | 252 |
| 241 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 253 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR
IDE; |
| 242 | 254 |
| 243 private: | 255 private: |
| 244 GrCubicEffect(GrEffectEdgeType); | 256 GrCubicEffect(GrPrimitiveEdgeType); |
| 245 | 257 |
| 246 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 258 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE; |
| 247 | 259 |
| 248 GrEffectEdgeType fEdgeType; | 260 GrPrimitiveEdgeType fEdgeType; |
| 249 const GrShaderVar& fInCubicCoeffs; | 261 const GrShaderVar& fInCubicCoeffs; |
| 250 | 262 |
| 251 GR_DECLARE_EFFECT_TEST; | 263 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 252 | 264 |
| 253 typedef GrGeometryProcessor INHERITED; | 265 typedef GrGeometryProcessor INHERITED; |
| 254 }; | 266 }; |
| 255 | 267 |
| 256 #endif | 268 #endif |
| OLD | NEW |