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