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 | /** |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 68 | * True if the first effective processor reads its input, false otherwise. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 69 | */ |
| 70 | bool inputColorIsUsed() const { return fInputColorIsUsed; } |
| 71 | |
| 72 | /** |
| 73 | * 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] | 74 | * first effective processor. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 75 | */ |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 76 | GrColor inputColorToFirstEffectiveProccesor() const { return fInputColor; } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 77 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 78 | private: |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 79 | void internalReset(GrColor color, GrColorComponentFlags colorFlags, bool isLCDCoverage) { |
| 80 | fInOut.reset(color, colorFlags); |
| 81 | fFirstEffectiveProcessorIndex = 0; |
| 82 | fInputColorIsUsed = true; |
| 83 | fInputColor = color; |
| 84 | fIsLCDCoverage = isLCDCoverage; |
| 85 | } |
| 86 | |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 87 | void internalCalc(const GrFragmentProcessor* const[], int cnt); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 88 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 89 | GrInvariantOutput fInOut; |
Brian Salomon | aab259e | 2017-01-17 10:44:34 -0500 | [diff] [blame] | 90 | int fFirstEffectiveProcessorIndex = 0; |
| 91 | bool fInputColorIsUsed = true; |
| 92 | bool fIsLCDCoverage = false; |
| 93 | GrColor fInputColor = 0; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | #endif |