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