michael@0: michael@0: #ifndef GrDrawEffect_DEFINED michael@0: #define GrDrawEffect_DEFINED michael@0: michael@0: #include "GrEffectStage.h" michael@0: michael@0: /** michael@0: * This class is used to communicate the particular GrEffect used in a draw to the backend-specific michael@0: * effect subclass (e.g. GrGLEffect). It is used to by the backend-specific class to generate a michael@0: * cache key for the effect, generate code on a program cache miss, and to upload uniform values to michael@0: * the program. michael@0: * In addition to the effect, it also communicates any changes between the relationship between michael@0: * the view matrix and local coordinate system since the effect was installed in its GrDrawState. michael@0: * The typical use case is that sometime after an effect was installed a decision was made to draw michael@0: * in device coordinates (i.e. use an identity view-matrix). In such a case the GrDrawEffect's michael@0: * coord-change-matrix would be the inverse of the view matrix that was set when the effect was michael@0: * installed. michael@0: */ michael@0: class GrDrawEffect { michael@0: public: michael@0: GrDrawEffect(const GrEffectStage& stage, bool explicitLocalCoords) michael@0: : fEffectStage(&stage) michael@0: , fExplicitLocalCoords(explicitLocalCoords) { michael@0: SkASSERT(NULL != fEffectStage); michael@0: SkASSERT(NULL != fEffectStage->getEffect()); michael@0: } michael@0: const GrEffectRef* effect() const { return fEffectStage->getEffect(); } michael@0: michael@0: template michael@0: const T& castEffect() const { return *static_cast(this->effect()->get()); } michael@0: michael@0: const SkMatrix& getCoordChangeMatrix() const { michael@0: if (fExplicitLocalCoords) { michael@0: return SkMatrix::I(); michael@0: } else { michael@0: return fEffectStage->getCoordChangeMatrix(); michael@0: } michael@0: } michael@0: michael@0: bool programHasExplicitLocalCoords() const { return fExplicitLocalCoords; } michael@0: michael@0: const int* getVertexAttribIndices() const { return fEffectStage->getVertexAttribIndices(); } michael@0: int getVertexAttribIndexCount() const { return fEffectStage->getVertexAttribIndexCount(); } michael@0: michael@0: private: michael@0: const GrEffectStage* fEffectStage; michael@0: bool fExplicitLocalCoords; michael@0: }; michael@0: michael@0: #endif