OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrXferProcessor_DEFINED | 8 #ifndef GrXferProcessor_DEFINED |
9 #define GrXferProcessor_DEFINED | 9 #define GrXferProcessor_DEFINED |
10 | 10 |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 #include "GrProcessor.h" | 12 #include "GrProcessor.h" |
13 #include "GrTexture.h" | |
13 #include "GrTypes.h" | 14 #include "GrTypes.h" |
14 #include "SkXfermode.h" | 15 #include "SkXfermode.h" |
15 | 16 |
16 class GrDrawTargetCaps; | 17 class GrDrawTargetCaps; |
17 class GrGLCaps; | 18 class GrGLCaps; |
18 class GrGLXferProcessor; | 19 class GrGLXferProcessor; |
19 class GrProcOptInfo; | 20 class GrProcOptInfo; |
20 | 21 |
21 /** | 22 /** |
22 * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst | 23 * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst |
23 * color. It does this by emitting fragment shader code and controlling the fixe d-function blend | 24 * color. It does this by emitting fragment shader code and controlling the fixe d-function blend |
24 * state. The inputs to its shader code are the final computed src color and fra ctional pixel | 25 * state. The inputs to its shader code are the final computed src color and fra ctional pixel |
25 * coverage. The GrXferProcessor's shader code writes the fragment shader output color that goes | 26 * coverage. The GrXferProcessor's shader code writes the fragment shader output color that goes |
26 * into the fixed-function blend. When dual-source blending is available, it may also write a | 27 * into the fixed-function blend. When dual-source blending is available, it may also write a |
27 * seconday fragment shader output color. When allowed by the backend API, the G rXferProcessor may | 28 * seconday fragment shader output color. When allowed by the backend API, the G rXferProcessor may |
28 * read the destination color. The GrXferProcessor is responsible for setting th e blend coefficients | 29 * read the destination color. The GrXferProcessor is responsible for setting th e blend coefficients |
29 * and blend constant color. | 30 * and blend constant color. |
30 * | 31 * |
31 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a | 32 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a |
32 * GrXPFactory once we have finalized the state of our draw. | 33 * GrXPFactory once we have finalized the state of our draw. |
33 */ | 34 */ |
34 class GrXferProcessor : public GrProcessor { | 35 class GrXferProcessor : public GrProcessor { |
35 public: | 36 public: |
36 /** | 37 /** |
37 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this xfer | 38 * Sets a unique key on the GrProcessorKeyBuilder calls onGetGLProcessorKey( ...) to get the |
38 * processor's GL backend implementation. | 39 * sepcific subclasses key. |
bsalomon
2015/01/30 14:59:14
specific subclass's ?
egdaniel
2015/02/03 16:47:43
Done.
| |
39 */ | 40 */ |
40 virtual void getGLProcessorKey(const GrGLCaps& caps, | 41 void getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const ; |
41 GrProcessorKeyBuilder* b) const = 0; | |
42 | 42 |
43 /** Returns a new instance of the appropriate *GL* implementation class | 43 /** Returns a new instance of the appropriate *GL* implementation class |
44 for the given GrXferProcessor; caller is responsible for deleting | 44 for the given GrXferProcessor; caller is responsible for deleting |
45 the object. */ | 45 the object. */ |
46 virtual GrGLXferProcessor* createGLInstance() const = 0; | 46 virtual GrGLXferProcessor* createGLInstance() const = 0; |
47 | 47 |
48 /** | 48 /** |
49 * Optimizations for blending / coverage that an OptDrawState should apply t o itself. | 49 * Optimizations for blending / coverage that an OptDrawState should apply t o itself. |
50 */ | 50 */ |
51 enum OptFlags { | 51 enum OptFlags { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 GrBlendCoeff fDstBlend; | 99 GrBlendCoeff fDstBlend; |
100 GrColor fBlendConstant; | 100 GrColor fBlendConstant; |
101 bool fWriteColor; | 101 bool fWriteColor; |
102 }; | 102 }; |
103 | 103 |
104 virtual void getBlendInfo(BlendInfo* blendInfo) const = 0; | 104 virtual void getBlendInfo(BlendInfo* blendInfo) const = 0; |
105 | 105 |
106 /** Will this prceossor read the destination pixel value? */ | 106 /** Will this prceossor read the destination pixel value? */ |
107 bool willReadDstColor() const { return fWillReadDstColor; } | 107 bool willReadDstColor() const { return fWillReadDstColor; } |
108 | 108 |
109 bool hasDstCopy() const; | |
bsalomon
2015/01/30 14:59:14
different than (bool)getDstCopyTexture()?
egdaniel
2015/02/03 16:47:43
Removed hasDstCopy
| |
110 bool dstCopyIsTopDown() const; | |
bsalomon
2015/01/30 14:59:14
can't we just canonicalize this?
egdaniel
2015/02/03 16:47:43
done
| |
111 | |
112 const GrTexture* getDstCopyTexture() const { return fDstCopy.getTexture(); } | |
bsalomon
2015/01/30 14:59:14
comments?
egdaniel
2015/02/03 16:47:43
Done.
| |
113 | |
114 const SkIPoint& offset() const { return fOffset; } | |
bsalomon
2015/01/30 14:59:14
offset() is a bit vague...
egdaniel
2015/02/03 16:47:43
made name more descriptive "DstcopyTextureOffset"
| |
115 | |
109 /** | 116 /** |
110 * Returns whether or not this xferProcossor will set a secondary output to be used with dual | 117 * Returns whether or not this xferProcossor will set a secondary output to be used with dual |
111 * source blending. | 118 * source blending. |
112 */ | 119 */ |
113 virtual bool hasSecondaryOutput() const { return false; } | 120 virtual bool hasSecondaryOutput() const { return false; } |
114 | 121 |
115 /** Returns true if this and other processor conservatively draw identically . It can only return | 122 /** Returns true if this and other processor conservatively draw identically . It can only return |
116 true when the two processor are of the same subclass (i.e. they return t he same object from | 123 true when the two processor are of the same subclass (i.e. they return t he same object from |
117 from getFactory()). | 124 from getFactory()). |
118 | 125 |
119 A return value of true from isEqual() should not be used to test whether the processor would | 126 A return value of true from isEqual() should not be used to test whether the processor would |
120 generate the same shader code. To test for identical code generation use getGLProcessorKey*/ | 127 generate the same shader code. To test for identical code generation use getGLProcessorKey*/ |
121 | 128 |
122 bool isEqual(const GrXferProcessor& that) const { | 129 bool isEqual(const GrXferProcessor& that) const { |
123 if (this->classID() != that.classID()) { | 130 if (this->classID() != that.classID()) { |
124 return false; | 131 return false; |
125 } | 132 } |
133 if (this->fDstCopy.getTexture() != that.fDstCopy.getTexture()) { | |
134 return false; | |
135 } | |
136 if (this->fOffset != that.fOffset) { | |
137 return false; | |
138 } | |
126 return this->onIsEqual(that); | 139 return this->onIsEqual(that); |
127 } | 140 } |
128 | 141 |
129 protected: | 142 protected: |
130 GrXferProcessor() : fWillReadDstColor(false) {} | 143 GrXferProcessor(); |
144 GrXferProcessor(const GrDeviceCoordTexture* dstCopy, int32_t dstReadKey); | |
131 | 145 |
132 /** | 146 /** |
133 * If the prceossor subclass will read the destination pixel value then it m ust call this | 147 * If the prceossor subclass will read the destination pixel value then it m ust call this |
134 * function from its constructor. Otherwise, when its generated backend-spec ific prceossor class | 148 * function from its constructor. Otherwise, when its generated backend-spec ific prceossor class |
135 * attempts to generate code that reads the destination pixel it will fail. | 149 * attempts to generate code that reads the destination pixel it will fail. |
136 */ | 150 */ |
137 void setWillReadDstColor() { fWillReadDstColor = true; } | 151 void setWillReadDstColor() { fWillReadDstColor = true; } |
138 | 152 |
139 private: | 153 private: |
154 /** | |
155 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this xfer | |
156 * processor's GL backend implementation. | |
157 */ | |
158 virtual void onGetGLProcessorKey(const GrGLCaps& caps, | |
159 GrProcessorKeyBuilder* b) const = 0; | |
160 | |
140 virtual bool onIsEqual(const GrXferProcessor&) const = 0; | 161 virtual bool onIsEqual(const GrXferProcessor&) const = 0; |
141 | 162 |
142 bool fWillReadDstColor; | 163 bool fWillReadDstColor; |
164 uint32_t fDstReadKey; | |
165 GrTextureAccess fDstCopy; | |
166 SkIPoint fOffset; | |
143 | 167 |
144 typedef GrFragmentProcessor INHERITED; | 168 typedef GrFragmentProcessor INHERITED; |
145 }; | 169 }; |
146 | 170 |
147 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); | 171 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); |
148 | 172 |
173 /////////////////////////////////////////////////////////////////////////////// | |
174 | |
149 /** | 175 /** |
150 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is | 176 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is |
151 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the | 177 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the |
152 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the | 178 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the |
153 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for | 179 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for |
154 * the draw. | 180 * the draw. |
155 * | 181 * |
156 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it | 182 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it |
157 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP | 183 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP |
158 * blend with the destination color. | 184 * blend with the destination color. |
159 */ | 185 */ |
160 class GrXPFactory : public SkRefCnt { | 186 class GrXPFactory : public SkRefCnt { |
161 public: | 187 public: |
162 virtual GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, | 188 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, |
163 const GrProcOptInfo& coveragePO I) const = 0; | 189 const GrProcOptInfo& coveragePOI, |
190 const GrDeviceCoordTexture* dstCopy, | |
191 const GrDrawTargetCaps& caps) const; | |
164 | 192 |
165 /** | 193 /** |
166 * This function returns true if the GrXferProcessor generated from this fac tory will be able to | 194 * This function returns true if the GrXferProcessor generated from this fac tory will be able to |
167 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the | 195 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the |
168 * final computed color from the color stages. | 196 * final computed color from the color stages. |
169 */ | 197 */ |
170 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; | 198 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; |
171 | 199 |
172 /** | 200 /** |
173 * Depending on color blend mode requested it may or may not be possible to correctly blend with | 201 * Depending on color blend mode requested it may or may not be possible to correctly blend with |
(...skipping 21 matching lines...) Expand all Loading... | |
195 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI, | 223 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI, |
196 InvariantOutput*) const = 0; | 224 InvariantOutput*) const = 0; |
197 | 225 |
198 /** | 226 /** |
199 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional | 227 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional |
200 * coverage before the blend will give the correct final destination color. In general it | 228 * coverage before the blend will give the correct final destination color. In general it |
201 * will not as coverage is applied after blending. | 229 * will not as coverage is applied after blending. |
202 */ | 230 */ |
203 virtual bool canTweakAlphaForCoverage() const = 0; | 231 virtual bool canTweakAlphaForCoverage() const = 0; |
204 | 232 |
205 /** | 233 bool willNeedDstCopy(const GrDrawTargetCaps& caps) const; |
206 * Returns true if the XP generated by this factory will read dst. | |
207 */ | |
208 virtual bool willReadDst() const = 0; | |
209 | 234 |
210 bool isEqual(const GrXPFactory& that) const { | 235 bool isEqual(const GrXPFactory& that) const { |
211 if (this->classID() != that.classID()) { | 236 if (this->classID() != that.classID()) { |
212 return false; | 237 return false; |
213 } | 238 } |
214 return this->onIsEqual(that); | 239 return this->onIsEqual(that); |
215 } | 240 } |
216 | 241 |
217 /** | 242 /** |
218 * Helper for down-casting to a GrXPFactory subclass | 243 * Helper for down-casting to a GrXPFactory subclass |
219 */ | 244 */ |
220 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } | 245 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } |
221 | 246 |
222 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; } | 247 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; } |
223 | 248 |
224 protected: | 249 protected: |
225 GrXPFactory() : fClassID(kIllegalXPFClassID) {} | 250 GrXPFactory() : fClassID(kIllegalXPFClassID) {} |
226 | 251 |
227 template <typename XPF_SUBCLASS> void initClassID() { | 252 template <typename XPF_SUBCLASS> void initClassID() { |
228 static uint32_t kClassID = GenClassID(); | 253 static uint32_t kClassID = GenClassID(); |
229 fClassID = kClassID; | 254 fClassID = kClassID; |
230 } | 255 } |
231 | 256 |
232 uint32_t fClassID; | 257 uint32_t fClassID; |
233 | 258 |
234 private: | 259 private: |
260 virtual GrXferProcessor* onCreateXferProcessor(const GrProcOptInfo& colorPOI , | |
261 const GrProcOptInfo& coverage POI, | |
262 const GrDeviceCoordTexture* d stCopy, | |
263 int32_t dstReadKey) const = 0 ; | |
264 /** | |
265 * Returns true if the XP generated by this factory will read dst. | |
266 */ | |
267 virtual bool willReadDst() const = 0; | |
bsalomon
2015/01/30 14:59:14
maybe make it clear that this refers to reading th
egdaniel
2015/02/03 16:47:43
Done.
| |
268 | |
235 virtual bool onIsEqual(const GrXPFactory&) const = 0; | 269 virtual bool onIsEqual(const GrXPFactory&) const = 0; |
236 | 270 |
237 static uint32_t GenClassID() { | 271 static uint32_t GenClassID() { |
238 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The | 272 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The |
239 // atomic inc returns the old value not the incremented value. So we add | 273 // atomic inc returns the old value not the incremented value. So we add |
240 // 1 to the returned value. | 274 // 1 to the returned value. |
241 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1 ; | 275 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1 ; |
242 if (!id) { | 276 if (!id) { |
243 SkFAIL("This should never wrap as it should only be called once for each GrXPFactory " | 277 SkFAIL("This should never wrap as it should only be called once for each GrXPFactory " |
244 "subclass."); | 278 "subclass."); |
245 } | 279 } |
246 return id; | 280 return id; |
247 } | 281 } |
248 | 282 |
249 enum { | 283 enum { |
250 kIllegalXPFClassID = 0, | 284 kIllegalXPFClassID = 0, |
251 }; | 285 }; |
252 static int32_t gCurrXPFClassID; | 286 static int32_t gCurrXPFClassID; |
253 | 287 |
254 typedef GrProgramElement INHERITED; | 288 typedef GrProgramElement INHERITED; |
255 }; | 289 }; |
256 | 290 |
257 #endif | 291 #endif |
258 | 292 |
OLD | NEW |