Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 1 | /* |
| 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 Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 9 | #include "GrAppliedClip.h" |
| 10 | #include "GrCaps.h" |
| 11 | #include "GrProcOptInfo.h" |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 12 | |
| 13 | GrProcessorSet::GrProcessorSet(GrPaint&& paint) { |
| 14 | fXPFactory = paint.fXPFactory; |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 15 | fFlags = 0; |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 16 | 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 Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 32 | } |
| 33 | if (paint.getDisableOutputConversionToSRGB()) { |
| 34 | fFlags |= kDisableOutputConversionToSRGB_Flag; |
| 35 | } |
| 36 | if (paint.getAllowSRGBInputs()) { |
| 37 | fFlags |= kAllowSRGBInputs_Flag; |
| 38 | } |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 39 | } |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 40 | |
| 41 | ////////////////////////////////////////////////////////////////////////////// |
| 42 | |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 43 | void GrProcessorSet::FragmentProcessorAnalysis::internalInit(const GrPipelineInput& colorInput, |
| 44 | const GrPipelineInput coverageInput, |
| 45 | const GrProcessorSet& processors, |
| 46 | const GrFragmentProcessor* clipFP, |
| 47 | const GrCaps& caps) { |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 48 | GrProcOptInfo colorInfo(colorInput); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 49 | fCompatibleWithCoverageAsAlpha = !coverageInput.isLCDCoverage(); |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 50 | fValidInputColor = colorInput.isConstant(&fInputColor); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 51 | |
| 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 Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame] | 58 | fUsesLocalCoords = colorInfo.usesLocalCoords(); |
| 59 | for (int i = 0; i < n; ++i) { |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 60 | 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 Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 65 | } |
Brian Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame] | 66 | fUsesLocalCoords |= fps[i]->usesLocalCoords(); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | if (clipFP) { |
| 70 | fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha(); |
Brian Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame] | 71 | fUsesLocalCoords |= clipFP->usesLocalCoords(); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 72 | hasCoverageFP = true; |
| 73 | } |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 74 | fInitialColorProcessorsToEliminate = colorInfo.initialProcessorsToEliminate(&fInputColor); |
| 75 | fValidInputColor |= SkToBool(fInitialColorProcessorsToEliminate); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 76 | |
| 77 | bool opaque = colorInfo.isOpaque(); |
| 78 | if (colorInfo.hasKnownOutputColor(&fKnownOutputColor)) { |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 79 | fOutputColorType = static_cast<unsigned>(opaque ? ColorType::kOpaqueConstant |
| 80 | : ColorType::kConstant); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 81 | } else if (opaque) { |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 82 | fOutputColorType = static_cast<unsigned>(ColorType::kOpaque); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 83 | } else { |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 84 | fOutputColorType = static_cast<unsigned>(ColorType::kUnknown); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | if (coverageInput.isLCDCoverage()) { |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 88 | fOutputCoverageType = static_cast<unsigned>(CoverageType::kLCD); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 89 | } else { |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 90 | fOutputCoverageType = hasCoverageFP || !coverageInput.isSolidWhite() |
| 91 | ? static_cast<unsigned>(CoverageType::kSingleChannel) |
| 92 | : static_cast<unsigned>(CoverageType::kNone); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 96 | void 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 Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | GrProcessorSet::FragmentProcessorAnalysis::FragmentProcessorAnalysis( |
| 108 | const GrPipelineInput& colorInput, const GrPipelineInput coverageInput, const GrCaps& caps) |
| 109 | : FragmentProcessorAnalysis() { |
Brian Salomon | 8d2f90b | 2017-03-13 09:11:58 -0400 | [diff] [blame^] | 110 | this->internalInit(colorInput, coverageInput, GrProcessorSet(GrPaint()), nullptr, caps); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 111 | } |