• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkPath.h"
12 #include "SkPathEffect.h"
13 #include "SkMatrix.h"
14 
15 class SK_API Sk2DPathEffect : public SkPathEffect {
16 public:
17     bool filterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override;
18 
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     */
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;
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     */
34     virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const;
35 
getMatrix()36     const SkMatrix& getMatrix() const { return fMatrix; }
37 
38     // protected so that subclasses can call this during unflattening
39     explicit Sk2DPathEffect(const SkMatrix& mat);
40     void flatten(SkWriteBuffer&) const override;
41 
42     SK_TO_STRING_OVERRIDE()
43 
44 private:
45     SkMatrix    fMatrix, fInverse;
46     bool        fMatrixIsInvertible;
47 
48     // illegal
49     Sk2DPathEffect(const Sk2DPathEffect&);
50     Sk2DPathEffect& operator=(const Sk2DPathEffect&);
51 
52     friend class Sk2DPathEffectBlitter;
53     typedef SkPathEffect INHERITED;
54 };
55 
56 class SK_API SkLine2DPathEffect : public Sk2DPathEffect {
57 public:
Make(SkScalar width,const SkMatrix & matrix)58     static sk_sp<SkPathEffect> Make(SkScalar width, const SkMatrix& matrix) {
59         return sk_sp<SkPathEffect>(new SkLine2DPathEffect(width, matrix));
60     }
61 
62     virtual bool filterPath(SkPath* dst, const SkPath& src,
63                             SkStrokeRec*, const SkRect*) const override;
64 
65     SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLine2DPathEffect)66     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLine2DPathEffect)
67 
68 protected:
69     SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
70         : Sk2DPathEffect(matrix), fWidth(width) {}
71     void flatten(SkWriteBuffer&) const override;
72 
73     void nextSpan(int u, int v, int ucount, SkPath*) const override;
74 
75 private:
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      */
Make(const SkMatrix & matrix,const SkPath & path)87     static sk_sp<SkPathEffect> Make(const SkMatrix& matrix, const SkPath& path) {
88         return sk_sp<SkPathEffect>(new SkPath2DPathEffect(matrix, path));
89     }
90 
91     SK_TO_STRING_OVERRIDE()
92     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath2DPathEffect)
93 
94 protected:
95     SkPath2DPathEffect(const SkMatrix&, const SkPath&);
96     void flatten(SkWriteBuffer&) const override;
97 
98     void next(const SkPoint&, int u, int v, SkPath*) const override;
99 
100 private:
101     SkPath  fPath;
102 
103     typedef Sk2DPathEffect INHERITED;
104 };
105 
106 #endif
107