blob: 6e8f615d2c0204c5b5333707a7b000561d281096 [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(); }
egdanielb6cbc382014-11-13 11:00:34 -080048
egdaniel309e3462014-12-09 10:35:58 -080049 // TODO: Once texture pixel configs quaries are updated, we no longer need this function.
50 // For now this function will correctly tell us if we are using LCD text or not and should only
51 // be called when looking at the coverage output.
52 bool isFourChannelOutput() const { return !fInOut.isSingleComponent() &&
53 fInOut.isLCDCoverage(); }
54
egdanielb6cbc382014-11-13 11:00:34 -080055 GrColor color() const { return fInOut.color(); }
56 uint8_t validFlags() const { return fInOut.validFlags(); }
57
58 /**
59 * Returns the index of the first effective color stage. If an intermediate stage doesn't read
60 * its input or has a known output, then we can ignore all earlier stages since they will not
61 * affect the final output. Thus the first effective stage index is the index to the first stage
62 * that will have an effect on the final output.
63 *
64 * If stages before the firstEffectiveStageIndex are removed, corresponding values from
65 * inputColorIsUsed(), inputColorToEffectiveStage(), removeVertexAttribs(), and readsDst() must
66 * be used when setting up the draw to ensure correct drawing.
67 */
68 int firstEffectiveStageIndex() const { return fFirstEffectStageIndex; }
69
70 /**
71 * True if the first effective stage reads its input, false otherwise.
72 */
73 bool inputColorIsUsed() const { return fInputColorIsUsed; }
74
75 /**
76 * If input color is used and per-vertex colors are not used, this is the input color to the
77 * first effective stage.
78 */
79 GrColor inputColorToEffectiveStage() const { return fInputColor; }
80
81 /**
egdaniel95131432014-12-09 11:15:43 -080082 * Returns true if any of the stages preserved by GrProcOptInfo read the frag position.
83 */
84 bool readsFragPosition() const { return fReadsFragPosition; }
85
egdanielb6cbc382014-11-13 11:00:34 -080086private:
joshualitt56995b52014-12-11 15:44:02 -080087 void internalCalc(const GrFragmentStage*, int stagecount, bool initWillReadFragPosition);
88
egdanielb6cbc382014-11-13 11:00:34 -080089 GrInvariantOutput fInOut;
90 int fFirstEffectStageIndex;
91 bool fInputColorIsUsed;
92 GrColor fInputColor;
egdaniel95131432014-12-09 11:15:43 -080093 bool fReadsFragPosition;
egdanielb6cbc382014-11-13 11:00:34 -080094};
95
96#endif