egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrProcOptInfo.h" |
| 9 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 10 | #include "GrGeometryProcessor.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 11 | |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 12 | #include "ops/GrDrawOp.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 13 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 14 | void GrProcOptInfo::calcWithInitialValues(const GrFragmentProcessor * const processors[], |
| 15 | int cnt, |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 16 | GrColor startColor, |
| 17 | GrColorComponentFlags flags, |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 18 | bool areCoverageStages, |
| 19 | bool isLCD) { |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 20 | GrPipelineInput out; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 21 | out.fIsSingleComponent = areCoverageStages; |
| 22 | out.fColor = startColor; |
| 23 | out.fValidFlags = flags; |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 24 | out.fIsLCDCoverage = isLCD; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 25 | fInOut.reset(out); |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 26 | this->internalCalc(processors, cnt); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 27 | } |
| 28 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 29 | void GrProcOptInfo::completeCalculations(const GrFragmentProcessor * const processors[], int cnt) { |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 30 | this->internalCalc(processors, cnt); |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 31 | } |
| 32 | |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 33 | void GrProcOptInfo::internalCalc(const GrFragmentProcessor* const processors[], int cnt) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 34 | fFirstEffectiveProcessorIndex = 0; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 35 | fInputColorIsUsed = true; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 36 | fInputColor = fInOut.color(); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 37 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 38 | for (int i = 0; i < cnt; ++i) { |
| 39 | const GrFragmentProcessor* processor = processors[i]; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 40 | fInOut.resetWillUseInputColor(); |
| 41 | processor->computeInvariantOutput(&fInOut); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 42 | SkDEBUGCODE(fInOut.validate()); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 43 | if (!fInOut.willUseInputColor()) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 44 | fFirstEffectiveProcessorIndex = i; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 45 | fInputColorIsUsed = false; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 46 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 47 | if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 48 | fFirstEffectiveProcessorIndex = i + 1; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 49 | fInputColor = fInOut.color(); |
| 50 | fInputColorIsUsed = true; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 51 | // Since we are clearing all previous color stages we are in a state where we have found |
| 52 | // zero stages that don't multiply the inputColor. |
| 53 | fInOut.resetNonMulStageFound(); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | } |