| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 8 #ifndef GrFragmentStage_DEFINED |
| 9 #define GrFragmentStage_DEFINED |
| 9 | 10 |
| 11 #include "GrFragmentProcessor.h" |
| 12 #include "SkMatrix.h" |
| 10 | 13 |
| 11 #ifndef GrProcessorStage_DEFINED | 14 /** |
| 12 #define GrProcessorStage_DEFINED | 15 * Wraps a GrFragmentProcessor. It also contains a coord change matrix. This mat
rix should be |
| 13 | 16 * concat'ed with all the processor's coord transforms that apply to local coord
s, unless |
| 14 #include "GrBackendProcessorFactory.h" | 17 * explicit local coords are provided with the draw. |
| 15 #include "GrCoordTransform.h" | 18 */ |
| 16 #include "GrFragmentProcessor.h" | |
| 17 #include "GrProgramElementRef.h" | |
| 18 #include "SkMatrix.h" | |
| 19 #include "SkShader.h" | |
| 20 | |
| 21 // TODO: Make two variations on this class: One for GrDrawState that only owns r
egular refs | |
| 22 // and supports compatibility checks and changing local coords. The second is fo
r GrOptDrawState, | |
| 23 // is immutable, and only owns pending execution refs. This requries removing th
e common base | |
| 24 // class from GrDrawState and GrOptDrawState called GrRODrawState and converting
to GrOptDrawState | |
| 25 // when draws are enqueued in the GrInOrderDrawBuffer. | |
| 26 class GrFragmentStage { | 19 class GrFragmentStage { |
| 27 public: | 20 public: |
| 28 explicit GrFragmentStage(const GrFragmentProcessor* proc) | 21 explicit GrFragmentStage(const GrFragmentProcessor* proc) |
| 29 : fProc(SkRef(proc)) { | 22 : fProc(SkRef(proc)) { |
| 30 fCoordChangeMatrixSet = false; | 23 fCoordChangeMatrixSet = false; |
| 31 } | 24 } |
| 32 | 25 |
| 33 GrFragmentStage(const GrFragmentStage& other) { | 26 GrFragmentStage(const GrFragmentStage& other) { |
| 34 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; | 27 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; |
| 35 if (other.fCoordChangeMatrixSet) { | 28 if (other.fCoordChangeMatrixSet) { |
| 36 fCoordChangeMatrix = other.fCoordChangeMatrix; | 29 fCoordChangeMatrix = other.fCoordChangeMatrix; |
| 37 } | 30 } |
| 38 fProc.initAndRef(other.fProc); | 31 fProc.reset(SkRef(other.fProc.get())); |
| 39 } | 32 } |
| 40 | 33 |
| 41 static bool AreCompatible(const GrFragmentStage& a, const GrFragmentStage& b
, | 34 static bool AreCompatible(const GrFragmentStage& a, const GrFragmentStage& b
, |
| 42 bool usingExplicitLocalCoords) { | 35 bool usingExplicitLocalCoords) { |
| 43 SkASSERT(a.fProc.get()); | 36 SkASSERT(a.fProc.get()); |
| 44 SkASSERT(b.fProc.get()); | 37 SkASSERT(b.fProc.get()); |
| 45 | 38 |
| 46 if (!a.getProcessor()->isEqual(*b.getProcessor())) { | 39 if (!a.getProcessor()->isEqual(*b.getProcessor())) { |
| 47 return false; | 40 return false; |
| 48 } | 41 } |
| 49 | 42 |
| 50 // We always track the coord change matrix, but it has no effect when ex
plicit local coords | 43 // We always track the coord change matrix, but it has no effect when ex
plicit local coords |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 * installed in the stage. | 115 * installed in the stage. |
| 123 */ | 116 */ |
| 124 const SkMatrix& getCoordChangeMatrix() const { | 117 const SkMatrix& getCoordChangeMatrix() const { |
| 125 if (fCoordChangeMatrixSet) { | 118 if (fCoordChangeMatrixSet) { |
| 126 return fCoordChangeMatrix; | 119 return fCoordChangeMatrix; |
| 127 } else { | 120 } else { |
| 128 return SkMatrix::I(); | 121 return SkMatrix::I(); |
| 129 } | 122 } |
| 130 } | 123 } |
| 131 | 124 |
| 132 bool isPerspectiveCoordTransform(int matrixIndex, bool useExplicitLocalCoord
s) const { | |
| 133 const GrCoordTransform& coordTransform = this->getProcessor()->coordTran
sform(matrixIndex); | |
| 134 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType(); | |
| 135 SkMatrix::TypeMask type1 = SkMatrix::kIdentity_Mask; | |
| 136 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | |
| 137 type1 = useExplicitLocalCoords ? | |
| 138 SkMatrix::kIdentity_Mask : this->getCoordChangeMatrix().getTyp
e(); | |
| 139 } | |
| 140 | |
| 141 int combinedTypes = type0 | type1; | |
| 142 if (SkMatrix::kPerspective_Mask & combinedTypes) { | |
| 143 return true; | |
| 144 } else { | |
| 145 return false; | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 const char* name() const { return fProc->name(); } | |
| 150 | |
| 151 const GrFragmentProcessor* getProcessor() const { return fProc.get(); } | 125 const GrFragmentProcessor* getProcessor() const { return fProc.get(); } |
| 152 | 126 |
| 153 void convertToPendingExec() { fProc.convertToPendingExec(); } | |
| 154 | |
| 155 protected: | 127 protected: |
| 156 bool fCoordChangeMatrixSet; | 128 bool fCoordChangeMatrixSet; |
| 157 SkMatrix fCoordChangeMatrix; | 129 SkMatrix fCoordChangeMatrix; |
| 158 GrProgramElementRef<const GrFragmentProcessor> fProc; | 130 SkAutoTUnref<const GrFragmentProcessor> fProc; |
| 159 }; | 131 }; |
| 160 | 132 |
| 161 #endif | 133 #endif |
| OLD | NEW |