| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrFragmentStage_DEFINED | 8 #ifndef GrFragmentStage_DEFINED |
| 9 #define GrFragmentStage_DEFINED | 9 #define GrFragmentStage_DEFINED |
| 10 | 10 |
| 11 #include "GrFragmentProcessor.h" | 11 #include "GrFragmentProcessor.h" |
| 12 #include "SkMatrix.h" | |
| 13 | 12 |
| 14 /** | 13 /** |
| 15 * Wraps a GrFragmentProcessor. It also contains a coord change matrix. This mat
rix should be | 14 * Wraps a GrFragmentProcessor, basically a copyable SkAutoTUnref |
| 16 * concat'ed with all the processor's coord transforms that apply to local coord
s, unless | |
| 17 * explicit local coords are provided with the draw. | |
| 18 */ | 15 */ |
| 19 class GrFragmentStage { | 16 class GrFragmentStage { |
| 20 public: | 17 public: |
| 21 explicit GrFragmentStage(const GrFragmentProcessor* proc) | 18 explicit GrFragmentStage(const GrFragmentProcessor* proc) : fProc(SkRef(proc
)) {} |
| 22 : fProc(SkRef(proc)) { | 19 |
| 23 fCoordChangeMatrixSet = false; | 20 GrFragmentStage(const GrFragmentStage& other) { fProc.reset(SkRef(other.fPro
c.get())); } |
| 21 |
| 22 const GrFragmentProcessor* processor() const { return fProc.get(); } |
| 23 |
| 24 bool operator==(const GrFragmentStage& that) const { |
| 25 return this->processor() == that.processor(); |
| 24 } | 26 } |
| 25 | 27 |
| 26 GrFragmentStage(const GrFragmentStage& other) { | 28 bool operator!=(const GrFragmentStage& that) const { return !(*this == that)
; } |
| 27 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; | |
| 28 if (other.fCoordChangeMatrixSet) { | |
| 29 fCoordChangeMatrix = other.fCoordChangeMatrix; | |
| 30 } | |
| 31 fProc.reset(SkRef(other.fProc.get())); | |
| 32 } | |
| 33 | |
| 34 static bool AreCompatible(const GrFragmentStage& a, const GrFragmentStage& b
, | |
| 35 bool usingExplicitLocalCoords) { | |
| 36 SkASSERT(a.fProc.get()); | |
| 37 SkASSERT(b.fProc.get()); | |
| 38 | |
| 39 if (!a.getProcessor()->isEqual(*b.getProcessor())) { | |
| 40 return false; | |
| 41 } | |
| 42 | |
| 43 // We always track the coord change matrix, but it has no effect when ex
plicit local coords | |
| 44 // are used. | |
| 45 if (usingExplicitLocalCoords) { | |
| 46 return true; | |
| 47 } | |
| 48 | |
| 49 if (a.fCoordChangeMatrixSet != b.fCoordChangeMatrixSet) { | |
| 50 return false; | |
| 51 } | |
| 52 | |
| 53 if (!a.fCoordChangeMatrixSet) { | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 return a.fCoordChangeMatrix == b.fCoordChangeMatrix; | |
| 58 } | |
| 59 | |
| 60 /** | |
| 61 * This is called when the coordinate system in which the geometry is specif
ied will change. | |
| 62 * | |
| 63 * @param matrix The transformation from the old coord system in which ge
ometry is specified | |
| 64 * to the new one from which it will actually be drawn. | |
| 65 */ | |
| 66 void localCoordChange(const SkMatrix& matrix) { | |
| 67 if (fCoordChangeMatrixSet) { | |
| 68 fCoordChangeMatrix.preConcat(matrix); | |
| 69 } else { | |
| 70 fCoordChangeMatrixSet = true; | |
| 71 fCoordChangeMatrix = matrix; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 class SavedCoordChange { | |
| 76 public: | |
| 77 SkDEBUGCODE(SavedCoordChange() : fEffectUniqueID(SK_InvalidUniqueID) {}) | |
| 78 private: | |
| 79 bool fCoordChangeMatrixSet; | |
| 80 SkMatrix fCoordChangeMatrix; | |
| 81 SkDEBUGCODE(mutable uint32_t fEffectUniqueID;) | |
| 82 | |
| 83 friend class GrFragmentStage; | |
| 84 }; | |
| 85 | |
| 86 /** | |
| 87 * This gets the current coordinate system change. It is the accumulation of | |
| 88 * localCoordChange calls since the effect was installed. It is used when th
en caller | |
| 89 * wants to temporarily change the source geometry coord system, draw someth
ing, and then | |
| 90 * restore the previous coord system (e.g. temporarily draw in device coords
). | |
| 91 */ | |
| 92 void saveCoordChange(SavedCoordChange* savedCoordChange) const { | |
| 93 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet; | |
| 94 if (fCoordChangeMatrixSet) { | |
| 95 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; | |
| 96 } | |
| 97 SkASSERT(SK_InvalidUniqueID == savedCoordChange->fEffectUniqueID); | |
| 98 SkDEBUGCODE(savedCoordChange->fEffectUniqueID = fProc->getUniqueID();) | |
| 99 } | |
| 100 | |
| 101 /** | |
| 102 * This balances the saveCoordChange call. | |
| 103 */ | |
| 104 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { | |
| 105 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; | |
| 106 if (fCoordChangeMatrixSet) { | |
| 107 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; | |
| 108 } | |
| 109 SkASSERT(savedCoordChange.fEffectUniqueID == fProc->getUniqueID()); | |
| 110 SkDEBUGCODE(savedCoordChange.fEffectUniqueID = SK_InvalidUniqueID); | |
| 111 } | |
| 112 | |
| 113 /** | |
| 114 * Gets the matrix representing all changes of coordinate system since the G
rProcessor was | |
| 115 * installed in the stage. | |
| 116 */ | |
| 117 const SkMatrix& getCoordChangeMatrix() const { | |
| 118 if (fCoordChangeMatrixSet) { | |
| 119 return fCoordChangeMatrix; | |
| 120 } else { | |
| 121 return SkMatrix::I(); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 const GrFragmentProcessor* getProcessor() const { return fProc.get(); } | |
| 126 | 29 |
| 127 protected: | 30 protected: |
| 128 bool fCoordChangeMatrixSet; | |
| 129 SkMatrix fCoordChangeMatrix; | |
| 130 SkAutoTUnref<const GrFragmentProcessor> fProc; | 31 SkAutoTUnref<const GrFragmentProcessor> fProc; |
| 131 }; | 32 }; |
| 132 | 33 |
| 133 #endif | 34 #endif |
| OLD | NEW |