Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| 11 #ifndef GrEffectStage_DEFINED | 11 #ifndef GrProcessorStage_DEFINED |
| 12 #define GrEffectStage_DEFINED | 12 #define GrProcessorStage_DEFINED |
| 13 | 13 |
| 14 #include "GrBackendEffectFactory.h" | 14 #include "GrBackendProcessorFactory.h" |
| 15 #include "GrCoordTransform.h" | 15 #include "GrCoordTransform.h" |
| 16 #include "GrEffect.h" | 16 #include "GrProcessor.h" |
| 17 #include "GrGeometryProcessor.h" | |
| 17 #include "GrProgramElementRef.h" | 18 #include "GrProgramElementRef.h" |
| 18 #include "SkMatrix.h" | 19 #include "SkMatrix.h" |
| 19 #include "SkShader.h" | 20 #include "SkShader.h" |
| 20 | 21 |
| 21 // TODO: Make two variations on this class: One for GrDrawState that only owns r egular refs | 22 // 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 // 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 // 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 // class from GrDrawState and GrOptDrawState called GrRODrawState and converting to GrOptDrawState |
| 25 // when draws are enqueued in the GrInOrderDrawBuffer. | 26 // when draws are enqueued in the GrInOrderDrawBuffer. |
| 26 class GrEffectStage { | 27 class GrProcessorStage { |
| 27 public: | 28 public: |
| 28 explicit GrEffectStage(const GrEffect* effect) | 29 explicit GrProcessorStage(const GrProcessor* proc) |
| 29 : fEffect(SkRef(effect)) { | 30 : fProc(SkRef(proc)) { |
| 30 fCoordChangeMatrixSet = false; | 31 fCoordChangeMatrixSet = false; |
| 31 } | 32 } |
| 32 | 33 |
| 33 GrEffectStage(const GrEffectStage& other) { | 34 GrProcessorStage(const GrProcessorStage& other) { |
| 34 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; | 35 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; |
| 35 if (other.fCoordChangeMatrixSet) { | 36 if (other.fCoordChangeMatrixSet) { |
| 36 fCoordChangeMatrix = other.fCoordChangeMatrix; | 37 fCoordChangeMatrix = other.fCoordChangeMatrix; |
| 37 } | 38 } |
| 38 fEffect.initAndRef(other.fEffect); | 39 fProc.initAndRef(other.fProc); |
| 39 } | 40 } |
| 40 | 41 |
| 41 static bool AreCompatible(const GrEffectStage& a, const GrEffectStage& b, | 42 static bool AreCompatible(const GrProcessorStage& a, const GrProcessorStage& b, |
| 42 bool usingExplicitLocalCoords) { | 43 bool usingExplicitLocalCoords) { |
| 43 SkASSERT(a.fEffect.get()); | 44 SkASSERT(a.fProc.get()); |
| 44 SkASSERT(b.fEffect.get()); | 45 SkASSERT(b.fProc.get()); |
| 45 | 46 |
| 46 if (!a.getEffect()->isEqual(*b.getEffect())) { | 47 if (!a.getProcessor()->isEqual(*b.getProcessor())) { |
| 47 return false; | 48 return false; |
| 48 } | 49 } |
| 49 | 50 |
| 50 // We always track the coord change matrix, but it has no effect when ex plicit local coords | 51 // We always track the coord change matrix, but it has no effect when ex plicit local coords |
| 51 // are used. | 52 // are used. |
| 52 if (usingExplicitLocalCoords) { | 53 if (usingExplicitLocalCoords) { |
| 53 return true; | 54 return true; |
| 54 } | 55 } |
| 55 | 56 |
| 56 if (a.fCoordChangeMatrixSet != b.fCoordChangeMatrixSet) { | 57 if (a.fCoordChangeMatrixSet != b.fCoordChangeMatrixSet) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 80 } | 81 } |
| 81 | 82 |
| 82 class SavedCoordChange { | 83 class SavedCoordChange { |
| 83 public: | 84 public: |
| 84 SkDEBUGCODE(SavedCoordChange() : fEffectUniqueID(SK_InvalidUniqueID) {}) | 85 SkDEBUGCODE(SavedCoordChange() : fEffectUniqueID(SK_InvalidUniqueID) {}) |
| 85 private: | 86 private: |
| 86 bool fCoordChangeMatrixSet; | 87 bool fCoordChangeMatrixSet; |
| 87 SkMatrix fCoordChangeMatrix; | 88 SkMatrix fCoordChangeMatrix; |
| 88 SkDEBUGCODE(mutable uint32_t fEffectUniqueID;) | 89 SkDEBUGCODE(mutable uint32_t fEffectUniqueID;) |
| 89 | 90 |
| 90 friend class GrEffectStage; | 91 friend class GrProcessorStage; |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 /** | 94 /** |
| 94 * This gets the current coordinate system change. It is the accumulation of | 95 * This gets the current coordinate system change. It is the accumulation of |
| 95 * localCoordChange calls since the effect was installed. It is used when th en caller | 96 * localCoordChange calls since the effect was installed. It is used when th en caller |
| 96 * wants to temporarily change the source geometry coord system, draw someth ing, and then | 97 * wants to temporarily change the source geometry coord system, draw someth ing, and then |
| 97 * restore the previous coord system (e.g. temporarily draw in device coords ). | 98 * restore the previous coord system (e.g. temporarily draw in device coords ). |
| 98 */ | 99 */ |
| 99 void saveCoordChange(SavedCoordChange* savedCoordChange) const { | 100 void saveCoordChange(SavedCoordChange* savedCoordChange) const { |
| 100 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet; | 101 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet; |
| 101 if (fCoordChangeMatrixSet) { | 102 if (fCoordChangeMatrixSet) { |
| 102 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; | 103 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; |
| 103 } | 104 } |
| 104 SkASSERT(SK_InvalidUniqueID == savedCoordChange->fEffectUniqueID); | 105 SkASSERT(SK_InvalidUniqueID == savedCoordChange->fEffectUniqueID); |
| 105 SkDEBUGCODE(savedCoordChange->fEffectUniqueID = fEffect->getUniqueID();) | 106 SkDEBUGCODE(savedCoordChange->fEffectUniqueID = fProc->getUniqueID();) |
| 106 } | 107 } |
| 107 | 108 |
| 108 /** | 109 /** |
| 109 * This balances the saveCoordChange call. | 110 * This balances the saveCoordChange call. |
| 110 */ | 111 */ |
| 111 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { | 112 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { |
| 112 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; | 113 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; |
| 113 if (fCoordChangeMatrixSet) { | 114 if (fCoordChangeMatrixSet) { |
| 114 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; | 115 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; |
| 115 } | 116 } |
| 116 SkASSERT(savedCoordChange.fEffectUniqueID == fEffect->getUniqueID()); | 117 SkASSERT(savedCoordChange.fEffectUniqueID == fProc->getUniqueID()); |
| 117 SkDEBUGCODE(savedCoordChange.fEffectUniqueID = SK_InvalidUniqueID); | 118 SkDEBUGCODE(savedCoordChange.fEffectUniqueID = SK_InvalidUniqueID); |
| 118 } | 119 } |
| 119 | 120 |
| 120 /** | 121 /** |
| 121 * Gets the matrix representing all changes of coordinate system since the G rEffect was | 122 * Gets the matrix representing all changes of coordinate system since the G rProcessor was |
| 122 * installed in the stage. | 123 * installed in the stage. |
| 123 */ | 124 */ |
| 124 const SkMatrix& getCoordChangeMatrix() const { | 125 const SkMatrix& getCoordChangeMatrix() const { |
| 125 if (fCoordChangeMatrixSet) { | 126 if (fCoordChangeMatrixSet) { |
| 126 return fCoordChangeMatrix; | 127 return fCoordChangeMatrix; |
| 127 } else { | 128 } else { |
| 128 return SkMatrix::I(); | 129 return SkMatrix::I(); |
| 129 } | 130 } |
| 130 } | 131 } |
| 131 | 132 |
| 132 bool isPerspectiveCoordTransform(int matrixIndex, bool useExplicitLocalCoord s) const { | 133 bool isPerspectiveCoordTransform(int matrixIndex, bool useExplicitLocalCoord s) const { |
| 133 const GrCoordTransform& coordTransform = this->getEffect()->coordTransfo rm(matrixIndex); | 134 const GrCoordTransform& coordTransform = this->getProcessor()->coordTran sform(matrixIndex); |
| 134 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType(); | 135 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType(); |
| 135 SkMatrix::TypeMask type1 = SkMatrix::kIdentity_Mask; | 136 SkMatrix::TypeMask type1 = SkMatrix::kIdentity_Mask; |
| 136 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 137 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
| 137 type1 = useExplicitLocalCoords ? | 138 type1 = useExplicitLocalCoords ? |
| 138 SkMatrix::kIdentity_Mask : this->getCoordChangeMatrix().getTyp e(); | 139 SkMatrix::kIdentity_Mask : this->getCoordChangeMatrix().getTyp e(); |
| 139 } | 140 } |
| 140 | 141 |
| 141 int combinedTypes = type0 | type1; | 142 int combinedTypes = type0 | type1; |
| 142 if (SkMatrix::kPerspective_Mask & combinedTypes) { | 143 if (SkMatrix::kPerspective_Mask & combinedTypes) { |
| 143 return true; | 144 return true; |
| 144 } else { | 145 } else { |
| 145 return false; | 146 return false; |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 | 149 |
| 149 const GrEffect* getEffect() const { return fEffect.get(); } | 150 const GrProcessor* getProcessor() const { return fProc.get(); } |
| 150 | 151 |
| 151 void convertToPendingExec() { fEffect.convertToPendingExec(); } | 152 void convertToPendingExec() { fProc.convertToPendingExec(); } |
| 152 | 153 |
| 153 private: | 154 private: |
| 154 bool fCoordChangeMatrixSet; | 155 bool fCoordChangeMatrixSet; |
| 155 SkMatrix fCoordChangeMatrix; | 156 SkMatrix fCoordChangeMatrix; |
| 156 GrProgramElementRef<const GrEffect> fEffect; | 157 GrProgramElementRef<const GrProcessor> fProc; |
| 158 }; | |
| 159 | |
| 160 class GrFragmentStage : public GrProcessorStage { | |
| 161 public: | |
| 162 GrFragmentStage(const GrFragmentProcessor* fp) : GrProcessorStage(fp) {} | |
| 163 | |
| 164 const GrFragmentProcessor* getFragmentProcessor() const { | |
| 165 return static_cast<const GrFragmentProcessor*>(this->getProcessor()); | |
|
bsalomon
2014/09/22 14:56:38
Is the base class ever useful? I wonder if we shou
joshua.litt
2014/09/22 18:14:44
Well, its useful a bit right now. Let me further
| |
| 166 } | |
| 167 }; | |
| 168 | |
| 169 class GrGeometryStage : public GrProcessorStage { | |
| 170 public: | |
| 171 GrGeometryStage(const GrGeometryProcessor* gp) : GrProcessorStage(gp) {} | |
| 172 | |
| 173 const GrGeometryProcessor* getGeometryProcessor() const { | |
| 174 return static_cast<const GrGeometryProcessor*>(this->getProcessor()); | |
| 175 } | |
| 157 }; | 176 }; |
| 158 | 177 |
| 159 #endif | 178 #endif |
| OLD | NEW |