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 #include "GrPaint.h" | 9 #include "GrPaint.h" |
10 #include "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 return kAOrB_CombinedState; | 48 return kAOrB_CombinedState; |
49 } | 49 } |
50 | 50 |
51 //////////////////////////////////////////////////////////////////////////////s | 51 //////////////////////////////////////////////////////////////////////////////s |
52 | 52 |
53 GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr
ix) { | 53 GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr
ix) { |
54 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 54 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
55 *this = state; | 55 *this = state; |
56 if (!preConcatMatrix.isIdentity()) { | 56 if (!preConcatMatrix.isIdentity()) { |
| 57 if (this->hasGeometryProcessor()) { |
| 58 fGeometryProcessor->localCoordChange(preConcatMatrix); |
| 59 } |
57 for (int i = 0; i < this->numColorStages(); ++i) { | 60 for (int i = 0; i < this->numColorStages(); ++i) { |
58 fColorStages[i].localCoordChange(preConcatMatrix); | 61 fColorStages[i].localCoordChange(preConcatMatrix); |
59 } | 62 } |
60 for (int i = 0; i < this->numCoverageStages(); ++i) { | 63 for (int i = 0; i < this->numCoverageStages(); ++i) { |
61 fCoverageStages[i].localCoordChange(preConcatMatrix); | 64 fCoverageStages[i].localCoordChange(preConcatMatrix); |
62 } | 65 } |
63 this->invalidateBlendOptFlags(); | 66 this->invalidateBlendOptFlags(); |
64 } | 67 } |
65 } | 68 } |
66 | 69 |
67 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { | 70 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { |
68 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 71 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
69 this->setRenderTarget(that.fRenderTarget.get()); | 72 this->setRenderTarget(that.fRenderTarget.get()); |
70 fColor = that.fColor; | 73 fColor = that.fColor; |
71 fViewMatrix = that.fViewMatrix; | 74 fViewMatrix = that.fViewMatrix; |
72 fSrcBlend = that.fSrcBlend; | 75 fSrcBlend = that.fSrcBlend; |
73 fDstBlend = that.fDstBlend; | 76 fDstBlend = that.fDstBlend; |
74 fBlendConstant = that.fBlendConstant; | 77 fBlendConstant = that.fBlendConstant; |
75 fFlagBits = that.fFlagBits; | 78 fFlagBits = that.fFlagBits; |
76 fVACount = that.fVACount; | 79 fVACount = that.fVACount; |
77 fVAPtr = that.fVAPtr; | 80 fVAPtr = that.fVAPtr; |
78 fVAStride = that.fVAStride; | 81 fVAStride = that.fVAStride; |
79 fStencilSettings = that.fStencilSettings; | 82 fStencilSettings = that.fStencilSettings; |
80 fCoverage = that.fCoverage; | 83 fCoverage = that.fCoverage; |
81 fDrawFace = that.fDrawFace; | 84 fDrawFace = that.fDrawFace; |
| 85 if (that.hasGeometryProcessor()) { |
| 86 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*that.fGeometryProce
ssor.get()))); |
| 87 } else { |
| 88 fGeometryProcessor.reset(NULL); |
| 89 } |
82 fColorStages = that.fColorStages; | 90 fColorStages = that.fColorStages; |
83 fCoverageStages = that.fCoverageStages; | 91 fCoverageStages = that.fCoverageStages; |
84 fOptSrcBlend = that.fOptSrcBlend; | 92 fOptSrcBlend = that.fOptSrcBlend; |
85 fOptDstBlend = that.fOptDstBlend; | 93 fOptDstBlend = that.fOptDstBlend; |
86 fBlendOptFlags = that.fBlendOptFlags; | 94 fBlendOptFlags = that.fBlendOptFlags; |
87 | 95 |
88 fHints = that.fHints; | 96 fHints = that.fHints; |
89 | 97 |
90 memcpy(fFixedFunctionVertexAttribIndices, | 98 memcpy(fFixedFunctionVertexAttribIndices, |
91 that.fFixedFunctionVertexAttribIndices, | 99 that.fFixedFunctionVertexAttribIndices, |
92 sizeof(fFixedFunctionVertexAttribIndices)); | 100 sizeof(fFixedFunctionVertexAttribIndices)); |
93 return *this; | 101 return *this; |
94 } | 102 } |
95 | 103 |
96 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { | 104 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { |
97 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 105 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 106 fGeometryProcessor.reset(NULL); |
98 fColorStages.reset(); | 107 fColorStages.reset(); |
99 fCoverageStages.reset(); | 108 fCoverageStages.reset(); |
100 | 109 |
101 fRenderTarget.reset(NULL); | 110 fRenderTarget.reset(NULL); |
102 | 111 |
103 this->setDefaultVertexAttribs(); | 112 this->setDefaultVertexAttribs(); |
104 | 113 |
105 fColor = 0xffffffff; | 114 fColor = 0xffffffff; |
106 if (NULL == initialViewMatrix) { | 115 if (NULL == initialViewMatrix) { |
107 fViewMatrix.reset(); | 116 fViewMatrix.reset(); |
(...skipping 13 matching lines...) Expand all Loading... |
121 this->invalidateBlendOptFlags(); | 130 this->invalidateBlendOptFlags(); |
122 } | 131 } |
123 | 132 |
124 bool GrDrawState::setIdentityViewMatrix() { | 133 bool GrDrawState::setIdentityViewMatrix() { |
125 if (this->numTotalStages()) { | 134 if (this->numTotalStages()) { |
126 SkMatrix invVM; | 135 SkMatrix invVM; |
127 if (!fViewMatrix.invert(&invVM)) { | 136 if (!fViewMatrix.invert(&invVM)) { |
128 // sad trombone sound | 137 // sad trombone sound |
129 return false; | 138 return false; |
130 } | 139 } |
| 140 if (this->hasGeometryProcessor()) { |
| 141 fGeometryProcessor->localCoordChange(invVM); |
| 142 } |
131 for (int s = 0; s < this->numColorStages(); ++s) { | 143 for (int s = 0; s < this->numColorStages(); ++s) { |
132 fColorStages[s].localCoordChange(invVM); | 144 fColorStages[s].localCoordChange(invVM); |
133 } | 145 } |
134 for (int s = 0; s < this->numCoverageStages(); ++s) { | 146 for (int s = 0; s < this->numCoverageStages(); ++s) { |
135 fCoverageStages[s].localCoordChange(invVM); | 147 fCoverageStages[s].localCoordChange(invVM); |
136 } | 148 } |
137 } | 149 } |
138 fViewMatrix.reset(); | 150 fViewMatrix.reset(); |
139 return true; | 151 return true; |
140 } | 152 } |
141 | 153 |
142 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
rTarget* rt) { | 154 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
rTarget* rt) { |
143 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 155 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
144 | 156 |
| 157 fGeometryProcessor.reset(NULL); |
145 fColorStages.reset(); | 158 fColorStages.reset(); |
146 fCoverageStages.reset(); | 159 fCoverageStages.reset(); |
147 | 160 |
148 for (int i = 0; i < paint.numColorStages(); ++i) { | 161 for (int i = 0; i < paint.numColorStages(); ++i) { |
149 fColorStages.push_back(paint.getColorStage(i)); | 162 fColorStages.push_back(paint.getColorStage(i)); |
150 } | 163 } |
151 | 164 |
152 for (int i = 0; i < paint.numCoverageStages(); ++i) { | 165 for (int i = 0; i < paint.numCoverageStages(); ++i) { |
153 fCoverageStages.push_back(paint.getCoverageStage(i)); | 166 fCoverageStages.push_back(paint.getCoverageStage(i)); |
154 } | 167 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 fVAPtr = drawState->fVAPtr; | 292 fVAPtr = drawState->fVAPtr; |
280 fVACount = drawState->fVACount; | 293 fVACount = drawState->fVACount; |
281 fVAStride = drawState->fVAStride; | 294 fVAStride = drawState->fVAStride; |
282 fDrawState->setDefaultVertexAttribs(); | 295 fDrawState->setDefaultVertexAttribs(); |
283 } | 296 } |
284 | 297 |
285 //////////////////////////////////////////////////////////////////////////////s | 298 //////////////////////////////////////////////////////////////////////////////s |
286 | 299 |
287 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { | 300 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { |
288 if (NULL != fDrawState) { | 301 if (NULL != fDrawState) { |
| 302 fDrawState->fGeometryProcessor.reset(fGeometryProcessor.detach()); |
| 303 |
289 int m = fDrawState->numColorStages() - fColorEffectCnt; | 304 int m = fDrawState->numColorStages() - fColorEffectCnt; |
290 SkASSERT(m >= 0); | 305 SkASSERT(m >= 0); |
291 fDrawState->fColorStages.pop_back_n(m); | 306 fDrawState->fColorStages.pop_back_n(m); |
292 | 307 |
293 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; | 308 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; |
294 SkASSERT(n >= 0); | 309 SkASSERT(n >= 0); |
295 fDrawState->fCoverageStages.pop_back_n(n); | 310 fDrawState->fCoverageStages.pop_back_n(n); |
296 if (m + n > 0) { | 311 if (m + n > 0) { |
297 fDrawState->invalidateBlendOptFlags(); | 312 fDrawState->invalidateBlendOptFlags(); |
298 } | 313 } |
299 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | 314 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
300 } | 315 } |
301 fDrawState = ds; | 316 fDrawState = ds; |
302 if (NULL != ds) { | 317 if (NULL != ds) { |
| 318 if (ds->hasGeometryProcessor()) { |
| 319 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*ds->getGeometry
Processor()))); |
| 320 } else { |
| 321 fGeometryProcessor.reset(NULL); |
| 322 } |
303 fColorEffectCnt = ds->numColorStages(); | 323 fColorEffectCnt = ds->numColorStages(); |
304 fCoverageEffectCnt = ds->numCoverageStages(); | 324 fCoverageEffectCnt = ds->numCoverageStages(); |
305 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) | 325 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) |
306 } | 326 } |
307 } | 327 } |
308 | 328 |
309 //////////////////////////////////////////////////////////////////////////////// | 329 //////////////////////////////////////////////////////////////////////////////// |
310 | 330 |
311 GrRODrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, | 331 GrRODrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, |
312 GrBlendCoeff* srcCoeff, | 332 GrBlendCoeff* srcCoeff, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 442 |
423 void GrDrawState::AutoViewMatrixRestore::restore() { | 443 void GrDrawState::AutoViewMatrixRestore::restore() { |
424 if (NULL != fDrawState) { | 444 if (NULL != fDrawState) { |
425 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | 445 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
426 fDrawState->fViewMatrix = fViewMatrix; | 446 fDrawState->fViewMatrix = fViewMatrix; |
427 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); | 447 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); |
428 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; | 448 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; |
429 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); | 449 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); |
430 | 450 |
431 int i = 0; | 451 int i = 0; |
| 452 if (fHasGeometryProcessor) { |
| 453 SkASSERT(fDrawState->hasGeometryProcessor()); |
| 454 fDrawState->fGeometryProcessor->restoreCoordChange(fSavedCoordChange
s[i++]); |
| 455 } |
432 for (int s = 0; s < fNumColorStages; ++s, ++i) { | 456 for (int s = 0; s < fNumColorStages; ++s, ++i) { |
433 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]
); | 457 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]
); |
434 } | 458 } |
435 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 459 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
436 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges
[i]); | 460 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges
[i]); |
437 } | 461 } |
438 fDrawState = NULL; | 462 fDrawState = NULL; |
439 } | 463 } |
440 } | 464 } |
441 | 465 |
(...skipping 22 matching lines...) Expand all Loading... |
464 } | 488 } |
465 | 489 |
466 if (drawState->getViewMatrix().isIdentity()) { | 490 if (drawState->getViewMatrix().isIdentity()) { |
467 return true; | 491 return true; |
468 } | 492 } |
469 | 493 |
470 fViewMatrix = drawState->getViewMatrix(); | 494 fViewMatrix = drawState->getViewMatrix(); |
471 if (0 == drawState->numTotalStages()) { | 495 if (0 == drawState->numTotalStages()) { |
472 drawState->fViewMatrix.reset(); | 496 drawState->fViewMatrix.reset(); |
473 fDrawState = drawState; | 497 fDrawState = drawState; |
| 498 fHasGeometryProcessor = false; |
474 fNumColorStages = 0; | 499 fNumColorStages = 0; |
475 fSavedCoordChanges.reset(0); | 500 fSavedCoordChanges.reset(0); |
476 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) | 501 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
477 return true; | 502 return true; |
478 } else { | 503 } else { |
479 SkMatrix inv; | 504 SkMatrix inv; |
480 if (!fViewMatrix.invert(&inv)) { | 505 if (!fViewMatrix.invert(&inv)) { |
481 return false; | 506 return false; |
482 } | 507 } |
483 drawState->fViewMatrix.reset(); | 508 drawState->fViewMatrix.reset(); |
484 fDrawState = drawState; | 509 fDrawState = drawState; |
485 this->doEffectCoordChanges(inv); | 510 this->doEffectCoordChanges(inv); |
486 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) | 511 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
487 return true; | 512 return true; |
488 } | 513 } |
489 } | 514 } |
490 | 515 |
491 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co
ordChangeMatrix) { | 516 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co
ordChangeMatrix) { |
492 fSavedCoordChanges.reset(fDrawState->numTotalStages()); | 517 fSavedCoordChanges.reset(fDrawState->numTotalStages()); |
493 int i = 0; | 518 int i = 0; |
494 | 519 |
| 520 fHasGeometryProcessor = false; |
| 521 if (fDrawState->hasGeometryProcessor()) { |
| 522 fDrawState->fGeometryProcessor->saveCoordChange(&fSavedCoordChanges[i++]
); |
| 523 fDrawState->fGeometryProcessor->localCoordChange(coordChangeMatrix); |
| 524 fHasGeometryProcessor = true; |
| 525 } |
| 526 |
495 fNumColorStages = fDrawState->numColorStages(); | 527 fNumColorStages = fDrawState->numColorStages(); |
496 for (int s = 0; s < fNumColorStages; ++s, ++i) { | 528 for (int s = 0; s < fNumColorStages; ++s, ++i) { |
497 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]); | 529 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
498 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | 530 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
499 } | 531 } |
500 | 532 |
501 int numCoverageStages = fDrawState->numCoverageStages(); | 533 int numCoverageStages = fDrawState->numCoverageStages(); |
502 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 534 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
503 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); | 535 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
504 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 536 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 uint32_t coverageComponentFlags; | 568 uint32_t coverageComponentFlags; |
537 if (this->hasCoverageVertexAttribute()) { | 569 if (this->hasCoverageVertexAttribute()) { |
538 coverageComponentFlags = 0; | 570 coverageComponentFlags = 0; |
539 coverage = 0; // suppresses any warnings. | 571 coverage = 0; // suppresses any warnings. |
540 } else { | 572 } else { |
541 coverageComponentFlags = kRGBA_GrColorComponentFlags; | 573 coverageComponentFlags = kRGBA_GrColorComponentFlags; |
542 coverage = this->getCoverageColor(); | 574 coverage = this->getCoverageColor(); |
543 } | 575 } |
544 | 576 |
545 // Run through the coverage stages | 577 // Run through the coverage stages |
| 578 if (this->hasGeometryProcessor()) { |
| 579 const GrEffect* effect = fGeometryProcessor->getEffect(); |
| 580 effect->getConstantColorComponents(&coverage, &coverageComponentFlag
s); |
| 581 } |
546 for (int s = 0; s < this->numCoverageStages(); ++s) { | 582 for (int s = 0; s < this->numCoverageStages(); ++s) { |
547 const GrEffect* effect = this->getCoverageStage(s).getEffect(); | 583 const GrEffect* effect = this->getCoverageStage(s).getEffect(); |
548 effect->getConstantColorComponents(&coverage, &coverageComponentFlag
s); | 584 effect->getConstantColorComponents(&coverage, &coverageComponentFlag
s); |
549 } | 585 } |
550 | 586 |
551 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if | 587 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if |
552 // coverage and color both have A==1. | 588 // coverage and color both have A==1. |
553 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen
tFlags) && | 589 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen
tFlags) && |
554 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage
); | 590 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage
); |
555 | 591 |
556 } | 592 } |
557 | 593 |
558 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp
ackA(color); | 594 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp
ackA(color); |
559 } | 595 } |
560 | 596 |
561 //////////////////////////////////////////////////////////////////////////////// | 597 //////////////////////////////////////////////////////////////////////////////// |
562 | 598 |
563 bool GrDrawState::canIgnoreColorAttribute() const { | 599 bool GrDrawState::canIgnoreColorAttribute() const { |
564 if (fBlendOptFlags & kInvalid_BlendOptFlag) { | 600 if (fBlendOptFlags & kInvalid_BlendOptFlag) { |
565 this->getBlendOpts(); | 601 this->getBlendOpts(); |
566 } | 602 } |
567 return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFla
g | | 603 return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFla
g | |
568 GrRODrawState::kEmitCoverage_BlendOptFlag)
); | 604 GrRODrawState::kEmitCoverage_BlendOptFlag)
); |
569 } | 605 } |
570 | 606 |
OLD | NEW |