blob: 823a6ad9d87b25a59255d7d69ab39c70cc26d049 [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
reed@google.com18dc4772011-08-09 18:47:40 +000011#include "SkPath.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkPathEffect.h"
13#include "SkMatrix.h"
14
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000015class SK_API Sk2DPathEffect : public SkPathEffect {
reed@android.com8a1c16f2008-12-17 15:59:43 +000016public:
mtklein36352bf2015-03-25 18:17:31 -070017 bool filterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000018
reed@android.com8a1c16f2008-12-17 15:59:43 +000019protected:
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 */
reed@google.com548a1f32012-12-18 16:12:09 +000026 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;
reed@android.com8a1c16f2008-12-17 15:59:43 +000029
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 */
reed@google.com548a1f32012-12-18 16:12:09 +000034 virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +000035
36 const SkMatrix& getMatrix() const { return fMatrix; }
37
38 // protected so that subclasses can call this during unflattening
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000039 explicit Sk2DPathEffect(const SkMatrix& mat);
mtklein36352bf2015-03-25 18:17:31 -070040 void flatten(SkWriteBuffer&) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000041
robertphillips42dbfa82015-01-26 06:08:52 -080042 SK_TO_STRING_OVERRIDE()
43
reed@android.com8a1c16f2008-12-17 15:59:43 +000044private:
45 SkMatrix fMatrix, fInverse;
mike@reedtribe.org90bf4272012-04-14 19:06:16 +000046 bool fMatrixIsInvertible;
47
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 // illegal
49 Sk2DPathEffect(const Sk2DPathEffect&);
50 Sk2DPathEffect& operator=(const Sk2DPathEffect&);
51
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 friend class Sk2DPathEffectBlitter;
53 typedef SkPathEffect INHERITED;
54};
55
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000056class SK_API SkLine2DPathEffect : public Sk2DPathEffect {
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000057public:
reeda4393342016-03-18 11:22:57 -070058 static sk_sp<SkPathEffect> Make(SkScalar width, const SkMatrix& matrix) {
59 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
reed@google.com548a1f32012-12-18 16:12:09 +000062 virtual bool filterPath(SkPath* dst, const SkPath& src,
mtklein36352bf2015-03-25 18:17:31 -070063 SkStrokeRec*, const SkRect*) const override;
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000064
robertphillips42dbfa82015-01-26 06:08:52 -080065 SK_TO_STRING_OVERRIDE()
scroggo@google.comd8a6cc82012-09-12 18:53:49 +000066 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLine2DPathEffect)
67
68protected:
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000069 SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
70 : Sk2DPathEffect(matrix), fWidth(width) {}
mtklein36352bf2015-03-25 18:17:31 -070071 void flatten(SkWriteBuffer&) 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:
76 SkScalar fWidth;
77
78 typedef Sk2DPathEffect INHERITED;
79};
80
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000081class SK_API SkPath2DPathEffect : public Sk2DPathEffect {
reed@google.com18dc4772011-08-09 18:47:40 +000082public:
83 /**
84 * Stamp the specified path to fill the shape, using the matrix to define
85 * the latice.
86 */
reeda4393342016-03-18 11:22:57 -070087 static sk_sp<SkPathEffect> Make(const SkMatrix& matrix, const SkPath& path) {
88 return sk_sp<SkPathEffect>(new SkPath2DPathEffect(matrix, path));
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000089 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000090
robertphillips42dbfa82015-01-26 06:08:52 -080091 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000092 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath2DPathEffect)
reed@google.com18dc4772011-08-09 18:47:40 +000093
94protected:
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000095 SkPath2DPathEffect(const SkMatrix&, const SkPath&);
mtklein36352bf2015-03-25 18:17:31 -070096 void flatten(SkWriteBuffer&) const override;
reed@google.com18dc4772011-08-09 18:47:40 +000097
mtklein36352bf2015-03-25 18:17:31 -070098 void next(const SkPoint&, int u, int v, SkPath*) const override;
reed@google.com18dc4772011-08-09 18:47:40 +000099
100private:
101 SkPath fPath;
102
103 typedef Sk2DPathEffect INHERITED;
104};
105
reed@android.com8a1c16f2008-12-17 15:59:43 +0000106#endif