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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 fStencilSettings = that.fStencilSettings; | 50 fStencilSettings = that.fStencilSettings; |
51 fDrawFace = that.fDrawFace; | 51 fDrawFace = that.fDrawFace; |
52 fXPFactory.reset(SkRef(that.getXPFactory())); | 52 fXPFactory.reset(SkRef(that.getXPFactory())); |
53 fColorStages = that.fColorStages; | 53 fColorStages = that.fColorStages; |
54 fCoverageStages = that.fCoverageStages; | 54 fCoverageStages = that.fCoverageStages; |
55 | 55 |
56 fColorProcInfoValid = that.fColorProcInfoValid; | 56 fColorProcInfoValid = that.fColorProcInfoValid; |
57 fCoverageProcInfoValid = that.fCoverageProcInfoValid; | 57 fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
58 fColorCache = that.fColorCache; | 58 fColorCache = that.fColorCache; |
59 fCoverageCache = that.fCoverageCache; | 59 fCoverageCache = that.fCoverageCache; |
60 fColorPrimProc = that.fColorPrimProc; | |
61 fCoveragePrimProc = that.fCoveragePrimProc; | |
62 if (fColorProcInfoValid) { | 60 if (fColorProcInfoValid) { |
63 fColorProcInfo = that.fColorProcInfo; | 61 fColorProcInfo = that.fColorProcInfo; |
64 } | 62 } |
65 if (fCoverageProcInfoValid) { | 63 if (fCoverageProcInfoValid) { |
66 fCoverageProcInfo = that.fCoverageProcInfo; | 64 fCoverageProcInfo = that.fCoverageProcInfo; |
67 } | 65 } |
68 return *this; | 66 return *this; |
69 } | 67 } |
70 | 68 |
71 void GrDrawState::onReset() { | 69 void GrDrawState::onReset() { |
72 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); | 70 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); |
73 fRenderTarget.reset(NULL); | 71 fRenderTarget.reset(NULL); |
74 | 72 |
75 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); | 73 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
76 fColorStages.reset(); | 74 fColorStages.reset(); |
77 fCoverageStages.reset(); | 75 fCoverageStages.reset(); |
78 | 76 |
79 fFlagBits = 0x0; | 77 fFlagBits = 0x0; |
80 fStencilSettings.setDisabled(); | 78 fStencilSettings.setDisabled(); |
81 fDrawFace = kBoth_DrawFace; | 79 fDrawFace = kBoth_DrawFace; |
82 | 80 |
83 fColorProcInfoValid = false; | 81 fColorProcInfoValid = false; |
84 fCoverageProcInfoValid = false; | 82 fCoverageProcInfoValid = false; |
85 | 83 |
86 fColorCache = GrColor_ILLEGAL; | 84 fColorCache = GrColor_ILLEGAL; |
87 fCoverageCache = GrColor_ILLEGAL; | 85 fCoverageCache = GrColor_ILLEGAL; |
88 | |
89 fColorPrimProc = NULL; | |
90 fCoveragePrimProc = NULL; | |
91 } | 86 } |
92 | 87 |
93 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { | 88 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { |
94 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); | 89 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); |
95 | 90 |
96 fColorStages.reset(); | 91 fColorStages.reset(); |
97 fCoverageStages.reset(); | 92 fCoverageStages.reset(); |
98 | 93 |
99 for (int i = 0; i < paint.numColorStages(); ++i) { | 94 for (int i = 0; i < paint.numColorStages(); ++i) { |
100 fColorStages.push_back(paint.getColorStage(i)); | 95 fColorStages.push_back(paint.getColorStage(i)); |
(...skipping 16 matching lines...) Expand all Loading... |
117 this->enableState(GrDrawState::kClip_StateBit); | 112 this->enableState(GrDrawState::kClip_StateBit); |
118 | 113 |
119 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 114 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
120 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 115 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
121 | 116 |
122 fColorProcInfoValid = false; | 117 fColorProcInfoValid = false; |
123 fCoverageProcInfoValid = false; | 118 fCoverageProcInfoValid = false; |
124 | 119 |
125 fColorCache = GrColor_ILLEGAL; | 120 fColorCache = GrColor_ILLEGAL; |
126 fCoverageCache = GrColor_ILLEGAL; | 121 fCoverageCache = GrColor_ILLEGAL; |
127 | |
128 fColorPrimProc = NULL; | |
129 fCoveragePrimProc = NULL; | |
130 } | 122 } |
131 | 123 |
132 //////////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////////// |
133 | 125 |
134 bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCa
ps& caps) const { | 126 bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCa
ps& caps) const { |
135 if (caps.dualSourceBlendingSupport()) { | 127 if (caps.dualSourceBlendingSupport()) { |
136 return true; | 128 return true; |
137 } | 129 } |
138 | 130 |
139 this->calcColorInvariantOutput(color); | 131 this->calcColorInvariantOutput(color); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const { | 185 bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const { |
194 this->calcColorInvariantOutput(pp); | 186 this->calcColorInvariantOutput(pp); |
195 this->calcCoverageInvariantOutput(pp); | 187 this->calcCoverageInvariantOutput(pp); |
196 | 188 |
197 GrXPFactory::InvariantOutput output; | 189 GrXPFactory::InvariantOutput output; |
198 fXPFactory->getInvariantOutput(fColorProcInfo, fCoverageProcInfo, &output); | 190 fXPFactory->getInvariantOutput(fColorProcInfo, fCoverageProcInfo, &output); |
199 return output.fWillBlendWithDst; | 191 return output.fWillBlendWithDst; |
200 } | 192 } |
201 | 193 |
202 void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const
{ | 194 void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const
{ |
203 if (!fColorProcInfoValid || fColorPrimProc != pp) { | 195 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColo
rStages()); |
204 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->num
ColorStages()); | 196 fColorProcInfoValid = false; |
205 fColorProcInfoValid = true; | 197 |
206 fColorPrimProc = pp; | |
207 } | |
208 } | 198 } |
209 | 199 |
210 void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) co
nst { | 200 void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) co
nst { |
211 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) { | 201 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), |
212 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), | 202 this->numCoverageStages()); |
213 this->numCoverageStages()); | 203 fCoverageProcInfoValid = false; |
214 fCoverageProcInfoValid = true; | |
215 fCoveragePrimProc = pp; | |
216 } | |
217 } | 204 } |
218 | 205 |
| 206 void GrDrawState::calcColorInvariantOutput(const GrBatch* batch) const { |
| 207 GrBatchOpt batchOpt; |
| 208 batchOpt.fCanTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 209 fColorProcInfo.calcColorWithBatch(batch, batchOpt, fColorStages.begin(), |
| 210 this->numColorStages()); |
| 211 fColorProcInfoValid = false; |
| 212 } |
| 213 |
| 214 void GrDrawState::calcCoverageInvariantOutput(const GrBatch* batch) const { |
| 215 GrBatchOpt batchOpt; |
| 216 batchOpt.fCanTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 217 fCoverageProcInfo.calcCoverageWithBatch(batch, batchOpt, fCoverageStages.beg
in(), |
| 218 this->numCoverageStages()); |
| 219 fCoverageProcInfoValid = false; |
| 220 } |
| 221 |
| 222 |
219 void GrDrawState::calcColorInvariantOutput(GrColor color) const { | 223 void GrDrawState::calcColorInvariantOutput(GrColor color) const { |
220 if (!fColorProcInfoValid || color != fColorCache) { | 224 if (!fColorProcInfoValid || color != fColorCache) { |
221 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | 225 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
222 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo
rStages(), color, | 226 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo
rStages(), color, |
223 flags, false); | 227 flags, false); |
224 fColorProcInfoValid = true; | 228 fColorProcInfoValid = true; |
225 fColorCache = color; | 229 fColorCache = color; |
226 } | 230 } |
227 } | 231 } |
228 | 232 |
229 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { | 233 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { |
230 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { | 234 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { |
231 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | 235 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
232 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), | 236 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), |
233 this->numCoverageStages(), cover
age, flags, | 237 this->numCoverageStages(), cover
age, flags, |
234 true); | 238 true); |
235 fCoverageProcInfoValid = true; | 239 fCoverageProcInfoValid = true; |
236 fCoverageCache = coverage; | 240 fCoverageCache = coverage; |
237 } | 241 } |
238 } | 242 } |
OLD | NEW |