blob: d5b33e31740aeb2dd48c50b04ca51c314c5d0604 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
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*/
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000018class SK_API SkAvoidXfermode : public SkXfermode {
reed@android.com8a1c16f2008-12-17 15:59:43 +000019public:
20 enum Mode {
21 kAvoidColor_Mode, //!< draw everywhere except on the opColor
22 kTargetColor_Mode //!< draw only on top of the opColor
23 };
24
reed@android.com0db5a7f2009-11-09 16:01:36 +000025 /** This xfermode draws, or doesn't draw, based on the destination's
26 distance from an op-color.
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000027
reed@android.com0db5a7f2009-11-09 16:01:36 +000028 There are two modes, and each mode interprets a tolerance value.
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000029
reed@android.com0db5a7f2009-11-09 16:01:36 +000030 Avoid: In this mode, drawing is allowed only on destination pixels that
31 are different from the op-color.
reed@android.com81dc3312010-02-18 19:32:03 +000032 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
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000034
reed@android.com0db5a7f2009-11-09 16:01:36 +000035 Target: In this mode, drawing only occurs on destination pixels that
36 are similar to the op-color
reed@android.com81dc3312010-02-18 19:32:03 +000037 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
reed@android.com0db5a7f2009-11-09 16:01:36 +000039 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000040 SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
41
42 // overrides from SkXfermode
43 virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
reed@google.com30da7452012-12-17 19:55:24 +000044 const SkAlpha aa[]) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
reed@google.com30da7452012-12-17 19:55:24 +000046 const SkAlpha aa[]) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
reed@google.com30da7452012-12-17 19:55:24 +000048 const SkAlpha aa[]) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
reed@google.com30da7452012-12-17 19:55:24 +000050 const SkAlpha aa[]) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000051
djsollen@google.comba28d032012-03-26 17:57:35 +000052 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode)
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054protected:
55 SkAvoidXfermode(SkFlattenableReadBuffer&);
djsollen@google.com54924242012-03-29 15:18:04 +000056 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000057
58private:
59 SkColor fOpColor;
60 uint32_t fDistMul; // x.14
61 Mode fMode;
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000062
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 typedef SkXfermode INHERITED;
64};
65
66#endif