SkAvoidXfermode.h revision 6ba4572eed5a4ecfdd22d118fa55b5c06902b574
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 "SkXfermode.h"
12
13/** \class SkAvoidXfermode
14
15    This xfermode will draw the src everywhere except on top of the specified
16    color.
17*/
18class SK_API SkAvoidXfermode : public SkXfermode {
19public:
20    enum Mode {
21        kAvoidColor_Mode,   //!< draw everywhere except on the opColor
22        kTargetColor_Mode   //!< draw only on top of the opColor
23    };
24
25    /** This xfermode draws, or doesn't draw, based on the destination's
26        distance from an op-color.
27
28        There are two modes, and each mode interprets a tolerance value.
29
30        Avoid: In this mode, drawing is allowed only on destination pixels that
31               are different from the op-color.
32               Tolerance near 0: avoid any colors even remotely similar to the op-color
33               Tolerance near 255: avoid only colors nearly identical to the op-color
34
35        Target: In this mode, drawing only occurs on destination pixels that
36                are similar to the op-color
37                Tolerance near 0: draw only on colors that are nearly identical to the op-color
38                Tolerance near 255: draw on any colors even remotely similar to the op-color
39     */
40    SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
41
42    // overrides from SkXfermode
43    virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
44                        const SkAlpha aa[]) const SK_OVERRIDE;
45    virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
46                        const SkAlpha aa[]) const SK_OVERRIDE;
47    virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
48                        const SkAlpha aa[]) const SK_OVERRIDE;
49
50    SK_DEVELOPER_TO_STRING()
51    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode)
52
53protected:
54    SkAvoidXfermode(SkFlattenableReadBuffer&);
55    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
56
57private:
58    SkColor     fOpColor;
59    uint32_t    fDistMul;   // x.14
60    Mode        fMode;
61
62    typedef SkXfermode INHERITED;
63};
64
65#endif
66