Chromium Code Reviews| Index: src/gpu/effects/GrBezierEffect.h |
| diff --git a/src/gpu/effects/GrBezierEffect.h b/src/gpu/effects/GrBezierEffect.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..25335c84438f4207f093bc3e8591d1904cbec359 |
| --- /dev/null |
| +++ b/src/gpu/effects/GrBezierEffect.h |
| @@ -0,0 +1,227 @@ |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef GrBezierEffect_DEFINED |
| +#define GrBezierEffect_DEFINED |
| + |
| +#include "GrEffect.h" |
| + |
| +enum BezierEffectType { |
|
bsalomon
2013/08/21 20:04:39
I'm wondering if there is something more specific
egdaniel
2013/08/21 20:18:06
I say either GrBezierEdgeType or Style...wish ther
|
| + kFillAA_BezierEffectType, |
| + kHairAA_BezierEffectType, |
| + kFillNoAA_BezierEffectType, |
| +}; |
| + |
| +/** |
| + * Shader is based off of Loop-Blinn Quadratic GPU Rendering |
|
bsalomon
2013/08/21 20:04:39
Should we merge this comment block with the next o
egdaniel
2013/08/21 20:18:06
Yeah, I just left them separate at first since the
|
| + * The output of this effect is a hairline edge for conics. |
| + * Conics specified by implicit equation K^2 - LM. |
| + * K, L, and M, are the first three values of the vertex attribute, |
| + * the fourth value is not used. Distance is calculated using a |
| + * first order approximation from the taylor series. |
| + * Coverage is max(0, 1-distance). |
| + */ |
| + |
| +/** |
| + * Test were also run using a second order distance approximation. |
| + * There were two versions of the second order approx. The first version |
| + * is of roughly the form: |
| + * f(q) = |f(p)| - ||f'(p)||*||q-p|| - ||f''(p)||*||q-p||^2. |
| + * The second is similar: |
| + * f(q) = |f(p)| + ||f'(p)||*||q-p|| + ||f''(p)||*||q-p||^2. |
| + * The exact version of the equations can be found in the paper |
| + * "Distance Approximations for Rasterizing Implicit Curves" by Gabriel Taubin |
| + * |
| + * In both versions we solve the quadratic for ||q-p||. |
| + * Version 1: |
| + * gFM is magnitude of first partials and gFM2 is magnitude of 2nd partials (as derived from paper) |
| + * builder->fsCodeAppend("\t\tedgeAlpha = (sqrt(gFM*gFM+4.0*func*gF2M) - gFM)/(2.0*gF2M);\n"); |
| + * Version 2: |
| + * builder->fsCodeAppend("\t\tedgeAlpha = (gFM - sqrt(gFM*gFM-4.0*func*gF2M))/(2.0*gF2M);\n"); |
| + * |
| + * Also note that 2nd partials of k,l,m are zero |
| + * |
| + * When comparing the two second order approximations to the first order approximations, |
| + * the following results were found. Version 1 tends to underestimate the distances, thus it |
| + * basically increases all the error that we were already seeing in the first order |
| + * approx. So this version is not the one to use. Version 2 has the opposite effect |
| + * and tends to overestimate the distances. This is much closer to what we are |
| + * looking for. It is able to render ellipses (even thin ones) without the need to chop. |
| + * However, it can not handle thin hyperbolas well and thus would still rely on |
| + * chopping to tighten the clipping. Another side effect of the overestimating is |
| + * that the curves become much thinner and "ropey". If all that was ever rendered |
| + * were "not too thin" curves and ellipses then 2nd order may have an advantage since |
| + * only one geometry would need to be rendered. However no benches were run comparing |
| + * chopped first order and non chopped 2nd order. |
| + */ |
| +class GrGLConicEffect; |
| + |
| +class GrConicEffect : public GrEffect { |
| +public: |
| + static GrEffectRef* Create(BezierEffectType effectType) { |
|
bsalomon
2013/08/21 20:11:29
Do we need to check or assert that we have derivat
egdaniel
2013/08/21 20:18:06
I suppose we should. Before we relied on the PathR
|
| + GR_CREATE_STATIC_EFFECT(gConicFillNoAA, GrConicEffect, (false, true)); |
|
bsalomon
2013/08/21 20:04:39
It seems like we should just plumb the enum value
egdaniel
2013/08/21 20:18:06
Will do
On 2013/08/21 20:04:39, bsalomon wrote:
|
| + GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (true, true)); |
| + GR_CREATE_STATIC_EFFECT(gConicHairAA, GrConicEffect, (true, false)); |
| + if (kFillAA_BezierEffectType == effectType) { |
| + gConicFillAA->ref(); |
| + return gConicFillAA; |
| + } else if (kHairAA_BezierEffectType == effectType) { |
| + gConicHairAA->ref(); |
| + return gConicHairAA; |
| + } else { |
| + gConicFillNoAA->ref(); |
| + return gConicFillNoAA; |
| + } |
| + } |
| + |
| + virtual ~GrConicEffect(); |
| + |
| + static const char* Name() { return "Conic"; } |
| + |
| + inline bool isAntiAliased() const { return fAntiAlias; } |
| + inline bool isFilled() const { return fFill; } |
| + |
| + typedef GrGLConicEffect GLEffect; |
| + |
| + virtual void getConstantColorComponents(GrColor* color, |
| + uint32_t* validFlags) const SK_OVERRIDE { |
| + *validFlags = 0; |
| + } |
| + |
| + virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| + |
| +private: |
| + GrConicEffect(bool antiAlias, bool fill); |
| + |
| + virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| + |
| + bool fAntiAlias; |
| + bool fFill; |
| + |
| + GR_DECLARE_EFFECT_TEST; |
| + |
| + typedef GrEffect INHERITED; |
| +}; |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| +/** |
| + * The output of this effect is a hairline edge for quadratics. |
| + * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
| + * two components of the vertex attribute. Uses unsigned distance. |
| + * Coverage is min(0, 1-distance). 3rd & 4th component unused. |
|
bsalomon
2013/08/21 20:04:39
maybe we should say somewhere in here that uv is {
egdaniel
2013/08/21 20:18:06
Adding it.
On 2013/08/21 20:04:39, bsalomon wrote
|
| + * Requires shader derivative instruction support. |
| + */ |
| +class GrGLQuadEffect; |
| + |
| +class GrQuadEffect : public GrEffect { |
| +public: |
| + static GrEffectRef* Create(BezierEffectType effectType) { |
| + GR_CREATE_STATIC_EFFECT(gQuadFillNoAA, GrQuadEffect, (false, true)); |
| + GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (true, true)); |
| + GR_CREATE_STATIC_EFFECT(gQuadHairAA, GrQuadEffect, (true, false)); |
| + if (kFillAA_BezierEffectType == effectType) { |
| + gQuadFillAA->ref(); |
| + return gQuadFillAA; |
| + } else if (kHairAA_BezierEffectType == effectType) { |
| + gQuadHairAA->ref(); |
| + return gQuadHairAA; |
| + } else { |
| + gQuadFillNoAA->ref(); |
| + return gQuadFillNoAA; |
| + } |
| + } |
| + |
| + virtual ~GrQuadEffect(); |
| + |
| + static const char* Name() { return "Quad"; } |
| + |
| + inline bool isAntiAliased() const { return fAntiAlias; } |
| + inline bool isFilled() const { return fFill; } |
| + |
| + typedef GrGLQuadEffect GLEffect; |
| + |
| + virtual void getConstantColorComponents(GrColor* color, |
| + uint32_t* validFlags) const SK_OVERRIDE { |
| + *validFlags = 0; |
| + } |
| + |
| + virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| + |
| +private: |
| + GrQuadEffect(bool antiAlias, bool fill); |
| + |
| + virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| + |
| + bool fAntiAlias; |
| + bool fFill; |
| + |
| + GR_DECLARE_EFFECT_TEST; |
| + |
| + typedef GrEffect INHERITED; |
| +}; |
| + |
| +////////////////////////////////////////////////////////////////////////////// |
| +/** |
| + * Shader is based off of "Resolution Independent Curve Rendering using |
| + * Programmable Graphics Hardware" by Loop and Blinn. |
| + * The output of this effect is a hairline edge for non rational cubics. |
| + * Cubics are specified by implicit equation K^3 - LM. |
| + * K, L, and M, are the first three values of the vertex attribute, |
| + * the fourth value is not used. Distance is calculated using a |
| + * first order approximation from the taylor series. |
| + * Coverage is max(0, 1-distance). |
| + */ |
| +class GrGLCubicEffect; |
| + |
| +class GrCubicEffect : public GrEffect { |
| +public: |
| + static GrEffectRef* Create(BezierEffectType effectType) { |
| + GR_CREATE_STATIC_EFFECT(gCubicFillNoAA, GrCubicEffect, (false, true)); |
| + GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (true, true)); |
| + GR_CREATE_STATIC_EFFECT(gCubicHairAA, GrCubicEffect, (true, false)); |
| + if (kFillAA_BezierEffectType == effectType) { |
| + gCubicFillAA->ref(); |
| + return gCubicFillAA; |
| + } else if (kHairAA_BezierEffectType == effectType) { |
| + gCubicHairAA->ref(); |
| + return gCubicHairAA; |
| + } else { |
| + gCubicFillNoAA->ref(); |
| + return gCubicFillNoAA; |
| + } |
| + } |
| + |
| + virtual ~GrCubicEffect(); |
| + |
| + static const char* Name() { return "Cubic"; } |
| + |
| + inline bool isAntiAliased() const { return fAntiAlias; } |
| + inline bool isFilled() const { return fFill; } |
| + |
| + typedef GrGLCubicEffect GLEffect; |
| + |
| + virtual void getConstantColorComponents(GrColor* color, |
| + uint32_t* validFlags) const SK_OVERRIDE { |
| + *validFlags = 0; |
| + } |
| + |
| + virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| + |
| +private: |
| + GrCubicEffect(bool antiAlias, bool fill); |
| + |
| + virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| + |
| + bool fAntiAlias; |
| + bool fFill; |
| + |
| + GR_DECLARE_EFFECT_TEST; |
| + |
| + typedef GrEffect INHERITED; |
| +}; |
| + |
| +#endif |