SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Create(edgeType, rrect));
SkASSERT(fp);
if (fp) {
- pipelineBuilder.addCoverageFragmentProcessor(fp);
+ pipelineBuilder.addCoverageProcessor(fp);
pipelineBuilder.setRenderTarget(rt);
SkRect bounds = SkRect::MakeWH(SkIntToScalar(kMaxSize),
GrClip clip;
GrPipelineBuilder pipelineBuilder(grPaint, rt, clip);
- pipelineBuilder.addColorFragmentProcessor(fp);
+ pipelineBuilder.addColorProcessor(fp);
tt.target()->drawNonAARect(pipelineBuilder,
grPaint.getColor(),
}
GrPipelineBuilder pipelineBuilder;
- pipelineBuilder.addCoverageFragmentProcessor(fp);
+ pipelineBuilder.addCoverageProcessor(fp);
pipelineBuilder.setRenderTarget(rt);
ConvexPolyTestBatch::Geometry geometry;
}
GrPipelineBuilder pipelineBuilder;
- pipelineBuilder.addCoverageFragmentProcessor(fp);
+ pipelineBuilder.addCoverageProcessor(fp);
pipelineBuilder.setRenderTarget(rt);
ConvexPolyTestBatch::Geometry geometry;
SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Create(edgeType,
rrect));
if (fp) {
- pipelineBuilder.addCoverageFragmentProcessor(fp);
+ pipelineBuilder.addCoverageProcessor(fp);
pipelineBuilder.setRenderTarget(rt);
SkRect bounds = rrect.getBounds();
}
const SkMatrix viewMatrix = SkMatrix::MakeTrans(x, y);
pipelineBuilder.setRenderTarget(rt);
- pipelineBuilder.addColorFragmentProcessor(fp);
+ pipelineBuilder.addColorProcessor(fp);
tt.target()->drawNonAARect(pipelineBuilder,
GrColor_WHITE,
SkMatrix viewMatrix;
viewMatrix.setTranslate(x, y);
pipelineBuilder.setRenderTarget(rt);
- pipelineBuilder.addColorFragmentProcessor(fp);
+ pipelineBuilder.addColorProcessor(fp);
tt.target()->drawNonAARect(pipelineBuilder,
GrColor_WHITE,
viewMatrix,
'<(skia_include_path)/gpu/GrRenderTarget.h',
'<(skia_include_path)/gpu/GrResourceKey.h',
'<(skia_include_path)/gpu/GrShaderVar.h',
+ '<(skia_include_path)/gpu/GrStagedProcessor.h',
'<(skia_include_path)/gpu/GrSurface.h',
'<(skia_include_path)/gpu/GrTexture.h',
'<(skia_include_path)/gpu/GrTextureProvider.h',
'<(skia_src_path)/gpu/GrPathUtils.cpp',
'<(skia_src_path)/gpu/GrPathUtils.h',
'<(skia_src_path)/gpu/GrPendingProgramElement.h',
+ '<(skia_src_path)/gpu/GrPendingFragmentStage.h',
'<(skia_src_path)/gpu/GrPipeline.cpp',
'<(skia_src_path)/gpu/GrPipeline.h',
'<(skia_src_path)/gpu/GrPipelineBuilder.cpp',
#define GrFragmentProcessor_DEFINED
#include "GrProcessor.h"
+#include "GrStagedProcessor.h"
class GrCoordTransform;
class GrGLSLCaps;
, fNumTexturesExclChildren(0)
, fNumTransformsExclChildren(0) {}
- ~GrFragmentProcessor() override;
-
GrGLFragmentProcessor* createGLInstance() const;
void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
this->onGetGLProcessorKey(caps, b);
for (int i = 0; i < fChildProcessors.count(); ++i) {
- fChildProcessors[i]->getGLProcessorKey(caps, b);
+ fChildProcessors[i].processor()->getGLProcessorKey(caps, b);
}
}
int numChildProcessors() const { return fChildProcessors.count(); }
- const GrFragmentProcessor& childProcessor(int index) const { return *fChildProcessors[index]; }
+ const GrFragmentProcessor& childProcessor(int index) const {
+ return *fChildProcessors[index].processor();
+ }
/** Do any of the coordtransforms for this processor require local coords? */
bool usesLocalCoords() const { return fUsesLocalCoords; }
int fNumTexturesExclChildren;
int fNumTransformsExclChildren;
- // TODO: These must convert their processors to pending-execution refs when the parent is
- // converted (do this automatically in GrProgramElement?).
- SkTArray<const GrFragmentProcessor*, true> fChildProcessors;
+ SkTArray<GrFragmentStage, false> fChildProcessors;
typedef GrProcessor INHERITED;
};
#define GrPaint_DEFINED
#include "GrColor.h"
+#include "GrStagedProcessor.h"
#include "GrProcessorDataManager.h"
#include "GrXferProcessor.h"
#include "effects/GrPorterDuffXferProcessor.h"
GrPaint(const GrPaint& paint) { *this = paint; }
- ~GrPaint() { this->resetFragmentProcessors(); }
+ ~GrPaint() {}
/**
* The initial color of the drawn primitive. Defaults to solid white.
/**
* Appends an additional color processor to the color computation.
*/
- const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* fp) {
+ const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* fp) {
SkASSERT(fp);
- fColorFragmentProcessors.push_back(SkRef(fp));
+ SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (fp));
return fp;
}
/**
* Appends an additional coverage processor to the coverage computation.
*/
- const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* fp) {
+ const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* fp) {
SkASSERT(fp);
- fCoverageFragmentProcessors.push_back(SkRef(fp));
+ SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (fp));
return fp;
}
void addColorTextureProcessor(GrTexture*, const SkMatrix&, const GrTextureParams&);
void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextureParams&);
- int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
- int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
- int numTotalFragmentProcessors() const { return this->numColorFragmentProcessors() +
- this->numCoverageFragmentProcessors(); }
+ int numColorStages() const { return fColorStages.count(); }
+ int numCoverageStages() const { return fCoverageStages.count(); }
+ int numTotalStages() const { return this->numColorStages() + this->numCoverageStages(); }
const GrXPFactory* getXPFactory() const {
if (!fXPFactory) {
return fXPFactory.get();
}
- const GrFragmentProcessor* getColorFragmentProcessor(int i) const {
- return fColorFragmentProcessors[i];
- }
- const GrFragmentProcessor* getCoverageFragmentProcessor(int i) const {
- return fCoverageFragmentProcessors[i];
- }
+ const GrFragmentStage& getColorStage(int s) const { return fColorStages[s]; }
+ const GrFragmentStage& getCoverageStage(int s) const { return fCoverageStages[s]; }
GrPaint& operator=(const GrPaint& paint) {
fAntiAlias = paint.fAntiAlias;
fDither = paint.fDither;
fColor = paint.fColor;
- this->resetFragmentProcessors();
- fColorFragmentProcessors = paint.fColorFragmentProcessors;
- fCoverageFragmentProcessors = paint.fCoverageFragmentProcessors;
- for (int i = 0; i < fColorFragmentProcessors.count(); ++i) {
- fColorFragmentProcessors[i]->ref();
- }
- for (int i = 0; i < fColorFragmentProcessors.count(); ++i) {
- fColorFragmentProcessors[i]->ref();
- }
+
+ fColorStages = paint.fColorStages;
+ fCoverageStages = paint.fCoverageStages;
fXPFactory.reset(SkRef(paint.getXPFactory()));
fProcDataManager.reset(SkNEW_ARGS(GrProcessorDataManager, (*paint.processorDataManager())));
const GrProcessorDataManager* processorDataManager() const { return fProcDataManager.get(); }
private:
- void resetFragmentProcessors() {
- for (int i = 0; i < fColorFragmentProcessors.count(); ++i) {
- fColorFragmentProcessors[i]->unref();
- }
- for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) {
- fCoverageFragmentProcessors[i]->unref();
- }
- fColorFragmentProcessors.reset();
- fCoverageFragmentProcessors.reset();
- }
-
- mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
- SkSTArray<4, const GrFragmentProcessor*, true> fColorFragmentProcessors;
- SkSTArray<2, const GrFragmentProcessor*, true> fCoverageFragmentProcessors;
+ mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
+ SkSTArray<4, GrFragmentStage> fColorStages;
+ SkSTArray<2, GrFragmentStage> fCoverageStages;
- bool fAntiAlias;
- bool fDither;
+ bool fAntiAlias;
+ bool fDither;
- GrColor fColor;
- SkAutoTUnref<GrProcessorDataManager> fProcDataManager;
+ GrColor fColor;
+ SkAutoTUnref<GrProcessorDataManager> fProcDataManager;
};
#endif
--- /dev/null
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrStagedProcessorStage_DEFINED
+#define GrStagedProcessorStage_DEFINED
+
+#include "SkRefCnt.h"
+
+class GrFragmentProcessor;
+
+/**
+ * Wraps a GrFragmentProcessor, basically a copyable SkAutoTUnref
+ * Templatized based on the ref type so backends can use the same wrapper
+ */
+template<template<typename> class T>
+class GrStagedProcessor {
+public:
+ explicit GrStagedProcessor(const GrFragmentProcessor* proc) : fProc(SkRef(proc)) {}
+
+ GrStagedProcessor(const GrStagedProcessor& other) { fProc.reset(SkRef(other.fProc.get())); }
+
+ const GrFragmentProcessor* processor() const { return fProc.get(); }
+
+ bool operator==(const GrStagedProcessor& that) const {
+ return this->processor()->isEqual(*that.processor());
+ }
+
+ bool operator!=(const GrStagedProcessor& that) const { return !(*this == that); }
+
+ const char* name() const { return fProc->name(); }
+
+protected:
+ GrStagedProcessor() {}
+
+ T<const GrFragmentProcessor> fProc;
+};
+
+typedef GrStagedProcessor<SkAutoTUnref> GrFragmentStage;
+
+#endif
GrPaint paint;
if (this->asFragmentProcessor(&fp, paint.getProcessorDataManager(), srcTexture, matrix, bounds)) {
SkASSERT(fp);
- paint.addColorFragmentProcessor(fp)->unref();
+ paint.addColorProcessor(fp)->unref();
GrDrawContext* drawContext = context->drawContext();
if (drawContext) {
return false;
}
- grp->addCoverageFragmentProcessor(fp);
+ grp->addCoverageProcessor(fp);
SkMatrix inverse;
if (!viewMatrix.invert(&inverse)) {
return false;
}
- grp->addCoverageFragmentProcessor(fp);
+ grp->addCoverageProcessor(fp);
SkMatrix inverse;
if (!viewMatrix.invert(&inverse)) {
SkMatrix matrix;
matrix.setIDiv(src->width(), src->height());
// Blend pathTexture over blurTexture.
- paint.addCoverageFragmentProcessor(
- GrSimpleTextureEffect::Create(paint.getProcessorDataManager(), src, matrix))->unref();
+ paint.addCoverageProcessor(GrSimpleTextureEffect::Create(paint.getProcessorDataManager(),
+ src, matrix))->unref();
if (kInner_SkBlurStyle == fBlurStyle) {
// inner: dst = dst * src
paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op);
offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.fX),
SkIntToScalar(colorOffset.fY - displacementOffset.fY));
- paint.addColorFragmentProcessor(
+ paint.addColorProcessor(
GrDisplacementMapEffect::Create(paint.getProcessorDataManager(),
fXChannelSelector,
fYChannelSelector,
GrPaint paint;
SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian(
paint.getProcessorDataManager(), texture, direction, radius, sigma, useBounds, bounds));
- paint.addColorFragmentProcessor(conv);
+ paint.addColorProcessor(conv);
drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), dstRect, srcRect);
}
texture, bounds, size, 1.0, 0.0, kernelOffset,
useBounds ? GrTextureDomain::kClamp_Mode : GrTextureDomain::kIgnore_Mode,
true, sigmaX, sigmaY));
- paint.addColorFragmentProcessor(conv);
+ paint.addColorProcessor(conv);
drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), dstRect, srcRect);
}
domain,
GrTextureDomain::kDecal_Mode,
GrTextureParams::kBilerp_FilterMode));
- paint.addColorFragmentProcessor(fp);
+ paint.addColorProcessor(fp);
} else {
GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode);
paint.addColorTextureProcessor(srcTexture, matrix, params);
GrPaint paint;
GrFragmentProcessor* fp = this->getFragmentProcessor(paint.getProcessorDataManager(), src,
matrix, bounds, boundaryMode);
- paint.addColorFragmentProcessor(fp)->unref();
+ paint.addColorProcessor(fp)->unref();
drawContext->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatrix::I(),
dstRect, srcRect);
}
float bounds[2],
Gr1DKernelEffect::Direction direction) {
GrPaint paint;
- paint.addColorFragmentProcessor(GrMorphologyEffect::Create(paint.getProcessorDataManager(),
- texture,
- direction,
- radius,
- morphType,
- bounds))->unref();
+ paint.addColorProcessor(GrMorphologyEffect::Create(paint.getProcessorDataManager(),
+ texture,
+ direction,
+ radius,
+ morphType,
+ bounds))->unref();
drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect));
}
GrMorphologyEffect::MorphologyType morphType,
Gr1DKernelEffect::Direction direction) {
GrPaint paint;
- paint.addColorFragmentProcessor(GrMorphologyEffect::Create(paint.getProcessorDataManager(),
- texture,
- direction,
- radius,
- morphType))->unref();
+ paint.addColorProcessor(GrMorphologyEffect::Create(paint.getProcessorDataManager(),
+ texture,
+ direction,
+ radius,
+ morphType))->unref();
drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect));
}
GrTextureParams::kNone_FilterMode)
);
- paint.addColorFragmentProcessor(foregroundDomain.get());
- paint.addColorFragmentProcessor(xferProcessor)->unref();
+ paint.addColorProcessor(foregroundDomain.get());
+ paint.addColorProcessor(xferProcessor)->unref();
GrDrawContext* drawContext = context->drawContext();
if (!drawContext) {
matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop);
matrix.postIDiv(mask->width(), mask->height());
- grp->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(grp->getProcessorDataManager(),
+ grp->addCoverageProcessor(GrSimpleTextureEffect::Create(grp->getProcessorDataManager(),
mask, matrix,
kDevice_GrCoordSet))->unref();
SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height());
// This could be a long-lived effect that is cached with the alpha-mask.
- arfps->addCoverageFragmentProcessor(
+ arfps->addCoverageProcessor(
GrTextureDomainEffect::Create(arfps->getProcessorDataManager(),
result,
mat,
break;
}
if (fp) {
- arfps->addCoverageFragmentProcessor(fp);
+ arfps->addCoverageProcessor(fp);
} else {
failed = true;
break;
SkMatrix sampleM;
sampleM.setIDiv(srcMask->width(), srcMask->height());
- pipelineBuilder->addCoverageFragmentProcessor(
+ pipelineBuilder->addCoverageProcessor(
GrTextureDomainEffect::Create(pipelineBuilder->getProcessorDataManager(),
srcMask,
sampleM,
if (!drawContext) {
return false;
}
- paint.addColorFragmentProcessor(fp);
+ paint.addColorProcessor(fp);
SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, matrix, rect, NULL);
GrConfigConversionEffect::kNone_PMConversion, textureMatrix));
}
if (fp) {
- paint.addColorFragmentProcessor(fp);
+ paint.addColorProcessor(fp);
SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
GrDrawContext* drawContext = this->drawContext();
drawContext->drawRect(temp->asRenderTarget(), GrClip::WideOpen(), paint,
return false;
}
arfps.set(&pipelineBuilder);
- arfps.addCoverageFragmentProcessor(fp)->unref();
+ arfps.addCoverageProcessor(fp)->unref();
}
SkStrokeRec fillRec(SkStrokeRec::kFill_InitStyle);
return false;
}
- arfps.addCoverageFragmentProcessor(effect)->unref();
+ arfps.addCoverageProcessor(effect)->unref();
SkRect bounds = outer->getBounds();
if (applyAA) {
bounds.outset(SK_ScalarHalf, SK_ScalarHalf);
}
void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
- this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
+ this->addColorProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
matrix))->unref();
}
void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
- this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
+ this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
matrix))->unref();
}
void GrPaint::addColorTextureProcessor(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params) {
- this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix,
+ this->addColorProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix,
params))->unref();
}
void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params) {
- this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix,
+ this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix,
params))->unref();
}
bool GrPaint::isConstantBlendedColor(GrColor* color) const {
GrProcOptInfo colorProcInfo;
- colorProcInfo.calcWithInitialValues(fColorFragmentProcessors.begin(),
- this->numColorFragmentProcessors(), fColor,
+ colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), fColor,
kRGBA_GrColorComponentFlags, false);
GrXPFactory::InvariantBlendedColor blendedColor;
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrPendingFragmentStage_DEFINED
+#define GrPendingFragmentStage_DEFINED
+
+#include "GrStagedProcessor.h"
+#include "GrPendingProgramElement.h"
+
+/**
+ * This a baked variant of GrFragmentStage, as recorded in GrPipeline
+ */
+class GrPendingFragmentStage : public GrStagedProcessor<GrPendingProgramElement> {
+public:
+ GrPendingFragmentStage(const GrFragmentStage& stage) {
+ INHERITED::fProc.reset(stage.processor());
+ }
+
+private:
+ typedef GrStagedProcessor<GrPendingProgramElement> INHERITED;
+};
+
+#endif
}
GrColor overrideColor = GrColor_ILLEGAL;
- if (args.fColorPOI.firstEffectiveProcessorIndex() != 0) {
- overrideColor = args.fColorPOI.inputColorToFirstEffectiveProccesor();
+ if (args.fColorPOI.firstEffectiveStageIndex() != 0) {
+ overrideColor = args.fColorPOI.inputColorToEffectiveStage();
}
GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags;
pipeline->fFlags |= kSnapVertices_Flag;
}
- int firstColorProcessorIdx = args.fColorPOI.firstEffectiveProcessorIndex();
+ int firstColorStageIdx = args.fColorPOI.firstEffectiveStageIndex();
- // TODO: Once we can handle single or four channel input into coverage GrFragmentProcessors
- // then we can use GrPipelineBuilder's coverageProcInfo (like color above) to set this initial
- // information.
- int firstCoverageProcessorIdx = 0;
+ // TODO: Once we can handle single or four channel input into coverage stages then we can use
+ // GrPipelineBuilder's coverageProcInfo (like color above) to set this initial information.
+ int firstCoverageStageIdx = 0;
pipeline->adjustProgramFromOptimizations(builder, optFlags, args.fColorPOI, args.fCoveragePOI,
- &firstColorProcessorIdx, &firstCoverageProcessorIdx);
+ &firstColorStageIdx, &firstCoverageStageIdx);
bool usesLocalCoords = false;
- // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline
- pipeline->fNumColorProcessors = builder.numColorFragmentProcessors() - firstColorProcessorIdx;
- int numTotalProcessors = pipeline->fNumColorProcessors +
- builder.numCoverageFragmentProcessors() - firstCoverageProcessorIdx;
- pipeline->fFragmentProcessors.reset(numTotalProcessors);
- int currFPIdx = 0;
- for (int i = firstColorProcessorIdx; i < builder.numColorFragmentProcessors();
- ++i, ++currFPIdx) {
- const GrFragmentProcessor* fp = builder.getColorFragmentProcessor(i);
- pipeline->fFragmentProcessors[currFPIdx].reset(fp);
+ // Copy Stages from PipelineBuilder to Pipeline
+ for (int i = firstColorStageIdx; i < builder.numColorFragmentStages(); ++i) {
+ const GrFragmentStage& fps = builder.fColorStages[i];
+ const GrFragmentProcessor* fp = fps.processor();
+ SkNEW_APPEND_TO_TARRAY(&pipeline->fFragmentStages, GrPendingFragmentStage, (fps));
usesLocalCoords = usesLocalCoords || fp->usesLocalCoords();
fp->gatherCoordTransforms(&pipeline->fCoordTransforms);
}
- for (int i = firstCoverageProcessorIdx; i < builder.numCoverageFragmentProcessors();
- ++i, ++currFPIdx) {
- const GrFragmentProcessor* fp = builder.getCoverageFragmentProcessor(i);
- pipeline->fFragmentProcessors[currFPIdx].reset(fp);
+ 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(&pipeline->fFragmentStages, GrPendingFragmentStage, (fps));
usesLocalCoords = usesLocalCoords || fp->usesLocalCoords();
fp->gatherCoordTransforms(&pipeline->fCoordTransforms);
}
GrXferProcessor::OptFlags flags,
const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
- int* firstColorProcessorIdx,
- int* firstCoverageProcessorIdx) {
+ int* firstColorStageIdx,
+ int* firstCoverageStageIdx) {
fReadsFragPosition = fXferProcessor->willReadFragmentPosition();
if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) ||
(flags & GrXferProcessor::kOverrideColor_OptFlag)) {
- *firstColorProcessorIdx = pipelineBuilder.numColorFragmentProcessors();
+ *firstColorStageIdx = pipelineBuilder.numColorFragmentStages();
} else {
if (coveragePOI.readsFragPosition()) {
fReadsFragPosition = true;
}
if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) {
- *firstCoverageProcessorIdx = pipelineBuilder.numCoverageFragmentProcessors();
+ *firstCoverageStageIdx = pipelineBuilder.numCoverageFragmentStages();
} else {
if (coveragePOI.readsFragPosition()) {
fReadsFragPosition = true;
SkASSERT(&a != &b);
if (a.getRenderTarget() != b.getRenderTarget() ||
- a.fFragmentProcessors.count() != b.fFragmentProcessors.count() ||
- a.fNumColorProcessors != b.fNumColorProcessors ||
+ a.fFragmentStages.count() != b.fFragmentStages.count() ||
+ a.fNumColorStages != b.fNumColorStages ||
a.fScissorState != b.fScissorState ||
a.fFlags != b.fFlags ||
a.fStencilSettings != b.fStencilSettings ||
return false;
}
- for (int i = 0; i < a.numFragmentProcessors(); i++) {
- if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i), ignoreCoordTransforms)) {
+ for (int i = 0; i < a.numFragmentStages(); i++) {
+ if (!a.getFragmentStage(i).processor()->isEqual(*b.getFragmentStage(i).processor(),
+ ignoreCoordTransforms)) {
return false;
}
}
#define GrPipeline_DEFINED
#include "GrColor.h"
-#include "GrFragmentProcessor.h"
#include "GrGpu.h"
#include "GrNonAtomicRef.h"
-#include "GrPendingProgramElement.h"
+#include "GrPendingFragmentStage.h"
#include "GrPrimitiveProcessor.h"
#include "GrProgramDesc.h"
#include "GrStencil.h"
/// @name GrFragmentProcessors
- int numColorFragmentProcessors() const { return fNumColorProcessors; }
- int numCoverageFragmentProcessors() const {
- return fFragmentProcessors.count() - fNumColorProcessors;
- }
- int numFragmentProcessors() const { return fFragmentProcessors.count(); }
+ int numColorFragmentStages() const { return fNumColorStages; }
+ int numCoverageFragmentStages() const { return fFragmentStages.count() - fNumColorStages; }
+ int numFragmentStages() const { return fFragmentStages.count(); }
const GrXferProcessor* getXferProcessor() const { return fXferProcessor.get(); }
- const GrFragmentProcessor& getColorFragmentProcessor(int idx) const {
- SkASSERT(idx < this->numColorFragmentProcessors());
- return *fFragmentProcessors[idx].get();
+ const GrPendingFragmentStage& getColorStage(int idx) const {
+ SkASSERT(idx < this->numColorFragmentStages());
+ return fFragmentStages[idx];
}
-
- const GrFragmentProcessor& getCoverageFragmentProcessor(int idx) const {
- SkASSERT(idx < this->numCoverageFragmentProcessors());
- return *fFragmentProcessors[fNumColorProcessors + idx].get();
+ const GrPendingFragmentStage& getCoverageStage(int idx) const {
+ SkASSERT(idx < this->numCoverageFragmentStages());
+ return fFragmentStages[fNumColorStages + idx];
}
-
- const GrFragmentProcessor& getFragmentProcessor(int idx) const {
- return *fFragmentProcessors[idx].get();
+ const GrPendingFragmentStage& getFragmentStage(int idx) const {
+ return fFragmentStages[idx];
}
/// @}
GrXferProcessor::OptFlags,
const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
- int* firstColorProcessorIdx,
- int* firstCoverageProcessorIdx);
+ int* firstColorStageIdx,
+ int* firstCoverageStageIdx);
/**
* Calculates the primary and secondary output types of the shader. For certain output types
};
typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget;
- typedef GrPendingProgramElement<const GrFragmentProcessor> PendingFragmentProcessor;
- typedef SkAutoSTArray<8, PendingFragmentProcessor> FragmentProcessorArray;
+ typedef SkSTArray<8, GrPendingFragmentStage> FragmentStageArray;
typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor;
RenderTarget fRenderTarget;
GrScissorState fScissorState;
GrPipelineBuilder::DrawFace fDrawFace;
uint32_t fFlags;
ProgramXferProcessor fXferProcessor;
- FragmentProcessorArray fFragmentProcessors;
+ FragmentStageArray fFragmentStages;
bool fReadsFragPosition;
- // This value is also the index in fFragmentProcessors where coverage processors begin.
- int fNumColorProcessors;
+ // This function is equivalent to the offset into fFragmentStages where coverage stages begin.
+ int fNumColorStages;
SkSTArray<8, const GrCoordTransform*, true> fCoordTransforms;
GrProgramDesc fDesc;
SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
}
+GrPipelineBuilder& GrPipelineBuilder::operator=(const GrPipelineBuilder& that) {
+ fProcDataManager.reset(SkNEW_ARGS(GrProcessorDataManager, (*that.processorDataManager())));
+ fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get()));
+ fFlags = that.fFlags;
+ fStencilSettings = that.fStencilSettings;
+ fDrawFace = that.fDrawFace;
+ fXPFactory.reset(SkRef(that.getXPFactory()));
+ fColorStages = that.fColorStages;
+ fCoverageStages = that.fCoverageStages;
+ fClip = that.fClip;
+
+ return *this;
+}
+
GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, GrRenderTarget* rt, const GrClip& clip) {
SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
fProcDataManager.reset(
const_cast<GrProcessorDataManager*>(SkRef(paint.processorDataManager())));
- for (int i = 0; i < paint.numColorFragmentProcessors(); ++i) {
- fColorFragmentProcessors.push_back(SkRef(paint.getColorFragmentProcessor(i)));
+ fColorStages.reset();
+ fCoverageStages.reset();
+
+ for (int i = 0; i < paint.numColorStages(); ++i) {
+ fColorStages.push_back(paint.getColorStage(i));
}
- for (int i = 0; i < paint.numCoverageFragmentProcessors(); ++i) {
- fCoverageFragmentProcessors.push_back(SkRef(paint.getCoverageFragmentProcessor(i)));
+ for (int i = 0; i < paint.numCoverageStages(); ++i) {
+ fCoverageStages.push_back(paint.getCoverageStage(i));
}
fXPFactory.reset(SkRef(paint.getXPFactory()));
void GrPipelineBuilder::AutoRestoreFragmentProcessorState::set(
const GrPipelineBuilder* pipelineBuilder) {
if (fPipelineBuilder) {
- int m = fPipelineBuilder->numColorFragmentProcessors() - fColorEffectCnt;
+ int m = fPipelineBuilder->numColorFragmentStages() - fColorEffectCnt;
SkASSERT(m >= 0);
- for (int i = 0; i < m; ++i) {
- fPipelineBuilder->fColorFragmentProcessors.fromBack(i)->unref();
- }
- fPipelineBuilder->fColorFragmentProcessors.pop_back_n(m);
+ fPipelineBuilder->fColorStages.pop_back_n(m);
- int n = fPipelineBuilder->numCoverageFragmentProcessors() - fCoverageEffectCnt;
+ int n = fPipelineBuilder->numCoverageFragmentStages() - fCoverageEffectCnt;
SkASSERT(n >= 0);
- for (int i = 0; i < n; ++i) {
- fPipelineBuilder->fCoverageFragmentProcessors.fromBack(i)->unref();
- }
- fPipelineBuilder->fCoverageFragmentProcessors.pop_back_n(n);
+ fPipelineBuilder->fCoverageStages.pop_back_n(n);
+
SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;)
fPipelineBuilder->getProcessorDataManager()->restoreToSaveMarker(/*fSaveMarker*/);
}
fPipelineBuilder = const_cast<GrPipelineBuilder*>(pipelineBuilder);
if (NULL != pipelineBuilder) {
- fColorEffectCnt = pipelineBuilder->numColorFragmentProcessors();
- fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentProcessors();
+ fColorEffectCnt = pipelineBuilder->numColorFragmentStages();
+ fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentStages();
SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;)
fSaveMarker = pipelineBuilder->processorDataManager()->currentSaveMarker();
}
GrPipelineBuilder::~GrPipelineBuilder() {
SkASSERT(0 == fBlockEffectRemovalCnt);
- for (int i = 0; i < fColorFragmentProcessors.count(); ++i) {
- fColorFragmentProcessors[i]->unref();
- }
- for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) {
- fCoverageFragmentProcessors[i]->unref();
- }
}
////////////////////////////////////////////////////////////////////////////////
void GrPipelineBuilder::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const {
- fColorProcInfo.calcColorWithPrimProc(pp, fColorFragmentProcessors.begin(),
- this->numColorFragmentProcessors());
-
+ fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColorFragmentStages());
}
void GrPipelineBuilder::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) const {
- fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageFragmentProcessors.begin(),
- this->numCoverageFragmentProcessors());
+ fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(),
+ this->numCoverageFragmentStages());
}
void GrPipelineBuilder::calcColorInvariantOutput(const GrDrawBatch* batch) const {
- fColorProcInfo.calcColorWithBatch(batch, fColorFragmentProcessors.begin(),
- this->numColorFragmentProcessors());
+ fColorProcInfo.calcColorWithBatch(batch, fColorStages.begin(), this->numColorFragmentStages());
}
void GrPipelineBuilder::calcCoverageInvariantOutput(const GrDrawBatch* batch) const {
- fCoverageProcInfo.calcCoverageWithBatch(batch, fCoverageFragmentProcessors.begin(),
- this->numCoverageFragmentProcessors());
+ fCoverageProcInfo.calcCoverageWithBatch(batch, fCoverageStages.begin(),
+ this->numCoverageFragmentStages());
}
+
#include "GrCaps.h"
#include "GrClip.h"
#include "GrGpuResourceRef.h"
+#include "GrStagedProcessor.h"
#include "GrProcOptInfo.h"
#include "GrProcessorDataManager.h"
#include "GrRenderTarget.h"
class GrPaint;
class GrTexture;
-class GrPipelineBuilder : public SkNoncopyable {
+class GrPipelineBuilder {
public:
GrPipelineBuilder();
+ GrPipelineBuilder(const GrPipelineBuilder& pipelineBuilder) {
+ SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
+ *this = pipelineBuilder;
+ }
+
/**
* Initializes the GrPipelineBuilder based on a GrPaint, render target, and clip. Note
* that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have
/// feed their output to the GrXferProcessor which controls blending.
////
- int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
- int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
- int numFragmentProcessors() const { return this->numColorFragmentProcessors() +
- this->numCoverageFragmentProcessors(); }
+ int numColorFragmentStages() const { return fColorStages.count(); }
+ int numCoverageFragmentStages() const { return fCoverageStages.count(); }
+ int numFragmentStages() const { return this->numColorFragmentStages() +
+ this->numCoverageFragmentStages(); }
- const GrFragmentProcessor* getColorFragmentProcessor(int idx) const {
- return fColorFragmentProcessors[idx];
- }
- const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const {
- return fCoverageFragmentProcessors[idx];
- }
+ const GrFragmentStage& getColorFragmentStage(int idx) const { return fColorStages[idx]; }
+ const GrFragmentStage& getCoverageFragmentStage(int idx) const { return fCoverageStages[idx]; }
- const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* processor) {
- SkASSERT(processor);
- fColorFragmentProcessors.push_back(SkRef(processor));
- return processor;
+ const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) {
+ SkASSERT(effect);
+ SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
+ return effect;
}
- const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* processor) {
- SkASSERT(processor);
- fCoverageFragmentProcessors.push_back(SkRef(processor));
- return processor;
+ const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) {
+ SkASSERT(effect);
+ SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
+ return effect;
}
/**
* Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
*/
void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
- this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
- matrix))->unref();
+ this->addColorProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
+ matrix))->unref();
}
void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
- this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
- matrix))->unref();
+ this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
+ matrix))->unref();
}
void addColorTextureProcessor(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params) {
- this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
- matrix,
- params))->unref();
+ this->addColorProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix,
+ params))->unref();
}
void addCoverageTextureProcessor(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params) {
- this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
- matrix, params))->unref();
+ this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix,
+ params))->unref();
}
/**
return fPipelineBuilder->getProcessorDataManager();
}
- const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* processor) {
+ const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* processor) {
SkASSERT(this->isSet());
- return fPipelineBuilder->addCoverageFragmentProcessor(processor);
+ return fPipelineBuilder->addCoverageProcessor(processor);
}
private:
///////////////////////////////////////////////////////////////////////////
+ GrPipelineBuilder& operator=(const GrPipelineBuilder& that);
+
// TODO delete when we have Batch
const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const {
this->calcColorInvariantOutput(pp);
// This is used to assert that this condition holds.
SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;)
- typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArray;
+ typedef SkSTArray<4, GrFragmentStage> FragmentStageArray;
SkAutoTUnref<GrProcessorDataManager> fProcDataManager;
SkAutoTUnref<GrRenderTarget> fRenderTarget;
GrStencilSettings fStencilSettings;
DrawFace fDrawFace;
mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
- FragmentProcessorArray fColorFragmentProcessors;
- FragmentProcessorArray fCoverageFragmentProcessors;
+ FragmentStageArray fColorStages;
+ FragmentStageArray fCoverageStages;
GrClip fClip;
mutable GrProcOptInfo fColorProcInfo;
#include "batches/GrDrawBatch.h"
void GrProcOptInfo::calcColorWithBatch(const GrDrawBatch* batch,
- const GrFragmentProcessor* const processors[],
- int cnt) {
+ const GrFragmentStage* stages,
+ int stageCount) {
GrInitInvariantOutput out;
batch->getInvariantOutputColor(&out);
fInOut.reset(out);
- this->internalCalc(processors, cnt, batch->willReadFragmentPosition());
+ this->internalCalc(stages, stageCount, batch->willReadFragmentPosition());
}
void GrProcOptInfo::calcCoverageWithBatch(const GrDrawBatch* batch,
- const GrFragmentProcessor* const processors[],
- int cnt) {
+ const GrFragmentStage* stages,
+ int stageCount) {
GrInitInvariantOutput out;
batch->getInvariantOutputCoverage(&out);
fInOut.reset(out);
- this->internalCalc(processors, cnt, batch->willReadFragmentPosition());
+ this->internalCalc(stages, stageCount, batch->willReadFragmentPosition());
}
void GrProcOptInfo::calcColorWithPrimProc(const GrPrimitiveProcessor* primProc,
- const GrFragmentProcessor * const processors[],
- int cnt) {
+ const GrFragmentStage* stages,
+ int stageCount) {
GrInitInvariantOutput out;
primProc->getInvariantOutputColor(&out);
fInOut.reset(out);
- this->internalCalc(processors, cnt, primProc->willReadFragmentPosition());
+ this->internalCalc(stages, stageCount, primProc->willReadFragmentPosition());
}
void GrProcOptInfo::calcCoverageWithPrimProc(const GrPrimitiveProcessor* primProc,
- const GrFragmentProcessor * const processors[],
- int cnt) {
+ const GrFragmentStage* stages,
+ int stageCount) {
GrInitInvariantOutput out;
primProc->getInvariantOutputCoverage(&out);
fInOut.reset(out);
- this->internalCalc(processors, cnt, primProc->willReadFragmentPosition());
+ this->internalCalc(stages, stageCount, primProc->willReadFragmentPosition());
}
-void GrProcOptInfo::calcWithInitialValues(const GrFragmentProcessor * const processors[],
- int cnt,
+void GrProcOptInfo::calcWithInitialValues(const GrFragmentStage* stages,
+ int stageCount,
GrColor startColor,
GrColorComponentFlags flags,
bool areCoverageStages) {
out.fColor = startColor;
out.fValidFlags = flags;
fInOut.reset(out);
- this->internalCalc(processors, cnt, false);
+ this->internalCalc(stages, stageCount, false);
}
-void GrProcOptInfo::internalCalc(const GrFragmentProcessor* const processors[],
- int cnt,
+void GrProcOptInfo::internalCalc(const GrFragmentStage* stages,
+ int stageCount,
bool initWillReadFragmentPosition) {
- fFirstEffectiveProcessorIndex = 0;
+ fFirstEffectStageIndex = 0;
fInputColorIsUsed = true;
fInputColor = fInOut.color();
fReadsFragPosition = initWillReadFragmentPosition;
- for (int i = 0; i < cnt; ++i) {
- const GrFragmentProcessor* processor = processors[i];
+ for (int i = 0; i < stageCount; ++i) {
+ const GrFragmentProcessor* processor = stages[i].processor();
fInOut.resetWillUseInputColor();
processor->computeInvariantOutput(&fInOut);
SkDEBUGCODE(fInOut.validate());
if (!fInOut.willUseInputColor()) {
- fFirstEffectiveProcessorIndex = i;
+ fFirstEffectStageIndex = i;
fInputColorIsUsed = false;
// Reset these since we don't care if previous stages read these values
fReadsFragPosition = initWillReadFragmentPosition;
fReadsFragPosition = true;
}
if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
- fFirstEffectiveProcessorIndex = i + 1;
+ fFirstEffectStageIndex = i + 1;
fInputColor = fInOut.color();
fInputColorIsUsed = true;
// Since we are clearing all previous color stages we are in a state where we have found
#include "GrColor.h"
#include "GrInvariantOutput.h"
+#include "GrStagedProcessor.h"
class GrDrawBatch;
class GrFragmentProcessor;
public:
GrProcOptInfo()
: fInOut(0, static_cast<GrColorComponentFlags>(0), false)
- , fFirstEffectiveProcessorIndex(0)
+ , fFirstEffectStageIndex(0)
, fInputColorIsUsed(true)
, fInputColor(0)
, fReadsFragPosition(false) {}
- void calcWithInitialValues(const GrFragmentProcessor* const *, int cnt, GrColor startColor,
- GrColorComponentFlags, bool areCoverageStages);
+ void calcWithInitialValues(const GrFragmentStage*, int stageCount, GrColor startColor,
+ GrColorComponentFlags flags, bool areCoverageStages);
- void calcColorWithBatch(const GrDrawBatch*, const GrFragmentProcessor* const[], int cnt);
- void calcCoverageWithBatch(const GrDrawBatch*, const GrFragmentProcessor* const[], int cnt);
+ void calcColorWithBatch(const GrDrawBatch*, const GrFragmentStage*, int stagecount);
+ void calcCoverageWithBatch(const GrDrawBatch*, const GrFragmentStage*, int stagecount);
// TODO delete these when batch is everywhere
- void calcColorWithPrimProc(const GrPrimitiveProcessor*, const GrFragmentProcessor* const[],
- int cnt);
- void calcCoverageWithPrimProc(const GrPrimitiveProcessor*, const GrFragmentProcessor* const[],
- int cnt);
+ void calcColorWithPrimProc(const GrPrimitiveProcessor*, const GrFragmentStage*, int stagecount);
+ void calcCoverageWithPrimProc(const GrPrimitiveProcessor*, const GrFragmentStage*,
+ int stagecount);
bool isSolidWhite() const { return fInOut.isSolidWhite(); }
bool isOpaque() const { return fInOut.isOpaque(); }
}
/**
- * Returns the index of the first effective color processor. If an intermediate processor
- * doesn't read its input or has a known output, then we can ignore all earlier processors
- * since they will not affect the final output. Thus the first effective processors index is
- * the index to the first processor that will have an effect on the final output.
+ * Returns the index of the first effective color stage. If an intermediate stage doesn't read
+ * its input or has a known output, then we can ignore all earlier stages since they will not
+ * affect the final output. Thus the first effective stage index is the index to the first stage
+ * that will have an effect on the final output.
*
- * If processors before the firstEffectiveProcessorIndex() are removed, corresponding values
- * from inputColorIsUsed(), inputColorToEffectiveProcessor(), removeVertexAttribs(), and
- * readsDst() must be used when setting up the draw to ensure correct drawing.
+ * If stages before the firstEffectiveStageIndex are removed, corresponding values from
+ * inputColorIsUsed(), inputColorToEffectiveStage(), removeVertexAttribs(), and readsDst() must
+ * be used when setting up the draw to ensure correct drawing.
*/
- int firstEffectiveProcessorIndex() const { return fFirstEffectiveProcessorIndex; }
+ int firstEffectiveStageIndex() const { return fFirstEffectStageIndex; }
/**
- * True if the first effective processor reads its input, false otherwise.
+ * True if the first effective stage reads its input, false otherwise.
*/
bool inputColorIsUsed() const { return fInputColorIsUsed; }
/**
* If input color is used and per-vertex colors are not used, this is the input color to the
- * first effective processor.
+ * first effective stage.
*/
- GrColor inputColorToFirstEffectiveProccesor() const { return fInputColor; }
+ GrColor inputColorToEffectiveStage() const { return fInputColor; }
/**
- * Returns true if any of the processor preserved by GrProcOptInfo read the frag position.
+ * Returns true if any of the stages preserved by GrProcOptInfo read the frag position.
*/
bool readsFragPosition() const { return fReadsFragPosition; }
private:
- void internalCalc(const GrFragmentProcessor* const[], int cnt, bool initWillReadFragPosition);
+ void internalCalc(const GrFragmentStage*, int stagecount, bool initWillReadFragPosition);
GrInvariantOutput fInOut;
- int fFirstEffectiveProcessorIndex;
+ int fFirstEffectStageIndex;
bool fInputColorIsUsed;
GrColor fInputColor;
bool fReadsFragPosition;
///////////////////////////////////////////////////////////////////////////////////////////////////
-GrFragmentProcessor::~GrFragmentProcessor() {
- for (int i = 0; i < fChildProcessors.count(); ++i) {
- fChildProcessors[i]->unref();
- }
-}
-
bool GrFragmentProcessor::isEqual(const GrFragmentProcessor& that,
bool ignoreCoordTransforms) const {
if (this->classID() != that.classID() ||
GrGLFragmentProcessor* glFragProc = this->onCreateGLInstance();
glFragProc->fChildProcessors.push_back_n(fChildProcessors.count());
for (int i = 0; i < fChildProcessors.count(); ++i) {
- glFragProc->fChildProcessors[i] = fChildProcessors[i]->createGLInstance();
+ glFragProc->fChildProcessors[i] = fChildProcessors[i].processor()->createGLInstance();
}
return glFragProc;
}
}
int index = fChildProcessors.count();
- fChildProcessors.push_back(SkRef(child));
+ fChildProcessors.push_back(GrFragmentStage(child));
if (child->willReadFragmentPosition()) {
this->setWillReadFragmentPosition();
maskMatrix.setIDiv(texture->width(), texture->height());
maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop));
- pipelineBuilder->addCoverageFragmentProcessor(
+ pipelineBuilder->addCoverageProcessor(
GrSimpleTextureEffect::Create(pipelineBuilder->getProcessorDataManager(),
texture,
maskMatrix,
}
// The bitmap read has to be first
- grPaint.addColorFragmentProcessor(fp);
+ grPaint.addColorProcessor(fp);
if (!SkPaint2GrPaintNoShader(context, renderTarget, paint, SkColor2GrColor(paint.getColor()),
false, &grPaint)) {
return;
SkMatrix::I(), params));
}
- grPaint.addColorFragmentProcessor(fp);
+ grPaint.addColorProcessor(fp);
bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType());
GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()) :
SkColor2GrColor(paint.getColor());
yuvToRgbProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorDataManager(), yuvTextures[0],
yuvTextures[1], yuvTextures[2],
yuvInfo.fSize, yuvInfo.fColorSpace));
- paint.addColorFragmentProcessor(yuvToRgbProcessor);
+ paint.addColorProcessor(yuvToRgbProcessor);
SkRect r = SkRect::MakeWH(SkIntToScalar(yuvInfo.fSize[0].fWidth),
SkIntToScalar(yuvInfo.fSize[0].fHeight));
if (colorFilter->asFragmentProcessors(context, grPaint->getProcessorDataManager(),
&array)) {
for (int i = 0; i < array.count(); ++i) {
- grPaint->addColorFragmentProcessor(array[i]);
+ grPaint->addColorProcessor(array[i]);
array[i]->unref();
}
}
#ifndef SK_IGNORE_GPU_DITHER
// If the dither flag is set, then we need to see if the underlying context
// supports it. If not, then install a dither effect.
- if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0) {
+ if (skPaint.isDither() && grPaint->numColorStages() > 0) {
// What are we rendering into?
SkASSERT(rt);
// not going to be dithered by the GPU.
SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create());
if (fp.get()) {
- grPaint->addColorFragmentProcessor(fp);
+ grPaint->addColorProcessor(fp);
grPaint->setDither(false);
}
}
return false;
}
if (fp) {
- grPaint->addColorFragmentProcessor(fp)->unref();
+ grPaint->addColorProcessor(fp)->unref();
constantColor = false;
}
}
SkString dumpInfo() const override {
SkString string;
string.append("ColorStages:\n");
- for (int i = 0; i < this->pipeline()->numColorFragmentProcessors(); i++) {
- string.appendf("\t\t%s\n", this->pipeline()->getColorFragmentProcessor(i).name());
+ for (int i = 0; i < this->pipeline()->numColorFragmentStages(); i++) {
+ string.appendf("\t\t%s\n", this->pipeline()->getColorStage(i).processor()->name());
}
string.append("CoverageStages:\n");
- for (int i = 0; i < this->pipeline()->numCoverageFragmentProcessors(); i++) {
- string.appendf("\t%s\n", this->pipeline()->getCoverageFragmentProcessor(i).name());
+ for (int i = 0; i < this->pipeline()->numCoverageFragmentStages(); i++) {
+ string.appendf("\t%s\n", this->pipeline()->getCoverageStage(i).processor()->name());
}
string.appendf("XP: %s\n", this->pipeline()->getXferProcessor()->name());
return string;
(paint3.getProcessorDataManager(), tempTex, false, *pmToUPMRule,
SkMatrix::I())));
- paint1.addColorFragmentProcessor(pmToUPM1);
+ paint1.addColorProcessor(pmToUPM1);
GrDrawContext* readDrawContext = context->drawContext();
readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead);
- paint2.addColorFragmentProcessor(upmToPM);
+ paint2.addColorProcessor(upmToPM);
GrDrawContext* tempDrawContext = context->drawContext();
if (!tempDrawContext) {
kDstRect,
kSrcRect);
- paint3.addColorFragmentProcessor(pmToUPM2);
+ paint3.addColorProcessor(pmToUPM2);
readDrawContext = context->drawContext();
if (!readDrawContext) {
}
void GrGLPathProgram::setTransformData(const GrPrimitiveProcessor& primProc,
- const GrFragmentProcessor& processor,
+ const GrPendingFragmentStage& proc,
int index,
GrGLInstalledFragProc* ip) {
GrGLPathProcessor* pathProc =
static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.get());
pathProc->setTransformData(primProc, fPathProgramDataManager, index,
- processor.coordTransforms());
+ proc.processor()->coordTransforms());
}
void GrGLPathProgram::onSetRenderTargetState(const GrPrimitiveProcessor& primProc,
private:
void didSetData() override;
virtual void setTransformData(const GrPrimitiveProcessor&,
- const GrFragmentProcessor&,
+ const GrPendingFragmentStage&,
int index,
GrGLInstalledFragProc*) override;
void onSetRenderTargetState(const GrPrimitiveProcessor&, const GrPipeline&) override;
const GrPipeline& pipeline,
SkTArray<const GrTextureAccess*>* textureBindings) {
int numProcessors = fFragmentProcessors->fProcs.count();
- for (int i = 0; i < numProcessors; ++i) {
- const GrFragmentProcessor& processor = pipeline.getFragmentProcessor(i);
- fFragmentProcessors->fProcs[i]->fGLProc->setData(fProgramDataManager, processor);
+ for (int e = 0; e < numProcessors; ++e) {
+ const GrPendingFragmentStage& stage = pipeline.getFragmentStage(e);
+ const GrFragmentProcessor& processor = *stage.processor();
+ fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor);
this->setTransformData(primProc,
- processor,
- i,
- fFragmentProcessors->fProcs[i]);
- append_texture_bindings(fFragmentProcessors->fProcs[i], processor, textureBindings);
+ stage,
+ e,
+ fFragmentProcessors->fProcs[e]);
+ append_texture_bindings(fFragmentProcessors->fProcs[e], processor, textureBindings);
}
}
void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc,
- const GrFragmentProcessor& processor,
+ const GrPendingFragmentStage& processor,
int index,
GrGLInstalledFragProc* ip) {
GrGLGeometryProcessor* gp =
static_cast<GrGLGeometryProcessor*>(fGeometryProcessor.get()->fGLProc.get());
gp->setTransformData(primProc, fProgramDataManager, index,
- processor.coordTransforms());
+ processor.processor()->coordTransforms());
}
void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc,
void setFragmentData(const GrPrimitiveProcessor&, const GrPipeline&,
SkTArray<const GrTextureAccess*>* textureBindings);
virtual void setTransformData(const GrPrimitiveProcessor&,
- const GrFragmentProcessor&,
+ const GrPendingFragmentStage&,
int index,
GrGLInstalledFragProc*);
return false;
}
- for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
- const GrFragmentProcessor& fp = pipeline.getFragmentProcessor(i);
+ for (int s = 0; s < pipeline.numFragmentStages(); ++s) {
+ const GrPendingFragmentStage& fps = pipeline.getFragmentStage(s);
+ const GrFragmentProcessor& fp = *fps.processor();
if (!get_frag_proc_and_meta_keys(primProc, fp, gpu->glCaps(), &b)) {
glDesc->key().reset();
return false;
header->fFragPosKey = 0;
}
header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters();
- header->fColorEffectCnt = pipeline.numColorFragmentProcessors();
- header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors();
+ header->fColorEffectCnt = pipeline.numColorFragmentStages();
+ header->fCoverageEffectCnt = pipeline.numCoverageFragmentStages();
glDesc->finalize();
return true;
}
int totalTextures = primProc.numTextures();
const int maxTextureUnits = fGpu->glCaps().maxFragmentTextureUnits();
- for (int i = 0; i < this->pipeline().numFragmentProcessors(); i++) {
- const GrFragmentProcessor& processor = this->pipeline().getFragmentProcessor(i);
+ for (int i = 0; i < this->pipeline().numFragmentStages(); i++) {
+ const GrFragmentProcessor* processor = this->pipeline().getFragmentStage(i).processor();
if (!primProc.hasTransformedLocalCoords()) {
- SkTArray<const GrCoordTransform*, true>& procCoords = fCoordTransforms.push_back();
- processor.gatherCoordTransforms(&procCoords);
+ SkSTArray<2, const GrCoordTransform*, true>& procCoords = fCoordTransforms.push_back();
+ processor->gatherCoordTransforms(&procCoords);
}
- totalTextures += processor.numTextures();
+ totalTextures += processor->numTextures();
if (totalTextures >= maxTextureUnits) {
GrCapsDebugf(fGpu->caps(), "Program would use too many texture units\n");
return false;
this->emitAndInstallProc(primProc, inputColor, inputCoverage);
fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs));
- int numProcs = this->pipeline().numFragmentProcessors();
- this->emitAndInstallFragProcs(0, this->pipeline().numColorFragmentProcessors(), inputColor);
- this->emitAndInstallFragProcs(this->pipeline().numColorFragmentProcessors(), numProcs,
+ int numProcs = this->pipeline().numFragmentStages();
+ this->emitAndInstallFragProcs(0, this->pipeline().numColorFragmentStages(), inputColor);
+ this->emitAndInstallFragProcs(this->pipeline().numColorFragmentStages(), numProcs,
inputCoverage);
this->emitAndInstallXferProc(*this->pipeline().getXferProcessor(), *inputColor, *inputCoverage);
return true;
void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset,
int numProcs,
GrGLSLExpr4* inOut) {
- for (int i = procOffset; i < numProcs; ++i) {
+ for (int e = procOffset; e < numProcs; ++e) {
GrGLSLExpr4 output;
- const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i);
- this->emitAndInstallProc(fp, i, *inOut, &output);
+ const GrPendingFragmentStage& stage = this->pipeline().getFragmentStage(e);
+ this->emitAndInstallProc(stage, e, *inOut, &output);
*inOut = output;
}
}
// TODO Processors cannot output zeros because an empty string is all 1s
// the fix is to allow effects to take the GrGLSLExpr4 directly
-void GrGLProgramBuilder::emitAndInstallProc(const GrFragmentProcessor& fp,
+void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& proc,
int index,
const GrGLSLExpr4& input,
GrGLSLExpr4* output) {
// Enclose custom code in a block to avoid namespace conflicts
SkString openBrace;
- openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name());
+ openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name());
fFS.codeAppend(openBrace.c_str());
- this->emitAndInstallProc(fp, index, output->c_str(), input.isOnes() ? NULL : input.c_str());
+ this->emitAndInstallProc(proc, index, output->c_str(), input.isOnes() ? NULL : input.c_str());
fFS.codeAppend("}");
}
fFS.codeAppend("}");
}
-void GrGLProgramBuilder::emitAndInstallProc(const GrFragmentProcessor& fp,
+void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs,
int index,
const char* outColor,
const char* inColor) {
GrGLInstalledFragProc* ifp = SkNEW(GrGLInstalledFragProc);
+ const GrFragmentProcessor& fp = *fs.processor();
ifp->fGLProc.reset(fp.createGLInstance());
SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures());
GrGLInstalledFragProcs::~GrGLInstalledFragProcs() {
int numProcs = fProcs.count();
- for (int i = 0; i < numProcs; ++i) {
- SkDELETE(fProcs[i]);
+ for (int e = 0; e < numProcs; ++e) {
+ SkDELETE(fProcs[e]);
}
}
#include "../GrGLUniformHandle.h"
#include "../GrGLPrimitiveProcessor.h"
#include "../GrGLXferProcessor.h"
+#include "../../GrPendingFragmentStage.h"
#include "../../GrPipeline.h"
-class GrFragmentProcessor;
-
// Enough precision to represent 1 / 2048 accurately in printf
#define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11
void nameExpression(GrGLSLExpr4*, const char* baseName);
bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage);
void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOut);
- void emitAndInstallProc(const GrFragmentProcessor&,
+ void emitAndInstallProc(const GrPendingFragmentStage&,
int index,
const GrGLSLExpr4& input,
GrGLSLExpr4* output);
GrGLSLExpr4* outputCoverage);
// these emit functions help to keep the createAndEmitProcessors template general
- void emitAndInstallProc(const GrFragmentProcessor&,
+ void emitAndInstallProc(const GrPendingFragmentStage&,
int index,
const char* outColor,
const char* inColor);
GrPaint paint;
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
- paint.addColorFragmentProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorDataManager(),
- yTex, uTex, vTex, yuvSizes,
- colorSpace))->unref();
+ paint.addColorProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorDataManager(), yTex, uTex,
+ vTex, yuvSizes, colorSpace))->unref();
const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth),
SkIntToScalar(dstDesc.fHeight));
// finally add the stage to the correct pipeline in the drawstate
if (s < numColorProcs) {
- pipelineBuilder->addColorFragmentProcessor(fp);
+ pipelineBuilder->addColorProcessor(fp);
} else {
- pipelineBuilder->addCoverageFragmentProcessor(fp);
+ pipelineBuilder->addCoverageProcessor(fp);
}
++s;
}