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 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 12 | #include "batches/GrDrawBatch.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) { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 20 | GrInitInvariantOutput out; |
| 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::initUsingInvariantOutput(GrInitInvariantOutput invOutput) { |
| 30 | fInOut.reset(invOutput); |
| 31 | } |
| 32 | |
| 33 | void GrProcOptInfo::completeCalculations(const GrFragmentProcessor * const processors[], int cnt) { |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 34 | this->internalCalc(processors, cnt); |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 35 | } |
| 36 | |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 37 | void GrProcOptInfo::internalCalc(const GrFragmentProcessor* const processors[], int cnt) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 38 | fFirstEffectiveProcessorIndex = 0; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 39 | fInputColorIsUsed = true; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 40 | fInputColor = fInOut.color(); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 41 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 42 | for (int i = 0; i < cnt; ++i) { |
| 43 | const GrFragmentProcessor* processor = processors[i]; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 44 | fInOut.resetWillUseInputColor(); |
| 45 | processor->computeInvariantOutput(&fInOut); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 46 | SkDEBUGCODE(fInOut.validate()); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 47 | if (!fInOut.willUseInputColor()) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 48 | fFirstEffectiveProcessorIndex = i; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 49 | fInputColorIsUsed = false; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 50 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 51 | if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 52 | fFirstEffectiveProcessorIndex = i + 1; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 53 | fInputColor = fInOut.color(); |
| 54 | fInputColorIsUsed = true; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 55 | // Since we are clearing all previous color stages we are in a state where we have found |
| 56 | // zero stages that don't multiply the inputColor. |
| 57 | fInOut.resetNonMulStageFound(); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |