Even more hiding of Geometry structs in GrBatch subclasses.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2110853004
Review-Url: https://codereview.chromium.org/2110853004
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index eec1389..6b3346c 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -585,10 +585,8 @@
AutoCheckFlush acf(fDrawingManager);
- GrDrawAtlasBatch::Geometry geometry;
- geometry.fColor = paint.getColor();
- SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount,
- xform, texRect, colors));
+ SkAutoTUnref<GrDrawBatch> batch(new GrDrawAtlasBatch(paint.getColor(), viewMatrix, spriteCount,
+ xform, texRect, colors));
GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint));
this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
diff --git a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
index 9748829..c799237 100644
--- a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
@@ -122,17 +122,26 @@
public:
DEFINE_BATCH_CLASS_ID
- struct Geometry {
- GrColor fColor;
- SkMatrix fViewMatrix;
- SkPath fPath;
- SkScalar fStrokeWidth;
- SkPaint::Join fJoin;
- SkScalar fMiterLimit;
- };
+ AAFlatteningConvexPathBatch(GrColor color,
+ const SkMatrix& viewMatrix,
+ const SkPath& path,
+ SkScalar strokeWidth,
+ SkPaint::Join join,
+ SkScalar miterLimit) : INHERITED(ClassID()) {
+ fGeoData.emplace_back(Geometry{color, viewMatrix, path, strokeWidth, join, miterLimit});
- static GrDrawBatch* Create(const Geometry& geometry) {
- return new AAFlatteningConvexPathBatch(geometry);
+ // compute bounds
+ fBounds = path.getBounds();
+ SkScalar w = strokeWidth;
+ if (w > 0) {
+ w /= 2;
+ // If the half stroke width is < 1 then we effectively fallback to bevel joins.
+ if (SkPaint::kMiter_Join == join && w > 1.f) {
+ w *= miterLimit;
+ }
+ fBounds.outset(w, w);
+ }
+ viewMatrix.mapRect(&fBounds);
}
const char* name() const override { return "AAConvexBatch"; }
@@ -256,25 +265,6 @@
sk_free(indices);
}
- SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
-
- AAFlatteningConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) {
- fGeoData.push_back(geometry);
-
- // compute bounds
- fBounds = geometry.fPath.getBounds();
- SkScalar w = geometry.fStrokeWidth;
- if (w > 0) {
- w /= 2;
- // If the miter limit is < 1 then we effectively fallback to bevel joins.
- if (SkPaint::kMiter_Join == geometry.fJoin && w > 1.f) {
- w *= geometry.fMiterLimit;
- }
- fBounds.outset(w, w);
- }
- geometry.fViewMatrix.mapRect(&fBounds);
- }
-
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
AAFlatteningConvexPathBatch* that = t->cast<AAFlatteningConvexPathBatch>();
if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
@@ -293,7 +283,7 @@
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;
}
@@ -314,6 +304,15 @@
bool fCanTweakAlphaForCoverage;
};
+ struct Geometry {
+ GrColor fColor;
+ SkMatrix fViewMatrix;
+ SkPath fPath;
+ SkScalar fStrokeWidth;
+ SkPaint::Join fJoin;
+ SkScalar fMiterLimit;
+ };
+
BatchTracker fBatch;
SkSTArray<1, Geometry, true> fGeoData;
@@ -326,17 +325,17 @@
SkASSERT(!args.fDrawContext->isUnifiedMultisampled());
SkASSERT(!args.fShape->isEmpty());
- AAFlatteningConvexPathBatch::Geometry geometry;
- geometry.fColor = args.fColor;
- geometry.fViewMatrix = *args.fViewMatrix;
- args.fShape->asPath(&geometry.fPath);
+ SkPath path;
+ args.fShape->asPath(&path);
bool fill = args.fShape->style().isSimpleFill();
const SkStrokeRec& stroke = args.fShape->style().strokeRec();
- geometry.fStrokeWidth = fill ? -1.0f : stroke.getWidth();
- geometry.fJoin = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
- geometry.fMiterLimit = stroke.getMiter();
+ SkScalar strokeWidth = fill ? -1.0f : stroke.getWidth();
+ SkPaint::Join join = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
+ SkScalar miterLimit = stroke.getMiter();
- SkAutoTUnref<GrDrawBatch> batch(AAFlatteningConvexPathBatch::Create(geometry));
+ SkAutoTUnref<GrDrawBatch> batch(new AAFlatteningConvexPathBatch(args.fColor, *args.fViewMatrix,
+ path, strokeWidth, join,
+ miterLimit));
GrPipelineBuilder pipelineBuilder(*args.fPaint);
pipelineBuilder.setUserStencil(args.fUserStencilSettings);
@@ -351,12 +350,13 @@
#ifdef GR_TEST_UTILS
DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) {
- AAFlatteningConvexPathBatch::Geometry geometry;
- geometry.fColor = GrRandomColor(random);
- geometry.fViewMatrix = GrTest::TestMatrixInvertible(random);
- geometry.fPath = GrTest::TestPathConvex(random);
-
- return AAFlatteningConvexPathBatch::Create(geometry);
+ GrColor color = GrRandomColor(random);
+ SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
+ SkPath path = GrTest::TestPathConvex(random);
+ SkScalar strokeWidth = random->nextBool() ? -1.f : 2.f;
+ SkPaint::Join join = SkPaint::kMiter_Join;
+ SkScalar miterLimit = 0.5f;
+ return new AAFlatteningConvexPathBatch(color, viewMatrix, path, strokeWidth, join, miterLimit);
}
#endif
diff --git a/src/gpu/batches/GrDefaultPathRenderer.cpp b/src/gpu/batches/GrDefaultPathRenderer.cpp
index 97200a1..769faa8 100644
--- a/src/gpu/batches/GrDefaultPathRenderer.cpp
+++ b/src/gpu/batches/GrDefaultPathRenderer.cpp
@@ -97,16 +97,22 @@
public:
DEFINE_BATCH_CLASS_ID
- struct Geometry {
- GrColor fColor;
- SkPath fPath;
- SkScalar fTolerance;
- };
+ DefaultPathBatch(GrColor color, const SkPath& path, SkScalar tolerance,
+ uint8_t coverage, const SkMatrix& viewMatrix, bool isHairline,
+ const SkRect& devBounds)
+ : INHERITED(ClassID()) {
+ fBatch.fCoverage = coverage;
+ fBatch.fIsHairline = isHairline;
+ fBatch.fViewMatrix = viewMatrix;
+ fGeoData.emplace_back(Geometry{color, path, tolerance});
- static GrDrawBatch* Create(const Geometry& geometry, uint8_t coverage,
- const SkMatrix& viewMatrix, bool isHairline,
- const SkRect& devBounds) {
- return new DefaultPathBatch(geometry, coverage, viewMatrix, isHairline, devBounds);
+ this->setBounds(devBounds);
+
+ // 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.
+ if (isHairline) {
+ fBounds.outset(0.5f, 0.5f);
+ }
}
const char* name() const override { return "DefaultPathBatch"; }
@@ -256,25 +262,6 @@
target->putBackVertices((size_t)(maxVertices - vertexOffset), (size_t)vertexStride);
}
- SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
-
- DefaultPathBatch(const Geometry& geometry, uint8_t coverage, const SkMatrix& viewMatrix,
- bool isHairline, const SkRect& devBounds)
- : INHERITED(ClassID()) {
- fBatch.fCoverage = coverage;
- fBatch.fIsHairline = isHairline;
- fBatch.fViewMatrix = viewMatrix;
- fGeoData.push_back(geometry);
-
- this->setBounds(devBounds);
-
- // 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.
- if (isHairline) {
- fBounds.outset(0.5f, 0.5f);
- }
- }
-
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
DefaultPathBatch* that = t->cast<DefaultPathBatch>();
if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
@@ -298,7 +285,7 @@
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;
}
@@ -417,6 +404,12 @@
bool fIsHairline;
};
+ struct Geometry {
+ GrColor fColor;
+ SkPath fPath;
+ SkScalar fTolerance;
+ };
+
BatchTracker fBatch;
SkSTArray<1, Geometry, true> fGeoData;
@@ -577,14 +570,9 @@
drawContext->drawBatch(pipelineBuilder, clip, batch);
} else {
- DefaultPathBatch::Geometry geometry;
- geometry.fColor = color;
- geometry.fPath = path;
- geometry.fTolerance = srcSpaceTol;
-
- SkAutoTUnref<GrDrawBatch> batch(DefaultPathBatch::Create(geometry, newCoverage,
- viewMatrix, isHairline,
- devBounds));
+ SkAutoTUnref<GrDrawBatch> batch(new DefaultPathBatch(color, path, srcSpaceTol,
+ newCoverage, viewMatrix,
+ isHairline, devBounds));
GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint));
pipelineBuilder.setDrawFace(drawFace[p]);
@@ -654,14 +642,9 @@
SkScalar tol = GrPathUtils::kDefaultTolerance;
SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bounds);
- DefaultPathBatch::Geometry geometry;
- geometry.fColor = color;
- geometry.fPath = path;
- geometry.fTolerance = srcSpaceTol;
-
viewMatrix.mapRect(&bounds);
uint8_t coverage = GrRandomCoverage(random);
- return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds);
+ return new DefaultPathBatch(color, path, srcSpaceTol, coverage, viewMatrix, true, bounds);
}
#endif
diff --git a/src/gpu/batches/GrDrawAtlasBatch.cpp b/src/gpu/batches/GrDrawAtlasBatch.cpp
index 5b823a9..9a8952f 100644
--- a/src/gpu/batches/GrDrawAtlasBatch.cpp
+++ b/src/gpu/batches/GrDrawAtlasBatch.cpp
@@ -82,15 +82,16 @@
helper.recordDraw(target, gp.get());
}
-GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& viewMatrix,
- int spriteCount, const SkRSXform* xforms, const SkRect* rects,
+GrDrawAtlasBatch::GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, int spriteCount,
+ const SkRSXform* xforms, const SkRect* rects,
const SkColor* colors)
- : INHERITED(ClassID()) {
+ : INHERITED(ClassID()) {
SkASSERT(xforms);
SkASSERT(rects);
fViewMatrix = viewMatrix;
- Geometry& installedGeo = fGeoData.push_back(geometry);
+ Geometry& installedGeo = fGeoData.push_back();
+ installedGeo.fColor = color;
// Figure out stride and offsets
// Order within the vertex is: position [color] texCoord
@@ -188,7 +189,7 @@
if (this->color() != that->color()) {
fColor = GrColor_ILLEGAL;
}
- fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin());
+ fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin());
fQuadCount += that->quadCount();
this->joinBounds(that->bounds());
@@ -256,10 +257,9 @@
SkMatrix viewMatrix = GrTest::TestMatrix(random);
- GrDrawAtlasBatch::Geometry geometry;
- geometry.fColor = GrRandomColor(random);
- return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.begin(),
- texRects.begin(), hasColors ? colors.begin() : nullptr);
+ GrColor color = GrRandomColor(random);
+ return new GrDrawAtlasBatch(color, viewMatrix, spriteCount, xforms.begin(), texRects.begin(),
+ hasColors ? colors.begin() : nullptr);
}
#endif
diff --git a/src/gpu/batches/GrDrawAtlasBatch.h b/src/gpu/batches/GrDrawAtlasBatch.h
index 0a3d613..d9adf22 100644
--- a/src/gpu/batches/GrDrawAtlasBatch.h
+++ b/src/gpu/batches/GrDrawAtlasBatch.h
@@ -16,16 +16,8 @@
public:
DEFINE_BATCH_CLASS_ID
- struct Geometry {
- GrColor fColor;
- SkTArray<uint8_t, true> fVerts;
- };
-
- static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix,
- int spriteCount, const SkRSXform* xforms, const SkRect* rects,
- const SkColor* colors) {
- return new GrDrawAtlasBatch(geometry, viewMatrix, spriteCount, xforms, rects, colors);
- }
+ GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, int spriteCount,
+ const SkRSXform* xforms, const SkRect* rects, const SkColor* colors);
const char* name() const override { return "DrawAtlasBatch"; }
@@ -41,16 +33,11 @@
coverage->setKnownSingleComponent(0xff);
}
- SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
-
private:
void onPrepareDraws(Target*) const override;
void initBatchTracker(const GrXPOverridesForBatch&) override;
- GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& viewMatrix, int spriteCount,
- const SkRSXform* xforms, const SkRect* rects, const SkColor* colors);
-
GrColor color() const { return fColor; }
bool colorIgnored() const { return fColorIgnored; }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
@@ -59,6 +46,12 @@
bool coverageIgnored() const { return fCoverageIgnored; }
bool onCombineIfPossible(GrBatch* t, const GrCaps&) override;
+
+ struct Geometry {
+ GrColor fColor;
+ SkTArray<uint8_t, true> fVerts;
+ };
+
SkSTArray<1, Geometry, true> fGeoData;
SkMatrix fViewMatrix;