• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkAvoidXfermode_DEFINED
11 #define SkAvoidXfermode_DEFINED
12 
13 #include "SkXfermode.h"
14 
15 /** \class SkAvoidXfermode
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 op-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     SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
43 
44     // overrides from SkXfermode
45     virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
46                         const SkAlpha aa[]) SK_OVERRIDE;
47     virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
48                         const SkAlpha aa[]) SK_OVERRIDE;
49     virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
50                           const SkAlpha aa[]) SK_OVERRIDE;
51     virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
52                         const SkAlpha aa[]) SK_OVERRIDE;
53 
54     // overrides from SkFlattenable
55     virtual Factory getFactory() SK_OVERRIDE;
56     virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
57 
CreateProc(SkFlattenableReadBuffer & buffer)58     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
59         return SkNEW_ARGS(SkAvoidXfermode, (buffer));
60     }
61 
62     SK_DECLARE_FLATTENABLE_REGISTRAR()
63 
64 protected:
65     SkAvoidXfermode(SkFlattenableReadBuffer&);
66 
67 private:
68     SkColor     fOpColor;
69     uint32_t    fDistMul;   // x.14
70     Mode        fMode;
71 
72     static SkFlattenable* Create(SkFlattenableReadBuffer&);
73 
74     typedef SkXfermode INHERITED;
75 };
76 
77 #endif
78