Coverage Report

Created: 2021-08-22 09:07

/src/skia/include/core/SkPathEffect.h
Line
Count
Source (jump to first uncovered line)
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 SkPathEffect_DEFINED
9
#define SkPathEffect_DEFINED
10
11
#include "include/core/SkFlattenable.h"
12
#include "include/core/SkScalar.h"
13
// not needed, but some of our clients need it (they don't IWYU)
14
#include "include/core/SkPath.h"
15
16
class SkPath;
17
struct SkRect;
18
class SkStrokeRec;
19
20
/** \class SkPathEffect
21
22
    SkPathEffect is the base class for objects in the SkPaint that affect
23
    the geometry of a drawing primitive before it is transformed by the
24
    canvas' matrix and drawn.
25
26
    Dashing is implemented as a subclass of SkPathEffect.
27
*/
28
class SK_API SkPathEffect : public SkFlattenable {
29
public:
30
    /**
31
     *  Returns a patheffect that apples each effect (first and second) to the original path,
32
     *  and returns a path with the sum of these.
33
     *
34
     *  result = first(path) + second(path)
35
     *
36
     */
37
    static sk_sp<SkPathEffect> MakeSum(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second);
38
39
    /**
40
     *  Returns a patheffect that applies the inner effect to the path, and then applies the
41
     *  outer effect to the result of the inner's.
42
     *
43
     *  result = outer(inner(path))
44
     */
45
    static sk_sp<SkPathEffect> MakeCompose(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner);
46
47
2.53k
    static SkFlattenable::Type GetFlattenableType() {
48
2.53k
        return kSkPathEffect_Type;
49
2.53k
    }
50
51
    // move to base?
52
53
    enum DashType {
54
        kNone_DashType, //!< ignores the info parameter
55
        kDash_DashType, //!< fills in all of the info parameter
56
    };
57
58
    struct DashInfo {
59
14.8k
        DashInfo() : fIntervals(nullptr), fCount(0), fPhase(0) {}
60
        DashInfo(SkScalar* intervals, int32_t count, SkScalar phase)
61
0
            : fIntervals(intervals), fCount(count), fPhase(phase) {}
62
63
        SkScalar*   fIntervals;         //!< Length of on/off intervals for dashed lines
64
                                        //   Even values represent ons, and odds offs
65
        int32_t     fCount;             //!< Number of intervals in the dash. Should be even number
66
        SkScalar    fPhase;             //!< Offset into the dashed interval pattern
67
                                        //   mod the sum of all intervals
68
    };
69
70
    DashType asADash(DashInfo* info) const;
71
72
    /**
73
     *  Given a src path (input) and a stroke-rec (input and output), apply
74
     *  this effect to the src path, returning the new path in dst, and return
75
     *  true. If this effect cannot be applied, return false and ignore dst
76
     *  and stroke-rec.
77
     *
78
     *  The stroke-rec specifies the initial request for stroking (if any).
79
     *  The effect can treat this as input only, or it can choose to change
80
     *  the rec as well. For example, the effect can decide to change the
81
     *  stroke's width or join, or the effect can change the rec from stroke
82
     *  to fill (or fill to stroke) in addition to returning a new (dst) path.
83
     *
84
     *  If this method returns true, the caller will apply (as needed) the
85
     *  resulting stroke-rec to dst and then draw.
86
     */
87
    bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect* cullR) const;
88
89
    /** Version of filterPath that can be called when the CTM is known. */
90
    bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect* cullR,
91
                    const SkMatrix& ctm) const;
92
93
    /** True if this path effect requires a valid CTM */
94
    bool needsCTM() const;
95
96
    static sk_sp<SkPathEffect> Deserialize(const void* data, size_t size,
97
                                           const SkDeserialProcs* procs = nullptr);
98
99
private:
100
370k
    SkPathEffect() = default;
101
    friend class SkPathEffectBase;
102
103
    using INHERITED = SkFlattenable;
104
};
105
106
#endif