OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #ifndef GrPaint_DEFINED | 10 #ifndef GrPaint_DEFINED |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 for (int i = 0; i < kMaxColorStages; ++i) { | 162 for (int i = 0; i < kMaxColorStages; ++i) { |
163 if (this->isColorStageEnabled(i)) { | 163 if (this->isColorStageEnabled(i)) { |
164 return true; | 164 return true; |
165 } | 165 } |
166 } | 166 } |
167 return false; | 167 return false; |
168 } | 168 } |
169 | 169 |
170 bool hasStage() const { return this->hasColorStage() || this->hasCoverageSta
ge(); } | 170 bool hasStage() const { return this->hasColorStage() || this->hasCoverageSta
ge(); } |
171 | 171 |
172 /** | |
173 * Called when the source coord system is changing. preConcatInverse is the
inverse of the | |
174 * transformation from the old coord system to the new coord system. Returns
false if the matrix | |
175 * cannot be inverted. | |
176 */ | |
177 bool sourceCoordChangeByInverse(const SkMatrix& preConcatInverse) { | |
178 SkMatrix inv; | |
179 bool computed = false; | |
180 for (int i = 0; i < kMaxColorStages; ++i) { | |
181 if (this->isColorStageEnabled(i)) { | |
182 if (!computed && !preConcatInverse.invert(&inv)) { | |
183 return false; | |
184 } else { | |
185 computed = true; | |
186 } | |
187 fColorStages[i].preConcatCoordChange(inv); | |
188 } | |
189 } | |
190 for (int i = 0; i < kMaxCoverageStages; ++i) { | |
191 if (this->isCoverageStageEnabled(i)) { | |
192 if (!computed && !preConcatInverse.invert(&inv)) { | |
193 return false; | |
194 } else { | |
195 computed = true; | |
196 } | |
197 fCoverageStages[i].preConcatCoordChange(inv); | |
198 } | |
199 } | |
200 return true; | |
201 } | |
202 | |
203 /** | |
204 * Called when the source coord system is changing. preConcat gives the tran
sformation from the | |
205 * old coord system to the new coord system. | |
206 */ | |
207 void sourceCoordChange(const SkMatrix& preConcat) { | |
208 for (int i = 0; i < kMaxColorStages; ++i) { | |
209 if (this->isColorStageEnabled(i)) { | |
210 fColorStages[i].preConcatCoordChange(preConcat); | |
211 } | |
212 } | |
213 for (int i = 0; i < kMaxCoverageStages; ++i) { | |
214 if (this->isCoverageStageEnabled(i)) { | |
215 fCoverageStages[i].preConcatCoordChange(preConcat); | |
216 } | |
217 } | |
218 } | |
219 | |
220 GrPaint& operator=(const GrPaint& paint) { | 172 GrPaint& operator=(const GrPaint& paint) { |
221 fSrcBlendCoeff = paint.fSrcBlendCoeff; | 173 fSrcBlendCoeff = paint.fSrcBlendCoeff; |
222 fDstBlendCoeff = paint.fDstBlendCoeff; | 174 fDstBlendCoeff = paint.fDstBlendCoeff; |
223 fAntiAlias = paint.fAntiAlias; | 175 fAntiAlias = paint.fAntiAlias; |
224 fDither = paint.fDither; | 176 fDither = paint.fDither; |
225 | 177 |
226 fColor = paint.fColor; | 178 fColor = paint.fColor; |
227 fCoverage = paint.fCoverage; | 179 fCoverage = paint.fCoverage; |
228 | 180 |
229 fColorFilterColor = paint.fColorFilterColor; | 181 fColorFilterColor = paint.fColorFilterColor; |
(...skipping 27 matching lines...) Expand all Loading... |
257 // internal use | 209 // internal use |
258 // GrPaint's textures and masks map to the first N stages | 210 // GrPaint's textures and masks map to the first N stages |
259 // of GrDrawTarget in that order (textures followed by masks) | 211 // of GrDrawTarget in that order (textures followed by masks) |
260 enum { | 212 enum { |
261 kFirstColorStage = 0, | 213 kFirstColorStage = 0, |
262 kFirstCoverageStage = kMaxColorStages, | 214 kFirstCoverageStage = kMaxColorStages, |
263 kTotalStages = kFirstColorStage + kMaxColorStages + kMaxCoverageStages, | 215 kTotalStages = kFirstColorStage + kMaxColorStages + kMaxCoverageStages, |
264 }; | 216 }; |
265 | 217 |
266 private: | 218 private: |
| 219 /** |
| 220 * Called when the source coord system from which geometry is rendered chang
es. It ensures that |
| 221 * the local coordinates seen by effects remains unchanged. oldToNew gives t
he transformation |
| 222 * from the previous coord system to the new coord system. |
| 223 */ |
| 224 void localCoordChange(const SkMatrix& oldToNew) { |
| 225 for (int i = 0; i < kMaxColorStages; ++i) { |
| 226 if (this->isColorStageEnabled(i)) { |
| 227 fColorStages[i].localCoordChange(oldToNew); |
| 228 } |
| 229 } |
| 230 for (int i = 0; i < kMaxCoverageStages; ++i) { |
| 231 if (this->isCoverageStageEnabled(i)) { |
| 232 fCoverageStages[i].localCoordChange(oldToNew); |
| 233 } |
| 234 } |
| 235 } |
| 236 |
| 237 bool localCoordChangeInverse(const SkMatrix& newToOld) { |
| 238 SkMatrix oldToNew; |
| 239 bool computed = false; |
| 240 for (int i = 0; i < kMaxColorStages; ++i) { |
| 241 if (this->isColorStageEnabled(i)) { |
| 242 if (!computed && !newToOld.invert(&oldToNew)) { |
| 243 return false; |
| 244 } else { |
| 245 computed = true; |
| 246 } |
| 247 fColorStages[i].localCoordChange(oldToNew); |
| 248 } |
| 249 } |
| 250 for (int i = 0; i < kMaxCoverageStages; ++i) { |
| 251 if (this->isCoverageStageEnabled(i)) { |
| 252 if (!computed && !newToOld.invert(&oldToNew)) { |
| 253 return false; |
| 254 } else { |
| 255 computed = true; |
| 256 } |
| 257 fCoverageStages[i].localCoordChange(oldToNew); |
| 258 } |
| 259 } |
| 260 return true; |
| 261 } |
| 262 |
| 263 friend GrContext; // To access above two functions |
267 | 264 |
268 GrEffectStage fColorStages[kMaxColorStages]; | 265 GrEffectStage fColorStages[kMaxColorStages]; |
269 GrEffectStage fCoverageStages[kMaxCoverageStages]; | 266 GrEffectStage fCoverageStages[kMaxCoverageStages]; |
270 | 267 |
271 GrBlendCoeff fSrcBlendCoeff; | 268 GrBlendCoeff fSrcBlendCoeff; |
272 GrBlendCoeff fDstBlendCoeff; | 269 GrBlendCoeff fDstBlendCoeff; |
273 bool fAntiAlias; | 270 bool fAntiAlias; |
274 bool fDither; | 271 bool fDither; |
275 | 272 |
276 GrColor fColor; | 273 GrColor fColor; |
(...skipping 24 matching lines...) Expand all Loading... |
301 for (int i = 0; i < kMaxColorStages; ++i) { | 298 for (int i = 0; i < kMaxColorStages; ++i) { |
302 fColorStages[i].reset(); | 299 fColorStages[i].reset(); |
303 } | 300 } |
304 for (int i = 0; i < kMaxCoverageStages; ++i) { | 301 for (int i = 0; i < kMaxCoverageStages; ++i) { |
305 fCoverageStages[i].reset(); | 302 fCoverageStages[i].reset(); |
306 } | 303 } |
307 } | 304 } |
308 }; | 305 }; |
309 | 306 |
310 #endif | 307 #endif |
OLD | NEW |