aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-07-13 16:42:55 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-13 21:52:14 +0000
commitb295573c93e7a9a78ee736a399c256d7669b79be (patch)
tree9ccfb5619baf4bc9a98fb8e07c72d5e45d0a4eda /src
parentb76a72a659f53b8bf449c5ca2685045d08a21e43 (diff)
Move GrAALinearizingConvexPathRenderer off GrLegacyMeshDrawOp
Change-Id: I7d3c4053d4a833215371d77de683964cef317a5c Reviewed-on: https://skia-review.googlesource.com/20460 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp157
1 files changed, 73 insertions, 84 deletions
diff --git a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
index ec8013cd3c..9a5f5b04dd 100644
--- a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
@@ -6,7 +6,6 @@
*/
#include "GrAALinearizingConvexPathRenderer.h"
-
#include "GrAAConvexTessellator.h"
#include "GrContext.h"
#include "GrDefaultGeoProcFactory.h"
@@ -23,6 +22,7 @@
#include "SkTraceEvent.h"
#include "glsl/GrGLSLGeometryProcessor.h"
#include "ops/GrMeshDrawOp.h"
+#include "ops/GrSimpleMeshDrawOpHelper.h"
static const int DEFAULT_BUFFER_SIZE = 100;
@@ -121,44 +121,37 @@ static sk_sp<GrGeometryProcessor> create_lines_only_gp(bool tweakAlphaForCoverag
viewMatrix);
}
-class AAFlatteningConvexPathOp final : public GrLegacyMeshDrawOp {
-public:
- DEFINE_OP_CLASS_ID
- static std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color,
- const SkMatrix& viewMatrix,
- const SkPath& path,
- SkScalar strokeWidth,
- SkStrokeRec::Style style,
- SkPaint::Join join,
- SkScalar miterLimit) {
- return std::unique_ptr<GrLegacyMeshDrawOp>(new AAFlatteningConvexPathOp(
- color, viewMatrix, path, strokeWidth, style, join, miterLimit));
- }
+namespace {
- const char* name() const override { return "AAFlatteningConvexPathOp"; }
+class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
+private:
+ using Helper = GrSimpleMeshDrawOpHelperWithStencil;
- SkString dumpInfo() const override {
- SkString string;
- for (const auto& path : fPaths) {
- string.appendf(
- "Color: 0x%08x, StrokeWidth: %.2f, Style: %d, Join: %d, "
- "MiterLimit: %.2f\n",
- path.fColor, path.fStrokeWidth, path.fStyle, path.fJoin, path.fMiterLimit);
- }
- string.append(DumpPipelineInfo(*this->pipeline()));
- string.append(INHERITED::dumpInfo());
- return string;
+public:
+ DEFINE_OP_CLASS_ID
+ static std::unique_ptr<GrDrawOp> Make(GrPaint&& paint,
+ const SkMatrix& viewMatrix,
+ const SkPath& path,
+ SkScalar strokeWidth,
+ SkStrokeRec::Style style,
+ SkPaint::Join join,
+ SkScalar miterLimit,
+ const GrUserStencilSettings* stencilSettings) {
+ return Helper::FactoryHelper<AAFlatteningConvexPathOp>(std::move(paint), viewMatrix, path,
+ strokeWidth, style, join, miterLimit,
+ stencilSettings);
}
-private:
- AAFlatteningConvexPathOp(GrColor color,
+ AAFlatteningConvexPathOp(const Helper::MakeArgs& helperArgs,
+ GrColor color,
const SkMatrix& viewMatrix,
const SkPath& path,
SkScalar strokeWidth,
SkStrokeRec::Style style,
SkPaint::Join join,
- SkScalar miterLimit)
- : INHERITED(ClassID()) {
+ SkScalar miterLimit,
+ const GrUserStencilSettings* stencilSettings)
+ : INHERITED(ClassID()), fHelper(helperArgs, GrAAType::kCoverage, stencilSettings) {
fPaths.emplace_back(
PathData{color, viewMatrix, path, strokeWidth, style, join, miterLimit});
@@ -176,20 +169,32 @@ private:
this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kYes, IsZeroArea::kNo);
}
- void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color,
- GrProcessorAnalysisCoverage* coverage) const override {
- color->setToConstant(fPaths[0].fColor);
- *coverage = GrProcessorAnalysisCoverage::kSingleChannel;
+ const char* name() const override { return "AAFlatteningConvexPathOp"; }
+
+ SkString dumpInfo() const override {
+ SkString string;
+ for (const auto& path : fPaths) {
+ string.appendf(
+ "Color: 0x%08x, StrokeWidth: %.2f, Style: %d, Join: %d, "
+ "MiterLimit: %.2f\n",
+ path.fColor, path.fStrokeWidth, path.fStyle, path.fJoin, path.fMiterLimit);
+ }
+ string += fHelper.dumpInfo();
+ string += INHERITED::dumpInfo();
+ return string;
}
- void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
- optimizations.getOverrideColorIfSet(&fPaths[0].fColor);
- fUsesLocalCoords = optimizations.readsLocalCoords();
- fCanTweakAlphaForCoverage = optimizations.canTweakAlphaForCoverage();
+ FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
+
+ RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
+ return fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kSingleChannel,
+ &fPaths.back().fColor);
}
- void draw(GrLegacyMeshDrawOp::Target* target, const GrGeometryProcessor* gp, int vertexCount,
- size_t vertexStride, void* vertices, int indexCount, uint16_t* indices) const {
+private:
+ void draw(GrMeshDrawOp::Target* target, const GrGeometryProcessor* gp,
+ const GrPipeline* pipeline, int vertexCount, size_t vertexStride, void* vertices,
+ int indexCount, uint16_t* indices) const {
if (vertexCount == 0 || indexCount == 0) {
return;
}
@@ -214,15 +219,16 @@ private:
memcpy(idxs, indices, indexCount * sizeof(uint16_t));
mesh.setIndexed(indexBuffer, indexCount, firstIndex, 0, vertexCount - 1);
mesh.setVertexData(vertexBuffer, firstVertex);
- target->draw(gp, this->pipeline(), mesh);
+ target->draw(gp, pipeline, mesh);
}
void onPrepareDraws(Target* target) const override {
- bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
+ const GrPipeline* pipeline = fHelper.makePipeline(target);
// Setup GrGeometryProcessor
- sk_sp<GrGeometryProcessor> gp(create_lines_only_gp(
- canTweakAlphaForCoverage, this->viewMatrix(), this->usesLocalCoords()));
+ sk_sp<GrGeometryProcessor> gp(create_lines_only_gp(fHelper.compatibleWithAlphaAsCoverage(),
+ this->viewMatrix(),
+ fHelper.usesLocalCoords()));
if (!gp) {
SkDebugf("Couldn't create a GrGeometryProcessor\n");
return;
@@ -230,9 +236,10 @@ private:
size_t vertexStride = gp->getVertexStride();
- SkASSERT(canTweakAlphaForCoverage ?
- vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
- vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
+ SkASSERT(fHelper.compatibleWithAlphaAsCoverage()
+ ? vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
+ : vertexStride ==
+ sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
int instanceCount = fPaths.count();
@@ -256,8 +263,8 @@ private:
if (indexCount + currentIndices > UINT16_MAX) {
// if we added the current instance, we would overflow the indices we can store in a
// uint16_t. Draw what we've got so far and reset.
- this->draw(target, gp.get(),
- vertexCount, vertexStride, vertices, indexCount, indices);
+ this->draw(target, gp.get(), pipeline, vertexCount, vertexStride, vertices,
+ indexCount, indices);
vertexCount = 0;
indexCount = 0;
}
@@ -272,40 +279,28 @@ private:
}
extract_verts(tess, vertices + vertexStride * vertexCount, vertexStride, args.fColor,
- vertexCount, indices + indexCount, canTweakAlphaForCoverage);
+ vertexCount, indices + indexCount,
+ fHelper.compatibleWithAlphaAsCoverage());
vertexCount += currentVertices;
indexCount += currentIndices;
}
- this->draw(target, gp.get(), vertexCount, vertexStride, vertices, indexCount, indices);
+ this->draw(target, gp.get(), pipeline, vertexCount, vertexStride, vertices, indexCount,
+ indices);
sk_free(vertices);
sk_free(indices);
}
bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
AAFlatteningConvexPathOp* that = t->cast<AAFlatteningConvexPathOp>();
- if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
- that->bounds(), caps)) {
+ if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
return false;
}
- SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
- if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
- return false;
- }
-
- // In the event of two ops, one who can tweak, one who cannot, we just fall back to not
- // tweaking
- if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()) {
- fCanTweakAlphaForCoverage = false;
- }
-
fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
this->joinBounds(*that);
return true;
}
- bool usesLocalCoords() const { return fUsesLocalCoords; }
- bool canTweakAlphaForCoverage() const { return fCanTweakAlphaForCoverage; }
const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
struct PathData {
@@ -318,13 +313,14 @@ private:
SkScalar fMiterLimit;
};
- bool fUsesLocalCoords;
- bool fCanTweakAlphaForCoverage;
SkSTArray<1, PathData, true> fPaths;
+ Helper fHelper;
- typedef GrLegacyMeshDrawOp INHERITED;
+ typedef GrMeshDrawOp INHERITED;
};
+} // anonymous namespace
+
bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrAALinearizingConvexPathRenderer::onDrawPath");
@@ -340,16 +336,10 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
SkPaint::Join join = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
SkScalar miterLimit = stroke.getMiter();
- std::unique_ptr<GrLegacyMeshDrawOp> op =
- AAFlatteningConvexPathOp::Make(args.fPaint.getColor(), *args.fViewMatrix, path,
- strokeWidth, stroke.getStyle(), join, miterLimit);
-
- GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
- pipelineBuilder.setUserStencil(args.fUserStencilSettings);
-
- args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip,
- std::move(op));
-
+ std::unique_ptr<GrDrawOp> op = AAFlatteningConvexPathOp::Make(
+ std::move(args.fPaint), *args.fViewMatrix, path, strokeWidth, stroke.getStyle(), join,
+ miterLimit, args.fUserStencilSettings);
+ args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
return true;
}
@@ -357,8 +347,7 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
#if GR_TEST_UTILS
-GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(AAFlatteningConvexPathOp) {
- GrColor color = GrRandomColor(random);
+GR_DRAW_OP_TEST_DEFINE(AAFlatteningConvexPathOp) {
SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
SkPath path = GrTest::TestPathConvex(random);
@@ -381,9 +370,9 @@ GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(AAFlatteningConvexPathOp) {
}
miterLimit = random->nextRangeF(0.5f, 2.0f);
}
-
- return AAFlatteningConvexPathOp::Make(color, viewMatrix, path, strokeWidth, style, join,
- miterLimit);
+ const GrUserStencilSettings* stencilSettings = GrGetRandomStencil(random, context);
+ return AAFlatteningConvexPathOp::Make(std::move(paint), viewMatrix, path, strokeWidth, style,
+ join, miterLimit, stencilSettings);
}
#endif