OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2006 The Android Open Source Project | |
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 SkAvoidXfermode_DEFINED | |
9 #define SkAvoidXfermode_DEFINED | |
10 | |
11 #include "SkColor.h" | |
12 #include "SkTypes.h" | |
13 #include "SkXfermode.h" | |
14 | |
15 /** \class AvoidXfermode | |
16 | |
17 This xfermode will draw the src everywhere except on top of the specified | |
18 color. | |
19 */ | |
20 class SkAvoidXfermode : public SkXfermode { | |
21 public: | |
22 enum Mode { | |
23 kAvoidColor_Mode, //!< draw everywhere except on the opColor | |
24 kTargetColor_Mode //!< draw only on top of the opColor | |
25 }; | |
26 | |
27 /** This xfermode draws, or doesn't draw, based on the destination's | |
28 distance from an op-color. | |
29 | |
30 There are two modes, and each mode interprets a tolerance value. | |
31 | |
32 Avoid: In this mode, drawing is allowed only on destination pixels that | |
33 are different from the op-color. | |
34 Tolerance near 0: avoid any colors even remotely similar to the o
p-color | |
35 Tolerance near 255: avoid only colors nearly identical to the op-
color | |
36 | |
37 Target: In this mode, drawing only occurs on destination pixels that | |
38 are similar to the op-color | |
39 Tolerance near 0: draw only on colors that are nearly identical
to the op-color | |
40 Tolerance near 255: draw on any colors even remotely similar to
the op-color | |
41 */ | |
42 static sk_sp<SkXfermode> Make(SkColor opColor, U8CPU tolerance, Mode mode) { | |
43 return sk_sp<SkXfermode>(new SkAvoidXfermode(opColor, tolerance, mode)); | |
44 } | |
45 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR | |
46 static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode)
{ | |
47 return (SkAvoidXfermode*)(Make(opColor, tolerance, mode).release()); | |
48 } | |
49 #endif | |
50 | |
51 // overrides from SkXfermode | |
52 void xfer32(SkPMColor dst[], const SkPMColor src[], int count, | |
53 const SkAlpha aa[]) const override; | |
54 void xfer16(uint16_t dst[], const SkPMColor src[], int count, | |
55 const SkAlpha aa[]) const override; | |
56 void xferA8(SkAlpha dst[], const SkPMColor src[], int count, | |
57 const SkAlpha aa[]) const override; | |
58 | |
59 #if SK_SUPPORT_GPU | |
60 const GrFragmentProcessor* getFragmentProcessorForImageFilter( | |
61 const GrFragmentProcessor* d
st) const override; | |
62 GrXPFactory* asXPFactory() const override; | |
63 #endif | |
64 | |
65 SK_TO_STRING_OVERRIDE() | |
66 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(AvoidXfermode) | |
67 | |
68 protected: | |
69 SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode); | |
70 void flatten(SkWriteBuffer&) const override; | |
71 | |
72 private: | |
73 SkColor fOpColor; | |
74 uint32_t fDistMul; // x.14 cached from fTolerance | |
75 uint8_t fTolerance; | |
76 Mode fMode; | |
77 | |
78 typedef SkXfermode INHERITED; | |
79 }; | |
80 | |
81 #endif | |
OLD | NEW |