Move GrAppliedClip into GrPipeline

Change-Id: I522c2fd52bea9813baba7cdb3f11b63e7ab96b50
Reviewed-on: https://skia-review.googlesource.com/28861
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Salomon 2017-08-09 16:27:09 -04:00 committed by Skia Commit-Bot
parent 65048139bd
commit bfd18cdd54
16 changed files with 61 additions and 45 deletions

View File

@ -44,7 +44,7 @@ protected:
}
const GrPipeline* makePipeline(Target* target) {
return target->makePipeline(0, std::move(fProcessorSet));
return target->makePipeline(0, std::move(fProcessorSet), target->detachAppliedClip());
}
const GrGeometryProcessor* gp() const { return fGeometryProcessor.get(); }

View File

@ -82,7 +82,9 @@ private:
fRect.toQuad(verts);
helper.recordDraw(target, gp.get(), target->makePipeline(0, std::move(fProcessors)));
helper.recordDraw(
target, gp.get(),
target->makePipeline(0, std::move(fProcessors), target->detachAppliedClip()));
}
bool onCombineIfPossible(GrOp* op, const GrCaps& caps) override { return false; }

View File

@ -27,6 +27,9 @@ public:
const GrScissorState& scissorState() const { return fScissorState; }
const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; }
GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fClipCoverageFP.get(); }
sk_sp<GrFragmentProcessor> detachClipCoverageFragmentProcessor() {
return std::move(fClipCoverageFP);
}
bool hasStencilClip() const { return SkClipStack::kInvalidGenID != fClipStackID; }
/**

View File

@ -8,6 +8,7 @@
#ifndef GrOpFlushState_DEFINED
#define GrOpFlushState_DEFINED
#include "GrAppliedClip.h"
#include "GrBufferAllocPool.h"
#include "SkArenaAlloc.h"
#include "ops/GrMeshDrawOp.h"
@ -100,8 +101,8 @@ public:
GrRenderTarget* renderTarget() const { return fProxy->priv().peekRenderTarget(); }
// TODO: do we still need the dst proxy here?
GrRenderTargetProxy* fProxy;
const GrAppliedClip* fAppliedClip;
GrRenderTargetProxy* fProxy;
GrAppliedClip* fAppliedClip;
GrXferProcessor::DstProxy fDstProxy;
};
@ -112,6 +113,11 @@ public:
return *fOpArgs;
}
GrAppliedClip detachAppliedClip() {
SkASSERT(fOpArgs);
return fOpArgs->fAppliedClip ? std::move(*fOpArgs->fAppliedClip) : GrAppliedClip();
}
template <typename... Args>
GrPipeline* allocPipeline(Args&&... args) {
return fPipelines.make<GrPipeline>(std::forward<Args>(args)...);
@ -239,6 +245,8 @@ public:
const GrAppliedClip* clip() const { return this->state()->drawOpArgs().fAppliedClip; }
GrAppliedClip detachAppliedClip() { return this->state()->detachAppliedClip(); }
const GrXferProcessor::DstProxy& dstProxy() const {
return this->state()->drawOpArgs().fDstProxy;
}
@ -252,15 +260,15 @@ public:
* Helper that makes a pipeline targeting the op's render target that incorporates the op's
* GrAppliedClip.
* */
GrPipeline* makePipeline(uint32_t pipelineFlags, GrProcessorSet&& processorSet) {
GrPipeline* makePipeline(uint32_t pipelineFlags, GrProcessorSet&& processorSet,
GrAppliedClip&& clip) {
GrPipeline::InitArgs pipelineArgs;
pipelineArgs.fFlags = pipelineFlags;
pipelineArgs.fProxy = this->proxy();
pipelineArgs.fAppliedClip = this->clip();
pipelineArgs.fDstProxy = this->dstProxy();
pipelineArgs.fCaps = &this->caps();
pipelineArgs.fResourceProvider = this->resourceProvider();
return this->allocPipeline(pipelineArgs, std::move(processorSet));
return this->allocPipeline(pipelineArgs, std::move(processorSet), std::move(clip));
}
private:

View File

@ -17,20 +17,19 @@
#include "ops/GrOp.h"
GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors) {
GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors,
GrAppliedClip&& appliedClip) {
SkASSERT(args.fProxy);
SkASSERT(processors.isFinalized());
fProxy.reset(args.fProxy);
fFlags = args.fFlags;
if (args.fAppliedClip) {
fScissorState = args.fAppliedClip->scissorState();
if (args.fAppliedClip->hasStencilClip()) {
fFlags |= kHasStencilClip_Flag;
}
fWindowRectsState = args.fAppliedClip->windowRectsState();
fScissorState = appliedClip.scissorState();
if (appliedClip.hasStencilClip()) {
fFlags |= kHasStencilClip_Flag;
}
fWindowRectsState = appliedClip.windowRectsState();
if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
fFlags |= kStencilEnabled_Flag;
}
@ -52,7 +51,8 @@ GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors) {
fNumColorProcessors = processors.numColorFragmentProcessors();
int numTotalProcessors =
fNumColorProcessors + processors.numCoverageFragmentProcessors();
if (args.fAppliedClip && args.fAppliedClip->clipCoverageFragmentProcessor()) {
auto clipFP = appliedClip.detachClipCoverageFragmentProcessor();
if (clipFP) {
++numTotalProcessors;
}
fFragmentProcessors.reset(numTotalProcessors);
@ -72,12 +72,10 @@ GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors) {
this->markAsBad();
}
}
if (args.fAppliedClip) {
if (const GrFragmentProcessor* fp = args.fAppliedClip->clipCoverageFragmentProcessor()) {
fFragmentProcessors[currFPIdx].reset(fp);
if (!fp->instantiate(args.fResourceProvider)) {
this->markAsBad();
}
if (clipFP) {
fFragmentProcessors[currFPIdx].reset(clipFP.get());
if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
this->markAsBad();
}
}
}

View File

@ -77,7 +77,6 @@ public:
struct InitArgs {
uint32_t fFlags = 0;
const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused;
const GrAppliedClip* fAppliedClip = nullptr;
GrRenderTargetProxy* fProxy = nullptr;
const GrCaps* fCaps = nullptr;
GrResourceProvider* fResourceProvider = nullptr;
@ -101,7 +100,7 @@ public:
**/
GrPipeline(GrRenderTargetProxy*, ScissorState, SkBlendMode);
GrPipeline(const InitArgs& args, GrProcessorSet&& processors);
GrPipeline(const InitArgs&, GrProcessorSet&&, GrAppliedClip&&);
GrPipeline(const GrPipeline&) = delete;
GrPipeline& operator=(const GrPipeline&) = delete;

View File

@ -113,18 +113,15 @@ private:
friend class GrRenderTargetContextPriv; // for stencil clip state. TODO: this is invasive
struct RecordedOp {
RecordedOp(std::unique_ptr<GrOp> op,
const GrAppliedClip* appliedClip,
const DstProxy* dstProxy)
: fOp(std::move(op))
, fAppliedClip(appliedClip) {
RecordedOp(std::unique_ptr<GrOp> op, GrAppliedClip* appliedClip, const DstProxy* dstProxy)
: fOp(std::move(op)), fAppliedClip(appliedClip) {
if (dstProxy) {
fDstProxy = *dstProxy;
}
}
std::unique_ptr<GrOp> fOp;
DstProxy fDstProxy;
const GrAppliedClip* fAppliedClip;
DstProxy fDstProxy;
GrAppliedClip* fAppliedClip;
};
// If the input op is combined with an earlier op, this returns the combined op. Otherwise, it

View File

@ -293,12 +293,11 @@ void DrawPathsOp::onExecute(GrOpFlushState* flushState) {
}
GrPipeline::InitArgs args;
args.fAppliedClip = flushState->drawOpArgs().fAppliedClip;
args.fCaps = &flushState->caps();
args.fFlags = fSRGBFlags;
args.fProxy = flushState->drawOpArgs().fProxy;
args.fDstProxy = flushState->drawOpArgs().fDstProxy;
GrPipeline pipeline(args, std::move(fProcessors));
GrPipeline pipeline(args, std::move(fProcessors), flushState->detachAppliedClip());
int baseInstance = fBaseInstance;

View File

@ -226,7 +226,6 @@ void InstancedOp::onExecute(GrOpFlushState* state) {
state->gpu()->handleDirtyContext();
GrPipeline::InitArgs args;
args.fAppliedClip = state->drawOpArgs().fAppliedClip;
args.fCaps = &state->caps();
args.fResourceProvider = state->resourceProvider();
args.fFlags = GrAATypeIsHW(fInfo.aaType()) ? GrPipeline::kHWAntialias_Flag : 0;
@ -238,7 +237,7 @@ void InstancedOp::onExecute(GrOpFlushState* state) {
}
args.fProxy = state->drawOpArgs().fProxy;
args.fDstProxy = state->drawOpArgs().fDstProxy;
GrPipeline pipeline(args, std::move(fProcessors));
GrPipeline pipeline(args, std::move(fProcessors), state->detachAppliedClip());
if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*state->gpu()->caps())) {
state->gpu()->xferBarrier(pipeline.renderTarget(), barrierType);

View File

@ -93,7 +93,8 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) {
GrMaskFormat maskFormat = this->maskFormat();
FlushInfo flushInfo;
flushInfo.fPipeline = target->makePipeline(fSRGBFlags, std::move(fProcessors));
flushInfo.fPipeline =
target->makePipeline(fSRGBFlags, std::move(fProcessors), target->detachAppliedClip());
if (this->usesDistanceFields()) {
flushInfo.fGeometryProcessor =
this->setupDfProcessor(this->viewMatrix(),

View File

@ -662,7 +662,8 @@ private:
if (fAllowsSRGBInputs) {
pipelineFlags |= GrPipeline::kAllowSRGBInputs_Flag;
}
const GrPipeline* pipeline = target->makePipeline(pipelineFlags, std::move(fProcessorSet));
const GrPipeline* pipeline = target->makePipeline(pipelineFlags, std::move(fProcessorSet),
target->detachAppliedClip());
helper.recordDraw(target, gp.get(), pipeline);
}

View File

@ -44,7 +44,6 @@ GrPipeline::InitArgs GrDrawPathOpBase::pipelineInitArgs(const GrOpFlushState& st
args.fFlags |= GrPipeline::kHWAntialias_Flag;
}
args.fUserStencil = &kCoverPass;
args.fAppliedClip = state.drawOpArgs().fAppliedClip;
args.fProxy = state.drawOpArgs().fProxy;
args.fCaps = &state.caps();
args.fResourceProvider = state.resourceProvider();
@ -65,7 +64,8 @@ void init_stencil_pass_settings(const GrOpFlushState& flushState,
//////////////////////////////////////////////////////////////////////////////
void GrDrawPathOp::onExecute(GrOpFlushState* state) {
GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors());
GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
state->detachAppliedClip());
sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
GrStencilSettings stencil;
@ -177,7 +177,8 @@ void GrDrawPathRangeOp::onExecute(GrOpFlushState* state) {
sk_sp<GrPathProcessor> pathProc(
GrPathProcessor::Create(this->color(), drawMatrix, localMatrix));
GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors());
GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
state->detachAppliedClip());
GrStencilSettings stencil;
init_stencil_pass_settings(*state, this->fillType(), &stencil);
if (fDraws.count() == 1) {

View File

@ -613,8 +613,8 @@ private:
}
static const uint32_t kPipelineFlags = 0;
const GrPipeline* pipeline =
target->makePipeline(kPipelineFlags, GrProcessorSet::MakeEmptySet());
const GrPipeline* pipeline = target->makePipeline(
kPipelineFlags, GrProcessorSet::MakeEmptySet(), target->detachAppliedClip());
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertCount - 1);

View File

@ -20,6 +20,7 @@ GrSimpleMeshDrawOpHelper::GrSimpleMeshDrawOpHelper(const MakeArgs& args, GrAATyp
, fUsesLocalCoords(false)
, fCompatibleWithAlphaAsCoveage(false) {
SkDEBUGCODE(fDidAnalysis = false);
SkDEBUGCODE(fMadePipeline = false);
if (GrAATypeIsHW(aaType)) {
fPipelineFlags |= GrPipeline::kHWAntialias_Flag;
}
@ -127,7 +128,6 @@ GrPipeline::InitArgs GrSimpleMeshDrawOpHelper::pipelineInitArgs(
GrPipeline::InitArgs args;
args.fFlags = this->pipelineFlags();
args.fProxy = target->proxy();
args.fAppliedClip = target->clip();
args.fDstProxy = target->dstProxy();
args.fCaps = &target->caps();
args.fResourceProvider = target->resourceProvider();
@ -136,10 +136,15 @@ GrPipeline::InitArgs GrSimpleMeshDrawOpHelper::pipelineInitArgs(
GrPipeline* GrSimpleMeshDrawOpHelper::internalMakePipeline(GrMeshDrawOp::Target* target,
const GrPipeline::InitArgs& args) {
// A caller really should only call this once as the processor set and applied clip get
// moved into the GrPipeline.
SkASSERT(!fMadePipeline);
SkDEBUGCODE(fMadePipeline = true);
if (fProcessors) {
return target->allocPipeline(args, std::move(*fProcessors));
return target->allocPipeline(args, std::move(*fProcessors), target->detachAppliedClip());
} else {
return target->allocPipeline(args, GrProcessorSet::MakeEmptySet());
return target->allocPipeline(args, GrProcessorSet::MakeEmptySet(),
target->detachAppliedClip());
}
}

View File

@ -82,6 +82,7 @@ public:
bool compatibleWithAlphaAsCoverage() const { return fCompatibleWithAlphaAsCoveage; }
/** Makes a pipeline that consumes the processor set and the op's applied clip. */
GrPipeline* makePipeline(GrMeshDrawOp::Target* target) {
return this->internalMakePipeline(target, this->pipelineInitArgs(target));
}
@ -113,6 +114,7 @@ private:
unsigned fRequiresDstTexture : 1;
unsigned fUsesLocalCoords : 1;
unsigned fCompatibleWithAlphaAsCoveage : 1;
SkDEBUGCODE(unsigned fMadePipeline : 1;)
SkDEBUGCODE(unsigned fDidAnalysis : 1;)
};

View File

@ -95,7 +95,8 @@ private:
SkPoint* vertices = reinterpret_cast<SkPoint*>(helper.init(target, vertexStride, 1));
vertices->setRectFan(0.f, 0.f, 1.f, 1.f, vertexStride);
helper.recordDraw(target, gp.get(),
target->makePipeline(0, GrProcessorSet::MakeEmptySet()));
target->makePipeline(0, GrProcessorSet::MakeEmptySet(),
target->detachAppliedClip()));
}
int fNumAttribs;