1 /*
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 
14 class GrDrawBatch;
15 class GrFragmentProcessor;
16 class GrPrimitiveProcessor;
17 
18 /**
19  * GrProcOptInfo gathers invariant data from a set of processor stages.It is used to recognize
20  * optimizations related to eliminating stages and vertex attributes that aren't necessary for a
21  * draw.
22  */
23 class GrProcOptInfo {
24 public:
GrProcOptInfo()25     GrProcOptInfo()
26         : fInOut(0, static_cast<GrColorComponentFlags>(0), false)
27         , fFirstEffectiveProcessorIndex(0)
28         , fInputColorIsUsed(true)
29         , fInputColor(0) {}
30 
31     void calcWithInitialValues(const GrFragmentProcessor* const *, int cnt, GrColor startColor,
32                                GrColorComponentFlags, bool areCoverageStages, bool isLCD = false);
33     void initUsingInvariantOutput(GrInitInvariantOutput invOutput);
34     void completeCalculations(const GrFragmentProcessor * const processors[], int cnt);
35 
isSolidWhite()36     bool isSolidWhite() const { return fInOut.isSolidWhite(); }
isOpaque()37     bool isOpaque() const { return fInOut.isOpaque(); }
isSingleComponent()38     bool isSingleComponent() const { return fInOut.isSingleComponent(); }
allStagesMultiplyInput()39     bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); }
40 
41     // TODO: Once texture pixel configs quaries are updated, we no longer need this function.
42     // For now this function will correctly tell us if we are using LCD text or not and should only
43     // be called when looking at the coverage output.
isFourChannelOutput()44     bool isFourChannelOutput() const { return !fInOut.isSingleComponent() &&
45                                                fInOut.isLCDCoverage(); }
46 
color()47     GrColor color() const { return fInOut.color(); }
48 
validFlags()49     GrColorComponentFlags validFlags() const {
50         return fInOut.validFlags();
51     }
52 
53     /**
54      * Returns the index of the first effective color processor. If an intermediate processor
55      * doesn't read its input or has a known output, then we can ignore all earlier processors
56      * since they will not affect the final output. Thus the first effective processors index is
57      * the index to the first processor that will have an effect on the final output.
58      *
59      * If processors before the firstEffectiveProcessorIndex() are removed, corresponding values
60      * from inputColorIsUsed(), inputColorToEffectiveProcessor(), removeVertexAttribs(), and
61      * readsDst() must be used when setting up the draw to ensure correct drawing.
62      */
firstEffectiveProcessorIndex()63     int firstEffectiveProcessorIndex() const { return fFirstEffectiveProcessorIndex; }
64 
65     /**
66      * True if the first effective processor reads its input, false otherwise.
67      */
inputColorIsUsed()68     bool inputColorIsUsed() const { return fInputColorIsUsed; }
69 
70     /**
71      * If input color is used and per-vertex colors are not used, this is the input color to the
72      * first effective processor.
73      */
inputColorToFirstEffectiveProccesor()74     GrColor inputColorToFirstEffectiveProccesor() const { return fInputColor; }
75 
76 private:
77     void internalCalc(const GrFragmentProcessor* const[], int cnt);
78 
79     GrInvariantOutput fInOut;
80     int fFirstEffectiveProcessorIndex;
81     bool fInputColorIsUsed;
82     GrColor fInputColor;
83 };
84 
85 #endif
86