aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrProcessorSet.cpp
blob: 179456209f1bbad189891a015a58963ceb528835 (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
97
98
99
100
101
102
103
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrProcessorSet.h"
#include "GrAppliedClip.h"
#include "GrCaps.h"
#include "GrProcOptInfo.h"

GrProcessorSet::GrProcessorSet(GrPaint&& paint) {
    fXPFactory = paint.fXPFactory;
    fColorFragmentProcessorCnt = paint.numColorFragmentProcessors();
    fFragmentProcessors.reset(paint.numTotalFragmentProcessors());
    int i = 0;
    for (auto& fp : paint.fColorFragmentProcessors) {
        fFragmentProcessors[i++] = fp.release();
    }
    for (auto& fp : paint.fCoverageFragmentProcessors) {
        fFragmentProcessors[i++] = fp.release();
    }
    fFlags = 0;
    if (paint.usesDistanceVectorField()) {
        fFlags |= kUseDistanceVectorField_Flag;
    }
    if (paint.getDisableOutputConversionToSRGB()) {
        fFlags |= kDisableOutputConversionToSRGB_Flag;
    }
    if (paint.getAllowSRGBInputs()) {
        fFlags |= kAllowSRGBInputs_Flag;
    }
}

//////////////////////////////////////////////////////////////////////////////

void GrProcessorSet::FragmentProcessorAnalysis::internalReset(const GrPipelineInput& colorInput,
                                                              const GrPipelineInput coverageInput,
                                                              const GrProcessorSet& processors,
                                                              bool usesPLSDstRead,
                                                              const GrFragmentProcessor* clipFP,
                                                              const GrCaps& caps) {
    GrProcOptInfo colorInfo(colorInput);
    fUsesPLSDstRead = usesPLSDstRead;
    fCompatibleWithCoverageAsAlpha = !coverageInput.isLCDCoverage();

    const GrFragmentProcessor* const* fps = processors.fFragmentProcessors.get();
    colorInfo.analyzeProcessors(fps, processors.fColorFragmentProcessorCnt);
    fCompatibleWithCoverageAsAlpha &= colorInfo.allProcessorsCompatibleWithCoverageAsAlpha();
    fps += processors.fColorFragmentProcessorCnt;
    int n = processors.numCoverageFragmentProcessors();
    bool hasCoverageFP = n > 0;
    for (int i = 0; i < n && fCompatibleWithCoverageAsAlpha; ++i) {
        if (!fps[i]->compatibleWithCoverageAsAlpha()) {
            fCompatibleWithCoverageAsAlpha = false;
            // Other than tests that exercise atypical behavior we expect all coverage FPs to be
            // compatible with the coverage-as-alpha optimization.
            GrCapsDebugf(&caps, "Coverage FP is not compatible with coverage as alpha.\n");
            break;
        }
    }

    if (clipFP) {
        fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha();
        hasCoverageFP = true;
    }
    fInitialColorProcessorsToEliminate =
            colorInfo.initialProcessorsToEliminate(&fOverrideInputColor);

    bool opaque = colorInfo.isOpaque();
    if (colorInfo.hasKnownOutputColor(&fKnownOutputColor)) {
        fColorType = opaque ? ColorType::kOpaqueConstant : ColorType::kConstant;
    } else if (opaque) {
        fColorType = ColorType::kOpaque;
    } else {
        fColorType = ColorType::kUnknown;
    }

    if (coverageInput.isLCDCoverage()) {
        fCoverageType = CoverageType::kLCD;
    } else {
        fCoverageType = hasCoverageFP || !coverageInput.isSolidWhite()
                                ? CoverageType::kSingleChannel
                                : CoverageType::kNone;
    }
}

void GrProcessorSet::FragmentProcessorAnalysis::reset(const GrPipelineInput& colorInput,
                                                      const GrPipelineInput coverageInput,
                                                      const GrProcessorSet& processors,
                                                      bool usesPLSDstRead,
                                                      const GrAppliedClip& appliedClip,
                                                      const GrCaps& caps) {
    this->internalReset(colorInput, coverageInput, processors, usesPLSDstRead,
                        appliedClip.clipCoverageFragmentProcessor(), caps);
}

GrProcessorSet::FragmentProcessorAnalysis::FragmentProcessorAnalysis(
        const GrPipelineInput& colorInput, const GrPipelineInput coverageInput, const GrCaps& caps)
        : FragmentProcessorAnalysis() {
    this->internalReset(colorInput, coverageInput, GrProcessorSet(GrPaint()), false, nullptr, caps);
}