blob: c4b82621d1f8853dd2088b1baed460bcd6e357f8 [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;
Brian Salomonf87e2b92017-01-19 11:31:50 -050015 fFlags = 0;
Brian Salomon8d2f90b2017-03-13 09:11:58 -040016 if (paint.numColorFragmentProcessors() <= kMaxColorProcessors) {
17 fColorFragmentProcessorCnt = paint.numColorFragmentProcessors();
18 fFragmentProcessors.reset(paint.numTotalFragmentProcessors());
19 int i = 0;
20 for (auto& fp : paint.fColorFragmentProcessors) {
21 fFragmentProcessors[i++] = fp.release();
22 }
23 for (auto& fp : paint.fCoverageFragmentProcessors) {
24 fFragmentProcessors[i++] = fp.release();
25 }
26 if (paint.usesDistanceVectorField()) {
27 fFlags |= kUseDistanceVectorField_Flag;
28 }
29 } else {
30 SkDebugf("Insane number of color fragment processors in paint. Dropping all processors.");
31 fColorFragmentProcessorCnt = 0;
Brian Salomonf87e2b92017-01-19 11:31:50 -050032 }
33 if (paint.getDisableOutputConversionToSRGB()) {
34 fFlags |= kDisableOutputConversionToSRGB_Flag;
35 }
36 if (paint.getAllowSRGBInputs()) {
37 fFlags |= kAllowSRGBInputs_Flag;
38 }
Brian Salomon92ce5942017-01-18 11:01:10 -050039}
Brian Salomon5298dc82017-02-22 11:52:03 -050040
41//////////////////////////////////////////////////////////////////////////////
42
Brian Salomon8d2f90b2017-03-13 09:11:58 -040043void GrProcessorSet::FragmentProcessorAnalysis::internalInit(const GrPipelineInput& colorInput,
44 const GrPipelineInput coverageInput,
45 const GrProcessorSet& processors,
46 const GrFragmentProcessor* clipFP,
47 const GrCaps& caps) {
Brian Salomon5298dc82017-02-22 11:52:03 -050048 GrProcOptInfo colorInfo(colorInput);
Brian Salomon5298dc82017-02-22 11:52:03 -050049 fCompatibleWithCoverageAsAlpha = !coverageInput.isLCDCoverage();
Brian Salomon8d2f90b2017-03-13 09:11:58 -040050 fValidInputColor = colorInput.isConstant(&fInputColor);
Brian Salomon5298dc82017-02-22 11:52:03 -050051
52 const GrFragmentProcessor* const* fps = processors.fFragmentProcessors.get();
53 colorInfo.analyzeProcessors(fps, processors.fColorFragmentProcessorCnt);
54 fCompatibleWithCoverageAsAlpha &= colorInfo.allProcessorsCompatibleWithCoverageAsAlpha();
55 fps += processors.fColorFragmentProcessorCnt;
56 int n = processors.numCoverageFragmentProcessors();
57 bool hasCoverageFP = n > 0;
Brian Salomonbfafcba2017-03-02 08:49:19 -050058 fUsesLocalCoords = colorInfo.usesLocalCoords();
59 for (int i = 0; i < n; ++i) {
Brian Salomon5298dc82017-02-22 11:52:03 -050060 if (!fps[i]->compatibleWithCoverageAsAlpha()) {
61 fCompatibleWithCoverageAsAlpha = false;
62 // Other than tests that exercise atypical behavior we expect all coverage FPs to be
63 // compatible with the coverage-as-alpha optimization.
64 GrCapsDebugf(&caps, "Coverage FP is not compatible with coverage as alpha.\n");
Brian Salomon5298dc82017-02-22 11:52:03 -050065 }
Brian Salomonbfafcba2017-03-02 08:49:19 -050066 fUsesLocalCoords |= fps[i]->usesLocalCoords();
Brian Salomon5298dc82017-02-22 11:52:03 -050067 }
68
69 if (clipFP) {
70 fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha();
Brian Salomonbfafcba2017-03-02 08:49:19 -050071 fUsesLocalCoords |= clipFP->usesLocalCoords();
Brian Salomon5298dc82017-02-22 11:52:03 -050072 hasCoverageFP = true;
73 }
Brian Salomon8d2f90b2017-03-13 09:11:58 -040074 fInitialColorProcessorsToEliminate = colorInfo.initialProcessorsToEliminate(&fInputColor);
75 fValidInputColor |= SkToBool(fInitialColorProcessorsToEliminate);
Brian Salomon5298dc82017-02-22 11:52:03 -050076
77 bool opaque = colorInfo.isOpaque();
78 if (colorInfo.hasKnownOutputColor(&fKnownOutputColor)) {
Brian Salomon8d2f90b2017-03-13 09:11:58 -040079 fOutputColorType = static_cast<unsigned>(opaque ? ColorType::kOpaqueConstant
80 : ColorType::kConstant);
Brian Salomon5298dc82017-02-22 11:52:03 -050081 } else if (opaque) {
Brian Salomon8d2f90b2017-03-13 09:11:58 -040082 fOutputColorType = static_cast<unsigned>(ColorType::kOpaque);
Brian Salomon5298dc82017-02-22 11:52:03 -050083 } else {
Brian Salomon8d2f90b2017-03-13 09:11:58 -040084 fOutputColorType = static_cast<unsigned>(ColorType::kUnknown);
Brian Salomon5298dc82017-02-22 11:52:03 -050085 }
86
87 if (coverageInput.isLCDCoverage()) {
Brian Salomon8d2f90b2017-03-13 09:11:58 -040088 fOutputCoverageType = static_cast<unsigned>(CoverageType::kLCD);
Brian Salomon5298dc82017-02-22 11:52:03 -050089 } else {
Brian Salomon8d2f90b2017-03-13 09:11:58 -040090 fOutputCoverageType = hasCoverageFP || !coverageInput.isSolidWhite()
91 ? static_cast<unsigned>(CoverageType::kSingleChannel)
92 : static_cast<unsigned>(CoverageType::kNone);
Brian Salomon5298dc82017-02-22 11:52:03 -050093 }
94}
95
Brian Salomon8d2f90b2017-03-13 09:11:58 -040096void GrProcessorSet::FragmentProcessorAnalysis::init(const GrPipelineInput& colorInput,
97 const GrPipelineInput coverageInput,
98 const GrProcessorSet& processors,
99 const GrAppliedClip* appliedClip,
100 const GrCaps& caps) {
101 const GrFragmentProcessor* clipFP =
102 appliedClip ? appliedClip->clipCoverageFragmentProcessor() : nullptr;
103 this->internalInit(colorInput, coverageInput, processors, clipFP, caps);
104 fIsInitializedWithProcessorSet = true;
Brian Salomon5298dc82017-02-22 11:52:03 -0500105}
106
107GrProcessorSet::FragmentProcessorAnalysis::FragmentProcessorAnalysis(
108 const GrPipelineInput& colorInput, const GrPipelineInput coverageInput, const GrCaps& caps)
109 : FragmentProcessorAnalysis() {
Brian Salomon8d2f90b2017-03-13 09:11:58 -0400110 this->internalInit(colorInput, coverageInput, GrProcessorSet(GrPaint()), nullptr, caps);
Brian Salomon5298dc82017-02-22 11:52:03 -0500111}