Sk2DPathEffect.h revision 548a1f321011292359ef163f78c8a1d4871b3b7f
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
15class SK_API Sk2DPathEffect : public SkPathEffect {
16public:
17    Sk2DPathEffect(const SkMatrix& mat);
18
19    virtual bool filterPath(SkPath*, const SkPath&,
20                            SkStrokeRec*) const SK_OVERRIDE;
21
22    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk2DPathEffect)
23
24protected:
25    /** New virtual, to be overridden by subclasses.
26        This is called once from filterPath, and provides the
27        uv parameter bounds for the path. Subsequent calls to
28        next() will receive u and v values within these bounds,
29        and then a call to end() will signal the end of processing.
30    */
31    virtual void begin(const SkIRect& uvBounds, SkPath* dst) const;
32    virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) const;
33    virtual void end(SkPath* dst) const;
34
35    /** Low-level virtual called per span of locations in the u-direction.
36        The default implementation calls next() repeatedly with each
37        location.
38    */
39    virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const;
40
41    const SkMatrix& getMatrix() const { return fMatrix; }
42
43    // protected so that subclasses can call this during unflattening
44    Sk2DPathEffect(SkFlattenableReadBuffer&);
45    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
46
47private:
48    SkMatrix    fMatrix, fInverse;
49    bool        fMatrixIsInvertible;
50
51    // illegal
52    Sk2DPathEffect(const Sk2DPathEffect&);
53    Sk2DPathEffect& operator=(const Sk2DPathEffect&);
54
55    friend class Sk2DPathEffectBlitter;
56    typedef SkPathEffect INHERITED;
57};
58
59class SK_API SkLine2DPathEffect : public Sk2DPathEffect {
60public:
61    SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
62    : Sk2DPathEffect(matrix), fWidth(width) {}
63
64    virtual bool filterPath(SkPath* dst, const SkPath& src,
65                            SkStrokeRec*) const SK_OVERRIDE;
66
67    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLine2DPathEffect)
68
69protected:
70    virtual void nextSpan(int u, int v, int ucount, SkPath*) const SK_OVERRIDE;
71
72    SkLine2DPathEffect(SkFlattenableReadBuffer&);
73
74    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
75
76private:
77    SkScalar fWidth;
78
79    typedef Sk2DPathEffect INHERITED;
80};
81
82class SK_API SkPath2DPathEffect : public Sk2DPathEffect {
83public:
84    /**
85     *  Stamp the specified path to fill the shape, using the matrix to define
86     *  the latice.
87     */
88    SkPath2DPathEffect(const SkMatrix&, const SkPath&);
89
90    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath2DPathEffect)
91
92protected:
93    SkPath2DPathEffect(SkFlattenableReadBuffer& buffer);
94    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
95
96    virtual void next(const SkPoint&, int u, int v, SkPath*) const SK_OVERRIDE;
97
98private:
99    SkPath  fPath;
100
101    typedef Sk2DPathEffect INHERITED;
102};
103
104#endif
105