| 1 | /* | 
|---|
| 2 | * Copyright 2006 The Android Open Source Project | 
|---|
| 3 | * | 
|---|
| 4 | * Use of this source code is governed by a BSD-style license that can be | 
|---|
| 5 | * found in the LICENSE file. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef SkDiscretePathEffect_DEFINED | 
|---|
| 9 | #define SkDiscretePathEffect_DEFINED | 
|---|
| 10 |  | 
|---|
| 11 | #include "include/core/SkFlattenable.h" | 
|---|
| 12 | #include "include/core/SkPathEffect.h" | 
|---|
| 13 |  | 
|---|
| 14 | /** \class SkDiscretePathEffect | 
|---|
| 15 |  | 
|---|
| 16 | This path effect chops a path into discrete segments, and randomly displaces them. | 
|---|
| 17 | */ | 
|---|
| 18 | class SK_API SkDiscretePathEffect : public SkPathEffect { | 
|---|
| 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 | 
|---|
| 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. | 
|---|
| 32 | */ | 
|---|
| 33 | static sk_sp<SkPathEffect> Make(SkScalar segLength, SkScalar dev, uint32_t seedAssist = 0); | 
|---|
| 34 |  | 
|---|
| 35 | protected: | 
|---|
| 36 | SkDiscretePathEffect(SkScalar segLength, | 
|---|
| 37 | SkScalar deviation, | 
|---|
| 38 | uint32_t seedAssist); | 
|---|
| 39 | void flatten(SkWriteBuffer&) const override; | 
|---|
| 40 | bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override; | 
|---|
| 41 |  | 
|---|
| 42 | private: | 
|---|
| 43 | SK_FLATTENABLE_HOOKS(SkDiscretePathEffect) | 
|---|
| 44 |  | 
|---|
| 45 | SkScalar fSegLength, fPerterb; | 
|---|
| 46 |  | 
|---|
| 47 | /* Caller-supplied 32 bit seed assist */ | 
|---|
| 48 | uint32_t fSeedAssist; | 
|---|
| 49 |  | 
|---|
| 50 | typedef SkPathEffect INHERITED; | 
|---|
| 51 | }; | 
|---|
| 52 |  | 
|---|
| 53 | #endif | 
|---|
| 54 |  | 
|---|