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(); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 51 | fReadsDst = false; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 52 | fReadsFragPosition = initWillReadFragmentPosition; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 53 | |
| 54 | for (int i = 0; i < stageCount; ++i) { |
joshualitt | 40d4bd8 | 2014-12-29 09:04:40 -0800 | [diff] [blame^] | 55 | const GrFragmentProcessor* processor = stages[i].processor(); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 56 | fInOut.resetWillUseInputColor(); |
| 57 | processor->computeInvariantOutput(&fInOut); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 58 | SkDEBUGCODE(fInOut.validate()); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 59 | if (!fInOut.willUseInputColor()) { |
| 60 | fFirstEffectStageIndex = i; |
| 61 | fInputColorIsUsed = false; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 62 | // Reset these since we don't care if previous stages read these values |
| 63 | fReadsDst = false; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 64 | fReadsFragPosition = initWillReadFragmentPosition; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 65 | } |
| 66 | if (processor->willReadDstColor()) { |
| 67 | fReadsDst = true; |
| 68 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 69 | if (processor->willReadFragmentPosition()) { |
| 70 | fReadsFragPosition = true; |
| 71 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 72 | if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) { |
| 73 | fFirstEffectStageIndex = i + 1; |
| 74 | fInputColor = fInOut.color(); |
| 75 | fInputColorIsUsed = true; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 76 | // Since we are clearing all previous color stages we are in a state where we have found |
| 77 | // zero stages that don't multiply the inputColor. |
| 78 | fInOut.resetNonMulStageFound(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 79 | // Reset these since we don't care if previous stages read these values |
| 80 | fReadsDst = false; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 81 | fReadsFragPosition = initWillReadFragmentPosition; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |