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; |
| 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 Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 24 | 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 Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 34 | } |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 35 | |
| 36 | ////////////////////////////////////////////////////////////////////////////// |
| 37 | |
| 38 | void 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 Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame^] | 54 | fUsesLocalCoords = colorInfo.usesLocalCoords(); |
| 55 | for (int i = 0; i < n; ++i) { |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 56 | 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 Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 61 | } |
Brian Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame^] | 62 | fUsesLocalCoords |= fps[i]->usesLocalCoords(); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | if (clipFP) { |
| 66 | fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha(); |
Brian Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame^] | 67 | fUsesLocalCoords |= clipFP->usesLocalCoords(); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 68 | 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 | |
| 91 | void 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 | |
| 101 | GrProcessorSet::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 | } |