skia2/include/core/SkPathEffect.h
Cary Clark 89ad31e97c Revert "Reland "remove toString""
This reverts commit 92e37b6d79.

Reason for revert: toString still used by flutter

Original change's description:
> Reland "remove toString"
> 
> This reverts commit 32a4910e57.
> 
> Reason for revert: SkMatrix::toString use has been removed from flutter and has been picked up in fuchsia
> 
> Original change's description:
> > Revert "remove toString"
> > 
> > This reverts commit 5191880cbf.
> > 
> > Reason for revert: broke flutter
> > 
> > Original change's description:
> > > remove toString
> > > 
> > > toString may have been used by obsolete debugger only
> > > find out if that is so
> > > 
> > > R=​brianosman@google.com,bsalomon@google.com
> > > 
> > > Docs-Preview: https://skia.org/?cl=119894
> > > Bug:830651
> > > Change-Id: I737f19b7d3fbc869bea2f443fa3b5ed7c1393ffd
> > > Reviewed-on: https://skia-review.googlesource.com/119894
> > > Commit-Queue: Cary Clark <caryclark@google.com>
> > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > 
> > TBR=bsalomon@google.com,brianosman@google.com,caryclark@google.com,caryclark@skia.org
> > 
> > Change-Id: I9f81de6c3615ee0608bcea9081b77239b4b8816c
> > No-Presubmit: true
> > No-Tree-Checks: true
> > No-Try: true
> > Bug: 830651
> > Reviewed-on: https://skia-review.googlesource.com/129340
> > Reviewed-by: Cary Clark <caryclark@google.com>
> > Commit-Queue: Cary Clark <caryclark@google.com>
> 
> TBR=bsalomon@google.com,brianosman@google.com,caryclark@google.com,caryclark@skia.org
> 
> # Not skipping CQ checks because original CL landed > 1 day ago.
> 
> Bug: 830651
> Change-Id: Ida8725b6051132d8c46faf99358a8fcc1bcabf34
> Reviewed-on: https://skia-review.googlesource.com/129623
> Reviewed-by: Cary Clark <caryclark@skia.org>
> Reviewed-by: Cary Clark <caryclark@google.com>
> Commit-Queue: Cary Clark <caryclark@google.com>

TBR=bsalomon@google.com,brianosman@google.com,caryclark@google.com,caryclark@skia.org

Change-Id: Iafc59ffc1b3db67c520ba31bf12d68e1b46c0ea2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 830651
Reviewed-on: https://skia-review.googlesource.com/131082
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Cary Clark <caryclark@google.com>
2018-05-31 12:27:44 +00:00

184 lines
7.0 KiB
C++

/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkPathEffect_DEFINED
#define SkPathEffect_DEFINED
#include "SkFlattenable.h"
#include "SkPath.h"
#include "SkPoint.h"
#include "SkRect.h"
class SkPath;
class SkStrokeRec;
/** \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.
*/
class SK_API SkPathEffect : public SkFlattenable {
public:
/**
* 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)
*
*/
static sk_sp<SkPathEffect> MakeSum(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second);
/**
* 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))
*/
static sk_sp<SkPathEffect> MakeCompose(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner);
/**
* 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*, const SkRect* cullR) const = 0;
/**
* 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) const;
/** \class PointData
PointData aggregates all the information needed to draw the point
primitives returned by an 'asPoints' call.
*/
class PointData {
public:
PointData()
: fFlags(0)
, fPoints(nullptr)
, fNumPoints(0) {
fSize.set(SK_Scalar1, SK_Scalar1);
// 'asPoints' needs to initialize/fill-in 'fClipRect' if it sets
// the kUseClip flag
}
~PointData() {
delete [] fPoints;
}
// 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
SkPoint* fPoints; // the center point of each generated point
int fNumPoints; // number of points in fPoints
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)
SkPath fFirst; // If not empty, contains geometry for first point
SkPath fLast; // If not empty, contains geometry for last point
};
/**
* Does applying this path effect to 'src' yield a set of points? If so,
* optionally return the points in 'results'.
*/
virtual bool asPoints(PointData* results, const SkPath& src,
const SkStrokeRec&, const SkMatrix&,
const SkRect* cullR) const;
/**
* 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 {
DashInfo() : fIntervals(nullptr), fCount(0), fPhase(0) {}
DashInfo(SkScalar* intervals, int32_t count, SkScalar phase)
: fIntervals(intervals), fCount(count), fPhase(phase) {}
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;
virtual void toString(SkString* str) const = 0;
static void InitializeFlattenables();
static SkFlattenable::Type GetFlattenableType() {
return kSkPathEffect_Type;
}
SkFlattenable::Type getFlattenableType() const override {
return kSkPathEffect_Type;
}
static sk_sp<SkPathEffect> Deserialize(const void* data, size_t size,
const SkDeserialProcs* procs = nullptr) {
return sk_sp<SkPathEffect>(static_cast<SkPathEffect*>(
SkFlattenable::Deserialize(
kSkPathEffect_Type, data, size, procs).release()));
}
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
/// Override for subclasses as appropriate.
virtual bool exposedInAndroidJavaAPI() const { return false; }
#endif
protected:
SkPathEffect() {}
private:
// illegal
SkPathEffect(const SkPathEffect&);
SkPathEffect& operator=(const SkPathEffect&);
typedef SkFlattenable INHERITED;
};
#endif