aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrProcessorAnalysis.cpp
blob: 2bbb54653ac0af13174786441d70d5fbd3f982e0 (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
/*
 * 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 "GrProcessorAnalysis.h"
#include "GrGeometryProcessor.h"
#include "ops/GrDrawOp.h"

GrColorFragmentProcessorAnalysis::GrColorFragmentProcessorAnalysis(
        const GrProcessorAnalysisColor& input,
        const GrFragmentProcessor* const* processors,
        int cnt) {
    fCompatibleWithCoverageAsAlpha = true;
    fIsOpaque = input.isOpaque();
    fUsesLocalCoords = false;
    fProcessorsToEliminate = 0;
    GrColor color;
    if ((fKnowOutputColor = input.isConstant(&color))) {
        fLastKnownOutputColor = GrColor4f::FromGrColor(color);
    }
    for (int i = 0; i < cnt; ++i) {
        if (fUsesLocalCoords && !fKnowOutputColor && !fCompatibleWithCoverageAsAlpha &&
            !fIsOpaque) {
            break;
        }
        const GrFragmentProcessor* fp = processors[i];
        if (fKnowOutputColor &&
            fp->hasConstantOutputForConstantInput(fLastKnownOutputColor, &fLastKnownOutputColor)) {
            ++fProcessorsToEliminate;
            fIsOpaque = fLastKnownOutputColor.isOpaque();
            // We reset these since the caller is expected to not use the earlier fragment
            // processors.
            fCompatibleWithCoverageAsAlpha = true;
            fUsesLocalCoords = false;
        } else {
            fKnowOutputColor = false;
            if (fIsOpaque && !fp->preservesOpaqueInput()) {
                fIsOpaque = false;
            }
            if (fCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) {
                fCompatibleWithCoverageAsAlpha = false;
            }
            if (fp->usesLocalCoords()) {
                fUsesLocalCoords = true;
            }
        }
    }
}