aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrProcOptInfo.cpp
blob: 18a32020d4539154ca9d993ea98698ea05f3c35f (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
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrProcOptInfo.h"

#include "GrGeometryProcessor.h"
#include "GrFragmentStage.h"

void GrProcOptInfo::calcWithInitialValues(const GrFragmentStage* stages,
                                          int stageCount,
                                          GrColor startColor,
                                          GrColorComponentFlags flags,
                                          bool areCoverageStages,
                                          const GrGeometryProcessor* gp) {
    fInOut.reset(startColor, flags, areCoverageStages);
    fFirstEffectStageIndex = 0;
    fInputColorIsUsed = true;
    fInputColor = startColor;
    fRemoveVertexAttrib = false;
    fReadsDst = false;

    if (areCoverageStages && gp) {
        gp->computeInvariantOutput(&fInOut);
    }

    for (int i = 0; i < stageCount; ++i) {
        const GrFragmentProcessor* processor = stages[i].getProcessor();
        fInOut.resetWillUseInputColor();
        processor->computeInvariantOutput(&fInOut);
        #ifdef SK_DEBUG
        fInOut.validate();
        #endif
        if (!fInOut.willUseInputColor()) {
            fFirstEffectStageIndex = i;
            fInputColorIsUsed = false;
            fReadsDst = false; // Reset this since we don't care if previous stages read dst
        }
        if (processor->willReadDstColor()) {
            fReadsDst = true;
        }
        if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
            fFirstEffectStageIndex = i + 1;
            fInputColor = fInOut.color();
            fInputColorIsUsed = true;
            fRemoveVertexAttrib = true;
            // Since we are clearing all previous color stages we are in a state where we have found
            // zero stages that don't multiply the inputColor.
            fInOut.resetNonMulStageFound();
            fReadsDst = false; // Reset this since we don't care if previous stages read dst
        }
    }
}