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