Revert "Remove GrPipeline from GrDrawOp."
This reverts commit 2bf4b3a97b770811d9e0558dbbfbdb57cfafbdb7.
Reason for revert: nanobench assertion
Original change's description:
> Remove GrPipeline from GrDrawOp.
>
> GrDrawOp subclasses are now free to construct their pipelines at flush time and now in theory could use multiple GrPipelines for multipass rendering.
>
> GrProcessorSet may be used to retain the processors from a GrPaint with "pending execution" style refs.
>
> NVPR and Instanced rendering are updated to create their pipelines at flush time without a GrPipelineBuilder.
>
> The monolithic pipeline creation/management that was on GrDrawOp is moved to GrMeshDrawOp. However, this is temporary and will be removed in coming changes.
>
> Change-Id: I124282e3cea5d070970b5460c8a679fcaf7a8eff
> Reviewed-on: https://skia-review.googlesource.com/7279
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>
>
TBR=bsalomon@google.com,robertphillips@google.com,csmartdalton@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: I1bc64f6cbbd5f482417637a034342c2b5371dc5c
Reviewed-on: https://skia-review.googlesource.com/9817
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrAppliedClip.h b/src/gpu/GrAppliedClip.h
index 8488dc4..57314ec 100644
--- a/src/gpu/GrAppliedClip.h
+++ b/src/gpu/GrAppliedClip.h
@@ -16,12 +16,8 @@
* Produced by GrClip. It provides a set of modifications to the drawing state that are used to
* create the final GrPipeline for a GrOp.
*/
-class GrAppliedClip {
+class GrAppliedClip : public SkNoncopyable {
public:
- GrAppliedClip() = default;
- GrAppliedClip(GrAppliedClip&& that) = default;
- GrAppliedClip(const GrAppliedClip&) = delete;
-
const GrScissorState& scissorState() const { return fScissorState; }
const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; }
GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fClipCoverageFP.get(); }
@@ -56,32 +52,12 @@
fHasStencilClip = true;
}
- bool doesClip() const {
- return fScissorState.enabled() || fClipCoverageFP || fHasStencilClip ||
- fWindowRectsState.enabled();
- }
-
- bool operator==(const GrAppliedClip& that) const {
- if (fScissorState != that.fScissorState || fHasStencilClip != that.fHasStencilClip) {
- return false;
- }
- if (SkToBool(fClipCoverageFP)) {
- if (!SkToBool(that.fClipCoverageFP) ||
- !that.fClipCoverageFP->isEqual(*fClipCoverageFP)) {
- return false;
- }
- } else if (SkToBool(that.fClipCoverageFP)) {
- return false;
- }
- return fWindowRectsState == that.fWindowRectsState;
- }
- bool operator!=(const GrAppliedClip& that) const { return !(*this == that); }
-
private:
GrScissorState fScissorState;
GrWindowRectsState fWindowRectsState;
sk_sp<GrFragmentProcessor> fClipCoverageFP;
bool fHasStencilClip = false;
+ typedef SkNoncopyable INHERITED;
};
#endif
diff --git a/src/gpu/GrOpFlushState.cpp b/src/gpu/GrOpFlushState.cpp
index c6f5d38..2dddbba 100644
--- a/src/gpu/GrOpFlushState.cpp
+++ b/src/gpu/GrOpFlushState.cpp
@@ -11,14 +11,13 @@
#include "GrPipeline.h"
GrOpFlushState::GrOpFlushState(GrGpu* gpu, GrResourceProvider* resourceProvider)
- : fGpu(gpu)
- , fResourceProvider(resourceProvider)
- , fCommandBuffer(nullptr)
- , fVertexPool(gpu)
- , fIndexPool(gpu)
- , fLastIssuedToken(GrDrawOpUploadToken::AlreadyFlushedToken())
- , fLastFlushedToken(0)
- , fOpArgs(nullptr) {}
+ : fGpu(gpu)
+ , fResourceProvider(resourceProvider)
+ , fCommandBuffer(nullptr)
+ , fVertexPool(gpu)
+ , fIndexPool(gpu)
+ , fLastIssuedToken(GrDrawOpUploadToken::AlreadyFlushedToken())
+ , fLastFlushedToken(0) {}
void* GrOpFlushState::makeVertexSpace(size_t vertexSize, int vertexCount,
const GrBuffer** buffer, int* startVertex) {
diff --git a/src/gpu/GrOpFlushState.h b/src/gpu/GrOpFlushState.h
index d7ed4e0..ed77c3b 100644
--- a/src/gpu/GrOpFlushState.h
+++ b/src/gpu/GrOpFlushState.h
@@ -96,30 +96,22 @@
fIndexPool.reset();
}
- /** Additional data required on a per-op basis when executing GrDrawOps. */
- struct DrawOpArgs {
- GrRenderTarget* fRenderTarget;
- const GrAppliedClip* fAppliedClip;
- GrXferProcessor::DstTexture fDstTexture;
- };
-
- void setDrawOpArgs(DrawOpArgs* opArgs) { fOpArgs = opArgs; }
-
- const DrawOpArgs& drawOpArgs() const {
- SkASSERT(fOpArgs);
- return *fOpArgs;
- }
-
private:
+
GrGpu* fGpu;
+
GrResourceProvider* fResourceProvider;
+
GrGpuCommandBuffer* fCommandBuffer;
+
GrVertexBufferAllocPool fVertexPool;
GrIndexBufferAllocPool fIndexPool;
+
SkSTArray<4, GrDrawOp::DeferredUploadFn> fAsapUploads;
+
GrDrawOpUploadToken fLastIssuedToken;
+
GrDrawOpUploadToken fLastFlushedToken;
- DrawOpArgs* fOpArgs;
};
/**
diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp
index 7ab5cbf..845ae44 100644
--- a/src/gpu/GrPipeline.cpp
+++ b/src/gpu/GrPipeline.cpp
@@ -24,31 +24,27 @@
SkASSERT(args.fRenderTarget);
fRenderTarget.reset(args.fRenderTarget);
+ fScissorState = args.fAppliedClip->scissorState();
+ fWindowRectsState = args.fAppliedClip->windowRectsState();
+ fUserStencilSettings = args.fUserStencil;
+ fDrawFace = static_cast<int16_t>(args.fDrawFace);
fFlags = args.fFlags;
- if (args.fAppliedClip) {
- fScissorState = args.fAppliedClip->scissorState();
- if (args.fAppliedClip->hasStencilClip()) {
- fFlags |= kHasStencilClip_Flag;
- }
- fWindowRectsState = args.fAppliedClip->windowRectsState();
- }
if (args.fProcessors->usesDistanceVectorField()) {
fFlags |= kUsesDistanceVectorField_Flag;
}
+ if (args.fAppliedClip->hasStencilClip()) {
+ fFlags |= kHasStencilClip_Flag;
+ }
+ if (!args.fUserStencil->isDisabled(args.fAppliedClip->hasStencilClip())) {
+ fFlags |= kStencilEnabled_Flag;
+ }
if (args.fProcessors->disableOutputConversionToSRGB()) {
fFlags |= kDisableOutputConversionToSRGB_Flag;
}
if (args.fProcessors->allowSRGBInputs()) {
fFlags |= kAllowSRGBInputs_Flag;
}
- if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
- fFlags |= kStencilEnabled_Flag;
- }
-
- fUserStencilSettings = args.fUserStencil;
-
- fDrawFace = static_cast<int16_t>(args.fDrawFace);
bool isHWAA = kHWAntialias_Flag & args.fFlags;
@@ -90,7 +86,7 @@
fNumColorProcessors = args.fProcessors->numColorFragmentProcessors() - colorFPsToEliminate;
int numTotalProcessors =
fNumColorProcessors + args.fProcessors->numCoverageFragmentProcessors();
- if (args.fAppliedClip && args.fAppliedClip->clipCoverageFragmentProcessor()) {
+ if (args.fAppliedClip->clipCoverageFragmentProcessor()) {
++numTotalProcessors;
}
fFragmentProcessors.reset(numTotalProcessors);
@@ -105,10 +101,8 @@
const GrFragmentProcessor* fp = args.fProcessors->coverageFragmentProcessor(i);
fFragmentProcessors[currFPIdx].reset(fp);
}
- if (args.fAppliedClip) {
- if (const GrFragmentProcessor* fp = args.fAppliedClip->clipCoverageFragmentProcessor()) {
- fFragmentProcessors[currFPIdx].reset(fp);
- }
+ if (const GrFragmentProcessor* fp = args.fAppliedClip->clipCoverageFragmentProcessor()) {
+ fFragmentProcessors[currFPIdx].reset(fp);
}
// Setup info we need to pass to GrPrimitiveProcessors that are used with this GrPipeline.
@@ -124,6 +118,10 @@
if (SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag)) {
optimizations.fFlags |= GrPipelineOptimizations::kCanTweakAlphaForCoverage_Flag;
}
+
+ if (GrXPFactory::WillReadDst(xpFactory, *args.fAnalysis)) {
+ optimizations.fFlags |= GrPipelineOptimizations::kXPReadsDst_Flag;
+ }
return optimizations;
}
diff --git a/src/gpu/GrPrimitiveProcessor.h b/src/gpu/GrPrimitiveProcessor.h
index 4c43943..f5b8fe9 100644
--- a/src/gpu/GrPrimitiveProcessor.h
+++ b/src/gpu/GrPrimitiveProcessor.h
@@ -70,6 +70,11 @@
return false;
}
+ /**
+ * Returns true if the color written to the output pixel depends on the pixels previous value.
+ */
+ bool xpReadsDst() const { return SkToBool(kXPReadsDst_Flag & fFlags); }
+
private:
enum {
// If this is not set the primitive processor need not produce local coordinates
@@ -82,6 +87,8 @@
// If this flag is set the GrPrimitiveProcessor must produce fOverrideColor as its
// output color. If not set fOverrideColor is to be ignored.
kUseOverrideColor_Flag = 0x4,
+
+ kXPReadsDst_Flag = 0x8,
};
uint32_t fFlags;
diff --git a/src/gpu/GrProcessorSet.cpp b/src/gpu/GrProcessorSet.cpp
index 94e2004..c4b8262 100644
--- a/src/gpu/GrProcessorSet.cpp
+++ b/src/gpu/GrProcessorSet.cpp
@@ -38,44 +38,6 @@
}
}
-GrProcessorSet::~GrProcessorSet() {
- if (this->isPendingExecution()) {
- for (auto fp : fFragmentProcessors) {
- fp->completedExecution();
- }
- } else {
- for (auto fp : fFragmentProcessors) {
- fp->unref();
- }
- }
-}
-
-void GrProcessorSet::makePendingExecution() {
- SkASSERT(!(kPendingExecution_Flag & fFlags));
- fFlags |= kPendingExecution_Flag;
- for (int i = 0; i < fFragmentProcessors.count(); ++i) {
- fFragmentProcessors[i]->addPendingExecution();
- fFragmentProcessors[i]->unref();
- }
-}
-
-bool GrProcessorSet::operator==(const GrProcessorSet& that) const {
- if (((fFlags ^ that.fFlags) & ~kPendingExecution_Flag) ||
- fFragmentProcessors.count() != that.fFragmentProcessors.count() ||
- fColorFragmentProcessorCnt != that.fColorFragmentProcessorCnt) {
- return false;
- }
- for (int i = 0; i < fFragmentProcessors.count(); ++i) {
- if (!fFragmentProcessors[i]->isEqual(*that.fFragmentProcessors[i])) {
- return false;
- }
- }
- if (fXPFactory != that.fXPFactory) {
- return false;
- }
- return true;
-}
-
//////////////////////////////////////////////////////////////////////////////
void GrProcessorSet::FragmentProcessorAnalysis::internalInit(const GrPipelineInput& colorInput,
diff --git a/src/gpu/GrProcessorSet.h b/src/gpu/GrProcessorSet.h
index 18a52fd..8203491 100644
--- a/src/gpu/GrProcessorSet.h
+++ b/src/gpu/GrProcessorSet.h
@@ -20,15 +20,13 @@
public:
GrProcessorSet(GrPaint&& paint);
- ~GrProcessorSet();
-
- /**
- * If an op is recorded with this processor set then this must be called to ensure pending
- * reads and writes are propagated to resources referred to by the processors. Otherwise,
- * data hazards may occur.
- */
- void makePendingExecution();
- bool isPendingExecution() const { return SkToBool(kPendingExecution_Flag & fFlags); }
+ ~GrProcessorSet() {
+ // We are deliberately not using sk_sp here because this will be updated to work with
+ // "pending execution" refs.
+ for (auto fp : fFragmentProcessors) {
+ fp->unref();
+ }
+ }
int numColorFragmentProcessors() const { return fColorFragmentProcessorCnt; }
int numCoverageFragmentProcessors() const {
@@ -52,9 +50,6 @@
}
bool allowSRGBInputs() const { return SkToBool(fFlags & kAllowSRGBInputs_Flag); }
- bool operator==(const GrProcessorSet& that) const;
- bool operator!=(const GrProcessorSet& that) const { return !(*this == that); }
-
/**
* This is used to track analysis of color and coverage values through the fragment processors.
*/
@@ -161,8 +156,7 @@
enum Flags : uint16_t {
kUseDistanceVectorField_Flag = 0x1,
kDisableOutputConversionToSRGB_Flag = 0x2,
- kAllowSRGBInputs_Flag = 0x4,
- kPendingExecution_Flag = 0x8
+ kAllowSRGBInputs_Flag = 0x4
};
const GrXPFactory* fXPFactory = nullptr;
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 85e5b74..8cc383d 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -507,17 +507,22 @@
return true;
}
- if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() &&
- (!ss || ss->isDisabled(false))) {
+ GrAAType aaType;
+
+ if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
InstancedRendering* ir = this->getOpList()->instancedRendering();
- std::unique_ptr<GrDrawOp> op = ir->recordRect(croppedRect, viewMatrix, std::move(paint), aa,
- fInstancedPipelineInfo);
+ std::unique_ptr<GrDrawOp> op = ir->recordRect(croppedRect, viewMatrix, paint.getColor(), aa,
+ fInstancedPipelineInfo, &aaType);
if (op) {
- this->addDrawOp(clip, std::move(op));
+ GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
+ if (ss) {
+ pipelineBuilder.setUserStencil(ss);
+ }
+ this->addDrawOp(pipelineBuilder, clip, std::move(op));
return true;
}
}
- GrAAType aaType = this->decideAAType(aa);
+ aaType = this->decideAAType(aa);
if (GrAAType::kCoverage == aaType) {
// The fill path can handle rotation but not skew.
if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
@@ -806,18 +811,21 @@
}
AutoCheckFlush acf(this->drawingManager());
+ GrAAType aaType;
if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
InstancedRendering* ir = this->getOpList()->instancedRendering();
- std::unique_ptr<GrDrawOp> op(ir->recordRect(croppedRect, viewMatrix, std::move(paint),
- croppedLocalRect, aa, fInstancedPipelineInfo));
+ std::unique_ptr<GrDrawOp> op(ir->recordRect(croppedRect, viewMatrix, paint.getColor(),
+ croppedLocalRect, aa, fInstancedPipelineInfo,
+ &aaType));
if (op) {
- this->addDrawOp(clip, std::move(op));
+ GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
+ this->addDrawOp(pipelineBuilder, clip, std::move(op));
return;
}
}
- GrAAType aaType = this->decideAAType(aa);
+ aaType = this->decideAAType(aa);
if (GrAAType::kCoverage != aaType) {
this->drawNonAAFilledRect(clip, std::move(paint), viewMatrix, croppedRect,
&croppedLocalRect, nullptr, nullptr, aaType);
@@ -825,10 +833,10 @@
}
if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
- std::unique_ptr<GrMeshDrawOp> op = GrAAFillRectOp::MakeWithLocalRect(
+ std::unique_ptr<GrDrawOp> op = GrAAFillRectOp::MakeWithLocalRect(
paint.getColor(), viewMatrix, croppedRect, croppedLocalRect);
GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
- this->addMeshDrawOp(pipelineBuilder, clip, std::move(op));
+ this->addDrawOp(pipelineBuilder, clip, std::move(op));
return;
}
@@ -862,18 +870,21 @@
}
AutoCheckFlush acf(this->drawingManager());
+ GrAAType aaType;
if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
InstancedRendering* ir = this->getOpList()->instancedRendering();
- std::unique_ptr<GrDrawOp> op(ir->recordRect(croppedRect, viewMatrix, std::move(paint),
- localMatrix, aa, fInstancedPipelineInfo));
+ std::unique_ptr<GrDrawOp> op(ir->recordRect(croppedRect, viewMatrix, paint.getColor(),
+ localMatrix, aa, fInstancedPipelineInfo,
+ &aaType));
if (op) {
- this->addDrawOp(clip, std::move(op));
+ GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
+ this->addDrawOp(pipelineBuilder, clip, std::move(op));
return;
}
}
- GrAAType aaType = this->decideAAType(aa);
+ aaType = this->decideAAType(aa);
if (GrAAType::kCoverage != aaType) {
this->drawNonAAFilledRect(clip, std::move(paint), viewMatrix, croppedRect, nullptr,
&localMatrix, nullptr, aaType);
@@ -1014,19 +1025,21 @@
AutoCheckFlush acf(this->drawingManager());
const SkStrokeRec stroke = style.strokeRec();
+ GrAAType aaType;
if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() &&
stroke.isFillStyle()) {
InstancedRendering* ir = this->getOpList()->instancedRendering();
- std::unique_ptr<GrDrawOp> op(
- ir->recordRRect(rrect, viewMatrix, std::move(paint), aa, fInstancedPipelineInfo));
+ std::unique_ptr<GrDrawOp> op(ir->recordRRect(rrect, viewMatrix, paint.getColor(), aa,
+ fInstancedPipelineInfo, &aaType));
if (op) {
- this->addDrawOp(*clip, std::move(op));
+ GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
+ this->addDrawOp(pipelineBuilder, *clip, std::move(op));
return;
}
}
- GrAAType aaType = this->decideAAType(aa);
+ aaType = this->decideAAType(aa);
if (GrAAType::kCoverage == aaType) {
const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
std::unique_ptr<GrMeshDrawOp> op =
@@ -1091,18 +1104,21 @@
const SkRRect& origInner) {
SkASSERT(!origInner.isEmpty());
SkASSERT(!origOuter.isEmpty());
+ GrAAType aaType;
if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
InstancedRendering* ir = this->getOpList()->instancedRendering();
- std::unique_ptr<GrDrawOp> op(ir->recordDRRect(
- origOuter, origInner, viewMatrix, std::move(paint), aa, fInstancedPipelineInfo));
+ std::unique_ptr<GrDrawOp> op(ir->recordDRRect(origOuter, origInner, viewMatrix,
+ paint.getColor(), aa, fInstancedPipelineInfo,
+ &aaType));
if (op) {
- this->addDrawOp(clip, std::move(op));
+ GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
+ this->addDrawOp(pipelineBuilder, clip, std::move(op));
return true;
}
}
- GrAAType aaType = this->decideAAType(aa);
+ aaType = this->decideAAType(aa);
GrPrimitiveEdgeType innerEdgeType, outerEdgeType;
if (GrAAType::kCoverage == aaType) {
@@ -1239,19 +1255,21 @@
AutoCheckFlush acf(this->drawingManager());
const SkStrokeRec& stroke = style.strokeRec();
+ GrAAType aaType;
if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() &&
stroke.isFillStyle()) {
InstancedRendering* ir = this->getOpList()->instancedRendering();
- std::unique_ptr<GrDrawOp> op(
- ir->recordOval(oval, viewMatrix, std::move(paint), aa, fInstancedPipelineInfo));
+ std::unique_ptr<GrDrawOp> op(ir->recordOval(oval, viewMatrix, paint.getColor(), aa,
+ fInstancedPipelineInfo, &aaType));
if (op) {
- this->addDrawOp(clip, std::move(op));
+ GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
+ this->addDrawOp(pipelineBuilder, clip, std::move(op));
return;
}
}
- GrAAType aaType = this->decideAAType(aa);
+ aaType = this->decideAAType(aa);
if (GrAAType::kCoverage == aaType) {
const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
std::unique_ptr<GrMeshDrawOp> op =
@@ -1655,7 +1673,15 @@
}
}
-uint32_t GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<GrDrawOp> op) {
+uint32_t GrRenderTargetContext::addMeshDrawOp(const GrPipelineBuilder& pipelineBuilder,
+ const GrClip& clip,
+ std::unique_ptr<GrMeshDrawOp> op) {
+ return this->addDrawOp(pipelineBuilder, clip, std::move(op));
+}
+
+uint32_t GrRenderTargetContext::addDrawOp(const GrPipelineBuilder& pipelineBuilder,
+ const GrClip& clip,
+ std::unique_ptr<GrDrawOp> op) {
ASSERT_SINGLE_OWNER
if (this->drawingManager()->wasAbandoned()) {
return SK_InvalidUniqueID;
@@ -1667,53 +1693,6 @@
SkRect bounds;
op_bounds(&bounds, op.get());
GrAppliedClip appliedClip;
- GrDrawOp::FixedFunctionFlags fixedFunctionFlags = op->fixedFunctionFlags();
- if (!clip.apply(fContext, this, fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesHWAA,
- fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil, &appliedClip,
- &bounds)) {
- return SK_InvalidUniqueID;
- }
-
- // This forces instantiation of the render target.
- GrRenderTarget* rt = this->accessRenderTarget();
- if (!rt) {
- return SK_InvalidUniqueID;
- }
-
- if (fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesStencil ||
- appliedClip.hasStencilClip()) {
- if (!fContext->resourceProvider()->attachStencilAttachment(rt)) {
- SkDebugf("ERROR creating stencil attachment. Draw skipped.\n");
- return SK_InvalidUniqueID;
- }
- }
-
- GrXferProcessor::DstTexture dstTexture;
- if (op->xpRequiresDstTexture(*this->caps(), &appliedClip)) {
- this->setupDstTexture(rt, clip, op->bounds(), &dstTexture);
- if (!dstTexture.texture()) {
- return SK_InvalidUniqueID;
- }
- }
-
- op->setClippedBounds(bounds);
- return this->getOpList()->addOp(std::move(op), this, std::move(appliedClip), dstTexture);
-}
-
-uint32_t GrRenderTargetContext::addMeshDrawOp(const GrPipelineBuilder& pipelineBuilder,
- const GrClip& clip,
- std::unique_ptr<GrMeshDrawOp> op) {
- ASSERT_SINGLE_OWNER
- if (this->drawingManager()->wasAbandoned()) {
- return SK_InvalidUniqueID;
- }
- SkDEBUGCODE(this->validate();)
- GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::addMeshDrawOp");
-
- // Setup clip
- SkRect bounds;
- op_bounds(&bounds, op.get());
- GrAppliedClip appliedClip;
if (!clip.apply(fContext, this, pipelineBuilder.isHWAntialias(),
pipelineBuilder.hasUserStencilSettings(), &appliedClip, &bounds)) {
return SK_InvalidUniqueID;
diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h
index 8b07c22..c6793d3 100644
--- a/src/gpu/GrRenderTargetContext.h
+++ b/src/gpu/GrRenderTargetContext.h
@@ -22,8 +22,8 @@
class GrDrawingManager;
class GrDrawOp;
class GrFixedClip;
-class GrMeshDrawOp;
class GrPipelineBuilder;
+class GrMeshDrawOp;
class GrRenderTarget;
class GrRenderTargetContextPriv;
class GrRenderTargetOpList;
@@ -478,8 +478,9 @@
// These perform processing specific to Gr[Mesh]DrawOp-derived ops before recording them into
// the op list. They return the id of the opList to which the op was added, or 0, if it was
// dropped (e.g., due to clipping).
- uint32_t addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>);
- uint32_t addMeshDrawOp(const GrPipelineBuilder&, const GrClip&, std::unique_ptr<GrMeshDrawOp>);
+ uint32_t addDrawOp(const GrPipelineBuilder&, const GrClip&, std::unique_ptr<GrDrawOp>);
+ uint32_t addMeshDrawOp(const GrPipelineBuilder&, const GrClip&,
+ std::unique_ptr<GrMeshDrawOp> op);
// Makes a copy of the dst if it is necessary for the draw and returns the texture that should
// be used by GrXferProcessor to access the destination color. If the texture is nullptr then
diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp
index 1a9452f..1c98353 100644
--- a/src/gpu/GrRenderTargetOpList.cpp
+++ b/src/gpu/GrRenderTargetOpList.cpp
@@ -30,12 +30,10 @@
GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* rtp, GrGpu* gpu,
GrResourceProvider* resourceProvider,
GrAuditTrail* auditTrail, const Options& options)
- : INHERITED(rtp, auditTrail)
- , fGpu(SkRef(gpu))
- , fResourceProvider(resourceProvider)
- , fLastClipStackGenID(SK_InvalidUniqueID)
- , fClipAllocator(fClipAllocatorStorage, sizeof(fClipAllocatorStorage),
- sizeof(fClipAllocatorStorage)) {
+ : INHERITED(rtp, auditTrail)
+ , fGpu(SkRef(gpu))
+ , fResourceProvider(resourceProvider)
+ , fLastClipStackGenID(SK_InvalidUniqueID) {
fMaxOpLookback = (options.fMaxOpCombineLookback < 0) ? kDefaultMaxOpLookback
: options.fMaxOpCombineLookback;
@@ -84,17 +82,7 @@
// Loop over the ops that haven't yet been prepared.
for (int i = 0; i < fRecordedOps.count(); ++i) {
if (fRecordedOps[i].fOp) {
- GrOpFlushState::DrawOpArgs opArgs;
- if (fRecordedOps[i].fRenderTarget) {
- opArgs = {
- fRecordedOps[i].fRenderTarget.get(),
- fRecordedOps[i].fAppliedClip,
- fRecordedOps[i].fDstTexture
- };
- }
- flushState->setDrawOpArgs(&opArgs);
fRecordedOps[i].fOp->prepare(flushState);
- flushState->setDrawOpArgs(nullptr);
}
}
@@ -134,17 +122,7 @@
}
flushState->setCommandBuffer(commandBuffer.get());
}
- GrOpFlushState::DrawOpArgs opArgs;
- if (fRecordedOps[i].fRenderTarget) {
- opArgs = {
- fRecordedOps[i].fRenderTarget.get(),
- fRecordedOps[i].fAppliedClip,
- fRecordedOps[i].fDstTexture
- };
- flushState->setDrawOpArgs(&opArgs);
- }
fRecordedOps[i].fOp->execute(flushState);
- flushState->setDrawOpArgs(nullptr);
}
if (commandBuffer) {
commandBuffer->end();
@@ -235,33 +213,8 @@
b.fRight <= a.fLeft || b.fBottom <= a.fTop;
}
-bool GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b,
- const GrAppliedClip* bClip,
- const DstTexture* bDstTexture) {
- if (a.fAppliedClip) {
- if (!bClip) {
- return false;
- }
- if (*a.fAppliedClip != *bClip) {
- return false;
- }
- } else if (bClip) {
- return false;
- }
- if (bDstTexture) {
- if (a.fDstTexture != *bDstTexture) {
- return false;
- }
- } else if (a.fDstTexture.texture()) {
- return false;
- }
- return a.fOp->combineIfPossible(b, *this->caps());
-}
-
GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op,
- GrRenderTargetContext* renderTargetContext,
- GrAppliedClip* clip,
- const DstTexture* dstTexture) {
+ GrRenderTargetContext* renderTargetContext) {
GrRenderTarget* renderTarget =
renderTargetContext ? renderTargetContext->accessRenderTarget()
: nullptr;
@@ -296,7 +249,7 @@
candidate.fOp->uniqueID());
break;
}
- if (this->combineIfPossible(candidate, op.get(), clip, dstTexture)) {
+ if (candidate.fOp->combineIfPossible(op.get(), *this->caps())) {
GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(),
candidate.fOp->uniqueID());
GrOP_INFO("\t\t\tCombined op info:\n");
@@ -320,10 +273,7 @@
GrOP_INFO("\t\tFirstOp\n");
}
GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op);
- if (clip) {
- clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip));
- }
- fRecordedOps.emplace_back(std::move(op), renderTarget, clip, dstTexture);
+ fRecordedOps.emplace_back(std::move(op), renderTarget);
fRecordedOps.back().fOp->wasRecorded();
fLastFullClearOp = nullptr;
fLastFullClearRenderTargetID.makeInvalid();
@@ -356,10 +306,9 @@
// via backwards combining in recordOp.
// not sure why this fires with device-clipping in gm/complexclip4.cpp
- SkASSERT(!this->combineIfPossible(fRecordedOps[i], candidate.fOp.get(),
- candidate.fAppliedClip, &candidate.fDstTexture));
- } else if (this->combineIfPossible(fRecordedOps[i], candidate.fOp.get(),
- candidate.fAppliedClip, &candidate.fDstTexture)) {
+// SkASSERT(!op->combineIfPossible(candidate.fOp.get(), *this->caps()));
+
+ } else if (op->combineIfPossible(candidate.fOp.get(), *this->caps())) {
GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(),
candidate.fOp->uniqueID());
GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get());
diff --git a/src/gpu/GrRenderTargetOpList.h b/src/gpu/GrRenderTargetOpList.h
index 976b271..f4458b5 100644
--- a/src/gpu/GrRenderTargetOpList.h
+++ b/src/gpu/GrRenderTargetOpList.h
@@ -8,11 +8,9 @@
#ifndef GrRenderTargetOpList_DEFINED
#define GrRenderTargetOpList_DEFINED
-#include "GrAppliedClip.h"
#include "GrOpList.h"
-#include "GrPathRendering.h"
#include "GrPrimitiveProcessor.h"
-#include "SkArenaAlloc.h"
+#include "GrPathRendering.h"
#include "SkClipStack.h"
#include "SkMatrix.h"
#include "SkStringUtils.h"
@@ -24,14 +22,12 @@
class GrAuditTrail;
class GrClearOp;
class GrCaps;
+class GrClip;
class GrOp;
class GrPipelineBuilder;
class GrRenderTargetProxy;
class GrRenderTargetOpList final : public GrOpList {
-private:
- using DstTexture = GrXferProcessor::DstTexture;
-
public:
/** Options for GrRenderTargetOpList behavior. */
struct Options {
@@ -72,13 +68,7 @@
const GrCaps* caps() const { return fGpu->caps(); }
uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) {
- this->recordOp(std::move(op), renderTargetContext, nullptr, nullptr);
- return this->uniqueID();
- }
- uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext,
- GrAppliedClip&& clip, const DstTexture& dstTexture) {
- this->recordOp(std::move(op), renderTargetContext, clip.doesClip() ? &clip : nullptr,
- &dstTexture);
+ this->recordOp(std::move(op), renderTargetContext);
return this->uniqueID();
}
@@ -115,34 +105,23 @@
private:
friend class GrRenderTargetContextPriv; // for clearStencilClip and stencil clip state.
- struct RecordedOp {
- RecordedOp(std::unique_ptr<GrOp> op, GrRenderTarget* rt, const GrAppliedClip* appliedClip,
- const DstTexture* dstTexture)
- : fOp(std::move(op)), fRenderTarget(rt), fAppliedClip(appliedClip) {
- if (dstTexture) {
- fDstTexture = *dstTexture;
- }
- }
- std::unique_ptr<GrOp> fOp;
- // TODO: These ops will all to target the same render target and this won't be needed.
- GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
- DstTexture fDstTexture;
- const GrAppliedClip* fAppliedClip;
- };
-
// If the input op is combined with an earlier op, this returns the combined op. Otherwise, it
// returns the input op.
- GrOp* recordOp(std::unique_ptr<GrOp>, GrRenderTargetContext*, GrAppliedClip* = nullptr,
- const DstTexture* = nullptr);
+ GrOp* recordOp(std::unique_ptr<GrOp>, GrRenderTargetContext*);
void forwardCombine();
// Used only via GrRenderTargetContextPriv.
void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTargetContext*);
- // If this returns true then b has been merged into a's op.
- bool combineIfPossible(const RecordedOp& a, GrOp* b, const GrAppliedClip* bClip,
- const DstTexture* bDstTexture);
+ struct RecordedOp {
+ RecordedOp(std::unique_ptr<GrOp> op, GrRenderTarget* rt)
+ : fOp(std::move(op)), fRenderTarget(rt) {}
+ std::unique_ptr<GrOp> fOp;
+ // TODO: These ops will all to target the same render target and this won't be needed.
+ GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
+ };
+ SkSTArray<256, RecordedOp, true> fRecordedOps;
GrClearOp* fLastFullClearOp = nullptr;
GrGpuResource::UniqueID fLastFullClearRenderTargetID = GrGpuResource::UniqueID::InvalidID();
@@ -158,11 +137,6 @@
int32_t fLastClipStackGenID;
SkIRect fLastDevClipBounds;
- SkSTArray<256, RecordedOp, true> fRecordedOps;
-
- char fClipAllocatorStorage[4096];
- SkArenaAlloc fClipAllocator;
-
typedef GrOpList INHERITED;
};
diff --git a/src/gpu/GrTextureOpList.cpp b/src/gpu/GrTextureOpList.cpp
index 8a0bc1a..d70daa2 100644
--- a/src/gpu/GrTextureOpList.cpp
+++ b/src/gpu/GrTextureOpList.cpp
@@ -54,7 +54,6 @@
// Loop over the ops that haven't yet generated their geometry
for (int i = 0; i < fRecordedOps.count(); ++i) {
if (fRecordedOps[i]) {
- // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
fRecordedOps[i]->prepare(flushState);
}
}
@@ -66,7 +65,6 @@
}
for (int i = 0; i < fRecordedOps.count(); ++i) {
- // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
fRecordedOps[i]->execute(flushState);
}
diff --git a/src/gpu/GrXferProcessor.cpp b/src/gpu/GrXferProcessor.cpp
index 32ab45c..4d877d6 100644
--- a/src/gpu/GrXferProcessor.cpp
+++ b/src/gpu/GrXferProcessor.cpp
@@ -176,6 +176,14 @@
///////////////////////////////////////////////////////////////////////////////
+bool GrXPFactory::WillReadDst(const GrXPFactory* factory,
+ const GrProcessorSet::FragmentProcessorAnalysis& analysis) {
+ if (factory) {
+ return factory->willReadsDst(analysis);
+ }
+ return GrPorterDuffXPFactory::WillSrcOverReadDst(analysis);
+}
+
bool GrXPFactory::WillNeedDstTexture(const GrXPFactory* factory, const GrCaps& caps,
const GrProcessorSet::FragmentProcessorAnalysis& analysis) {
bool result;
@@ -185,6 +193,7 @@
} else {
result = GrPorterDuffXPFactory::WillSrcOverNeedDstTexture(caps, analysis);
}
+ SkASSERT(!(result && !WillReadDst(factory, analysis)));
return result;
}
@@ -195,14 +204,6 @@
return GrPorterDuffXPFactory::SrcOverIsCompatibleWithCoverageAsAlpha();
}
-bool GrXPFactory::CanCombineOverlappedStencilAndCover(const GrXPFactory* factory,
- bool colorIsOpaque) {
- if (factory) {
- return factory->canCombineOverlappedStencilAndCover(colorIsOpaque);
- }
- return GrPorterDuffXPFactory::SrcOverCanCombineOverlappedStencilAndCover(colorIsOpaque);
-}
-
GrXferProcessor* GrXPFactory::createXferProcessor(const FragmentProcessorAnalysis& analysis,
bool hasMixedSamples,
const DstTexture* dstTexture,
diff --git a/src/gpu/GrXferProcessor.h b/src/gpu/GrXferProcessor.h
index 35ce5fa..7f3fd30 100644
--- a/src/gpu/GrXferProcessor.h
+++ b/src/gpu/GrXferProcessor.h
@@ -65,7 +65,9 @@
}
DstTexture(GrTexture* texture, const SkIPoint& offset)
- : fTexture(SkSafeRef(texture)), fOffset(texture ? offset : SkIPoint{0, 0}) {}
+ : fTexture(SkSafeRef(texture))
+ , fOffset(offset) {
+ }
DstTexture& operator=(const DstTexture& other) {
fTexture = other.fTexture;
@@ -73,11 +75,6 @@
return *this;
}
- bool operator==(const DstTexture& that) const {
- return fTexture == that.fTexture && fOffset == that.fOffset;
- }
- bool operator!=(const DstTexture& that) const { return !(*this == that); }
-
const SkIPoint& offset() const { return fOffset; }
void setOffset(const SkIPoint& offset) { fOffset = offset; }
@@ -87,9 +84,6 @@
void setTexture(sk_sp<GrTexture> texture) {
fTexture = std::move(texture);
- if (!fTexture) {
- fOffset = {0, 0};
- }
}
private:
@@ -307,6 +301,11 @@
const GrCaps& caps) const;
/**
+ * Is the destination color required either in the shader or fixed function blending.
+ */
+ static bool WillReadDst(const GrXPFactory*, const FragmentProcessorAnalysis&);
+
+ /**
* This will return true if the xfer processor needs the dst color in the shader and the way
* that the color will be made available to the xfer processor is by sampling a texture.
*/
@@ -316,17 +315,13 @@
static bool CompatibleWithCoverageAsAlpha(const GrXPFactory*, bool colorIsOpaque);
- /**
- * This indicates whether the the xfer processor will produce the same bleneded color result
- * if a series of overlapping stencil and cover operations are replaced by a series of stencil
- * operations and a single cover. A uniform src color is assumed.
- **/
- static bool CanCombineOverlappedStencilAndCover(const GrXPFactory*, bool colorIsOpaque);
-
protected:
constexpr GrXPFactory() {}
private:
+ /** Subclass-specific implementation of WillReadDst(). */
+ virtual bool willReadsDst(const FragmentProcessorAnalysis& pipelineAnalysis) const = 0;
+
virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
const FragmentProcessorAnalysis&,
bool hasMixedSamples,
@@ -339,7 +334,6 @@
virtual bool willReadDstInShader(const GrCaps&, const FragmentProcessorAnalysis&) const = 0;
virtual bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const = 0;
- virtual bool canCombineOverlappedStencilAndCover(bool colorIsOpaque) const { return false; }
};
#if defined(__GNUC__) || defined(__clang)
#pragma GCC diagnostic pop
diff --git a/src/gpu/effects/GrCoverageSetOpXP.h b/src/gpu/effects/GrCoverageSetOpXP.h
index 184ef4e..807a2b0 100644
--- a/src/gpu/effects/GrCoverageSetOpXP.h
+++ b/src/gpu/effects/GrCoverageSetOpXP.h
@@ -32,6 +32,10 @@
private:
constexpr GrCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage);
+ bool willReadsDst(const FragmentProcessorAnalysis&) const override {
+ return fRegionOp != SkRegion::kReplace_Op;
+ }
+
GrXferProcessor* onCreateXferProcessor(const GrCaps&,
const FragmentProcessorAnalysis&,
bool hasMixedSamples,
diff --git a/src/gpu/effects/GrCustomXfermode.cpp b/src/gpu/effects/GrCustomXfermode.cpp
index 37e4c16..31c42eb 100644
--- a/src/gpu/effects/GrCustomXfermode.cpp
+++ b/src/gpu/effects/GrCustomXfermode.cpp
@@ -327,6 +327,8 @@
bool hasMixedSamples,
const DstTexture*) const override;
+ bool willReadsDst(const FragmentProcessorAnalysis&) const override { return true; }
+
bool willReadDstInShader(const GrCaps&, const FragmentProcessorAnalysis&) const override;
bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const override { return true; }
diff --git a/src/gpu/effects/GrDisableColorXP.h b/src/gpu/effects/GrDisableColorXP.h
index 78442f4..f9206f7 100644
--- a/src/gpu/effects/GrDisableColorXP.h
+++ b/src/gpu/effects/GrDisableColorXP.h
@@ -24,6 +24,8 @@
static const GrXPFactory* Get();
private:
+ bool willReadsDst(const FragmentProcessorAnalysis&) const override { return false; }
+
constexpr GrDisableColorXPFactory() {}
bool willReadDstInShader(const GrCaps&, const FragmentProcessorAnalysis&) const override {
diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp
index f984355..8b35bb9 100644
--- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp
+++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp
@@ -759,11 +759,10 @@
return new PorterDuffXferProcessor(blendFormula);
}
-bool GrPorterDuffXPFactory::canCombineOverlappedStencilAndCover(bool colorIsOpaque) const {
- // Ignore the effect of coverage here.
- BlendFormula colorFormula = gBlendTable[colorIsOpaque][0][(int)fBlendMode];
+bool GrPorterDuffXPFactory::willReadsDst(const FragmentProcessorAnalysis& analysis) const {
+ BlendFormula colorFormula = gBlendTable[analysis.isOutputColorOpaque()][0][(int)fBlendMode];
SkASSERT(kAdd_GrBlendEquation == colorFormula.fBlendEquation);
- return !colorFormula.usesDstColor();
+ return (colorFormula.usesDstColor() || analysis.hasCoverage());
}
bool GrPorterDuffXPFactory::willReadDstInShader(const GrCaps& caps,
@@ -870,6 +869,10 @@
return sk_make_sp<PorterDuffXferProcessor>(formula);
}
+bool GrPorterDuffXPFactory::WillSrcOverReadDst(const FragmentProcessorAnalysis& analysis) {
+ return analysis.hasCoverage() || !analysis.isOutputColorOpaque();
+}
+
bool GrPorterDuffXPFactory::WillSrcOverNeedDstTexture(const GrCaps& caps,
const FragmentProcessorAnalysis& analysis) {
if (caps.shaderCaps()->dstReadInShaderSupport() ||
diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.h b/src/gpu/effects/GrPorterDuffXferProcessor.h
index 719bd18..dd790e8 100644
--- a/src/gpu/effects/GrPorterDuffXferProcessor.h
+++ b/src/gpu/effects/GrPorterDuffXferProcessor.h
@@ -37,16 +37,14 @@
by reference because it is global and its ref-cnting methods are not thread safe. */
static const GrXferProcessor& SimpleSrcOverXP();
+ static bool WillSrcOverReadDst(const FragmentProcessorAnalysis& analysis);
static bool WillSrcOverNeedDstTexture(const GrCaps&, const FragmentProcessorAnalysis&);
static bool SrcOverIsCompatibleWithCoverageAsAlpha() { return true; }
- static bool SrcOverCanCombineOverlappedStencilAndCover(bool colorIsOpaque) {
- return colorIsOpaque;
- }
private:
constexpr GrPorterDuffXPFactory(SkBlendMode);
- bool canCombineOverlappedStencilAndCover(bool colorIsOpaque) const override;
+ bool willReadsDst(const FragmentProcessorAnalysis&) const override;
GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
const FragmentProcessorAnalysis&,
diff --git a/src/gpu/instanced/GLInstancedRendering.cpp b/src/gpu/instanced/GLInstancedRendering.cpp
index bfdb960..0d2a2dd 100644
--- a/src/gpu/instanced/GLInstancedRendering.cpp
+++ b/src/gpu/instanced/GLInstancedRendering.cpp
@@ -19,8 +19,7 @@
public:
DEFINE_OP_CLASS_ID
- GLOp(GLInstancedRendering* instRendering, GrPaint&& paint)
- : INHERITED(ClassID(), std::move(paint), instRendering) {}
+ GLOp(GLInstancedRendering* instRendering) : INHERITED(ClassID(), instRendering) {}
int numGLCommands() const { return 1 + fNumChangesInGeometry; }
private:
@@ -61,8 +60,8 @@
return static_cast<GrGLGpu*>(this->gpu());
}
-std::unique_ptr<InstancedRendering::Op> GLInstancedRendering::makeOp(GrPaint&& paint) {
- return std::unique_ptr<Op>(new GLOp(this, std::move(paint)));
+std::unique_ptr<InstancedRendering::Op> GLInstancedRendering::makeOp() {
+ return std::unique_ptr<Op>(new GLOp(this));
}
void GLInstancedRendering::onBeginFlush(GrResourceProvider* rp) {
diff --git a/src/gpu/instanced/GLInstancedRendering.h b/src/gpu/instanced/GLInstancedRendering.h
index d1affba..0088217 100644
--- a/src/gpu/instanced/GLInstancedRendering.h
+++ b/src/gpu/instanced/GLInstancedRendering.h
@@ -33,7 +33,7 @@
GrGLGpu* glGpu() const;
- std::unique_ptr<Op> makeOp(GrPaint&& paint) override;
+ std::unique_ptr<Op> makeOp() override;
void onBeginFlush(GrResourceProvider*) override;
void onDraw(const GrPipeline&, const InstanceProcessor&, const Op*) override;
diff --git a/src/gpu/instanced/InstancedRendering.cpp b/src/gpu/instanced/InstancedRendering.cpp
index 179552c..ef2264b 100644
--- a/src/gpu/instanced/InstancedRendering.cpp
+++ b/src/gpu/instanced/InstancedRendering.cpp
@@ -22,31 +22,32 @@
}
std::unique_ptr<GrDrawOp> InstancedRendering::recordRect(const SkRect& rect,
- const SkMatrix& viewMatrix,
- GrPaint&& paint, GrAA aa,
- const GrInstancedPipelineInfo& info) {
- return this->recordShape(ShapeType::kRect, rect, viewMatrix, std::move(paint), rect, aa, info);
-}
-
-std::unique_ptr<GrDrawOp> InstancedRendering::recordRect(const SkRect& rect,
- const SkMatrix& viewMatrix,
- GrPaint&& paint, const SkRect& localRect,
+ const SkMatrix& viewMatrix, GrColor color,
GrAA aa,
- const GrInstancedPipelineInfo& info) {
- return this->recordShape(ShapeType::kRect, rect, viewMatrix, std::move(paint), localRect, aa,
- info);
+ const GrInstancedPipelineInfo& info,
+ GrAAType* aaType) {
+ return this->recordShape(ShapeType::kRect, rect, viewMatrix, color, rect, aa, info, aaType);
}
std::unique_ptr<GrDrawOp> InstancedRendering::recordRect(const SkRect& rect,
- const SkMatrix& viewMatrix,
- GrPaint&& paint,
+ const SkMatrix& viewMatrix, GrColor color,
+ const SkRect& localRect, GrAA aa,
+ const GrInstancedPipelineInfo& info,
+ GrAAType* aaType) {
+ return this->recordShape(ShapeType::kRect, rect, viewMatrix, color, localRect, aa, info,
+ aaType);
+}
+
+std::unique_ptr<GrDrawOp> InstancedRendering::recordRect(const SkRect& rect,
+ const SkMatrix& viewMatrix, GrColor color,
const SkMatrix& localMatrix, GrAA aa,
- const GrInstancedPipelineInfo& info) {
+ const GrInstancedPipelineInfo& info,
+ GrAAType* aaType) {
if (localMatrix.hasPerspective()) {
return nullptr; // Perspective is not yet supported in the local matrix.
}
- if (std::unique_ptr<Op> op = this->recordShape(ShapeType::kRect, rect, viewMatrix,
- std::move(paint), rect, aa, info)) {
+ if (std::unique_ptr<Op> op = this->recordShape(ShapeType::kRect, rect, viewMatrix, color, rect,
+ aa, info, aaType)) {
op->getSingleInstance().fInfo |= kLocalMatrix_InfoFlag;
op->appendParamsTexel(localMatrix.getScaleX(), localMatrix.getSkewX(),
localMatrix.getTranslateX());
@@ -59,39 +60,39 @@
}
std::unique_ptr<GrDrawOp> InstancedRendering::recordOval(const SkRect& oval,
- const SkMatrix& viewMatrix,
- GrPaint&& paint, GrAA aa,
- const GrInstancedPipelineInfo& info) {
- return this->recordShape(ShapeType::kOval, oval, viewMatrix, std::move(paint), oval, aa, info);
+ const SkMatrix& viewMatrix, GrColor color,
+ GrAA aa,
+ const GrInstancedPipelineInfo& info,
+ GrAAType* aaType) {
+ return this->recordShape(ShapeType::kOval, oval, viewMatrix, color, oval, aa, info, aaType);
}
std::unique_ptr<GrDrawOp> InstancedRendering::recordRRect(const SkRRect& rrect,
- const SkMatrix& viewMatrix,
- GrPaint&& paint, GrAA aa,
- const GrInstancedPipelineInfo& info) {
+ const SkMatrix& viewMatrix, GrColor color,
+ GrAA aa,
+ const GrInstancedPipelineInfo& info,
+ GrAAType* aaType) {
if (std::unique_ptr<Op> op =
- this->recordShape(GetRRectShapeType(rrect), rrect.rect(), viewMatrix,
- std::move(paint), rrect.rect(), aa, info)) {
+ this->recordShape(GetRRectShapeType(rrect), rrect.rect(), viewMatrix, color,
+ rrect.rect(), aa, info, aaType)) {
op->appendRRectParams(rrect);
return std::move(op);
}
return nullptr;
}
-std::unique_ptr<GrDrawOp> InstancedRendering::recordDRRect(const SkRRect& outer,
- const SkRRect& inner,
- const SkMatrix& viewMatrix,
- GrPaint&& paint, GrAA aa,
- const GrInstancedPipelineInfo& info) {
+std::unique_ptr<GrDrawOp> InstancedRendering::recordDRRect(
+ const SkRRect& outer, const SkRRect& inner, const SkMatrix& viewMatrix, GrColor color,
+ GrAA aa, const GrInstancedPipelineInfo& info, GrAAType* aaType) {
if (inner.getType() > SkRRect::kSimple_Type) {
return nullptr; // Complex inner round rects are not yet supported.
}
if (SkRRect::kEmpty_Type == inner.getType()) {
- return this->recordRRect(outer, viewMatrix, std::move(paint), aa, info);
+ return this->recordRRect(outer, viewMatrix, color, aa, info, aaType);
}
if (std::unique_ptr<Op> op =
- this->recordShape(GetRRectShapeType(outer), outer.rect(), viewMatrix,
- std::move(paint), outer.rect(), aa, info)) {
+ this->recordShape(GetRRectShapeType(outer), outer.rect(), viewMatrix, color,
+ outer.rect(), aa, info, aaType)) {
op->appendRRectParams(outer);
ShapeType innerShapeType = GetRRectShapeType(inner);
op->fInfo.fInnerShapeTypes |= GetShapeFlag(innerShapeType);
@@ -104,31 +105,28 @@
}
std::unique_ptr<InstancedRendering::Op> InstancedRendering::recordShape(
- ShapeType type, const SkRect& bounds, const SkMatrix& viewMatrix, GrPaint&& paint,
- const SkRect& localRect, GrAA aa, const GrInstancedPipelineInfo& info) {
+ ShapeType type, const SkRect& bounds, const SkMatrix& viewMatrix, GrColor color,
+ const SkRect& localRect, GrAA aa, const GrInstancedPipelineInfo& info, GrAAType* aaType) {
SkASSERT(State::kRecordingDraws == fState);
if (info.fIsRenderingToFloat && fGpu->caps()->avoidInstancedDrawsToFPTargets()) {
return nullptr;
}
- GrAAType aaType;
- if (!this->selectAntialiasMode(viewMatrix, aa, info, &aaType)) {
+ if (!this->selectAntialiasMode(viewMatrix, aa, info, aaType)) {
return nullptr;
}
- GrColor color = paint.getColor();
- std::unique_ptr<Op> op = this->makeOp(std::move(paint));
- op->fInfo.setAAType(aaType);
+ std::unique_ptr<Op> op = this->makeOp();
+ op->fInfo.setAAType(*aaType);
op->fInfo.fShapeTypes = GetShapeFlag(type);
op->fInfo.fCannotDiscard = true;
- op->fDrawColorsAreOpaque = GrColorIsOpaque(color);
- op->fDrawColorsAreSame = true;
+
Instance& instance = op->getSingleInstance();
instance.fInfo = (int)type << kShapeType_InfoBit;
Op::HasAABloat aaBloat =
- (aaType == GrAAType::kCoverage) ? Op::HasAABloat::kYes : Op::HasAABloat::kNo;
+ (*aaType == GrAAType::kCoverage) ? Op::HasAABloat::kYes : Op::HasAABloat::kNo;
Op::IsZeroArea zeroArea = (bounds.isEmpty()) ? Op::IsZeroArea::kYes : Op::IsZeroArea::kNo;
// The instanced shape renderer draws rectangles of [-1, -1, +1, +1], so we find the matrix that
@@ -231,10 +229,9 @@
return false;
}
-InstancedRendering::Op::Op(uint32_t classID, GrPaint&& paint, InstancedRendering* ir)
+InstancedRendering::Op::Op(uint32_t classID, InstancedRendering* ir)
: INHERITED(classID)
, fInstancedRendering(ir)
- , fProcessors(std::move(paint))
, fIsTracked(false)
, fNumDraws(1)
, fNumChangesInGeometry(0) {
@@ -332,17 +329,20 @@
fInfo.fHasParams = true;
}
-bool InstancedRendering::Op::xpRequiresDstTexture(const GrCaps& caps, const GrAppliedClip* clip) {
- GrProcessorSet::FragmentProcessorAnalysis analysis;
- GrPipelineInput coverageInput;
+void InstancedRendering::Op::getFragmentProcessorAnalysisInputs(
+ FragmentProcessorAnalysisInputs* input) const {
+ input->colorInput()->setToConstant(this->getSingleInstance().fColor);
+
if (GrAAType::kCoverage == fInfo.aaType() ||
(GrAAType::kNone == fInfo.aaType() && !fInfo.isSimpleRects() && fInfo.fCannotDiscard)) {
- coverageInput = GrPipelineInput();
+ input->coverageInput()->setToUnknown();
} else {
- coverageInput = GrColor_WHITE;
+ input->coverageInput()->setToSolidCoverage();
}
- analysis.init(this->getSingleInstance().fColor, coverageInput, fProcessors, clip, caps);
+}
+void InstancedRendering::Op::applyPipelineOptimizations(
+ const GrPipelineOptimizations& optimizations) {
Draw& draw = this->getSingleDraw(); // This will assert if we have > 1 command.
SkASSERT(draw.fGeometry.isEmpty());
SkASSERT(SkIsPow2(fInfo.fShapeTypes));
@@ -363,23 +363,17 @@
}
GrColor overrideColor;
- if (analysis.initialColorProcessorsToEliminate(&overrideColor)) {
+ if (optimizations.getOverrideColorIfSet(&overrideColor)) {
SkASSERT(State::kRecordingDraws == fInstancedRendering->fState);
- this->getSingleDraw().fInstance.fColor = overrideColor;
+ this->getSingleInstance().fColor = overrideColor;
}
- fInfo.fCannotTweakAlphaForCoverage =
- !analysis.isCompatibleWithCoverageAsAlpha() ||
- !GrXPFactory::CompatibleWithCoverageAsAlpha(fProcessors.xpFactory(),
- analysis.isOutputColorOpaque());
-
- fInfo.fUsesLocalCoords = analysis.usesLocalCoords();
- return GrXPFactory::WillNeedDstTexture(fProcessors.xpFactory(), caps, analysis);
+ fInfo.fUsesLocalCoords = optimizations.readsLocalCoords();
+ fInfo.fCannotTweakAlphaForCoverage = !optimizations.canTweakAlphaForCoverage();
}
void InstancedRendering::Op::wasRecorded() {
SkASSERT(!fIsTracked);
fInstancedRendering->fTrackedOps.addToTail(this);
- fProcessors.makePendingExecution();
fIsTracked = true;
}
@@ -389,7 +383,9 @@
SkASSERT(fTailDraw);
SkASSERT(that->fTailDraw);
- if (!OpInfo::CanCombine(fInfo, that->fInfo) || fProcessors != that->fProcessors) {
+ if (!OpInfo::CanCombine(fInfo, that->fInfo) ||
+ !GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
+ that->bounds(), caps)) {
return false;
}
@@ -410,9 +406,7 @@
this->joinBounds(*that);
fInfo = combinedInfo;
fPixelLoad += that->fPixelLoad;
- fDrawColorsAreOpaque = fDrawColorsAreOpaque && that->fDrawColorsAreOpaque;
- fDrawColorsAreSame = fDrawColorsAreSame && that->fDrawColorsAreSame &&
- fHeadDraw->fInstance.fColor == that->fHeadDraw->fInstance.fColor;
+
// Adopt the other op's draws.
fNumDraws += that->fNumDraws;
fNumChangesInGeometry += that->fNumChangesInGeometry;
@@ -468,40 +462,12 @@
SkASSERT(state->gpu() == fInstancedRendering->gpu());
state->gpu()->handleDirtyContext();
-
- GrProcessorSet::FragmentProcessorAnalysis analysis;
- GrPipelineInput coverageInput;
- if (GrAAType::kCoverage == fInfo.aaType() ||
- (GrAAType::kNone == fInfo.aaType() && !fInfo.isSimpleRects() && fInfo.fCannotDiscard)) {
- coverageInput = GrPipelineInput();
- } else {
- coverageInput = GrColor_WHITE;
+ if (GrXferBarrierType barrierType = this->pipeline()->xferBarrierType(*state->gpu()->caps())) {
+ state->gpu()->xferBarrier(this->pipeline()->getRenderTarget(), barrierType);
}
- GrPipelineInput colorInput;
- if (fDrawColorsAreSame) {
- colorInput = fHeadDraw->fInstance.fColor;
- } else if (fDrawColorsAreOpaque) {
- colorInput = GrPipelineInput::Opaque::kYes;
- }
- const GrAppliedClip* clip = state->drawOpArgs().fAppliedClip;
- analysis.init(colorInput, coverageInput, fProcessors, clip, state->caps());
- GrPipeline pipeline;
- GrPipeline::InitArgs args;
- args.fAnalysis = &analysis;
- args.fAppliedClip = clip;
- args.fCaps = &state->caps();
- args.fProcessors = &fProcessors;
- args.fFlags = GrAATypeIsHW(fInfo.aaType()) ? GrPipeline::kHWAntialias_Flag : 0;
- args.fRenderTarget = state->drawOpArgs().fRenderTarget;
- args.fDstTexture = state->drawOpArgs().fDstTexture;
- pipeline.init(args);
-
- if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*state->gpu()->caps())) {
- state->gpu()->xferBarrier(pipeline.getRenderTarget(), barrierType);
- }
InstanceProcessor instProc(fInfo, fInstancedRendering->fParamsBuffer.get());
- fInstancedRendering->onDraw(pipeline, instProc, this);
+ fInstancedRendering->onDraw(*this->pipeline(), instProc, this);
}
void InstancedRendering::endFlush() {
diff --git a/src/gpu/instanced/InstancedRendering.h b/src/gpu/instanced/InstancedRendering.h
index c2db768..778e8b4 100644
--- a/src/gpu/instanced/InstancedRendering.h
+++ b/src/gpu/instanced/InstancedRendering.h
@@ -46,31 +46,35 @@
* draws between beginFlush() and endFlush().
*/
std::unique_ptr<GrDrawOp> SK_WARN_UNUSED_RESULT recordRect(const SkRect&, const SkMatrix&,
- GrPaint&&, GrAA,
- const GrInstancedPipelineInfo&);
+ GrColor, GrAA,
+ const GrInstancedPipelineInfo&,
+ GrAAType*);
std::unique_ptr<GrDrawOp> SK_WARN_UNUSED_RESULT recordRect(const SkRect&, const SkMatrix&,
- GrPaint&&, const SkRect& localRect,
- GrAA,
- const GrInstancedPipelineInfo&);
+ GrColor, const SkRect& localRect,
+ GrAA, const GrInstancedPipelineInfo&,
+ GrAAType*);
std::unique_ptr<GrDrawOp> SK_WARN_UNUSED_RESULT recordRect(const SkRect&, const SkMatrix&,
- GrPaint&&,
- const SkMatrix& localMatrix, GrAA,
- const GrInstancedPipelineInfo&);
+ GrColor, const SkMatrix& localMatrix,
+ GrAA, const GrInstancedPipelineInfo&,
+ GrAAType*);
std::unique_ptr<GrDrawOp> SK_WARN_UNUSED_RESULT recordOval(const SkRect&, const SkMatrix&,
- GrPaint&&, GrAA,
- const GrInstancedPipelineInfo&);
+ GrColor, GrAA,
+ const GrInstancedPipelineInfo&,
+ GrAAType*);
std::unique_ptr<GrDrawOp> SK_WARN_UNUSED_RESULT recordRRect(const SkRRect&, const SkMatrix&,
- GrPaint&&, GrAA,
- const GrInstancedPipelineInfo&);
+ GrColor, GrAA,
+ const GrInstancedPipelineInfo&,
+ GrAAType*);
std::unique_ptr<GrDrawOp> SK_WARN_UNUSED_RESULT recordDRRect(const SkRRect& outer,
const SkRRect& inner,
- const SkMatrix&, GrPaint&&, GrAA,
- const GrInstancedPipelineInfo&);
+ const SkMatrix&, GrColor, GrAA,
+ const GrInstancedPipelineInfo&,
+ GrAAType*);
/**
* Compiles all recorded draws into GPU buffers and allows the client to begin flushing the
@@ -118,6 +122,7 @@
fIsTracked,
fNumDraws,
fNumChangesInGeometry);
+ string.append(DumpPipelineInfo(*this->pipeline()));
string.append(INHERITED::dumpInfo());
return string;
}
@@ -135,32 +140,27 @@
void appendParamsTexel(const SkScalar* vals, int count);
void appendParamsTexel(SkScalar x, SkScalar y, SkScalar z, SkScalar w);
void appendParamsTexel(SkScalar x, SkScalar y, SkScalar z);
- FixedFunctionFlags fixedFunctionFlags() const override {
- return GrAATypeIsHW(fInfo.aaType()) ? FixedFunctionFlags::kUsesHWAA
- : FixedFunctionFlags::kNone;
- }
- bool xpRequiresDstTexture(const GrCaps&, const GrAppliedClip*) override;
// Registers the op with the InstancedRendering list of tracked ops.
void wasRecorded() override;
protected:
- Op(uint32_t classID, GrPaint&&, InstancedRendering*);
+ Op(uint32_t classID, InstancedRendering* ir);
InstancedRendering* const fInstancedRendering;
OpInfo fInfo;
SkScalar fPixelLoad;
- GrProcessorSet fProcessors;
SkSTArray<5, ParamsTexel, true> fParams;
- bool fIsTracked : 1;
- bool fDrawColorsAreOpaque : 1;
- bool fDrawColorsAreSame : 1;
+ bool fIsTracked;
int fNumDraws;
int fNumChangesInGeometry;
Draw* fHeadDraw;
Draw* fTailDraw;
private:
+ void getFragmentProcessorAnalysisInputs(
+ FragmentProcessorAnalysisInputs* input) const override;
+ void applyPipelineOptimizations(const GrPipelineOptimizations&) override;
bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override;
void onPrepare(GrOpFlushState*) override {}
void onExecute(GrOpFlushState*) override;
@@ -190,14 +190,15 @@
};
std::unique_ptr<Op> SK_WARN_UNUSED_RESULT recordShape(ShapeType, const SkRect& bounds,
- const SkMatrix& viewMatrix, GrPaint&&,
+ const SkMatrix& viewMatrix, GrColor,
const SkRect& localRect, GrAA aa,
- const GrInstancedPipelineInfo&);
+ const GrInstancedPipelineInfo&,
+ GrAAType*);
bool selectAntialiasMode(const SkMatrix& viewMatrix, GrAA aa, const GrInstancedPipelineInfo&,
GrAAType*);
- virtual std::unique_ptr<Op> makeOp(GrPaint&&) = 0;
+ virtual std::unique_ptr<Op> makeOp() = 0;
const sk_sp<GrGpu> fGpu;
State fState;
diff --git a/src/gpu/ops/GrDrawOp.h b/src/gpu/ops/GrDrawOp.h
index 0458370..62a1688 100644
--- a/src/gpu/ops/GrDrawOp.h
+++ b/src/gpu/ops/GrDrawOp.h
@@ -12,8 +12,6 @@
#include "GrOp.h"
#include "GrPipeline.h"
-class GrAppliedClip;
-
/**
* GrDrawOps are flushed in two phases (preDraw, and draw). In preDraw uploads to GrGpuResources
* and draws are determined and scheduled. They are issued in the draw phase. GrDrawOpUploadToken is
@@ -58,27 +56,22 @@
GrDrawOp(uint32_t classID) : INHERITED(classID) {}
- /**
- * This information is required to determine how to compute a GrAppliedClip from a GrClip for
- * this op.
- */
- enum class FixedFunctionFlags : uint32_t {
- kNone = 0x0,
- /** Indices that the op will enable MSAA or mixed samples rendering. */
- kUsesHWAA = 0x1,
- /** Indices that the op reads and/or writes the stencil buffer */
- kUsesStencil = 0x2,
- };
- GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(FixedFunctionFlags);
- virtual FixedFunctionFlags fixedFunctionFlags() const = 0;
+ void initPipeline(const GrPipeline::InitArgs& args) {
+ this->applyPipelineOptimizations(fPipeline.init(args));
+ }
/**
- * This is called after the GrAppliedClip has been computed and just prior to recording the op
- * or combining it with a previously recorded op. It is used to determine whether a copy of the
- * destination (or destination texture itself) needs to be provided to the xp when this op
- * executes.
+ * Performs analysis of the fragment processors in GrProcessorSet and GrAppliedClip using the
+ * initial color and coverage from this op's geometry processor.
*/
- virtual bool xpRequiresDstTexture(const GrCaps&, const GrAppliedClip*) = 0;
+ void analyzeProcessors(GrProcessorSet::FragmentProcessorAnalysis* analysis,
+ const GrProcessorSet& processors,
+ const GrAppliedClip* appliedClip,
+ const GrCaps& caps) const {
+ FragmentProcessorAnalysisInputs input;
+ this->getFragmentProcessorAnalysisInputs(&input);
+ analysis->init(*input.colorInput(), *input.coverageInput(), processors, appliedClip, caps);
+ }
protected:
static SkString DumpPipelineInfo(const GrPipeline& pipeline) {
@@ -112,20 +105,53 @@
return string;
}
+ const GrPipeline* pipeline() const {
+ SkASSERT(fPipeline.isInitialized());
+ return &fPipeline;
+ }
+
+ /**
+ * This describes aspects of the GrPrimitiveProcessor produced by a GrDrawOp that are used in
+ * pipeline analysis.
+ */
+ class FragmentProcessorAnalysisInputs {
+ public:
+ FragmentProcessorAnalysisInputs() = default;
+ GrPipelineInput* colorInput() { return &fColorInput; }
+ GrPipelineInput* coverageInput() { return &fCoverageInput; }
+
+ private:
+ GrPipelineInput fColorInput;
+ GrPipelineInput fCoverageInput;
+ };
+
+private:
+ /**
+ * Provides information about the GrPrimitiveProccesor color and coverage outputs which become
+ * inputs to the first color and coverage fragment processors.
+ */
+ virtual void getFragmentProcessorAnalysisInputs(FragmentProcessorAnalysisInputs*) const = 0;
+
+ /**
+ * After GrPipeline analysis is complete this is called so that the op can use the analysis
+ * results when constructing its GrPrimitiveProcessor.
+ */
+ virtual void applyPipelineOptimizations(const GrPipelineOptimizations&) = 0;
+
+protected:
struct QueuedUpload {
QueuedUpload(DeferredUploadFn&& upload, GrDrawOpUploadToken token)
: fUpload(std::move(upload))
, fUploadBeforeToken(token) {}
- DeferredUploadFn fUpload;
+ DeferredUploadFn fUpload;
GrDrawOpUploadToken fUploadBeforeToken;
};
- SkTArray<QueuedUpload> fInlineUploads;
+ SkTArray<QueuedUpload> fInlineUploads;
private:
+ GrPipeline fPipeline;
typedef GrOp INHERITED;
};
-GR_MAKE_BITFIELD_CLASS_OPS(GrDrawOp::FixedFunctionFlags);
-
#endif
diff --git a/src/gpu/ops/GrDrawPathOp.cpp b/src/gpu/ops/GrDrawPathOp.cpp
index fa08ae6..85fb147 100644
--- a/src/gpu/ops/GrDrawPathOp.cpp
+++ b/src/gpu/ops/GrDrawPathOp.cpp
@@ -6,78 +6,36 @@
*/
#include "GrDrawPathOp.h"
-#include "GrAppliedClip.h"
-#include "GrRenderTargetContext.h"
-#include "GrRenderTargetPriv.h"
-#include "SkTemplates.h"
-GrDrawPathOpBase::GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&& paint,
- GrPathRendering::FillType fill, GrAA aa)
- : INHERITED(classID)
- , fViewMatrix(viewMatrix)
- , fProcessorSet(std::move(paint))
- , fAnalysis(paint.getColor())
- , fFillType(fill)
- , fAA(aa) {}
+#include "GrRenderTargetPriv.h"
+
+static void pre_translate_transform_values(const float* xforms,
+ GrPathRendering::PathTransformType type, int count,
+ SkScalar x, SkScalar y, float* dst);
+
+void GrDrawPathOpBase::onPrepare(GrOpFlushState*) {
+ const GrRenderTargetPriv& rtPriv = this->pipeline()->getRenderTarget()->renderTargetPriv();
+ fStencilPassSettings.reset(GrPathRendering::GetStencilPassSettings(fFillType),
+ this->pipeline()->hasStencilClip(), rtPriv.numStencilBits());
+}
SkString GrDrawPathOp::dumpInfo() const {
SkString string;
string.printf("PATH: 0x%p", fPath.get());
+ string.append(DumpPipelineInfo(*this->pipeline()));
string.append(INHERITED::dumpInfo());
return string;
}
-GrPipelineOptimizations GrDrawPathOpBase::initPipeline(const GrOpFlushState& state,
- GrPipeline* pipeline) {
- static constexpr GrUserStencilSettings kCoverPass{
- GrUserStencilSettings::StaticInit<
- 0x0000,
- GrUserStencilTest::kNotEqual,
- 0xffff,
- GrUserStencilOp::kZero,
- GrUserStencilOp::kKeep,
- 0xffff>()
- };
- GrPipeline::InitArgs args;
- args.fProcessors = &this->processors();
- args.fFlags = GrAA::kYes == fAA ? GrPipeline::kHWAntialias_Flag : 0;
- args.fUserStencil = &kCoverPass;
- args.fAppliedClip = state.drawOpArgs().fAppliedClip;
- args.fRenderTarget = state.drawOpArgs().fRenderTarget;
- args.fCaps = &state.caps();
- args.fDstTexture = state.drawOpArgs().fDstTexture;
- args.fAnalysis =
- &this->doFragmentProcessorAnalysis(state.caps(), state.drawOpArgs().fAppliedClip);
-
- return pipeline->init(args);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-void init_stencil_pass_settings(const GrOpFlushState& flushState,
- GrPathRendering::FillType fillType, GrStencilSettings* stencil) {
- const GrAppliedClip* appliedClip = flushState.drawOpArgs().fAppliedClip;
- bool stencilClip = appliedClip && appliedClip->hasStencilClip();
- stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
- flushState.drawOpArgs().fRenderTarget->renderTargetPriv().numStencilBits());
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
void GrDrawPathOp::onExecute(GrOpFlushState* state) {
- GrColor color = this->color();
- GrPipeline pipeline;
- GrPipelineOptimizations optimizations = this->initPipeline(*state, &pipeline);
- optimizations.getOverrideColorIfSet(&color);
- sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(color, this->viewMatrix()));
+ GrProgramDesc desc;
- GrStencilSettings stencil;
- init_stencil_pass_settings(*state, this->fillType(), &stencil);
- state->gpu()->pathRendering()->drawPath(pipeline, *pathProc, stencil, fPath.get());
+ sk_sp<GrPathProcessor> pathProc(
+ GrPathProcessor::Create(this->color(), this->viewMatrix()));
+ state->gpu()->pathRendering()->drawPath(*this->pipeline(), *pathProc,
+ this->stencilPassSettings(), fPath.get());
}
-//////////////////////////////////////////////////////////////////////////////
-
SkString GrDrawPathRangeOp::dumpInfo() const {
SkString string;
string.printf("RANGE: 0x%p COUNTS: [", fPathRange.get());
@@ -86,15 +44,16 @@
}
string.remove(string.size() - 2, 2);
string.append("]");
+ string.append(DumpPipelineInfo(*this->pipeline()));
string.append(INHERITED::dumpInfo());
return string;
}
GrDrawPathRangeOp::GrDrawPathRangeOp(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x,
- SkScalar y, GrPaint&& paint, GrPathRendering::FillType fill,
- GrAA aa, GrPathRange* range, const InstanceData* instanceData,
+ SkScalar y, GrColor color, GrPathRendering::FillType fill,
+ GrPathRange* range, const InstanceData* instanceData,
const SkRect& bounds)
- : INHERITED(ClassID(), viewMatrix, std::move(paint), fill, aa)
+ : INHERITED(ClassID(), viewMatrix, color, fill)
, fPathRange(range)
, fTotalPathCount(instanceData->count())
, fScale(scale) {
@@ -102,10 +61,6 @@
this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo);
}
-static void pre_translate_transform_values(const float* xforms,
- GrPathRendering::PathTransformType type, int count,
- SkScalar x, SkScalar y, float* dst);
-
bool GrDrawPathRangeOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
GrDrawPathRangeOp* that = t->cast<GrDrawPathRangeOp>();
if (this->fPathRange.get() != that->fPathRange.get() ||
@@ -113,7 +68,7 @@
this->color() != that->color() || !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
return false;
}
- if (this->processors() != that->processors()) {
+ if (!GrPipeline::AreEqual(*this->pipeline(), *that->pipeline())) {
return false;
}
switch (fDraws.head()->fInstanceData->transformType()) {
@@ -143,20 +98,11 @@
// work). Note that it's also possible for overlapping paths to cancel each other's winding
// numbers, and we only partially account for this by not allowing even/odd paths to be
// combined. (Glyphs in the same font tend to wind the same direction so it works out OK.)
-
if (GrPathRendering::kWinding_FillType != this->fillType() ||
- GrPathRendering::kWinding_FillType != that->fillType()) {
+ GrPathRendering::kWinding_FillType != that->fillType() || this->xpReadsDst()) {
return false;
}
- // If we have non-clipping coverage processors we don't try to merge as its unclear whether it
- // will be correct. We don't expect this to happen in practice.
- if (this->processors().numCoverageFragmentProcessors()) {
- return false;
- }
- bool opaque = this->fragmentProcessorAnalysis().isOutputColorOpaque();
- if (!GrXPFactory::CanCombineOverlappedStencilAndCover(this->processors().xpFactory(), opaque)) {
- return false;
- }
+ SkASSERT(!that->xpReadsDst());
fTotalPathCount += that->fTotalPathCount;
while (Draw* head = that->fDraws.head()) {
Draw* draw = fDraws.addToTail();
@@ -183,15 +129,11 @@
sk_sp<GrPathProcessor> pathProc(
GrPathProcessor::Create(this->color(), drawMatrix, localMatrix));
- GrPipeline pipeline;
- this->initPipeline(*state, &pipeline);
- GrStencilSettings stencil;
- init_stencil_pass_settings(*state, this->fillType(), &stencil);
if (fDraws.count() == 1) {
const InstanceData& instances = *head.fInstanceData;
- state->gpu()->pathRendering()->drawPaths(pipeline,
+ state->gpu()->pathRendering()->drawPaths(*this->pipeline(),
*pathProc,
- stencil,
+ this->stencilPassSettings(),
fPathRange.get(),
instances.indices(),
GrPathRange::kU16_PathIndexType,
@@ -217,9 +159,9 @@
}
SkASSERT(idx == fTotalPathCount);
- state->gpu()->pathRendering()->drawPaths(pipeline,
+ state->gpu()->pathRendering()->drawPaths(*this->pipeline(),
*pathProc,
- stencil,
+ this->stencilPassSettings(),
fPathRange.get(),
indexStorage,
GrPathRange::kU16_PathIndexType,
diff --git a/src/gpu/ops/GrDrawPathOp.h b/src/gpu/ops/GrDrawPathOp.h
index cf3ce2f..ffe8768 100644
--- a/src/gpu/ops/GrDrawPathOp.h
+++ b/src/gpu/ops/GrDrawPathOp.h
@@ -14,53 +14,45 @@
#include "GrPath.h"
#include "GrPathProcessor.h"
#include "GrPathRendering.h"
-#include "GrProcessorSet.h"
#include "GrStencilSettings.h"
#include "SkTLList.h"
-class GrPaint;
-
class GrDrawPathOpBase : public GrDrawOp {
protected:
- GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&& paint,
- GrPathRendering::FillType fill, GrAA aa);
- FixedFunctionFlags fixedFunctionFlags() const override {
- return FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil;
- }
- bool xpRequiresDstTexture(const GrCaps& caps, const GrAppliedClip* clip) override {
- return GrXPFactory::WillNeedDstTexture(fProcessorSet.xpFactory(), caps,
- this->doFragmentProcessorAnalysis(caps, clip));
- }
+ GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrColor initialColor,
+ GrPathRendering::FillType fill)
+ : INHERITED(classID), fViewMatrix(viewMatrix), fColor(initialColor), fFillType(fill) {}
- void wasRecorded() override { fProcessorSet.makePendingExecution(); }
+ const GrStencilSettings& stencilPassSettings() const {
+ SkASSERT(!fStencilPassSettings.isDisabled()); // This shouldn't be called before onPrepare.
+ return fStencilPassSettings;
+ }
protected:
const SkMatrix& viewMatrix() const { return fViewMatrix; }
- GrColor color() const { return fAnalysis.inputColor(); }
+ GrColor color() const { return fColor; }
GrPathRendering::FillType fillType() const { return fFillType; }
- const GrProcessorSet& processors() const { return fProcessorSet; }
- GrPipelineOptimizations initPipeline(const GrOpFlushState&, GrPipeline*);
- const GrProcessorSet::FragmentProcessorAnalysis& doFragmentProcessorAnalysis(
- const GrCaps& caps, const GrAppliedClip* clip) {
- if (!fAnalysis.isInitializedWithProcessorSet()) {
- fAnalysis.init(fAnalysis.inputColor(), GrColor_WHITE, fProcessorSet, clip, caps);
- }
- return fAnalysis;
- }
- const GrProcessorSet::FragmentProcessorAnalysis& fragmentProcessorAnalysis() const {
- SkASSERT(fAnalysis.isInitializedWithProcessorSet());
- return fAnalysis;
- }
+ bool xpReadsDst() const { return fXPReadsDst; }
private:
- void onPrepare(GrOpFlushState*) final {}
+ void getFragmentProcessorAnalysisInputs(FragmentProcessorAnalysisInputs* input) const override {
+ input->colorInput()->setToConstant(fColor);
+ input->coverageInput()->setToSolidCoverage();
+ }
+
+ void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
+ optimizations.getOverrideColorIfSet(&fColor);
+ fXPReadsDst = optimizations.xpReadsDst();
+ }
+
+ void onPrepare(GrOpFlushState*) override; // Initializes fStencilPassSettings.
SkMatrix fViewMatrix;
- GrProcessorSet fProcessorSet;
- GrProcessorSet::FragmentProcessorAnalysis fAnalysis;
+ GrColor fColor;
GrPathRendering::FillType fFillType;
- GrAA fAA;
+ GrStencilSettings fStencilPassSettings;
+ bool fXPReadsDst;
typedef GrDrawOp INHERITED;
};
@@ -69,9 +61,9 @@
public:
DEFINE_OP_CLASS_ID
- static std::unique_ptr<GrDrawOp> Make(const SkMatrix& viewMatrix, GrPaint&& paint, GrAA aa,
- GrPath* path) {
- return std::unique_ptr<GrDrawOp>(new GrDrawPathOp(viewMatrix, std::move(paint), aa, path));
+ static std::unique_ptr<GrDrawOp> Make(const SkMatrix& viewMatrix, GrColor color,
+ const GrPath* path) {
+ return std::unique_ptr<GrDrawOp>(new GrDrawPathOp(viewMatrix, color, path));
}
const char* name() const override { return "DrawPath"; }
@@ -79,9 +71,8 @@
SkString dumpInfo() const override;
private:
- GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAA aa, const GrPath* path)
- : GrDrawPathOpBase(ClassID(), viewMatrix, std::move(paint), path->getFillType(), aa)
- , fPath(path) {
+ GrDrawPathOp(const SkMatrix& viewMatrix, GrColor color, const GrPath* path)
+ : GrDrawPathOpBase(ClassID(), viewMatrix, color, path->getFillType()), fPath(path) {
this->setTransformedBounds(path->getBounds(), viewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
}
@@ -161,12 +152,11 @@
};
static std::unique_ptr<GrDrawOp> Make(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x,
- SkScalar y, GrPaint&& paint,
- GrPathRendering::FillType fill, GrAA aa,
+ SkScalar y, GrColor color, GrPathRendering::FillType fill,
GrPathRange* range, const InstanceData* instanceData,
const SkRect& bounds) {
- return std::unique_ptr<GrDrawOp>(new GrDrawPathRangeOp(
- viewMatrix, scale, x, y, std::move(paint), fill, aa, range, instanceData, bounds));
+ return std::unique_ptr<GrDrawOp>(new GrDrawPathRangeOp(viewMatrix, scale, x, y, color, fill,
+ range, instanceData, bounds));
}
const char* name() const override { return "DrawPathRange"; }
@@ -175,7 +165,7 @@
private:
GrDrawPathRangeOp(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x, SkScalar y,
- GrPaint&& paint, GrPathRendering::FillType fill, GrAA aa, GrPathRange* range,
+ GrColor color, GrPathRendering::FillType fill, GrPathRange* range,
const InstanceData* instanceData, const SkRect& bounds);
TransformType transformType() const { return fDraws.head()->fInstanceData->transformType(); }
diff --git a/src/gpu/ops/GrMeshDrawOp.cpp b/src/gpu/ops/GrMeshDrawOp.cpp
index 59335d4..5d83bd5 100644
--- a/src/gpu/ops/GrMeshDrawOp.cpp
+++ b/src/gpu/ops/GrMeshDrawOp.cpp
@@ -60,9 +60,6 @@
}
void GrMeshDrawOp::onExecute(GrOpFlushState* state) {
- SkASSERT(!state->drawOpArgs().fAppliedClip);
- SkASSERT(!state->drawOpArgs().fDstTexture.texture());
- SkASSERT(state->drawOpArgs().fRenderTarget == this->pipeline()->getRenderTarget());
int currUploadIdx = 0;
int currMeshIdx = 0;
diff --git a/src/gpu/ops/GrMeshDrawOp.h b/src/gpu/ops/GrMeshDrawOp.h
index 4cf7c52..a7d312f 100644
--- a/src/gpu/ops/GrMeshDrawOp.h
+++ b/src/gpu/ops/GrMeshDrawOp.h
@@ -15,7 +15,6 @@
#include "SkTLList.h"
-class GrCaps;
class GrOpFlushState;
/**
@@ -25,39 +24,9 @@
public:
class Target;
- /**
- * Performs analysis of the fragment processors in GrProcessorSet and GrAppliedClip using the
- * initial color and coverage from this op's geometry processor.
- */
- void analyzeProcessors(GrProcessorSet::FragmentProcessorAnalysis* analysis,
- const GrProcessorSet& processors,
- const GrAppliedClip* appliedClip,
- const GrCaps& caps) const {
- FragmentProcessorAnalysisInputs input;
- this->getFragmentProcessorAnalysisInputs(&input);
- analysis->init(*input.colorInput(), *input.coverageInput(), processors, appliedClip, caps);
- }
-
- void initPipeline(const GrPipeline::InitArgs& args) {
- this->applyPipelineOptimizations(fPipeline.init(args));
- }
-
- /**
- * Mesh draw ops use a legacy system in GrRenderTargetContext where the pipeline is created when
- * the op is recorded. These methods are unnecessary as this information is in the pipeline.
- */
- FixedFunctionFlags fixedFunctionFlags() const override {
- SkFAIL("This should never be called for mesh draw ops.");
- return FixedFunctionFlags::kNone;
- }
- bool xpRequiresDstTexture(const GrCaps&, const GrAppliedClip*) override {
- SkFAIL("Should never be called for mesh draw ops.");
- return false;
- }
-
-protected:
GrMeshDrawOp(uint32_t classID);
+protected:
/** Helper for rendering instances using an instanced index index buffer. This class creates the
space for the vertices and flushes the draws to the GrMeshDrawOp::Target. */
class InstancedHelper {
@@ -93,39 +62,7 @@
typedef InstancedHelper INHERITED;
};
- const GrPipeline* pipeline() const {
- SkASSERT(fPipeline.isInitialized());
- return &fPipeline;
- }
-
- /**
- * This describes aspects of the GrPrimitiveProcessor produced by a GrDrawOp that are used in
- * pipeline analysis.
- */
- class FragmentProcessorAnalysisInputs {
- public:
- FragmentProcessorAnalysisInputs() = default;
- GrPipelineInput* colorInput() { return &fColorInput; }
- GrPipelineInput* coverageInput() { return &fCoverageInput; }
-
- private:
- GrPipelineInput fColorInput;
- GrPipelineInput fCoverageInput;
- };
-
private:
- /**
- * Provides information about the GrPrimitiveProccesor color and coverage outputs which become
- * inputs to the first color and coverage fragment processors.
- */
- virtual void getFragmentProcessorAnalysisInputs(FragmentProcessorAnalysisInputs*) const = 0;
-
- /**
- * After GrPipeline analysis is complete this is called so that the op can use the analysis
- * results when constructing its GrPrimitiveProcessor.
- */
- virtual void applyPipelineOptimizations(const GrPipelineOptimizations&) = 0;
-
void onPrepare(GrOpFlushState* state) final;
void onExecute(GrOpFlushState* state) final;
@@ -145,7 +82,7 @@
// globally across all ops. This is the offset of the first entry in fQueuedDraws.
// fQueuedDraws[i]'s token is fBaseDrawToken + i.
GrDrawOpUploadToken fBaseDrawToken;
- GrPipeline fPipeline;
+
SkSTArray<4, GrMesh> fMeshes;
SkSTArray<4, QueuedDraw, true> fQueuedDraws;
diff --git a/src/gpu/ops/GrOp.h b/src/gpu/ops/GrOp.h
index ef752b5..c1bf7f7 100644
--- a/src/gpu/ops/GrOp.h
+++ b/src/gpu/ops/GrOp.h
@@ -11,7 +11,6 @@
#include "../private/SkAtomics.h"
#include "GrGpuResource.h"
#include "GrNonAtomicRef.h"
-#include "GrXferProcessor.h"
#include "SkMatrix.h"
#include "SkRect.h"
#include "SkString.h"
diff --git a/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp b/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp
index 4c2edf4..3b38163 100644
--- a/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp
+++ b/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp
@@ -145,10 +145,22 @@
std::move(coverOp));
}
} else {
- GrAA aa = GrBoolToAA(GrAATypeIsHW(args.fAAType));
+ static constexpr GrUserStencilSettings kCoverPass(
+ GrUserStencilSettings::StaticInit<
+ 0x0000,
+ GrUserStencilTest::kNotEqual,
+ 0xffff,
+ GrUserStencilOp::kZero,
+ GrUserStencilOp::kKeep,
+ 0xffff>()
+ );
+
std::unique_ptr<GrDrawOp> op =
- GrDrawPathOp::Make(viewMatrix, std::move(args.fPaint), aa, path.get());
- args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
+ GrDrawPathOp::Make(viewMatrix, args.fPaint.getColor(), path.get());
+
+ GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
+ pipelineBuilder.setUserStencil(&kCoverPass);
+ args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
}
return true;
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp
index e572e5d..acd4267 100644
--- a/src/gpu/text/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp
@@ -605,13 +605,24 @@
const SkRect bounds = SkRect::MakeIWH(renderTargetContext->width(),
renderTargetContext->height());
- // The run's "font" overrides the anti-aliasing of the passed in SkPaint!
std::unique_ptr<GrDrawOp> op = GrDrawPathRangeOp::Make(
viewMatrix, fTextRatio, fTextInverseRatio * x, fTextInverseRatio * y,
- std::move(grPaint), GrPathRendering::kWinding_FillType, runAA, glyphs.get(),
+ grPaint.getColor(), GrPathRendering::kWinding_FillType, glyphs.get(),
fInstanceData.get(), bounds);
- renderTargetContext->addDrawOp(clip, std::move(op));
+ // The run's "font" overrides the anti-aliasing of the passed in SkPaint!
+ GrAAType aaType = GrAAType::kNone;
+ if (GrAA::kYes == runAA) {
+ if (renderTargetContext->isUnifiedMultisampled()) {
+ aaType = GrAAType::kMSAA;
+ } else if (renderTargetContext->isStencilBufferMultisampled()) {
+ aaType = GrAAType::kMixedSamples;
+ }
+ }
+ GrPipelineBuilder pipelineBuilder(std::move(grPaint), aaType);
+ pipelineBuilder.setUserStencil(&kCoverPass);
+
+ renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
}
if (fFallbackTextBlob) {