blob: 457f0354239fc8eb96d4cbc2196f103ca4dd9a88 [file] [log] [blame]
egdaniel3658f382014-09-15 07:01:59 -07001/*
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
egdaniel170f90b2014-09-16 12:54:40 -070011#include "GrDrawState.h"
egdaniel3658f382014-09-15 07:01:59 -070012#include "GrRODrawState.h"
13
egdaniel3658f382014-09-15 07:01:59 -070014/**
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 */
19class GrOptDrawState : public GrRODrawState {
20public:
egdaniel170f90b2014-09-16 12:54:40 -070021 bool operator== (const GrOptDrawState& that) const;
22
23 bool inputColorIsUsed() const { return fInputColorIsUsed; }
24 bool inputCoverageIsUsed() const { return fInputCoverageIsUsed; }
25
26private:
egdaniel3658f382014-09-15 07:01:59 -070027 /**
28 * Constructs and optimized drawState out of a GrRODrawState.
29 */
egdaniel170f90b2014-09-16 12:54:40 -070030 GrOptDrawState(const GrDrawState& drawState, BlendOptFlags blendOptFlags,
31 GrBlendCoeff optSrcCoeff, GrBlendCoeff optDstCoeff);
egdaniel3658f382014-09-15 07:01:59 -070032
egdaniel170f90b2014-09-16 12:54:40 -070033 /**
egdaniel3658f382014-09-15 07:01:59 -070034 * 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
egdaniel170f90b2014-09-16 12:54:40 -070043 /**
egdaniel3658f382014-09-15 07:01:59 -070044 * 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
egdaniel170f90b2014-09-16 12:54:40 -070051 /**
egdaniel3658f382014-09-15 07:01:59 -070052 * 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
egdaniel170f90b2014-09-16 12:54:40 -070058 /**
59 * Alter the OptDrawState (adjusting stages, vertex attribs, flags, etc.) based on the
60 * BlendOptFlags.
61 */
62 void adjustFromBlendOpts();
egdaniel3658f382014-09-15 07:01:59 -070063
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
egdaniel170f90b2014-09-16 12:54:40 -070071 BlendOptFlags fBlendOptFlags;
72
73 friend GrOptDrawState* GrDrawState::createOptState() const;
egdaniel3658f382014-09-15 07:01:59 -070074 typedef GrRODrawState INHERITED;
75};
76
77#endif