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 | |
| 11 | #include "SkPathEffect.h" |
| 12 | |
| 13 | /** \class SkDiscretePathEffect |
| 14 | |
| 15 | This path effect chops a path into discrete segments, and randomly displaces them. |
| 16 | */ |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 17 | class SK_API SkDiscretePathEffect : public SkPathEffect { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | public: |
| 19 | /** Break the path into segments of segLength length, and randomly move the endpoints |
| 20 | away from the original path by a maximum of deviation. |
| 21 | Note: works on filled or framed paths |
rs.prinja | 39e58ad | 2014-06-12 22:55:08 -0700 | [diff] [blame] | 22 | |
| 23 | @param seedAssist This is a caller-supplied seedAssist that modifies |
| 24 | the seed value that is used to randomize the path |
| 25 | segments' endpoints. If not supplied it defaults to 0, |
| 26 | in which case filtering a path multiple times will |
| 27 | result in the same set of segments (this is useful for |
| 28 | testing). If a caller does not want this behaviour |
| 29 | they can pass in a different seedAssist to get a |
| 30 | different set of path segments. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | */ |
reed | 5e1ddb1 | 2015-12-21 08:52:45 -0800 | [diff] [blame^] | 32 | static SkPathEffect* Create(SkScalar segLength, SkScalar deviation, uint32_t seedAssist = 0) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 33 | return new SkDiscretePathEffect(segLength, deviation, seedAssist); |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 34 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 36 | virtual bool filterPath(SkPath* dst, const SkPath& src, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 37 | SkStrokeRec*, const SkRect*) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | |
robertphillips | 42dbfa8 | 2015-01-26 06:08:52 -0800 | [diff] [blame] | 39 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 40 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiscretePathEffect) |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 41 | |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 42 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 43 | bool exposedInAndroidJavaAPI() const override { return true; } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 44 | #endif |
| 45 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | protected: |
rs.prinja | 39e58ad | 2014-06-12 22:55:08 -0700 | [diff] [blame] | 47 | SkDiscretePathEffect(SkScalar segLength, |
| 48 | SkScalar deviation, |
| 49 | uint32_t seedAssist); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 50 | void flatten(SkWriteBuffer&) const override; |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 51 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | private: |
| 53 | SkScalar fSegLength, fPerterb; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 54 | |
rs.prinja | 39e58ad | 2014-06-12 22:55:08 -0700 | [diff] [blame] | 55 | /* Caller-supplied 32 bit seed assist */ |
| 56 | uint32_t fSeedAssist; |
| 57 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | typedef SkPathEffect INHERITED; |
| 59 | }; |
| 60 | |
| 61 | #endif |