blob: 78d4516ee6feb9c859f4397fb9ec3c63dcd0072e [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 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.org6806fe82012-10-12 14:41:39 +000017class SK_API SkDiscretePathEffect : public SkPathEffect {
reed@android.com8a1c16f2008-12-17 15:59:43 +000018public:
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.prinja39e58ad2014-06-12 22:55:08 -070022
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.com8a1c16f2008-12-17 15:59:43 +000031 */
reeda4393342016-03-18 11:22:57 -070032 static sk_sp<SkPathEffect> Make(SkScalar segLength, SkScalar dev, uint32_t seedAssist = 0);
33
34#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
reed5e1ddb12015-12-21 08:52:45 -080035 static SkPathEffect* Create(SkScalar segLength, SkScalar deviation, uint32_t seedAssist = 0) {
reeda4393342016-03-18 11:22:57 -070036 return Make(segLength, deviation, seedAssist).release();
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000037 }
reeda4393342016-03-18 11:22:57 -070038#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000039
reed@google.com548a1f32012-12-18 16:12:09 +000040 virtual bool filterPath(SkPath* dst, const SkPath& src,
mtklein36352bf2015-03-25 18:17:31 -070041 SkStrokeRec*, const SkRect*) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000042
robertphillips42dbfa82015-01-26 06:08:52 -080043 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000044 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiscretePathEffect)
reed@google.com6bac9472011-06-21 19:24:00 +000045
tomhudson64de1e12015-03-05 08:01:07 -080046#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
mtklein36352bf2015-03-25 18:17:31 -070047 bool exposedInAndroidJavaAPI() const override { return true; }
tomhudson64de1e12015-03-05 08:01:07 -080048#endif
49
reed@android.com8a1c16f2008-12-17 15:59:43 +000050protected:
rs.prinja39e58ad2014-06-12 22:55:08 -070051 SkDiscretePathEffect(SkScalar segLength,
52 SkScalar deviation,
53 uint32_t seedAssist);
mtklein36352bf2015-03-25 18:17:31 -070054 void flatten(SkWriteBuffer&) const override;
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000055
reed@android.com8a1c16f2008-12-17 15:59:43 +000056private:
57 SkScalar fSegLength, fPerterb;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000058
rs.prinja39e58ad2014-06-12 22:55:08 -070059 /* Caller-supplied 32 bit seed assist */
60 uint32_t fSeedAssist;
61
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 typedef SkPathEffect INHERITED;
63};
64
65#endif