blob: 87e7cd9c69774ed677cf5fcf0bc35538e0cc6edf [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;
egdanielb6cbc382014-11-13 11:00:34 -080017
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 */
23class GrProcOptInfo {
24public:
25 GrProcOptInfo()
26 : fInOut(0, static_cast<GrColorComponentFlags>(0), false)
bsalomonac856c92015-08-27 06:30:17 -070027 , fFirstEffectiveProcessorIndex(0)
egdanielb6cbc382014-11-13 11:00:34 -080028 , fInputColorIsUsed(true)
cdalton87332102016-02-26 12:22:02 -080029 , fInputColor(0) {}
egdanielb6cbc382014-11-13 11:00:34 -080030
bsalomonac856c92015-08-27 06:30:17 -070031 void calcWithInitialValues(const GrFragmentProcessor* const *, int cnt, GrColor startColor,
egdaniel723b0502015-09-15 09:31:40 -070032 GrColorComponentFlags, bool areCoverageStages, bool isLCD = false);
ethannicholasff210322015-11-24 12:10:10 -080033 void initUsingInvariantOutput(GrInitInvariantOutput invOutput);
34 void completeCalculations(const GrFragmentProcessor * const processors[], int cnt);
halcanary9d524f22016-03-29 09:03:52 -070035
egdanielb6cbc382014-11-13 11:00:34 -080036 bool isSolidWhite() const { return fInOut.isSolidWhite(); }
37 bool isOpaque() const { return fInOut.isOpaque(); }
egdaniel378092f2014-12-03 10:40:13 -080038 bool isSingleComponent() const { return fInOut.isSingleComponent(); }
egdanielf7c2d552015-02-13 12:11:00 -080039 bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); }
egdanielb6cbc382014-11-13 11:00:34 -080040
egdaniel309e3462014-12-09 10:35:58 -080041 // 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.
44 bool isFourChannelOutput() const { return !fInOut.isSingleComponent() &&
45 fInOut.isLCDCoverage(); }
46
egdanielb6cbc382014-11-13 11:00:34 -080047 GrColor color() const { return fInOut.color(); }
cdalton1fa45722015-06-02 10:43:39 -070048
49 GrColorComponentFlags validFlags() const {
bsalomone25eea42015-09-29 06:38:55 -070050 return fInOut.validFlags();
cdalton1fa45722015-06-02 10:43:39 -070051 }
egdanielb6cbc382014-11-13 11:00:34 -080052
53 /**
bsalomonac856c92015-08-27 06:30:17 -070054 * 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.
egdanielb6cbc382014-11-13 11:00:34 -080058 *
bsalomonac856c92015-08-27 06:30:17 -070059 * 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.
egdanielb6cbc382014-11-13 11:00:34 -080062 */
bsalomonac856c92015-08-27 06:30:17 -070063 int firstEffectiveProcessorIndex() const { return fFirstEffectiveProcessorIndex; }
egdanielb6cbc382014-11-13 11:00:34 -080064
65 /**
bsalomonac856c92015-08-27 06:30:17 -070066 * True if the first effective processor reads its input, false otherwise.
egdanielb6cbc382014-11-13 11:00:34 -080067 */
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
bsalomonac856c92015-08-27 06:30:17 -070072 * first effective processor.
egdanielb6cbc382014-11-13 11:00:34 -080073 */
bsalomonac856c92015-08-27 06:30:17 -070074 GrColor inputColorToFirstEffectiveProccesor() const { return fInputColor; }
egdanielb6cbc382014-11-13 11:00:34 -080075
egdanielb6cbc382014-11-13 11:00:34 -080076private:
cdalton87332102016-02-26 12:22:02 -080077 void internalCalc(const GrFragmentProcessor* const[], int cnt);
joshualitt56995b52014-12-11 15:44:02 -080078
egdanielb6cbc382014-11-13 11:00:34 -080079 GrInvariantOutput fInOut;
bsalomonac856c92015-08-27 06:30:17 -070080 int fFirstEffectiveProcessorIndex;
egdanielb6cbc382014-11-13 11:00:34 -080081 bool fInputColorIsUsed;
82 GrColor fInputColor;
egdanielb6cbc382014-11-13 11:00:34 -080083};
84
85#endif