9 #ifndef SkPathRef_DEFINED
10 #define SkPathRef_DEFINED
12 #include "../private/SkAtomics.h"
13 #include "../private/SkTDArray.h"
44 int incReserveVerbs = 0,
45 int incReservePoints = 0);
47 ~
Editor() { SkDEBUGCODE(sk_atomic_dec(&fPathRef->fEditorsAttached);) }
53 const SkPoint* points()
const {
return fPathRef->points(); }
59 SkASSERT((
unsigned) i < (
unsigned) fPathRef->fPointCnt);
60 return this->points() + i;
62 const SkPoint* atPoint(
int i)
const {
63 SkASSERT((
unsigned) i < (
unsigned) fPathRef->fPointCnt);
64 return this->points() + i;
73 SkDEBUGCODE(fPathRef->validate();)
74 return fPathRef->growForVerb(verb, weight);
86 SkScalar** weights = NULL) {
87 return fPathRef->growForRepeatedVerb(verb, numVbs, weights);
94 void resetToSize(
int newVerbCnt,
int newPointCnt,
int newConicCount) {
95 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount);
103 void setIsOval(
bool isOval,
bool isCCW,
unsigned start) {
104 fPathRef->setIsOval(isOval, isCCW, start);
107 void setIsRRect(
bool isRRect,
bool isCCW,
unsigned start) {
108 fPathRef->setIsRRect(isRRect, isCCW, start);
111 void setBounds(
const SkRect& rect) { fPathRef->setBounds(rect); }
132 uint8_t peek()
const;
134 SkScalar conicWeight()
const {
return *fConicWeights; }
138 const uint8_t* fVerbs;
139 const uint8_t* fVerbStop;
140 const SkScalar* fConicWeights;
154 if (fBoundsIsDirty) {
155 this->computeBounds();
183 *rect = this->getBounds();
186 *isCCW =
SkToBool(fRRectOrOvalIsCCW);
189 *start = fRRectOrOvalStartIdx;
196 bool isRRect(
SkRRect* rrect,
bool* isCCW,
unsigned* start)
const {
199 *rrect = this->getRRect();
202 *isCCW =
SkToBool(fRRectOrOvalIsCCW);
205 *start = fRRectOrOvalStartIdx;
212 bool hasComputedBounds()
const {
213 return !fBoundsIsDirty;
222 if (fBoundsIsDirty) {
223 this->computeBounds();
237 static SkPathRef* CreateFromBuffer(SkRBuffer* buffer);
247 int countPoints()
const { SkDEBUGCODE(this->validate();)
return fPointCnt; }
248 int countVerbs()
const { SkDEBUGCODE(this->validate();)
return fVerbCnt; }
249 int countWeights()
const { SkDEBUGCODE(this->validate();)
return fConicWeights.count(); }
254 const uint8_t*
verbs()
const { SkDEBUGCODE(this->validate();)
return fVerbs; }
264 const SkPoint*
points()
const { SkDEBUGCODE(this->validate();)
return fPoints; }
271 const SkScalar* conicWeights()
const { SkDEBUGCODE(this->validate();)
return fConicWeights.begin(); }
272 const SkScalar* conicWeightsEnd()
const { SkDEBUGCODE(this->validate();)
return fConicWeights.end(); }
278 SkASSERT((
unsigned) index < (
unsigned) fVerbCnt);
279 return this->verbs()[~index];
281 const SkPoint& atPoint(
int index)
const {
282 SkASSERT((
unsigned) index < (
unsigned) fPointCnt);
283 return this->points()[index];
286 bool operator== (
const SkPathRef& ref)
const;
291 void writeToBuffer(SkWBuffer* buffer)
const;
296 uint32_t writeSize()
const;
305 uint32_t genID()
const;
309 virtual void onChange() = 0;
314 SkDEBUGCODE(
void validate()
const;)
317 enum SerializationOffsets {
318 kRRectOrOvalStartIdx_SerializationShift = 28,
319 kRRectOrOvalIsCCW_SerializationShift = 27,
320 kIsRRect_SerializationShift = 26,
321 kIsFinite_SerializationShift = 25,
322 kIsOval_SerializationShift = 24,
323 kSegmentMask_SerializationShift = 0
327 fBoundsIsDirty =
true;
333 fGenerationID = kEmptyGenID;
338 fRRectOrOvalIsCCW =
false;
339 fRRectOrOvalStartIdx = 0xAC;
340 SkDEBUGCODE(fEditorsAttached = 0;)
341 SkDEBUGCODE(this->validate();)
344 void copy(
const SkPathRef& ref,
int additionalReserveVerbs,
int additionalReservePoints);
352 void computeBounds()
const {
353 SkDEBUGCODE(this->validate();)
356 SkASSERT(fBoundsIsDirty);
358 fIsFinite = ComputePtBounds(&fBounds, *
this);
359 fBoundsIsDirty =
false;
362 void setBounds(
const SkRect& rect) {
363 SkASSERT(rect.fLeft <= rect.fRight && rect.fTop <= rect.fBottom);
365 fBoundsIsDirty =
false;
371 SkDEBUGCODE(this->validate();)
372 size_t space = additionalVerbs *
sizeof(uint8_t) + additionalPoints *
sizeof (
SkPoint);
373 this->makeSpace(space);
374 SkDEBUGCODE(this->validate();)
380 int reserveVerbs = 0,
int reservePoints = 0) {
381 SkDEBUGCODE(this->validate();)
382 fBoundsIsDirty =
true;
389 size_t newSize =
sizeof(uint8_t) * verbCount +
sizeof(
SkPoint) * pointCount;
390 size_t newReserve =
sizeof(uint8_t) * reserveVerbs +
sizeof(
SkPoint) * reservePoints;
391 size_t minSize = newSize + newReserve;
393 ptrdiff_t sizeDelta = this->currSize() - minSize;
395 if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) {
402 this->makeSpace(minSize);
403 fVerbCnt = verbCount;
404 fPointCnt = pointCount;
405 fFreeSpace -= newSize;
407 fPointCnt = pointCount;
408 fVerbCnt = verbCount;
409 fFreeSpace = this->currSize() - minSize;
411 fConicWeights.setCount(conicCount);
412 SkDEBUGCODE(this->validate();)
421 SkPoint* growForRepeatedVerb(
int verb,
int numVbs, SkScalar** weights);
428 SkPoint* growForVerb(
int verb, SkScalar weight);
435 SkDEBUGCODE(this->validate();)
436 ptrdiff_t growSize = size - fFreeSpace;
440 size_t oldSize = this->currSize();
442 growSize = (growSize + 7) & ~static_cast<size_t>(7);
444 if (static_cast<size_t>(growSize) < oldSize) {
447 if (growSize < kMinSize) {
450 size_t newSize = oldSize + growSize;
454 size_t oldVerbSize = fVerbCnt *
sizeof(uint8_t);
455 void* newVerbsDst =
reinterpret_cast<void*
>(
456 reinterpret_cast<intptr_t
>(fPoints) + newSize - oldVerbSize);
457 void* oldVerbsSrc =
reinterpret_cast<void*
>(
458 reinterpret_cast<intptr_t
>(fPoints) + oldSize - oldVerbSize);
459 memmove(newVerbsDst, oldVerbsSrc, oldVerbSize);
460 fVerbs =
reinterpret_cast<uint8_t*
>(
reinterpret_cast<intptr_t
>(fPoints) + newSize);
461 fFreeSpace += growSize;
462 SkDEBUGCODE(this->validate();)
469 SkDEBUGCODE(this->validate();)
470 return fVerbs - fVerbCnt;
477 return reinterpret_cast<intptr_t
>(fVerbs) - reinterpret_cast<intptr_t>(fPoints);
483 friend SkPathRef* sk_create_empty_pathref();
485 void setIsOval(
bool isOval,
bool isCCW,
unsigned start) {
487 fRRectOrOvalIsCCW = isCCW;
488 fRRectOrOvalStartIdx = start;
491 void setIsRRect(
bool isRRect,
bool isCCW,
unsigned start) {
493 fRRectOrOvalIsCCW = isCCW;
494 fRRectOrOvalStartIdx = start;
499 SkDEBUGCODE(this->validate();)
505 const SkPoint* getPoints()
const {
506 SkDEBUGCODE(this->validate();)
510 void callGenIDChangeListeners();
523 SkTDArray<SkScalar> fConicWeights;
528 mutable uint32_t fGenerationID;
529 SkDEBUGCODE(int32_t fEditorsAttached;)
531 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners;
533 mutable uint8_t fBoundsIsDirty;
541 uint8_t fRRectOrOvalStartIdx;
542 uint8_t fSegmentMask;
544 friend class PathRefTest_Private;
545 friend class ForceIsRRect_Private;
The SkRRect class represents a rounded rect with a potentially different radii for each corner...
Definition: SkRRect.h:48
Definition: SkPathRef.h:41
uint8_t atVerb(int index) const
Convenience methods for getting to a verb or point by index.
Definition: SkPathRef.h:277
const SkRect & getBounds() const
Returns the bounds of the path's points.
Definition: SkPathRef.h:221
bool isFinite() const
Returns true if all of the points in this path are finite, meaning there are no infinities and no NaN...
Definition: SkPathRef.h:153
void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount)
Resets the path ref to a new verb and point count.
Definition: SkPathRef.h:94
SkPoint * atPoint(int i)
Gets the ith point.
Definition: SkPathRef.h:58
Definition: SkPoint.h:156
bool isOval(SkRect *rect, bool *isCCW, unsigned *start) const
Returns true if the path is an oval.
Definition: SkPathRef.h:180
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
uint8_t SkBool8
Meant to be a small version of bool, for storage purposes.
Definition: SkTypes.h:268
bool isFinite() const
Returns true iff all values in the rect are finite.
Definition: SkRect.h:465
Holds the path verbs and points.
Definition: SkPathRef.h:39
SK_API void sk_free(void *)
Free memory returned by sk_malloc().
SkPoint * points()
Returns the array of points.
Definition: SkPathRef.h:52
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:287
void incReserve(int additionalVerbs, int additionalPoints)
Makes additional room but does not change the counts or change the genID.
Definition: SkPathRef.h:370
Definition: SkPathRef.h:307
void makeSpace(size_t size)
Ensures that the free space available in the path ref is >= size.
Definition: SkPathRef.h:434
uint32_t getSegmentMasks() const
Returns a mask, where each bit corresponding to a SegmentMask is set if the path contains 1 or more s...
Definition: SkPathRef.h:165
const uint8_t * verbsMemBegin() const
Returns a const pointer to the first verb in memory (which is the last logical verb).
Definition: SkPathRef.h:259
SkPoint * growForRepeatedVerb(intverb, int numVbs, SkScalar **weights=NULL)
Allocates space for multiple instances of a particular verb and the requisite points & weights...
Definition: SkPathRef.h:84
SkPoint * growForVerb(intverb, SkScalar weight=0)
Adds the verb and allocates space for the number of points indicated by the verb. ...
Definition: SkPathRef.h:72
Definition: SkPathRef.h:117
SkPathRef * pathRef()
Gets the path ref that is wrapped in the Editor.
Definition: SkPathRef.h:101
const SkPoint * points() const
Returns a const pointer to the first point.
Definition: SkPathRef.h:264
const SkPoint * pointsEnd() const
Shortcut for this->points() + this->countPoints()
Definition: SkPathRef.h:269
SK_API void * sk_realloc_throw(void *buffer, size_t size)
Same as standard realloc(), but this one never returns null on failure.
Definition: SkRefCnt.h:221
bool setBoundsCheck(const SkPoint pts[], int count)
Compute the bounds of the array of points, and set this rect to that bounds and return true...
const uint8_t * verbs() const
Returns a pointer one beyond the first logical verb (last verb in memory order).
Definition: SkPathRef.h:254
uint8_t * verbsMemWritable()
Private, non-const-ptr version of the public function verbsMemBegin().
Definition: SkPathRef.h:468
size_t currSize() const
Gets the total amount of space allocated for verbs, points, and reserve.
Definition: SkPathRef.h:476
void resetToSize(int verbCount, int pointCount, int conicCount, int reserveVerbs=0, int reservePoints=0)
Resets the path ref with verbCount verbs and pointCount points, all uninitialized.
Definition: SkPathRef.h:379