OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkXfermode_DEFINED | 10 #ifndef SkXfermode_DEFINED |
11 #define SkXfermode_DEFINED | 11 #define SkXfermode_DEFINED |
12 | 12 |
13 #include "SkFlattenable.h" | 13 #include "SkFlattenable.h" |
14 #include "SkColor.h" | 14 #include "SkColor.h" |
15 | 15 |
16 class GrFragmentProcessor; | 16 class GrFragmentProcessor; |
17 class GrTexture; | 17 class GrTexture; |
| 18 class GrXPFactory; |
18 class SkString; | 19 class SkString; |
19 | 20 |
20 /** \class SkXfermode | 21 /** \class SkXfermode |
21 * | 22 * |
22 * SkXfermode is the base class for objects that are called to implement custom | 23 * SkXfermode is the base class for objects that are called to implement custom |
23 * "transfer-modes" in the drawing pipeline. The static function Create(Modes) | 24 * "transfer-modes" in the drawing pipeline. The static function Create(Modes) |
24 * can be called to return an instance of any of the predefined subclasses as | 25 * can be called to return an instance of any of the predefined subclasses as |
25 * specified in the Modes enum. When an SkXfermode is assigned to an SkPaint, | 26 * specified in the Modes enum. When an SkXfermode is assigned to an SkPaint, |
26 * then objects drawn with that paint have the xfermode applied. | 27 * then objects drawn with that paint have the xfermode applied. |
27 * | 28 * |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 192 |
192 /** A subclass may implement this factory function to work with the GPU back
end. It is legal | 193 /** A subclass may implement this factory function to work with the GPU back
end. It is legal |
193 to call this with all params NULL to simply test the return value. If ef
fect is non-NULL | 194 to call this with all params NULL to simply test the return value. If ef
fect is non-NULL |
194 then the xfermode may optionally allocate an effect to return and the ca
ller as *effect. | 195 then the xfermode may optionally allocate an effect to return and the ca
ller as *effect. |
195 The caller will install it and own a ref to it. Since the xfermode may o
r may not assign | 196 The caller will install it and own a ref to it. Since the xfermode may o
r may not assign |
196 *effect, the caller should set *effect to NULL beforehand. background sp
ecifies the | 197 *effect, the caller should set *effect to NULL beforehand. background sp
ecifies the |
197 texture to use as the background for compositing, and should be accessed
in the effect's | 198 texture to use as the background for compositing, and should be accessed
in the effect's |
198 fragment shader. If NULL, the effect should request access to destinatio
n color | 199 fragment shader. If NULL, the effect should request access to destinatio
n color |
199 (setWillReadDstColor()), and use that in the fragment shader (builder->d
stColor()). | 200 (setWillReadDstColor()), and use that in the fragment shader (builder->d
stColor()). |
200 */ | 201 */ |
| 202 // TODO: Once all custom xp's have been created the background parameter wil
l be required here. |
| 203 // We will always use the XPFactory if there is no background texture
and the fragment if |
| 204 // there is one. |
201 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture* backgroun
d = NULL) const; | 205 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture* backgroun
d = NULL) const; |
202 | 206 |
203 /** Returns true if the xfermode can be expressed as coeffs (src, dst), or a
s an effect | 207 /** A subclass may implement this factory function to work with the GPU back
end. It is legal |
204 (effect). This helper calls the asCoeff() and asFragmentProcessor() virt
uals. If the | 208 to call this with xpf NULL to simply test the return value. If xpf is no
n-NULL then the |
205 xfermode is NULL, it is treated as kSrcOver_Mode. It is legal to call th
is with all params | 209 xfermode may optionally allocate a factory to return to the caller as *x
pf. The caller |
206 NULL to simply test the return value. effect, src, and dst must all be
NULL or all | 210 will install it and own a ref to it. Since the xfermode may or may not a
ssign *xpf, the |
207 non-NULL. | 211 caller should set *xpf to NULL beforehand. XP's cannot use a background
texture since they |
| 212 have no coord transforms. |
208 */ | 213 */ |
209 static bool asFragmentProcessorOrCoeff(SkXfermode*, GrFragmentProcessor**, C
oeff* src, | 214 virtual bool asXPFactory(GrXPFactory** xpf) const; |
210 Coeff* dst, GrTexture* background = N
ULL); | 215 |
| 216 /** Returns true if the xfermode can be expressed as an xfer processor facto
ry (xpFactory), |
| 217 or a fragment processor. This helper calls the asCoeff(), asXPFactory(), |
| 218 and asFragmentProcessor() virtuals. If the xfermode is NULL, it is treat
ed as kSrcOver_Mode. |
| 219 It is legal to call this with all params NULL to simply test the return
value. |
| 220 fp, xpf, src, and dst must all be NULL or all non-NULL. |
| 221 */ |
| 222 static bool AsFragmentProcessorOrXPFactory(SkXfermode*, GrFragmentProcessor*
*, |
| 223 GrXPFactory**, Coeff* src, Coeff*
dst); |
211 | 224 |
212 SK_TO_STRING_PUREVIRT() | 225 SK_TO_STRING_PUREVIRT() |
213 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 226 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
214 SK_DEFINE_FLATTENABLE_TYPE(SkXfermode) | 227 SK_DEFINE_FLATTENABLE_TYPE(SkXfermode) |
215 | 228 |
216 protected: | 229 protected: |
217 SkXfermode() {} | 230 SkXfermode() {} |
218 /** The default implementation of xfer32/xfer16/xferA8 in turn call this | 231 /** The default implementation of xfer32/xfer16/xferA8 in turn call this |
219 method, 1 color at a time (upscaled to a SkPMColor). The default | 232 method, 1 color at a time (upscaled to a SkPMColor). The default |
220 implmentation of this method just returns dst. If performance is | 233 implmentation of this method just returns dst. If performance is |
221 important, your subclass should override xfer32/xfer16/xferA8 directly. | 234 important, your subclass should override xfer32/xfer16/xferA8 directly. |
222 | 235 |
223 This method will not be called directly by the client, so it need not | 236 This method will not be called directly by the client, so it need not |
224 be implemented if your subclass has overridden xfer32/xfer16/xferA8 | 237 be implemented if your subclass has overridden xfer32/xfer16/xferA8 |
225 */ | 238 */ |
226 virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const; | 239 virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const; |
227 | 240 |
228 private: | 241 private: |
229 enum { | 242 enum { |
230 kModeCount = kLastMode + 1 | 243 kModeCount = kLastMode + 1 |
231 }; | 244 }; |
232 | 245 |
233 typedef SkFlattenable INHERITED; | 246 typedef SkFlattenable INHERITED; |
234 }; | 247 }; |
235 | 248 |
236 #endif | 249 #endif |
OLD | NEW |