blob: 6b040045e0b74880a6c4a26c194c2185aae138b4 [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
Brian Salomon9afd3712016-12-01 10:59:09 -050014class GrDrawOp;
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:
Brian Salomonaab259e2017-01-17 10:44:34 -050025 GrProcOptInfo() : fInOut(0, static_cast<GrColorComponentFlags>(0)) {}
egdanielb6cbc382014-11-13 11:00:34 -080026
Brian Salomonaab259e2017-01-17 10:44:34 -050027 GrProcOptInfo(GrColor color, GrColorComponentFlags colorFlags)
28 : fInOut(color, colorFlags), fInputColor(color) {}
29
30 void resetToLCDCoverage(GrColor color, GrColorComponentFlags colorFlags) {
31 this->internalReset(color, colorFlags, true);
32 }
33
34 void reset(GrColor color, GrColorComponentFlags colorFlags) {
35 this->internalReset(color, colorFlags, false);
36 }
37
38 void reset(const GrPipelineInput& input) {
39 this->internalReset(input.fColor, input.fValidFlags, input.fIsLCDCoverage);
40 }
41
42 /**
43 * Runs through a series of processors and updates calculated values. This can be called
44 * repeatedly for cases when the sequence of processors is not in a contiguous array.
45 */
Brian Salomon0831f1b2017-01-18 11:08:41 -050046 void analyzeProcessors(const GrFragmentProcessor* const* processors, int cnt);
halcanary9d524f22016-03-29 09:03:52 -070047
egdanielb6cbc382014-11-13 11:00:34 -080048 bool isSolidWhite() const { return fInOut.isSolidWhite(); }
49 bool isOpaque() const { return fInOut.isOpaque(); }
egdanielf7c2d552015-02-13 12:11:00 -080050 bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); }
Brian Salomonaab259e2017-01-17 10:44:34 -050051 bool isLCDCoverage() const { return fIsLCDCoverage; }
egdanielb6cbc382014-11-13 11:00:34 -080052 GrColor color() const { return fInOut.color(); }
Brian Salomonaab259e2017-01-17 10:44:34 -050053 GrColorComponentFlags validFlags() const { return fInOut.validFlags(); }
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
egdanielb6cbc382014-11-13 11:00:34 -080078private:
Brian Salomonaab259e2017-01-17 10:44:34 -050079 void internalReset(GrColor color, GrColorComponentFlags colorFlags, bool isLCDCoverage) {
80 fInOut.reset(color, colorFlags);
81 fFirstEffectiveProcessorIndex = 0;
82 fInputColorIsUsed = true;
83 fInputColor = color;
84 fIsLCDCoverage = isLCDCoverage;
85 }
86
cdalton87332102016-02-26 12:22:02 -080087 void internalCalc(const GrFragmentProcessor* const[], int cnt);
joshualitt56995b52014-12-11 15:44:02 -080088
egdanielb6cbc382014-11-13 11:00:34 -080089 GrInvariantOutput fInOut;
Brian Salomonaab259e2017-01-17 10:44:34 -050090 int fFirstEffectiveProcessorIndex = 0;
91 bool fInputColorIsUsed = true;
92 bool fIsLCDCoverage = false;
93 GrColor fInputColor = 0;
egdanielb6cbc382014-11-13 11:00:34 -080094};
95
96#endif