Skip to content

Commit

Permalink
Don't require GrPipelineBuilder to build GrPipeline
Browse files Browse the repository at this point in the history
Change-Id: Ic978913aa9dd0811eac102755934d77b4853a568
Reviewed-on: https://skia-review.googlesource.com/7207
Commit-Queue: Brian Salomon <[email protected]>
Reviewed-by: Greg Daniel <[email protected]>
  • Loading branch information
bsalomon authored and Skia Commit-Bot committed Jan 19, 2017
1 parent 52b346e commit 189098e
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 160 deletions.
48 changes: 19 additions & 29 deletions src/gpu/GrPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 21,6 @@

GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args,
GrPipelineOptimizations* optimizations) {
const GrPipelineBuilder& builder = *args.fPipelineBuilder;
const GrUserStencilSettings* userStencil = builder.getUserStencil();
GrRenderTarget* rt = args.fRenderTargetContext->accessRenderTarget();
if (!rt) {
return nullptr;
Expand All @@ -33,36 31,26 @@ GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args,
SkASSERT(pipeline->fRenderTarget);
pipeline->fScissorState = args.fAppliedClip->scissorState();
pipeline->fWindowRectsState = args.fAppliedClip->windowRectsState();
pipeline->fUserStencilSettings = userStencil;
pipeline->fDrawFace = builder.getDrawFace();
pipeline->fUserStencilSettings = args.fUserStencil;
pipeline->fDrawFace = static_cast<int16_t>(args.fDrawFace);

pipeline->fFlags = 0;
if (builder.isHWAntialias()) {
pipeline->fFlags |= kHWAA_Flag;
}
if (builder.snapVerticesToPixelCenters()) {
pipeline->fFlags |= kSnapVertices_Flag;
}
if (builder.getDisableOutputConversionToSRGB()) {
pipeline->fFlags |= kDisableOutputConversionToSRGB_Flag;
}
if (builder.getAllowSRGBInputs()) {
pipeline->fFlags |= kAllowSRGBInputs_Flag;
}
if (builder.getUsesDistanceVectorField()) {
pipeline->fFlags = args.fFlags;
if (args.fProcessors->usesDistanceVectorField()) {
pipeline->fFlags |= kUsesDistanceVectorField_Flag;
}
if (args.fAppliedClip->hasStencilClip()) {
pipeline->fFlags |= kHasStencilClip_Flag;
}
if (!userStencil->isDisabled(args.fAppliedClip->hasStencilClip())) {
if (!args.fUserStencil->isDisabled(args.fAppliedClip->hasStencilClip())) {
pipeline->fFlags |= kStencilEnabled_Flag;
}

bool isHWAA = kHWAntialias_Flag & args.fFlags;

// Create XferProcessor from DS's XPFactory
bool hasMixedSamples = args.fRenderTargetContext->hasMixedSamples() &&
(builder.isHWAntialias() || pipeline->isStencilEnabled());
const GrXPFactory* xpFactory = builder.getXPFactory();
(isHWAA || pipeline->isStencilEnabled());
const GrXPFactory* xpFactory = args.fProcessors->xpFactory();
sk_sp<GrXferProcessor> xferProcessor;
if (xpFactory) {
xferProcessor.reset(xpFactory->createXferProcessor(
Expand All @@ -86,7 74,7 @@ GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args,
const GrXferProcessor* xpForOpts = xferProcessor ? xferProcessor.get() :
&GrPorterDuffXPFactory::SimpleSrcOverXP();
optFlags = xpForOpts->getOptimizations(
args.fAnalysis, userStencil->doesWrite(args.fAppliedClip->hasStencilClip()),
args.fAnalysis, args.fUserStencil->doesWrite(args.fAppliedClip->hasStencilClip()),
&overrideColor, *args.fCaps);

// When path rendering the stencil settings are not always set on the GrPipelineBuilder
Expand All @@ -113,30 101,32 @@ GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args,

if ((optFlags & GrXferProcessor::kIgnoreColor_OptFlag) ||
(optFlags & GrXferProcessor::kOverrideColor_OptFlag)) {
firstColorProcessorIdx = builder.numColorFragmentProcessors();
firstColorProcessorIdx = args.fProcessors->numColorFragmentProcessors();
}

bool usesLocalCoords = false;

// Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline
pipeline->fNumColorProcessors = builder.numColorFragmentProcessors() - firstColorProcessorIdx;
pipeline->fNumColorProcessors =
args.fProcessors->numColorFragmentProcessors() - firstColorProcessorIdx;
int numTotalProcessors = pipeline->fNumColorProcessors
builder.numCoverageFragmentProcessors() - firstCoverageProcessorIdx;
args.fProcessors->numCoverageFragmentProcessors() -
firstCoverageProcessorIdx;
if (args.fAppliedClip->clipCoverageFragmentProcessor()) {
numTotalProcessors;
}
pipeline->fFragmentProcessors.reset(numTotalProcessors);
int currFPIdx = 0;
for (int i = firstColorProcessorIdx; i < builder.numColorFragmentProcessors();
for (int i = firstColorProcessorIdx; i < args.fProcessors->numColorFragmentProcessors();
i, currFPIdx) {
const GrFragmentProcessor* fp = builder.getColorFragmentProcessor(i);
const GrFragmentProcessor* fp = args.fProcessors->colorFragmentProcessor(i);
pipeline->fFragmentProcessors[currFPIdx].reset(fp);
usesLocalCoords = usesLocalCoords || fp->usesLocalCoords();
}

for (int i = firstCoverageProcessorIdx; i < builder.numCoverageFragmentProcessors();
for (int i = firstCoverageProcessorIdx; i < args.fProcessors->numCoverageFragmentProcessors();
i, currFPIdx) {
const GrFragmentProcessor* fp = builder.getCoverageFragmentProcessor(i);
const GrFragmentProcessor* fp = args.fProcessors->coverageFragmentProcessor(i);
pipeline->fFragmentProcessors[currFPIdx].reset(fp);
usesLocalCoords = usesLocalCoords || fp->usesLocalCoords();
}
Expand Down
70 changes: 44 additions & 26 deletions src/gpu/GrPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 60,8 @@ struct GrPipelineAnalysis {
bool fUsesPLSDstRead = false;
};

class GrProcessorSet;

/**
* Class that holds an optimized version of a GrPipelineBuilder. It is meant to be an immutable
* class, and contains all data needed to set the state for a gpu draw.
Expand All @@ -69,11 71,38 @@ class GrPipeline : public GrNonAtomicRef<GrPipeline> {
///////////////////////////////////////////////////////////////////////////
/// @name Creation

enum Flags {
/**
* Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
* or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
* the 3D API.
*/
kHWAntialias_Flag = 0x1,

/**
* Modifies the vertex shader so that vertices will be positioned at pixel centers.
*/
kSnapVerticesToPixelCenters_Flag = 0x2,

/**
* Suppress linear -> sRGB conversion when rendering to sRGB render targets.
*/
kDisableOutputConversionToSRGB_Flag = 0x4,

/**
* Allow sRGB -> linear conversion when reading from sRGB inputs.
*/
kAllowSRGBInputs_Flag = 0x8,
};

struct CreateArgs {
const GrPipelineBuilder* fPipelineBuilder;
GrAppliedClip* fAppliedClip;
GrRenderTargetContext* fRenderTargetContext;
const GrCaps* fCaps;
uint32_t fFlags = 0;
GrDrawFace fDrawFace = GrDrawFace::kBoth;
const GrProcessorSet* fProcessors = nullptr;
const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused;
GrAppliedClip* fAppliedClip = nullptr;
GrRenderTargetContext* fRenderTargetContext = nullptr;
const GrCaps* fCaps = nullptr;
GrPipelineAnalysis fAnalysis;
GrXferProcessor::DstTexture fDstTexture;
};
Expand Down Expand Up @@ -168,8 197,10 @@ class GrPipeline : public GrNonAtomicRef<GrPipeline> {

const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; }

bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); }
bool snapVerticesToPixelCenters() const { return SkToBool(fFlags & kSnapVertices_Flag); }
bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAntialias_Flag); }
bool snapVerticesToPixelCenters() const {
return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag);
}
bool getDisableOutputConversionToSRGB() const {
return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag);
}
Expand All @@ -195,28 226,15 @@ class GrPipeline : public GrNonAtomicRef<GrPipeline> {
* or both faces.
* @return the current draw face(s).
*/
GrDrawFace getDrawFace() const { return fDrawFace; }

GrDrawFace getDrawFace() const { return static_cast<GrDrawFace>(fDrawFace); }

private:
GrPipeline() { /** Initialized in factory function*/ }

/**
* Calculates the primary and secondary output types of the shader. For certain output types
* the function may adjust the blend coefficients. After this function is called the src and dst
* blend coeffs will represent those used by backend API.
*/
void setOutputStateInfo(const GrPipelineBuilder& ds, GrXferProcessor::OptFlags,
const GrCaps&);

enum Flags {
kHWAA_Flag = 0x1,
kSnapVertices_Flag = 0x2,
kDisableOutputConversionToSRGB_Flag = 0x4,
kAllowSRGBInputs_Flag = 0x8,
kUsesDistanceVectorField_Flag = 0x10,
kHasStencilClip_Flag = 0x20,
kStencilEnabled_Flag = 0x40,
enum PrivateFlags {
kUsesDistanceVectorField_Flag = 0x10,
kHasStencilClip_Flag = 0x20,
kStencilEnabled_Flag = 0x40,
};

typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget;
Expand All @@ -227,8 245,8 @@ class GrPipeline : public GrNonAtomicRef<GrPipeline> {
GrScissorState fScissorState;
GrWindowRectsState fWindowRectsState;
const GrUserStencilSettings* fUserStencilSettings;
GrDrawFace fDrawFace;
uint32_t fFlags;
uint16_t fDrawFace;
uint16_t fFlags;
ProgramXferProcessor fXferProcessor;
FragmentProcessorArray fFragmentProcessors;

Expand Down
23 changes: 12 additions & 11 deletions src/gpu/GrPipelineBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 17,24 @@

GrPipelineBuilder::GrPipelineBuilder(GrPaint&& paint, GrAAType aaType)
: fFlags(0x0)
, fUserStencilSettings(&GrUserStencilSettings::kUnused)
, fDrawFace(GrDrawFace::kBoth)
, fUserStencilSettings(&GrUserStencilSettings::kUnused)
, fProcessors(std::move(paint)) {
this->setState(GrPipelineBuilder::kHWAntialias_Flag, GrAATypeIsHW(aaType));
// The processors have been moved out of paint, but its flags should still be unmodified.
this->setState(GrPipelineBuilder::kDisableOutputConversionToSRGB_Flag,
paint.getDisableOutputConversionToSRGB());
this->setState(GrPipelineBuilder::kAllowSRGBInputs_Flag,
paint.getAllowSRGBInputs());
this->setState(GrPipelineBuilder::kUsesDistanceVectorField_Flag,
paint.usesDistanceVectorField());
if (GrAATypeIsHW(aaType)) {
fFlags |= GrPipeline::kHWAntialias_Flag;
}
if (paint.getDisableOutputConversionToSRGB()) {
fFlags |= GrPipeline::kDisableOutputConversionToSRGB_Flag;
}
if (paint.getAllowSRGBInputs()) {
fFlags |= GrPipeline::kAllowSRGBInputs_Flag;
}
}

bool GrPipelineBuilder::willXPNeedDstTexture(const GrCaps& caps,
const GrPipelineAnalysis& analysis) const {
if (this->getXPFactory()) {
return this->getXPFactory()->willNeedDstTexture(caps, analysis);
if (fProcessors.xpFactory()) {
return fProcessors.xpFactory()->willNeedDstTexture(caps, analysis);
}
return GrPorterDuffXPFactory::SrcOverWillNeedDstTexture(caps, analysis);
}
Loading

0 comments on commit 189098e

Please sign in to comment.