2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPathEffect_DEFINED
|
|
|
|
#define SkPathEffect_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkFlattenable.h"
|
2021-05-21 21:42:14 +00:00
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
// not needed, but some of our clients need it (they don't IWYU)
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SkPath;
|
2021-05-21 21:42:14 +00:00
|
|
|
struct SkRect;
|
2015-09-15 19:53:07 +00:00
|
|
|
class SkStrokeRec;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** \class SkPathEffect
|
|
|
|
|
|
|
|
SkPathEffect is the base class for objects in the SkPaint that affect
|
|
|
|
the geometry of a drawing primitive before it is transformed by the
|
|
|
|
canvas' matrix and drawn.
|
|
|
|
|
|
|
|
Dashing is implemented as a subclass of SkPathEffect.
|
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API SkPathEffect : public SkFlattenable {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2017-03-09 12:51:09 +00:00
|
|
|
/**
|
|
|
|
* Returns a patheffect that apples each effect (first and second) to the original path,
|
|
|
|
* and returns a path with the sum of these.
|
|
|
|
*
|
|
|
|
* result = first(path) + second(path)
|
|
|
|
*
|
|
|
|
*/
|
2017-02-26 03:34:32 +00:00
|
|
|
static sk_sp<SkPathEffect> MakeSum(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second);
|
2017-03-09 12:51:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a patheffect that applies the inner effect to the path, and then applies the
|
|
|
|
* outer effect to the result of the inner's.
|
|
|
|
*
|
|
|
|
* result = outer(inner(path))
|
|
|
|
*/
|
2017-02-26 03:34:32 +00:00
|
|
|
static sk_sp<SkPathEffect> MakeCompose(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner);
|
|
|
|
|
2021-05-21 21:42:14 +00:00
|
|
|
static SkFlattenable::Type GetFlattenableType() {
|
|
|
|
return kSkPathEffect_Type;
|
|
|
|
}
|
2012-11-28 17:18:11 +00:00
|
|
|
|
2021-05-21 21:42:14 +00:00
|
|
|
// move to base?
|
2014-04-22 15:21:18 +00:00
|
|
|
|
|
|
|
enum DashType {
|
|
|
|
kNone_DashType, //!< ignores the info parameter
|
|
|
|
kDash_DashType, //!< fills in all of the info parameter
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DashInfo {
|
2017-08-28 14:34:05 +00:00
|
|
|
DashInfo() : fIntervals(nullptr), fCount(0), fPhase(0) {}
|
2016-08-10 23:36:11 +00:00
|
|
|
DashInfo(SkScalar* intervals, int32_t count, SkScalar phase)
|
|
|
|
: fIntervals(intervals), fCount(count), fPhase(phase) {}
|
2014-04-22 15:21:18 +00:00
|
|
|
|
|
|
|
SkScalar* fIntervals; //!< Length of on/off intervals for dashed lines
|
|
|
|
// Even values represent ons, and odds offs
|
|
|
|
int32_t fCount; //!< Number of intervals in the dash. Should be even number
|
|
|
|
SkScalar fPhase; //!< Offset into the dashed interval pattern
|
|
|
|
// mod the sum of all intervals
|
|
|
|
};
|
|
|
|
|
2018-08-16 17:22:16 +00:00
|
|
|
DashType asADash(DashInfo* info) const;
|
2014-04-22 15:21:18 +00:00
|
|
|
|
2021-05-21 21:42:14 +00:00
|
|
|
/**
|
|
|
|
* Given a src path (input) and a stroke-rec (input and output), apply
|
|
|
|
* this effect to the src path, returning the new path in dst, and return
|
|
|
|
* true. If this effect cannot be applied, return false and ignore dst
|
|
|
|
* and stroke-rec.
|
|
|
|
*
|
|
|
|
* The stroke-rec specifies the initial request for stroking (if any).
|
|
|
|
* The effect can treat this as input only, or it can choose to change
|
|
|
|
* the rec as well. For example, the effect can decide to change the
|
|
|
|
* stroke's width or join, or the effect can change the rec from stroke
|
|
|
|
* to fill (or fill to stroke) in addition to returning a new (dst) path.
|
|
|
|
*
|
|
|
|
* If this method returns true, the caller will apply (as needed) the
|
|
|
|
* resulting stroke-rec to dst and then draw.
|
|
|
|
*/
|
|
|
|
bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect* cullR) const;
|
2018-08-16 17:22:16 +00:00
|
|
|
|
2021-06-17 16:23:33 +00:00
|
|
|
static sk_sp<SkPathEffect> Deserialize(const void* data, size_t size,
|
|
|
|
const SkDeserialProcs* procs = nullptr);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2021-05-21 21:42:14 +00:00
|
|
|
SkPathEffect() = default;
|
|
|
|
friend class SkPathEffectBase;
|
2012-03-26 17:57:35 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = SkFlattenable;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|