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 | |
| 26 | private: |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Constructs and optimized drawState out of a GrRODrawState. |
| 29 | */ |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame^] | 30 | GrOptDrawState(const GrDrawState& drawState, BlendOptFlags blendOptFlags, |
| 31 | GrBlendCoeff optSrcCoeff, GrBlendCoeff optDstCoeff); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 32 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame^] | 33 | /** |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 34 | * Loops through all the color stage effects to check if the stage will ignore color input or |
| 35 | * always output a constant color. In the ignore color input case we can ignore all previous |
| 36 | * stages. In the constant color case, we can ignore all previous stages and |
| 37 | * the current one and set the state color to the constant color. Once we determine the so |
| 38 | * called first effective stage, we copy all the effective stages into our optimized |
| 39 | * state. |
| 40 | */ |
| 41 | void copyEffectiveColorStages(const GrDrawState& ds); |
| 42 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame^] | 43 | /** |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 44 | * Loops through all the coverage stage effects to check if the stage will ignore color input. |
| 45 | * If a coverage stage will ignore input, then we can ignore all coverage stages before it. We |
| 46 | * loop to determine the first effective coverage stage, and then copy all of our effective |
| 47 | * coverage stages into our optimized state. |
| 48 | */ |
| 49 | void copyEffectiveCoverageStages(const GrDrawState& ds); |
| 50 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame^] | 51 | /** |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 52 | * This function takes in a flag and removes the corresponding fixed function vertex attributes. |
| 53 | * The flags are in the same order as GrVertexAttribBinding array. If bit i of removeVAFlags is |
| 54 | * set, then vertex attributes with binding (GrVertexAttribute)i will be removed. |
| 55 | */ |
| 56 | void removeFixedFunctionVertexAttribs(uint8_t removeVAFlags); |
| 57 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame^] | 58 | /** |
| 59 | * Alter the OptDrawState (adjusting stages, vertex attribs, flags, etc.) based on the |
| 60 | * BlendOptFlags. |
| 61 | */ |
| 62 | void adjustFromBlendOpts(); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 63 | |
| 64 | // These flags are needed to protect the code from creating an unused uniform color/coverage |
| 65 | // which will cause shader compiler errors. |
| 66 | bool fInputColorIsUsed; |
| 67 | bool fInputCoverageIsUsed; |
| 68 | |
| 69 | SkAutoSTArray<4, GrVertexAttrib> fOptVA; |
| 70 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame^] | 71 | BlendOptFlags fBlendOptFlags; |
| 72 | |
| 73 | friend GrOptDrawState* GrDrawState::createOptState() const; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 74 | typedef GrRODrawState INHERITED; |
| 75 | }; |
| 76 | |
| 77 | #endif |