| 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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 if (NULL == fEffectRef) { | 35 if (NULL == fEffectRef) { |
| 36 return NULL == other.fEffectRef; | 36 return NULL == other.fEffectRef; |
| 37 } else if (NULL == other.fEffectRef) { | 37 } else if (NULL == other.fEffectRef) { |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 | 40 |
| 41 if (!(*this->getEffect())->isEqual(*other.getEffect())) { | 41 if (!(*this->getEffect())->isEqual(*other.getEffect())) { |
| 42 return false; | 42 return false; |
| 43 } | 43 } |
| 44 | 44 |
| 45 if (fCoordChangeMatrixSet != other.fCoordChangeMatrixSet) { |
| 46 return false; |
| 47 } |
| 48 |
| 49 if (!fCoordChangeMatrixSet) { |
| 50 return true; |
| 51 } |
| 52 |
| 45 return fCoordChangeMatrix == other.fCoordChangeMatrix; | 53 return fCoordChangeMatrix == other.fCoordChangeMatrix; |
| 46 } | 54 } |
| 47 | 55 |
| 48 bool operator !=(const GrEffectStage& s) const { return !(*this == s); } | 56 bool operator !=(const GrEffectStage& s) const { return !(*this == s); } |
| 49 | 57 |
| 50 GrEffectStage& operator =(const GrEffectStage& other) { | 58 GrEffectStage& operator =(const GrEffectStage& other) { |
| 51 GrSafeAssign(fEffectRef, other.fEffectRef); | 59 GrSafeAssign(fEffectRef, other.fEffectRef); |
| 52 if (NULL != fEffectRef) { | 60 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; |
| 61 if (NULL != fEffectRef && fCoordChangeMatrixSet) { |
| 53 fCoordChangeMatrix = other.fCoordChangeMatrix; | 62 fCoordChangeMatrix = other.fCoordChangeMatrix; |
| 54 } | 63 } |
| 55 return *this; | 64 return *this; |
| 56 } | 65 } |
| 57 | 66 |
| 58 /** | 67 /** |
| 59 * This is called when the coordinate system in which the geometry is specif
ied will change. | 68 * This is called when the coordinate system in which the geometry is specif
ied will change. |
| 60 * | 69 * |
| 61 * @param matrix The transformation from the old coord system in which ge
ometry is specified | 70 * @param matrix The transformation from the old coord system in which ge
ometry is specified |
| 62 * to the new one from which it will actually be drawn. | 71 * to the new one from which it will actually be drawn. |
| 63 */ | 72 */ |
| 64 void localCoordChange(const SkMatrix& matrix) { fCoordChangeMatrix.preConcat
(matrix); } | 73 void localCoordChange(const SkMatrix& matrix) { |
| 74 if (fCoordChangeMatrixSet) { |
| 75 fCoordChangeMatrix.preConcat(matrix); |
| 76 } else { |
| 77 fCoordChangeMatrixSet = true; |
| 78 fCoordChangeMatrix = matrix; |
| 79 } |
| 80 } |
| 65 | 81 |
| 66 class SavedCoordChange { | 82 class SavedCoordChange { |
| 67 private: | 83 private: |
| 84 bool fCoordChangeMatrixSet; |
| 68 SkMatrix fCoordChangeMatrix; | 85 SkMatrix fCoordChangeMatrix; |
| 69 GR_DEBUGCODE(mutable SkAutoTUnref<const GrEffectRef> fEffectRef;) | 86 GR_DEBUGCODE(mutable SkAutoTUnref<const GrEffectRef> fEffectRef;) |
| 70 | 87 |
| 71 friend class GrEffectStage; | 88 friend class GrEffectStage; |
| 72 }; | 89 }; |
| 73 | 90 |
| 74 /** | 91 /** |
| 75 * This gets the current coordinate system change. It is the accumulation of | 92 * This gets the current coordinate system change. It is the accumulation of |
| 76 * localCoordChange calls since the effect was installed. It is used when th
en caller | 93 * localCoordChange calls since the effect was installed. It is used when th
en caller |
| 77 * wants to temporarily change the source geometry coord system, draw someth
ing, and then | 94 * wants to temporarily change the source geometry coord system, draw someth
ing, and then |
| 78 * restore the previous coord system (e.g. temporarily draw in device coords
). | 95 * restore the previous coord system (e.g. temporarily draw in device coords
). |
| 79 */ | 96 */ |
| 80 void saveCoordChange(SavedCoordChange* savedCoordChange) const { | 97 void saveCoordChange(SavedCoordChange* savedCoordChange) const { |
| 81 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; | 98 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet; |
| 99 if (fCoordChangeMatrixSet) { |
| 100 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; |
| 101 } |
| 82 GrAssert(NULL == savedCoordChange->fEffectRef.get()); | 102 GrAssert(NULL == savedCoordChange->fEffectRef.get()); |
| 83 GR_DEBUGCODE(GrSafeRef(fEffectRef);) | 103 GR_DEBUGCODE(GrSafeRef(fEffectRef);) |
| 84 GR_DEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef);) | 104 GR_DEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef);) |
| 85 GR_DEBUGCODE(++fSavedCoordChangeCnt); | 105 GR_DEBUGCODE(++fSavedCoordChangeCnt); |
| 86 } | 106 } |
| 87 | 107 |
| 88 /** | 108 /** |
| 89 * This balances the saveCoordChange call. | 109 * This balances the saveCoordChange call. |
| 90 */ | 110 */ |
| 91 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { | 111 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { |
| 92 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; | 112 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; |
| 113 if (fCoordChangeMatrixSet) { |
| 114 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; |
| 115 } |
| 93 GrAssert(savedCoordChange.fEffectRef.get() == fEffectRef); | 116 GrAssert(savedCoordChange.fEffectRef.get() == fEffectRef); |
| 94 GR_DEBUGCODE(--fSavedCoordChangeCnt); | 117 GR_DEBUGCODE(--fSavedCoordChangeCnt); |
| 95 GR_DEBUGCODE(savedCoordChange.fEffectRef.reset(NULL);) | 118 GR_DEBUGCODE(savedCoordChange.fEffectRef.reset(NULL);) |
| 96 } | 119 } |
| 97 | 120 |
| 98 /** | 121 /** |
| 99 * Used when storing a deferred GrDrawState. The DeferredStage allows resour
ces owned by its | 122 * Used when storing a deferred GrDrawState. The DeferredStage allows resour
ces owned by its |
| 100 * GrEffect to be recycled through the cache. | 123 * GrEffect to be recycled through the cache. |
| 101 */ | 124 */ |
| 102 class DeferredStage { | 125 class DeferredStage { |
| 103 public: | 126 public: |
| 104 DeferredStage() : fEffect(NULL) { | 127 DeferredStage() : fEffect(NULL) { |
| 105 SkDEBUGCODE(fInitialized = false;) | 128 SkDEBUGCODE(fInitialized = false;) |
| 106 } | 129 } |
| 107 | 130 |
| 108 ~DeferredStage() { | 131 ~DeferredStage() { |
| 109 if (NULL != fEffect) { | 132 if (NULL != fEffect) { |
| 110 fEffect->decDeferredRefCounts(); | 133 fEffect->decDeferredRefCounts(); |
| 111 } | 134 } |
| 112 } | 135 } |
| 113 | 136 |
| 114 void saveFrom(const GrEffectStage& stage) { | 137 void saveFrom(const GrEffectStage& stage) { |
| 115 GrAssert(!fInitialized); | 138 GrAssert(!fInitialized); |
| 116 if (NULL != stage.fEffectRef) { | 139 if (NULL != stage.fEffectRef) { |
| 117 stage.fEffectRef->get()->incDeferredRefCounts(); | 140 stage.fEffectRef->get()->incDeferredRefCounts(); |
| 118 fEffect = stage.fEffectRef->get(); | 141 fEffect = stage.fEffectRef->get(); |
| 119 fCoordChangeMatrix = stage.fCoordChangeMatrix; | 142 fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet; |
| 143 if (fCoordChangeMatrixSet) { |
| 144 fCoordChangeMatrix = stage.fCoordChangeMatrix; |
| 145 } |
| 120 fVertexAttribIndices[0] = stage.fVertexAttribIndices[0]; | 146 fVertexAttribIndices[0] = stage.fVertexAttribIndices[0]; |
| 121 fVertexAttribIndices[1] = stage.fVertexAttribIndices[1]; | 147 fVertexAttribIndices[1] = stage.fVertexAttribIndices[1]; |
| 122 } | 148 } |
| 123 SkDEBUGCODE(fInitialized = true;) | 149 SkDEBUGCODE(fInitialized = true;) |
| 124 } | 150 } |
| 125 | 151 |
| 126 void restoreTo(GrEffectStage* stage) { | 152 void restoreTo(GrEffectStage* stage) { |
| 127 GrAssert(fInitialized); | 153 GrAssert(fInitialized); |
| 128 const GrEffectRef* oldEffectRef = stage->fEffectRef; | 154 const GrEffectRef* oldEffectRef = stage->fEffectRef; |
| 129 if (NULL != fEffect) { | 155 if (NULL != fEffect) { |
| 130 stage->fEffectRef = GrEffect::CreateEffectRef(fEffect); | 156 stage->fEffectRef = GrEffect::CreateEffectRef(fEffect); |
| 131 stage->fCoordChangeMatrix = fCoordChangeMatrix; | 157 stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet; |
| 158 if (fCoordChangeMatrixSet) { |
| 159 stage->fCoordChangeMatrix = fCoordChangeMatrix; |
| 160 } |
| 132 stage->fVertexAttribIndices[0] = fVertexAttribIndices[0]; | 161 stage->fVertexAttribIndices[0] = fVertexAttribIndices[0]; |
| 133 stage->fVertexAttribIndices[1] = fVertexAttribIndices[1]; | 162 stage->fVertexAttribIndices[1] = fVertexAttribIndices[1]; |
| 134 } else { | 163 } else { |
| 135 stage->fEffectRef = NULL; | 164 stage->fEffectRef = NULL; |
| 136 } | 165 } |
| 137 SkSafeUnref(oldEffectRef); | 166 SkSafeUnref(oldEffectRef); |
| 138 } | 167 } |
| 139 | 168 |
| 140 bool isEqual(const GrEffectStage& stage) const { | 169 bool isEqual(const GrEffectStage& stage) const { |
| 141 if (NULL == stage.fEffectRef) { | 170 if (NULL == stage.fEffectRef) { |
| 142 return NULL == fEffect; | 171 return NULL == fEffect; |
| 143 } else if (NULL == fEffect) { | 172 } else if (NULL == fEffect) { |
| 144 return false; | 173 return false; |
| 145 } | 174 } |
| 146 | 175 |
| 147 if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0] | 176 if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0] |
| 148 || fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) { | 177 || fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) { |
| 149 return false; | 178 return false; |
| 150 } | 179 } |
| 151 | 180 |
| 152 if (!(*stage.getEffect())->isEqual(*fEffect)) { | 181 if (!(*stage.getEffect())->isEqual(*fEffect)) { |
| 153 return false; | 182 return false; |
| 154 } | 183 } |
| 155 | 184 |
| 185 if (fCoordChangeMatrixSet != stage.fCoordChangeMatrixSet) { |
| 186 return false; |
| 187 } |
| 188 |
| 189 if (!fCoordChangeMatrixSet) { |
| 190 return true; |
| 191 } |
| 192 |
| 156 return fCoordChangeMatrix == stage.fCoordChangeMatrix; | 193 return fCoordChangeMatrix == stage.fCoordChangeMatrix; |
| 157 } | 194 } |
| 158 | 195 |
| 159 private: | 196 private: |
| 160 const GrEffect* fEffect; | 197 const GrEffect* fEffect; |
| 198 bool fCoordChangeMatrixSet; |
| 161 SkMatrix fCoordChangeMatrix; | 199 SkMatrix fCoordChangeMatrix; |
| 162 int fVertexAttribIndices[2]; | 200 int fVertexAttribIndices[2]; |
| 163 SkDEBUGCODE(bool fInitialized;) | 201 SkDEBUGCODE(bool fInitialized;) |
| 164 }; | 202 }; |
| 165 | 203 |
| 166 /** | 204 /** |
| 167 * Gets the matrix representing all changes of coordinate system since the G
rEffect was | 205 * Gets the matrix representing all changes of coordinate system since the G
rEffect was |
| 168 * installed in the stage. | 206 * installed in the stage. |
| 169 */ | 207 */ |
| 170 const SkMatrix& getCoordChangeMatrix() const { return fCoordChangeMatrix; } | 208 const SkMatrix& getCoordChangeMatrix() const { |
| 209 if (fCoordChangeMatrixSet) { |
| 210 return fCoordChangeMatrix; |
| 211 } else { |
| 212 return SkMatrix::I(); |
| 213 } |
| 214 } |
| 171 | 215 |
| 172 void reset() { | 216 void reset() { |
| 173 GrSafeSetNull(fEffectRef); | 217 GrSafeSetNull(fEffectRef); |
| 174 } | 218 } |
| 175 | 219 |
| 176 const GrEffectRef* setEffect(const GrEffectRef* EffectRef) { | 220 const GrEffectRef* setEffect(const GrEffectRef* EffectRef) { |
| 177 GrAssert(0 == fSavedCoordChangeCnt); | 221 GrAssert(0 == fSavedCoordChangeCnt); |
| 178 GrSafeAssign(fEffectRef, EffectRef); | 222 GrSafeAssign(fEffectRef, EffectRef); |
| 179 fCoordChangeMatrix.reset(); | 223 fCoordChangeMatrixSet = false; |
| 180 | 224 |
| 181 fVertexAttribIndices[0] = -1; | 225 fVertexAttribIndices[0] = -1; |
| 182 fVertexAttribIndices[1] = -1; | 226 fVertexAttribIndices[1] = -1; |
| 183 | 227 |
| 184 return EffectRef; | 228 return EffectRef; |
| 185 } | 229 } |
| 186 | 230 |
| 187 const GrEffectRef* setEffect(const GrEffectRef* EffectRef, int attr0, int at
tr1 = -1) { | 231 const GrEffectRef* setEffect(const GrEffectRef* EffectRef, int attr0, int at
tr1 = -1) { |
| 188 GrAssert(0 == fSavedCoordChangeCnt); | 232 GrAssert(0 == fSavedCoordChangeCnt); |
| 189 GrSafeAssign(fEffectRef, EffectRef); | 233 GrSafeAssign(fEffectRef, EffectRef); |
| 190 fCoordChangeMatrix.reset(); | 234 fCoordChangeMatrixSet = false; |
| 191 | 235 |
| 192 fVertexAttribIndices[0] = attr0; | 236 fVertexAttribIndices[0] = attr0; |
| 193 fVertexAttribIndices[1] = attr1; | 237 fVertexAttribIndices[1] = attr1; |
| 194 | 238 |
| 195 return EffectRef; | 239 return EffectRef; |
| 196 } | 240 } |
| 197 | 241 |
| 198 const GrEffectRef* getEffect() const { return fEffectRef; } | 242 const GrEffectRef* getEffect() const { return fEffectRef; } |
| 199 | 243 |
| 200 const int* getVertexAttribIndices() const { return fVertexAttribIndices; } | 244 const int* getVertexAttribIndices() const { return fVertexAttribIndices; } |
| 201 int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexA
ttribs(); } | 245 int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexA
ttribs(); } |
| 202 | 246 |
| 203 private: | 247 private: |
| 248 bool fCoordChangeMatrixSet; |
| 204 SkMatrix fCoordChangeMatrix; | 249 SkMatrix fCoordChangeMatrix; |
| 205 const GrEffectRef* fEffectRef; | 250 const GrEffectRef* fEffectRef; |
| 206 int fVertexAttribIndices[2]; | 251 int fVertexAttribIndices[2]; |
| 207 | 252 |
| 208 GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;) | 253 GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;) |
| 209 }; | 254 }; |
| 210 | 255 |
| 211 #endif | 256 #endif |
| OLD | NEW |