Index: src/gpu/effects/GrConvexPolyEffect.cpp |
diff --git a/src/gpu/effects/GrConvexPolyEffect.cpp b/src/gpu/effects/GrConvexPolyEffect.cpp |
index baad92837c233721542a4d723bb3c354d154824b..0793befb57c1b9d1903001b971163fc08a12f070 100644 |
--- a/src/gpu/effects/GrConvexPolyEffect.cpp |
+++ b/src/gpu/effects/GrConvexPolyEffect.cpp |
@@ -19,13 +19,12 @@ class GLAARectEffect; |
class AARectEffect : public GrEffect { |
public: |
typedef GLAARectEffect GLEffect; |
- typedef GrConvexPolyEffect::EdgeType EdgeType; |
const SkRect& getRect() const { return fRect; } |
static const char* Name() { return "AARect"; } |
- static GrEffectRef* Create(EdgeType edgeType, const SkRect& rect) { |
+ static GrEffectRef* Create(GrEffectEdgeType edgeType, const SkRect& rect) { |
return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(AARectEffect, (edgeType, rect)))); |
} |
@@ -40,12 +39,12 @@ public: |
} |
} |
- GrConvexPolyEffect::EdgeType getEdgeType() const { return fEdgeType; } |
+ GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
private: |
- AARectEffect(EdgeType edgeType, const SkRect& rect) : fRect(rect), fEdgeType(edgeType) { |
+ AARectEffect(GrEffectEdgeType edgeType, const SkRect& rect) : fRect(rect), fEdgeType(edgeType) { |
this->setWillReadFragmentPosition(); |
} |
@@ -55,7 +54,7 @@ private: |
} |
SkRect fRect; |
- EdgeType fEdgeType; |
+ GrEffectEdgeType fEdgeType; |
typedef GrEffect INHERITED; |
@@ -69,14 +68,18 @@ GrEffectRef* AARectEffect::TestCreate(SkRandom* random, |
GrContext*, |
const GrDrawTargetCaps& caps, |
GrTexture*[]) { |
- EdgeType edgeType = static_cast<EdgeType>( |
- random->nextULessThan(GrConvexPolyEffect::kEdgeTypeCnt)); |
- |
SkRect rect = SkRect::MakeLTRB(random->nextSScalar1(), |
random->nextSScalar1(), |
random->nextSScalar1(), |
random->nextSScalar1()); |
- return AARectEffect::Create(edgeType, rect); |
+ GrEffectRef* effect; |
+ do { |
+ GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextULessThan( |
+ kGrEffectEdgeTypeCnt)); |
+ |
+ effect = AARectEffect::Create(edgeType, rect); |
+ } while (NULL == effect); |
+ return effect; |
} |
////////////////////////////////////////////////////////////////////////////// |
@@ -125,8 +128,7 @@ void GLAARectEffect::emitCode(GrGLShaderBuilder* builder, |
"rect", |
&rectName); |
const char* fragmentPos = builder->fragmentPosition(); |
- if (GrConvexPolyEffect::kFillAA_EdgeType == aare.getEdgeType() || |
- GrConvexPolyEffect::kInverseFillAA_EdgeType == aare.getEdgeType()) { |
+ if (GrEffectEdgeTypeIsAA(aare.getEdgeType())) { |
// The amount of coverage removed in x and y by the edges is computed as a pair of negative |
// numbers, xSub and ySub. |
builder->fsCodeAppend("\t\tfloat xSub, ySub;\n"); |
@@ -145,8 +147,7 @@ void GLAARectEffect::emitCode(GrGLShaderBuilder* builder, |
builder->fsCodeAppendf("\t\talpha *= (%s.w - %s.y) > 0.5 ? 1.0 : 0.0;\n", rectName, fragmentPos); |
} |
- if (GrConvexPolyEffect::kInverseFillAA_EdgeType == aare.getEdgeType() || |
- GrConvexPolyEffect::kInverseFillNoAA_EdgeType == aare.getEdgeType()) { |
+ if (GrEffectEdgeTypeIsInverseFill(aare.getEdgeType())) { |
builder->fsCodeAppend("\t\talpha = 1.0 - alpha;\n"); |
} |
builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
@@ -223,15 +224,10 @@ void GrGLConvexPolyEffect::emitCode(GrGLShaderBuilder* builder, |
for (int i = 0; i < cpe.getEdgeCount(); ++i) { |
builder->fsCodeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n", |
edgeArrayName, i, fragmentPos, fragmentPos); |
- switch (cpe.getEdgeType()) { |
- case GrConvexPolyEffect::kFillAA_EdgeType: |
- case GrConvexPolyEffect::kInverseFillAA_EdgeType: // inverse handled at the end |
- builder->fsCodeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); |
- break; |
- case GrConvexPolyEffect::kFillNoAA_EdgeType: |
- case GrConvexPolyEffect::kInverseFillNoAA_EdgeType: // inverse handled at the end |
- builder->fsCodeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); |
- break; |
+ if (GrEffectEdgeTypeIsAA(cpe.getEdgeType())) { |
+ builder->fsCodeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); |
+ } else { |
+ builder->fsCodeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); |
} |
builder->fsCodeAppend("\t\talpha *= edge;\n"); |
} |
@@ -241,8 +237,7 @@ void GrGLConvexPolyEffect::emitCode(GrGLShaderBuilder* builder, |
builder->fsCodeAppend("\t\tif (-1.0 == alpha) {\n\t\t\tdiscard;\n\t\t}\n"); |
} |
- if (GrConvexPolyEffect::kInverseFillAA_EdgeType == cpe.getEdgeType() || |
- GrConvexPolyEffect::kInverseFillNoAA_EdgeType == cpe.getEdgeType() ) { |
+ if (GrEffectEdgeTypeIsInverseFill(cpe.getEdgeType())) { |
builder->fsCodeAppend("\talpha = 1.0 - alpha;\n"); |
} |
builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
@@ -261,16 +256,18 @@ void GrGLConvexPolyEffect::setData(const GrGLUniformManager& uman, const GrDrawE |
GrGLEffect::EffectKey GrGLConvexPolyEffect::GenKey(const GrDrawEffect& drawEffect, |
const GrGLCaps&) { |
const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); |
- GR_STATIC_ASSERT(GrConvexPolyEffect::kEdgeTypeCnt <= 4); |
- return (cpe.getEdgeCount() << 2) | cpe.getEdgeType(); |
+ GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); |
+ return (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); |
} |
////////////////////////////////////////////////////////////////////////////// |
-GrEffectRef* GrConvexPolyEffect::Create(EdgeType type, const SkPath& path, const SkVector* offset) { |
+GrEffectRef* GrConvexPolyEffect::Create(GrEffectEdgeType type, const SkPath& path, const SkVector* offset) { |
+ if (kHairlineAA_GrEffectEdgeType == type) { |
+ return NULL; |
+ } |
if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || |
- !path.isConvex() || |
- path.isInverseFillType()) { |
+ !path.isConvex()) { |
return NULL; |
} |
@@ -309,10 +306,16 @@ GrEffectRef* GrConvexPolyEffect::Create(EdgeType type, const SkPath& path, const |
++n; |
} |
} |
+ if (path.isInverseFillType()) { |
+ type = GrInvertEffectEdgeType(type); |
+ } |
return Create(type, n, edges); |
} |
-GrEffectRef* GrConvexPolyEffect::Create(EdgeType edgeType, const SkRect& rect) { |
+GrEffectRef* GrConvexPolyEffect::Create(GrEffectEdgeType edgeType, const SkRect& rect) { |
+ if (kHairlineAA_GrEffectEdgeType == edgeType){ |
+ return NULL; |
+ } |
return AARectEffect::Create(edgeType, rect); |
} |
@@ -326,7 +329,7 @@ const GrBackendEffectFactory& GrConvexPolyEffect::getFactory() const { |
return GrTBackendEffectFactory<GrConvexPolyEffect>::getInstance(); |
} |
-GrConvexPolyEffect::GrConvexPolyEffect(EdgeType edgeType, int n, const SkScalar edges[]) |
+GrConvexPolyEffect::GrConvexPolyEffect(GrEffectEdgeType edgeType, int n, const SkScalar edges[]) |
: fEdgeType(edgeType) |
, fEdgeCount(n) { |
// Factory function should have already ensured this. |
@@ -355,12 +358,17 @@ GrEffectRef* GrConvexPolyEffect::TestCreate(SkRandom* random, |
GrContext*, |
const GrDrawTargetCaps& caps, |
GrTexture*[]) { |
- EdgeType edgeType = static_cast<EdgeType>(random->nextULessThan(kEdgeTypeCnt)); |
int count = random->nextULessThan(kMaxEdges) + 1; |
SkScalar edges[kMaxEdges * 3]; |
for (int i = 0; i < 3 * count; ++i) { |
edges[i] = random->nextSScalar1(); |
} |
- return GrConvexPolyEffect::Create(edgeType, count, edges); |
+ GrEffectRef* effect; |
+ do { |
+ GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>( |
+ random->nextULessThan(kGrEffectEdgeTypeCnt)); |
+ effect = GrConvexPolyEffect::Create(edgeType, count, edges); |
+ } while (NULL == effect); |
+ return effect; |
} |