OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrOptDrawState.h" | 8 #include "GrOptDrawState.h" |
9 | 9 |
10 #include "GrDrawState.h" | 10 #include "GrDrawState.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 memcpy(fFixedFunctionVertexAttribIndices, | 33 memcpy(fFixedFunctionVertexAttribIndices, |
34 drawState.getFixedFunctionVertexAttribIndices(), | 34 drawState.getFixedFunctionVertexAttribIndices(), |
35 sizeof(fFixedFunctionVertexAttribIndices)); | 35 sizeof(fFixedFunctionVertexAttribIndices)); |
36 | 36 |
37 | 37 |
38 fInputColorIsUsed = true; | 38 fInputColorIsUsed = true; |
39 fInputCoverageIsUsed = true; | 39 fInputCoverageIsUsed = true; |
40 | 40 |
41 if (drawState.hasGeometryProcessor()) { | 41 if (drawState.hasGeometryProcessor()) { |
42 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*drawState.getGeomet
ryProcessor()))); | 42 fGeometryProcessor.reset(SkNEW_ARGS(GrGeometryStage, (*drawState.getGeom
etryProcessor()))); |
43 } else { | 43 } else { |
44 fGeometryProcessor.reset(NULL); | 44 fGeometryProcessor.reset(NULL); |
45 } | 45 } |
46 | 46 |
47 this->copyEffectiveColorStages(drawState); | 47 this->copyEffectiveColorStages(drawState); |
48 this->copyEffectiveCoverageStages(drawState); | 48 this->copyEffectiveCoverageStages(drawState); |
49 this->adjustFromBlendOpts(); | 49 this->adjustFromBlendOpts(); |
50 this->getStageStats(); | 50 this->getStageStats(); |
51 this->setOutputStateInfo(caps); | 51 this->setOutputStateInfo(caps); |
52 }; | 52 }; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if (ds.vertexColorsAreOpaque()) { | 177 if (ds.vertexColorsAreOpaque()) { |
178 color = 0xFF << GrColor_SHIFT_A; | 178 color = 0xFF << GrColor_SHIFT_A; |
179 validComponentFlags = kA_GrColorComponentFlag; | 179 validComponentFlags = kA_GrColorComponentFlag; |
180 } else { | 180 } else { |
181 validComponentFlags = 0; | 181 validComponentFlags = 0; |
182 color = 0; // not strictly necessary but we get false alarms from to
ols about uninit. | 182 color = 0; // not strictly necessary but we get false alarms from to
ols about uninit. |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 for (int i = 0; i < ds.numColorStages(); ++i) { | 186 for (int i = 0; i < ds.numColorStages(); ++i) { |
187 const GrEffect* effect = ds.getColorStage(i).getEffect(); | 187 const GrFragmentProcessor* fp = ds.getColorStage(i).getFragmentProcessor
(); |
188 if (!effect->willUseInputColor()) { | 188 if (!fp->willUseInputColor()) { |
189 firstColorStage = i; | 189 firstColorStage = i; |
190 fInputColorIsUsed = false; | 190 fInputColorIsUsed = false; |
191 } | 191 } |
192 effect->getConstantColorComponents(&color, &validComponentFlags); | 192 fp->getConstantColorComponents(&color, &validComponentFlags); |
193 if (kRGBA_GrColorComponentFlags == validComponentFlags) { | 193 if (kRGBA_GrColorComponentFlags == validComponentFlags) { |
194 firstColorStage = i + 1; | 194 firstColorStage = i + 1; |
195 fColor = color; | 195 fColor = color; |
196 fInputColorIsUsed = true; | 196 fInputColorIsUsed = true; |
197 this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribB
inding); | 197 this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribB
inding); |
198 } | 198 } |
199 } | 199 } |
200 if (firstColorStage < ds.numColorStages()) { | 200 if (firstColorStage < ds.numColorStages()) { |
201 fColorStages.reset(&ds.getColorStage(firstColorStage), | 201 fColorStages.reset(&ds.getColorStage(firstColorStage), |
202 ds.numColorStages() - firstColorStage); | 202 ds.numColorStages() - firstColorStage); |
203 } else { | 203 } else { |
204 fColorStages.reset(); | 204 fColorStages.reset(); |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 void GrOptDrawState::copyEffectiveCoverageStages(const GrDrawState& ds) { | 208 void GrOptDrawState::copyEffectiveCoverageStages(const GrDrawState& ds) { |
209 int firstCoverageStage = 0; | 209 int firstCoverageStage = 0; |
210 | 210 |
211 // We do not try to optimize out constantColor coverage effects here. It is
extremely rare | 211 // We do not try to optimize out constantColor coverage effects here. It is
extremely rare |
212 // to have a coverage effect that returns a constant value for all four chan
nels. Thus we | 212 // to have a coverage effect that returns a constant value for all four chan
nels. Thus we |
213 // save having to make extra virtual calls by not checking for it. | 213 // save having to make extra virtual calls by not checking for it. |
214 | 214 |
215 // Don't do any optimizations on coverage stages. It should not be the case
where we do not use | 215 // Don't do any optimizations on coverage stages. It should not be the case
where we do not use |
216 // input coverage in an effect | 216 // input coverage in an effect |
217 #ifdef OptCoverageStages | 217 #ifdef OptCoverageStages |
218 for (int i = 0; i < ds.numCoverageStages(); ++i) { | 218 for (int i = 0; i < ds.numCoverageStages(); ++i) { |
219 const GrEffect* effect = ds.getCoverageStage(i).getEffect(); | 219 const GrProcessor* processor = ds.getCoverageStage(i).getProcessor(); |
220 if (!effect->willUseInputColor()) { | 220 if (!processor->willUseInputColor()) { |
221 firstCoverageStage = i; | 221 firstCoverageStage = i; |
222 fInputCoverageIsUsed = false; | 222 fInputCoverageIsUsed = false; |
223 } | 223 } |
224 } | 224 } |
225 #endif | 225 #endif |
226 if (ds.numCoverageStages() > 0) { | 226 if (ds.numCoverageStages() > 0) { |
227 fCoverageStages.reset(&ds.getCoverageStage(firstCoverageStage), | 227 fCoverageStages.reset(&ds.getCoverageStage(firstCoverageStage), |
228 ds.numCoverageStages() - firstCoverageStage); | 228 ds.numCoverageStages() - firstCoverageStage); |
229 } else { | 229 } else { |
230 fCoverageStages.reset(); | 230 fCoverageStages.reset(); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 static void get_stage_stats(const GrEffectStage& stage, bool* readsDst, bool* re
adsFragPosition) { | 234 static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool*
readsFragPosition) { |
235 if (stage.getEffect()->willReadDstColor()) { | 235 if (stage.getFragmentProcessor()->willReadDstColor()) { |
236 *readsDst = true; | 236 *readsDst = true; |
237 } | 237 } |
238 if (stage.getEffect()->willReadFragmentPosition()) { | 238 if (stage.getFragmentProcessor()->willReadFragmentPosition()) { |
239 *readsFragPosition = true; | 239 *readsFragPosition = true; |
240 } | 240 } |
241 } | 241 } |
| 242 |
242 void GrOptDrawState::getStageStats() { | 243 void GrOptDrawState::getStageStats() { |
243 // We will need a local coord attrib if there is one currently set on the op
tState and we are | 244 // We will need a local coord attrib if there is one currently set on the op
tState and we are |
244 // actually generating some effect code | 245 // actually generating some effect code |
245 fRequiresLocalCoordAttrib = this->hasLocalCoordAttribute() && this->numTotal
Stages() > 0; | 246 fRequiresLocalCoordAttrib = this->hasLocalCoordAttribute() && this->numTotal
Stages() > 0; |
246 | 247 |
247 // if 1 == fVACount then that VA must be position, otherwise it contains som
e attribute which | 248 // if 1 == fVACount then that VA must be position, otherwise it contains som
e attribute which |
248 // will require a vertexShader | 249 // will require a vertexShader |
249 fRequiresVertexShader = fVACount > 1; | 250 fRequiresVertexShader = fVACount > 1; |
250 | 251 |
251 fReadsDst = false; | 252 fReadsDst = false; |
252 fReadsFragPosition = false; | 253 fReadsFragPosition = false; |
253 | 254 |
254 for (int s = 0; s < this->numColorStages(); ++s) { | 255 for (int s = 0; s < this->numColorStages(); ++s) { |
255 const GrEffectStage& stage = this->getColorStage(s); | 256 const GrFragmentStage& stage = this->getColorStage(s); |
256 get_stage_stats(stage, &fReadsDst, &fReadsFragPosition); | 257 get_stage_stats(stage, &fReadsDst, &fReadsFragPosition); |
257 } | 258 } |
258 for (int s = 0; s < this->numCoverageStages(); ++s) { | 259 for (int s = 0; s < this->numCoverageStages(); ++s) { |
259 const GrEffectStage& stage = this->getCoverageStage(s); | 260 const GrFragmentStage& stage = this->getCoverageStage(s); |
260 get_stage_stats(stage, &fReadsDst, &fReadsFragPosition); | 261 get_stage_stats(stage, &fReadsDst, &fReadsFragPosition); |
261 } | 262 } |
262 if (this->hasGeometryProcessor()) { | 263 if (this->hasGeometryProcessor()) { |
263 const GrEffectStage& stage = *this->getGeometryProcessor(); | 264 const GrGeometryStage& stage = *this->getGeometryProcessor(); |
264 get_stage_stats(stage, &fReadsDst, &fReadsFragPosition); | 265 fReadsFragPosition = fReadsFragPosition || stage.getProcessor()->willRea
dFragmentPosition(); |
265 SkASSERT(fRequiresVertexShader); | 266 SkASSERT(fRequiresVertexShader); |
266 } | 267 } |
267 } | 268 } |
268 | 269 |
269 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { | 270 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { |
270 return this->isEqual(that); | 271 return this->isEqual(that); |
271 } | 272 } |
272 | 273 |
OLD | NEW |