blob: 53ce708e36ff8e7a4de69249b5642ac8e0122954 [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 */
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000040 static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode) {
41 return SkNEW_ARGS(SkAvoidXfermode, (opColor, tolerance, mode));
42 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000043
44 // overrides from SkXfermode
45 virtual void xfer32(SkPMColor 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 xfer16(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
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000052 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000053 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode)
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000054
reed@android.com8a1c16f2008-12-17 15:59:43 +000055protected:
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000056 SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
reed9fa60da2014-08-21 07:59:51 -070057#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000058 explicit SkAvoidXfermode(SkReadBuffer&);
reed9fa60da2014-08-21 07:59:51 -070059#endif
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000060 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000061
reed@android.com8a1c16f2008-12-17 15:59:43 +000062private:
63 SkColor fOpColor;
reed9fa60da2014-08-21 07:59:51 -070064 uint32_t fDistMul; // x.14 cached from fTolerance
65 uint8_t fTolerance;
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 Mode fMode;
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000067
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 typedef SkXfermode INHERITED;
69};
70
71#endif