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