diff options
author | Chris Dalton <csmartdalton@google.com> | 2017-10-31 00:37:52 -0600 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-31 21:46:44 +0000 |
commit | 6982400f9a414bbe7cff5e2dd32cf9893b07c370 (patch) | |
tree | 3bc5ac04d5f18ea2ddf1ddeba4dff105a65496e6 | |
parent | 3cbcb738456f72a9e2aedd96b5e5f20d4074aba0 (diff) |
Allow GrAppliedClip to have >1 clip coverage FP
Bug: skia:7190
Change-Id: I07fc689b20968a1b9fe2620bf8a33faacf917823
Reviewed-on: https://skia-review.googlesource.com/65401
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
-rw-r--r-- | src/gpu/GrAppliedClip.h | 45 | ||||
-rw-r--r-- | src/gpu/GrClipStackClip.cpp | 4 | ||||
-rw-r--r-- | src/gpu/GrPipeline.cpp | 14 | ||||
-rw-r--r-- | src/gpu/GrProcessorSet.cpp | 13 | ||||
-rw-r--r-- | src/gpu/GrReducedClip.cpp | 3 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 2 | ||||
-rw-r--r-- | src/gpu/ops/GrDashOp.cpp | 2 | ||||
-rw-r--r-- | src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp | 2 |
8 files changed, 50 insertions, 35 deletions
diff --git a/src/gpu/GrAppliedClip.h b/src/gpu/GrAppliedClip.h index 92cd45be10..d96370ecc0 100644 --- a/src/gpu/GrAppliedClip.h +++ b/src/gpu/GrAppliedClip.h @@ -26,9 +26,14 @@ public: const GrScissorState& scissorState() const { return fScissorState; } const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } - GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fClipCoverageFP.get(); } - std::unique_ptr<GrFragmentProcessor> detachClipCoverageFragmentProcessor() { - return std::move(fClipCoverageFP); + int numClipCoverageFragmentProcessors() const { return fClipCoverageFPs.count(); } + const GrFragmentProcessor* clipCoverageFragmentProcessor(int i) const { + SkASSERT(fClipCoverageFPs[i]); + return fClipCoverageFPs[i].get(); + } + std::unique_ptr<const GrFragmentProcessor> detachClipCoverageFragmentProcessor(int i) { + SkASSERT(fClipCoverageFPs[i]); + return std::move(fClipCoverageFPs[i]); } bool hasStencilClip() const { return SkClipStack::kInvalidGenID != fClipStackID; } @@ -52,8 +57,8 @@ public: } void addCoverageFP(std::unique_ptr<GrFragmentProcessor> fp) { - SkASSERT(!fClipCoverageFP); - fClipCoverageFP = std::move(fp); + SkASSERT(fp); + fClipCoverageFPs.push_back(std::move(fp)); } void addStencilClip(uint32_t clipStackID) { @@ -62,36 +67,44 @@ public: } bool doesClip() const { - return fScissorState.enabled() || fClipCoverageFP || this->hasStencilClip() || + return fScissorState.enabled() || !fClipCoverageFPs.empty() || this->hasStencilClip() || fWindowRectsState.enabled(); } bool operator==(const GrAppliedClip& that) const { - if (fScissorState != that.fScissorState || fClipStackID != that.fClipStackID) { + if (fScissorState != that.fScissorState || + fWindowRectsState != that.fWindowRectsState || + fClipCoverageFPs.count() != that.fClipCoverageFPs.count() || + fClipStackID != that.fClipStackID) { return false; } - if (SkToBool(fClipCoverageFP)) { - if (!SkToBool(that.fClipCoverageFP) || - !that.fClipCoverageFP->isEqual(*fClipCoverageFP)) { + for (int i = 0; i < fClipCoverageFPs.count(); ++i) { + if (!fClipCoverageFPs[i] || !that.fClipCoverageFPs[i]) { + if (fClipCoverageFPs[i] == that.fClipCoverageFPs[i]) { + continue; // Both are null. + } + return false; + } + if (!fClipCoverageFPs[i]->isEqual(*that.fClipCoverageFPs[i])) { return false; } - } else if (SkToBool(that.fClipCoverageFP)) { - return false; } - return fWindowRectsState == that.fWindowRectsState; + return true; } bool operator!=(const GrAppliedClip& that) const { return !(*this == that); } void visitProxies(const std::function<void(GrSurfaceProxy*)>& func) const { - if (fClipCoverageFP) { - fClipCoverageFP->visitProxies(func); + for (const std::unique_ptr<GrFragmentProcessor>& fp : fClipCoverageFPs) { + if (fp) { // This might be called after detach. + fp->visitProxies(func); + } } } private: GrScissorState fScissorState; GrWindowRectsState fWindowRectsState; - std::unique_ptr<GrFragmentProcessor> fClipCoverageFP; + SkSTArray<4, std::unique_ptr<GrFragmentProcessor>> fClipCoverageFPs; uint32_t fClipStackID = SkClipStack::kInvalidGenID; }; diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp index 6a71e00a1c..aa2b9fdd29 100644 --- a/src/gpu/GrClipStackClip.cpp +++ b/src/gpu/GrClipStackClip.cpp @@ -314,7 +314,9 @@ bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTar if ((reducedClip.maskRequiresAA() || avoidStencilBuffers) && get_analytic_clip_processor(reducedClip.maskElements(), disallowAnalyticAA, devBounds, &clipFP)) { - out->addCoverageFP(std::move(clipFP)); + if (clipFP) { + out->addCoverageFP(std::move(clipFP)); + } return true; } } diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp index 4083afae1c..a0eceb32af 100644 --- a/src/gpu/GrPipeline.cpp +++ b/src/gpu/GrPipeline.cpp @@ -48,12 +48,9 @@ GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors, // Copy GrFragmentProcessors from GrProcessorSet to Pipeline fNumColorProcessors = processors.numColorFragmentProcessors(); - int numTotalProcessors = - fNumColorProcessors + processors.numCoverageFragmentProcessors(); - auto clipFP = appliedClip.detachClipCoverageFragmentProcessor(); - if (clipFP) { - ++numTotalProcessors; - } + int numTotalProcessors = fNumColorProcessors + + processors.numCoverageFragmentProcessors() + + appliedClip.numClipCoverageFragmentProcessors(); fFragmentProcessors.reset(numTotalProcessors); int currFPIdx = 0; for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) { @@ -62,15 +59,14 @@ GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors, this->markAsBad(); } } - for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) { fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i); if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) { this->markAsBad(); } } - if (clipFP) { - fFragmentProcessors[currFPIdx] = std::move(clipFP); + for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) { + fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i); if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) { this->markAsBad(); } diff --git a/src/gpu/GrProcessorSet.cpp b/src/gpu/GrProcessorSet.cpp index 7694806659..0601d92db8 100644 --- a/src/gpu/GrProcessorSet.cpp +++ b/src/gpu/GrProcessorSet.cpp @@ -168,7 +168,6 @@ GrProcessorSet::Analysis GrProcessorSet::finalize(const GrProcessorAnalysisColor GrProcessorSet::Analysis analysis; analysis.fCompatibleWithCoverageAsAlpha = GrProcessorAnalysisCoverage::kLCD != coverageInput; - const GrFragmentProcessor* clipFP = clip ? clip->clipCoverageFragmentProcessor() : nullptr; const std::unique_ptr<const GrFragmentProcessor>* fps = fFragmentProcessors.get() + fFragmentProcessorOffset; GrColorFragmentProcessorAnalysis colorAnalysis( @@ -188,11 +187,13 @@ GrProcessorSet::Analysis GrProcessorSet::finalize(const GrProcessorAnalysisColor } coverageUsesLocalCoords |= fps[i]->usesLocalCoords(); } - - if (clipFP) { - analysis.fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha(); - coverageUsesLocalCoords |= clipFP->usesLocalCoords(); - hasCoverageFP = true; + if (clip) { + hasCoverageFP = hasCoverageFP || clip->numClipCoverageFragmentProcessors(); + for (int i = 0; i < clip->numClipCoverageFragmentProcessors(); ++i) { + const GrFragmentProcessor* clipFP = clip->clipCoverageFragmentProcessor(i); + analysis.fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha(); + coverageUsesLocalCoords |= clipFP->usesLocalCoords(); + } } int colorFPsToEliminate = colorAnalysis.initialProcessorsToEliminate(overrideInputColor); analysis.fInputColorType = static_cast<Analysis::PackedInputColorType>( diff --git a/src/gpu/GrReducedClip.cpp b/src/gpu/GrReducedClip.cpp index 29f483022b..bc3286bdf0 100644 --- a/src/gpu/GrReducedClip.cpp +++ b/src/gpu/GrReducedClip.cpp @@ -137,6 +137,9 @@ void GrReducedClip::walkStack(const SkClipStack& stack, const SkRect& queryBound // account for floating point rounding error that may have occurred during coord transforms. SkRect relaxedQueryBounds = queryBounds.makeInset(GrClip::kBoundsTolerance, GrClip::kBoundsTolerance); + if (relaxedQueryBounds.isEmpty()) { + relaxedQueryBounds = queryBounds; + } SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); int numAAElements = 0; diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index 44550e1ee5..e1ce24c886 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -653,7 +653,7 @@ void GrRenderTargetContextPriv::stencilPath(const GrClip& clip, // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never // attempt this in a situation that would require coverage AA. - SkASSERT(!appliedClip.clipCoverageFragmentProcessor()); + SkASSERT(!appliedClip.numClipCoverageFragmentProcessors()); fRenderTargetContext->setNeedsStencil(); diff --git a/src/gpu/ops/GrDashOp.cpp b/src/gpu/ops/GrDashOp.cpp index 6b014fffbf..82b2012587 100644 --- a/src/gpu/ops/GrDashOp.cpp +++ b/src/gpu/ops/GrDashOp.cpp @@ -299,7 +299,7 @@ public: RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip, GrPixelConfigIsClamped dstIsClamped) override { GrProcessorAnalysisCoverage coverage; - if (AAMode::kNone == fAAMode && !clip->clipCoverageFragmentProcessor()) { + if (AAMode::kNone == fAAMode && !clip->numClipCoverageFragmentProcessors()) { coverage = GrProcessorAnalysisCoverage::kNone; } else { coverage = GrProcessorAnalysisCoverage::kSingleChannel; diff --git a/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp b/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp index b32344af11..8b83271105 100644 --- a/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp +++ b/src/gpu/ops/GrSimpleMeshDrawOpHelper.cpp @@ -71,7 +71,7 @@ GrDrawOp::RequiresDstTexture GrSimpleMeshDrawOpHelper::xpRequiresDstTexture( if (fProcessors) { GrProcessorAnalysisCoverage coverage = geometryCoverage; if (GrProcessorAnalysisCoverage::kNone == coverage) { - coverage = clip->clipCoverageFragmentProcessor() + coverage = clip->numClipCoverageFragmentProcessors() ? GrProcessorAnalysisCoverage::kSingleChannel : GrProcessorAnalysisCoverage::kNone; } |