blob: 19f01a2821659b2131fb3b9f43ee46a32ad1025d [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);
ethannicholasff210322015-11-24 12:10:10 -080035 void initUsingInvariantOutput(GrInitInvariantOutput invOutput);
36 void completeCalculations(const GrFragmentProcessor * const processors[], int cnt);
37
egdanielb6cbc382014-11-13 11:00:34 -080038 bool isSolidWhite() const { return fInOut.isSolidWhite(); }
39 bool isOpaque() const { return fInOut.isOpaque(); }
egdaniel378092f2014-12-03 10:40:13 -080040 bool isSingleComponent() const { return fInOut.isSingleComponent(); }
egdanielf7c2d552015-02-13 12:11:00 -080041 bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); }
egdanielb6cbc382014-11-13 11:00:34 -080042
egdaniel309e3462014-12-09 10:35:58 -080043 // TODO: Once texture pixel configs quaries are updated, we no longer need this function.
44 // For now this function will correctly tell us if we are using LCD text or not and should only
45 // be called when looking at the coverage output.
46 bool isFourChannelOutput() const { return !fInOut.isSingleComponent() &&
47 fInOut.isLCDCoverage(); }
48
egdanielb6cbc382014-11-13 11:00:34 -080049 GrColor color() const { return fInOut.color(); }
cdalton1fa45722015-06-02 10:43:39 -070050
51 GrColorComponentFlags validFlags() const {
bsalomone25eea42015-09-29 06:38:55 -070052 return fInOut.validFlags();
cdalton1fa45722015-06-02 10:43:39 -070053 }
egdanielb6cbc382014-11-13 11:00:34 -080054
55 /**
bsalomonac856c92015-08-27 06:30:17 -070056 * Returns the index of the first effective color processor. If an intermediate processor
57 * doesn't read its input or has a known output, then we can ignore all earlier processors
58 * since they will not affect the final output. Thus the first effective processors index is
59 * the index to the first processor that will have an effect on the final output.
egdanielb6cbc382014-11-13 11:00:34 -080060 *
bsalomonac856c92015-08-27 06:30:17 -070061 * If processors before the firstEffectiveProcessorIndex() are removed, corresponding values
62 * from inputColorIsUsed(), inputColorToEffectiveProcessor(), removeVertexAttribs(), and
63 * readsDst() must be used when setting up the draw to ensure correct drawing.
egdanielb6cbc382014-11-13 11:00:34 -080064 */
bsalomonac856c92015-08-27 06:30:17 -070065 int firstEffectiveProcessorIndex() const { return fFirstEffectiveProcessorIndex; }
egdanielb6cbc382014-11-13 11:00:34 -080066
67 /**
bsalomonac856c92015-08-27 06:30:17 -070068 * True if the first effective processor reads its input, false otherwise.
egdanielb6cbc382014-11-13 11:00:34 -080069 */
70 bool inputColorIsUsed() const { return fInputColorIsUsed; }
71
72 /**
73 * 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 -070074 * first effective processor.
egdanielb6cbc382014-11-13 11:00:34 -080075 */
bsalomonac856c92015-08-27 06:30:17 -070076 GrColor inputColorToFirstEffectiveProccesor() const { return fInputColor; }
egdanielb6cbc382014-11-13 11:00:34 -080077
78 /**
bsalomonac856c92015-08-27 06:30:17 -070079 * Returns true if any of the processor preserved by GrProcOptInfo read the frag position.
egdaniel95131432014-12-09 11:15:43 -080080 */
81 bool readsFragPosition() const { return fReadsFragPosition; }
82
egdanielb6cbc382014-11-13 11:00:34 -080083private:
bsalomonac856c92015-08-27 06:30:17 -070084 void internalCalc(const GrFragmentProcessor* const[], int cnt, bool initWillReadFragPosition);
joshualitt56995b52014-12-11 15:44:02 -080085
egdanielb6cbc382014-11-13 11:00:34 -080086 GrInvariantOutput fInOut;
bsalomonac856c92015-08-27 06:30:17 -070087 int fFirstEffectiveProcessorIndex;
egdanielb6cbc382014-11-13 11:00:34 -080088 bool fInputColorIsUsed;
89 GrColor fInputColor;
egdaniel95131432014-12-09 11:15:43 -080090 bool fReadsFragPosition;
egdanielb6cbc382014-11-13 11:00:34 -080091};
92
93#endif