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 SkDiscretePathEffect_DEFINED |
| 9 | #define SkDiscretePathEffect_DEFINED |
| 10 | |
Cary Clark | 4dc5a45 | 2018-05-21 11:56:57 -0400 | [diff] [blame] | 11 | #include "SkFlattenable.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkPathEffect.h" |
| 13 | |
| 14 | /** \class SkDiscretePathEffect |
| 15 | |
| 16 | This path effect chops a path into discrete segments, and randomly displaces them. |
| 17 | */ |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 18 | class SK_API SkDiscretePathEffect : public SkPathEffect { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | public: |
| 20 | /** Break the path into segments of segLength length, and randomly move the endpoints |
| 21 | away from the original path by a maximum of deviation. |
| 22 | Note: works on filled or framed paths |
rs.prinja | 39e58ad | 2014-06-12 22:55:08 -0700 | [diff] [blame] | 23 | |
| 24 | @param seedAssist This is a caller-supplied seedAssist that modifies |
| 25 | the seed value that is used to randomize the path |
| 26 | segments' endpoints. If not supplied it defaults to 0, |
| 27 | in which case filtering a path multiple times will |
| 28 | result in the same set of segments (this is useful for |
| 29 | testing). If a caller does not want this behaviour |
| 30 | they can pass in a different seedAssist to get a |
| 31 | different set of path segments. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | */ |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 33 | static sk_sp<SkPathEffect> Make(SkScalar segLength, SkScalar dev, uint32_t seedAssist = 0); |
| 34 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | protected: |
rs.prinja | 39e58ad | 2014-06-12 22:55:08 -0700 | [diff] [blame] | 36 | SkDiscretePathEffect(SkScalar segLength, |
| 37 | SkScalar deviation, |
| 38 | uint32_t seedAssist); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 39 | void flatten(SkWriteBuffer&) const override; |
Mike Reed | 6d10f8b | 2018-08-16 13:22:16 -0400 | [diff] [blame] | 40 | bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override; |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 41 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 42 | private: |
Mike Klein | 4fee323 | 2018-10-18 17:27:16 -0400 | [diff] [blame] | 43 | SK_FLATTENABLE_HOOKS(SkDiscretePathEffect) |
Cary Clark | 4dc5a45 | 2018-05-21 11:56:57 -0400 | [diff] [blame] | 44 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | SkScalar fSegLength, fPerterb; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 46 | |
rs.prinja | 39e58ad | 2014-06-12 22:55:08 -0700 | [diff] [blame] | 47 | /* Caller-supplied 32 bit seed assist */ |
| 48 | uint32_t fSeedAssist; |
| 49 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | typedef SkPathEffect INHERITED; |
| 51 | }; |
| 52 | |
| 53 | #endif |