From 3968fcbc3a7ab0f5ecbc24e32bcdb4ec7488d78f Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Thu, 5 Dec 2019 16:40:31 -0500 Subject: [PATCH] Pull creation of GrPipeline explicitly into the Ops' onExecute methods This is a first step towards pulling the creation of the GrProgramInfos explicitly into the Ops' onExecute methods. We need this behavior so programInfo creation can be moved forward to onPrePrepare. For now, pipeline creation is a static member on GrSimpleMeshDrawOpHelper so GrPipeline creation can be bottle-neckedOps for Ops that don't use the helper. In some future world CreatePipeline could become non-static to reduce some of the duplicate code. Bug: skia:9455 Change-Id: I2d35dd223db824e84616f5df0f1dca34c1b6e412 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/258003 Reviewed-by: Michael Ludwig Commit-Queue: Robert Phillips --- bench/VertexColorSpaceBench.cpp | 8 ++- gm/beziereffects.cpp | 8 ++- src/gpu/GrOpFlushState.cpp | 13 +---- src/gpu/GrOpFlushState.h | 6 +-- src/gpu/ccpr/GrStencilAtlasOp.cpp | 7 ++- src/gpu/ops/GrAAConvexPathRenderer.cpp | 7 ++- src/gpu/ops/GrAAHairLinePathRenderer.cpp | 7 ++- .../ops/GrAALinearizingConvexPathRenderer.cpp | 7 ++- src/gpu/ops/GrAtlasTextOp.cpp | 8 ++- src/gpu/ops/GrDashOp.cpp | 10 +++- src/gpu/ops/GrDefaultPathRenderer.cpp | 7 ++- src/gpu/ops/GrDrawAtlasOp.cpp | 6 ++- src/gpu/ops/GrDrawPathOp.cpp | 51 +++++++++---------- src/gpu/ops/GrDrawPathOp.h | 4 +- src/gpu/ops/GrDrawVerticesOp.cpp | 6 ++- src/gpu/ops/GrFillRectOp.cpp | 7 ++- src/gpu/ops/GrLatticeOp.cpp | 6 ++- src/gpu/ops/GrOvalOpFactory.cpp | 36 ++++++++++--- src/gpu/ops/GrRegionOp.cpp | 7 ++- src/gpu/ops/GrShadowRRectOp.cpp | 8 ++- src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp | 36 ++++++------- src/gpu/ops/GrSimpleMeshDrawOpHelper.h | 18 +++++-- src/gpu/ops/GrSmallPathRenderer.cpp | 7 ++- src/gpu/ops/GrStrokeRectOp.cpp | 12 ++++- src/gpu/ops/GrTessellatingPathRenderer.cpp | 7 ++- src/gpu/ops/GrTextureOp.cpp | 9 +++- tests/GrMeshTest.cpp | 20 +++++++- tests/OnFlushCallbackTest.cpp | 6 ++- tests/PrimitiveProcessorTest.cpp | 8 ++- tools/gpu/TestOps.cpp | 7 ++- 30 files changed, 239 insertions(+), 110 deletions(-) diff --git a/bench/VertexColorSpaceBench.cpp b/bench/VertexColorSpaceBench.cpp index ddafc3d572..db2dfa409a 100644 --- a/bench/VertexColorSpaceBench.cpp +++ b/bench/VertexColorSpaceBench.cpp @@ -23,6 +23,7 @@ #include "src/gpu/glsl/GrGLSLVarying.h" #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" #include "src/gpu/ops/GrMeshDrawOp.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" namespace { @@ -235,8 +236,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - flushState->executeDrawsAndUploadsForMeshDrawOp( - this, chainBounds, GrProcessorSet::MakeEmptySet()); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + GrProcessorSet::MakeEmptySet(), + GrPipeline::InputFlags::kNone); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } Mode fMode; diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp index d9442196be..f2674ed410 100644 --- a/gm/beziereffects.cpp +++ b/gm/beziereffects.cpp @@ -46,6 +46,7 @@ #include "src/gpu/ops/GrDrawOp.h" #include "src/gpu/ops/GrMeshDrawOp.h" #include "src/gpu/ops/GrOp.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" #include #include @@ -81,8 +82,11 @@ protected: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - flushState->executeDrawsAndUploadsForMeshDrawOp( - this, chainBounds, std::move(fProcessorSet)); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + std::move(fProcessorSet), + GrPipeline::InputFlags::kNone); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } GrClipEdgeType edgeType() const { return fEdgeType; } diff --git a/src/gpu/GrOpFlushState.cpp b/src/gpu/GrOpFlushState.cpp index 60ffa51c47..cb8b13b796 100644 --- a/src/gpu/GrOpFlushState.cpp +++ b/src/gpu/GrOpFlushState.cpp @@ -32,20 +32,9 @@ const GrCaps& GrOpFlushState::caps() const { } void GrOpFlushState::executeDrawsAndUploadsForMeshDrawOp( - const GrOp* op, const SkRect& chainBounds, GrProcessorSet&& processorSet, - GrPipeline::InputFlags pipelineFlags, const GrUserStencilSettings* stencilSettings) { + const GrOp* op, const SkRect& chainBounds, const GrPipeline* pipeline) { SkASSERT(this->opsRenderPass()); - GrPipeline::InitArgs pipelineArgs; - pipelineArgs.fInputFlags = pipelineFlags; - pipelineArgs.fDstProxyView = this->dstProxyView(); - pipelineArgs.fCaps = &this->caps(); - pipelineArgs.fUserStencil = stencilSettings; - pipelineArgs.fOutputSwizzle = this->drawOpArgs().outputSwizzle(); - auto pipeline = this->allocator()->make(pipelineArgs, - std::move(processorSet), - this->detachAppliedClip()); - while (fCurrDraw != fDraws.end() && fCurrDraw->fOp == op) { GrDeferredUploadToken drawToken = fTokenTracker->nextTokenToFlush(); while (fCurrUpload != fInlineUploads.end() && diff --git a/src/gpu/GrOpFlushState.h b/src/gpu/GrOpFlushState.h index b9340975a9..d4c8f28804 100644 --- a/src/gpu/GrOpFlushState.h +++ b/src/gpu/GrOpFlushState.h @@ -44,10 +44,8 @@ public: void doUpload(GrDeferredTextureUploadFn&, bool shouldPrepareSurfaceForSampling = false); /** Called as ops are executed. Must be called in the same order as the ops were prepared. */ - void executeDrawsAndUploadsForMeshDrawOp( - const GrOp* op, const SkRect& chainBounds, GrProcessorSet&&, - GrPipeline::InputFlags = GrPipeline::InputFlags::kNone, - const GrUserStencilSettings* = &GrUserStencilSettings::kUnused); + void executeDrawsAndUploadsForMeshDrawOp(const GrOp* op, const SkRect& chainBounds, + const GrPipeline*); GrOpsRenderPass* opsRenderPass() { return fOpsRenderPass; } void setOpsRenderPass(GrOpsRenderPass* renderPass) { fOpsRenderPass = renderPass; } diff --git a/src/gpu/ccpr/GrStencilAtlasOp.cpp b/src/gpu/ccpr/GrStencilAtlasOp.cpp index 2fed59ea79..b5caf85bdb 100644 --- a/src/gpu/ccpr/GrStencilAtlasOp.cpp +++ b/src/gpu/ccpr/GrStencilAtlasOp.cpp @@ -119,10 +119,9 @@ static constexpr GrUserStencilSettings kResolveStencilCoverageAndReset( void GrStencilAtlasOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { SkIRect drawBoundsRect = SkIRect::MakeWH(fDrawBounds.width(), fDrawBounds.height()); - GrPipeline pipeline( - GrScissorTest::kEnabled, GrDisableColorXPFactory::MakeXferProcessor(), - flushState->drawOpArgs().outputSwizzle(), GrPipeline::InputFlags::kHWAntialias, - &kIncrDecrStencil); + GrPipeline pipeline(GrScissorTest::kEnabled, GrDisableColorXPFactory::MakeXferProcessor(), + flushState->drawOpArgs().outputSwizzle(), + GrPipeline::InputFlags::kHWAntialias, &kIncrDecrStencil); GrSampleMaskProcessor sampleMaskProc; diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp index 9efdd3a02c..8e66ae84c4 100644 --- a/src/gpu/ops/GrAAConvexPathRenderer.cpp +++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp @@ -821,7 +821,12 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags(), + fHelper.stencilSettings()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp index b41a968cc9..7a6ce00dae 100644 --- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp +++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp @@ -1105,7 +1105,12 @@ void AAHairlineOp::onPrepareDraws(Target* target) { } void AAHairlineOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags(), + fHelper.stencilSettings()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { diff --git a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp index 0f3508ba48..aa8d437c3d 100644 --- a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp +++ b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp @@ -304,7 +304,12 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags(), + fHelper.stencilSettings()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp index d425b713e8..a493fb6615 100644 --- a/src/gpu/ops/GrAtlasTextOp.cpp +++ b/src/gpu/ops/GrAtlasTextOp.cpp @@ -19,6 +19,7 @@ #include "src/gpu/GrResourceProvider.h" #include "src/gpu/effects/GrBitmapTextGeoProc.h" #include "src/gpu/effects/GrDistanceFieldGeoProc.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" #include "src/gpu/text/GrAtlasManager.h" #include "src/gpu/text/GrStrikeCache.h" @@ -393,8 +394,11 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) { } void GrAtlasTextOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { - flushState->executeDrawsAndUploadsForMeshDrawOp( - this, chainBounds, std::move(fProcessors), GrPipeline::InputFlags::kNone); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + std::move(fProcessors), + GrPipeline::InputFlags::kNone); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const { diff --git a/src/gpu/ops/GrDashOp.cpp b/src/gpu/ops/GrDashOp.cpp index ecd5b16646..6643f1ec3f 100644 --- a/src/gpu/ops/GrDashOp.cpp +++ b/src/gpu/ops/GrDashOp.cpp @@ -30,6 +30,7 @@ #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" #include "src/gpu/ops/GrDashOp.h" #include "src/gpu/ops/GrMeshDrawOp.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" using AAMode = GrDashOp::AAMode; @@ -632,8 +633,13 @@ private: if (AAMode::kCoverageWithMSAA == fAAMode) { pipelineFlags |= GrPipeline::InputFlags::kHWAntialias; } - flushState->executeDrawsAndUploadsForMeshDrawOp( - this, chainBounds, std::move(fProcessorSet), pipelineFlags, fStencilSettings); + + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + std::move(fProcessorSet), + pipelineFlags, + fStencilSettings); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/src/gpu/ops/GrDefaultPathRenderer.cpp b/src/gpu/ops/GrDefaultPathRenderer.cpp index 6b8e50222a..e8603357e3 100644 --- a/src/gpu/ops/GrDefaultPathRenderer.cpp +++ b/src/gpu/ops/GrDefaultPathRenderer.cpp @@ -442,7 +442,12 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags(), + fHelper.stencilSettings()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/src/gpu/ops/GrDrawAtlasOp.cpp b/src/gpu/ops/GrDrawAtlasOp.cpp index c8818ecc57..8ffe0d7d18 100644 --- a/src/gpu/ops/GrDrawAtlasOp.cpp +++ b/src/gpu/ops/GrDrawAtlasOp.cpp @@ -214,7 +214,11 @@ void DrawAtlasOp::onPrepareDraws(Target* target) { } void DrawAtlasOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } GrOp::CombineResult DrawAtlasOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { diff --git a/src/gpu/ops/GrDrawPathOp.cpp b/src/gpu/ops/GrDrawPathOp.cpp index f2fdbb2e56..489b7f7cd6 100644 --- a/src/gpu/ops/GrDrawPathOp.cpp +++ b/src/gpu/ops/GrDrawPathOp.cpp @@ -14,6 +14,7 @@ #include "src/gpu/GrRenderTargetContext.h" #include "src/gpu/GrRenderTargetPriv.h" #include "src/gpu/ops/GrDrawPathOp.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" static constexpr GrUserStencilSettings kCoverPass{ GrUserStencilSettings::StaticInit< @@ -43,18 +44,6 @@ SkString GrDrawPathOp::dumpInfo() const { } #endif -GrPipeline::InitArgs GrDrawPathOpBase::pipelineInitArgs(const GrOpFlushState& state) { - GrPipeline::InitArgs args; - if (fDoAA) { - args.fInputFlags |= GrPipeline::InputFlags::kHWAntialias; - } - args.fUserStencil = &kCoverPass; - args.fCaps = &state.caps(); - args.fDstProxyView = state.drawOpArgs().dstProxyView(); - args.fOutputSwizzle = state.drawOpArgs().outputSwizzle(); - return args; -} - const GrProcessorSet::Analysis& GrDrawPathOpBase::doProcessorAnalysis( const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, GrClampType clampType) { @@ -87,34 +76,42 @@ std::unique_ptr GrDrawPathOp::Make(GrRecordingContext* context, return pool->allocate(viewMatrix, std::move(paint), aa, std::move(path)); } -void GrDrawPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) { - GrAppliedClip appliedClip = state->detachAppliedClip(); - +void GrDrawPathOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { GrPipeline::FixedDynamicState* fixedDynamicState = nullptr, storage; - if (appliedClip.scissorState().enabled()) { - storage.fScissorRect = appliedClip.scissorState().rect(); + const GrAppliedClip* appliedClip = flushState->appliedClip(); + if (appliedClip && appliedClip->scissorState().enabled()) { + storage.fScissorRect = appliedClip->scissorState().rect(); fixedDynamicState = &storage; } - GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(), - std::move(appliedClip)); + GrPipeline::InputFlags pipelineFlags = GrPipeline::InputFlags::kNone; + if (this->doAA()) { + pipelineFlags |= GrPipeline::InputFlags::kHWAntialias; + } + + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + this->detachProcessorSet(), + pipelineFlags, + &kCoverPass); + sk_sp pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix())); - GrProgramInfo programInfo(state->proxy()->numSamples(), - state->proxy()->numStencilSamples(), - state->proxy()->backendFormat(), - state->view()->origin(), - &pipeline, + GrRenderTargetProxy* proxy = flushState->proxy(); + GrProgramInfo programInfo(proxy->numSamples(), + proxy->numStencilSamples(), + proxy->backendFormat(), + flushState->view()->origin(), + pipeline, pathProc.get(), fixedDynamicState, nullptr, 0, GrPrimitiveType::kPath); GrStencilSettings stencil; - init_stencil_pass_settings(*state, this->fillType(), &stencil); - state->gpu()->pathRendering()->drawPath(state->drawOpArgs().proxy()->peekRenderTarget(), - programInfo, stencil, fPath.get()); + init_stencil_pass_settings(*flushState, this->fillType(), &stencil); + flushState->gpu()->pathRendering()->drawPath(proxy->peekRenderTarget(), + programInfo, stencil, fPath.get()); } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/ops/GrDrawPathOp.h b/src/gpu/ops/GrDrawPathOp.h index f40c2b96b9..c11be49d79 100644 --- a/src/gpu/ops/GrDrawPathOp.h +++ b/src/gpu/ops/GrDrawPathOp.h @@ -43,9 +43,9 @@ protected: const SkMatrix& viewMatrix() const { return fViewMatrix; } const SkPMColor4f& color() const { return fInputColor; } GrPathRendering::FillType fillType() const { return fFillType; } + bool doAA() const { return fDoAA; } const GrProcessorSet& processors() const { return fProcessorSet; } - GrProcessorSet detachProcessors() { return std::move(fProcessorSet); } - inline GrPipeline::InitArgs pipelineInitArgs(const GrOpFlushState&); + GrProcessorSet detachProcessorSet() { return std::move(fProcessorSet); } const GrProcessorSet::Analysis& doProcessorAnalysis( const GrCaps&, const GrAppliedClip*, bool hasMixedSampledCoverage, GrClampType); const GrProcessorSet::Analysis& processorAnalysis() const { diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp index 102fa3d901..f51307c018 100644 --- a/src/gpu/ops/GrDrawVerticesOp.cpp +++ b/src/gpu/ops/GrDrawVerticesOp.cpp @@ -512,7 +512,11 @@ void DrawVerticesOp::drawVertices(Target* target, } void DrawVerticesOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } GrOp::CombineResult DrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { diff --git a/src/gpu/ops/GrFillRectOp.cpp b/src/gpu/ops/GrFillRectOp.cpp index ab5c833168..afd8ba240b 100644 --- a/src/gpu/ops/GrFillRectOp.cpp +++ b/src/gpu/ops/GrFillRectOp.cpp @@ -281,7 +281,12 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags(), + fHelper.stencilSettings()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/src/gpu/ops/GrLatticeOp.cpp b/src/gpu/ops/GrLatticeOp.cpp index b1e430e875..9995b771d9 100644 --- a/src/gpu/ops/GrLatticeOp.cpp +++ b/src/gpu/ops/GrLatticeOp.cpp @@ -290,7 +290,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/src/gpu/ops/GrOvalOpFactory.cpp b/src/gpu/ops/GrOvalOpFactory.cpp index 6adb970867..5e32b0a972 100644 --- a/src/gpu/ops/GrOvalOpFactory.cpp +++ b/src/gpu/ops/GrOvalOpFactory.cpp @@ -1399,7 +1399,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { @@ -1690,7 +1694,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { @@ -1945,7 +1953,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { @@ -2182,7 +2194,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { @@ -2613,7 +2629,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { @@ -2895,7 +2915,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/src/gpu/ops/GrRegionOp.cpp b/src/gpu/ops/GrRegionOp.cpp index cc78057a49..e12a865e1b 100644 --- a/src/gpu/ops/GrRegionOp.cpp +++ b/src/gpu/ops/GrRegionOp.cpp @@ -133,7 +133,12 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags(), + fHelper.stencilSettings()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/src/gpu/ops/GrShadowRRectOp.cpp b/src/gpu/ops/GrShadowRRectOp.cpp index d8999546d2..6a4bbab6d7 100644 --- a/src/gpu/ops/GrShadowRRectOp.cpp +++ b/src/gpu/ops/GrShadowRRectOp.cpp @@ -15,6 +15,7 @@ #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/effects/GrShadowGeoProc.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" /////////////////////////////////////////////////////////////////////////////// // Circle Data @@ -602,8 +603,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - flushState->executeDrawsAndUploadsForMeshDrawOp( - this, chainBounds, GrProcessorSet::MakeEmptySet()); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + GrProcessorSet::MakeEmptySet(), + GrPipeline::InputFlags::kNone); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp b/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp index 96545612c7..9b6e945053 100644 --- a/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp +++ b/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp @@ -106,15 +106,22 @@ GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors( return analysis; } -void GrSimpleMeshDrawOpHelper::executeDrawsAndUploads( - const GrOp* op, GrOpFlushState* flushState, const SkRect& chainBounds) { - if (fProcessors) { - flushState->executeDrawsAndUploadsForMeshDrawOp( - op, chainBounds, std::move(*fProcessors), fPipelineFlags); - } else { - flushState->executeDrawsAndUploadsForMeshDrawOp( - op, chainBounds, GrProcessorSet::MakeEmptySet(), fPipelineFlags); - } +const GrPipeline* GrSimpleMeshDrawOpHelper::CreatePipeline( + GrOpFlushState* flushState, + GrProcessorSet&& processorSet, + GrPipeline::InputFlags pipelineFlags, + const GrUserStencilSettings* stencilSettings) { + GrPipeline::InitArgs pipelineArgs; + + pipelineArgs.fInputFlags = pipelineFlags; + pipelineArgs.fDstProxyView = flushState->dstProxyView(); + pipelineArgs.fCaps = &flushState->caps(); + pipelineArgs.fUserStencil = stencilSettings; + pipelineArgs.fOutputSwizzle = flushState->view()->swizzle(); + + return flushState->allocator()->make(pipelineArgs, + std::move(processorSet), + flushState->detachAppliedClip()); } #ifdef SK_DEBUG @@ -186,17 +193,6 @@ bool GrSimpleMeshDrawOpHelperWithStencil::isCompatible( fStencilSettings == that.fStencilSettings; } -void GrSimpleMeshDrawOpHelperWithStencil::executeDrawsAndUploads( - const GrOp* op, GrOpFlushState* flushState, const SkRect& chainBounds) { - if (fProcessors) { - flushState->executeDrawsAndUploadsForMeshDrawOp( - op, chainBounds, std::move(*fProcessors), fPipelineFlags, fStencilSettings); - } else { - flushState->executeDrawsAndUploadsForMeshDrawOp( - op, chainBounds, GrProcessorSet::MakeEmptySet(), fPipelineFlags, fStencilSettings); - } -} - #ifdef SK_DEBUG SkString GrSimpleMeshDrawOpHelperWithStencil::dumpInfo() const { SkString result = INHERITED::dumpInfo(); diff --git a/src/gpu/ops/GrSimpleMeshDrawOpHelper.h b/src/gpu/ops/GrSimpleMeshDrawOpHelper.h index f1847695fc..8929af64e0 100644 --- a/src/gpu/ops/GrSimpleMeshDrawOpHelper.h +++ b/src/gpu/ops/GrSimpleMeshDrawOpHelper.h @@ -122,11 +122,19 @@ public: fAAType = static_cast(aaType); } - void executeDrawsAndUploads(const GrOp*, GrOpFlushState*, const SkRect& chainBounds); + static const GrPipeline* CreatePipeline( + GrOpFlushState*, + GrProcessorSet&&, + GrPipeline::InputFlags fPipelineFlags, + const GrUserStencilSettings* = &GrUserStencilSettings::kUnused); + + GrProcessorSet detachProcessorSet() { + return fProcessors ? std::move(*fProcessors) : GrProcessorSet::MakeEmptySet(); + } -protected: GrPipeline::InputFlags pipelineFlags() const { return fPipelineFlags; } +protected: GrProcessorSet::Analysis finalizeProcessors( const GrCaps& caps, const GrAppliedClip*, const GrUserStencilSettings*, bool hasMixedSampledCoverage, GrClampType, GrProcessorAnalysisCoverage geometryCoverage, @@ -185,17 +193,19 @@ public: using GrSimpleMeshDrawOpHelper::isTrivial; using GrSimpleMeshDrawOpHelper::usesLocalCoords; using GrSimpleMeshDrawOpHelper::compatibleWithCoverageAsAlpha; + using GrSimpleMeshDrawOpHelper::detachProcessorSet; + using GrSimpleMeshDrawOpHelper::pipelineFlags; bool isCompatible(const GrSimpleMeshDrawOpHelperWithStencil& that, const GrCaps&, const SkRect& thisBounds, const SkRect& thatBounds, bool ignoreAAType = false) const; - void executeDrawsAndUploads(const GrOp*, GrOpFlushState*, const SkRect& chainBounds); - #ifdef SK_DEBUG SkString dumpInfo() const; #endif + const GrUserStencilSettings* stencilSettings() const { return fStencilSettings; } + private: const GrUserStencilSettings* fStencilSettings; typedef GrSimpleMeshDrawOpHelper INHERITED; diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp index 742aa58436..96b40c4efb 100644 --- a/src/gpu/ops/GrSmallPathRenderer.cpp +++ b/src/gpu/ops/GrSmallPathRenderer.cpp @@ -812,7 +812,12 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags(), + fHelper.stencilSettings()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } const SkPMColor4f& color() const { return fShapes[0].fColor; } diff --git a/src/gpu/ops/GrStrokeRectOp.cpp b/src/gpu/ops/GrStrokeRectOp.cpp index 6c95eae1d8..045f69cc9c 100644 --- a/src/gpu/ops/GrStrokeRectOp.cpp +++ b/src/gpu/ops/GrStrokeRectOp.cpp @@ -228,7 +228,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } // TODO: override onCombineIfPossible @@ -520,7 +524,11 @@ void AAStrokeRectOp::onPrepareDraws(Target* target) { } void AAStrokeRectOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } sk_sp AAStrokeRectOp::GetIndexBuffer(GrResourceProvider* resourceProvider, diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp index ba1e853dae..ee4d91d0a6 100644 --- a/src/gpu/ops/GrTessellatingPathRenderer.cpp +++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp @@ -382,7 +382,12 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags(), + fHelper.stencilSettings()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } Helper fHelper; diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp index e68701198f..b6e39cb2ab 100644 --- a/src/gpu/ops/GrTextureOp.cpp +++ b/src/gpu/ops/GrTextureOp.cpp @@ -39,6 +39,7 @@ #include "src/gpu/ops/GrFillRectOp.h" #include "src/gpu/ops/GrMeshDrawOp.h" #include "src/gpu/ops/GrQuadPerEdgeAA.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" #include "src/gpu/ops/GrTextureOp.h" namespace { @@ -883,8 +884,12 @@ private: auto pipelineFlags = (GrAAType::kMSAA == fMetadata.aaType()) ? GrPipeline::InputFlags::kHWAntialias : GrPipeline::InputFlags::kNone; - flushState->executeDrawsAndUploadsForMeshDrawOp( - this, chainBounds, GrProcessorSet::MakeEmptySet(), pipelineFlags); + + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + GrProcessorSet::MakeEmptySet(), + pipelineFlags); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp index b2338e55bb..33637684a7 100644 --- a/tests/GrMeshTest.cpp +++ b/tests/GrMeshTest.cpp @@ -28,6 +28,7 @@ #include "src/gpu/glsl/GrGLSLGeometryProcessor.h" #include "src/gpu/glsl/GrGLSLVarying.h" #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" GR_DECLARE_STATIC_UNIQUE_KEY(gIndexBufferKey); @@ -417,7 +418,22 @@ sk_sp DrawMeshHelper::getIndexBuffer() { } void DrawMeshHelper::drawMesh(const GrMesh& mesh, GrPrimitiveType primitiveType) { - GrPipeline pipeline(GrScissorTest::kDisabled, SkBlendMode::kSrc, GrSwizzle::RGBA()); + GrProcessorSet processorSet(SkBlendMode::kSrc); + + // TODO: add a GrProcessorSet testing helper to make this easier + SkPMColor4f overrideColor; + processorSet.finalize(GrProcessorAnalysisColor(), + GrProcessorAnalysisCoverage::kNone, + fState->appliedClip(), + nullptr, + false, + fState->caps(), + GrClampType::kAuto, + &overrideColor); + + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(fState, + std::move(processorSet), + GrPipeline::InputFlags::kNone); GrGeometryProcessor* mtp = GrMeshTestProcessor::Make(fState->allocator(), mesh.isInstanced(), mesh.hasVertexData()); @@ -426,7 +442,7 @@ void DrawMeshHelper::drawMesh(const GrMesh& mesh, GrPrimitiveType primitiveType) fState->proxy()->numStencilSamples(), fState->proxy()->backendFormat(), fState->view()->origin(), - &pipeline, + pipeline, mtp, nullptr, nullptr, 0, primitiveType); diff --git a/tests/OnFlushCallbackTest.cpp b/tests/OnFlushCallbackTest.cpp index 62a61bb0a2..674b51de09 100644 --- a/tests/OnFlushCallbackTest.cpp +++ b/tests/OnFlushCallbackTest.cpp @@ -166,7 +166,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - fHelper.executeDrawsAndUploads(this, flushState, chainBounds); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + fHelper.detachProcessorSet(), + fHelper.pipelineFlags()); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } Helper fHelper; diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp index e9a10e05d6..acfa54d0a9 100644 --- a/tests/PrimitiveProcessorTest.cpp +++ b/tests/PrimitiveProcessorTest.cpp @@ -24,6 +24,7 @@ #include "src/gpu/glsl/GrGLSLGeometryProcessor.h" #include "src/gpu/glsl/GrGLSLVarying.h" #include "src/gpu/ops/GrMeshDrawOp.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" namespace { class Op : public GrMeshDrawOp { @@ -124,8 +125,11 @@ private: } void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { - flushState->executeDrawsAndUploadsForMeshDrawOp( - this, chainBounds, GrProcessorSet::MakeEmptySet()); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + GrProcessorSet::MakeEmptySet(), + GrPipeline::InputFlags::kNone); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } int fNumAttribs; diff --git a/tools/gpu/TestOps.cpp b/tools/gpu/TestOps.cpp index 22a8a66657..c819784e98 100644 --- a/tools/gpu/TestOps.cpp +++ b/tools/gpu/TestOps.cpp @@ -17,6 +17,7 @@ #include "src/gpu/glsl/GrGLSLGeometryProcessor.h" #include "src/gpu/glsl/GrGLSLVarying.h" #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" +#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" namespace { @@ -160,7 +161,11 @@ void TestRectOp::onPrepareDraws(Target* target) { } void TestRectOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { - flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, std::move(fProcessorSet)); + auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, + std::move(fProcessorSet), + GrPipeline::InputFlags::kNone); + + flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline); } } // anonymous namespace