}
void onDraw(SkCanvas* canvas) override {
+ using namespace GrDefaultGeoProcFactory;
GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget();
if (NULL == rt) {
this->drawGpuOnlyMessage(canvas);
return;
}
- static const GrColor color = 0xff000000;
+ Color color(0xff000000);
+ Coverage coverage(Coverage::kSolid_Type);
+ LocalCoords localCoords(LocalCoords::kUnused_Type);
SkAutoTUnref<const GrGeometryProcessor> gp(
- GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, color,
- false, false));
+ GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkMatrix::I()));
SkScalar y = 0;
for (SkTLList<SkPath>::Iter iter(fPaths, SkTLList<SkPath>::Iter::kHead_IterStart);
pipelineBuilder.setRenderTarget(rt);
ConvexPolyTestBatch::Geometry geometry;
- geometry.fColor = color;
+ geometry.fColor = color.fColor;
geometry.fBounds = p.getBounds();
SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geometry));
pipelineBuilder.setRenderTarget(rt);
ConvexPolyTestBatch::Geometry geometry;
- geometry.fColor = color;
+ geometry.fColor = color.fColor;
geometry.fBounds = rect;
SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geometry));
}
static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage,
- const SkMatrix& localMatrix,
+ const SkMatrix& viewMatrix,
bool usesLocalCoords,
bool coverageIgnored) {
- uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType;
- if (!tweakAlphaForCoverage) {
- flags |= GrDefaultGeoProcFactory::kCoverage_GPType;
+ using namespace GrDefaultGeoProcFactory;
+
+ Color color(Color::kAttribute_Type);
+ Coverage::Type coverageType;
+ // TODO remove coverage if coverage is ignored
+ /*if (coverageIgnored) {
+ coverageType = Coverage::kNone_Type;
+ } else*/ if (tweakAlphaForCoverage) {
+ coverageType = Coverage::kSolid_Type;
+ } else {
+ coverageType = Coverage::kAttribute_Type;
}
-
- return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoords, coverageIgnored,
- SkMatrix::I(), localMatrix);
+ Coverage coverage(coverageType);
+ LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type :
+ LocalCoords::kUnused_Type);
+ return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix);
}
class AAConvexPathBatch : public GrBatch {
void generateGeometryLinesOnly(GrBatchTarget* batchTarget, const GrPipeline* pipeline) {
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
- SkMatrix invert;
- if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
- SkDebugf("Could not invert viewmatrix\n");
+ // Setup GrGeometryProcessor
+ SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaForCoverage,
+ this->viewMatrix(),
+ this->usesLocalCoords(),
+ this->coverageIgnored()));
+ if (!gp) {
+ SkDebugf("Could not create GrGeometryProcessor\n");
return;
}
- // Setup GrGeometryProcessor
- SkAutoTUnref<const GrGeometryProcessor> gp(
- create_fill_gp(canTweakAlphaForCoverage, invert,
- this->usesLocalCoords(),
- this->coverageIgnored()));
-
batchTarget->initDraw(gp, pipeline);
size_t vertexStride = gp->getVertexStride();
toSrc = &invert;
}
- // Setup geometry processors for worst case
- uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType |
- GrDefaultGeoProcFactory::kCoverage_GPType;
-
- SkAutoTUnref<const GrGeometryProcessor> lineGP(
- GrDefaultGeoProcFactory::Create(gpFlags,
- this->color(),
- this->usesLocalCoords(),
- this->coverageIgnored(),
- *geometryProcessorViewM,
- *geometryProcessorLocalM,
- this->coverage()));
+ SkAutoTUnref<const GrGeometryProcessor> lineGP;
+ {
+ using namespace GrDefaultGeoProcFactory;
+
+ Color color(this->color());
+ Coverage coverage(Coverage::kAttribute_Type);
+ LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUsePosition_Type :
+ LocalCoords::kUnused_Type);
+ localCoords.fMatrix = geometryProcessorLocalM;
+ lineGP.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoords,
+ *geometryProcessorViewM));
+ }
SkAutoTUnref<const GrGeometryProcessor> quadGP(
GrQuadEffect::Create(this->color(),
}
static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage,
- const SkMatrix& localMatrix,
+ const SkMatrix& viewMatrix,
bool usesLocalCoords,
bool coverageIgnored) {
- uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType;
- if (!tweakAlphaForCoverage) {
- flags |= GrDefaultGeoProcFactory::kCoverage_GPType;
+ using namespace GrDefaultGeoProcFactory;
+
+ Color color(Color::kAttribute_Type);
+ Coverage::Type coverageType;
+ // TODO remove coverage if coverage is ignored
+ /*if (coverageIgnored) {
+ coverageType = Coverage::kNone_Type;
+ } else*/ if (tweakAlphaForCoverage) {
+ coverageType = Coverage::kSolid_Type;
+ } else {
+ coverageType = Coverage::kAttribute_Type;
}
-
- return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoords, coverageIgnored,
- SkMatrix::I(), localMatrix);
+ Coverage coverage(coverageType);
+ LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type :
+ LocalCoords::kUnused_Type);
+ return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix);
}
class AAFlatteningConvexPathBatch : public GrBatch {
void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
- SkMatrix invert;
- if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
- SkDebugf("Could not invert viewmatrix\n");
+ // Setup GrGeometryProcessor
+ SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaForCoverage,
+ this->viewMatrix(),
+ this->usesLocalCoords(),
+ this->coverageIgnored()));
+ if (!gp) {
+ SkDebugf("Couldn't create a GrGeometryProcessor\n");
return;
}
- // Setup GrGeometryProcessor
- SkAutoTUnref<const GrGeometryProcessor> gp(
- create_fill_gp(canTweakAlphaForCoverage, invert,
- this->usesLocalCoords(),
- this->coverageIgnored()));
-
batchTarget->initDraw(gp, pipeline);
size_t vertexStride = gp->getVertexStride();
}
static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage,
- const SkMatrix& localMatrix,
+ const SkMatrix& viewMatrix,
bool usesLocalCoords,
bool coverageIgnored) {
- uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType;
- const GrGeometryProcessor* gp;
- if (tweakAlphaForCoverage) {
- gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoords, coverageIgnored,
- SkMatrix::I(), localMatrix);
+ using namespace GrDefaultGeoProcFactory;
+
+ Color color(Color::kAttribute_Type);
+ Coverage::Type coverageType;
+ // TODO remove coverage if coverage is ignored
+ /*if (coverageIgnored) {
+ coverageType = Coverage::kNone_Type;
+ } else*/ if (tweakAlphaForCoverage) {
+ coverageType = Coverage::kSolid_Type;
} else {
- flags |= GrDefaultGeoProcFactory::kCoverage_GPType;
- gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoords, coverageIgnored,
- SkMatrix::I(), localMatrix);
+ coverageType = Coverage::kAttribute_Type;
}
- return gp;
+ Coverage coverage(coverageType);
+ LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type :
+ LocalCoords::kUnused_Type);
+ return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix);
}
GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey);
void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
- SkMatrix localMatrix;
- if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) {
- SkDebugf("Cannot invert\n");
- return;
- }
-
SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakAlphaForCoverage,
- localMatrix,
+ this->viewMatrix(),
this->usesLocalCoords(),
this->coverageIgnored()));
+ if (!gp) {
+ SkDebugf("Couldn't create GrGeometryProcessor\n");
+ return;
+ }
batchTarget->initDraw(gp, pipeline);
void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
- // Local matrix is ignored if we don't have local coords. If we have localcoords we only
- // batch with identical view matrices
- SkMatrix localMatrix;
- if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) {
- SkDebugf("Cannot invert\n");
- return;
- }
-
SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakAlphaForCoverage,
- localMatrix,
+ this->viewMatrix(),
this->usesLocalCoords(),
this->coverageIgnored()));
+ if (!gp) {
+ SkDebugf("Couldn't create GrGeometryProcessor\n");
+ return;
+ }
batchTarget->initDraw(gp, pipeline);
GrRandomCoverage(d->fRandom));
}
-const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags,
- GrColor color,
- bool localCoordsWillBeRead,
- bool coverageWillBeIgnored,
- const SkMatrix& viewMatrix,
- const SkMatrix& localMatrix,
- uint8_t coverage) {
- return DefaultGeoProc::Create(gpTypeFlags,
- color,
- viewMatrix,
- localMatrix,
- localCoordsWillBeRead,
- coverageWillBeIgnored,
- coverage);
-}
-
const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(const Color& color,
const Coverage& coverage,
const LocalCoords& localCoords,
const Coverage& coverage,
const LocalCoords& localCoords,
const SkMatrix& viewMatrix) {
- SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType);
SkMatrix invert = SkMatrix::I();
- if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) {
- SkDebugf("Could not invert\n");
- return NULL;
- }
+ if (LocalCoords::kUnused_Type != localCoords.fType) {
+ SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType);
+ if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) {
+ SkDebugf("Could not invert\n");
+ return NULL;
+ }
- if (localCoords.hasLocalMatrix()) {
- invert.preConcat(*localCoords.fMatrix);
+ if (localCoords.hasLocalMatrix()) {
+ invert.preConcat(*localCoords.fMatrix);
+ }
}
LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert);
- return Create(color, coverage, inverted);
+ return Create(color, coverage, inverted, SkMatrix::I());
}
const GrGeometryProcessor* Create(const Color&,
const Coverage&,
const LocalCoords&,
- const SkMatrix& viewMatrix = SkMatrix::I());
+ const SkMatrix& viewMatrix);
/*
* Use this factory to create a GrGeometryProcessor that expects a device space vertex position
const LocalCoords&,
const SkMatrix& viewMatrix);
- // TODO deprecate this
- const GrGeometryProcessor* Create(uint32_t gpTypeFlags,
- GrColor,
- bool localCoordsWillBeRead,
- bool coverageWillBeIgnored,
- const SkMatrix& viewMatrix = SkMatrix::I(),
- const SkMatrix& localMatrix = SkMatrix::I(),
- uint8_t coverage = 0xff);
-
inline size_t DefaultVertexStride() { return sizeof(PositionAttr); }
};
}
void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
- SkAutoTUnref<const GrGeometryProcessor> gp(
- GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType,
- this->color(),
- this->usesLocalCoords(),
- this->coverageIgnored(),
- this->viewMatrix(),
- SkMatrix::I(),
- this->coverage()));
+ SkAutoTUnref<const GrGeometryProcessor> gp;
+ {
+ using namespace GrDefaultGeoProcFactory;
+ Color color(this->color());
+ Coverage coverage(this->coverage());
+ if (this->coverageIgnored()) {
+ coverage.fType = Coverage::kNone_Type;
+ }
+ LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUsePosition_Type :
+ LocalCoords::kUnused_Type);
+ gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoords,
+ this->viewMatrix()));
+ }
size_t vertexStride = gp->getVertexStride();
SkASSERT(vertexStride == sizeof(SkPoint));
}
void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
- SkAutoTUnref<const GrGeometryProcessor> gp(
- GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType,
- this->color(),
- this->usesLocalCoords(),
- this->coverageIgnored(),
- this->viewMatrix(),
- SkMatrix::I()));
+ SkAutoTUnref<const GrGeometryProcessor> gp;
+ {
+ using namespace GrDefaultGeoProcFactory;
+ Color color(this->color());
+ Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type :
+ Coverage::kNone_Type);
+ LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUsePosition_Type :
+ LocalCoords::kUnused_Type);
+ gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoords,
+ this->viewMatrix()));
+ }
batchTarget->initDraw(gp, pipeline);
GrColor color,
const SkMatrix& viewMatrix,
bool coverageIgnored) {
+ using namespace GrDefaultGeoProcFactory;
*texOffset = -1;
*colorOffset = -1;
- uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType;
+ Color gpColor(color);
+ if (hasColors) {
+ gpColor.fType = Color::kAttribute_Type;
+ }
+
+ Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_Type);
+ LocalCoords localCoords(hasLocalCoords ? LocalCoords::kHasExplicit_Type :
+ LocalCoords::kUsePosition_Type);
if (hasLocalCoords && hasColors) {
*colorOffset = sizeof(SkPoint);
*texOffset = sizeof(SkPoint) + sizeof(GrColor);
- flags |= GrDefaultGeoProcFactory::kColor_GPType |
- GrDefaultGeoProcFactory::kLocalCoord_GPType;
} else if (hasLocalCoords) {
*texOffset = sizeof(SkPoint);
- flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType;
} else if (hasColors) {
*colorOffset = sizeof(SkPoint);
- flags |= GrDefaultGeoProcFactory::kColor_GPType;
}
- return GrDefaultGeoProcFactory::Create(flags, color, hasLocalCoords, coverageIgnored,
- viewMatrix, SkMatrix::I());
+ return GrDefaultGeoProcFactory::Create(gpColor, coverage, localCoords, viewMatrix);
}
class DrawVerticesBatch : public GrBatch {
// generate vertex local coords
if (this->hasLocalRect()) {
LocalCoords localCoords(LocalCoords::kHasExplicit_Type);
- return GrDefaultGeoProcFactory::Create(color, coverage, localCoords);
+ return GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkMatrix::I());
} else {
LocalCoords localCoords(LocalCoords::kUsePosition_Type,
this->hasLocalMatrix() ? &this->localMatrix() : NULL);
}
LOG("got %d pts, %d contours\n", maxPts, contourCnt);
- uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType;
- SkAutoTUnref<const GrGeometryProcessor> gp(
- GrDefaultGeoProcFactory::Create(flags, fColor, fPipelineInfo.readsLocalCoords(),
- !fPipelineInfo.readsCoverage(), fViewMatrix,
- SkMatrix::I()));
+ SkAutoTUnref<const GrGeometryProcessor> gp;
+ {
+ using namespace GrDefaultGeoProcFactory;
+
+ Color color(fColor);
+ LocalCoords localCoords(fPipelineInfo.readsLocalCoords() ?
+ LocalCoords::kUsePosition_Type :
+ LocalCoords::kUnused_Type);
+ Coverage::Type coverageType;
+ if (fPipelineInfo.readsCoverage()) {
+ coverageType = Coverage::kSolid_Type;
+ } else {
+ coverageType = Coverage::kNone_Type;
+ }
+ Coverage coverage(coverageType);
+ gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoords,
+ fViewMatrix));
+ }
batchTarget->initDraw(gp, pipeline);
SkAutoTDeleteArray<Vertex*> contours(SkNEW_ARRAY(Vertex *, contourCnt));
void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
int instanceCount = fGeoData.count();
-
- SkMatrix invert;
- if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
- SkDebugf("Failed to invert\n");
- return;
- }
-
SkPaint::Cap cap = this->cap();
-
- SkAutoTUnref<const GrGeometryProcessor> gp;
-
bool isRoundCap = SkPaint::kRound_Cap == cap;
DashCap capType = isRoundCap ? kRound_DashCap : kNonRound_DashCap;
+
+ SkAutoTUnref<const GrGeometryProcessor> gp;
if (this->fullDash()) {
- gp.reset(create_dash_gp(this->color(), this->aaMode(), capType, invert,
+ gp.reset(create_dash_gp(this->color(), this->aaMode(), capType, this->viewMatrix(),
this->usesLocalCoords()));
} else {
// Set up the vertex data for the line and start/end dashes
- gp.reset(GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType,
- this->color(),
- this->usesLocalCoords(),
- this->coverageIgnored(),
- SkMatrix::I(),
- invert));
+ using namespace GrDefaultGeoProcFactory;
+ Color color(this->color());
+ Coverage coverage(this->coverageIgnored() ? Coverage::kNone_Type :
+ Coverage::kSolid_Type);
+ LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUsePosition_Type :
+ LocalCoords::kUnused_Type);
+ gp.reset(CreateForDeviceSpace(color, coverage, localCoords, this->viewMatrix()));
+ }
+
+ if (!gp) {
+ SkDebugf("Could not create GrGeometryProcessor\n");
+ return;
}
batchTarget->initDraw(gp, pipeline);
static GrGeometryProcessor* create_dash_gp(GrColor color,
DashAAMode dashAAMode,
DashCap cap,
- const SkMatrix& localMatrix,
+ const SkMatrix& viewMatrix,
bool usesLocalCoords) {
+ SkMatrix invert;
+ if (usesLocalCoords && !viewMatrix.invert(&invert)) {
+ SkDebugf("Failed to invert\n");
+ return NULL;
+ }
+
switch (cap) {
case kRound_DashCap:
- return DashingCircleEffect::Create(color, dashAAMode, localMatrix, usesLocalCoords);
+ return DashingCircleEffect::Create(color, dashAAMode, invert, usesLocalCoords);
case kNonRound_DashCap:
- return DashingLineEffect::Create(color, dashAAMode, localMatrix, usesLocalCoords);
- default:
- SkFAIL("Unexpected dashed cap.");
+ return DashingLineEffect::Create(color, dashAAMode, invert, usesLocalCoords);
}
return NULL;
}