| 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 "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
| 11 #include "GrOptDrawState.h" | 11 #include "GrOptDrawState.h" |
| 12 #include "GrPaint.h" | 12 #include "GrPaint.h" |
| 13 | 13 |
| 14 //////////////////////////////////////////////////////////////////////////////s | 14 //////////////////////////////////////////////////////////////////////////////s |
| 15 | 15 |
| 16 GrOptDrawState* GrDrawState::createOptState() const { | 16 GrOptDrawState* GrDrawState::createOptState() const { |
| 17 if (NULL == fCachedOptState) { | 17 if (NULL == fCachedOptState) { |
| 18 GrBlendCoeff srcCoeff; | 18 fCachedOptState = SkNEW_ARGS(GrOptDrawState, (*this)); |
| 19 GrBlendCoeff dstCoeff; | |
| 20 BlendOptFlags blendFlags = this->getBlendOpts(false, &srcCoeff, &dstCoef
f); | |
| 21 fCachedOptState = SkNEW_ARGS(GrOptDrawState, (*this, blendFlags, srcCoef
f, dstCoeff)); | |
| 22 } else { | 19 } else { |
| 23 #ifdef SK_DEBUG | 20 SkASSERT(GrOptDrawState(*this) == *fCachedOptState); |
| 24 GrBlendCoeff srcCoeff; | |
| 25 GrBlendCoeff dstCoeff; | |
| 26 BlendOptFlags blendFlags = this->getBlendOpts(false, &srcCoeff, &dstCoef
f); | |
| 27 SkASSERT(GrOptDrawState(*this, blendFlags, srcCoeff, dstCoeff) == *fCach
edOptState); | |
| 28 #endif | |
| 29 } | 21 } |
| 30 fCachedOptState->ref(); | 22 fCachedOptState->ref(); |
| 31 return fCachedOptState; | 23 return fCachedOptState; |
| 32 } | 24 } |
| 33 | 25 |
| 34 //////////////////////////////////////////////////////////////////////////////s | 26 //////////////////////////////////////////////////////////////////////////////s |
| 35 | 27 |
| 36 GrDrawState::CombinedState GrDrawState::CombineIfPossible( | 28 GrDrawState::CombinedState GrDrawState::CombineIfPossible( |
| 37 const GrDrawState& a, const GrDrawState& b, const GrDrawTargetCaps& caps) { | 29 const GrDrawState& a, const GrDrawState& b, const GrDrawTargetCaps& caps) { |
| 38 | 30 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 fStencilSettings = that.fStencilSettings; | 99 fStencilSettings = that.fStencilSettings; |
| 108 fCoverage = that.fCoverage; | 100 fCoverage = that.fCoverage; |
| 109 fDrawFace = that.fDrawFace; | 101 fDrawFace = that.fDrawFace; |
| 110 if (that.hasGeometryProcessor()) { | 102 if (that.hasGeometryProcessor()) { |
| 111 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*that.fGeometryProce
ssor.get()))); | 103 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*that.fGeometryProce
ssor.get()))); |
| 112 } else { | 104 } else { |
| 113 fGeometryProcessor.reset(NULL); | 105 fGeometryProcessor.reset(NULL); |
| 114 } | 106 } |
| 115 fColorStages = that.fColorStages; | 107 fColorStages = that.fColorStages; |
| 116 fCoverageStages = that.fCoverageStages; | 108 fCoverageStages = that.fCoverageStages; |
| 109 fOptSrcBlend = that.fOptSrcBlend; |
| 110 fOptDstBlend = that.fOptDstBlend; |
| 111 fBlendOptFlags = that.fBlendOptFlags; |
| 117 | 112 |
| 118 fHints = that.fHints; | 113 fHints = that.fHints; |
| 119 | 114 |
| 120 SkRefCnt_SafeAssign(fCachedOptState, that.fCachedOptState); | 115 SkRefCnt_SafeAssign(fCachedOptState, that.fCachedOptState); |
| 121 | 116 |
| 122 memcpy(fFixedFunctionVertexAttribIndices, | 117 memcpy(fFixedFunctionVertexAttribIndices, |
| 123 that.fFixedFunctionVertexAttribIndices, | 118 that.fFixedFunctionVertexAttribIndices, |
| 124 sizeof(fFixedFunctionVertexAttribIndices)); | 119 sizeof(fFixedFunctionVertexAttribIndices)); |
| 125 return *this; | 120 return *this; |
| 126 } | 121 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 292 |
| 298 bool GrDrawState::couldApplyCoverage(const GrDrawTargetCaps& caps) const { | 293 bool GrDrawState::couldApplyCoverage(const GrDrawTargetCaps& caps) const { |
| 299 if (caps.dualSourceBlendingSupport()) { | 294 if (caps.dualSourceBlendingSupport()) { |
| 300 return true; | 295 return true; |
| 301 } | 296 } |
| 302 // we can correctly apply coverage if a) we have dual source blending | 297 // we can correctly apply coverage if a) we have dual source blending |
| 303 // or b) one of our blend optimizations applies | 298 // or b) one of our blend optimizations applies |
| 304 // or c) the src, dst blend coeffs are 1,0 and we will read Dst Color | 299 // or c) the src, dst blend coeffs are 1,0 and we will read Dst Color |
| 305 GrBlendCoeff srcCoeff; | 300 GrBlendCoeff srcCoeff; |
| 306 GrBlendCoeff dstCoeff; | 301 GrBlendCoeff dstCoeff; |
| 307 BlendOptFlags flag = this->getBlendOpts(true, &srcCoeff, &dstCoeff); | 302 GrRODrawState::BlendOptFlags flag = this->getBlendOpts(true, &srcCoeff, &dst
Coeff); |
| 308 return GrRODrawState::kNone_BlendOpt != flag || | 303 return GrRODrawState::kNone_BlendOpt != flag || |
| 309 (this->willEffectReadDstColor() && | 304 (this->willEffectReadDstColor() && |
| 310 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff); | 305 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff); |
| 311 } | 306 } |
| 312 | 307 |
| 313 ////////////////////////////////////////////////////////////////////////////// | 308 ////////////////////////////////////////////////////////////////////////////// |
| 314 | 309 |
| 315 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(GrDrawState* drawS
tate) { | 310 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(GrDrawState* drawS
tate) { |
| 316 SkASSERT(drawState); | 311 SkASSERT(drawState); |
| 317 fDrawState = drawState; | 312 fDrawState = drawState; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | 448 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
| 454 } | 449 } |
| 455 | 450 |
| 456 int numCoverageStages = fDrawState->numCoverageStages(); | 451 int numCoverageStages = fDrawState->numCoverageStages(); |
| 457 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 452 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
| 458 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); | 453 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
| 459 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 454 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
| 460 } | 455 } |
| 461 } | 456 } |
| 462 | 457 |
| 463 //////////////////////////////////////////////////////////////////////////////// | |
| 464 | |
| 465 void GrDrawState::invalidateOptState() const { | |
| 466 SkSafeSetNull(fCachedOptState); | |
| 467 } | |
| 468 | |
| 469 //////////////////////////////////////////////////////////////////////////////// | |
| 470 | |
| 471 GrDrawState::~GrDrawState() { | |
| 472 SkSafeUnref(fCachedOptState); | |
| 473 SkASSERT(0 == fBlockEffectRemovalCnt); | |
| 474 } | |
| 475 | |
| OLD | NEW |