blob: 179456209f1bbad189891a015a58963ceb528835 [file] [log] [blame]
Brian Salomon92ce5942017-01-18 11:01:10 -05001/*
2 * Copyright 2017 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#include "GrProcessorSet.h"
Brian Salomon5298dc82017-02-22 11:52:03 -05009#include "GrAppliedClip.h"
10#include "GrCaps.h"
11#include "GrProcOptInfo.h"
Brian Salomon92ce5942017-01-18 11:01:10 -050012
13GrProcessorSet::GrProcessorSet(GrPaint&& paint) {
14 fXPFactory = paint.fXPFactory;
15 fColorFragmentProcessorCnt = paint.numColorFragmentProcessors();
16 fFragmentProcessors.reset(paint.numTotalFragmentProcessors());
17 int i = 0;
18 for (auto& fp : paint.fColorFragmentProcessors) {
19 fFragmentProcessors[i++] = fp.release();
20 }
21 for (auto& fp : paint.fCoverageFragmentProcessors) {
22 fFragmentProcessors[i++] = fp.release();
23 }
Brian Salomonf87e2b92017-01-19 11:31:50 -050024 fFlags = 0;
25 if (paint.usesDistanceVectorField()) {
26 fFlags |= kUseDistanceVectorField_Flag;
27 }
28 if (paint.getDisableOutputConversionToSRGB()) {
29 fFlags |= kDisableOutputConversionToSRGB_Flag;
30 }
31 if (paint.getAllowSRGBInputs()) {
32 fFlags |= kAllowSRGBInputs_Flag;
33 }
Brian Salomon92ce5942017-01-18 11:01:10 -050034}
Brian Salomon5298dc82017-02-22 11:52:03 -050035
36//////////////////////////////////////////////////////////////////////////////
37
38void GrProcessorSet::FragmentProcessorAnalysis::internalReset(const GrPipelineInput& colorInput,
39 const GrPipelineInput coverageInput,
40 const GrProcessorSet& processors,
41 bool usesPLSDstRead,
42 const GrFragmentProcessor* clipFP,
43 const GrCaps& caps) {
44 GrProcOptInfo colorInfo(colorInput);
45 fUsesPLSDstRead = usesPLSDstRead;
46 fCompatibleWithCoverageAsAlpha = !coverageInput.isLCDCoverage();
47
48 const GrFragmentProcessor* const* fps = processors.fFragmentProcessors.get();
49 colorInfo.analyzeProcessors(fps, processors.fColorFragmentProcessorCnt);
50 fCompatibleWithCoverageAsAlpha &= colorInfo.allProcessorsCompatibleWithCoverageAsAlpha();
51 fps += processors.fColorFragmentProcessorCnt;
52 int n = processors.numCoverageFragmentProcessors();
53 bool hasCoverageFP = n > 0;
54 for (int i = 0; i < n && fCompatibleWithCoverageAsAlpha; ++i) {
55 if (!fps[i]->compatibleWithCoverageAsAlpha()) {
56 fCompatibleWithCoverageAsAlpha = false;
57 // Other than tests that exercise atypical behavior we expect all coverage FPs to be
58 // compatible with the coverage-as-alpha optimization.
59 GrCapsDebugf(&caps, "Coverage FP is not compatible with coverage as alpha.\n");
60 break;
61 }
62 }
63
64 if (clipFP) {
65 fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha();
66 hasCoverageFP = true;
67 }
68 fInitialColorProcessorsToEliminate =
69 colorInfo.initialProcessorsToEliminate(&fOverrideInputColor);
70
71 bool opaque = colorInfo.isOpaque();
72 if (colorInfo.hasKnownOutputColor(&fKnownOutputColor)) {
73 fColorType = opaque ? ColorType::kOpaqueConstant : ColorType::kConstant;
74 } else if (opaque) {
75 fColorType = ColorType::kOpaque;
76 } else {
77 fColorType = ColorType::kUnknown;
78 }
79
80 if (coverageInput.isLCDCoverage()) {
81 fCoverageType = CoverageType::kLCD;
82 } else {
83 fCoverageType = hasCoverageFP || !coverageInput.isSolidWhite()
84 ? CoverageType::kSingleChannel
85 : CoverageType::kNone;
86 }
87}
88
89void GrProcessorSet::FragmentProcessorAnalysis::reset(const GrPipelineInput& colorInput,
90 const GrPipelineInput coverageInput,
91 const GrProcessorSet& processors,
92 bool usesPLSDstRead,
93 const GrAppliedClip& appliedClip,
94 const GrCaps& caps) {
95 this->internalReset(colorInput, coverageInput, processors, usesPLSDstRead,
96 appliedClip.clipCoverageFragmentProcessor(), caps);
97}
98
99GrProcessorSet::FragmentProcessorAnalysis::FragmentProcessorAnalysis(
100 const GrPipelineInput& colorInput, const GrPipelineInput coverageInput, const GrCaps& caps)
101 : FragmentProcessorAnalysis() {
102 this->internalReset(colorInput, coverageInput, GrProcessorSet(GrPaint()), false, nullptr, caps);
103}