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
|
|
|
|
|
2016-04-08 13:58:51 +00:00
|
|
|
#include "../private/SkAtomics.h"
|
2016-02-18 16:53:33 +00:00
|
|
|
#include "../private/SkTDArray.h"
|
2013-09-26 12:18:23 +00:00
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkPoint.h"
|
2015-11-19 22:47:43 +00:00
|
|
|
#include "SkRRect.h"
|
2013-09-26 12:18:23 +00:00
|
|
|
#include "SkRect.h"
|
2012-10-03 13:46:20 +00:00
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include <stddef.h> // ptrdiff_t
|
|
|
|
|
2013-09-26 12:18:23 +00:00
|
|
|
class SkRBuffer;
|
|
|
|
class SkWBuffer;
|
|
|
|
|
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
|
|
|
|
2016-08-09 19:20:04 +00:00
|
|
|
class SK_API SkPathRef final : public SkNVRefCnt<SkPathRef> {
|
2012-10-03 13:46:20 +00:00
|
|
|
public:
|
|
|
|
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
|
|
|
|
2013-06-27 18:39:39 +00:00
|
|
|
~Editor() { SkDEBUGCODE(sk_atomic_dec(&fPathRef->fEditorsAttached);) }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the array of points.
|
|
|
|
*/
|
2013-12-13 19:36:25 +00:00
|
|
|
SkPoint* points() { return fPathRef->getPoints(); }
|
|
|
|
const SkPoint* points() const { return fPathRef->points(); }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the ith point. Shortcut for this->points() + i
|
|
|
|
*/
|
|
|
|
SkPoint* atPoint(int i) {
|
|
|
|
SkASSERT((unsigned) i < (unsigned) fPathRef->fPointCnt);
|
|
|
|
return this->points() + i;
|
2016-09-27 13:34:10 +00:00
|
|
|
}
|
2013-12-13 19:36:25 +00:00
|
|
|
const SkPoint* atPoint(int i) const {
|
|
|
|
SkASSERT((unsigned) i < (unsigned) fPathRef->fPointCnt);
|
|
|
|
return this->points() + i;
|
2016-09-27 13:34:10 +00:00
|
|
|
}
|
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,
|
|
|
|
SkScalar** weights = NULL) {
|
|
|
|
return fPathRef->growForRepeatedVerb(verb, numVbs, weights);
|
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.
|
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
2016-05-27 16:17:04 +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;
|
|
|
|
}
|
2015-11-19 22:47:43 +00:00
|
|
|
}
|
|
|
|
return SkToBool(fIsRRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-01-23 15:16:05 +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();
|
2013-10-02 16:42:21 +00:00
|
|
|
int countPoints() const { SkDEBUGCODE(this->validate();) return fPointCnt; }
|
|
|
|
int countVerbs() const { SkDEBUGCODE(this->validate();) return fVerbCnt; }
|
2013-12-12 23:03:51 +00:00
|
|
|
int countWeights() const { SkDEBUGCODE(this->validate();) return fConicWeights.count(); }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a pointer one beyond the first logical verb (last verb in memory order).
|
|
|
|
*/
|
2013-10-02 16:42:21 +00:00
|
|
|
const uint8_t* verbs() const { SkDEBUGCODE(this->validate();) return fVerbs; }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a const pointer to the first verb in memory (which is the last logical verb).
|
|
|
|
*/
|
|
|
|
const uint8_t* verbsMemBegin() const { return this->verbs() - fVerbCnt; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a const pointer to the first point.
|
|
|
|
*/
|
2013-10-02 16:42:21 +00:00
|
|
|
const SkPoint* points() const { SkDEBUGCODE(this->validate();) return fPoints; }
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for this->points() + this->countPoints()
|
|
|
|
*/
|
|
|
|
const SkPoint* pointsEnd() const { return this->points() + this->countPoints(); }
|
|
|
|
|
2013-10-02 16:42:21 +00:00
|
|
|
const SkScalar* conicWeights() const { SkDEBUGCODE(this->validate();) return fConicWeights.begin(); }
|
|
|
|
const SkScalar* conicWeightsEnd() const { SkDEBUGCODE(this->validate();) 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.
|
|
|
|
*/
|
2013-12-12 23:03:51 +00:00
|
|
|
uint8_t atVerb(int index) const {
|
2012-10-03 13:46:20 +00:00
|
|
|
SkASSERT((unsigned) index < (unsigned) fVerbCnt);
|
|
|
|
return this->verbs()[~index];
|
|
|
|
}
|
|
|
|
const SkPoint& atPoint(int index) const {
|
|
|
|
SkASSERT((unsigned) index < (unsigned) fPointCnt);
|
|
|
|
return this->points()[index];
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2015-08-04 17:01:58 +00:00
|
|
|
struct GenIDChangeListener {
|
|
|
|
virtual ~GenIDChangeListener() {}
|
|
|
|
virtual void onChange() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void addGenIDChangeListener(GenIDChangeListener* listener);
|
|
|
|
|
2014-12-15 20:28:33 +00:00
|
|
|
SkDEBUGCODE(void validate() const;)
|
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
private:
|
2013-09-26 12:18:23 +00:00
|
|
|
enum SerializationOffsets {
|
2016-05-27 16:17:04 +00:00
|
|
|
kRRectOrOvalStartIdx_SerializationShift = 28, // requires 3 bits
|
|
|
|
kRRectOrOvalIsCCW_SerializationShift = 27, // requires 1 bit
|
|
|
|
kIsRRect_SerializationShift = 26, // requires 1 bit
|
|
|
|
kIsFinite_SerializationShift = 25, // requires 1 bit
|
|
|
|
kIsOval_SerializationShift = 24, // requires 1 bit
|
|
|
|
kSegmentMask_SerializationShift = 0 // requires 4 bits
|
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
|
|
|
fPointCnt = 0;
|
|
|
|
fVerbCnt = 0;
|
|
|
|
fVerbs = NULL;
|
|
|
|
fPoints = NULL;
|
|
|
|
fFreeSpace = 0;
|
|
|
|
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;
|
2013-06-27 18:39:39 +00:00
|
|
|
SkDEBUGCODE(fEditorsAttached = 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();)
|
2012-10-03 13:46:20 +00:00
|
|
|
size_t space = additionalVerbs * sizeof(uint8_t) + additionalPoints * sizeof (SkPoint);
|
|
|
|
this->makeSpace(space);
|
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();)
|
|
|
|
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
|
|
|
|
2013-10-02 17:49:50 +00:00
|
|
|
size_t newSize = sizeof(uint8_t) * verbCount + sizeof(SkPoint) * pointCount;
|
|
|
|
size_t newReserve = sizeof(uint8_t) * reserveVerbs + sizeof(SkPoint) * reservePoints;
|
|
|
|
size_t minSize = newSize + newReserve;
|
|
|
|
|
|
|
|
ptrdiff_t sizeDelta = this->currSize() - minSize;
|
|
|
|
|
|
|
|
if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) {
|
|
|
|
sk_free(fPoints);
|
|
|
|
fPoints = NULL;
|
|
|
|
fVerbs = NULL;
|
|
|
|
fFreeSpace = 0;
|
|
|
|
fVerbCnt = 0;
|
|
|
|
fPointCnt = 0;
|
|
|
|
this->makeSpace(minSize);
|
|
|
|
fVerbCnt = verbCount;
|
|
|
|
fPointCnt = pointCount;
|
|
|
|
fFreeSpace -= newSize;
|
|
|
|
} else {
|
|
|
|
fPointCnt = pointCount;
|
|
|
|
fVerbCnt = verbCount;
|
|
|
|
fFreeSpace = this->currSize() - minSize;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that the free space available in the path ref is >= size. The verb and point counts
|
|
|
|
* are not changed.
|
|
|
|
*/
|
2013-10-02 17:49:50 +00:00
|
|
|
void makeSpace(size_t size) {
|
|
|
|
SkDEBUGCODE(this->validate();)
|
|
|
|
ptrdiff_t growSize = size - fFreeSpace;
|
|
|
|
if (growSize <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size_t oldSize = this->currSize();
|
|
|
|
// round to next multiple of 8 bytes
|
|
|
|
growSize = (growSize + 7) & ~static_cast<size_t>(7);
|
|
|
|
// we always at least double the allocation
|
|
|
|
if (static_cast<size_t>(growSize) < oldSize) {
|
|
|
|
growSize = oldSize;
|
|
|
|
}
|
|
|
|
if (growSize < kMinSize) {
|
|
|
|
growSize = kMinSize;
|
|
|
|
}
|
|
|
|
size_t newSize = oldSize + growSize;
|
|
|
|
// Note that realloc could memcpy more than we need. It seems to be a win anyway. TODO:
|
|
|
|
// encapsulate this.
|
|
|
|
fPoints = reinterpret_cast<SkPoint*>(sk_realloc_throw(fPoints, newSize));
|
|
|
|
size_t oldVerbSize = fVerbCnt * sizeof(uint8_t);
|
|
|
|
void* newVerbsDst = reinterpret_cast<void*>(
|
|
|
|
reinterpret_cast<intptr_t>(fPoints) + newSize - oldVerbSize);
|
|
|
|
void* oldVerbsSrc = reinterpret_cast<void*>(
|
|
|
|
reinterpret_cast<intptr_t>(fPoints) + oldSize - oldVerbSize);
|
|
|
|
memmove(newVerbsDst, oldVerbsSrc, oldVerbSize);
|
|
|
|
fVerbs = reinterpret_cast<uint8_t*>(reinterpret_cast<intptr_t>(fPoints) + newSize);
|
|
|
|
fFreeSpace += growSize;
|
|
|
|
SkDEBUGCODE(this->validate();)
|
|
|
|
}
|
2012-10-03 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private, non-const-ptr version of the public function verbsMemBegin().
|
|
|
|
*/
|
|
|
|
uint8_t* verbsMemWritable() {
|
2013-10-02 16:42:21 +00:00
|
|
|
SkDEBUGCODE(this->validate();)
|
2012-10-03 13:46:20 +00:00
|
|
|
return fVerbs - fVerbCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the total amount of space allocated for verbs, points, and reserve.
|
|
|
|
*/
|
|
|
|
size_t currSize() const {
|
|
|
|
return reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(fPoints);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
fRRectOrOvalStartIdx = 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) {
|
|
|
|
fIsRRect = isRRect;
|
|
|
|
fRRectOrOvalIsCCW = isCCW;
|
|
|
|
fRRectOrOvalStartIdx = start;
|
|
|
|
}
|
2015-11-19 22:47:43 +00:00
|
|
|
|
|
|
|
// called only by the editor. Note that this is not a const function.
|
2013-12-16 07:01:40 +00:00
|
|
|
SkPoint* getPoints() {
|
|
|
|
SkDEBUGCODE(this->validate();)
|
2013-12-13 19:36:25 +00:00
|
|
|
fIsOval = false;
|
2015-11-19 22:47:43 +00:00
|
|
|
fIsRRect = false;
|
|
|
|
return fPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkPoint* getPoints() const {
|
|
|
|
SkDEBUGCODE(this->validate();)
|
2013-12-16 07:01:40 +00:00
|
|
|
return fPoints;
|
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
|
|
|
|
2012-10-03 13:46:20 +00:00
|
|
|
SkPoint* fPoints; // points to begining of the allocation
|
|
|
|
uint8_t* fVerbs; // points just past the end of the allocation (verbs grow backwards)
|
|
|
|
int fVerbCnt;
|
|
|
|
int fPointCnt;
|
|
|
|
size_t fFreeSpace; // redundant but saves computation
|
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;
|
2013-06-27 18:39:39 +00:00
|
|
|
SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time.
|
2012-10-03 13:46:20 +00:00
|
|
|
|
2015-08-04 17:01:58 +00:00
|
|
|
SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owned
|
|
|
|
|
2015-11-19 22:47:43 +00:00
|
|
|
mutable uint8_t fBoundsIsDirty;
|
|
|
|
mutable SkBool8 fIsFinite; // only meaningful if bounds are valid
|
|
|
|
|
|
|
|
SkBool8 fIsOval;
|
|
|
|
SkBool8 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.
|
|
|
|
SkBool8 fRRectOrOvalIsCCW;
|
|
|
|
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
|
2012-10-03 13:46:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|