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 "GrFragmentProcessor.h" |
egdaniel | 8d95ffa | 2014-12-08 13:26:43 -0800 | [diff] [blame] | 11 | #include "GrFragmentStage.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 13 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 14 | void GrProcOptInfo::calcColorWithPrimProc(const GrPrimitiveProcessor* primProc, |
| 15 | const GrFragmentStage* stages, |
| 16 | int stageCount) { |
| 17 | GrInitInvariantOutput out; |
| 18 | primProc->getInvariantOutputColor(&out); |
| 19 | fInOut.reset(out); |
| 20 | this->internalCalc(stages, stageCount, primProc->willReadFragmentPosition()); |
| 21 | } |
| 22 | |
| 23 | void GrProcOptInfo::calcCoverageWithPrimProc(const GrPrimitiveProcessor* primProc, |
| 24 | const GrFragmentStage* stages, |
| 25 | int stageCount) { |
| 26 | GrInitInvariantOutput out; |
| 27 | primProc->getInvariantOutputCoverage(&out); |
| 28 | fInOut.reset(out); |
| 29 | this->internalCalc(stages, stageCount, primProc->willReadFragmentPosition()); |
| 30 | } |
| 31 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 32 | void GrProcOptInfo::calcWithInitialValues(const GrFragmentStage* stages, |
| 33 | int stageCount, |
| 34 | GrColor startColor, |
| 35 | GrColorComponentFlags flags, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 36 | bool areCoverageStages) { |
| 37 | GrInitInvariantOutput out; |
| 38 | out.fIsSingleComponent = areCoverageStages; |
| 39 | out.fColor = startColor; |
| 40 | out.fValidFlags = flags; |
| 41 | fInOut.reset(out); |
| 42 | this->internalCalc(stages, stageCount, false); |
| 43 | } |
| 44 | |
| 45 | void GrProcOptInfo::internalCalc(const GrFragmentStage* stages, |
| 46 | int stageCount, |
| 47 | bool initWillReadFragmentPosition) { |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 48 | fFirstEffectStageIndex = 0; |
| 49 | fInputColorIsUsed = true; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 50 | fInputColor = fInOut.color(); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 51 | fReadsFragPosition = initWillReadFragmentPosition; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 52 | |
| 53 | for (int i = 0; i < stageCount; ++i) { |
joshualitt | 40d4bd8 | 2014-12-29 09:04:40 -0800 | [diff] [blame] | 54 | const GrFragmentProcessor* processor = stages[i].processor(); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 55 | fInOut.resetWillUseInputColor(); |
| 56 | processor->computeInvariantOutput(&fInOut); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 57 | SkDEBUGCODE(fInOut.validate()); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 58 | if (!fInOut.willUseInputColor()) { |
| 59 | fFirstEffectStageIndex = i; |
| 60 | fInputColorIsUsed = false; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 61 | // Reset these since we don't care if previous stages read these values |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 62 | fReadsFragPosition = initWillReadFragmentPosition; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 63 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 64 | if (processor->willReadFragmentPosition()) { |
| 65 | fReadsFragPosition = true; |
| 66 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 67 | if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) { |
| 68 | fFirstEffectStageIndex = i + 1; |
| 69 | fInputColor = fInOut.color(); |
| 70 | fInputColorIsUsed = true; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 71 | // Since we are clearing all previous color stages we are in a state where we have found |
| 72 | // zero stages that don't multiply the inputColor. |
| 73 | fInOut.resetNonMulStageFound(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 74 | // Reset these since we don't care if previous stages read these values |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 75 | fReadsFragPosition = initWillReadFragmentPosition; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | } |