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 "GrProcOptInfo.h" | 8 #include "GrProcOptInfo.h" |
9 | 9 |
10 #include "GrFragmentProcessor.h" | 10 #include "GrFragmentProcessor.h" |
11 #include "GrFragmentStage.h" | 11 #include "GrFragmentStage.h" |
12 #include "GrGeometryProcessor.h" | 12 #include "GrGeometryProcessor.h" |
13 | 13 |
| 14 void GrProcOptInfo::calcColorWithPrimProc(const GrPrimitiveProcessor* pp, |
| 15 const GrFragmentStage* stages, |
| 16 int stageCount) { |
| 17 GrInitInvariantOutput out; |
| 18 pp->computeOutputColor(&out); |
| 19 fInOut.reset(out); |
| 20 this->internalCalc(stages, stageCount); |
| 21 } |
| 22 |
| 23 void GrProcOptInfo::calcCoverageWithPrimProc(const GrPrimitiveProcessor* pp, |
| 24 const GrFragmentStage* stages, |
| 25 int stageCount) { |
| 26 GrInitInvariantOutput out; |
| 27 pp->computeOutputCoverage(&out); |
| 28 fInOut.reset(out); |
| 29 this->internalCalc(stages, stageCount); |
| 30 } |
| 31 |
14 void GrProcOptInfo::calcWithInitialValues(const GrFragmentStage* stages, | 32 void GrProcOptInfo::calcWithInitialValues(const GrFragmentStage* stages, |
15 int stageCount, | 33 int stageCount, |
16 GrColor startColor, | 34 GrColor startColor, |
17 GrColorComponentFlags flags, | 35 GrColorComponentFlags flags, |
18 bool areCoverageStages, | 36 bool areCoverageStages) { |
19 const GrGeometryProcessor* gp) { | 37 GrInitInvariantOutput out; |
20 fInOut.reset(startColor, flags, areCoverageStages); | 38 out.fIsSingleComponent = areCoverageStages; |
| 39 out.fColor = startColor; |
| 40 out.fValidFlags = flags; |
| 41 this->internalCalc(stages, stageCount); |
| 42 } |
| 43 |
| 44 void GrProcOptInfo::internalCalc(const GrFragmentStage* stages, int stageCount)
{ |
21 fFirstEffectStageIndex = 0; | 45 fFirstEffectStageIndex = 0; |
22 fInputColorIsUsed = true; | 46 fInputColorIsUsed = true; |
23 fInputColor = startColor; | 47 fInputColor = fInOut.color(); |
24 fRemoveVertexAttrib = false; | 48 fRemoveVertexAttrib = false; |
25 fReadsDst = false; | 49 fReadsDst = false; |
26 fReadsFragPosition = false; | 50 fReadsFragPosition = false; |
27 | 51 |
28 if (areCoverageStages && gp) { | |
29 gp->computeInvariantOutput(&fInOut); | |
30 } | |
31 | |
32 for (int i = 0; i < stageCount; ++i) { | 52 for (int i = 0; i < stageCount; ++i) { |
33 const GrFragmentProcessor* processor = stages[i].getProcessor(); | 53 const GrFragmentProcessor* processor = stages[i].getProcessor(); |
34 fInOut.resetWillUseInputColor(); | 54 fInOut.resetWillUseInputColor(); |
35 processor->computeInvariantOutput(&fInOut); | 55 processor->computeInvariantOutput(&fInOut); |
36 #ifdef SK_DEBUG | 56 SkDEBUGCODE(fInOut.validate()); |
37 fInOut.validate(); | |
38 #endif | |
39 if (!fInOut.willUseInputColor()) { | 57 if (!fInOut.willUseInputColor()) { |
40 fFirstEffectStageIndex = i; | 58 fFirstEffectStageIndex = i; |
41 fInputColorIsUsed = false; | 59 fInputColorIsUsed = false; |
42 // Reset these since we don't care if previous stages read these val
ues | 60 // Reset these since we don't care if previous stages read these val
ues |
43 fReadsDst = false; | 61 fReadsDst = false; |
44 fReadsFragPosition = false; | 62 fReadsFragPosition = false; |
45 } | 63 } |
46 if (processor->willReadDstColor()) { | 64 if (processor->willReadDstColor()) { |
47 fReadsDst = true; | 65 fReadsDst = true; |
48 } | 66 } |
49 if (processor->willReadFragmentPosition()) { | 67 if (processor->willReadFragmentPosition()) { |
50 fReadsFragPosition = true; | 68 fReadsFragPosition = true; |
51 } | 69 } |
52 if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) { | 70 if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) { |
53 fFirstEffectStageIndex = i + 1; | 71 fFirstEffectStageIndex = i + 1; |
54 fInputColor = fInOut.color(); | 72 fInputColor = fInOut.color(); |
55 fInputColorIsUsed = true; | 73 fInputColorIsUsed = true; |
56 fRemoveVertexAttrib = true; | 74 fRemoveVertexAttrib = true; |
57 // Since we are clearing all previous color stages we are in a state
where we have found | 75 // Since we are clearing all previous color stages we are in a state
where we have found |
58 // zero stages that don't multiply the inputColor. | 76 // zero stages that don't multiply the inputColor. |
59 fInOut.resetNonMulStageFound(); | 77 fInOut.resetNonMulStageFound(); |
60 // Reset these since we don't care if previous stages read these val
ues | 78 // Reset these since we don't care if previous stages read these val
ues |
61 fReadsDst = false; | 79 fReadsDst = false; |
62 fReadsFragPosition = false; | 80 fReadsFragPosition = false; |
63 } | 81 } |
64 } | 82 } |
65 } | 83 } |
66 | |
OLD | NEW |