aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrProcOptInfo.h
blob: 6b040045e0b74880a6c4a26c194c2185aae138b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrProcOptInfo_DEFINED
#define GrProcOptInfo_DEFINED

#include "GrColor.h"
#include "GrInvariantOutput.h"

class GrDrawOp;
class GrFragmentProcessor;
class GrPrimitiveProcessor;

/**
 * GrProcOptInfo gathers invariant data from a set of processor stages.It is used to recognize
 * optimizations related to eliminating stages and vertex attributes that aren't necessary for a
 * draw.
 */
class GrProcOptInfo {
public:
    GrProcOptInfo() : fInOut(0, static_cast<GrColorComponentFlags>(0)) {}

    GrProcOptInfo(GrColor color, GrColorComponentFlags colorFlags)
            : fInOut(color, colorFlags), fInputColor(color) {}

    void resetToLCDCoverage(GrColor color, GrColorComponentFlags colorFlags) {
        this->internalReset(color, colorFlags, true);
    }

    void reset(GrColor color, GrColorComponentFlags colorFlags) {
        this->internalReset(color, colorFlags, false);
    }

    void reset(const GrPipelineInput& input) {
        this->internalReset(input.fColor, input.fValidFlags, input.fIsLCDCoverage);
    }

    /**
     * Runs through a series of processors and updates calculated values. This can be called
     * repeatedly for cases when the sequence of processors is not in a contiguous array.
     */
    void analyzeProcessors(const GrFragmentProcessor* const* processors, int cnt);

    bool isSolidWhite() const { return fInOut.isSolidWhite(); }
    bool isOpaque() const { return fInOut.isOpaque(); }
    bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); }
    bool isLCDCoverage() const { return fIsLCDCoverage; }
    GrColor color() const { return fInOut.color(); }
    GrColorComponentFlags validFlags() const { return fInOut.validFlags(); }

    /**
     * Returns the index of the first effective color processor. If an intermediate processor
     * doesn't read its input or has a known output, then we can ignore all earlier processors
     * since they will not affect the final output. Thus the first effective processors index is
     * the index to the first processor that will have an effect on the final output.
     *
     * If processors before the firstEffectiveProcessorIndex() are removed, corresponding values
     * from inputColorIsUsed(), inputColorToEffectiveProcessor(), removeVertexAttribs(), and
     * readsDst() must be used when setting up the draw to ensure correct drawing.
     */
    int firstEffectiveProcessorIndex() const { return fFirstEffectiveProcessorIndex; }

    /**
     * True if the first effective processor reads its input, false otherwise.
     */
    bool inputColorIsUsed() const { return fInputColorIsUsed; }

    /**
     * If input color is used and per-vertex colors are not used, this is the input color to the
     * first effective processor.
     */
    GrColor inputColorToFirstEffectiveProccesor() const { return fInputColor; }

private:
    void internalReset(GrColor color, GrColorComponentFlags colorFlags, bool isLCDCoverage) {
        fInOut.reset(color, colorFlags);
        fFirstEffectiveProcessorIndex = 0;
        fInputColorIsUsed = true;
        fInputColor = color;
        fIsLCDCoverage = isLCDCoverage;
    }

    void internalCalc(const GrFragmentProcessor* const[], int cnt);

    GrInvariantOutput fInOut;
    int fFirstEffectiveProcessorIndex = 0;
    bool fInputColorIsUsed = true;
    bool fIsLCDCoverage = false;
    GrColor fInputColor = 0;
};

#endif