blob: 43d6c558f1d4749c158b8be1bb0495d3d07218ca [file] [log] [blame]
egdanielb6cbc382014-11-13 11:00:34 -08001/*
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
14class GrFragmentStage;
egdaniel95131432014-12-09 11:15:43 -080015class GrFragmentProcessor;
joshualitt56995b52014-12-11 15:44:02 -080016class GrPrimitiveProcessor;
egdaniel95131432014-12-09 11:15:43 -080017class GrProcessor;
egdanielb6cbc382014-11-13 11:00:34 -080018
19/**
20 * GrProcOptInfo gathers invariant data from a set of processor stages.It is used to recognize
21 * optimizations related to eliminating stages and vertex attributes that aren't necessary for a
22 * draw.
23 */
24class GrProcOptInfo {
25public:
26 GrProcOptInfo()
27 : fInOut(0, static_cast<GrColorComponentFlags>(0), false)
28 , fFirstEffectStageIndex(0)
29 , fInputColorIsUsed(true)
30 , fInputColor(0)
egdaniel95131432014-12-09 11:15:43 -080031 , fReadsDst(false)
32 , fReadsFragPosition(false) {}
egdanielb6cbc382014-11-13 11:00:34 -080033
34 void calcWithInitialValues(const GrFragmentStage*, int stageCount, GrColor startColor,
joshualitt56995b52014-12-11 15:44:02 -080035 GrColorComponentFlags flags, bool areCoverageStages);
36
37 void calcColorWithPrimProc(const GrPrimitiveProcessor*, const GrFragmentStage*, int stagecount);
38 void calcCoverageWithPrimProc(const GrPrimitiveProcessor*, const GrFragmentStage*,
39 int stagecount);
egdanielb6cbc382014-11-13 11:00:34 -080040
41 bool isSolidWhite() const { return fInOut.isSolidWhite(); }
42 bool isOpaque() const { return fInOut.isOpaque(); }
egdaniel378092f2014-12-03 10:40:13 -080043 bool isSingleComponent() const { return fInOut.isSingleComponent(); }
egdanielb6cbc382014-11-13 11:00:34 -080044
egdaniel309e3462014-12-09 10:35:58 -080045 // TODO: Once texture pixel configs quaries are updated, we no longer need this function.
46 // For now this function will correctly tell us if we are using LCD text or not and should only
47 // be called when looking at the coverage output.
48 bool isFourChannelOutput() const { return !fInOut.isSingleComponent() &&
49 fInOut.isLCDCoverage(); }
50
egdanielb6cbc382014-11-13 11:00:34 -080051 GrColor color() const { return fInOut.color(); }
52 uint8_t validFlags() const { return fInOut.validFlags(); }
53
54 /**
55 * Returns the index of the first effective color stage. If an intermediate stage doesn't read
56 * its input or has a known output, then we can ignore all earlier stages since they will not
57 * affect the final output. Thus the first effective stage index is the index to the first stage
58 * that will have an effect on the final output.
59 *
60 * If stages before the firstEffectiveStageIndex are removed, corresponding values from
61 * inputColorIsUsed(), inputColorToEffectiveStage(), removeVertexAttribs(), and readsDst() must
62 * be used when setting up the draw to ensure correct drawing.
63 */
64 int firstEffectiveStageIndex() const { return fFirstEffectStageIndex; }
65
66 /**
67 * True if the first effective stage reads its input, false otherwise.
68 */
69 bool inputColorIsUsed() const { return fInputColorIsUsed; }
70
71 /**
72 * If input color is used and per-vertex colors are not used, this is the input color to the
73 * first effective stage.
74 */
75 GrColor inputColorToEffectiveStage() const { return fInputColor; }
76
77 /**
egdanielb6cbc382014-11-13 11:00:34 -080078 * Returns true if any of the stages preserved by GrProcOptInfo read the dst color.
79 */
80 bool readsDst() const { return fReadsDst; }
81
egdaniel95131432014-12-09 11:15:43 -080082 /**
83 * Returns true if any of the stages preserved by GrProcOptInfo read the frag position.
84 */
85 bool readsFragPosition() const { return fReadsFragPosition; }
86
egdanielb6cbc382014-11-13 11:00:34 -080087private:
joshualitt56995b52014-12-11 15:44:02 -080088 void internalCalc(const GrFragmentStage*, int stagecount, bool initWillReadFragPosition);
89
egdanielb6cbc382014-11-13 11:00:34 -080090 GrInvariantOutput fInOut;
91 int fFirstEffectStageIndex;
92 bool fInputColorIsUsed;
93 GrColor fInputColor;
egdanielb6cbc382014-11-13 11:00:34 -080094 bool fReadsDst;
egdaniel95131432014-12-09 11:15:43 -080095 bool fReadsFragPosition;
egdanielb6cbc382014-11-13 11:00:34 -080096};
97
98#endif