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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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; | 60 fColorPrimProc = that.fColorPrimProc; |
61 fCoveragePrimProc = that.fCoveragePrimProc; | 61 fCoveragePrimProc = that.fCoveragePrimProc; |
62 fColorBatch = that.fColorBatch; | |
63 fCoverageBatch = that.fCoverageBatch; | |
62 if (fColorProcInfoValid) { | 64 if (fColorProcInfoValid) { |
63 fColorProcInfo = that.fColorProcInfo; | 65 fColorProcInfo = that.fColorProcInfo; |
64 } | 66 } |
65 if (fCoverageProcInfoValid) { | 67 if (fCoverageProcInfoValid) { |
66 fCoverageProcInfo = that.fCoverageProcInfo; | 68 fCoverageProcInfo = that.fCoverageProcInfo; |
67 } | 69 } |
68 return *this; | 70 return *this; |
69 } | 71 } |
70 | 72 |
71 void GrDrawState::onReset() { | 73 void GrDrawState::onReset() { |
72 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); | 74 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); |
73 fRenderTarget.reset(NULL); | 75 fRenderTarget.reset(NULL); |
74 | 76 |
75 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); | 77 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
76 fColorStages.reset(); | 78 fColorStages.reset(); |
77 fCoverageStages.reset(); | 79 fCoverageStages.reset(); |
78 | 80 |
79 fFlagBits = 0x0; | 81 fFlagBits = 0x0; |
80 fStencilSettings.setDisabled(); | 82 fStencilSettings.setDisabled(); |
81 fDrawFace = kBoth_DrawFace; | 83 fDrawFace = kBoth_DrawFace; |
82 | 84 |
83 fColorProcInfoValid = false; | 85 fColorProcInfoValid = false; |
84 fCoverageProcInfoValid = false; | 86 fCoverageProcInfoValid = false; |
85 | 87 |
86 fColorCache = GrColor_ILLEGAL; | 88 fColorCache = GrColor_ILLEGAL; |
87 fCoverageCache = GrColor_ILLEGAL; | 89 fCoverageCache = GrColor_ILLEGAL; |
88 | 90 |
89 fColorPrimProc = NULL; | 91 fColorPrimProc = NULL; |
90 fCoveragePrimProc = NULL; | 92 fCoveragePrimProc = NULL; |
93 | |
94 fColorBatch = NULL; | |
95 fCoverageBatch = NULL; | |
91 } | 96 } |
92 | 97 |
93 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { | 98 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { |
94 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); | 99 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); |
95 | 100 |
96 fColorStages.reset(); | 101 fColorStages.reset(); |
97 fCoverageStages.reset(); | 102 fCoverageStages.reset(); |
98 | 103 |
99 for (int i = 0; i < paint.numColorStages(); ++i) { | 104 for (int i = 0; i < paint.numColorStages(); ++i) { |
100 fColorStages.push_back(paint.getColorStage(i)); | 105 fColorStages.push_back(paint.getColorStage(i)); |
(...skipping 19 matching lines...) Expand all Loading... | |
120 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 125 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
121 | 126 |
122 fColorProcInfoValid = false; | 127 fColorProcInfoValid = false; |
123 fCoverageProcInfoValid = false; | 128 fCoverageProcInfoValid = false; |
124 | 129 |
125 fColorCache = GrColor_ILLEGAL; | 130 fColorCache = GrColor_ILLEGAL; |
126 fCoverageCache = GrColor_ILLEGAL; | 131 fCoverageCache = GrColor_ILLEGAL; |
127 | 132 |
128 fColorPrimProc = NULL; | 133 fColorPrimProc = NULL; |
129 fCoveragePrimProc = NULL; | 134 fCoveragePrimProc = NULL; |
135 | |
136 fColorBatch = NULL; | |
137 fCoverageBatch = NULL; | |
130 } | 138 } |
131 | 139 |
132 //////////////////////////////////////////////////////////////////////////////// | 140 //////////////////////////////////////////////////////////////////////////////// |
133 | 141 |
134 bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCa ps& caps) const { | 142 bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCa ps& caps) const { |
135 if (caps.dualSourceBlendingSupport()) { | 143 if (caps.dualSourceBlendingSupport()) { |
136 return true; | 144 return true; |
137 } | 145 } |
138 | 146 |
139 this->calcColorInvariantOutput(color); | 147 this->calcColorInvariantOutput(color); |
140 | 148 |
141 // The coverage isn't actually white, its unknown, but this will produce the same effect | 149 // The coverage isn't actually white, its unknown, but this will produce the same effect |
142 // TODO we want to cache the result of this call, but we can probably clean up the interface | 150 // TODO we want to cache the result of this call, but we can probably clean up the interface |
143 // so we don't have to pass in a seemingly known coverage | 151 // so we don't have to pass in a seemingly known coverage |
144 this->calcCoverageInvariantOutput(GrColor_WHITE); | 152 this->calcCoverageInvariantOutput(GrColor_WHITE); |
145 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo); | 153 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo); |
146 } | 154 } |
147 | 155 |
148 //////////////////////////////////////////////////////////////////////////////s | 156 //////////////////////////////////////////////////////////////////////////////s |
149 | 157 |
150 bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp) const { | 158 bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp) const { |
151 this->calcColorInvariantOutput(pp); | 159 this->calcColorInvariantOutput(pp); |
152 this->calcCoverageInvariantOutput(pp); | 160 this->calcCoverageInvariantOutput(pp); |
153 | 161 |
154 return fXPFactory->willReadDst(fColorProcInfo, fCoverageProcInfo); | 162 return fXPFactory->willReadDst(fColorProcInfo, fCoverageProcInfo); |
155 } | 163 } |
156 | 164 |
165 bool GrDrawState::willEffectReadDstColor(const GrBatch* batch) const { | |
166 this->calcColorInvariantOutput(batch); | |
167 this->calcCoverageInvariantOutput(batch); | |
168 | |
169 return fXPFactory->willReadDst(fColorProcInfo, fCoverageProcInfo); | |
170 } | |
171 | |
172 | |
157 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { | 173 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { |
158 if (fDrawState) { | 174 if (fDrawState) { |
159 int m = fDrawState->numColorStages() - fColorEffectCnt; | 175 int m = fDrawState->numColorStages() - fColorEffectCnt; |
160 SkASSERT(m >= 0); | 176 SkASSERT(m >= 0); |
161 fDrawState->fColorStages.pop_back_n(m); | 177 fDrawState->fColorStages.pop_back_n(m); |
162 | 178 |
163 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; | 179 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; |
164 SkASSERT(n >= 0); | 180 SkASSERT(n >= 0); |
165 fDrawState->fCoverageStages.pop_back_n(n); | 181 fDrawState->fCoverageStages.pop_back_n(n); |
166 if (m + n > 0) { | 182 if (m + n > 0) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 | 228 |
213 void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) co nst { | 229 void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) co nst { |
214 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) { | 230 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) { |
215 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), | 231 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), |
216 this->numCoverageStages()); | 232 this->numCoverageStages()); |
217 fCoverageProcInfoValid = true; | 233 fCoverageProcInfoValid = true; |
218 fCoveragePrimProc = pp; | 234 fCoveragePrimProc = pp; |
219 } | 235 } |
220 } | 236 } |
221 | 237 |
238 void GrDrawState::calcColorInvariantOutput(const GrBatch* batch) const { | |
239 if (!fColorProcInfoValid || fColorBatch != batch) { | |
bsalomon
2015/01/20 16:14:02
all this storing of mutable ptrs seems very fragil
joshualitt
2015/01/20 17:03:08
How could we assign a uniqueID to each batch witho
bsalomon
2015/01/20 20:49:58
I mean its fragile because two batches that exist
| |
240 GrBatchOpt batchOpt; | |
241 batchOpt.fCanTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | |
242 fColorProcInfo.calcColorWithBatch(batch, batchOpt, fColorStages.begin(), | |
243 this->numColorStages()); | |
244 fColorProcInfoValid = true; | |
245 fColorBatch = batch; | |
246 } | |
247 } | |
248 | |
249 void GrDrawState::calcCoverageInvariantOutput(const GrBatch* batch) const { | |
250 if (!fCoverageProcInfoValid || fCoverageBatch != batch) { | |
251 GrBatchOpt batchOpt; | |
252 batchOpt.fCanTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | |
253 fCoverageProcInfo.calcCoverageWithBatch(batch, batchOpt, fCoverageStages .begin(), | |
254 this->numCoverageStages()); | |
255 fCoverageProcInfoValid = true; | |
256 fCoverageBatch = batch; | |
257 } | |
258 } | |
259 | |
260 | |
222 void GrDrawState::calcColorInvariantOutput(GrColor color) const { | 261 void GrDrawState::calcColorInvariantOutput(GrColor color) const { |
223 if (!fColorProcInfoValid || color != fColorCache) { | 262 if (!fColorProcInfoValid || color != fColorCache) { |
224 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | 263 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
225 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo rStages(), color, | 264 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo rStages(), color, |
226 flags, false); | 265 flags, false); |
227 fColorProcInfoValid = true; | 266 fColorProcInfoValid = true; |
228 fColorCache = color; | 267 fColorCache = color; |
229 } | 268 } |
230 } | 269 } |
231 | 270 |
232 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { | 271 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { |
233 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { | 272 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { |
234 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | 273 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
235 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), | 274 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), |
236 this->numCoverageStages(), cover age, flags, | 275 this->numCoverageStages(), cover age, flags, |
237 true); | 276 true); |
238 fCoverageProcInfoValid = true; | 277 fCoverageProcInfoValid = true; |
239 fCoverageCache = coverage; | 278 fCoverageCache = coverage; |
240 } | 279 } |
241 } | 280 } |
OLD | NEW |