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 Sk2DPathEffect_DEFINED |
| 9 | #define Sk2DPathEffect_DEFINED |
| 10 | |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 11 | #include "SkPath.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkPathEffect.h" |
| 13 | #include "SkMatrix.h" |
| 14 | |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 15 | class SK_API Sk2DPathEffect : public SkPathEffect { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | public: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 17 | bool filterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | protected: |
| 20 | /** New virtual, to be overridden by subclasses. |
| 21 | This is called once from filterPath, and provides the |
| 22 | uv parameter bounds for the path. Subsequent calls to |
| 23 | next() will receive u and v values within these bounds, |
| 24 | and then a call to end() will signal the end of processing. |
| 25 | */ |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 26 | virtual void begin(const SkIRect& uvBounds, SkPath* dst) const; |
| 27 | virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) const; |
| 28 | virtual void end(SkPath* dst) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | |
| 30 | /** Low-level virtual called per span of locations in the u-direction. |
| 31 | The default implementation calls next() repeatedly with each |
| 32 | location. |
| 33 | */ |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 34 | virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | |
| 36 | const SkMatrix& getMatrix() const { return fMatrix; } |
| 37 | |
| 38 | // protected so that subclasses can call this during unflattening |
commit-bot@chromium.org | bd0be25 | 2014-05-15 15:40:41 +0000 | [diff] [blame] | 39 | explicit Sk2DPathEffect(const SkMatrix& mat); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 40 | void flatten(SkWriteBuffer&) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | |
robertphillips | 42dbfa8 | 2015-01-26 06:08:52 -0800 | [diff] [blame] | 42 | SK_TO_STRING_OVERRIDE() |
| 43 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | private: |
| 45 | SkMatrix fMatrix, fInverse; |
mike@reedtribe.org | 90bf427 | 2012-04-14 19:06:16 +0000 | [diff] [blame] | 46 | bool fMatrixIsInvertible; |
| 47 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | // illegal |
| 49 | Sk2DPathEffect(const Sk2DPathEffect&); |
| 50 | Sk2DPathEffect& operator=(const Sk2DPathEffect&); |
| 51 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | friend class Sk2DPathEffectBlitter; |
| 53 | typedef SkPathEffect INHERITED; |
| 54 | }; |
| 55 | |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 56 | class SK_API SkLine2DPathEffect : public Sk2DPathEffect { |
scroggo@google.com | d8a6cc8 | 2012-09-12 18:53:49 +0000 | [diff] [blame] | 57 | public: |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 58 | static sk_sp<SkPathEffect> Make(SkScalar width, const SkMatrix& matrix) { |
| 59 | return sk_sp<SkPathEffect>(new SkLine2DPathEffect(width, matrix)); |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 60 | } |
scroggo@google.com | d8a6cc8 | 2012-09-12 18:53:49 +0000 | [diff] [blame] | 61 | |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 62 | virtual bool filterPath(SkPath* dst, const SkPath& src, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 63 | SkStrokeRec*, const SkRect*) const override; |
scroggo@google.com | d8a6cc8 | 2012-09-12 18:53:49 +0000 | [diff] [blame] | 64 | |
robertphillips | 42dbfa8 | 2015-01-26 06:08:52 -0800 | [diff] [blame] | 65 | SK_TO_STRING_OVERRIDE() |
scroggo@google.com | d8a6cc8 | 2012-09-12 18:53:49 +0000 | [diff] [blame] | 66 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLine2DPathEffect) |
| 67 | |
| 68 | protected: |
commit-bot@chromium.org | bd0be25 | 2014-05-15 15:40:41 +0000 | [diff] [blame] | 69 | SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix) |
| 70 | : Sk2DPathEffect(matrix), fWidth(width) {} |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 71 | void flatten(SkWriteBuffer&) const override; |
scroggo@google.com | d8a6cc8 | 2012-09-12 18:53:49 +0000 | [diff] [blame] | 72 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 73 | void nextSpan(int u, int v, int ucount, SkPath*) const override; |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 74 | |
scroggo@google.com | d8a6cc8 | 2012-09-12 18:53:49 +0000 | [diff] [blame] | 75 | private: |
| 76 | SkScalar fWidth; |
| 77 | |
| 78 | typedef Sk2DPathEffect INHERITED; |
| 79 | }; |
| 80 | |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 81 | class SK_API SkPath2DPathEffect : public Sk2DPathEffect { |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 82 | public: |
| 83 | /** |
| 84 | * Stamp the specified path to fill the shape, using the matrix to define |
| 85 | * the latice. |
| 86 | */ |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 87 | static sk_sp<SkPathEffect> Make(const SkMatrix& matrix, const SkPath& path) { |
| 88 | return sk_sp<SkPathEffect>(new SkPath2DPathEffect(matrix, path)); |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 89 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 90 | |
robertphillips | 42dbfa8 | 2015-01-26 06:08:52 -0800 | [diff] [blame] | 91 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 92 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath2DPathEffect) |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 93 | |
| 94 | protected: |
commit-bot@chromium.org | bd0be25 | 2014-05-15 15:40:41 +0000 | [diff] [blame] | 95 | SkPath2DPathEffect(const SkMatrix&, const SkPath&); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 96 | void flatten(SkWriteBuffer&) const override; |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 97 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 98 | void next(const SkPoint&, int u, int v, SkPath*) const override; |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 99 | |
| 100 | private: |
| 101 | SkPath fPath; |
| 102 | |
| 103 | typedef Sk2DPathEffect INHERITED; |
| 104 | }; |
| 105 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | #endif |