Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Unified Diff: src/gpu/effects/GrDashingEffect.cpp

Issue 2042923003: Make GrDashEffect take a AA mode enum. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: rm unneeded scoping Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/effects/GrDashingEffect.cpp
diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp
index 8a38ebe5733e4a69362b07f5397330fa63b9af19..8a7cb5edc4b0ca03afa4aceea0cb6278be99b594 100644
--- a/src/gpu/effects/GrDashingEffect.cpp
+++ b/src/gpu/effects/GrDashingEffect.cpp
@@ -26,6 +26,8 @@
#include "glsl/GrGLSLVarying.h"
#include "glsl/GrGLSLVertexShaderBuilder.h"
+using AAMode = GrDashingEffect::AAMode;
+
///////////////////////////////////////////////////////////////////////////////
// Returns whether or not the gpu can fast path the dash line effect.
@@ -74,14 +76,6 @@ struct DashCircleVertex {
SkScalar fRadius;
SkScalar fCenterX;
};
-
-enum DashAAMode {
- kBW_DashAAMode,
- kEdgeAA_DashAAMode,
- kMSAA_DashAAMode,
-
- kDashAAModeCount,
-};
};
static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale,
@@ -239,7 +233,7 @@ static void setup_dashed_rect_pos(const SkRect& rect, int idx, const SkMatrix& m
* position relative to the dashed line.
*/
static GrGeometryProcessor* create_dash_gp(GrColor,
- DashAAMode aaMode,
+ AAMode aaMode,
DashCap cap,
const SkMatrix& localMatrix,
bool usesLocalCoords);
@@ -247,7 +241,6 @@ static GrGeometryProcessor* create_dash_gp(GrColor,
class DashBatch : public GrVertexBatch {
public:
DEFINE_BATCH_CLASS_ID
-
struct Geometry {
SkMatrix fViewMatrix;
SkMatrix fSrcRotInv;
@@ -260,7 +253,7 @@ public:
GrColor fColor;
};
- static GrDrawBatch* Create(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode,
+ static GrDrawBatch* Create(const Geometry& geometry, SkPaint::Cap cap, AAMode aaMode,
bool fullDash) {
return new DashBatch(geometry, cap, aaMode, fullDash);
}
@@ -278,7 +271,7 @@ public:
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
private:
- DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, bool fullDash)
+ DashBatch(const Geometry& geometry, SkPaint::Cap cap, AAMode aaMode, bool fullDash)
: INHERITED(ClassID()) {
fGeoData.push_back(geometry);
@@ -359,7 +352,7 @@ private:
}
// useAA here means Edge AA or MSAA
- bool useAA = this->aaMode() != kBW_DashAAMode;
+ bool useAA = this->aaMode() != AAMode::kNone;
bool fullDash = this->fullDash();
// We do two passes over all of the dashes. First we setup the start, end, and bounds,
@@ -486,9 +479,13 @@ private:
// For EdgeAA, we bloat in X & Y for both square and round caps.
// For MSAA, we don't bloat at all for square caps, and bloat in Y only for round caps.
- SkScalar devBloatX = this->aaMode() == kEdgeAA_DashAAMode ? 0.5f : 0.0f;
- SkScalar devBloatY = (SkPaint::kRound_Cap == cap && this->aaMode() == kMSAA_DashAAMode)
- ? 0.5f : devBloatX;
+ SkScalar devBloatX = this->aaMode() == AAMode::kCoverage ? 0.5f : 0.0f;
+ SkScalar devBloatY;
+ if (SkPaint::kRound_Cap == cap && this->aaMode() == AAMode::kCoverageWithMSAA) {
+ devBloatY = 0.5f;
+ } else {
+ devBloatY = devBloatX;
+ }
SkScalar bloatX = devBloatX / args.fParallelScale;
SkScalar bloatY = devBloatY / args.fPerpendicularScale;
@@ -665,7 +662,7 @@ private:
GrColor color() const { return fBatch.fColor; }
bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
- DashAAMode aaMode() const { return fBatch.fAAMode; }
+ AAMode aaMode() const { return fBatch.fAAMode; }
bool fullDash() const { return fBatch.fFullDash; }
SkPaint::Cap cap() const { return fBatch.fCap; }
bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
@@ -676,7 +673,7 @@ private:
bool fColorIgnored;
bool fCoverageIgnored;
SkPaint::Cap fCap;
- DashAAMode fAAMode;
+ AAMode fAAMode;
bool fFullDash;
};
@@ -689,8 +686,11 @@ private:
typedef GrVertexBatch INHERITED;
};
-static GrDrawBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, const SkPoint pts[2],
- bool useAA, const GrStyle& style, bool msaaRT) {
+GrDrawBatch* GrDashingEffect::CreateDashLineBatch(GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkPoint pts[2],
+ AAMode aaMode,
+ const GrStyle& style) {
SkASSERT(GrDashingEffect::CanDrawDashLine(pts, style, viewMatrix));
const SkScalar* intervals = style.dashIntervals();
SkScalar phase = style.dashPhase();
@@ -728,11 +728,8 @@ static GrDrawBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, cons
offInterval -= strokeWidth;
}
- DashAAMode aaMode = msaaRT ? kMSAA_DashAAMode :
- useAA ? kEdgeAA_DashAAMode : kBW_DashAAMode;
-
// TODO we can do a real rect call if not using fulldash(ie no off interval, not using AA)
- bool fullDash = offInterval > 0.f || aaMode != kBW_DashAAMode;
+ bool fullDash = offInterval > 0.f || aaMode != AAMode::kNone;
geometry.fColor = color;
geometry.fViewMatrix = viewMatrix;
@@ -743,15 +740,6 @@ static GrDrawBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, cons
return DashBatch::Create(geometry, cap, aaMode, fullDash);
}
-GrDrawBatch* GrDashingEffect::CreateDashLineBatch(GrColor color,
- const SkMatrix& viewMatrix,
- const SkPoint pts[2],
- bool useAA,
- bool msaaIsEnabled,
- const GrStyle& style) {
- return create_batch(color, viewMatrix, pts, useAA, style, msaaIsEnabled);
-}
-
//////////////////////////////////////////////////////////////////////////////
class GLDashingCircleEffect;
@@ -770,7 +758,7 @@ public:
typedef SkPathEffect::DashInfo DashInfo;
static GrGeometryProcessor* Create(GrColor,
- DashAAMode aaMode,
+ AAMode aaMode,
const SkMatrix& localMatrix,
bool usesLocalCoords);
@@ -782,7 +770,7 @@ public:
const Attribute* inCircleParams() const { return fInCircleParams; }
- DashAAMode aaMode() const { return fAAMode; }
+ AAMode aaMode() const { return fAAMode; }
GrColor color() const { return fColor; }
@@ -797,13 +785,13 @@ public:
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const override;
private:
- DashingCircleEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix,
+ DashingCircleEffect(GrColor, AAMode aaMode, const SkMatrix& localMatrix,
bool usesLocalCoords);
GrColor fColor;
SkMatrix fLocalMatrix;
bool fUsesLocalCoords;
- DashAAMode fAAMode;
+ AAMode fAAMode;
const Attribute* fInPosition;
const Attribute* fInDashParams;
const Attribute* fInCircleParams;
@@ -896,7 +884,7 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dashParams.fsIn());
fragBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn());
fragBuilder->codeAppend("float dist = length(center - fragPosShifted);");
- if (dce.aaMode() != kBW_DashAAMode) {
+ if (dce.aaMode() != AAMode::kNone) {
fragBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn());
fragBuilder->codeAppend("diff = 1.0 - diff;");
fragBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);");
@@ -925,14 +913,14 @@ void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp,
uint32_t key = 0;
key |= dce.usesLocalCoords() && dce.localMatrix().hasPerspective() ? 0x1 : 0x0;
key |= dce.colorIgnored() ? 0x2 : 0x0;
- key |= dce.aaMode() << 8;
+ key |= static_cast<uint32_t>(dce.aaMode()) << 8;
b->add32(key);
}
//////////////////////////////////////////////////////////////////////////////
GrGeometryProcessor* DashingCircleEffect::Create(GrColor color,
- DashAAMode aaMode,
+ AAMode aaMode,
const SkMatrix& localMatrix,
bool usesLocalCoords) {
return new DashingCircleEffect(color, aaMode, localMatrix, usesLocalCoords);
@@ -948,7 +936,7 @@ GrGLSLPrimitiveProcessor* DashingCircleEffect::createGLSLInstance(const GrGLSLCa
}
DashingCircleEffect::DashingCircleEffect(GrColor color,
- DashAAMode aaMode,
+ AAMode aaMode,
const SkMatrix& localMatrix,
bool usesLocalCoords)
: fColor(color)
@@ -965,7 +953,7 @@ DashingCircleEffect::DashingCircleEffect(GrColor color,
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect);
const GrGeometryProcessor* DashingCircleEffect::TestCreate(GrProcessorTestData* d) {
- DashAAMode aaMode = static_cast<DashAAMode>(d->fRandom->nextULessThan(kDashAAModeCount));
+ AAMode aaMode = static_cast<AAMode>(d->fRandom->nextULessThan(GrDashingEffect::kAAModeCnt));
return DashingCircleEffect::Create(GrRandomColor(d->fRandom),
aaMode, GrTest::TestMatrix(d->fRandom),
d->fRandom->nextBool());
@@ -989,7 +977,7 @@ public:
typedef SkPathEffect::DashInfo DashInfo;
static GrGeometryProcessor* Create(GrColor,
- DashAAMode aaMode,
+ AAMode aaMode,
const SkMatrix& localMatrix,
bool usesLocalCoords);
@@ -1001,7 +989,7 @@ public:
const Attribute* inRectParams() const { return fInRectParams; }
- DashAAMode aaMode() const { return fAAMode; }
+ AAMode aaMode() const { return fAAMode; }
GrColor color() const { return fColor; }
@@ -1016,13 +1004,13 @@ public:
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const override;
private:
- DashingLineEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix,
+ DashingLineEffect(GrColor, AAMode aaMode, const SkMatrix& localMatrix,
bool usesLocalCoords);
GrColor fColor;
SkMatrix fLocalMatrix;
bool fUsesLocalCoords;
- DashAAMode fAAMode;
+ AAMode fAAMode;
const Attribute* fInPosition;
const Attribute* fInDashParams;
const Attribute* fInRectParams;
@@ -1108,7 +1096,7 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
inDashParams.fsIn(), inDashParams.fsIn(), inDashParams.fsIn(),
inDashParams.fsIn());
fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDashParams.fsIn());
- if (de.aaMode() == kEdgeAA_DashAAMode) {
+ if (de.aaMode() == AAMode::kCoverage) {
// The amount of coverage removed in x and y by the edges is computed as a pair of negative
// numbers, xSub and ySub.
fragBuilder->codeAppend("float xSub, ySub;");
@@ -1120,7 +1108,7 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// covered.
fragBuilder->codeAppendf(
"float alpha = (1.0 + max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));");
- } else if (de.aaMode() == kMSAA_DashAAMode) {
+ } else if (de.aaMode() == AAMode::kCoverageWithMSAA) {
// For MSAA, we don't modulate the alpha by the Y distance, since MSAA coverage will handle
// AA on the the top and bottom edges. The shader is only responsible for intra-dash alpha.
fragBuilder->codeAppend("float xSub;");
@@ -1157,14 +1145,14 @@ void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp,
uint32_t key = 0;
key |= de.usesLocalCoords() && de.localMatrix().hasPerspective() ? 0x1 : 0x0;
key |= de.colorIgnored() ? 0x2 : 0x0;
- key |= de.aaMode() << 8;
+ key |= static_cast<int>(de.aaMode()) << 8;
b->add32(key);
}
//////////////////////////////////////////////////////////////////////////////
GrGeometryProcessor* DashingLineEffect::Create(GrColor color,
- DashAAMode aaMode,
+ AAMode aaMode,
const SkMatrix& localMatrix,
bool usesLocalCoords) {
return new DashingLineEffect(color, aaMode, localMatrix, usesLocalCoords);
@@ -1180,7 +1168,7 @@ GrGLSLPrimitiveProcessor* DashingLineEffect::createGLSLInstance(const GrGLSLCaps
}
DashingLineEffect::DashingLineEffect(GrColor color,
- DashAAMode aaMode,
+ AAMode aaMode,
const SkMatrix& localMatrix,
bool usesLocalCoords)
: fColor(color)
@@ -1196,7 +1184,7 @@ DashingLineEffect::DashingLineEffect(GrColor color,
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect);
const GrGeometryProcessor* DashingLineEffect::TestCreate(GrProcessorTestData* d) {
- DashAAMode aaMode = static_cast<DashAAMode>(d->fRandom->nextULessThan(kDashAAModeCount));
+ AAMode aaMode = static_cast<AAMode>(d->fRandom->nextULessThan(GrDashingEffect::kAAModeCnt));
return DashingLineEffect::Create(GrRandomColor(d->fRandom),
aaMode, GrTest::TestMatrix(d->fRandom),
d->fRandom->nextBool());
@@ -1205,7 +1193,7 @@ const GrGeometryProcessor* DashingLineEffect::TestCreate(GrProcessorTestData* d)
//////////////////////////////////////////////////////////////////////////////
static GrGeometryProcessor* create_dash_gp(GrColor color,
- DashAAMode dashAAMode,
+ AAMode aaMode,
DashCap cap,
const SkMatrix& viewMatrix,
bool usesLocalCoords) {
@@ -1217,9 +1205,9 @@ static GrGeometryProcessor* create_dash_gp(GrColor color,
switch (cap) {
case kRound_DashCap:
- return DashingCircleEffect::Create(color, dashAAMode, invert, usesLocalCoords);
+ return DashingCircleEffect::Create(color, aaMode, invert, usesLocalCoords);
case kNonRound_DashCap:
- return DashingLineEffect::Create(color, dashAAMode, invert, usesLocalCoords);
+ return DashingLineEffect::Create(color, aaMode, invert, usesLocalCoords);
}
return nullptr;
}
@@ -1231,8 +1219,7 @@ static GrGeometryProcessor* create_dash_gp(GrColor color,
DRAW_BATCH_TEST_DEFINE(DashBatch) {
GrColor color = GrRandomColor(random);
SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
- bool useAA = random->nextBool();
- bool msaaRT = random->nextBool();
+ AAMode aaMode = static_cast<AAMode>(random->nextULessThan(GrDashingEffect::kAAModeCnt));
// We can only dash either horizontal or vertical lines
SkPoint pts[2];
@@ -1294,7 +1281,7 @@ DRAW_BATCH_TEST_DEFINE(DashBatch) {
GrStyle style(p);
- return create_batch(color, viewMatrix, pts, useAA, style, msaaRT);
+ return GrDashingEffect::CreateDashLineBatch(color, viewMatrix, pts, aaMode, style);
}
#endif
« src/gpu/batches/GrDashLinePathRenderer.cpp ('K') | « src/gpu/effects/GrDashingEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698