Chromium Code Reviews| Index: src/gpu/effects/GrEdgeEffect.h |
| =================================================================== |
| --- src/gpu/effects/GrEdgeEffect.h (revision 0) |
| +++ src/gpu/effects/GrEdgeEffect.h (working copy) |
| @@ -0,0 +1,84 @@ |
| +/* |
| + * 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 GrEdgeEffect_DEFINED |
| +#define GrEdgeEffect_DEFINED |
| + |
| +#include "GrEffect.h" |
| + |
| +class GrGLEdgeEffect; |
| + |
| +/** |
| + * The output of this effect is one of three different edge types: hairlines, quads, |
| + * and hairline quads. |
| + * |
| + * TODO: Fix the fact that HairLine edge types use y-down coords. |
|
bsalomon
2013/03/25 13:35:54
I think this copied comment is out-of-date. We're
|
| + * (either adjust in VS or use origin_upper_left in GLSL) |
| + */ |
| + |
| +class GrEdgeEffect : public GrEffect { |
| +public: |
| + enum EdgeType { |
| + /* 1-pixel wide line |
| + 2D implicit line eq (a*x + b*y +c = 0). 4th component unused. */ |
| + kHairLine_EdgeType = 0, |
| + /* Quadratic specified by u^2-v canonical coords (only 2 |
| + components used). Coverage based on signed distance with negative |
| + being inside, positive outside. Edge specified in window space |
| + (y-down) */ |
| + kQuad_EdgeType, |
| + /* Same as above but for hairline quadratics. Uses unsigned distance. |
| + Coverage is min(0, 1-distance). 3rd & 4th component unused. */ |
| + kHairQuad_EdgeType, |
| + |
| + kLast_EdgeType = kHairQuad_EdgeType |
| + }; |
| + static const int kEdgeTypeCount = kLast_EdgeType + 1; |
| + |
| + static GrEffectRef* Create(EdgeType type) { |
| + // we go through this so we only have one copy of each effect (stroked/filled) |
| + static SkAutoTUnref<GrEffectRef> gEdgeEffectRef[kEdgeTypeCount] = { |
| + SkAutoTUnref<GrEffectRef>( |
| + CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrEdgeEffect, (kHairLine_EdgeType))))), |
| + SkAutoTUnref<GrEffectRef>( |
| + CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrEdgeEffect, (kQuad_EdgeType))))), |
| + SkAutoTUnref<GrEffectRef>( |
| + CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrEdgeEffect, (kHairQuad_EdgeType))))) |
| + }; |
| + |
| + gEdgeEffectRef[type].get()->ref(); |
| + return gEdgeEffectRef[type]; |
| + } |
| + |
| + virtual ~GrEdgeEffect() {} |
| + |
| + static const char* Name() { return "Edge"; } |
| + |
| + virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
| + |
| + typedef GrGLEdgeEffect GLEffect; |
| + |
| + virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| + |
| + inline EdgeType edgeType() const { return fEdgeType; } |
| + |
| +private: |
| + GrEdgeEffect(EdgeType edgeType); |
| + |
| + virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| + const GrEdgeEffect& qee = CastEffect<GrEdgeEffect>(other); |
| + return qee.fEdgeType == fEdgeType; |
| + } |
| + |
| + EdgeType fEdgeType; |
| + |
| + GR_DECLARE_EFFECT_TEST; |
| + |
| + typedef GrEffect INHERITED; |
| +}; |
| + |
| +#endif |