2012-10-03 13:46:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPathRef_DEFINED
|
|
|
|
#define SkPathRef_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
2022-02-24 12:49:50 +00:00
|
|
|
#include "include/core/SkRRect.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
2020-03-02 21:59:40 +00:00
|
|
|
#include "include/private/SkIDChangeListener.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/SkMutex.h"
|
|
|
|
#include "include/private/SkTDArray.h"
|
|
|
|
#include "include/private/SkTemplates.h"
|
|
|
|
#include "include/private/SkTo.h"
|
2020-03-02 17:50:47 +00:00
|
|
|
|
2018-12-04 16:16:08 +00:00
|
|
|
#include <atomic>
|
2018-06-11 15:56:57 +00:00
|
|
|
#include <limits>
|
2020-08-06 12:58:25 +00:00
|
|
|
#include <tuple>
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2013-09-26 12:18:23 +00:00
|
|
|
class SkRBuffer;
|
|
|
|
class SkWBuffer;
|
|
|
|
|
2020-08-29 21:46:51 +00:00
|
|
|
enum class SkPathConvexity {
|
|
|
|
kConvex,
|
|
|
|
kConcave,
|
|
|
|
kUnknown,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class SkPathFirstDirection {
|
|
|
|
kCW, // == SkPathDirection::kCW
|
|
|
|
kCCW, // == SkPathDirection::kCCW
|
|
|
|
kUnknown,
|
|
|
|
};
|
|
|
|
|
2020-12-09 21:52:37 +00:00
|
|
|
// These are computed from a stream of verbs
|
|
|
|
struct SkPathVerbAnalysis {
|
|
|
|
bool valid;
|
|
|
|
int points, weights;
|
|
|
|
unsigned segmentMask;
|
|
|
|
};
|
|
|
|
SkPathVerbAnalysis sk_path_analyze_verbs(const uint8_t verbs[], int count);
|
|
|
|
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
/**
|
|
|
|
* Holds the path verbs and points. It is versioned by a generation ID. None of its public methods
|
|
|
|
* modify the contents. To modify or append to the verbs/points wrap the SkPathRef in an
|
|
|
|
* SkPathRef::Editor object. Installing the editor resets the generation ID. It also performs
|
2013-12-03 16:43:54 +00:00
|
|
|
* copy-on-write if the SkPathRef is shared by multiple SkPaths. The caller passes the Editor's
|
2016-10-27 16:30:08 +00:00
|
|
|
* constructor a pointer to a sk_sp<SkPathRef>, which may be updated to point to a new SkPathRef
|
|
|
|
* after the editor's constructor returns.
|
2012-10-03 13:46:20 +00:00
|
|
|
*
|
|
|
|
* The points and verbs are stored in a single allocation. The points are at the begining of the
|
|
|
|
* allocation while the verbs are stored at end of the allocation, in reverse order. Thus the points
|
|
|
|
* and verbs both grow into the middle of the allocation until the meet. To access verb i in the
|
|
|
|
* verb array use ref.verbs()[~i] (because verbs() returns a pointer just beyond the first
|
|
|
|
* logical verb or the last verb in memory).
|
|
|
|
*/
|
2012-10-03 19:57:01 +00:00
|
|
|
|
2018-10-30 15:23:00 +00:00
|
|
|
class SK_API SkPathRef final : public SkNVRefCnt<SkPathRef> {
|
2012-10-03 13:46:20 +00:00
|
|
|
public:
|
2020-06-24 01:06:28 +00:00
|
|
|
SkPathRef(SkTDArray<SkPoint> points, SkTDArray<uint8_t> verbs, SkTDArray<SkScalar> weights,
|
|
|
|
unsigned segmentMask)
|
|
|
|
: fPoints(std::move(points))
|
|
|
|
, fVerbs(std::move(verbs))
|
|
|
|
, fConicWeights(std::move(weights))
|
|
|
|
{
|
|
|
|
fBoundsIsDirty = true; // this also invalidates fIsFinite
|
2020-07-31 17:40:09 +00:00
|
|
|
fGenerationID = 0; // recompute
|
2020-06-24 01:06:28 +00:00
|
|
|
fSegmentMask = segmentMask;
|
|
|
|
fIsOval = false;
|
|
|
|
fIsRRect = false;
|
|
|
|
// The next two values don't matter unless fIsOval or fIsRRect are true.
|
|
|
|
fRRectOrOvalIsCCW = false;
|
|
|
|
fRRectOrOvalStartIdx = 0xAC;
|
|
|
|
SkDEBUGCODE(fEditorsAttached.store(0);)
|
2020-08-26 18:41:37 +00:00
|
|
|
|
|
|
|
this->computeBounds(); // do this now, before we worry about multiple owners/threads
|
2020-06-24 01:06:28 +00:00
|
|
|
SkDEBUGCODE(this->validate();)
|
|
|
|
}
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
class Editor {
|
|
|
|
public:
|
2016-10-27 16:30:08 +00:00
|
|
|
Editor(sk_sp<SkPathRef>* pathRef,
|
2012-10-03 13:46:20 +00:00
|
|
|
int incReserveVerbs = 0,
|
2013-09-27 17:48:49 +00:00
|
|
|
int incReservePoints = 0);
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2018-12-04 16:16:08 +00:00
|
|
|
~Editor() { SkDEBUGCODE(fPathRef->fEditorsAttached--;) }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the array of points.
|
|
|
|
*/
|
2019-09-05 18:14:38 +00:00
|
|
|
SkPoint* writablePoints() { return fPathRef->getWritablePoints(); }
|
2013-12-13 19:36:25 +00:00
|
|
|
const SkPoint* points() const { return fPathRef->points(); }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the ith point. Shortcut for this->points() + i
|
|
|
|
*/
|
2019-09-05 18:14:38 +00:00
|
|
|
SkPoint* atPoint(int i) { return fPathRef->getWritablePoints() + i; }
|
|
|
|
const SkPoint* atPoint(int i) const { return &fPathRef->fPoints[i]; }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the verb and allocates space for the number of points indicated by the verb. The
|
|
|
|
* return value is a pointer to where the points for the verb should be written.
|
2013-12-12 23:03:51 +00:00
|
|
|
* 'weight' is only used if 'verb' is kConic_Verb
|
2012-10-03 13:46:20 +00:00
|
|
|
*/
|
2013-12-12 23:03:51 +00:00
|
|
|
SkPoint* growForVerb(int /*SkPath::Verb*/ verb, SkScalar weight = 0) {
|
2013-10-02 16:42:21 +00:00
|
|
|
SkDEBUGCODE(fPathRef->validate();)
|
2013-12-12 23:03:51 +00:00
|
|
|
return fPathRef->growForVerb(verb, weight);
|
2013-09-27 17:48:49 +00:00
|
|
|
}
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-12 23:03:51 +00:00
|
|
|
* Allocates space for multiple instances of a particular verb and the
|
|
|
|
* requisite points & weights.
|
|
|
|
* The return pointer points at the first new point (indexed normally [<i>]).
|
|
|
|
* If 'verb' is kConic_Verb, 'weights' will return a pointer to the
|
2013-12-16 07:01:40 +00:00
|
|
|
* space for the conic weights (indexed normally).
|
2012-10-03 13:46:20 +00:00
|
|
|
*/
|
2013-12-16 07:01:40 +00:00
|
|
|
SkPoint* growForRepeatedVerb(int /*SkPath::Verb*/ verb,
|
|
|
|
int numVbs,
|
2017-08-28 14:34:05 +00:00
|
|
|
SkScalar** weights = nullptr) {
|
2013-12-16 07:01:40 +00:00
|
|
|
return fPathRef->growForRepeatedVerb(verb, numVbs, weights);
|
2012-10-03 13:46:20 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 00:38:37 +00:00
|
|
|
/**
|
|
|
|
* Concatenates all verbs from 'path' onto the pathRef's verbs array. Increases the point
|
|
|
|
* count by the number of points in 'path', and the conic weight count by the number of
|
|
|
|
* conics in 'path'.
|
|
|
|
*
|
|
|
|
* Returns pointers to the uninitialized points and conic weights data.
|
|
|
|
*/
|
|
|
|
std::tuple<SkPoint*, SkScalar*> growForVerbsInPath(const SkPathRef& path) {
|
|
|
|
return fPathRef->growForVerbsInPath(path);
|
|
|
|
}
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
/**
|
|
|
|
* Resets the path ref to a new verb and point count. The new verbs and points are
|
|
|
|
* uninitialized.
|
|
|
|
*/
|
2013-05-31 15:17:50 +00:00
|
|
|
void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) {
|
|
|
|
fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount);
|
2012-10-03 13:46:20 +00:00
|
|
|
}
|
2013-12-13 19:36:25 +00:00
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
/**
|
|
|
|
* Gets the path ref that is wrapped in the Editor.
|
|
|
|
*/
|
|
|
|
SkPathRef* pathRef() { return fPathRef; }
|
|
|
|
|
2016-05-27 16:17:04 +00:00
|
|
|
void setIsOval(bool isOval, bool isCCW, unsigned start) {
|
|
|
|
fPathRef->setIsOval(isOval, isCCW, start);
|
|
|
|
}
|
2013-12-03 16:43:54 +00:00
|
|
|
|
2016-05-27 16:17:04 +00:00
|
|
|
void setIsRRect(bool isRRect, bool isCCW, unsigned start) {
|
|
|
|
fPathRef->setIsRRect(isRRect, isCCW, start);
|
|
|
|
}
|
2015-11-19 22:47:43 +00:00
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
void setBounds(const SkRect& rect) { fPathRef->setBounds(rect); }
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
private:
|
|
|
|
SkPathRef* fPathRef;
|
|
|
|
};
|
|
|
|
|
2015-11-19 22:47:43 +00:00
|
|
|
class SK_API Iter {
|
|
|
|
public:
|
|
|
|
Iter();
|
|
|
|
Iter(const SkPathRef&);
|
|
|
|
|
|
|
|
void setPathRef(const SkPathRef&);
|
|
|
|
|
|
|
|
/** Return the next verb in this iteration of the path. When all
|
|
|
|
segments have been visited, return kDone_Verb.
|
|
|
|
|
2017-09-08 19:00:25 +00:00
|
|
|
If any point in the path is non-finite, return kDone_Verb immediately.
|
|
|
|
|
2015-11-19 22:47:43 +00:00
|
|
|
@param pts The points representing the current verb and/or segment
|
|
|
|
This must not be NULL.
|
|
|
|
@return The verb for the current segment
|
|
|
|
*/
|
|
|
|
uint8_t next(SkPoint pts[4]);
|
2015-12-09 22:04:46 +00:00
|
|
|
uint8_t peek() const;
|
2015-11-19 22:47:43 +00:00
|
|
|
|
|
|
|
SkScalar conicWeight() const { return *fConicWeights; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const SkPoint* fPts;
|
|
|
|
const uint8_t* fVerbs;
|
|
|
|
const uint8_t* fVerbStop;
|
|
|
|
const SkScalar* fConicWeights;
|
|
|
|
};
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Gets a path ref with no verbs or points.
|
|
|
|
*/
|
2013-10-23 14:44:08 +00:00
|
|
|
static SkPathRef* CreateEmpty();
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2013-09-26 12:18:23 +00:00
|
|
|
/**
|
|
|
|
* Returns true if all of the points in this path are finite, meaning there
|
|
|
|
* are no infinities and no NaNs.
|
|
|
|
*/
|
|
|
|
bool isFinite() const {
|
|
|
|
if (fBoundsIsDirty) {
|
|
|
|
this->computeBounds();
|
|
|
|
}
|
|
|
|
return SkToBool(fIsFinite);
|
|
|
|
}
|
|
|
|
|
2013-12-12 23:03:51 +00:00
|
|
|
/**
|
|
|
|
* Returns a mask, where each bit corresponding to a SegmentMask is
|
|
|
|
* set if the path contains 1 or more segments of that type.
|
|
|
|
* Returns 0 for an empty path (no segments).
|
|
|
|
*/
|
|
|
|
uint32_t getSegmentMasks() const { return fSegmentMask; }
|
|
|
|
|
2013-12-03 16:43:54 +00:00
|
|
|
/** Returns true if the path is an oval.
|
|
|
|
*
|
|
|
|
* @param rect returns the bounding rect of this oval. It's a circle
|
|
|
|
* if the height and width are the same.
|
2016-05-27 16:17:04 +00:00
|
|
|
* @param isCCW is the oval CCW (or CW if false).
|
|
|
|
* @param start indicates where the contour starts on the oval (see
|
|
|
|
* SkPath::addOval for intepretation of the index).
|
2013-12-03 16:43:54 +00:00
|
|
|
*
|
|
|
|
* @return true if this path is an oval.
|
|
|
|
* Tracking whether a path is an oval is considered an
|
|
|
|
* optimization for performance and so some paths that are in
|
|
|
|
* fact ovals can report false.
|
|
|
|
*/
|
2016-05-27 16:17:04 +00:00
|
|
|
bool isOval(SkRect* rect, bool* isCCW, unsigned* start) const {
|
|
|
|
if (fIsOval) {
|
|
|
|
if (rect) {
|
|
|
|
*rect = this->getBounds();
|
|
|
|
}
|
|
|
|
if (isCCW) {
|
|
|
|
*isCCW = SkToBool(fRRectOrOvalIsCCW);
|
|
|
|
}
|
|
|
|
if (start) {
|
|
|
|
*start = fRRectOrOvalStartIdx;
|
|
|
|
}
|
2013-12-03 16:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SkToBool(fIsOval);
|
|
|
|
}
|
|
|
|
|
2022-02-24 12:49:50 +00:00
|
|
|
bool isRRect(SkRRect* rrect, bool* isCCW, unsigned* start) const {
|
|
|
|
if (fIsRRect) {
|
|
|
|
if (rrect) {
|
|
|
|
*rrect = this->getRRect();
|
|
|
|
}
|
|
|
|
if (isCCW) {
|
|
|
|
*isCCW = SkToBool(fRRectOrOvalIsCCW);
|
|
|
|
}
|
|
|
|
if (start) {
|
|
|
|
*start = fRRectOrOvalStartIdx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SkToBool(fIsRRect);
|
|
|
|
}
|
|
|
|
|
2015-11-19 22:47:43 +00:00
|
|
|
|
2013-09-26 12:18:23 +00:00
|
|
|
bool hasComputedBounds() const {
|
|
|
|
return !fBoundsIsDirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns the bounds of the path's points. If the path contains 0 or 1
|
|
|
|
points, the bounds is set to (0,0,0,0), and isEmpty() will return true.
|
|
|
|
Note: this bounds may be larger than the actual shape, since curves
|
|
|
|
do not extend as far as their control points.
|
|
|
|
*/
|
2013-09-27 07:01:29 +00:00
|
|
|
const SkRect& getBounds() const {
|
2013-09-26 12:18:23 +00:00
|
|
|
if (fBoundsIsDirty) {
|
|
|
|
this->computeBounds();
|
|
|
|
}
|
|
|
|
return fBounds;
|
|
|
|
}
|
|
|
|
|
2015-11-19 22:47:43 +00:00
|
|
|
SkRRect getRRect() const;
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
/**
|
|
|
|
* Transforms a path ref by a matrix, allocating a new one only if necessary.
|
|
|
|
*/
|
2016-10-27 16:30:08 +00:00
|
|
|
static void CreateTransformedCopy(sk_sp<SkPathRef>* dst,
|
2012-10-03 13:46:20 +00:00
|
|
|
const SkPathRef& src,
|
2013-09-27 17:48:49 +00:00
|
|
|
const SkMatrix& matrix);
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2019-09-05 18:14:38 +00:00
|
|
|
// static SkPathRef* CreateFromBuffer(SkRBuffer* buffer);
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rollsback a path ref to zero verbs and points with the assumption that the path ref will be
|
|
|
|
* repopulated with approximately the same number of verbs and points. A new path ref is created
|
|
|
|
* only if necessary.
|
|
|
|
*/
|
2016-10-27 16:30:08 +00:00
|
|
|
static void Rewind(sk_sp<SkPathRef>* pathRef);
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2016-08-09 19:20:04 +00:00
|
|
|
~SkPathRef();
|
2019-09-05 18:14:38 +00:00
|
|
|
int countPoints() const { return fPoints.count(); }
|
|
|
|
int countVerbs() const { return fVerbs.count(); }
|
Speed up convexpaths GM in debug builds
That GM has a path with 16k points, arranged in a rectangle. When we try
to draw it in Ganesh, we first check to see if it's a (closed) rectangle.
We eventually decide that it is a rectangle, but not closed, so it gets
passed along. Then we construct a GrShape, which tries to simplify the
shape, again asking if it's a rectangle...
Each isRect query was iterating over the 16k verbs, and for each one,
calling atVerb(i). That, internally, calls verbs(), which calls validate()
in debug builds. So we were walking all 16k points 16k times (to ensure
the bounds were correct). The end result is that the GM took over 11
seconds to draw, and now takes 3 ms.
Bug: skia:
Change-Id: If5f7a067b8c25f049dc64275d94a42ae4a50f6a9
Reviewed-on: https://skia-review.googlesource.com/34723
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-08-15 20:08:48 +00:00
|
|
|
int countWeights() const { return fConicWeights.count(); }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2020-10-14 14:13:14 +00:00
|
|
|
size_t approximateBytesUsed() const;
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer one beyond the first logical verb (last verb in memory order).
|
|
|
|
*/
|
2019-09-05 18:14:38 +00:00
|
|
|
const uint8_t* verbsBegin() const { return fVerbs.begin(); }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a const pointer to the first verb in memory (which is the last logical verb).
|
|
|
|
*/
|
2019-09-05 18:14:38 +00:00
|
|
|
const uint8_t* verbsEnd() const { return fVerbs.end(); }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a const pointer to the first point.
|
|
|
|
*/
|
2019-09-05 18:14:38 +00:00
|
|
|
const SkPoint* points() const { return fPoints.begin(); }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for this->points() + this->countPoints()
|
|
|
|
*/
|
|
|
|
const SkPoint* pointsEnd() const { return this->points() + this->countPoints(); }
|
|
|
|
|
Speed up convexpaths GM in debug builds
That GM has a path with 16k points, arranged in a rectangle. When we try
to draw it in Ganesh, we first check to see if it's a (closed) rectangle.
We eventually decide that it is a rectangle, but not closed, so it gets
passed along. Then we construct a GrShape, which tries to simplify the
shape, again asking if it's a rectangle...
Each isRect query was iterating over the 16k verbs, and for each one,
calling atVerb(i). That, internally, calls verbs(), which calls validate()
in debug builds. So we were walking all 16k points 16k times (to ensure
the bounds were correct). The end result is that the GM took over 11
seconds to draw, and now takes 3 ms.
Bug: skia:
Change-Id: If5f7a067b8c25f049dc64275d94a42ae4a50f6a9
Reviewed-on: https://skia-review.googlesource.com/34723
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-08-15 20:08:48 +00:00
|
|
|
const SkScalar* conicWeights() const { return fConicWeights.begin(); }
|
|
|
|
const SkScalar* conicWeightsEnd() const { return fConicWeights.end(); }
|
2013-05-31 15:17:50 +00:00
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
/**
|
|
|
|
* Convenience methods for getting to a verb or point by index.
|
|
|
|
*/
|
2019-09-05 18:14:38 +00:00
|
|
|
uint8_t atVerb(int index) const { return fVerbs[index]; }
|
|
|
|
const SkPoint& atPoint(int index) const { return fPoints[index]; }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2013-09-27 17:48:49 +00:00
|
|
|
bool operator== (const SkPathRef& ref) const;
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes the path points and verbs to a buffer.
|
|
|
|
*/
|
2013-12-12 23:03:51 +00:00
|
|
|
void writeToBuffer(SkWBuffer* buffer) const;
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the number of bytes that would be written in writeBuffer()
|
|
|
|
*/
|
2013-12-12 23:03:51 +00:00
|
|
|
uint32_t writeSize() const;
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2016-02-18 12:11:48 +00:00
|
|
|
void interpolate(const SkPathRef& ending, SkScalar weight, SkPathRef* out) const;
|
|
|
|
|
2013-10-30 18:57:55 +00:00
|
|
|
/**
|
|
|
|
* Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the
|
|
|
|
* same ID then they have the same verbs and points. However, two path refs may have the same
|
|
|
|
* contents but different genIDs.
|
|
|
|
*/
|
|
|
|
uint32_t genID() const;
|
|
|
|
|
2020-03-02 17:50:47 +00:00
|
|
|
void addGenIDChangeListener(sk_sp<SkIDChangeListener>); // Threadsafe.
|
2020-02-25 14:14:08 +00:00
|
|
|
int genIDChangeListenerCount(); // Threadsafe
|
2015-08-04 17:01:58 +00:00
|
|
|
|
2020-12-09 21:52:37 +00:00
|
|
|
bool dataMatchesVerbs() const;
|
2017-08-10 19:16:37 +00:00
|
|
|
bool isValid() const;
|
|
|
|
SkDEBUGCODE(void validate() const { SkASSERT(this->isValid()); } )
|
2014-12-15 20:28:33 +00:00
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
private:
|
2013-09-26 12:18:23 +00:00
|
|
|
enum SerializationOffsets {
|
2017-09-21 20:59:17 +00:00
|
|
|
kLegacyRRectOrOvalStartIdx_SerializationShift = 28, // requires 3 bits, ignored.
|
|
|
|
kLegacyRRectOrOvalIsCCW_SerializationShift = 27, // requires 1 bit, ignored.
|
|
|
|
kLegacyIsRRect_SerializationShift = 26, // requires 1 bit, ignored.
|
|
|
|
kIsFinite_SerializationShift = 25, // requires 1 bit
|
|
|
|
kLegacyIsOval_SerializationShift = 24, // requires 1 bit, ignored.
|
2018-02-20 14:48:13 +00:00
|
|
|
kSegmentMask_SerializationShift = 0 // requires 4 bits (deprecated)
|
2013-09-26 12:18:23 +00:00
|
|
|
};
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
SkPathRef() {
|
2013-09-26 12:18:23 +00:00
|
|
|
fBoundsIsDirty = true; // this also invalidates fIsFinite
|
2012-10-03 13:46:20 +00:00
|
|
|
fGenerationID = kEmptyGenID;
|
2013-12-12 23:03:51 +00:00
|
|
|
fSegmentMask = 0;
|
2013-12-03 16:43:54 +00:00
|
|
|
fIsOval = false;
|
2015-11-19 22:47:43 +00:00
|
|
|
fIsRRect = false;
|
2016-05-27 16:17:04 +00:00
|
|
|
// The next two values don't matter unless fIsOval or fIsRRect are true.
|
2016-07-22 20:51:42 +00:00
|
|
|
fRRectOrOvalIsCCW = false;
|
|
|
|
fRRectOrOvalStartIdx = 0xAC;
|
2018-12-04 16:16:08 +00:00
|
|
|
SkDEBUGCODE(fEditorsAttached.store(0);)
|
2013-10-02 16:42:21 +00:00
|
|
|
SkDEBUGCODE(this->validate();)
|
2012-10-03 13:46:20 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 17:48:49 +00:00
|
|
|
void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalReservePoints);
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2013-09-26 12:18:23 +00:00
|
|
|
// Return true if the computed bounds are finite.
|
|
|
|
static bool ComputePtBounds(SkRect* bounds, const SkPathRef& ref) {
|
2015-07-28 13:00:50 +00:00
|
|
|
return bounds->setBoundsCheck(ref.points(), ref.countPoints());
|
2013-09-26 12:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// called, if dirty, by getBounds()
|
|
|
|
void computeBounds() const {
|
|
|
|
SkDEBUGCODE(this->validate();)
|
2014-07-16 21:18:20 +00:00
|
|
|
// TODO(mtklein): remove fBoundsIsDirty and fIsFinite,
|
|
|
|
// using an inverted rect instead of fBoundsIsDirty and always recalculating fIsFinite.
|
2014-12-01 14:59:54 +00:00
|
|
|
SkASSERT(fBoundsIsDirty);
|
2013-09-26 12:18:23 +00:00
|
|
|
|
2014-12-01 14:59:54 +00:00
|
|
|
fIsFinite = ComputePtBounds(&fBounds, *this);
|
2013-09-26 12:18:23 +00:00
|
|
|
fBoundsIsDirty = false;
|
|
|
|
}
|
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
void setBounds(const SkRect& rect) {
|
|
|
|
SkASSERT(rect.fLeft <= rect.fRight && rect.fTop <= rect.fBottom);
|
|
|
|
fBounds = rect;
|
|
|
|
fBoundsIsDirty = false;
|
2014-12-01 14:59:54 +00:00
|
|
|
fIsFinite = fBounds.isFinite();
|
2013-12-13 19:36:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
/** Makes additional room but does not change the counts or change the genID */
|
|
|
|
void incReserve(int additionalVerbs, int additionalPoints) {
|
2013-10-02 16:42:21 +00:00
|
|
|
SkDEBUGCODE(this->validate();)
|
2019-09-05 18:14:38 +00:00
|
|
|
fPoints.setReserve(fPoints.count() + additionalPoints);
|
|
|
|
fVerbs.setReserve(fVerbs.count() + additionalVerbs);
|
2013-10-02 16:42:21 +00:00
|
|
|
SkDEBUGCODE(this->validate();)
|
2012-10-03 13:46:20 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 12:18:23 +00:00
|
|
|
/** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also
|
2012-10-03 13:46:20 +00:00
|
|
|
* allocates space for reserveVerb additional verbs and reservePoints additional points.*/
|
2013-05-31 15:17:50 +00:00
|
|
|
void resetToSize(int verbCount, int pointCount, int conicCount,
|
2013-10-02 17:49:50 +00:00
|
|
|
int reserveVerbs = 0, int reservePoints = 0) {
|
|
|
|
SkDEBUGCODE(this->validate();)
|
2019-03-07 21:50:30 +00:00
|
|
|
this->callGenIDChangeListeners();
|
2013-10-02 17:49:50 +00:00
|
|
|
fBoundsIsDirty = true; // this also invalidates fIsFinite
|
|
|
|
fGenerationID = 0;
|
|
|
|
|
2013-12-12 23:03:51 +00:00
|
|
|
fSegmentMask = 0;
|
2013-12-03 16:43:54 +00:00
|
|
|
fIsOval = false;
|
2015-11-19 22:47:43 +00:00
|
|
|
fIsRRect = false;
|
2013-12-03 16:43:54 +00:00
|
|
|
|
2019-09-05 18:14:38 +00:00
|
|
|
fPoints.setReserve(pointCount + reservePoints);
|
|
|
|
fPoints.setCount(pointCount);
|
|
|
|
fVerbs.setReserve(verbCount + reserveVerbs);
|
|
|
|
fVerbs.setCount(verbCount);
|
2013-10-02 17:49:50 +00:00
|
|
|
fConicWeights.setCount(conicCount);
|
|
|
|
SkDEBUGCODE(this->validate();)
|
|
|
|
}
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-16 07:01:40 +00:00
|
|
|
* Increases the verb count by numVbs and point count by the required amount.
|
|
|
|
* The new points are uninitialized. All the new verbs are set to the specified
|
2013-12-12 23:03:51 +00:00
|
|
|
* verb. If 'verb' is kConic_Verb, 'weights' will return a pointer to the
|
|
|
|
* uninitialized conic weights.
|
2012-10-03 13:46:20 +00:00
|
|
|
*/
|
2013-12-12 23:03:51 +00:00
|
|
|
SkPoint* growForRepeatedVerb(int /*SkPath::Verb*/ verb, int numVbs, SkScalar** weights);
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increases the verb count 1, records the new verb, and creates room for the requisite number
|
|
|
|
* of additional points. A pointer to the first point is returned. Any new points are
|
|
|
|
* uninitialized.
|
|
|
|
*/
|
2013-12-12 23:03:51 +00:00
|
|
|
SkPoint* growForVerb(int /*SkPath::Verb*/ verb, SkScalar weight);
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2020-02-07 00:38:37 +00:00
|
|
|
/**
|
|
|
|
* Concatenates all verbs from 'path' onto our own verbs array. Increases the point count by the
|
|
|
|
* number of points in 'path', and the conic weight count by the number of conics in 'path'.
|
|
|
|
*
|
|
|
|
* Returns pointers to the uninitialized points and conic weights data.
|
|
|
|
*/
|
|
|
|
std::tuple<SkPoint*, SkScalar*> growForVerbsInPath(const SkPathRef& path);
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
/**
|
|
|
|
* Private, non-const-ptr version of the public function verbsMemBegin().
|
|
|
|
*/
|
2019-09-05 18:14:38 +00:00
|
|
|
uint8_t* verbsBeginWritable() { return fVerbs.begin(); }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2013-10-23 14:44:08 +00:00
|
|
|
/**
|
|
|
|
* Called the first time someone calls CreateEmpty to actually create the singleton.
|
|
|
|
*/
|
2014-10-13 20:17:56 +00:00
|
|
|
friend SkPathRef* sk_create_empty_pathref();
|
2013-10-23 14:44:08 +00:00
|
|
|
|
2016-05-27 16:17:04 +00:00
|
|
|
void setIsOval(bool isOval, bool isCCW, unsigned start) {
|
|
|
|
fIsOval = isOval;
|
|
|
|
fRRectOrOvalIsCCW = isCCW;
|
2018-03-20 08:38:31 +00:00
|
|
|
fRRectOrOvalStartIdx = SkToU8(start);
|
2016-05-27 16:17:04 +00:00
|
|
|
}
|
2013-12-03 16:43:54 +00:00
|
|
|
|
2016-05-27 16:17:04 +00:00
|
|
|
void setIsRRect(bool isRRect, bool isCCW, unsigned start) {
|
|
|
|
fIsRRect = isRRect;
|
|
|
|
fRRectOrOvalIsCCW = isCCW;
|
2018-03-20 08:38:31 +00:00
|
|
|
fRRectOrOvalStartIdx = SkToU8(start);
|
2016-05-27 16:17:04 +00:00
|
|
|
}
|
2015-11-19 22:47:43 +00:00
|
|
|
|
|
|
|
// called only by the editor. Note that this is not a const function.
|
2019-09-05 18:14:38 +00:00
|
|
|
SkPoint* getWritablePoints() {
|
2013-12-16 07:01:40 +00:00
|
|
|
SkDEBUGCODE(this->validate();)
|
2013-12-13 19:36:25 +00:00
|
|
|
fIsOval = false;
|
2015-11-19 22:47:43 +00:00
|
|
|
fIsRRect = false;
|
2019-09-05 18:14:38 +00:00
|
|
|
return fPoints.begin();
|
2015-11-19 22:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SkPoint* getPoints() const {
|
|
|
|
SkDEBUGCODE(this->validate();)
|
2019-09-05 18:14:38 +00:00
|
|
|
return fPoints.begin();
|
2013-12-13 19:36:25 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 17:01:58 +00:00
|
|
|
void callGenIDChangeListeners();
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
enum {
|
|
|
|
kMinSize = 256,
|
|
|
|
};
|
|
|
|
|
2014-12-01 14:59:54 +00:00
|
|
|
mutable SkRect fBounds;
|
2013-09-26 12:18:23 +00:00
|
|
|
|
2019-09-05 18:14:38 +00:00
|
|
|
SkTDArray<SkPoint> fPoints;
|
|
|
|
SkTDArray<uint8_t> fVerbs;
|
2013-05-31 15:17:50 +00:00
|
|
|
SkTDArray<SkScalar> fConicWeights;
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
enum {
|
|
|
|
kEmptyGenID = 1, // GenID reserved for path ref with zero points and zero verbs.
|
|
|
|
};
|
2013-10-30 18:57:55 +00:00
|
|
|
mutable uint32_t fGenerationID;
|
2018-12-04 16:16:08 +00:00
|
|
|
SkDEBUGCODE(std::atomic<int> fEditorsAttached;) // assert only one editor in use at any time.
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2020-03-02 21:59:40 +00:00
|
|
|
SkIDChangeListener::List fGenIDChangeListeners;
|
2015-08-04 17:01:58 +00:00
|
|
|
|
2015-11-19 22:47:43 +00:00
|
|
|
mutable uint8_t fBoundsIsDirty;
|
2018-06-12 20:30:29 +00:00
|
|
|
mutable bool fIsFinite; // only meaningful if bounds are valid
|
2015-11-19 22:47:43 +00:00
|
|
|
|
2018-06-12 20:30:29 +00:00
|
|
|
bool fIsOval;
|
|
|
|
bool fIsRRect;
|
2016-05-27 16:17:04 +00:00
|
|
|
// Both the circle and rrect special cases have a notion of direction and starting point
|
|
|
|
// The next two variables store that information for either.
|
2018-06-12 20:30:29 +00:00
|
|
|
bool fRRectOrOvalIsCCW;
|
2016-05-27 16:17:04 +00:00
|
|
|
uint8_t fRRectOrOvalStartIdx;
|
2015-11-19 22:47:43 +00:00
|
|
|
uint8_t fSegmentMask;
|
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
friend class PathRefTest_Private;
|
2015-11-19 22:47:43 +00:00
|
|
|
friend class ForceIsRRect_Private; // unit test isRRect
|
2018-09-11 18:01:42 +00:00
|
|
|
friend class SkPath;
|
2020-08-03 02:14:43 +00:00
|
|
|
friend class SkPathBuilder;
|
2018-12-01 19:07:49 +00:00
|
|
|
friend class SkPathPriv;
|
2012-10-03 13:46:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|