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 Sk2DPathEffect_DEFINED
|
|
|
|
#define Sk2DPathEffect_DEFINED
|
|
|
|
|
2018-05-21 15:56:57 +00:00
|
|
|
#include "SkFlattenable.h"
|
2011-08-09 18:47:40 +00:00
|
|
|
#include "SkPath.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkPathEffect.h"
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
|
2012-10-12 14:41:39 +00:00
|
|
|
class SK_API Sk2DPathEffect : public SkPathEffect {
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
|
|
|
/** New virtual, to be overridden by subclasses.
|
|
|
|
This is called once from filterPath, and provides the
|
|
|
|
uv parameter bounds for the path. Subsequent calls to
|
|
|
|
next() will receive u and v values within these bounds,
|
|
|
|
and then a call to end() will signal the end of processing.
|
|
|
|
*/
|
2012-12-18 16:12:09 +00:00
|
|
|
virtual void begin(const SkIRect& uvBounds, SkPath* dst) const;
|
|
|
|
virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) const;
|
|
|
|
virtual void end(SkPath* dst) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Low-level virtual called per span of locations in the u-direction.
|
|
|
|
The default implementation calls next() repeatedly with each
|
|
|
|
location.
|
|
|
|
*/
|
2012-12-18 16:12:09 +00:00
|
|
|
virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
const SkMatrix& getMatrix() const { return fMatrix; }
|
|
|
|
|
|
|
|
// protected so that subclasses can call this during unflattening
|
2014-05-15 15:40:41 +00:00
|
|
|
explicit Sk2DPathEffect(const SkMatrix& mat);
|
2015-03-26 01:17:31 +00:00
|
|
|
void flatten(SkWriteBuffer&) const override;
|
2018-08-16 17:22:16 +00:00
|
|
|
bool onFilterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkMatrix fMatrix, fInverse;
|
2012-04-14 19:06:16 +00:00
|
|
|
bool fMatrixIsInvertible;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// illegal
|
|
|
|
Sk2DPathEffect(const Sk2DPathEffect&);
|
|
|
|
Sk2DPathEffect& operator=(const Sk2DPathEffect&);
|
|
|
|
|
|
|
|
friend class Sk2DPathEffectBlitter;
|
|
|
|
typedef SkPathEffect INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-10-12 14:41:39 +00:00
|
|
|
class SK_API SkLine2DPathEffect : public Sk2DPathEffect {
|
2012-09-12 18:53:49 +00:00
|
|
|
public:
|
2016-03-18 18:22:57 +00:00
|
|
|
static sk_sp<SkPathEffect> Make(SkScalar width, const SkMatrix& matrix) {
|
2018-05-18 20:29:11 +00:00
|
|
|
if (!(width >= 0)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-03-18 18:22:57 +00:00
|
|
|
return sk_sp<SkPathEffect>(new SkLine2DPathEffect(width, matrix));
|
2014-02-20 20:40:19 +00:00
|
|
|
}
|
2012-09-12 18:53:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
protected:
|
2014-05-15 15:40:41 +00:00
|
|
|
SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
|
2018-05-18 20:29:11 +00:00
|
|
|
: Sk2DPathEffect(matrix), fWidth(width) {
|
|
|
|
SkASSERT(width >= 0);
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void flatten(SkWriteBuffer&) const override;
|
2018-08-16 17:22:16 +00:00
|
|
|
bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
|
2012-09-12 18:53:49 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void nextSpan(int u, int v, int ucount, SkPath*) const override;
|
2014-02-20 20:40:19 +00:00
|
|
|
|
2012-09-12 18:53:49 +00:00
|
|
|
private:
|
2018-10-18 21:27:16 +00:00
|
|
|
SK_FLATTENABLE_HOOKS(SkLine2DPathEffect)
|
2018-05-21 15:56:57 +00:00
|
|
|
|
2012-09-12 18:53:49 +00:00
|
|
|
SkScalar fWidth;
|
|
|
|
|
|
|
|
typedef Sk2DPathEffect INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-10-12 14:41:39 +00:00
|
|
|
class SK_API SkPath2DPathEffect : public Sk2DPathEffect {
|
2011-08-09 18:47:40 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Stamp the specified path to fill the shape, using the matrix to define
|
|
|
|
* the latice.
|
|
|
|
*/
|
2016-03-18 18:22:57 +00:00
|
|
|
static sk_sp<SkPathEffect> Make(const SkMatrix& matrix, const SkPath& path) {
|
|
|
|
return sk_sp<SkPathEffect>(new SkPath2DPathEffect(matrix, path));
|
2014-02-20 20:40:19 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-08-09 18:47:40 +00:00
|
|
|
protected:
|
2014-05-15 15:40:41 +00:00
|
|
|
SkPath2DPathEffect(const SkMatrix&, const SkPath&);
|
2015-03-26 01:17:31 +00:00
|
|
|
void flatten(SkWriteBuffer&) const override;
|
2011-08-09 18:47:40 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void next(const SkPoint&, int u, int v, SkPath*) const override;
|
2011-08-09 18:47:40 +00:00
|
|
|
|
|
|
|
private:
|
2018-10-18 21:27:16 +00:00
|
|
|
SK_FLATTENABLE_HOOKS(SkPath2DPathEffect)
|
2018-05-21 15:56:57 +00:00
|
|
|
|
2011-08-09 18:47:40 +00:00
|
|
|
SkPath fPath;
|
|
|
|
|
|
|
|
typedef Sk2DPathEffect INHERITED;
|
|
|
|
};
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|