blob: c61fe8bc79bd2744b5b22f008975fac7c8d39de9 [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;
Brian Salomonbfafcba2017-03-02 08:49:19 -050054 fUsesLocalCoords = colorInfo.usesLocalCoords();
55 for (int i = 0; i < n; ++i) {
Brian Salomon5298dc82017-02-22 11:52:03 -050056 if (!fps[i]->compatibleWithCoverageAsAlpha()) {
57 fCompatibleWithCoverageAsAlpha = false;
58 // Other than tests that exercise atypical behavior we expect all coverage FPs to be
59 // compatible with the coverage-as-alpha optimization.
60 GrCapsDebugf(&caps, "Coverage FP is not compatible with coverage as alpha.\n");
Brian Salomon5298dc82017-02-22 11:52:03 -050061 }
Brian Salomonbfafcba2017-03-02 08:49:19 -050062 fUsesLocalCoords |= fps[i]->usesLocalCoords();
Brian Salomon5298dc82017-02-22 11:52:03 -050063 }
64
65 if (clipFP) {
66 fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha();
Brian Salomonbfafcba2017-03-02 08:49:19 -050067 fUsesLocalCoords |= clipFP->usesLocalCoords();
Brian Salomon5298dc82017-02-22 11:52:03 -050068 hasCoverageFP = true;
69 }
70 fInitialColorProcessorsToEliminate =
71 colorInfo.initialProcessorsToEliminate(&fOverrideInputColor);
72
73 bool opaque = colorInfo.isOpaque();
74 if (colorInfo.hasKnownOutputColor(&fKnownOutputColor)) {
75 fColorType = opaque ? ColorType::kOpaqueConstant : ColorType::kConstant;
76 } else if (opaque) {
77 fColorType = ColorType::kOpaque;
78 } else {
79 fColorType = ColorType::kUnknown;
80 }
81
82 if (coverageInput.isLCDCoverage()) {
83 fCoverageType = CoverageType::kLCD;
84 } else {
85 fCoverageType = hasCoverageFP || !coverageInput.isSolidWhite()
86 ? CoverageType::kSingleChannel
87 : CoverageType::kNone;
88 }
89}
90
91void GrProcessorSet::FragmentProcessorAnalysis::reset(const GrPipelineInput& colorInput,
92 const GrPipelineInput coverageInput,
93 const GrProcessorSet& processors,
94 bool usesPLSDstRead,
95 const GrAppliedClip& appliedClip,
96 const GrCaps& caps) {
97 this->internalReset(colorInput, coverageInput, processors, usesPLSDstRead,
98 appliedClip.clipCoverageFragmentProcessor(), caps);
99}
100
101GrProcessorSet::FragmentProcessorAnalysis::FragmentProcessorAnalysis(
102 const GrPipelineInput& colorInput, const GrPipelineInput coverageInput, const GrCaps& caps)
103 : FragmentProcessorAnalysis() {
104 this->internalReset(colorInput, coverageInput, GrProcessorSet(GrPaint()), false, nullptr, caps);
105}