epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrSamplerState_DEFINED |
| 12 | #define GrSamplerState_DEFINED |
| 13 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 14 | #include "GrCustomStage.h" |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 15 | #include "GrMatrix.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 16 | #include "GrTypes.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 18 | #include "SkShader.h" |
| 19 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | class GrSamplerState { |
| 21 | public: |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 6aab8e3 | 2011-06-21 20:32:12 +0000 | [diff] [blame] | 23 | GrSamplerState() |
tomhudson@google.com | 898e7b5 | 2012-06-01 20:42:15 +0000 | [diff] [blame] | 24 | : fCustomStage (NULL) { |
tomhudson@google.com | 194de08 | 2012-05-31 20:35:27 +0000 | [diff] [blame] | 25 | memset(this, 0, sizeof(GrSamplerState)); |
bsalomon@google.com | 9791291 | 2011-12-06 16:30:36 +0000 | [diff] [blame] | 26 | this->reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | } |
| 28 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 29 | ~GrSamplerState() { |
| 30 | GrSafeUnref(fCustomStage); |
| 31 | } |
| 32 | |
tomhudson@google.com | 02b1ea2 | 2012-04-30 20:19:07 +0000 | [diff] [blame] | 33 | bool operator ==(const GrSamplerState& s) const { |
tomhudson@google.com | b88bbd2 | 2012-05-01 12:48:07 +0000 | [diff] [blame] | 34 | /* We must be bit-identical as far as the CustomStage; |
| 35 | there may be multiple CustomStages that will produce |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 36 | the same shader code and so are equivalent. |
tomhudson@google.com | b88bbd2 | 2012-05-01 12:48:07 +0000 | [diff] [blame] | 37 | Can't take the address of fWrapX because it's :8 */ |
| 38 | int bitwiseRegion = (intptr_t) &fCustomStage - (intptr_t) this; |
| 39 | GrAssert(sizeof(GrSamplerState) == |
| 40 | bitwiseRegion + sizeof(fCustomStage)); |
| 41 | return !memcmp(this, &s, bitwiseRegion) && |
| 42 | ((fCustomStage == s.fCustomStage) || |
| 43 | (fCustomStage && s.fCustomStage && |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 44 | (fCustomStage->getFactory() == |
| 45 | s.fCustomStage->getFactory()) && |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 46 | fCustomStage->isEqual(*s.fCustomStage))); |
tomhudson@google.com | 02b1ea2 | 2012-04-30 20:19:07 +0000 | [diff] [blame] | 47 | } |
| 48 | bool operator !=(const GrSamplerState& s) const { return !(*this == s); } |
| 49 | |
tomhudson@google.com | 0bdbed3 | 2012-06-01 19:50:02 +0000 | [diff] [blame] | 50 | GrSamplerState& operator =(const GrSamplerState& s) { |
tomhudson@google.com | 1117559 | 2012-05-31 14:23:28 +0000 | [diff] [blame] | 51 | fMatrix = s.fMatrix; |
tomhudson@google.com | 50e4ce0 | 2012-06-19 15:27:50 +0000 | [diff] [blame] | 52 | GrSafeAssign(fCustomStage, s.fCustomStage); |
tomhudson@google.com | 02b1ea2 | 2012-04-30 20:19:07 +0000 | [diff] [blame] | 53 | return *this; |
| 54 | } |
| 55 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 56 | const GrMatrix& getMatrix() const { return fMatrix; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 57 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 58 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 59 | * Multiplies the current sampler matrix a matrix |
| 60 | * |
| 61 | * After this call M' = M*m where M is the old matrix, m is the parameter |
| 62 | * to this function, and M' is the new matrix. (We consider points to |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 63 | * be column vectors so tex cood vector t is transformed by matrix X as |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 64 | * t' = X*t.) |
| 65 | * |
| 66 | * @param matrix the matrix used to modify the matrix. |
| 67 | */ |
| 68 | void preConcatMatrix(const GrMatrix& matrix) { fMatrix.preConcat(matrix); } |
| 69 | |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 70 | /** |
| 71 | * Do not call this function. It will be removed soon. |
| 72 | */ |
| 73 | void setMatrixDeprecated(const GrMatrix& matrix) { fMatrix = matrix; } |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 74 | |
bsalomon@google.com | aa814fe | 2011-12-12 18:45:07 +0000 | [diff] [blame] | 75 | void reset() { |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 76 | fMatrix.reset(); |
| 77 | GrSafeSetNull(fCustomStage); |
bsalomon@google.com | 1e266f8 | 2011-12-12 16:11:33 +0000 | [diff] [blame] | 78 | } |
bsalomon@google.com | 9791291 | 2011-12-06 16:30:36 +0000 | [diff] [blame] | 79 | |
tomhudson@google.com | 83e5eb8 | 2012-06-04 19:58:30 +0000 | [diff] [blame] | 80 | GrCustomStage* setCustomStage(GrCustomStage* stage) { |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 81 | GrSafeAssign(fCustomStage, stage); |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 82 | fMatrix.reset(); |
tomhudson@google.com | 83e5eb8 | 2012-06-04 19:58:30 +0000 | [diff] [blame] | 83 | return stage; |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 84 | } |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 85 | |
| 86 | GrCustomStage* setCustomStage(GrCustomStage* stage, const GrMatrix& matrix) { |
| 87 | GrSafeAssign(fCustomStage, stage); |
| 88 | fMatrix = matrix; |
| 89 | return stage; |
| 90 | } |
| 91 | |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 92 | const GrCustomStage* getCustomStage() const { return fCustomStage; } |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 93 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | private: |
tomhudson@google.com | 898e7b5 | 2012-06-01 20:42:15 +0000 | [diff] [blame] | 95 | GrMatrix fMatrix; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 96 | |
tomhudson@google.com | 02b1ea2 | 2012-04-30 20:19:07 +0000 | [diff] [blame] | 97 | GrCustomStage* fCustomStage; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | #endif |
| 101 | |