blob: caf53d773ace6dc919f2cdb6170ce50e349622f5 [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
bsalomonabd30f52015-08-13 13:34:48 -070014class GrDrawBatch;
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)
bsalomonac856c92015-08-27 06:30:17 -070028 , fFirstEffectiveProcessorIndex(0)
egdanielb6cbc382014-11-13 11:00:34 -080029 , fInputColorIsUsed(true)
30 , fInputColor(0)
egdaniel95131432014-12-09 11:15:43 -080031 , fReadsFragPosition(false) {}
egdanielb6cbc382014-11-13 11:00:34 -080032
bsalomonac856c92015-08-27 06:30:17 -070033 void calcWithInitialValues(const GrFragmentProcessor* const *, int cnt, GrColor startColor,
egdaniel723b0502015-09-15 09:31:40 -070034 GrColorComponentFlags, bool areCoverageStages, bool isLCD = false);
joshualitt56995b52014-12-11 15:44:02 -080035
bsalomonac856c92015-08-27 06:30:17 -070036 void calcColorWithBatch(const GrDrawBatch*, const GrFragmentProcessor* const[], int cnt);
37 void calcCoverageWithBatch(const GrDrawBatch*, const GrFragmentProcessor* const[], int cnt);
joshualitt4d8da812015-01-28 12:53:54 -080038
egdanielb6cbc382014-11-13 11:00:34 -080039 bool isSolidWhite() const { return fInOut.isSolidWhite(); }
40 bool isOpaque() const { return fInOut.isOpaque(); }
egdaniel378092f2014-12-03 10:40:13 -080041 bool isSingleComponent() const { return fInOut.isSingleComponent(); }
egdanielf7c2d552015-02-13 12:11:00 -080042 bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); }
egdanielb6cbc382014-11-13 11:00:34 -080043
egdaniel309e3462014-12-09 10:35:58 -080044 // TODO: Once texture pixel configs quaries are updated, we no longer need this function.
45 // For now this function will correctly tell us if we are using LCD text or not and should only
46 // be called when looking at the coverage output.
47 bool isFourChannelOutput() const { return !fInOut.isSingleComponent() &&
48 fInOut.isLCDCoverage(); }
49
egdanielb6cbc382014-11-13 11:00:34 -080050 GrColor color() const { return fInOut.color(); }
cdalton1fa45722015-06-02 10:43:39 -070051
52 GrColorComponentFlags validFlags() const {
bsalomone25eea42015-09-29 06:38:55 -070053 return fInOut.validFlags();
cdalton1fa45722015-06-02 10:43:39 -070054 }
egdanielb6cbc382014-11-13 11:00:34 -080055
56 /**
bsalomonac856c92015-08-27 06:30:17 -070057 * Returns the index of the first effective color processor. If an intermediate processor
58 * doesn't read its input or has a known output, then we can ignore all earlier processors
59 * since they will not affect the final output. Thus the first effective processors index is
60 * the index to the first processor that will have an effect on the final output.
egdanielb6cbc382014-11-13 11:00:34 -080061 *
bsalomonac856c92015-08-27 06:30:17 -070062 * If processors before the firstEffectiveProcessorIndex() are removed, corresponding values
63 * from inputColorIsUsed(), inputColorToEffectiveProcessor(), removeVertexAttribs(), and
64 * readsDst() must be used when setting up the draw to ensure correct drawing.
egdanielb6cbc382014-11-13 11:00:34 -080065 */
bsalomonac856c92015-08-27 06:30:17 -070066 int firstEffectiveProcessorIndex() const { return fFirstEffectiveProcessorIndex; }
egdanielb6cbc382014-11-13 11:00:34 -080067
68 /**
bsalomonac856c92015-08-27 06:30:17 -070069 * True if the first effective processor reads its input, false otherwise.
egdanielb6cbc382014-11-13 11:00:34 -080070 */
71 bool inputColorIsUsed() const { return fInputColorIsUsed; }
72
73 /**
74 * If input color is used and per-vertex colors are not used, this is the input color to the
bsalomonac856c92015-08-27 06:30:17 -070075 * first effective processor.
egdanielb6cbc382014-11-13 11:00:34 -080076 */
bsalomonac856c92015-08-27 06:30:17 -070077 GrColor inputColorToFirstEffectiveProccesor() const { return fInputColor; }
egdanielb6cbc382014-11-13 11:00:34 -080078
79 /**
bsalomonac856c92015-08-27 06:30:17 -070080 * Returns true if any of the processor preserved by GrProcOptInfo read the frag position.
egdaniel95131432014-12-09 11:15:43 -080081 */
82 bool readsFragPosition() const { return fReadsFragPosition; }
83
egdanielb6cbc382014-11-13 11:00:34 -080084private:
bsalomonac856c92015-08-27 06:30:17 -070085 void internalCalc(const GrFragmentProcessor* const[], int cnt, bool initWillReadFragPosition);
joshualitt56995b52014-12-11 15:44:02 -080086
egdanielb6cbc382014-11-13 11:00:34 -080087 GrInvariantOutput fInOut;
bsalomonac856c92015-08-27 06:30:17 -070088 int fFirstEffectiveProcessorIndex;
egdanielb6cbc382014-11-13 11:00:34 -080089 bool fInputColorIsUsed;
90 GrColor fInputColor;
egdaniel95131432014-12-09 11:15:43 -080091 bool fReadsFragPosition;
egdanielb6cbc382014-11-13 11:00:34 -080092};
93
94#endif