blob: 9c9bf94597ef712d3d0b8f6735f5f5601cc9616e [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
egdaniela7dc0a82014-09-17 08:25:05 -070026 bool readsDst() const { return fReadsDst; }
27 bool readsFragPosition() const { return fReadsFragPosition; }
28 bool requiresVertexShader() const { return fRequiresVertexShader; }
29 bool requiresLocalCoordAttrib() const { return fRequiresLocalCoordAttrib; }
30
egdaniel170f90b2014-09-16 12:54:40 -070031private:
egdaniel3658f382014-09-15 07:01:59 -070032 /**
33 * Constructs and optimized drawState out of a GrRODrawState.
34 */
egdaniel170f90b2014-09-16 12:54:40 -070035 GrOptDrawState(const GrDrawState& drawState, BlendOptFlags blendOptFlags,
36 GrBlendCoeff optSrcCoeff, GrBlendCoeff optDstCoeff);
egdaniel3658f382014-09-15 07:01:59 -070037
egdaniel170f90b2014-09-16 12:54:40 -070038 /**
egdaniel3658f382014-09-15 07:01:59 -070039 * 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
egdaniel170f90b2014-09-16 12:54:40 -070048 /**
egdaniel3658f382014-09-15 07:01:59 -070049 * 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
egdaniel170f90b2014-09-16 12:54:40 -070056 /**
egdaniel3658f382014-09-15 07:01:59 -070057 * 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
egdaniel170f90b2014-09-16 12:54:40 -070063 /**
64 * Alter the OptDrawState (adjusting stages, vertex attribs, flags, etc.) based on the
65 * BlendOptFlags.
66 */
67 void adjustFromBlendOpts();
egdaniel3658f382014-09-15 07:01:59 -070068
egdaniela7dc0a82014-09-17 08:25:05 -070069 /**
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
egdaniel3658f382014-09-15 07:01:59 -070075 // 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
egdaniela7dc0a82014-09-17 08:25:05 -070080 // 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
egdaniel3658f382014-09-15 07:01:59 -070086 SkAutoSTArray<4, GrVertexAttrib> fOptVA;
87
egdaniel170f90b2014-09-16 12:54:40 -070088 BlendOptFlags fBlendOptFlags;
89
90 friend GrOptDrawState* GrDrawState::createOptState() const;
egdaniel3658f382014-09-15 07:01:59 -070091 typedef GrRODrawState INHERITED;
92};
93
94#endif