| 1 | /* |
| 2 | * Copyright 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef Sk2DPathEffect_DEFINED |
| 9 | #define Sk2DPathEffect_DEFINED |
| 10 | |
| 11 | #include "include/core/SkFlattenable.h" |
| 12 | #include "include/core/SkMatrix.h" |
| 13 | #include "include/core/SkPath.h" |
| 14 | #include "include/core/SkPathEffect.h" |
| 15 | |
| 16 | class SK_API Sk2DPathEffect : public SkPathEffect { |
| 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 | */ |
| 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; |
| 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 | */ |
| 32 | virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const; |
| 33 | |
| 34 | const SkMatrix& getMatrix() const { return fMatrix; } |
| 35 | |
| 36 | // protected so that subclasses can call this during unflattening |
| 37 | explicit Sk2DPathEffect(const SkMatrix& mat); |
| 38 | void flatten(SkWriteBuffer&) const override; |
| 39 | bool onFilterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override; |
| 40 | |
| 41 | private: |
| 42 | SkMatrix fMatrix, fInverse; |
| 43 | bool fMatrixIsInvertible; |
| 44 | |
| 45 | // illegal |
| 46 | Sk2DPathEffect(const Sk2DPathEffect&); |
| 47 | Sk2DPathEffect& operator=(const Sk2DPathEffect&); |
| 48 | |
| 49 | friend class Sk2DPathEffectBlitter; |
| 50 | typedef SkPathEffect INHERITED; |
| 51 | }; |
| 52 | |
| 53 | class SK_API SkLine2DPathEffect : public Sk2DPathEffect { |
| 54 | public: |
| 55 | static sk_sp<SkPathEffect> Make(SkScalar width, const SkMatrix& matrix) { |
| 56 | if (!(width >= 0)) { |
| 57 | return nullptr; |
| 58 | } |
| 59 | return sk_sp<SkPathEffect>(new SkLine2DPathEffect(width, matrix)); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | protected: |
| 64 | SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix) |
| 65 | : Sk2DPathEffect(matrix), fWidth(width) { |
| 66 | SkASSERT(width >= 0); |
| 67 | } |
| 68 | void flatten(SkWriteBuffer&) const override; |
| 69 | bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override; |
| 70 | |
| 71 | void nextSpan(int u, int v, int ucount, SkPath*) const override; |
| 72 | |
| 73 | private: |
| 74 | SK_FLATTENABLE_HOOKS(SkLine2DPathEffect) |
| 75 | |
| 76 | SkScalar fWidth; |
| 77 | |
| 78 | typedef Sk2DPathEffect INHERITED; |
| 79 | }; |
| 80 | |
| 81 | class SK_API SkPath2DPathEffect : public Sk2DPathEffect { |
| 82 | public: |
| 83 | /** |
| 84 | * Stamp the specified path to fill the shape, using the matrix to define |
| 85 | * the latice. |
| 86 | */ |
| 87 | static sk_sp<SkPathEffect> Make(const SkMatrix& matrix, const SkPath& path) { |
| 88 | return sk_sp<SkPathEffect>(new SkPath2DPathEffect(matrix, path)); |
| 89 | } |
| 90 | |
| 91 | protected: |
| 92 | SkPath2DPathEffect(const SkMatrix&, const SkPath&); |
| 93 | void flatten(SkWriteBuffer&) const override; |
| 94 | |
| 95 | void next(const SkPoint&, int u, int v, SkPath*) const override; |
| 96 | |
| 97 | private: |
| 98 | SK_FLATTENABLE_HOOKS(SkPath2DPathEffect) |
| 99 | |
| 100 | SkPath fPath; |
| 101 | |
| 102 | typedef Sk2DPathEffect INHERITED; |
| 103 | }; |
| 104 | |
| 105 | #endif |
| 106 | |