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
|
|
|
|
|
|
|
|
#include "SkFlattenable.h"
|
2012-11-28 17:18:11 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "SkRect.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SkPath;
|
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);
|
|
|
|
|
Change patheffect to take a (new) StrokeRec object, which encapsulates the fill
or stroke parameters for a path.
Today, the patheffect only sees if the caller was going to stroke or fill, and
if stroke, it just sees the width. With this change, the effect can see all of the
related parameters (e.g. cap/join/miter). No other change is intended at this
time.
After this change, I hope to use this additional data to allow SkDashPathEffect
to, at times, apply the stroke as part of its effect, which may be much more
efficient than first dashing, and then reading that and stroking it.
Most of these files changed just because of the new parameter to filterPath. The
key changes are in SkPathEffect.[h,cpp], SkPaint.cpp and SkScalerContext.cpp
Review URL: https://codereview.appspot.com/6250051
git-svn-id: http://skia.googlecode.com/svn/trunk@4048 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-05-25 01:04:12 +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.
|
|
|
|
*/
|
2012-12-18 16:12:09 +00:00
|
|
|
virtual bool filterPath(SkPath* dst, const SkPath& src,
|
2013-01-24 21:03:11 +00:00
|
|
|
SkStrokeRec*, const SkRect* cullR) const = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-05-15 20:47:50 +00:00
|
|
|
/**
|
|
|
|
* Compute a conservative bounds for its effect, given the src bounds.
|
|
|
|
* The baseline implementation just assigns src to dst.
|
|
|
|
*/
|
2012-12-18 16:12:09 +00:00
|
|
|
virtual void computeFastBounds(SkRect* dst, const SkRect& src) const;
|
2012-05-15 20:47:50 +00:00
|
|
|
|
2012-11-28 17:18:11 +00:00
|
|
|
/** \class PointData
|
|
|
|
|
|
|
|
PointData aggregates all the information needed to draw the point
|
2012-11-29 02:01:19 +00:00
|
|
|
primitives returned by an 'asPoints' call.
|
2012-11-28 17:18:11 +00:00
|
|
|
*/
|
|
|
|
class PointData {
|
|
|
|
public:
|
|
|
|
PointData()
|
2012-12-05 19:07:21 +00:00
|
|
|
: fFlags(0)
|
2017-08-28 14:34:05 +00:00
|
|
|
, fPoints(nullptr)
|
2012-12-05 19:07:21 +00:00
|
|
|
, fNumPoints(0) {
|
2012-11-28 17:18:11 +00:00
|
|
|
fSize.set(SK_Scalar1, SK_Scalar1);
|
2012-11-29 02:01:19 +00:00
|
|
|
// 'asPoints' needs to initialize/fill-in 'fClipRect' if it sets
|
2012-11-28 17:18:11 +00:00
|
|
|
// the kUseClip flag
|
2016-09-27 13:34:10 +00:00
|
|
|
}
|
2012-12-05 19:07:21 +00:00
|
|
|
~PointData() {
|
|
|
|
delete [] fPoints;
|
|
|
|
}
|
2012-11-28 17:18:11 +00:00
|
|
|
|
|
|
|
// TODO: consider using passed-in flags to limit the work asPoints does.
|
|
|
|
// For example, a kNoPath flag could indicate don't bother generating
|
|
|
|
// stamped solutions.
|
|
|
|
|
|
|
|
// Currently none of these flags are supported.
|
|
|
|
enum PointFlags {
|
|
|
|
kCircles_PointFlag = 0x01, // draw points as circles (instead of rects)
|
|
|
|
kUsePath_PointFlag = 0x02, // draw points as stamps of the returned path
|
|
|
|
kUseClip_PointFlag = 0x04, // apply 'fClipRect' before drawing the points
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t fFlags; // flags that impact the drawing of the points
|
2012-12-05 19:07:21 +00:00
|
|
|
SkPoint* fPoints; // the center point of each generated point
|
|
|
|
int fNumPoints; // number of points in fPoints
|
2012-11-28 17:18:11 +00:00
|
|
|
SkVector fSize; // the size to draw the points
|
|
|
|
SkRect fClipRect; // clip required to draw the points (if kUseClip is set)
|
|
|
|
SkPath fPath; // 'stamp' to be used at each point (if kUsePath is set)
|
2012-12-17 18:56:29 +00:00
|
|
|
|
|
|
|
SkPath fFirst; // If not empty, contains geometry for first point
|
|
|
|
SkPath fLast; // If not empty, contains geometry for last point
|
2012-11-28 17:18:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does applying this path effect to 'src' yield a set of points? If so,
|
|
|
|
* optionally return the points in 'results'.
|
|
|
|
*/
|
2012-11-29 02:01:19 +00:00
|
|
|
virtual bool asPoints(PointData* results, const SkPath& src,
|
2013-01-24 21:03:11 +00:00
|
|
|
const SkStrokeRec&, const SkMatrix&,
|
|
|
|
const SkRect* cullR) const;
|
2012-11-28 17:18:11 +00:00
|
|
|
|
2014-04-22 15:21:18 +00:00
|
|
|
/**
|
|
|
|
* If the PathEffect can be represented as a dash pattern, asADash will return kDash_DashType
|
|
|
|
* and None otherwise. If a non NULL info is passed in, the various DashInfo will be filled
|
|
|
|
* in if the PathEffect can be a dash pattern. If passed in info has an fCount equal or
|
|
|
|
* greater to that of the effect, it will memcpy the values of the dash intervals into the
|
|
|
|
* info. Thus the general approach will be call asADash once with default info to get DashType
|
|
|
|
* and fCount. If effect can be represented as a dash pattern, allocate space for the intervals
|
|
|
|
* in info, then call asADash again with the same info and the intervals will get copied in.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual DashType asADash(DashInfo* info) const;
|
|
|
|
|
2015-01-26 14:08:52 +00:00
|
|
|
SK_TO_STRING_PUREVIRT()
|
2016-04-04 21:57:19 +00:00
|
|
|
SK_DEFINE_FLATTENABLE_TYPE(SkPathEffect)
|
2013-10-23 17:06:21 +00:00
|
|
|
|
2015-03-05 16:01:07 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
|
|
/// Override for subclasses as appropriate.
|
|
|
|
virtual bool exposedInAndroidJavaAPI() const { return false; }
|
|
|
|
#endif
|
|
|
|
|
2017-02-26 03:34:32 +00:00
|
|
|
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
|
|
|
|
2012-03-26 17:57:35 +00:00
|
|
|
protected:
|
2014-02-20 20:40:19 +00:00
|
|
|
SkPathEffect() {}
|
2012-03-26 17:57:35 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
// illegal
|
|
|
|
SkPathEffect(const SkPathEffect&);
|
|
|
|
SkPathEffect& operator=(const SkPathEffect&);
|
2012-03-26 17:57:35 +00:00
|
|
|
|
|
|
|
typedef SkFlattenable INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|