diff options
author | bsalomon <bsalomon@google.com> | 2016-06-30 07:19:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-30 07:19:27 -0700 |
commit | 0432dd6ee62d0c1c1ca67b7f6f6fcf3de75aaf77 (patch) | |
tree | f16030ed5557dd0481a0fa153629516bb62dfb59 /src/gpu/batches | |
parent | 47df89ebfd548de2ccd91387e1d7eee418b65f96 (diff) |
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
Diffstat (limited to 'src/gpu/batches')
-rw-r--r-- | src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp | 88 | ||||
-rw-r--r-- | src/gpu/batches/GrDefaultPathRenderer.cpp | 69 | ||||
-rw-r--r-- | src/gpu/batches/GrDrawAtlasBatch.cpp | 18 | ||||
-rw-r--r-- | src/gpu/batches/GrDrawAtlasBatch.h | 23 |
4 files changed, 87 insertions, 111 deletions
diff --git a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp index 9748829386..c7992373aa 100644 --- a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp +++ b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp @@ -122,17 +122,26 @@ class AAFlatteningConvexPathBatch : public GrVertexBatch { 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 @@ private: 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 @@ private: 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 @@ private: 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 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { 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 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { #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 97200a1981..769faa84b0 100644 --- a/src/gpu/batches/GrDefaultPathRenderer.cpp +++ b/src/gpu/batches/GrDefaultPathRenderer.cpp @@ -97,16 +97,22 @@ class DefaultPathBatch : public GrVertexBatch { 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}); + + this->setBounds(devBounds); - 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 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 @@ private: 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 @@ private: 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 @@ private: bool fIsHairline; }; + struct Geometry { + GrColor fColor; + SkPath fPath; + SkScalar fTolerance; + }; + BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; @@ -577,14 +570,9 @@ bool GrDefaultPathRenderer::internalDrawPath(GrDrawContext* drawContext, 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 @@ DRAW_BATCH_TEST_DEFINE(DefaultPathBatch) { 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 5b823a95a1..9a8952fa3a 100644 --- a/src/gpu/batches/GrDrawAtlasBatch.cpp +++ b/src/gpu/batches/GrDrawAtlasBatch.cpp @@ -82,15 +82,16 @@ void GrDrawAtlasBatch::onPrepareDraws(Target* target) const { 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 @@ bool GrDrawAtlasBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { 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 @@ DRAW_BATCH_TEST_DEFINE(GrDrawAtlasBatch) { 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 0a3d6136be..d9adf22a60 100644 --- a/src/gpu/batches/GrDrawAtlasBatch.h +++ b/src/gpu/batches/GrDrawAtlasBatch.h @@ -16,16 +16,8 @@ class GrDrawAtlasBatch : public GrVertexBatch { 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 @@ public: 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 @@ private: 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; |