class AAConvexPathBatch : public GrVertexBatch {
public:
DEFINE_BATCH_CLASS_ID
- struct Geometry {
- GrColor fColor;
- SkMatrix fViewMatrix;
- SkPath fPath;
- };
-
- static GrDrawBatch* Create(const Geometry& geometry) { return new AAConvexPathBatch(geometry); }
+ AAConvexPathBatch(GrColor color, const SkMatrix& viewMatrix, const SkPath& path)
+ : INHERITED(ClassID()) {
+ fGeoData.emplace_back(Geometry{color, viewMatrix, path});
+ // compute bounds
+ fBounds = path.getBounds();
+ viewMatrix.mapRect(&fBounds);
+ }
const char* name() const override { return "AAConvexBatch"; }
}
}
- SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
-
- AAConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) {
- fGeoData.push_back(geometry);
-
- // compute bounds
- fBounds = geometry.fPath.getBounds();
- geometry.fViewMatrix.mapRect(&fBounds);
- }
-
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
AAConvexPathBatch* that = t->cast<AAConvexPathBatch>();
if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
fBatch.fCanTweakAlphaForCoverage = false;
}
- fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin());
+ fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin());
this->joinBounds(that->bounds());
return true;
}
bool fCanTweakAlphaForCoverage;
};
+ struct Geometry {
+ GrColor fColor;
+ SkMatrix fViewMatrix;
+ SkPath fPath;
+ };
+
BatchTracker fBatch;
SkSTArray<1, Geometry, true> fGeoData;
SkASSERT(!args.fDrawContext->isUnifiedMultisampled());
SkASSERT(!args.fShape->isEmpty());
- AAConvexPathBatch::Geometry geometry;
- geometry.fColor = args.fColor;
- geometry.fViewMatrix = *args.fViewMatrix;
- args.fShape->asPath(&geometry.fPath);
+ SkPath path;
+ args.fShape->asPath(&path);
- SkAutoTUnref<GrDrawBatch> batch(AAConvexPathBatch::Create(geometry));
+ SkAutoTUnref<GrDrawBatch> batch(new AAConvexPathBatch(args.fColor, *args.fViewMatrix, path));
GrPipelineBuilder pipelineBuilder(*args.fPaint);
pipelineBuilder.setUserStencil(args.fUserStencilSettings);
#ifdef GR_TEST_UTILS
DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) {
- AAConvexPathBatch::Geometry geometry;
- geometry.fColor = GrRandomColor(random);
- geometry.fViewMatrix = GrTest::TestMatrixInvertible(random);
- geometry.fPath = GrTest::TestPathConvex(random);
+ GrColor color = GrRandomColor(random);
+ SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
+ SkPath path = GrTest::TestPathConvex(random);
- return AAConvexPathBatch::Create(geometry);
+ return new AAConvexPathBatch(color, viewMatrix, path);
}
#endif
typedef SkTDynamicHash<ShapeData, ShapeData::Key> ShapeCache;
typedef GrAADistanceFieldPathRenderer::ShapeDataList ShapeDataList;
- struct Geometry {
- GrShape fShape;
- GrColor fColor;
- bool fAntiAlias;
- };
+ AADistanceFieldPathBatch(GrColor color,
+ const GrShape& shape,
+ bool antiAlias,
+ const SkMatrix& viewMatrix,
+ GrBatchAtlas* atlas,
+ ShapeCache* shapeCache, ShapeDataList* shapeList,
+ bool gammaCorrect)
+ : INHERITED(ClassID()) {
+ SkASSERT(shape.hasUnstyledKey());
+ fBatch.fViewMatrix = viewMatrix;
+ fGeoData.emplace_back(Geometry{color, shape, antiAlias});
- static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix,
- GrBatchAtlas* atlas, ShapeCache* shapeCache,
- ShapeDataList* shapeList, bool gammaCorrect) {
- return new AADistanceFieldPathBatch(geometry, viewMatrix, atlas, shapeCache, shapeList,
- gammaCorrect);
+ fAtlas = atlas;
+ fShapeCache = shapeCache;
+ fShapeList = shapeList;
+ fGammaCorrect = gammaCorrect;
+
+ // Compute bounds
+ fBounds = shape.bounds();
+ viewMatrix.mapRect(&fBounds);
}
const char* name() const override { return "AADistanceFieldPathBatch"; }
this->flush(target, &flushInfo);
}
- AADistanceFieldPathBatch(const Geometry& geometry,
- const SkMatrix& viewMatrix,
- GrBatchAtlas* atlas,
- ShapeCache* shapeCache, ShapeDataList* shapeList,
- bool gammaCorrect)
- : INHERITED(ClassID()) {
- SkASSERT(geometry.fShape.hasUnstyledKey());
- fBatch.fViewMatrix = viewMatrix;
- fGeoData.push_back(geometry);
- SkASSERT(fGeoData[0].fShape.hasUnstyledKey());
-
- fAtlas = atlas;
- fShapeCache = shapeCache;
- fShapeList = shapeList;
- fGammaCorrect = gammaCorrect;
-
- // Compute bounds
- fBounds = geometry.fShape.bounds();
- viewMatrix.mapRect(&fBounds);
- }
-
bool addPathToAtlas(GrVertexBatch::Target* target,
FlushInfo* flushInfo,
GrBatchAtlas* atlas,
bool fCoverageIgnored;
};
+ struct Geometry {
+ GrColor fColor;
+ GrShape fShape;
+ bool fAntiAlias;
+ };
+
BatchTracker fBatch;
SkSTArray<1, Geometry> fGeoData;
GrBatchAtlas* fAtlas;
}
}
- AADistanceFieldPathBatch::Geometry geometry;
- geometry.fShape = *args.fShape;
- geometry.fColor = args.fColor;
- geometry.fAntiAlias = args.fAntiAlias;
-
- SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry,
- *args.fViewMatrix, fAtlas,
- &fShapeCache, &fShapeList,
- args.fGammaCorrect));
+ SkAutoTUnref<GrDrawBatch> batch(new AADistanceFieldPathBatch(args.fColor, *args.fShape,
+ args.fAntiAlias, *args.fViewMatrix,
+ fAtlas, &fShapeCache, &fShapeList,
+ args.fGammaCorrect));
GrPipelineBuilder pipelineBuilder(*args.fPaint);
pipelineBuilder.setUserStencil(args.fUserStencilSettings);
GrColor color = GrRandomColor(random);
bool gammaCorrect = random->nextBool();
- AADistanceFieldPathBatch::Geometry geometry;
// This path renderer only allows fill styles.
GrShape shape(GrTest::TestPath(random), GrStyle::SimpleFill());
- geometry.fShape = shape;
- geometry.fColor = color;
- geometry.fAntiAlias = random->nextBool();
-
- return AADistanceFieldPathBatch::Create(geometry, viewMatrix,
- gTestStruct.fAtlas,
- &gTestStruct.fShapeCache,
- &gTestStruct.fShapeList,
- gammaCorrect);
+ bool antiAlias = random->nextBool();
+
+ return new AADistanceFieldPathBatch(color,
+ shape,
+ antiAlias,
+ viewMatrix,
+ gTestStruct.fAtlas,
+ &gTestStruct.fShapeCache,
+ &gTestStruct.fShapeList,
+ gammaCorrect);
}
#endif
public:
DEFINE_BATCH_CLASS_ID
- struct Geometry {
- GrColor fColor;
- uint8_t fCoverage;
- SkMatrix fViewMatrix;
- SkPath fPath;
- SkIRect fDevClipBounds;
- };
+ AAHairlineBatch(GrColor color,
+ uint8_t coverage,
+ const SkMatrix& viewMatrix,
+ const SkPath& path,
+ SkIRect devClipBounds) : INHERITED(ClassID()) {
+ fGeoData.emplace_back(Geometry{color, coverage, viewMatrix, path, devClipBounds});
+
+ // compute bounds
+ fBounds = path.getBounds();
+ viewMatrix.mapRect(&fBounds);
- static GrDrawBatch* Create(const Geometry& geometry) { return new AAHairlineBatch(geometry); }
+ // This is b.c. hairlines are notionally infinitely thin so without expansion
+ // two overlapping lines could be reordered even though they hit the same pixels.
+ fBounds.outset(0.5f, 0.5f);
+ }
const char* name() const override { return "AAHairlineBatch"; }
fBatch.fCoverage = fGeoData[0].fCoverage;
}
- SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
-
void onPrepareDraws(Target*) const override;
typedef SkTArray<SkPoint, true> PtArray;
typedef SkTArray<int, true> IntArray;
typedef SkTArray<float, true> FloatArray;
- AAHairlineBatch(const Geometry& geometry) : INHERITED(ClassID()) {
- fGeoData.push_back(geometry);
-
- // compute bounds
- fBounds = geometry.fPath.getBounds();
- geometry.fViewMatrix.mapRect(&fBounds);
-
- // This is b.c. hairlines are notionally infinitely thin so without expansion
- // two overlapping lines could be reordered even though they hit the same pixels.
- fBounds.outset(0.5f, 0.5f);
- }
-
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
AAHairlineBatch* that = t->cast<AAHairlineBatch>();
return false;
}
- fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin());
+ fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin());
this->joinBounds(that->bounds());
return true;
}
const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
+
+ struct Geometry {
+ GrColor fColor;
+ uint8_t fCoverage;
+ SkMatrix fViewMatrix;
+ SkPath fPath;
+ SkIRect fDevClipBounds;
+ };
+
struct BatchTracker {
GrColor fColor;
uint8_t fCoverage;
newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff);
}
- AAHairlineBatch::Geometry geometry;
- geometry.fColor = color;
- geometry.fCoverage = newCoverage;
- geometry.fViewMatrix = viewMatrix;
- geometry.fPath = path;
- geometry.fDevClipBounds = devClipBounds;
-
- return AAHairlineBatch::Create(geometry);
+ return new AAHairlineBatch(color, newCoverage, viewMatrix, path, devClipBounds);
}
bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) {