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 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 14 | class GrDrawBatch; |
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: |
| 25 | GrProcOptInfo() |
| 26 | : fInOut(0, static_cast<GrColorComponentFlags>(0), false) |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 27 | , fFirstEffectiveProcessorIndex(0) |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 28 | , fInputColorIsUsed(true) |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 29 | , fInputColor(0) {} |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 30 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 31 | void calcWithInitialValues(const GrFragmentProcessor* const *, int cnt, GrColor startColor, |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 32 | GrColorComponentFlags, bool areCoverageStages, bool isLCD = false); |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 33 | void initUsingInvariantOutput(GrInitInvariantOutput invOutput); |
| 34 | void completeCalculations(const GrFragmentProcessor * const processors[], int cnt); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 35 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 36 | bool isSolidWhite() const { return fInOut.isSolidWhite(); } |
| 37 | bool isOpaque() const { return fInOut.isOpaque(); } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 38 | bool isSingleComponent() const { return fInOut.isSingleComponent(); } |
egdaniel | f7c2d55 | 2015-02-13 12:11:00 -0800 | [diff] [blame] | 39 | bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 40 | |
egdaniel | 309e346 | 2014-12-09 10:35:58 -0800 | [diff] [blame] | 41 | // TODO: Once texture pixel configs quaries are updated, we no longer need this function. |
| 42 | // For now this function will correctly tell us if we are using LCD text or not and should only |
| 43 | // be called when looking at the coverage output. |
| 44 | bool isFourChannelOutput() const { return !fInOut.isSingleComponent() && |
| 45 | fInOut.isLCDCoverage(); } |
| 46 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 47 | GrColor color() const { return fInOut.color(); } |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 48 | |
| 49 | GrColorComponentFlags validFlags() const { |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 50 | return fInOut.validFlags(); |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 51 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 52 | |
| 53 | /** |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 54 | * Returns the index of the first effective color processor. If an intermediate processor |
| 55 | * doesn't read its input or has a known output, then we can ignore all earlier processors |
| 56 | * since they will not affect the final output. Thus the first effective processors index is |
| 57 | * 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] | 58 | * |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 59 | * If processors before the firstEffectiveProcessorIndex() are removed, corresponding values |
| 60 | * from inputColorIsUsed(), inputColorToEffectiveProcessor(), removeVertexAttribs(), and |
| 61 | * readsDst() must be used when setting up the draw to ensure correct drawing. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 62 | */ |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 63 | int firstEffectiveProcessorIndex() const { return fFirstEffectiveProcessorIndex; } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 66 | * True if the first effective processor reads its input, false otherwise. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 67 | */ |
| 68 | bool inputColorIsUsed() const { return fInputColorIsUsed; } |
| 69 | |
| 70 | /** |
| 71 | * 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] | 72 | * first effective processor. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 73 | */ |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 74 | GrColor inputColorToFirstEffectiveProccesor() const { return fInputColor; } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 75 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 76 | private: |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 77 | void internalCalc(const GrFragmentProcessor* const[], int cnt); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 78 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 79 | GrInvariantOutput fInOut; |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 80 | int fFirstEffectiveProcessorIndex; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 81 | bool fInputColorIsUsed; |
| 82 | GrColor fInputColor; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | #endif |