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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef Sk1DPathEffect_DEFINED |
| 9 | #define Sk1DPathEffect_DEFINED |
| 10 | |
| 11 | #include "SkPathEffect.h" |
| 12 | #include "SkPath.h" |
| 13 | |
| 14 | class SkPathMeasure; |
| 15 | |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 16 | // This class is not exported to java. |
| 17 | class SK_API Sk1DPathEffect : public SkPathEffect { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | public: |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 19 | virtual bool filterPath(SkPath* dst, const SkPath& src, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 20 | SkStrokeRec*, const SkRect*) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | |
| 22 | protected: |
| 23 | /** Called at the start of each contour, returns the initial offset |
| 24 | into that contour. |
| 25 | */ |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 26 | virtual SkScalar begin(SkScalar contourLength) const = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | /** Called with the current distance along the path, with the current matrix |
| 28 | for the point/tangent at the specified distance. |
| 29 | Return the distance to travel for the next call. If return <= 0, then that |
| 30 | contour is done. |
| 31 | */ |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 32 | virtual SkScalar next(SkPath* dst, SkScalar dist, SkPathMeasure&) const = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 34 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 35 | bool exposedInAndroidJavaAPI() const override { return true; } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 36 | #endif |
| 37 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | private: |
| 39 | typedef SkPathEffect INHERITED; |
| 40 | }; |
| 41 | |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 42 | class SK_API SkPath1DPathEffect : public Sk1DPathEffect { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | public: |
| 44 | enum Style { |
| 45 | kTranslate_Style, // translate the shape to each position |
| 46 | kRotate_Style, // rotate the shape about its center |
| 47 | kMorph_Style, // transform each point, and turn lines into curves |
ethannicholas | 23e7af0 | 2016-02-22 07:42:18 -0800 | [diff] [blame] | 48 | |
reed | ca726ab | 2016-02-22 12:50:25 -0800 | [diff] [blame] | 49 | kLastEnum_Style = kMorph_Style, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | }; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 51 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | /** Dash by replicating the specified path. |
| 53 | @param path The path to replicate (dash) |
| 54 | @param advance The space between instances of path |
| 55 | @param phase distance (mod advance) along path for its initial position |
| 56 | @param style how to transform path at each point (based on the current |
| 57 | position and tangent) |
| 58 | */ |
reed | 9fbee18 | 2016-03-18 10:00:32 -0700 | [diff] [blame^] | 59 | static sk_sp<SkPathEffect> Make(const SkPath& path, SkScalar advance, SkScalar phase, Style); |
| 60 | |
| 61 | #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR |
| 62 | static SkPathEffect* Create(const SkPath& path, SkScalar advance, SkScalar phase, Style s) { |
| 63 | return Make(path, advance, phase, s).release(); |
| 64 | } |
| 65 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 67 | virtual bool filterPath(SkPath*, const SkPath&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 68 | SkStrokeRec*, const SkRect*) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | |
robertphillips | 42dbfa8 | 2015-01-26 06:08:52 -0800 | [diff] [blame] | 70 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 71 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath1DPathEffect) |
reed@google.com | e28b917 | 2011-08-09 18:14:31 +0000 | [diff] [blame] | 72 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | protected: |
commit-bot@chromium.org | bd0be25 | 2014-05-15 15:40:41 +0000 | [diff] [blame] | 74 | SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 75 | void flatten(SkWriteBuffer&) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | |
| 77 | // overrides from Sk1DPathEffect |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 78 | SkScalar begin(SkScalar contourLength) const override; |
| 79 | SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const override; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 80 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 81 | private: |
| 82 | SkPath fPath; // copied from constructor |
| 83 | SkScalar fAdvance; // copied from constructor |
| 84 | SkScalar fInitialOffset; // computed from phase |
| 85 | Style fStyle; // copied from constructor |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | |
| 87 | typedef Sk1DPathEffect INHERITED; |
| 88 | }; |
| 89 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 90 | #endif |