bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 1 | |
| 2 | #ifndef GrDrawEffect_DEFINED |
| 3 | #define GrDrawEffect_DEFINED |
| 4 | |
| 5 | #include "GrEffectStage.h" |
| 6 | |
| 7 | /** |
| 8 | * This class is used to communicate the particular GrEffect used in a draw to the backend-specific |
| 9 | * effect subclass (e.g. GrGLEffect). It is used to by the backend-specific class to generate a |
| 10 | * cache key for the effect, generate code on a program cache miss, and to upload uniform values to |
| 11 | * the program. |
| 12 | * In addition to the effect, it also communicates any changes between the relationship between |
| 13 | * the view matrix and local coordinate system since the effect was installed in its GrDrawState. |
| 14 | * The typical use case is that sometime after an effect was installed a decision was made to draw |
| 15 | * in device coordinates (i.e. use an identity view-matrix). In such a case the GrDrawEffect's |
| 16 | * coord-change-matrix would be the inverse of the view matrix that was set when the effect was |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 17 | * installed. |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 18 | */ |
| 19 | class GrDrawEffect { |
| 20 | public: |
| 21 | GrDrawEffect(const GrEffectStage& stage, bool explicitLocalCoords) |
| 22 | : fEffectStage(&stage) |
| 23 | , fExplicitLocalCoords(explicitLocalCoords) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 24 | SkASSERT(NULL != fEffectStage); |
| 25 | SkASSERT(NULL != fEffectStage->getEffect()); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 26 | } |
bsalomon | f99f884 | 2014-07-07 11:54:23 -0700 | [diff] [blame] | 27 | const GrEffect* effect() const { return fEffectStage->getEffect(); } |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 28 | |
| 29 | template <typename T> |
bsalomon | f99f884 | 2014-07-07 11:54:23 -0700 | [diff] [blame] | 30 | const T& castEffect() const { return *static_cast<const T*>(this->effect()); } |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 31 | |
| 32 | const SkMatrix& getCoordChangeMatrix() const { |
| 33 | if (fExplicitLocalCoords) { |
| 34 | return SkMatrix::I(); |
| 35 | } else { |
| 36 | return fEffectStage->getCoordChangeMatrix(); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | bool programHasExplicitLocalCoords() const { return fExplicitLocalCoords; } |
| 41 | |
| 42 | const int* getVertexAttribIndices() const { return fEffectStage->getVertexAttribIndices(); } |
| 43 | int getVertexAttribIndexCount() const { return fEffectStage->getVertexAttribIndexCount(); } |
| 44 | |
| 45 | private: |
| 46 | const GrEffectStage* fEffectStage; |
| 47 | bool fExplicitLocalCoords; |
| 48 | }; |
| 49 | |
| 50 | #endif |