2011-07-28 14:26:00 +00:00
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkPathEffect_DEFINED
|
|
|
|
#define SkPathEffect_DEFINED
|
|
|
|
|
|
|
|
#include "SkFlattenable.h"
|
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
|
|
|
#include "SkPaint.h"
|
2012-11-28 17:18:11 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkTDArray.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SkPath;
|
|
|
|
|
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
|
|
|
class SkStrokeRec {
|
|
|
|
public:
|
|
|
|
enum InitStyle {
|
|
|
|
kHairline_InitStyle,
|
|
|
|
kFill_InitStyle
|
|
|
|
};
|
|
|
|
SkStrokeRec(InitStyle style);
|
|
|
|
|
|
|
|
SkStrokeRec(const SkStrokeRec&);
|
|
|
|
explicit SkStrokeRec(const SkPaint&);
|
|
|
|
|
|
|
|
enum Style {
|
|
|
|
kHairline_Style,
|
|
|
|
kFill_Style,
|
|
|
|
kStroke_Style,
|
|
|
|
kStrokeAndFill_Style
|
|
|
|
};
|
|
|
|
|
|
|
|
Style getStyle() const;
|
|
|
|
SkScalar getWidth() const { return fWidth; }
|
|
|
|
SkScalar getMiter() const { return fMiterLimit; }
|
|
|
|
SkPaint::Cap getCap() const { return fCap; }
|
|
|
|
SkPaint::Join getJoin() const { return fJoin; }
|
|
|
|
|
|
|
|
bool isHairlineStyle() const {
|
|
|
|
return kHairline_Style == this->getStyle();
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
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
|
|
|
bool isFillStyle() const {
|
|
|
|
return kFill_Style == this->getStyle();
|
|
|
|
}
|
|
|
|
|
2012-05-29 12:03:46 +00:00
|
|
|
void setFillStyle();
|
|
|
|
void setHairlineStyle();
|
|
|
|
/**
|
|
|
|
* Specify the strokewidth, and optionally if you want stroke + fill.
|
|
|
|
* Note, if width==0, then this request is taken to mean:
|
|
|
|
* strokeAndFill==true -> new style will be Fill
|
|
|
|
* strokeAndFill==false -> new style will be Hairline
|
|
|
|
*/
|
|
|
|
void setStrokeStyle(SkScalar width, bool strokeAndFill = false);
|
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
|
|
|
|
|
|
|
void setStrokeParams(SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit) {
|
|
|
|
fCap = cap;
|
|
|
|
fJoin = join;
|
|
|
|
fMiterLimit = miterLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this specifes any thick stroking, i.e. applyToPath()
|
|
|
|
* will return true.
|
|
|
|
*/
|
|
|
|
bool needToApply() const {
|
|
|
|
Style style = this->getStyle();
|
|
|
|
return (kStroke_Style == style) || (kStrokeAndFill_Style == style);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply these stroke parameters to the src path, returning the result
|
|
|
|
* in dst.
|
|
|
|
*
|
|
|
|
* If there was no change (i.e. style == hairline or fill) this returns
|
|
|
|
* false and dst is unchanged. Otherwise returns true and the result is
|
|
|
|
* stored in dst.
|
|
|
|
*
|
|
|
|
* src and dst may be the same path.
|
|
|
|
*/
|
|
|
|
bool applyToPath(SkPath* dst, const SkPath& src) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkScalar fWidth;
|
|
|
|
SkScalar fMiterLimit;
|
|
|
|
SkPaint::Cap fCap;
|
|
|
|
SkPaint::Join fJoin;
|
|
|
|
bool fStrokeAndFill;
|
|
|
|
};
|
|
|
|
|
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:
|
2012-06-27 14:03:26 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkPathEffect)
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPathEffect() {}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) = 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.
|
|
|
|
*/
|
|
|
|
virtual void computeFastBounds(SkRect* dst, const SkRect& src);
|
|
|
|
|
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()
|
|
|
|
: fFlags(0) {
|
|
|
|
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
|
|
|
|
};
|
|
|
|
~PointData() {};
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// TODO: consider replacing the TDArray with either SkData or a ptr/len field
|
|
|
|
SkTDArray<SkPoint> fPoints; // the center point of each generated point
|
|
|
|
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)
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2012-11-28 17:18:11 +00:00
|
|
|
const SkStrokeRec&, const SkMatrix&) const;
|
|
|
|
|
2012-03-26 17:57:35 +00:00
|
|
|
protected:
|
|
|
|
SkPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/** \class SkPairPathEffect
|
|
|
|
|
|
|
|
Common baseclass for Compose and Sum. This subclass manages two pathEffects,
|
|
|
|
including flattening them. It does nothing in filterPath, and is only useful
|
|
|
|
for managing the lifetimes of its two arguments.
|
|
|
|
*/
|
|
|
|
class SkPairPathEffect : public SkPathEffect {
|
|
|
|
public:
|
|
|
|
SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1);
|
|
|
|
virtual ~SkPairPathEffect();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkPairPathEffect(SkFlattenableReadBuffer&);
|
2012-03-29 15:18:04 +00:00
|
|
|
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// these are visible to our subclasses
|
|
|
|
SkPathEffect* fPE0, *fPE1;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
typedef SkPathEffect INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \class SkComposePathEffect
|
|
|
|
|
|
|
|
This subclass of SkPathEffect composes its two arguments, to create
|
|
|
|
a compound pathEffect.
|
|
|
|
*/
|
|
|
|
class SkComposePathEffect : public SkPairPathEffect {
|
|
|
|
public:
|
|
|
|
/** Construct a pathEffect whose effect is to apply first the inner pathEffect
|
|
|
|
and the the outer pathEffect (e.g. outer(inner(path)))
|
|
|
|
The reference counts for outer and inner are both incremented in the constructor,
|
|
|
|
and decremented in the destructor.
|
|
|
|
*/
|
|
|
|
SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner)
|
|
|
|
: INHERITED(outer, 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
|
|
|
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-26 17:57:35 +00:00
|
|
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-29 15:18:04 +00:00
|
|
|
protected:
|
2008-12-17 15:59:43 +00:00
|
|
|
SkComposePathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
|
|
|
|
|
2012-03-29 15:18:04 +00:00
|
|
|
private:
|
2008-12-17 15:59:43 +00:00
|
|
|
// illegal
|
|
|
|
SkComposePathEffect(const SkComposePathEffect&);
|
|
|
|
SkComposePathEffect& operator=(const SkComposePathEffect&);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
typedef SkPairPathEffect INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \class SkSumPathEffect
|
|
|
|
|
|
|
|
This subclass of SkPathEffect applies two pathEffects, one after the other.
|
|
|
|
Its filterPath() returns true if either of the effects succeeded.
|
|
|
|
*/
|
|
|
|
class SkSumPathEffect : public SkPairPathEffect {
|
|
|
|
public:
|
|
|
|
/** Construct a pathEffect whose effect is to apply two effects, in sequence.
|
|
|
|
(e.g. first(path) + second(path))
|
|
|
|
The reference counts for first and second are both incremented in the constructor,
|
|
|
|
and decremented in the destructor.
|
|
|
|
*/
|
|
|
|
SkSumPathEffect(SkPathEffect* first, SkPathEffect* second)
|
|
|
|
: INHERITED(first, second) {}
|
|
|
|
|
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
|
|
|
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-26 17:57:35 +00:00
|
|
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-29 15:18:04 +00:00
|
|
|
protected:
|
2008-12-17 15:59:43 +00:00
|
|
|
SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
|
|
|
|
|
2012-03-29 15:18:04 +00:00
|
|
|
private:
|
2008-12-17 15:59:43 +00:00
|
|
|
// illegal
|
|
|
|
SkSumPathEffect(const SkSumPathEffect&);
|
|
|
|
SkSumPathEffect& operator=(const SkSumPathEffect&);
|
|
|
|
|
|
|
|
typedef SkPairPathEffect INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|