reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | */ |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 18 | class SK_API SkAvoidXfermode : public SkXfermode { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | public: |
| 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.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 25 | /** This xfermode draws, or doesn't draw, based on the destination's |
| 26 | distance from an op-color. |
tomhudson@google.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 27 | |
reed@android.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 28 | There are two modes, and each mode interprets a tolerance value. |
tomhudson@google.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 29 | |
reed@android.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 30 | Avoid: In this mode, drawing is allowed only on destination pixels that |
| 31 | are different from the op-color. |
reed@android.com | 81dc331 | 2010-02-18 19:32:03 +0000 | [diff] [blame] | 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 |
tomhudson@google.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 34 | |
reed@android.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 35 | Target: In this mode, drawing only occurs on destination pixels that |
| 36 | are similar to the op-color |
reed@android.com | 81dc331 | 2010-02-18 19:32:03 +0000 | [diff] [blame] | 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 |
reed@android.com | 0db5a7f | 2009-11-09 16:01:36 +0000 | [diff] [blame] | 39 | */ |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 40 | static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode) { |
| 41 | return SkNEW_ARGS(SkAvoidXfermode, (opColor, tolerance, mode)); |
| 42 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | |
| 44 | // overrides from SkXfermode |
| 45 | virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count, |
reed@google.com | 30da745 | 2012-12-17 19:55:24 +0000 | [diff] [blame] | 46 | const SkAlpha aa[]) const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, |
reed@google.com | 30da745 | 2012-12-17 19:55:24 +0000 | [diff] [blame] | 48 | const SkAlpha aa[]) const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count, |
reed@google.com | 30da745 | 2012-12-17 19:55:24 +0000 | [diff] [blame] | 50 | const SkAlpha aa[]) const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 52 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 53 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode) |
tomhudson@google.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 54 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | protected: |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 56 | SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 57 | #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
commit-bot@chromium.org | bd0be25 | 2014-05-15 15:40:41 +0000 | [diff] [blame] | 58 | explicit SkAvoidXfermode(SkReadBuffer&); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 59 | #endif |
commit-bot@chromium.org | bd0be25 | 2014-05-15 15:40:41 +0000 | [diff] [blame] | 60 | virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 61 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | private: |
| 63 | SkColor fOpColor; |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 64 | uint32_t fDistMul; // x.14 cached from fTolerance |
| 65 | uint8_t fTolerance; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | Mode fMode; |
tomhudson@google.com | 1447c6f | 2011-04-27 14:09:52 +0000 | [diff] [blame] | 67 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | typedef SkXfermode INHERITED; |
| 69 | }; |
| 70 | |
| 71 | #endif |