blob: e29ce1e65399afbbd17cde1ddf2a395b6529d561 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef Sk2DPathEffect_DEFINED
9#define Sk2DPathEffect_DEFINED
10
Cary Clark4dc5a452018-05-21 11:56:57 -040011#include "SkFlattenable.h"
reed@google.com18dc4772011-08-09 18:47:40 +000012#include "SkPath.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkPathEffect.h"
14#include "SkMatrix.h"
15
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000016class SK_API Sk2DPathEffect : public SkPathEffect {
reed@android.com8a1c16f2008-12-17 15:59:43 +000017protected:
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.com548a1f32012-12-18 16:12:09 +000024 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.com8a1c16f2008-12-17 15:59:43 +000027
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.com548a1f32012-12-18 16:12:09 +000032 virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033
34 const SkMatrix& getMatrix() const { return fMatrix; }
35
36 // protected so that subclasses can call this during unflattening
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000037 explicit Sk2DPathEffect(const SkMatrix& mat);
mtklein36352bf2015-03-25 18:17:31 -070038 void flatten(SkWriteBuffer&) const override;
Mike Reed6d10f8b2018-08-16 13:22:16 -040039 bool onFilterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000040
41private:
42 SkMatrix fMatrix, fInverse;
mike@reedtribe.org90bf4272012-04-14 19:06:16 +000043 bool fMatrixIsInvertible;
44
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 // illegal
46 Sk2DPathEffect(const Sk2DPathEffect&);
47 Sk2DPathEffect& operator=(const Sk2DPathEffect&);
48
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 friend class Sk2DPathEffectBlitter;
50 typedef SkPathEffect INHERITED;
51};
52
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000053class SK_API SkLine2DPathEffect : public Sk2DPathEffect {
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000054public:
reeda4393342016-03-18 11:22:57 -070055 static sk_sp<SkPathEffect> Make(SkScalar width, const SkMatrix& matrix) {
Mike Reedba5b5f52018-05-18 16:29:11 -040056 if (!(width >= 0)) {
57 return nullptr;
58 }
reeda4393342016-03-18 11:22:57 -070059 return sk_sp<SkPathEffect>(new SkLine2DPathEffect(width, matrix));
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000060 }
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000061
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000062
Cary Clark4dc5a452018-05-21 11:56:57 -040063 Factory getFactory() const override { return CreateProc; }
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000064
65protected:
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000066 SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
Mike Reedba5b5f52018-05-18 16:29:11 -040067 : Sk2DPathEffect(matrix), fWidth(width) {
68 SkASSERT(width >= 0);
69 }
mtklein36352bf2015-03-25 18:17:31 -070070 void flatten(SkWriteBuffer&) const override;
Mike Reed6d10f8b2018-08-16 13:22:16 -040071 bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000072
mtklein36352bf2015-03-25 18:17:31 -070073 void nextSpan(int u, int v, int ucount, SkPath*) const override;
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000074
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000075private:
Cary Clark4dc5a452018-05-21 11:56:57 -040076 static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&);
77 friend class SkFlattenable::PrivateInitializer;
78
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000079 SkScalar fWidth;
80
81 typedef Sk2DPathEffect INHERITED;
82};
83
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000084class SK_API SkPath2DPathEffect : public Sk2DPathEffect {
reed@google.com18dc4772011-08-09 18:47:40 +000085public:
86 /**
87 * Stamp the specified path to fill the shape, using the matrix to define
88 * the latice.
89 */
reeda4393342016-03-18 11:22:57 -070090 static sk_sp<SkPathEffect> Make(const SkMatrix& matrix, const SkPath& path) {
91 return sk_sp<SkPathEffect>(new SkPath2DPathEffect(matrix, path));
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000092 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000093
Cary Clark4dc5a452018-05-21 11:56:57 -040094 Factory getFactory() const override { return CreateProc; }
reed@google.com18dc4772011-08-09 18:47:40 +000095
96protected:
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000097 SkPath2DPathEffect(const SkMatrix&, const SkPath&);
mtklein36352bf2015-03-25 18:17:31 -070098 void flatten(SkWriteBuffer&) const override;
reed@google.com18dc4772011-08-09 18:47:40 +000099
mtklein36352bf2015-03-25 18:17:31 -0700100 void next(const SkPoint&, int u, int v, SkPath*) const override;
reed@google.com18dc4772011-08-09 18:47:40 +0000101
102private:
Cary Clark4dc5a452018-05-21 11:56:57 -0400103 static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&);
104 friend class SkFlattenable::PrivateInitializer;
105
reed@google.com18dc4772011-08-09 18:47:40 +0000106 SkPath fPath;
107
108 typedef Sk2DPathEffect INHERITED;
109};
110
reed@android.com8a1c16f2008-12-17 15:59:43 +0000111#endif