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 | #ifndef GrProcessorSet_DEFINED |
| 9 | #define GrProcessorSet_DEFINED |
| 10 | |
| 11 | #include "GrFragmentProcessor.h" |
| 12 | #include "GrPaint.h" |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame^] | 13 | #include "GrPipelineInput.h" |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 14 | #include "SkTemplates.h" |
| 15 | |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame^] | 16 | class GrAppliedClip; |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 17 | class GrXPFactory; |
| 18 | |
| 19 | class GrProcessorSet : private SkNoncopyable { |
| 20 | public: |
| 21 | GrProcessorSet(GrPaint&& paint); |
| 22 | |
| 23 | ~GrProcessorSet() { |
| 24 | // We are deliberately not using sk_sp here because this will be updated to work with |
| 25 | // "pending execution" refs. |
| 26 | for (auto fp : fFragmentProcessors) { |
| 27 | fp->unref(); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | int numColorFragmentProcessors() const { return fColorFragmentProcessorCnt; } |
| 32 | int numCoverageFragmentProcessors() const { |
| 33 | return fFragmentProcessors.count() - fColorFragmentProcessorCnt; |
| 34 | } |
| 35 | int numFragmentProcessors() const { return fFragmentProcessors.count(); } |
| 36 | |
| 37 | const GrFragmentProcessor* colorFragmentProcessor(int idx) const { |
| 38 | SkASSERT(idx < fColorFragmentProcessorCnt); |
| 39 | return fFragmentProcessors[idx]; |
| 40 | } |
| 41 | const GrFragmentProcessor* coverageFragmentProcessor(int idx) const { |
| 42 | return fFragmentProcessors[idx + fColorFragmentProcessorCnt]; |
| 43 | } |
| 44 | |
| 45 | const GrXPFactory* xpFactory() const { return fXPFactory; } |
| 46 | |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 47 | bool usesDistanceVectorField() const { return SkToBool(fFlags & kUseDistanceVectorField_Flag); } |
| 48 | bool disableOutputConversionToSRGB() const { |
| 49 | return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag); |
| 50 | } |
| 51 | bool allowSRGBInputs() const { return SkToBool(fFlags & kAllowSRGBInputs_Flag); } |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 52 | |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame^] | 53 | /** |
| 54 | * This is used to track analysis of color and coverage values through the fragment processors. |
| 55 | */ |
| 56 | class FragmentProcessorAnalysis { |
| 57 | public: |
| 58 | FragmentProcessorAnalysis() = default; |
| 59 | // This version is used by a unit test that assumes no clip, no processors, and no PLS. |
| 60 | FragmentProcessorAnalysis(const GrPipelineInput& colorInput, |
| 61 | const GrPipelineInput coverageInput, const GrCaps&); |
| 62 | |
| 63 | void reset(const GrPipelineInput& colorInput, const GrPipelineInput coverageInput, |
| 64 | const GrProcessorSet&, bool usesPLSDstRead, const GrAppliedClip&, const GrCaps&); |
| 65 | |
| 66 | int initialColorProcessorsToEliminate(GrColor* newInputColor) const { |
| 67 | if (fInitialColorProcessorsToEliminate > 0) { |
| 68 | *newInputColor = fOverrideInputColor; |
| 69 | } |
| 70 | return fInitialColorProcessorsToEliminate; |
| 71 | } |
| 72 | |
| 73 | bool usesPLSDstRead() const { return fUsesPLSDstRead; } |
| 74 | bool isCompatibleWithCoverageAsAlpha() const { return fCompatibleWithCoverageAsAlpha; } |
| 75 | bool isOutputColorOpaque() const { |
| 76 | return ColorType::kOpaque == fColorType || ColorType::kOpaqueConstant == fColorType; |
| 77 | } |
| 78 | bool hasKnownOutputColor(GrColor* color = nullptr) const { |
| 79 | bool constant = |
| 80 | ColorType::kConstant == fColorType || ColorType::kOpaqueConstant == fColorType; |
| 81 | if (constant && color) { |
| 82 | *color = fKnownOutputColor; |
| 83 | } |
| 84 | return constant; |
| 85 | } |
| 86 | bool hasCoverage() const { return CoverageType::kNone != fCoverageType; } |
| 87 | bool hasLCDCoverage() const { return CoverageType::kLCD == fCoverageType; } |
| 88 | |
| 89 | private: |
| 90 | void internalReset(const GrPipelineInput& colorInput, const GrPipelineInput coverageInput, |
| 91 | const GrProcessorSet&, bool usesPLSDstRead, |
| 92 | const GrFragmentProcessor* clipFP, const GrCaps&); |
| 93 | |
| 94 | enum class ColorType { kUnknown, kOpaqueConstant, kConstant, kOpaque }; |
| 95 | enum class CoverageType { kNone, kSingleChannel, kLCD }; |
| 96 | |
| 97 | bool fUsesPLSDstRead = false; |
| 98 | bool fCompatibleWithCoverageAsAlpha = true; |
| 99 | CoverageType fCoverageType = CoverageType::kNone; |
| 100 | ColorType fColorType = ColorType::kUnknown; |
| 101 | int fInitialColorProcessorsToEliminate = 0; |
| 102 | GrColor fOverrideInputColor; |
| 103 | GrColor fKnownOutputColor; |
| 104 | }; |
| 105 | |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 106 | private: |
| 107 | const GrXPFactory* fXPFactory = nullptr; |
| 108 | SkAutoSTArray<4, const GrFragmentProcessor*> fFragmentProcessors; |
| 109 | int fColorFragmentProcessorCnt; |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 110 | enum Flags : uint32_t { |
| 111 | kUseDistanceVectorField_Flag = 0x1, |
| 112 | kDisableOutputConversionToSRGB_Flag = 0x2, |
| 113 | kAllowSRGBInputs_Flag = 0x4 |
| 114 | }; |
| 115 | uint32_t fFlags; |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | #endif |