diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-26 14:45:27 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-26 14:45:27 +0000 |
commit | 4647f9059825c062169d4d454c12640d82ae16c0 (patch) | |
tree | 9f7f237472cecc53d47400d3a718a2d1a7d6aad3 /src/gpu/effects/GrEdgeEffect.h | |
parent | 36ee020fc7da44465382eb7771935385093e5f33 (diff) |
Replace edge types with GrEdgeEffect.
This strips out last of the edge types and the fixed function edge attribute and replaces them with using GrEdgeEffect. Also fixes a minor bug when checking attribute counts -- it was using kAttribIndexCount instead of kVertexAttribCnt.
Original Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/13069003
git-svn-id: http://skia.googlecode.com/svn/trunk@8392 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/effects/GrEdgeEffect.h')
-rw-r--r-- | src/gpu/effects/GrEdgeEffect.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/gpu/effects/GrEdgeEffect.h b/src/gpu/effects/GrEdgeEffect.h new file mode 100644 index 0000000000..c6238a2e09 --- /dev/null +++ b/src/gpu/effects/GrEdgeEffect.h @@ -0,0 +1,85 @@ +/* + * 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. + */ + +class GrEdgeEffect : public GrEffect { +public: + enum EdgeType { + /* 1-pixel wide line + 2D implicit device coord line eq (a*x + b*y +c = 0). 4th component unused. */ + kHairLine_EdgeType = 0, + /* Quadratic specified by 0=u^2-v canonical coords. u and v are the first + two components of the vertex attribute. Coverage is based on signed + distance with negative being inside, positive outside. The edge is specified in + window space (y-down). If either the third or fourth component of the interpolated + vertex coord is > 0 then the pixel is considered outside the edge. This is used to + attempt to trim to a portion of the infinite quad. Requires shader derivative + instruction support. */ + kQuad_EdgeType, + /* Similar to above but for hairline quadratics. Uses unsigned distance. + Coverage is min(0, 1-distance). 3rd & 4th component unused. Requires + shader derivative instruction support. */ + 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 + static GrEffectRef* gEdgeEffectRef[kEdgeTypeCount] = { + CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrEdgeEffect, (kHairLine_EdgeType)))), + CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrEdgeEffect, (kQuad_EdgeType)))), + CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrEdgeEffect, (kHairQuad_EdgeType)))), + }; + static SkAutoTUnref<GrEffectRef> gUnref0(gEdgeEffectRef[0]); + static SkAutoTUnref<GrEffectRef> gUnref1(gEdgeEffectRef[1]); + static SkAutoTUnref<GrEffectRef> gUnref2(gEdgeEffectRef[2]); + + gEdgeEffectRef[type]->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; + + 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 |