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