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 | #ifndef GrProcOptInfo_DEFINED |
| 9 | #define GrProcOptInfo_DEFINED |
| 10 | |
| 11 | #include "GrColor.h" |
| 12 | #include "GrInvariantOutput.h" |
| 13 | |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 14 | class GrDrawOp; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 15 | class GrFragmentProcessor; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 16 | class GrPrimitiveProcessor; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * GrProcOptInfo gathers invariant data from a set of processor stages.It is used to recognize |
| 20 | * optimizations related to eliminating stages and vertex attributes that aren't necessary for a |
| 21 | * draw. |
| 22 | */ |
| 23 | class GrProcOptInfo { |
| 24 | public: |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 25 | GrProcOptInfo() : fInOut(0, static_cast<GrColorComponentFlags>(0)) {} |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 26 | |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 27 | GrProcOptInfo(GrColor color, GrColorComponentFlags colorFlags) |
| 28 | : fInOut(color, colorFlags), fInputColor(color) {} |
| 29 | |
| 30 | void resetToLCDCoverage(GrColor color, GrColorComponentFlags colorFlags) { |
| 31 | this->internalReset(color, colorFlags, true); |
| 32 | } |
| 33 | |
| 34 | void reset(GrColor color, GrColorComponentFlags colorFlags) { |
| 35 | this->internalReset(color, colorFlags, false); |
| 36 | } |
| 37 | |
| 38 | void reset(const GrPipelineInput& input) { |
| 39 | this->internalReset(input.fColor, input.fValidFlags, input.fIsLCDCoverage); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Runs through a series of processors and updates calculated values. This can be called |
| 44 | * repeatedly for cases when the sequence of processors is not in a contiguous array. |
| 45 | */ |
Brian Salomon | 0831f1b | 2017-01-18 11:08:41 -0500 | [diff] [blame] | 46 | void analyzeProcessors(const GrFragmentProcessor* const* processors, int cnt); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 47 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 48 | bool isSolidWhite() const { return fInOut.isSolidWhite(); } |
| 49 | bool isOpaque() const { return fInOut.isOpaque(); } |
egdaniel | f7c2d55 | 2015-02-13 12:11:00 -0800 | [diff] [blame] | 50 | bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); } |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 51 | bool isLCDCoverage() const { return fIsLCDCoverage; } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 52 | GrColor color() const { return fInOut.color(); } |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 53 | GrColorComponentFlags validFlags() const { return fInOut.validFlags(); } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 54 | |
| 55 | /** |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 56 | * Returns the index of the first effective color processor. If an intermediate processor |
| 57 | * doesn't read its input or has a known output, then we can ignore all earlier processors |
| 58 | * since they will not affect the final output. Thus the first effective processors index is |
| 59 | * the index to the first processor that will have an effect on the final output. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 60 | * |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 61 | * If processors before the firstEffectiveProcessorIndex() are removed, corresponding values |
| 62 | * from inputColorIsUsed(), inputColorToEffectiveProcessor(), removeVertexAttribs(), and |
| 63 | * readsDst() must be used when setting up the draw to ensure correct drawing. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 64 | */ |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 65 | int firstEffectiveProcessorIndex() const { return fFirstEffectiveProcessorIndex; } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 66 | |
| 67 | /** |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 68 | * If input color is used and per-vertex colors are not used, this is the input color to the |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 69 | * first effective processor. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 70 | */ |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 71 | GrColor inputColorToFirstEffectiveProccesor() const { return fInputColor; } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 72 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 73 | private: |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 74 | void internalReset(GrColor color, GrColorComponentFlags colorFlags, bool isLCDCoverage) { |
| 75 | fInOut.reset(color, colorFlags); |
| 76 | fFirstEffectiveProcessorIndex = 0; |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 77 | fInputColor = color; |
| 78 | fIsLCDCoverage = isLCDCoverage; |
| 79 | } |
| 80 | |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 81 | void internalCalc(const GrFragmentProcessor* const[], int cnt); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 82 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 83 | GrInvariantOutput fInOut; |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 84 | int fFirstEffectiveProcessorIndex = 0; |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 85 | bool fIsLCDCoverage = false; |
| 86 | GrColor fInputColor = 0; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | #endif |