blob: 059bca4dd8b8762b9879e95eb7c2d90844f0dd98 [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
joshualitt4d8da812015-01-28 12:53:54 -080014class GrBatch;
egdanielb6cbc382014-11-13 11:00:34 -080015class GrFragmentStage;
egdaniel95131432014-12-09 11:15:43 -080016class GrFragmentProcessor;
joshualitt56995b52014-12-11 15:44:02 -080017class GrPrimitiveProcessor;
egdaniel95131432014-12-09 11:15:43 -080018class GrProcessor;
egdanielb6cbc382014-11-13 11:00:34 -080019
20/**
21 * GrProcOptInfo gathers invariant data from a set of processor stages.It is used to recognize
22 * optimizations related to eliminating stages and vertex attributes that aren't necessary for a
23 * draw.
24 */
25class GrProcOptInfo {
26public:
27 GrProcOptInfo()
28 : fInOut(0, static_cast<GrColorComponentFlags>(0), false)
29 , fFirstEffectStageIndex(0)
30 , fInputColorIsUsed(true)
31 , fInputColor(0)
egdaniel95131432014-12-09 11:15:43 -080032 , 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
joshualitt4d8da812015-01-28 12:53:54 -080037 void calcColorWithBatch(const GrBatch*, const GrFragmentStage*, int stagecount);
38 void calcCoverageWithBatch(const GrBatch*, const GrFragmentStage*, int stagecount);
39
40 // TODO delete these when batch is everywhere
joshualitt56995b52014-12-11 15:44:02 -080041 void calcColorWithPrimProc(const GrPrimitiveProcessor*, const GrFragmentStage*, int stagecount);
42 void calcCoverageWithPrimProc(const GrPrimitiveProcessor*, const GrFragmentStage*,
43 int stagecount);
egdanielb6cbc382014-11-13 11:00:34 -080044
45 bool isSolidWhite() const { return fInOut.isSolidWhite(); }
46 bool isOpaque() const { return fInOut.isOpaque(); }
egdaniel378092f2014-12-03 10:40:13 -080047 bool isSingleComponent() const { return fInOut.isSingleComponent(); }
egdanielf7c2d552015-02-13 12:11:00 -080048 bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); }
egdanielb6cbc382014-11-13 11:00:34 -080049
egdaniel309e3462014-12-09 10:35:58 -080050 // TODO: Once texture pixel configs quaries are updated, we no longer need this function.
51 // For now this function will correctly tell us if we are using LCD text or not and should only
52 // be called when looking at the coverage output.
53 bool isFourChannelOutput() const { return !fInOut.isSingleComponent() &&
54 fInOut.isLCDCoverage(); }
55
egdanielb6cbc382014-11-13 11:00:34 -080056 GrColor color() const { return fInOut.color(); }
57 uint8_t validFlags() const { return fInOut.validFlags(); }
58
59 /**
60 * Returns the index of the first effective color stage. If an intermediate stage doesn't read
61 * its input or has a known output, then we can ignore all earlier stages since they will not
62 * affect the final output. Thus the first effective stage index is the index to the first stage
63 * that will have an effect on the final output.
64 *
65 * If stages before the firstEffectiveStageIndex are removed, corresponding values from
66 * inputColorIsUsed(), inputColorToEffectiveStage(), removeVertexAttribs(), and readsDst() must
67 * be used when setting up the draw to ensure correct drawing.
68 */
69 int firstEffectiveStageIndex() const { return fFirstEffectStageIndex; }
70
71 /**
72 * True if the first effective stage reads its input, false otherwise.
73 */
74 bool inputColorIsUsed() const { return fInputColorIsUsed; }
75
76 /**
77 * If input color is used and per-vertex colors are not used, this is the input color to the
78 * first effective stage.
79 */
80 GrColor inputColorToEffectiveStage() const { return fInputColor; }
81
82 /**
egdaniel95131432014-12-09 11:15:43 -080083 * 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;
egdaniel95131432014-12-09 11:15:43 -080094 bool fReadsFragPosition;
egdanielb6cbc382014-11-13 11:00:34 -080095};
96
97#endif