| 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" |
| 11 #include "GrOptDrawState.h" | 11 #include "GrOptDrawState.h" |
| 12 #include "GrPaint.h" | 12 #include "GrPaint.h" |
| 13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
| 14 #include "GrXferProcessor.h" | 14 #include "GrXferProcessor.h" |
| 15 #include "effects/GrPorterDuffXferProcessor.h" | 15 #include "effects/GrPorterDuffXferProcessor.h" |
| 16 | 16 |
| 17 bool GrDrawState::isEqual(const GrDrawState& that, bool explicitLocalCoords) con
st { | 17 bool GrDrawState::isEqual(const GrDrawState& that, bool explicitLocalCoords) con
st { |
| 18 if (this->getRenderTarget() != that.getRenderTarget() || | 18 if (this->getRenderTarget() != that.getRenderTarget() || |
| 19 this->fColorStages.count() != that.fColorStages.count() || | 19 this->fColorStages.count() != that.fColorStages.count() || |
| 20 this->fCoverageStages.count() != that.fCoverageStages.count() || | 20 this->fCoverageStages.count() != that.fCoverageStages.count() || |
| 21 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || | |
| 22 this->fFlagBits != that.fFlagBits || | 21 this->fFlagBits != that.fFlagBits || |
| 23 this->fStencilSettings != that.fStencilSettings || | 22 this->fStencilSettings != that.fStencilSettings || |
| 24 this->fDrawFace != that.fDrawFace) { | 23 this->fDrawFace != that.fDrawFace) { |
| 25 return false; | 24 return false; |
| 26 } | 25 } |
| 27 | 26 |
| 28 if (!this->getXPFactory()->isEqual(*that.getXPFactory())) { | 27 if (!this->getXPFactory()->isEqual(*that.getXPFactory())) { |
| 29 return false; | 28 return false; |
| 30 } | 29 } |
| 31 | 30 |
| 32 for (int i = 0; i < this->numColorStages(); i++) { | 31 for (int i = 0; i < this->numColorStages(); i++) { |
| 33 if (this->getColorStage(i) != that.getColorStage(i)) { | 32 if (this->getColorStage(i) != that.getColorStage(i)) { |
| 34 return false; | 33 return false; |
| 35 } | 34 } |
| 36 } | 35 } |
| 37 for (int i = 0; i < this->numCoverageStages(); i++) { | 36 for (int i = 0; i < this->numCoverageStages(); i++) { |
| 38 if (this->getCoverageStage(i) != that.getCoverageStage(i)) { | 37 if (this->getCoverageStage(i) != that.getCoverageStage(i)) { |
| 39 return false; | 38 return false; |
| 40 } | 39 } |
| 41 } | 40 } |
| 42 | 41 |
| 43 return true; | 42 return true; |
| 44 } | 43 } |
| 45 | 44 |
| 46 ////////////////////////////////////////////////////////////////////////////// | 45 ////////////////////////////////////////////////////////////////////////////// |
| 47 | 46 |
| 48 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { | 47 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { |
| 49 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); | 48 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); |
| 50 fViewMatrix = that.fViewMatrix; | |
| 51 fFlagBits = that.fFlagBits; | 49 fFlagBits = that.fFlagBits; |
| 52 fStencilSettings = that.fStencilSettings; | 50 fStencilSettings = that.fStencilSettings; |
| 53 fDrawFace = that.fDrawFace; | 51 fDrawFace = that.fDrawFace; |
| 54 fXPFactory.reset(SkRef(that.getXPFactory())); | 52 fXPFactory.reset(SkRef(that.getXPFactory())); |
| 55 fColorStages = that.fColorStages; | 53 fColorStages = that.fColorStages; |
| 56 fCoverageStages = that.fCoverageStages; | 54 fCoverageStages = that.fCoverageStages; |
| 57 | 55 |
| 58 fColorProcInfoValid = that.fColorProcInfoValid; | 56 fColorProcInfoValid = that.fColorProcInfoValid; |
| 59 fCoverageProcInfoValid = that.fCoverageProcInfoValid; | 57 fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
| 60 fColorCache = that.fColorCache; | 58 fColorCache = that.fColorCache; |
| 61 fCoverageCache = that.fCoverageCache; | 59 fCoverageCache = that.fCoverageCache; |
| 62 fColorPrimProc = that.fColorPrimProc; | 60 fColorPrimProc = that.fColorPrimProc; |
| 63 fCoveragePrimProc = that.fCoveragePrimProc; | 61 fCoveragePrimProc = that.fCoveragePrimProc; |
| 64 if (fColorProcInfoValid) { | 62 if (fColorProcInfoValid) { |
| 65 fColorProcInfo = that.fColorProcInfo; | 63 fColorProcInfo = that.fColorProcInfo; |
| 66 } | 64 } |
| 67 if (fCoverageProcInfoValid) { | 65 if (fCoverageProcInfoValid) { |
| 68 fCoverageProcInfo = that.fCoverageProcInfo; | 66 fCoverageProcInfo = that.fCoverageProcInfo; |
| 69 } | 67 } |
| 70 return *this; | 68 return *this; |
| 71 } | 69 } |
| 72 | 70 |
| 73 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { | 71 void GrDrawState::onReset() { |
| 74 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); | 72 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); |
| 75 fRenderTarget.reset(NULL); | 73 fRenderTarget.reset(NULL); |
| 76 | 74 |
| 77 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); | 75 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
| 78 fColorStages.reset(); | 76 fColorStages.reset(); |
| 79 fCoverageStages.reset(); | 77 fCoverageStages.reset(); |
| 80 | 78 |
| 81 if (NULL == initialViewMatrix) { | |
| 82 fViewMatrix.reset(); | |
| 83 } else { | |
| 84 fViewMatrix = *initialViewMatrix; | |
| 85 } | |
| 86 fFlagBits = 0x0; | 79 fFlagBits = 0x0; |
| 87 fStencilSettings.setDisabled(); | 80 fStencilSettings.setDisabled(); |
| 88 fDrawFace = kBoth_DrawFace; | 81 fDrawFace = kBoth_DrawFace; |
| 89 | 82 |
| 90 fColorProcInfoValid = false; | 83 fColorProcInfoValid = false; |
| 91 fCoverageProcInfoValid = false; | 84 fCoverageProcInfoValid = false; |
| 92 | 85 |
| 93 fColorCache = GrColor_ILLEGAL; | 86 fColorCache = GrColor_ILLEGAL; |
| 94 fCoverageCache = GrColor_ILLEGAL; | 87 fCoverageCache = GrColor_ILLEGAL; |
| 95 | 88 |
| 96 fColorPrimProc = NULL; | 89 fColorPrimProc = NULL; |
| 97 fCoveragePrimProc = NULL; | 90 fCoveragePrimProc = NULL; |
| 98 } | 91 } |
| 99 | 92 |
| 100 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
rTarget* rt) { | 93 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { |
| 101 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); | 94 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); |
| 102 | 95 |
| 103 fColorStages.reset(); | 96 fColorStages.reset(); |
| 104 fCoverageStages.reset(); | 97 fCoverageStages.reset(); |
| 105 | 98 |
| 106 for (int i = 0; i < paint.numColorStages(); ++i) { | 99 for (int i = 0; i < paint.numColorStages(); ++i) { |
| 107 fColorStages.push_back(paint.getColorStage(i)); | 100 fColorStages.push_back(paint.getColorStage(i)); |
| 108 } | 101 } |
| 109 | 102 |
| 110 for (int i = 0; i < paint.numCoverageStages(); ++i) { | 103 for (int i = 0; i < paint.numCoverageStages(); ++i) { |
| 111 fCoverageStages.push_back(paint.getCoverageStage(i)); | 104 fCoverageStages.push_back(paint.getCoverageStage(i)); |
| 112 } | 105 } |
| 113 | 106 |
| 114 fXPFactory.reset(SkRef(paint.getXPFactory())); | 107 fXPFactory.reset(SkRef(paint.getXPFactory())); |
| 115 | 108 |
| 116 this->setRenderTarget(rt); | 109 this->setRenderTarget(rt); |
| 117 | 110 |
| 118 fViewMatrix = vm; | |
| 119 | |
| 120 // These have no equivalent in GrPaint, set them to defaults | 111 // These have no equivalent in GrPaint, set them to defaults |
| 121 fDrawFace = kBoth_DrawFace; | 112 fDrawFace = kBoth_DrawFace; |
| 122 fStencilSettings.setDisabled(); | 113 fStencilSettings.setDisabled(); |
| 123 fFlagBits = 0; | 114 fFlagBits = 0; |
| 124 | 115 |
| 125 // Enable the clip bit | 116 // Enable the clip bit |
| 126 this->enableState(GrDrawState::kClip_StateBit); | 117 this->enableState(GrDrawState::kClip_StateBit); |
| 127 | 118 |
| 128 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 119 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
| 129 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 120 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { | 232 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { |
| 242 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { | 233 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { |
| 243 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | 234 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
| 244 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), | 235 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), |
| 245 this->numCoverageStages(), cover
age, flags, | 236 this->numCoverageStages(), cover
age, flags, |
| 246 true); | 237 true); |
| 247 fCoverageProcInfoValid = true; | 238 fCoverageProcInfoValid = true; |
| 248 fCoverageCache = coverage; | 239 fCoverageCache = coverage; |
| 249 } | 240 } |
| 250 } | 241 } |
| OLD | NEW |