*/
class GrBackendProcessorFactory : SkNoncopyable {
public:
- /**
- * Generates an processor's key. The key is based on the aspects of the GrProcessor object's
- * configuration that affect GLSL code generation. Two GrProcessor instances that would cause
- * this->createGLInstance()->emitCode() to produce different code must produce different keys.
- */
- virtual void getGLProcessorKey(const GrProcessor&, const GrGLCaps&,
- GrProcessorKeyBuilder*) const = 0;
-
/**
* Produces a human-reable name for the v.
*/
class GrBackendFragmentProcessorFactory : public GrBackendProcessorFactory {
public:
+ /**
+ * Generates an processor's key. The key is based on the aspects of the GrProcessor object's
+ * configuration that affect GLSL code generation. Two GrProcessor instances that would cause
+ * this->createGLInstance()->emitCode() to produce different code must produce different keys.
+ */
+ virtual void getGLProcessorKey(const GrFragmentProcessor&,
+ const GrGLCaps&,
+ GrProcessorKeyBuilder*) const = 0;
+
/**
* Creates a GrGLProcessor instance that is used both to generate code for the GrProcessor in a
* GLSL program and to manage updating uniforms for the program when it is used.
virtual GrGLXferProcessor* createGLInstance(const GrXferProcessor&) const = 0;
};
+class GrBatchTracker;
+
class GrBackendGeometryProcessorFactory : public GrBackendProcessorFactory {
public:
+ /**
+ * Generates an processor's key. The key is based on the aspects of the GrProcessor object's
+ * configuration that affect GLSL code generation. Two GrProcessor instances that would cause
+ * this->createGLInstance()->emitCode() to produce different code must produce different keys.
+ */
+ virtual void getGLProcessorKey(const GrGeometryProcessor&,
+ const GrBatchTracker&,
+ const GrGLCaps&,
+ GrProcessorKeyBuilder*) const = 0;
+
/**
* Creates a GrGLProcessor instance that is used both to generate code for the GrProcessor in a
* GLSL program and to manage updating uniforms for the program when it is used.
*/
- virtual GrGLGeometryProcessor* createGLInstance(const GrGeometryProcessor&) const = 0;
+ virtual GrGLGeometryProcessor* createGLInstance(const GrGeometryProcessor&,
+ const GrBatchTracker&) const = 0;
};
#endif
* described in this class's comment. */
virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name(); }
-
- /** Implemented using GLProcessor::GenKey as described in this class's comment. */
- virtual void getGLProcessorKey(const GrProcessor& processor,
- const GrGLCaps& caps,
- GrProcessorKeyBuilder* b) const SK_OVERRIDE {
- GLProcessor::GenKey(processor, caps, b);
- }
-
/** Returns a new instance of the appropriate *GL* implementation class
for the given GrProcessor; caller is responsible for deleting
the object. */
* typesafe and does not require any casting.
*/
template <class ProcessorClass>
-class GrTBackendGeometryProcessorFactory
- : public GrTBackendProcessorFactory<ProcessorClass,
- GrBackendGeometryProcessorFactory,
- GrGeometryProcessor,
- GrGLGeometryProcessor> {
+class GrTBackendGeometryProcessorFactory : public GrBackendGeometryProcessorFactory {
+public:
+ typedef typename ProcessorClass::GLProcessor GLProcessor;
+
+ /** Returns a human-readable name for the processor. Implemented using GLProcessor::Name as
+ * described in this class's comment. */
+ virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name(); }
+
+ /** Implemented using GLProcessor::GenKey as described in this class's comment. */
+ virtual void getGLProcessorKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker& bt,
+ const GrGLCaps& caps,
+ GrProcessorKeyBuilder* b) const SK_OVERRIDE {
+ GLProcessor::GenKey(processor, bt, caps, b);
+ }
+
+
+ /** Returns a new instance of the appropriate *GL* implementation class
+ for the given GrProcessor; caller is responsible for deleting
+ the object. */
+ virtual GrGLGeometryProcessor* createGLInstance(const GrGeometryProcessor& gp,
+ const GrBatchTracker& bt) const SK_OVERRIDE {
+ return SkNEW_ARGS(GLProcessor, (*this, gp, bt));
+ }
+
+ /** This class is a singleton. This function returns the single instance. */
+ static const GrBackendGeometryProcessorFactory& getInstance() {
+ static SkAlignedSTStorage<1, GrTBackendGeometryProcessorFactory> gInstanceMem;
+ static const GrTBackendGeometryProcessorFactory* gInstance;
+ if (!gInstance) {
+ gInstance = SkNEW_PLACEMENT(gInstanceMem.get(),
+ GrTBackendGeometryProcessorFactory);
+ }
+ return *gInstance;
+ }
protected:
GrTBackendGeometryProcessorFactory() {}
};
template <class ProcessorClass>
-class GrTBackendFragmentProcessorFactory
- : public GrTBackendProcessorFactory<ProcessorClass,
- GrBackendFragmentProcessorFactory,
- GrFragmentProcessor,
- GrGLFragmentProcessor> {
+class GrTBackendFragmentProcessorFactory : public GrBackendFragmentProcessorFactory {
+public:
+ typedef typename ProcessorClass::GLProcessor GLProcessor;
+
+ /** Returns a human-readable name for the processor. Implemented using GLProcessor::Name as
+ * described in this class's comment. */
+ virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name(); }
+
+ /** Implemented using GLProcessor::GenKey as described in this class's comment. */
+ virtual void getGLProcessorKey(const GrFragmentProcessor& processor,
+ const GrGLCaps& caps,
+ GrProcessorKeyBuilder* b) const SK_OVERRIDE {
+ GLProcessor::GenKey(processor, caps, b);
+ }
+
+ /** Returns a new instance of the appropriate *GL* implementation class
+ for the given GrProcessor; caller is responsible for deleting
+ the object. */
+ virtual GrGLFragmentProcessor* createGLInstance(const GrFragmentProcessor& gp) const SK_OVERRIDE {
+ return SkNEW_ARGS(GLProcessor, (*this, gp));
+ }
+
+ /** This class is a singleton. This function returns the single instance. */
+ static const GrBackendFragmentProcessorFactory& getInstance() {
+ static SkAlignedSTStorage<1, GrTBackendFragmentProcessorFactory> gInstanceMem;
+ static const GrTBackendFragmentProcessorFactory* gInstance;
+ if (!gInstance) {
+ gInstance = SkNEW_PLACEMENT(gInstanceMem.get(),
+ GrTBackendFragmentProcessorFactory);
+ }
+ return *gInstance;
+ }
protected:
GrTBackendFragmentProcessorFactory() {}
};
-
#endif
class GLProcessor : public GrGLGeometryProcessor {
public:
- GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+ GLProcessor(const GrBackendProcessorFactory& factory,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory) {}
virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
- static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*) {}
+ static inline void GenKey(const GrGeometryProcessor&,
+ const GrBatchTracker&,
+ const GrGLCaps&,
+ GrProcessorKeyBuilder*) {}
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE {}
private:
typedef GrGLGeometryProcessor INHERITED;
class GLProcessor : public GrGLGeometryProcessor {
public:
- GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+ GLProcessor(const GrBackendProcessorFactory& factory,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory) {}
virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
}
- static inline void GenKey(const GrProcessor& gp, const GrGLCaps&, GrProcessorKeyBuilder* b) {
+ static inline void GenKey(const GrGeometryProcessor& gp,
+ const GrBatchTracker&,
+ const GrGLCaps&,
+ GrProcessorKeyBuilder* b) {
const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
b->add32(def.fFlags);
}
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE {}
private:
typedef GrGLGeometryProcessor INHERITED;
#include "GrProcessor.h"
#include "GrShaderVar.h"
+/*
+ * A struct for tracking batching decisions. While this lives on GrOptState, it is managed
+ * entirely by the derived classes of the GP.
+ */
+class GrBatchTracker {
+public:
+ template <typename T> const T& cast() const {
+ SkASSERT(sizeof(T) <= kMaxSize);
+ return *reinterpret_cast<const T*>(fData);
+ }
+
+ template <typename T> T* cast() {
+ SkASSERT(sizeof(T) <= kMaxSize);
+ return reinterpret_cast<T*>(fData);
+ }
+
+ static const size_t kMaxSize = 32;
+
+private:
+ uint8_t fData[kMaxSize];
+};
+
+class GrOptDrawState;
+
/**
* A GrGeometryProcessor is used to perform computation in the vertex shader and
* add support for custom vertex attributes. A GrGemeotryProcessor is typically
return this->onIsEqual(that);
}
+ struct InitBT {
+ bool fOutputColor;
+ bool fOutputCoverage;
+ GrColor fColor;
+ GrColor fCoverage;
+ };
+
+ virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {}
+
// TODO this is a total hack until the gp can own whether or not it uses uniform
// color / coverage
bool hasVertexColor() const { return fHasVertexColor; }
}
this->setOutputStateInfo(drawState, blendOpt, caps);
-};
+
+ // let the GP init the batch tracker
+ if (drawState.hasGeometryProcessor()) {
+ GrGeometryProcessor::InitBT init;
+ init.fOutputColor = fDescInfo.fInputColorIsUsed;
+ init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed;
+ init.fColor = this->getColor();
+ init.fCoverage = this->getCoverage();
+ fGeometryProcessor->initBatchTracker(&fBatchTracker, init);
+ }
+}
void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
GrDrawState::BlendOpt blendOpt,
bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()); }
const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryProcessor.get(); }
+ const GrBatchTracker& getBatchTracker() const { return fBatchTracker; }
const GrXferProcessor* getXferProcessor() const { return fXferProcessor.get(); }
GrBlendCoeff fDstBlend;
uint32_t fFlags;
ProgramGeometryProcessor fGeometryProcessor;
+ GrBatchTracker fBatchTracker;
ProgramXferProcessor fXferProcessor;
FragmentStageArray fFragmentStages;
GrGpu::DrawType fDrawType;
class GLProcessor : public GrGLGeometryProcessor {
public:
- GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+ GLProcessor(const GrBackendProcessorFactory& factory,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory) {}
virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
- static void GenKey(const GrProcessor& processor, const GrGLCaps&,
+ static void GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const CircleEdgeEffect& circleEffect = processor.cast<CircleEdgeEffect>();
b->add32(circleEffect.isStroked());
}
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE {}
private:
typedef GrGLGeometryProcessor INHERITED;
class GLProcessor : public GrGLGeometryProcessor {
public:
- GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+ GLProcessor(const GrBackendProcessorFactory& factory,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory) {}
virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
- static void GenKey(const GrProcessor& processor, const GrGLCaps&,
+ static void GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const EllipseEdgeEffect& ellipseEffect = processor.cast<EllipseEdgeEffect>();
b->add32(ellipseEffect.isStroked());
}
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE {
}
private:
class GLProcessor : public GrGLGeometryProcessor {
public:
- GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+ GLProcessor(const GrBackendProcessorFactory& factory,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory) {}
virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
- static void GenKey(const GrProcessor& processor, const GrGLCaps&,
+ static void GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const DIEllipseEdgeEffect& ellipseEffect = processor.cast<DIEllipseEdgeEffect>();
b->add32(ellipseEffect.getMode());
}
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE {
}
private:
class GrGLConicEffect : public GrGLGeometryProcessor {
public:
- GrGLConicEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+ GrGLConicEffect(const GrBackendProcessorFactory&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&);
virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
- static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+ static inline void GenKey(const GrGeometryProcessor&,
+ const GrBatchTracker&,
+ const GrGLCaps&,
+ GrProcessorKeyBuilder*);
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE {}
private:
GrPrimitiveEdgeType fEdgeType;
};
GrGLConicEffect::GrGLConicEffect(const GrBackendProcessorFactory& factory,
- const GrProcessor& effect)
+ const GrGeometryProcessor& processor,
+ const GrBatchTracker& bt)
: INHERITED (factory) {
- const GrConicEffect& ce = effect.cast<GrConicEffect>();
+ const GrConicEffect& ce = processor.cast<GrConicEffect>();
fEdgeType = ce.getEdgeType();
}
fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
-void GrGLConicEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GrGLConicEffect::GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const GrConicEffect& ce = processor.cast<GrConicEffect>();
uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
class GrGLQuadEffect : public GrGLGeometryProcessor {
public:
- GrGLQuadEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+ GrGLQuadEffect(const GrBackendProcessorFactory&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&);
virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
- static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+ static inline void GenKey(const GrGeometryProcessor&,
+ const GrBatchTracker&,
+ const GrGLCaps&,
+ GrProcessorKeyBuilder*);
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE {}
private:
GrPrimitiveEdgeType fEdgeType;
};
GrGLQuadEffect::GrGLQuadEffect(const GrBackendProcessorFactory& factory,
- const GrProcessor& effect)
+ const GrGeometryProcessor& processor,
+ const GrBatchTracker& bt)
: INHERITED (factory) {
- const GrQuadEffect& ce = effect.cast<GrQuadEffect>();
+ const GrQuadEffect& ce = processor.cast<GrQuadEffect>();
fEdgeType = ce.getEdgeType();
}
fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
-void GrGLQuadEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GrGLQuadEffect::GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const GrQuadEffect& ce = processor.cast<GrQuadEffect>();
uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
class GrGLCubicEffect : public GrGLGeometryProcessor {
public:
- GrGLCubicEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+ GrGLCubicEffect(const GrBackendProcessorFactory&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&);
virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
- static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+ static inline void GenKey(const GrGeometryProcessor&,
+ const GrBatchTracker&,
+ const GrGLCaps&,
+ GrProcessorKeyBuilder*);
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE {}
private:
GrPrimitiveEdgeType fEdgeType;
};
GrGLCubicEffect::GrGLCubicEffect(const GrBackendProcessorFactory& factory,
- const GrProcessor& processor)
+ const GrGeometryProcessor& processor,
+ const GrBatchTracker&)
: INHERITED (factory) {
const GrCubicEffect& ce = processor.cast<GrCubicEffect>();
fEdgeType = ce.getEdgeType();
fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_str());
}
-void GrGLCubicEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GrGLCubicEffect::GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const GrCubicEffect& ce = processor.cast<GrCubicEffect>();
uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor {
public:
- GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory, const GrProcessor&)
+ GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory) {}
virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
}
virtual void setData(const GrGLProgramDataManager&,
- const GrProcessor&) SK_OVERRIDE {}
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE {}
- static inline void GenKey(const GrProcessor& proc, const GrGLCaps&,
+ static inline void GenKey(const GrGeometryProcessor& proc,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const GrCustomCoordsTextureEffect& gp = proc.cast<GrCustomCoordsTextureEffect>();
class GLDashingCircleEffect : public GrGLGeometryProcessor {
public:
- GLDashingCircleEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+ GLDashingCircleEffect(const GrBackendProcessorFactory&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&);
virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
- static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+ static inline void GenKey(const GrGeometryProcessor&,
+ const GrBatchTracker&,
+ const GrGLCaps&,
+ GrProcessorKeyBuilder*);
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE;
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE;
private:
GrGLProgramDataManager::UniformHandle fParamUniform;
};
GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendProcessorFactory& factory,
- const GrProcessor&)
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory) {
fPrevRadius = SK_ScalarMin;
fPrevCenterX = SK_ScalarMin;
fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
}
-void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman
- , const GrProcessor& processor) {
+void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman,
+ const GrGeometryProcessor& processor,
+ const GrBatchTracker&) {
const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
SkScalar radius = dce.getRadius();
SkScalar centerX = dce.getCenterX();
}
}
-void GLDashingCircleEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
b->add32(dce.getEdgeType());
class GLDashingLineEffect : public GrGLGeometryProcessor {
public:
- GLDashingLineEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+ GLDashingLineEffect(const GrBackendProcessorFactory&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&);
virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
- static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+ static inline void GenKey(const GrGeometryProcessor&,
+ const GrBatchTracker&,
+ const GrGLCaps&,
+ GrProcessorKeyBuilder*);
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE;
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) SK_OVERRIDE;
private:
GrGLProgramDataManager::UniformHandle fRectUniform;
};
GLDashingLineEffect::GLDashingLineEffect(const GrBackendProcessorFactory& factory,
- const GrProcessor&)
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory) {
fPrevRect.fLeft = SK_ScalarNaN;
fPrevIntervalLength = SK_ScalarMax;
}
void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman,
- const GrProcessor& processor) {
+ const GrGeometryProcessor& processor,
+ const GrBatchTracker&) {
const DashingLineEffect& de = processor.cast<DashingLineEffect>();
const SkRect& rect = de.getRect();
SkScalar intervalLength = de.getIntervalLength();
}
}
-void GLDashingLineEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GLDashingLineEffect::GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const DashingLineEffect& de = processor.cast<DashingLineEffect>();
b->add32(de.getEdgeType());
class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor {
public:
GrGLDistanceFieldTextureEffect(const GrBackendProcessorFactory& factory,
- const GrProcessor&)
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory)
, fTextureSize(SkISize::Make(-1,-1))
#ifdef SK_GAMMA_APPLY_TO_A8
}
virtual void setData(const GrGLProgramDataManager& pdman,
- const GrProcessor& effect) SK_OVERRIDE {
+ const GrGeometryProcessor& proc,
+ const GrBatchTracker&) SK_OVERRIDE {
SkASSERT(fTextureSizeUni.isValid());
- GrTexture* texture = effect.texture(0);
+ GrTexture* texture = proc.texture(0);
if (texture->width() != fTextureSize.width() ||
texture->height() != fTextureSize.height()) {
fTextureSize = SkISize::Make(texture->width(), texture->height());
}
#ifdef SK_GAMMA_APPLY_TO_A8
const GrDistanceFieldTextureEffect& dfTexEffect =
- effect.cast<GrDistanceFieldTextureEffect>();
+ proc.cast<GrDistanceFieldTextureEffect>();
float luminance = dfTexEffect.getLuminance();
if (luminance != fLuminance) {
pdman.set1f(fLuminanceUni, luminance);
#endif
}
- static inline void GenKey(const GrProcessor& processor, const GrGLCaps&,
+ static inline void GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const GrDistanceFieldTextureEffect& dfTexEffect =
processor.cast<GrDistanceFieldTextureEffect>();
class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor {
public:
GrGLDistanceFieldNoGammaTextureEffect(const GrBackendProcessorFactory& factory,
- const GrProcessor& effect)
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED(factory)
, fTextureSize(SkISize::Make(-1, -1)) {}
}
virtual void setData(const GrGLProgramDataManager& pdman,
- const GrProcessor& effect) SK_OVERRIDE {
+ const GrGeometryProcessor& proc,
+ const GrBatchTracker&) SK_OVERRIDE {
SkASSERT(fTextureSizeUni.isValid());
- GrTexture* texture = effect.texture(0);
+ GrTexture* texture = proc.texture(0);
if (texture->width() != fTextureSize.width() ||
texture->height() != fTextureSize.height()) {
fTextureSize = SkISize::Make(texture->width(), texture->height());
}
}
- static inline void GenKey(const GrProcessor& effect, const GrGLCaps&,
+ static inline void GenKey(const GrGeometryProcessor& proc,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const GrDistanceFieldNoGammaTextureEffect& dfTexEffect =
- effect.cast<GrDistanceFieldNoGammaTextureEffect>();
+ proc.cast<GrDistanceFieldNoGammaTextureEffect>();
b->add32(dfTexEffect.getFlags());
}
class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor {
public:
GrGLDistanceFieldLCDTextureEffect(const GrBackendProcessorFactory& factory,
- const GrProcessor&)
+ const GrGeometryProcessor&,
+ const GrBatchTracker&)
: INHERITED (factory)
, fTextureSize(SkISize::Make(-1,-1))
, fTextColor(GrColor_ILLEGAL) {}
}
virtual void setData(const GrGLProgramDataManager& pdman,
- const GrProcessor& processor) SK_OVERRIDE {
+ const GrGeometryProcessor& processor,
+ const GrBatchTracker&) SK_OVERRIDE {
SkASSERT(fTextureSizeUni.isValid());
SkASSERT(fTextColorUni.isValid());
}
}
- static inline void GenKey(const GrProcessor& processor, const GrGLCaps&,
+ static inline void GenKey(const GrGeometryProcessor& processor,
+ const GrBatchTracker&,
+ const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const GrDistanceFieldLCDTextureEffect& dfTexEffect =
processor.cast<GrDistanceFieldLCDTextureEffect>();
#include "GrGLProcessor.h"
+class GrBatchTracker;
class GrGLGPBuilder;
/**
struct EmitArgs {
EmitArgs(GrGLGPBuilder* pb,
const GrGeometryProcessor& gp,
+ const GrBatchTracker& bt,
const char* outputColor,
const char* outputCoverage,
const TextureSamplerArray& samplers)
: fPB(pb)
, fGP(gp)
+ , fBT(bt)
, fOutputColor(outputColor)
, fOutputCoverage(outputCoverage)
, fSamplers(samplers) {}
GrGLGPBuilder* fPB;
const GrGeometryProcessor& fGP;
+ const GrBatchTracker& fBT;
const char* fOutputColor;
const char* fOutputCoverage;
const TextureSamplerArray& fSamplers;
*/
virtual void emitCode(const EmitArgs&) = 0;
+ /** A GrGLGeometryProcessor instance can be reused with any GrGLGeometryProcessor that produces
+ the same stage key; this function reads data from a GrGLGeometryProcessor and uploads any
+ uniform variables required by the shaders created in emitCode(). The GrGeometryProcessor
+ parameter is guaranteed to be of the same type that created this GrGLGeometryProcessor and
+ to have an identical processor key as the one that created this GrGLGeometryProcessor. */
+ virtual void setData(const GrGLProgramDataManager&,
+ const GrGeometryProcessor&,
+ const GrBatchTracker&) = 0;
+
private:
typedef GrGLProcessor INHERITED;
};
that their GrGLProcessors would emit the same GLSL code.
The GrGLProcessor subclass must also have a constructor of the form:
- EffectSubclass::EffectSubclass(const GrBackendProcessorFactory&, const GrProcessor&)
+ ProcessorSubclass::ProcessorSubclass(const GrBackendProcessorFactory&, const GrProcessor&)
These objects are created by the factory object returned by the GrProcessor::getFactory().
*/
virtual ~GrGLProcessor() {}
- /** A GrGLProcessor instance can be reused with any GrProcessor that produces the same stage
- key; this function reads data from a GrProcessor and uploads any uniform variables required
- by the shaders created in emitCode(). The GrProcessor parameter is guaranteed to be of the
- same type that created this GrGLProcessor and to have an identical effect key as the one
- that created this GrGLProcessor. */
- virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) {}
-
const char* name() const { return fFactory.name(); }
static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*) {}
stages.
@param builder Interface used to emit code in the shaders.
- @param effect The effect that generated this program stage.
+ @param processor The processor that generated this program stage.
@param key The key that was computed by GenKey() from the generating GrProcessor.
@param outputColor A predefined vec4 in the FS in which the stage should place its output
color (or coverage).
NULL in which case the implied input is solid white (all ones).
TODO: Better system for communicating optimization info (e.g. input
color is solid white, trans black, known to be opaque, etc.) that allows
- the effect to communicate back similar known info about its output.
+ the processor to communicate back similar known info about its output.
@param samplers Contains one entry for each GrTextureAccess of the GrProcessor. These
can be passed to the builder to emit texture reads in the generated
code.
TODO this should take a struct
*/
virtual void emitCode(GrGLFPBuilder* builder,
- const GrFragmentProcessor& effect,
+ const GrFragmentProcessor&,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) = 0;
+ /** A GrGLFragmentProcessor instance can be reused with any GrFragmentProcessor that produces
+ the same stage key; this function reads data from a GrFragmentProcessor and uploads any
+ uniform variables required by the shaders created in emitCode(). The GrFragmentProcessor
+ parameter is guaranteed to be of the same type that created this GrGLFragmentProcessor and
+ to have an identical processor key as the one that created this GrGLFragmentProcessor. */
+ // TODO update this to pass in GrFragmentProcessor
+ virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) {}
+
private:
typedef GrGLProcessor INHERITED;
};
if (fGeometryProcessor.get()) {
SkASSERT(optState.hasGeometryProcessor());
const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
- fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp);
+ const GrBatchTracker& bt = optState.getBatchTracker();
+ fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp, bt);
this->bindTextures(fGeometryProcessor, gp);
}
this->setFragmentData(optState);
uint32_t transformKey,
uint32_t attribKey,
GrProcessorKeyBuilder* b) {
- const GrBackendProcessorFactory& factory = proc.getFactory();
- factory.getGLProcessorKey(proc, caps, b);
-
size_t processorKeySize = b->size();
uint32_t textureKey = gen_texture_key(proc, caps);
uint32_t classID = proc.getFactory().classID();
if (optState.hasGeometryProcessor()) {
const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
GrProcessorKeyBuilder b(&desc->fKey);
+ const GrBackendGeometryProcessorFactory& factory = gp.getFactory();
+ factory.getGLProcessorKey(gp, optState.getBatchTracker(), gpu->glCaps(), &b);
if (!get_meta_key(gp, gpu->glCaps(), 0, gen_attrib_key(gp), &b)) {
desc->fKey.reset();
return false;
for (int s = 0; s < optState.numFragmentStages(); ++s) {
const GrPendingFragmentStage& fps = optState.getFragmentStage(s);
+ const GrFragmentProcessor& fp = *fps.getProcessor();
GrProcessorKeyBuilder b(&desc->fKey);
+ const GrBackendFragmentProcessorFactory& factory = fp.getFactory();
+ factory.getGLProcessorKey(fp, gpu->glCaps(), &b);
if (!get_meta_key(*fps.getProcessor(), gpu->glCaps(),
gen_transform_key(fps, requiresLocalCoordAttrib), 0, &b)) {
desc->fKey.reset();
SkASSERT(!fGeometryProcessor);
fGeometryProcessor = SkNEW(GrGLInstalledGeoProc);
- fGeometryProcessor->fGLProc.reset(gp.getFactory().createGLInstance(gp));
+ const GrBatchTracker& bt = fOptState.getBatchTracker();
+ fGeometryProcessor->fGLProc.reset(gp.getFactory().createGLInstance(gp, bt));
SkSTArray<4, GrGLProcessor::TextureSampler> samplers(gp.numTextures());
this->emitSamplers(gp, &samplers, fGeometryProcessor);
- GrGLGeometryProcessor::EmitArgs args(this, gp, outColor, outCoverage, samplers);
+ GrGLGeometryProcessor::EmitArgs args(this, gp, bt, outColor, outCoverage, samplers);
fGeometryProcessor->fGLProc->emitCode(args);
// We have to check that effects and the code they emit are consistent, ie if an effect