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 | 7c66342 | 2014-12-08 11:20:39 -0800 | [diff] [blame^] | 10 | #include "GrFragmentProcessor.h" |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 11 | #include "GrFragmentStage.h" |
egdaniel | 7c66342 | 2014-12-08 11:20:39 -0800 | [diff] [blame^] | 12 | #include "GrGeometryProcessor.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 13 | |
| 14 | void GrProcOptInfo::calcWithInitialValues(const GrFragmentStage* stages, |
| 15 | int stageCount, |
| 16 | GrColor startColor, |
| 17 | GrColorComponentFlags flags, |
| 18 | bool areCoverageStages, |
| 19 | const GrGeometryProcessor* gp) { |
| 20 | fInOut.reset(startColor, flags, areCoverageStages); |
| 21 | fFirstEffectStageIndex = 0; |
| 22 | fInputColorIsUsed = true; |
| 23 | fInputColor = startColor; |
| 24 | fRemoveVertexAttrib = false; |
| 25 | fReadsDst = false; |
egdaniel | 7c66342 | 2014-12-08 11:20:39 -0800 | [diff] [blame^] | 26 | fReadsFragPosition = false; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 27 | |
| 28 | if (areCoverageStages && gp) { |
| 29 | gp->computeInvariantOutput(&fInOut); |
| 30 | } |
| 31 | |
| 32 | for (int i = 0; i < stageCount; ++i) { |
| 33 | const GrFragmentProcessor* processor = stages[i].getProcessor(); |
| 34 | fInOut.resetWillUseInputColor(); |
| 35 | processor->computeInvariantOutput(&fInOut); |
egdaniel | 7c66342 | 2014-12-08 11:20:39 -0800 | [diff] [blame^] | 36 | #ifdef SK_DEBUG |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 37 | fInOut.validate(); |
egdaniel | 7c66342 | 2014-12-08 11:20:39 -0800 | [diff] [blame^] | 38 | #endif |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 39 | if (!fInOut.willUseInputColor()) { |
| 40 | fFirstEffectStageIndex = i; |
| 41 | fInputColorIsUsed = false; |
egdaniel | 7c66342 | 2014-12-08 11:20:39 -0800 | [diff] [blame^] | 42 | // Reset these since we don't care if previous stages read these values |
| 43 | fReadsDst = false; |
| 44 | fReadsFragPosition = false; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 45 | } |
| 46 | if (processor->willReadDstColor()) { |
| 47 | fReadsDst = true; |
| 48 | } |
egdaniel | 7c66342 | 2014-12-08 11:20:39 -0800 | [diff] [blame^] | 49 | if (processor->willReadFragmentPosition()) { |
| 50 | fReadsFragPosition = true; |
| 51 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 52 | if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) { |
| 53 | fFirstEffectStageIndex = i + 1; |
| 54 | fInputColor = fInOut.color(); |
| 55 | fInputColorIsUsed = true; |
| 56 | fRemoveVertexAttrib = true; |
| 57 | // Since we are clearing all previous color stages we are in a state where we have found |
| 58 | // zero stages that don't multiply the inputColor. |
| 59 | fInOut.resetNonMulStageFound(); |
egdaniel | 7c66342 | 2014-12-08 11:20:39 -0800 | [diff] [blame^] | 60 | // Reset these since we don't care if previous stages read these values |
| 61 | fReadsDst = false; |
| 62 | fReadsFragPosition = false; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | } |
egdaniel | 7c66342 | 2014-12-08 11:20:39 -0800 | [diff] [blame^] | 66 | |