egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [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 GrOptDrawState_DEFINED |
| 9 | #define GrOptDrawState_DEFINED |
| 10 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 11 | #include "GrDrawState.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 12 | #include "GrRODrawState.h" |
| 13 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 14 | /** |
| 15 | * Subclass of GrRODrawState that holds an optimized version of a GrDrawState. Like it's parent |
| 16 | * it is meant to be an immutable class, and simply adds a few helpful data members not in the |
| 17 | * base class. |
| 18 | */ |
| 19 | class GrOptDrawState : public GrRODrawState { |
| 20 | public: |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 21 | bool operator== (const GrOptDrawState& that) const; |
| 22 | |
| 23 | bool inputColorIsUsed() const { return fInputColorIsUsed; } |
| 24 | bool inputCoverageIsUsed() const { return fInputCoverageIsUsed; } |
| 25 | |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame^] | 26 | bool readsDst() const { return fReadsDst; } |
| 27 | bool readsFragPosition() const { return fReadsFragPosition; } |
| 28 | bool requiresVertexShader() const { return fRequiresVertexShader; } |
| 29 | bool requiresLocalCoordAttrib() const { return fRequiresLocalCoordAttrib; } |
| 30 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 31 | private: |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Constructs and optimized drawState out of a GrRODrawState. |
| 34 | */ |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 35 | GrOptDrawState(const GrDrawState& drawState, BlendOptFlags blendOptFlags, |
| 36 | GrBlendCoeff optSrcCoeff, GrBlendCoeff optDstCoeff); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 37 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 38 | /** |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 39 | * Loops through all the color stage effects to check if the stage will ignore color input or |
| 40 | * always output a constant color. In the ignore color input case we can ignore all previous |
| 41 | * stages. In the constant color case, we can ignore all previous stages and |
| 42 | * the current one and set the state color to the constant color. Once we determine the so |
| 43 | * called first effective stage, we copy all the effective stages into our optimized |
| 44 | * state. |
| 45 | */ |
| 46 | void copyEffectiveColorStages(const GrDrawState& ds); |
| 47 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 48 | /** |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 49 | * Loops through all the coverage stage effects to check if the stage will ignore color input. |
| 50 | * If a coverage stage will ignore input, then we can ignore all coverage stages before it. We |
| 51 | * loop to determine the first effective coverage stage, and then copy all of our effective |
| 52 | * coverage stages into our optimized state. |
| 53 | */ |
| 54 | void copyEffectiveCoverageStages(const GrDrawState& ds); |
| 55 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 56 | /** |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 57 | * This function takes in a flag and removes the corresponding fixed function vertex attributes. |
| 58 | * The flags are in the same order as GrVertexAttribBinding array. If bit i of removeVAFlags is |
| 59 | * set, then vertex attributes with binding (GrVertexAttribute)i will be removed. |
| 60 | */ |
| 61 | void removeFixedFunctionVertexAttribs(uint8_t removeVAFlags); |
| 62 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Alter the OptDrawState (adjusting stages, vertex attribs, flags, etc.) based on the |
| 65 | * BlendOptFlags. |
| 66 | */ |
| 67 | void adjustFromBlendOpts(); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 68 | |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame^] | 69 | /** |
| 70 | * Loop over the effect stages to determine various info like what data they will read and what |
| 71 | * shaders they require. |
| 72 | */ |
| 73 | void getStageStats(); |
| 74 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 75 | // These flags are needed to protect the code from creating an unused uniform color/coverage |
| 76 | // which will cause shader compiler errors. |
| 77 | bool fInputColorIsUsed; |
| 78 | bool fInputCoverageIsUsed; |
| 79 | |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame^] | 80 | // These flags give aggregated info on the effect stages that are used when building programs. |
| 81 | bool fReadsDst; |
| 82 | bool fReadsFragPosition; |
| 83 | bool fRequiresVertexShader; |
| 84 | bool fRequiresLocalCoordAttrib; |
| 85 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 86 | SkAutoSTArray<4, GrVertexAttrib> fOptVA; |
| 87 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 88 | BlendOptFlags fBlendOptFlags; |
| 89 | |
| 90 | friend GrOptDrawState* GrDrawState::createOptState() const; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 91 | typedef GrRODrawState INHERITED; |
| 92 | }; |
| 93 | |
| 94 | #endif |