Remove GrPipelineOptimizations member from GrPipeline

Review URL: https://codereview.chromium.org/1275003004
This commit is contained in:
bsalomon 2015-08-10 12:01:15 -07:00 committed by Commit bot
parent b7ee1bf017
commit c699873ac7
9 changed files with 99 additions and 99 deletions

View File

@ -28,7 +28,8 @@ GrBufferedDrawTarget::~GrBufferedDrawTarget() {
void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch,
const PipelineInfo& pipelineInfo) {
State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo);
GrPipelineOptimizations opts;
State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo, &opts);
if (!state) {
return;
}
@ -52,7 +53,8 @@ void GrBufferedDrawTarget::onDrawPath(const GrPathProcessor* pathProc,
const GrPath* path,
const GrStencilSettings& stencilSettings,
const PipelineInfo& pipelineInfo) {
State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
GrPipelineOptimizations opts;
State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo, &opts);
if (!state) {
return;
}
@ -69,7 +71,8 @@ void GrBufferedDrawTarget::onDrawPaths(const GrPathProcessor* pathProc,
int count,
const GrStencilSettings& stencilSettings,
const PipelineInfo& pipelineInfo) {
State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
GrPipelineOptimizations opts;
State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo, &opts);
if (!state) {
return;
}
@ -148,17 +151,17 @@ void GrBufferedDrawTarget::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd*
GrTargetCommands::State*
GrBufferedDrawTarget::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* primProc,
const GrDrawTarget::PipelineInfo& pipelineInfo) {
const GrDrawTarget::PipelineInfo& pipelineInfo,
GrPipelineOptimizations* opts) {
State* state = this->allocState(primProc);
this->setupPipeline(pipelineInfo, state->pipelineLocation());
this->setupPipeline(pipelineInfo, state->pipelineLocation(), opts);
if (state->getPipeline()->mustSkip()) {
this->unallocState(state);
return NULL;
}
state->fPrimitiveProcessor->initBatchTracker(
&state->fBatchTracker, state->getPipeline()->infoForPrimitiveProcessor());
state->fPrimitiveProcessor->initBatchTracker(&state->fBatchTracker, *opts);
if (fPrevState && fPrevState->fPrimitiveProcessor.get() &&
fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker,
@ -177,16 +180,17 @@ GrBufferedDrawTarget::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* pri
GrTargetCommands::State*
GrBufferedDrawTarget::setupPipelineAndShouldDraw(GrBatch* batch,
const GrDrawTarget::PipelineInfo& pipelineInfo) {
const GrDrawTarget::PipelineInfo& pipelineInfo,
GrPipelineOptimizations* opts) {
State* state = this->allocState();
this->setupPipeline(pipelineInfo, state->pipelineLocation());
this->setupPipeline(pipelineInfo, state->pipelineLocation(), opts);
if (state->getPipeline()->mustSkip()) {
this->unallocState(state);
return NULL;
}
batch->initBatchTracker(state->getPipeline()->infoForPrimitiveProcessor());
batch->initBatchTracker(*opts);
if (fPrevState && !fPrevState->fPrimitiveProcessor.get() &&
fPrevState->getPipeline()->isEqual(*state->getPipeline())) {

View File

@ -113,9 +113,11 @@ private:
bool isIssued(uint32_t drawID) override { return drawID != fDrawID; }
State* SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(const GrPrimitiveProcessor*,
const GrDrawTarget::PipelineInfo&);
const GrDrawTarget::PipelineInfo&,
GrPipelineOptimizations* opts);
State* SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrBatch*,
const GrDrawTarget::PipelineInfo&);
const GrDrawTarget::PipelineInfo&,
GrPipelineOptimizations* opts);
// TODO: Use a single allocator for commands and records
enum {

View File

@ -459,13 +459,15 @@ void GrDrawTarget::copySurface(GrSurface* dst,
}
const GrPipeline* GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo,
void* pipelineAddr) {
void* pipelineAddr,
GrPipelineOptimizations* optimizations) {
return GrPipeline::CreateAt(pipelineAddr, *pipelineInfo.fPipelineBuilder,
pipelineInfo.fColorPOI,
pipelineInfo.fCoveragePOI,
*this->caps(),
*pipelineInfo.fScissor,
&pipelineInfo.fDstTexture);
&pipelineInfo.fDstTexture,
optimizations);
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -239,12 +239,13 @@ protected:
const GrPipelineBuilder* fPipelineBuilder;
GrScissorState* fScissor;
GrProcOptInfo fColorPOI;
GrProcOptInfo fCoveragePOI;
GrProcOptInfo fColorPOI;
GrProcOptInfo fCoveragePOI;
GrXferProcessor::DstTexture fDstTexture;
};
const GrPipeline* setupPipeline(const PipelineInfo& pipelineInfo, void* pipelineAddr);
const GrPipeline* setupPipeline(const PipelineInfo&, void* pipelineAddr,
GrPipelineOptimizations*);
private:
virtual void onReset() = 0;

View File

@ -27,8 +27,9 @@ GrImmediateDrawTarget::~GrImmediateDrawTarget() {
void GrImmediateDrawTarget::onDrawBatch(GrBatch* batch,
const PipelineInfo& pipelineInfo) {
GrPipelineOptimizations opts;
SkAlignedSStorage<sizeof(GrPipeline)> pipelineStorage;
bool shouldDraw = this->setupPipelineAndShouldDraw(pipelineStorage.get(), pipelineInfo);
bool shouldDraw = this->setupPipelineAndShouldDraw(pipelineStorage.get(), pipelineInfo, &opts);
GrPipeline* pipeline = reinterpret_cast<GrPipeline*>(pipelineStorage.get());
if (!shouldDraw) {
@ -36,7 +37,7 @@ void GrImmediateDrawTarget::onDrawBatch(GrBatch* batch,
return;
}
batch->initBatchTracker(pipeline->infoForPrimitiveProcessor());
batch->initBatchTracker(opts);
fBatchTarget.resetNumberOfDraws();
@ -86,8 +87,9 @@ void GrImmediateDrawTarget::onFlush() {
bool
GrImmediateDrawTarget::setupPipelineAndShouldDraw(void* pipelineAddr,
const GrDrawTarget::PipelineInfo& pipelineInfo) {
const GrPipeline* pipeline = this->setupPipeline(pipelineInfo, pipelineAddr);
const GrDrawTarget::PipelineInfo& pipelineInfo,
GrPipelineOptimizations* opts) {
const GrPipeline* pipeline = this->setupPipeline(pipelineInfo, pipelineAddr, opts);
if (pipeline->mustSkip()) {
return false;

View File

@ -74,7 +74,8 @@ private:
bool isIssued(uint32_t drawID) override { return drawID != fDrawID; }
bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(void* pipelineAddr,
const GrDrawTarget::PipelineInfo&);
const GrDrawTarget::PipelineInfo&,
GrPipelineOptimizations* opts);
void recordXferBarrierIfNecessary(const GrPipeline*);

View File

@ -15,16 +15,20 @@
#include "batches/GrBatch.h"
GrPipeline::GrPipeline(const GrPipelineBuilder& pipelineBuilder,
const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
const GrCaps& caps,
const GrScissorState& scissorState,
const GrXferProcessor::DstTexture* dstTexture) {
GrPipeline* GrPipeline::CreateAt(void* memory,
const GrPipelineBuilder& builder,
const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
const GrCaps& caps,
const GrScissorState& scissor,
const GrXferProcessor::DstTexture* dst,
GrPipelineOptimizations* opts) {
GrPipeline* pipeline = SkNEW_PLACEMENT(memory, GrPipeline);
// Create XferProcessor from DS's XPFactory
SkAutoTUnref<GrXferProcessor> xferProcessor(
pipelineBuilder.getXPFactory()->createXferProcessor(
colorPOI, coveragePOI, pipelineBuilder.hasMixedSamples(), dstTexture, caps));
builder.getXPFactory()->createXferProcessor(
colorPOI, coveragePOI, builder.hasMixedSamples(), dst, caps));
GrColor overrideColor = GrColor_ILLEGAL;
if (colorPOI.firstEffectiveStageIndex() != 0) {
@ -33,11 +37,11 @@ GrPipeline::GrPipeline(const GrPipelineBuilder& pipelineBuilder,
GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags;
if (xferProcessor) {
fXferProcessor.reset(xferProcessor.get());
pipeline->fXferProcessor.reset(xferProcessor.get());
optFlags = xferProcessor->getOptimizations(colorPOI,
coveragePOI,
pipelineBuilder.getStencil().doesWrite(),
builder.getStencil().doesWrite(),
&overrideColor,
caps);
}
@ -53,26 +57,26 @@ GrPipeline::GrPipeline(const GrPipelineBuilder& pipelineBuilder,
if (!xferProcessor || (GrXferProcessor::kSkipDraw_OptFlag & optFlags)) {
// Set the fields that don't default init and return. The lack of a render target will
// indicate that this can be skipped.
fFlags = 0;
fDrawFace = GrPipelineBuilder::kInvalid_DrawFace;
return;
pipeline->fFlags = 0;
pipeline->fDrawFace = GrPipelineBuilder::kInvalid_DrawFace;
return pipeline;
}
fRenderTarget.reset(pipelineBuilder.fRenderTarget.get());
SkASSERT(fRenderTarget);
fScissorState = scissorState;
fStencilSettings = pipelineBuilder.getStencil();
fDrawFace = pipelineBuilder.getDrawFace();
pipeline->fRenderTarget.reset(builder.fRenderTarget.get());
SkASSERT(pipeline->fRenderTarget);
pipeline->fScissorState = scissor;
pipeline->fStencilSettings = builder.getStencil();
pipeline->fDrawFace = builder.getDrawFace();
fFlags = 0;
if (pipelineBuilder.isHWAntialias()) {
fFlags |= kHWAA_Flag;
pipeline->fFlags = 0;
if (builder.isHWAntialias()) {
pipeline->fFlags |= kHWAA_Flag;
}
if (pipelineBuilder.isDither()) {
fFlags |= kDither_Flag;
if (builder.isDither()) {
pipeline->fFlags |= kDither_Flag;
}
if (pipelineBuilder.snapVerticesToPixelCenters()) {
fFlags |= kSnapVertices_Flag;
if (builder.snapVerticesToPixelCenters()) {
pipeline->fFlags |= kSnapVertices_Flag;
}
int firstColorStageIdx = colorPOI.firstEffectiveStageIndex();
@ -81,52 +85,48 @@ GrPipeline::GrPipeline(const GrPipelineBuilder& pipelineBuilder,
// GrPipelineBuilder's coverageProcInfo (like color above) to set this initial information.
int firstCoverageStageIdx = 0;
this->adjustProgramFromOptimizations(pipelineBuilder, optFlags, colorPOI, coveragePOI,
&firstColorStageIdx, &firstCoverageStageIdx);
pipeline->adjustProgramFromOptimizations(builder, optFlags, colorPOI, coveragePOI,
&firstColorStageIdx, &firstCoverageStageIdx);
bool usesLocalCoords = false;
// Copy Stages from PipelineBuilder to Pipeline
for (int i = firstColorStageIdx; i < pipelineBuilder.numColorFragmentStages(); ++i) {
const GrFragmentStage& fps = pipelineBuilder.fColorStages[i];
for (int i = firstColorStageIdx; i < builder.numColorFragmentStages(); ++i) {
const GrFragmentStage& fps = builder.fColorStages[i];
const GrFragmentProcessor* fp = fps.processor();
SkNEW_APPEND_TO_TARRAY(&fFragmentStages, GrPendingFragmentStage, (fps));
SkNEW_APPEND_TO_TARRAY(&pipeline->fFragmentStages, GrPendingFragmentStage, (fps));
usesLocalCoords = usesLocalCoords || fp->usesLocalCoords();
fp->gatherCoordTransforms(&fCoordTransforms);
fp->gatherCoordTransforms(&pipeline->fCoordTransforms);
}
fNumColorStages = fFragmentStages.count();
for (int i = firstCoverageStageIdx; i < pipelineBuilder.numCoverageFragmentStages(); ++i) {
const GrFragmentStage& fps = pipelineBuilder.fCoverageStages[i];
pipeline->fNumColorStages = pipeline->fFragmentStages.count();
for (int i = firstCoverageStageIdx; i < builder.numCoverageFragmentStages(); ++i) {
const GrFragmentStage& fps = builder.fCoverageStages[i];
const GrFragmentProcessor* fp = fps.processor();
SkNEW_APPEND_TO_TARRAY(&fFragmentStages, GrPendingFragmentStage, (fps));
SkNEW_APPEND_TO_TARRAY(&pipeline->fFragmentStages, GrPendingFragmentStage, (fps));
usesLocalCoords = usesLocalCoords || fp->usesLocalCoords();
fp->gatherCoordTransforms(&fCoordTransforms);
fp->gatherCoordTransforms(&pipeline->fCoordTransforms);
}
// Setup info we need to pass to GrPrimitiveProcessors that are used with this GrPipeline.
fInfoForPrimitiveProcessor.fFlags = 0;
opts->fFlags = 0;
if (!SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag)) {
fInfoForPrimitiveProcessor.fFlags |=
GrPipelineOptimizations::kReadsColor_GrPipelineOptimizationsFlag;
opts->fFlags |= GrPipelineOptimizations::kReadsColor_Flag;
}
if (GrColor_ILLEGAL != overrideColor) {
fInfoForPrimitiveProcessor.fFlags |=
GrPipelineOptimizations::kUseOverrideColor_GrPipelineOptimizationsFlag;
fInfoForPrimitiveProcessor.fOverrideColor = overrideColor;
opts->fFlags |= GrPipelineOptimizations::kUseOverrideColor_Flag;
opts->fOverrideColor = overrideColor;
}
if (!SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag)) {
fInfoForPrimitiveProcessor.fFlags |=
GrPipelineOptimizations::kReadsCoverage_GrPipelineOptimizationsFlag;
opts->fFlags |= GrPipelineOptimizations::kReadsCoverage_Flag;
}
if (usesLocalCoords) {
fInfoForPrimitiveProcessor.fFlags |=
GrPipelineOptimizations::kReadsLocalCoords_GrPipelineOptimizationsFlag;
opts->fFlags |= GrPipelineOptimizations::kReadsLocalCoords_Flag;
}
if (SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag)) {
fInfoForPrimitiveProcessor.fFlags |=
GrPipelineOptimizations::kCanTweakAlphaForCoverage_GrPipelineOptimizationsFlag;
opts->fFlags |= GrPipelineOptimizations::kCanTweakAlphaForCoverage_Flag;
}
return pipeline;
}
void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelineBuilder,

View File

@ -31,15 +31,13 @@ class GrPipeline : public GrNonAtomicRef {
public:
/** Creates a pipeline into a pre-allocated buffer */
static GrPipeline* CreateAt(void* memory,
const GrPipelineBuilder& pb,
const GrPipelineBuilder&,
const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
const GrCaps& caps,
const GrScissorState& scissor,
const GrXferProcessor::DstTexture* dst) {
return SkNEW_PLACEMENT_ARGS(memory, GrPipeline, (pb, colorPOI, coveragePOI, caps, scissor,
dst));
}
const GrCaps&,
const GrScissorState&,
const GrXferProcessor::DstTexture*,
GrPipelineOptimizations*);
/*
* Returns true if these pipelines are equivalent. Coord transforms may be applied either on
@ -104,21 +102,12 @@ public:
bool readsFragPosition() const { return fReadsFragPosition; }
const GrPipelineOptimizations& infoForPrimitiveProcessor() const {
return fInfoForPrimitiveProcessor;
}
const SkTArray<const GrCoordTransform*, true>& coordTransforms() const {
return fCoordTransforms;
}
private:
GrPipeline(const GrPipelineBuilder&,
const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
const GrCaps&,
const GrScissorState&,
const GrXferProcessor::DstTexture*);
GrPipeline() { /** Initialized in factory function*/ }
/**
* Alter the program desc and inputs (attribs and processors) based on the blend optimization.
@ -155,7 +144,6 @@ private:
ProgramXferProcessor fXferProcessor;
FragmentStageArray fFragmentStages;
bool fReadsFragPosition;
GrPipelineOptimizations fInfoForPrimitiveProcessor;
// This function is equivalent to the offset into fFragmentStages where coverage stages begin.
int fNumColorStages;

View File

@ -83,28 +83,28 @@ struct GrInitInvariantOutput;
class GrPipelineOptimizations {
public:
/** Does the pipeline require the GrPrimitiveProcessor's color? */
bool readsColor() const { return SkToBool(kReadsColor_GrPipelineOptimizationsFlag & fFlags); }
bool readsColor() const { return SkToBool(kReadsColor_Flag & fFlags); }
/** Does the pipeline require the GrPrimitiveProcessor's coverage? */
bool readsCoverage() const { return
SkToBool(kReadsCoverage_GrPipelineOptimizationsFlag & fFlags); }
SkToBool(kReadsCoverage_Flag & fFlags); }
/** Does the pipeline require access to (implicit or explicit) local coordinates? */
bool readsLocalCoords() const {
return SkToBool(kReadsLocalCoords_GrPipelineOptimizationsFlag & fFlags);
return SkToBool(kReadsLocalCoords_Flag & fFlags);
}
/** Does the pipeline allow the GrPrimitiveProcessor to combine color and coverage into one
color output ? */
bool canTweakAlphaForCoverage() const {
return SkToBool(kCanTweakAlphaForCoverage_GrPipelineOptimizationsFlag & fFlags);
return SkToBool(kCanTweakAlphaForCoverage_Flag & fFlags);
}
/** Does the pipeline require the GrPrimitiveProcessor to specify a specific color (and if
so get the color)? */
bool getOverrideColorIfSet(GrColor* overrideColor) const {
if (SkToBool(kUseOverrideColor_GrPipelineOptimizationsFlag & fFlags)) {
SkASSERT(SkToBool(kReadsColor_GrPipelineOptimizationsFlag & fFlags));
if (SkToBool(kUseOverrideColor_Flag & fFlags)) {
SkASSERT(SkToBool(kReadsColor_Flag & fFlags));
if (overrideColor) {
*overrideColor = fOverrideColor;
}
@ -116,21 +116,21 @@ public:
private:
enum {
// If this is not set the primitive processor need not produce a color output
kReadsColor_GrPipelineOptimizationsFlag = 0x1,
kReadsColor_Flag = 0x1,
// If this is not set the primitive processor need not produce a coverage output
kReadsCoverage_GrPipelineOptimizationsFlag = 0x2,
kReadsCoverage_Flag = 0x2,
// If this is not set the primitive processor need not produce local coordinates
kReadsLocalCoords_GrPipelineOptimizationsFlag = 0x4,
kReadsLocalCoords_Flag = 0x4,
// If this flag is set then the primitive processor may produce color*coverage as
// its color output (and not output a separate coverage).
kCanTweakAlphaForCoverage_GrPipelineOptimizationsFlag = 0x8,
kCanTweakAlphaForCoverage_Flag = 0x8,
// If this flag is set the GrPrimitiveProcessor must produce fOverrideColor as its
// output color. If not set fOverrideColor is to be ignored.
kUseOverrideColor_GrPipelineOptimizationsFlag = 0x10,
kUseOverrideColor_Flag = 0x10,
};
uint32_t fFlags;