Cleanup Default Geo Proc API

TBR=bsalomon@google.com
BUG=skia:

Review URL: https://codereview.chromium.org/1253393002
This commit is contained in:
joshualitt 2015-07-27 12:13:14 -07:00 committed by Commit bot
parent 2c323427cb
commit e9d6095674
3 changed files with 91 additions and 11 deletions

View File

@ -275,3 +275,27 @@ const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags,
coverageWillBeIgnored,
coverage);
}
const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(const Color& color,
const Coverage& coverage,
LocalCoords::Type localCoords,
const SkMatrix& viewMatrix,
const SkMatrix& localMatrix) {
uint32_t flags = 0;
flags |= color.fType == Color::kAttribute_Type ? kColor_GPType : 0;
flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPType : 0;
flags |= localCoords == LocalCoords::kHasExplicit_Type ? kLocalCoord_GPType : 0;
uint8_t inCoverage = coverage.fCoverage;
bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type;
bool localCoordsWillBeRead = localCoords != LocalCoords::kNone_Type;
GrColor inColor = color.fColor;
return DefaultGeoProc::Create(flags,
inColor,
viewMatrix,
localMatrix,
localCoordsWillBeRead,
coverageWillBeIgnored,
inCoverage);
}

View File

@ -73,6 +73,56 @@ public:
kLastGPType = kCoverage_GPType
};
struct Color {
enum Type {
kNone_Type,
kUniform_Type,
kAttribute_Type,
};
Color(GrColor color) : fType(kUniform_Type), fColor(color) {}
Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) {
SkASSERT(type != kUniform_Type);
// TODO This is temporary
if (kAttribute_Type == type) {
fColor = GrColor_WHITE;
}
}
Type fType;
GrColor fColor;
};
struct Coverage {
enum Type {
kNone_Type,
kSolid_Type,
kUniform_Type,
kAttribute_Type,
};
Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
Coverage(Type type) : fType(type), fCoverage(0xff) {
SkASSERT(type != kUniform_Type);
}
Type fType;
uint8_t fCoverage;
};
struct LocalCoords {
enum Type {
kNone_Type,
kUsePosition_Type,
kHasExplicit_Type,
};
};
static const GrGeometryProcessor* Create(const Color&,
const Coverage&,
LocalCoords::Type,
const SkMatrix& viewMatrix = SkMatrix::I(),
const SkMatrix& localMatrix = SkMatrix::I());
/*
* The following functions are used to create default GPs. If you just need to create
* attributes separately from creating the default GP, use the SetAttribs function followed

View File

@ -25,18 +25,24 @@
*/
static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords,
const SkMatrix* localMatrix,
bool usesLocalCoords,
bool coverageIgnored) {
// TODO remove color when we have ignored color from the XP
uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType |
GrDefaultGeoProcFactory::kColor_GPType;
flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0;
if (localMatrix) {
return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoords,
coverageIgnored, SkMatrix::I(), *localMatrix);
typedef GrDefaultGeoProcFactory::Color Color;
typedef GrDefaultGeoProcFactory::Coverage Coverage;
typedef GrDefaultGeoProcFactory::LocalCoords LocalCoords;
Color color(Color::kAttribute_Type);
Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_Type);
LocalCoords::Type localCoords;
if (hasExplicitLocalCoords) {
localCoords = LocalCoords::kHasExplicit_Type;
} else {
return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoords,
coverageIgnored, SkMatrix::I(), SkMatrix::I());
localCoords = LocalCoords::kUsePosition_Type;
}
if (localMatrix) {
return GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkMatrix::I(),
*localMatrix);
} else {
return GrDefaultGeoProcFactory::Create(color, coverage, localCoords);
}
}
@ -101,7 +107,6 @@ public:
SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLocalCoords,
&invert,
this->usesLocalCoords(),
this->coverageIgnored()));
batchTarget->initDraw(gp, pipeline);
@ -129,6 +134,7 @@ public:
geom.fRect.fRight, geom.fRect.fBottom, vertexStride);
geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerticesPerQuad);
// TODO we should only do this if local coords are being read
if (geom.fHasLocalRect) {
static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
SkPoint* coords = reinterpret_cast<SkPoint*>(offset + kLocalOffset);