Flutter Engine
The Flutter Engine
GrProcessorSet.h
Go to the documentation of this file.
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
16
18class GrAppliedClip;
19class GrXPFactory;
20
22private:
23 // Arbitrary constructor arg for empty set and analysis
24 enum class Empty { kEmpty };
25
26public:
29 GrProcessorSet(std::unique_ptr<GrFragmentProcessor> colorFP);
33
35
36 bool hasColorFragmentProcessor() const { return fColorFragmentProcessor != nullptr; }
37 bool hasCoverageFragmentProcessor() const { return fCoverageFragmentProcessor != nullptr; }
38
40 return fColorFragmentProcessor.get();
41 }
43 return fCoverageFragmentProcessor.get();
44 }
45
47 SkASSERT(this->isFinalized());
48 return fXP.fProcessor;
49 }
51 SkASSERT(this->isFinalized());
52 return sk_ref_sp(fXP.fProcessor);
53 }
54
55 std::unique_ptr<GrFragmentProcessor> detachColorFragmentProcessor() {
56 return std::move(fColorFragmentProcessor);
57 }
58
59 std::unique_ptr<GrFragmentProcessor> detachCoverageFragmentProcessor() {
60 return std::move(fCoverageFragmentProcessor);
61 }
62
63 /** Comparisons are only legal on finalized processor sets. */
64 bool operator==(const GrProcessorSet& that) const;
65 bool operator!=(const GrProcessorSet& that) const { return !(*this == that); }
66
67 /**
68 * This is used to report results of processor analysis when a processor set is finalized (see
69 * below).
70 */
71 class Analysis {
72 public:
73 Analysis(const Analysis&) = default;
74 Analysis() { *reinterpret_cast<uint32_t*>(this) = 0; }
75
76 Analysis& operator=(const Analysis &other) = default;
77
78 bool isInitialized() const { return fIsInitialized; }
79 bool usesLocalCoords() const { return fUsesLocalCoords; }
80 bool requiresDstTexture() const { return fRequiresDstTexture; }
81 bool requiresNonOverlappingDraws() const { return fRequiresNonOverlappingDraws; }
82 bool isCompatibleWithCoverageAsAlpha() const { return fCompatibleWithCoverageAsAlpha; }
83 // Indicates whether all color fragment processors were eliminated in the analysis.
84 bool hasColorFragmentProcessor() const { return fHasColorFragmentProcessor; }
85
86 bool inputColorIsIgnored() const { return fInputColorType == kIgnored_InputColorType; }
88 return fInputColorType == kOverridden_InputColorType;
89 }
90 bool usesNonCoherentHWBlending() const { return fUsesNonCoherentHWBlending; }
91 bool unaffectedByDstValue() const { return fUnaffectedByDstValue; }
92
93 private:
94 constexpr Analysis(Empty)
95 : fUsesLocalCoords(false)
96 , fCompatibleWithCoverageAsAlpha(true)
97 , fRequiresDstTexture(false)
98 , fRequiresNonOverlappingDraws(false)
99 , fHasColorFragmentProcessor(false)
100 , fIsInitialized(true)
101 , fUsesNonCoherentHWBlending(false)
102 , fUnaffectedByDstValue(false)
103 , fInputColorType(kOriginal_InputColorType) {}
104 enum InputColorType : uint32_t {
105 kOriginal_InputColorType,
106 kOverridden_InputColorType,
107 kIgnored_InputColorType
108 };
109
110 // MSVS 2015 won't pack different underlying types
111 using PackedBool = uint32_t;
112 using PackedInputColorType = uint32_t;
113
114 PackedBool fUsesLocalCoords : 1;
115 PackedBool fCompatibleWithCoverageAsAlpha : 1;
116 PackedBool fRequiresDstTexture : 1;
117 PackedBool fRequiresNonOverlappingDraws : 1;
118 PackedBool fHasColorFragmentProcessor : 1;
119 PackedBool fIsInitialized : 1;
120 PackedBool fUsesNonCoherentHWBlending : 1;
121 PackedBool fUnaffectedByDstValue : 1;
122 PackedInputColorType fInputColorType : 2;
123
124 friend class GrProcessorSet;
125 };
126 static_assert(sizeof(Analysis) <= sizeof(uint32_t));
127
128 /**
129 * This analyzes the processors given an op's input color and coverage as well as a clip. The
130 * state of the processor set may change to an equivalent but more optimal set of processors.
131 * This new state requires that the caller respect the returned 'inputColorOverride'. This is
132 * indicated by the returned Analysis's inputColorIsOverridden(). 'inputColorOverride' will not
133 * be written if the analysis does not override the input color.
134 *
135 * This must be called before the processor set is used to construct a GrPipeline and may only
136 * be called once.
137 *
138 * This also puts the processors in "pending execution" state and must be called when an op
139 * that owns a processor set is recorded to ensure pending and writes are propagated to
140 * resources referred to by the processors. Otherwise, data hazards may occur.
141 */
143 const GrAppliedClip*, const GrUserStencilSettings*, const GrCaps&,
144 GrClampType, SkPMColor4f* inputColorOverride);
145
146 bool isFinalized() const { return SkToBool(kFinalized_Flag & fFlags); }
147
148 /** These are valid only for non-LCD coverage. */
149 static const GrProcessorSet& EmptySet();
151 static constexpr Analysis EmptySetAnalysis() { return Analysis(Empty::kEmpty); }
152
153#if defined(GR_TEST_UTILS)
154 SkString dumpProcessors() const;
155#endif
156
157 void visitProxies(const GrVisitProxyFunc&) const;
158
159private:
160 GrProcessorSet(Empty) : fXP((const GrXferProcessor*)nullptr), fFlags(kFinalized_Flag) {}
161
162 int numFragmentProcessors() const {
163 return (fColorFragmentProcessor ? 1 : 0) + (fCoverageFragmentProcessor ? 1 : 0);
164 }
165
166 enum Flags : uint16_t { kFinalized_Flag = 0x1 };
167
168 union XP {
169 XP(const GrXPFactory* factory) : fFactory(factory) {}
170 XP(const GrXferProcessor* processor) : fProcessor(processor) {}
171 explicit XP(XP&& that) : fProcessor(that.fProcessor) {
172 SkASSERT(fProcessor == that.fProcessor);
173 that.fProcessor = nullptr;
174 }
175 const GrXPFactory* fFactory;
176 const GrXferProcessor* fProcessor;
177 };
178
179 const GrXPFactory* xpFactory() const {
180 SkASSERT(!this->isFinalized());
181 return fXP.fFactory;
182 }
183
184 std::unique_ptr<GrFragmentProcessor> fColorFragmentProcessor;
185 std::unique_ptr<GrFragmentProcessor> fCoverageFragmentProcessor;
186 XP fXP;
187 uint8_t fFlags = 0;
188};
189
190#endif
GrProcessorAnalysisCoverage
GrClampType
Definition: GrTypesPriv.h:228
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
Definition: GrTypesPriv.h:943
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBlendMode
Definition: SkBlendMode.h:38
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
Definition: GrCaps.h:57
bool inputColorIsIgnored() const
bool requiresNonOverlappingDraws() const
bool inputColorIsOverridden() const
bool usesLocalCoords() const
Analysis(const Analysis &)=default
bool usesNonCoherentHWBlending() const
bool unaffectedByDstValue() const
bool hasColorFragmentProcessor() const
Analysis & operator=(const Analysis &other)=default
bool requiresDstTexture() const
bool isCompatibleWithCoverageAsAlpha() const
const GrFragmentProcessor * coverageFragmentProcessor() const
std::unique_ptr< GrFragmentProcessor > detachCoverageFragmentProcessor()
bool operator!=(const GrProcessorSet &that) const
static constexpr Analysis EmptySetAnalysis()
bool hasCoverageFragmentProcessor() const
void visitProxies(const GrVisitProxyFunc &) const
std::unique_ptr< GrFragmentProcessor > detachColorFragmentProcessor()
GrProcessorSet & operator=(const GrProcessorSet &)=delete
bool isFinalized() const
bool hasColorFragmentProcessor() const
GrProcessorSet(const GrProcessorSet &)=delete
GrProcessorSet(GrPaint &&)
static const GrProcessorSet & EmptySet()
Analysis finalize(const GrProcessorAnalysisColor &, const GrProcessorAnalysisCoverage, const GrAppliedClip *, const GrUserStencilSettings *, const GrCaps &, GrClampType, SkPMColor4f *inputColorOverride)
bool operator==(const GrProcessorSet &that) const
const GrFragmentProcessor * colorFragmentProcessor() const
const GrXferProcessor * xferProcessor() const
static GrProcessorSet MakeEmptySet()
sk_sp< const GrXferProcessor > refXferProcessor() const