blob: 99bfb3a4b612c9b6a7b9cd8640dffb83ee58ddb2 [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
Cary Clark4dc5a452018-05-21 11:56:57 -040011#include "SkFlattenable.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#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.org6806fe82012-10-12 14:41:39 +000018class SK_API SkDiscretePathEffect : public SkPathEffect {
reed@android.com8a1c16f2008-12-17 15:59:43 +000019public:
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.prinja39e58ad2014-06-12 22:55:08 -070023
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.com8a1c16f2008-12-17 15:59:43 +000032 */
reeda4393342016-03-18 11:22:57 -070033 static sk_sp<SkPathEffect> Make(SkScalar segLength, SkScalar dev, uint32_t seedAssist = 0);
34
Cary Clark4dc5a452018-05-21 11:56:57 -040035 Factory getFactory() const override { return CreateProc; }
reed@google.com6bac9472011-06-21 19:24:00 +000036
tomhudson64de1e12015-03-05 08:01:07 -080037#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
mtklein36352bf2015-03-25 18:17:31 -070038 bool exposedInAndroidJavaAPI() const override { return true; }
tomhudson64de1e12015-03-05 08:01:07 -080039#endif
40
reed@android.com8a1c16f2008-12-17 15:59:43 +000041protected:
rs.prinja39e58ad2014-06-12 22:55:08 -070042 SkDiscretePathEffect(SkScalar segLength,
43 SkScalar deviation,
44 uint32_t seedAssist);
mtklein36352bf2015-03-25 18:17:31 -070045 void flatten(SkWriteBuffer&) const override;
Mike Reed6d10f8b2018-08-16 13:22:16 -040046 bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000047
reed@android.com8a1c16f2008-12-17 15:59:43 +000048private:
Cary Clark4dc5a452018-05-21 11:56:57 -040049 static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&);
50 friend class SkFlattenable::PrivateInitializer;
51
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 SkScalar fSegLength, fPerterb;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000053
rs.prinja39e58ad2014-06-12 22:55:08 -070054 /* Caller-supplied 32 bit seed assist */
55 uint32_t fSeedAssist;
56
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 typedef SkPathEffect INHERITED;
58};
59
60#endif