From 41d91b68b5ad535072fcc5ba3b5694d7bdf41c2c Mon Sep 17 00:00:00 2001 From: John Stiles Date: Tue, 21 Jul 2020 14:39:40 -0400 Subject: [PATCH] Remove support for multiple coverage processors from GrPaint API. Change-Id: I82276e38ea4a5524127176eb5a34066b6cb06d88 Bug: skia:10217 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304799 Reviewed-by: Brian Osman Commit-Queue: John Stiles --- gm/bigrrectaaeffect.cpp | 2 +- gm/convexpolyeffect.cpp | 4 ++-- gm/fpcoordinateoverride.cpp | 2 +- gm/rrects.cpp | 2 +- src/core/SkBlurMF.cpp | 8 ++++---- src/gpu/GrBlurUtils.cpp | 2 +- src/gpu/GrFragmentProcessor.cpp | 4 ++-- src/gpu/GrPaint.cpp | 7 +++---- src/gpu/GrPaint.h | 16 +++++++++------- src/gpu/GrProcessorSet.cpp | 5 ++--- src/gpu/GrRenderTargetContext.cpp | 5 ++--- src/gpu/GrSoftwarePathRenderer.cpp | 2 +- src/gpu/SkGr.cpp | 2 +- .../tessellate/GrTessellationPathRenderer.cpp | 2 +- tests/ProgramsTest.cpp | 19 +++++++------------ 15 files changed, 38 insertions(+), 44 deletions(-) diff --git a/gm/bigrrectaaeffect.cpp b/gm/bigrrectaaeffect.cpp index de5c4b069b..4ef31c5fbf 100644 --- a/gm/bigrrectaaeffect.cpp +++ b/gm/bigrrectaaeffect.cpp @@ -98,7 +98,7 @@ protected: GrPaint grPaint; grPaint.setColor4f({ 0, 0, 0, 1.f }); grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); - grPaint.addCoverageFragmentProcessor(std::move(fp)); + grPaint.setCoverageFragmentProcessor(std::move(fp)); SkRect bounds = testBounds; bounds.offset(SkIntToScalar(x), SkIntToScalar(y)); diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp index e32cc516d7..88d87aa3c4 100644 --- a/gm/convexpolyeffect.cpp +++ b/gm/convexpolyeffect.cpp @@ -133,7 +133,7 @@ protected: GrPaint grPaint; grPaint.setColor4f({ 0, 0, 0, 1.f }); grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); - grPaint.addCoverageFragmentProcessor(std::move(fp)); + grPaint.setCoverageFragmentProcessor(std::move(fp)); auto rect = p.getBounds().makeOutset(kOutset, kOutset); auto op = sk_gpu_test::test_ops::MakeRect(context, std::move(grPaint), rect); @@ -172,7 +172,7 @@ protected: GrPaint grPaint; grPaint.setColor4f({ 0, 0, 0, 1.f }); grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); - grPaint.addCoverageFragmentProcessor(std::move(fp)); + grPaint.setCoverageFragmentProcessor(std::move(fp)); auto drawRect = rect.makeOutset(kOutset, kOutset); auto op = sk_gpu_test::test_ops::MakeRect(context, std::move(grPaint), drawRect); diff --git a/gm/fpcoordinateoverride.cpp b/gm/fpcoordinateoverride.cpp index f1392aa494..a42acf65d9 100644 --- a/gm/fpcoordinateoverride.cpp +++ b/gm/fpcoordinateoverride.cpp @@ -89,7 +89,7 @@ DEF_SIMPLE_GPU_GM_BG(fpcoordinateoverride, ctx, rtCtx, canvas, 512, 512, auto fp = std::unique_ptr(new SampleCoordEffect(std::move(imgFP))); GrPaint grPaint; - grPaint.addCoverageFragmentProcessor(std::move(fp)); + grPaint.setCoverageFragmentProcessor(std::move(fp)); rtCtx->priv().testingOnly_addDrawOp(GrFillRectOp::MakeNonAARect(ctx, std::move(grPaint), diff --git a/gm/rrects.cpp b/gm/rrects.cpp index 4dd5523a03..e7a3760a44 100644 --- a/gm/rrects.cpp +++ b/gm/rrects.cpp @@ -124,7 +124,7 @@ protected: if (success) { GrPaint grPaint; grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); - grPaint.addCoverageFragmentProcessor(std::move(fp)); + grPaint.setCoverageFragmentProcessor(std::move(fp)); grPaint.setColor4f({ 0, 0, 0, 1.f }); SkRect bounds = rrect.getBounds(); diff --git a/src/core/SkBlurMF.cpp b/src/core/SkBlurMF.cpp index d78f33693a..26d545cfd9 100644 --- a/src/core/SkBlurMF.cpp +++ b/src/core/SkBlurMF.cpp @@ -769,7 +769,7 @@ bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrRecordingContext* context, if (!fp) { return false; } - paint.addCoverageFragmentProcessor(std::move(fp)); + paint.setCoverageFragmentProcessor(std::move(fp)); SkRect srcProxyRect = srcRRect.rect(); SkScalar outsetX = 3.0f*fSigma; @@ -804,7 +804,7 @@ bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrRecordingContext* context, memcpy(builder.indices(), fullIndices, sizeof(fullIndices)); sk_sp vertices = builder.detach(); - paint.addCoverageFragmentProcessor(std::move(fp)); + paint.setCoverageFragmentProcessor(std::move(fp)); SkSimpleMatrixProvider matrixProvider(viewMatrix); renderTargetContext->drawVertices(clip, std::move(paint), matrixProvider, std::move(vertices)); @@ -818,7 +818,7 @@ bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrRecordingContext* context, SkRect proxyRect = devRRect.rect(); proxyRect.outset(extra, extra); - paint.addCoverageFragmentProcessor(std::move(fp)); + paint.setCoverageFragmentProcessor(std::move(fp)); renderTargetContext->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), proxyRect, inverse); } @@ -896,7 +896,7 @@ GrSurfaceProxyView SkBlurMaskFilterImpl::filterMaskGPU(GrRecordingContext* conte if (!isNormalBlur) { GrPaint paint; // Blend pathTexture over blurTexture. - paint.addCoverageFragmentProcessor(GrTextureEffect::Make(std::move(srcView), srcAlphaType)); + paint.setCoverageFragmentProcessor(GrTextureEffect::Make(std::move(srcView), srcAlphaType)); if (kInner_SkBlurStyle == fBlurStyle) { // inner: dst = dst * src paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op); diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp index 03ad192c1e..c1a3b3ce38 100644 --- a/src/gpu/GrBlurUtils.cpp +++ b/src/gpu/GrBlurUtils.cpp @@ -56,7 +56,7 @@ static bool draw_mask(GrRenderTargetContext* renderTargetContext, SkMatrix matrix = SkMatrix::Translate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop)); matrix.preConcat(viewMatrix); - paint.addCoverageFragmentProcessor( + paint.setCoverageFragmentProcessor( GrTextureEffect::Make(std::move(mask), kUnknown_SkAlphaType, matrix)); renderTargetContext->fillRectWithLocalMatrix(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp index ad071b93af..91c4a59544 100644 --- a/src/gpu/GrFragmentProcessor.cpp +++ b/src/gpu/GrFragmentProcessor.cpp @@ -481,8 +481,8 @@ std::unique_ptr GrFragmentProcessor::RunInSeries( ////////////////////////////////////////////////////////////////////////////// GrFragmentProcessor::CIter::CIter(const GrPaint& paint) { - for (int i = paint.numCoverageFragmentProcessors() - 1; i >= 0; --i) { - fFPStack.push_back(paint.getCoverageFragmentProcessor(i)); + if (paint.hasCoverageFragmentProcessor()) { + fFPStack.push_back(paint.getCoverageFragmentProcessor()); } if (paint.hasColorFragmentProcessor()) { fFPStack.push_back(paint.getColorFragmentProcessor()); diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp index 724c1be574..4249543491 100644 --- a/src/gpu/GrPaint.cpp +++ b/src/gpu/GrPaint.cpp @@ -13,16 +13,15 @@ GrPaint::GrPaint(const GrPaint& that) : fXPFactory(that.fXPFactory) - , fCoverageFragmentProcessors(that.fCoverageFragmentProcessors.count()) , fTrivial(that.fTrivial) , fColor(that.fColor) { if (that.fColorFragmentProcessor) { fColorFragmentProcessor = that.fColorFragmentProcessor->clone(); SkASSERT(fColorFragmentProcessor); } - for (int i = 0; i < that.fCoverageFragmentProcessors.count(); ++i) { - fCoverageFragmentProcessors.push_back(that.fCoverageFragmentProcessors[i]->clone()); - SkASSERT(fCoverageFragmentProcessors[i]); + if (that.fCoverageFragmentProcessor) { + fCoverageFragmentProcessor = that.fCoverageFragmentProcessor->clone(); + SkASSERT(fCoverageFragmentProcessor); } } diff --git a/src/gpu/GrPaint.h b/src/gpu/GrPaint.h index d5cce589a4..1ac34fb7f6 100644 --- a/src/gpu/GrPaint.h +++ b/src/gpu/GrPaint.h @@ -72,16 +72,18 @@ public: /** * Appends an additional coverage processor to the coverage computation. */ - void addCoverageFragmentProcessor(std::unique_ptr fp) { + void setCoverageFragmentProcessor(std::unique_ptr fp) { SkASSERT(fp); - fCoverageFragmentProcessors.push_back(std::move(fp)); + SkASSERT(fCoverageFragmentProcessor == nullptr); + fCoverageFragmentProcessor = std::move(fp); fTrivial = false; } bool hasColorFragmentProcessor() const { return fColorFragmentProcessor ? true : false; } - int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); } + int hasCoverageFragmentProcessor() const { return fCoverageFragmentProcessor ? true : false; } int numTotalFragmentProcessors() const { - return (this->hasColorFragmentProcessor() ? 1 : 0) + this->numCoverageFragmentProcessors(); + return (this->hasColorFragmentProcessor() ? 1 : 0) + + (this->hasCoverageFragmentProcessor() ? 1 : 0); } const GrXPFactory* getXPFactory() const { return fXPFactory; } @@ -89,8 +91,8 @@ public: GrFragmentProcessor* getColorFragmentProcessor() const { return fColorFragmentProcessor.get(); } - GrFragmentProcessor* getCoverageFragmentProcessor(int i) const { - return fCoverageFragmentProcessors[i].get(); + GrFragmentProcessor* getCoverageFragmentProcessor() const { + return fCoverageFragmentProcessor.get(); } /** @@ -121,7 +123,7 @@ private: const GrXPFactory* fXPFactory = nullptr; std::unique_ptr fColorFragmentProcessor; - SkSTArray<2, std::unique_ptr> fCoverageFragmentProcessors; + std::unique_ptr fCoverageFragmentProcessor; bool fTrivial = true; SkPMColor4f fColor = SK_PMColor4fWHITE; SkDEBUGCODE(bool fAlive = true;) // Set false after moved from. diff --git a/src/gpu/GrProcessorSet.cpp b/src/gpu/GrProcessorSet.cpp index 8a0f5957b3..f85b99cf3e 100644 --- a/src/gpu/GrProcessorSet.cpp +++ b/src/gpu/GrProcessorSet.cpp @@ -31,9 +31,8 @@ GrProcessorSet::GrProcessorSet(GrPaint&& paint) : fXP(paint.getXPFactory()) { if (paint.fColorFragmentProcessor) { fFragmentProcessors[i++] = std::move(paint.fColorFragmentProcessor); } - for (auto& fp : paint.fCoverageFragmentProcessors) { - SkASSERT(fp.get()); - fFragmentProcessors[i++] = std::move(fp); + if (paint.fCoverageFragmentProcessor) { + fFragmentProcessors[i++] = std::move(paint.fCoverageFragmentProcessor); } SkDEBUGCODE(paint.fAlive = false;) diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index 52139468be..bc84e7dd91 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -776,8 +776,7 @@ void GrRenderTargetContext::drawFilledQuad(const GrClip* clip, SkPMColor4f* constColor = nullptr; SkPMColor4f paintColor; - if (!ss && !paint.numCoverageFragmentProcessors() && - paint.isConstantBlendedColor(&paintColor)) { + if (!ss && !paint.hasCoverageFragmentProcessor() && paint.isConstantBlendedColor(&paintColor)) { // Only consider clears/rrects when it's easy to guarantee 100% fill with single color constColor = &paintColor; } @@ -1444,7 +1443,7 @@ bool GrRenderTargetContext::drawFilledDRRect(const GrClip* clip, return false; } - paint.addCoverageFragmentProcessor(std::move(fp)); + paint.setCoverageFragmentProcessor(std::move(fp)); SkRect bounds = outer->getBounds(); if (GrAAType::kCoverage == aaType) { diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp index 2e441b5224..af0ed0ad6b 100644 --- a/src/gpu/GrSoftwarePathRenderer.cpp +++ b/src/gpu/GrSoftwarePathRenderer.cpp @@ -167,7 +167,7 @@ void GrSoftwarePathRenderer::DrawToTargetWithShapeMask( SkIntToScalar(-textureOriginInDeviceSpace.fY)); maskMatrix.preConcat(viewMatrix); - paint.addCoverageFragmentProcessor(GrTextureEffect::Make( + paint.setCoverageFragmentProcessor(GrTextureEffect::Make( std::move(view), kPremul_SkAlphaType, maskMatrix, GrSamplerState::Filter::kNearest)); DrawNonAARect(renderTargetContext, std::move(paint), userStencilSettings, clip, SkMatrix::I(), dstRect, invert); diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 42d9d1a9e7..1aaeaecc4c 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -313,7 +313,7 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context, // We may have set this before passing to the SkShader. fpArgs.fInputColorIsOpaque = false; if (auto mfFP = maskFilter->asFragmentProcessor(fpArgs)) { - grPaint->addCoverageFragmentProcessor(std::move(mfFP)); + grPaint->setCoverageFragmentProcessor(std::move(mfFP)); } } diff --git a/src/gpu/tessellate/GrTessellationPathRenderer.cpp b/src/gpu/tessellate/GrTessellationPathRenderer.cpp index d12d356428..10224dd348 100644 --- a/src/gpu/tessellate/GrTessellationPathRenderer.cpp +++ b/src/gpu/tessellate/GrTessellationPathRenderer.cpp @@ -143,7 +143,7 @@ GrPathRenderer::CanDrawPath GrTessellationPathRenderer::onCanDrawPath( !args.fCaps->shaderCaps()->tessellationSupport() || GrAAType::kCoverage == args.fAAType || !args.fViewMatrix->isSimilarity() || !args.fPaint->isConstantBlendedColor(&constantColor) || - args.fPaint->numCoverageFragmentProcessors()) { + args.fPaint->hasCoverageFragmentProcessor()) { return CanDrawPath::kNo; } } diff --git a/tests/ProgramsTest.cpp b/tests/ProgramsTest.cpp index afa3e1326f..dfbcb47f7f 100644 --- a/tests/ProgramsTest.cpp +++ b/tests/ProgramsTest.cpp @@ -232,19 +232,14 @@ static void set_random_color_coverage_stages(GrPaint* paint, paint->setColorFragmentProcessor(std::move(fp)); } } else { - int numProcs = d->fRandom->nextULessThan(maxStages + 1); - int numColorProcs = 1; - - for (int s = 0; s < numProcs; ++s) { - std::unique_ptr fp(GrFragmentProcessorTestFactory::Make(d)); - if (!fp) { - continue; - } - // finally add the stage to the correct pipeline in the drawstate - if (s < numColorProcs) { + if (maxStages >= 1) { + if (std::unique_ptr fp = GrFragmentProcessorTestFactory::Make(d)) { paint->setColorFragmentProcessor(std::move(fp)); - } else { - paint->addCoverageFragmentProcessor(std::move(fp)); + } + } + if (maxStages >= 2) { + if (std::unique_ptr fp = GrFragmentProcessorTestFactory::Make(d)) { + paint->setCoverageFragmentProcessor(std::move(fp)); } } }