OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "GrDrawState.h" | 8 #include "GrDrawState.h" |
9 | 9 |
10 #include "GrBlend.h" | 10 #include "GrBlend.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 //////////////////////////////////////////////////////////////////////////////// | 204 //////////////////////////////////////////////////////////////////////////////// |
205 | 205 |
206 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while | 206 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while |
207 // others will blend incorrectly. | 207 // others will blend incorrectly. |
208 bool GrDrawState::canTweakAlphaForCoverage() const { | 208 bool GrDrawState::canTweakAlphaForCoverage() const { |
209 return fXPFactory->canTweakAlphaForCoverage(); | 209 return fXPFactory->canTweakAlphaForCoverage(); |
210 } | 210 } |
211 | 211 |
212 //////////////////////////////////////////////////////////////////////////////// | 212 //////////////////////////////////////////////////////////////////////////////// |
213 | 213 |
214 void GrDrawState::AutoViewMatrixRestore::restore() { | |
215 if (fDrawState) { | |
216 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | |
217 fDrawState->fViewMatrix = fViewMatrix; | |
218 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); | |
219 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; | |
220 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); | |
221 | |
222 int i = 0; | |
223 for (int s = 0; s < fNumColorStages; ++s, ++i) { | |
224 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]
); | |
225 } | |
226 for (int s = 0; s < numCoverageStages; ++s, ++i) { | |
227 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges
[i]); | |
228 } | |
229 fDrawState = NULL; | |
230 } | |
231 } | |
232 | |
233 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, | |
234 const SkMatrix& preconcatMatrix) { | |
235 this->restore(); | |
236 | |
237 SkASSERT(NULL == fDrawState); | |
238 if (NULL == drawState || preconcatMatrix.isIdentity()) { | |
239 return; | |
240 } | |
241 fDrawState = drawState; | |
242 | |
243 fViewMatrix = drawState->getViewMatrix(); | |
244 drawState->fViewMatrix.preConcat(preconcatMatrix); | |
245 | |
246 this->doEffectCoordChanges(preconcatMatrix); | |
247 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) | |
248 } | |
249 | |
250 bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) { | |
251 this->restore(); | |
252 | |
253 if (NULL == drawState) { | |
254 return false; | |
255 } | |
256 | |
257 if (drawState->getViewMatrix().isIdentity()) { | |
258 return true; | |
259 } | |
260 | |
261 fViewMatrix = drawState->getViewMatrix(); | |
262 if (0 == drawState->numFragmentStages()) { | |
263 drawState->fViewMatrix.reset(); | |
264 fDrawState = drawState; | |
265 fNumColorStages = 0; | |
266 fSavedCoordChanges.reset(0); | |
267 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) | |
268 return true; | |
269 } else { | |
270 SkMatrix inv; | |
271 if (!fViewMatrix.invert(&inv)) { | |
272 return false; | |
273 } | |
274 drawState->fViewMatrix.reset(); | |
275 fDrawState = drawState; | |
276 this->doEffectCoordChanges(inv); | |
277 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) | |
278 return true; | |
279 } | |
280 } | |
281 | |
282 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co
ordChangeMatrix) { | |
283 fSavedCoordChanges.reset(fDrawState->numFragmentStages()); | |
284 int i = 0; | |
285 | |
286 fNumColorStages = fDrawState->numColorStages(); | |
287 for (int s = 0; s < fNumColorStages; ++s, ++i) { | |
288 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]); | |
289 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | |
290 } | |
291 | |
292 int numCoverageStages = fDrawState->numCoverageStages(); | |
293 for (int s = 0; s < numCoverageStages; ++s, ++i) { | |
294 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); | |
295 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | |
296 } | |
297 } | |
298 | |
299 //////////////////////////////////////////////////////////////////////////////// | |
300 | |
301 GrDrawState::~GrDrawState() { | 214 GrDrawState::~GrDrawState() { |
302 SkASSERT(0 == fBlockEffectRemovalCnt); | 215 SkASSERT(0 == fBlockEffectRemovalCnt); |
303 } | 216 } |
304 | 217 |
305 //////////////////////////////////////////////////////////////////////////////// | 218 //////////////////////////////////////////////////////////////////////////////// |
306 | 219 |
307 bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const { | 220 bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const { |
308 this->calcColorInvariantOutput(pp); | 221 this->calcColorInvariantOutput(pp); |
309 this->calcCoverageInvariantOutput(pp); | 222 this->calcCoverageInvariantOutput(pp); |
310 | 223 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { | 256 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { |
344 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { | 257 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { |
345 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | 258 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
346 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), | 259 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), |
347 this->numCoverageStages(), cover
age, flags, | 260 this->numCoverageStages(), cover
age, flags, |
348 true); | 261 true); |
349 fCoverageProcInfoValid = true; | 262 fCoverageProcInfoValid = true; |
350 fCoverageCache = coverage; | 263 fCoverageCache = coverage; |
351 } | 264 } |
352 } | 265 } |
OLD | NEW |