Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkPathRef Class Referencefinal

Holds the path verbs and points. More...

#include <SkPathRef.h>

Inheritance diagram for SkPathRef:
SkNVRefCnt< SkPathRef >

Classes

class  Editor
 
struct  GenIDChangeListener
 
class  Iter
 

Public Member Functions

bool isFinite () const
 Returns true if all of the points in this path are finite, meaning there are no infinities and no NaNs.
 
uint32_t getSegmentMasks () const
 Returns a mask, where each bit corresponding to a SegmentMask is set if the path contains 1 or more segments of that type. More...
 
bool isOval (SkRect *rect, bool *isCCW, unsigned *start) const
 Returns true if the path is an oval. More...
 
bool isRRect (SkRRect *rrect, bool *isCCW, unsigned *start) const
 
bool hasComputedBounds () const
 
const SkRectgetBounds () const
 Returns the bounds of the path's points. More...
 
SkRRect getRRect () const
 
int countPoints () const
 
int countVerbs () const
 
int countWeights () const
 
const uint8_t * verbs () const
 Returns a pointer one beyond the first logical verb (last verb in memory order).
 
const uint8_t * verbsMemBegin () const
 Returns a const pointer to the first verb in memory (which is the last logical verb).
 
const SkPointpoints () const
 Returns a const pointer to the first point.
 
const SkPointpointsEnd () const
 Shortcut for this->points() + this->countPoints()
 
const SkScalar * conicWeights () const
 
const SkScalar * conicWeightsEnd () const
 
uint8_t atVerb (int index) const
 Convenience methods for getting to a verb or point by index.
 
const SkPointatPoint (int index) const
 
bool operator== (const SkPathRef &ref) const
 
void writeToBuffer (SkWBuffer *buffer) const
 Writes the path points and verbs to a buffer.
 
uint32_t writeSize () const
 Gets the number of bytes that would be written in writeBuffer()
 
void interpolate (const SkPathRef &ending, SkScalar weight, SkPathRef *out) const
 
uint32_t genID () const
 Gets an ID that uniquely identifies the contents of the path ref. More...
 
void addGenIDChangeListener (GenIDChangeListener *listener)
 
void validate () const
 
- Public Member Functions inherited from SkNVRefCnt< SkPathRef >
bool unique () const
 
void ref () const
 
void unref () const
 
void deref () const
 

Static Public Member Functions

static SkPathRefCreateEmpty ()
 Gets a path ref with no verbs or points.
 
static void CreateTransformedCopy (SkAutoTUnref< SkPathRef > *dst, const SkPathRef &src, const SkMatrix &matrix)
 Transforms a path ref by a matrix, allocating a new one only if necessary.
 
static SkPathRefCreateFromBuffer (SkRBuffer *buffer)
 
static void Rewind (SkAutoTUnref< SkPathRef > *pathRef)
 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. More...
 

Private Types

enum  SerializationOffsets {
  kRRectOrOvalStartIdx_SerializationShift = 28, kRRectOrOvalIsCCW_SerializationShift = 27, kIsRRect_SerializationShift = 26, kIsFinite_SerializationShift = 25,
  kIsOval_SerializationShift = 24, kSegmentMask_SerializationShift = 0
}
 
enum  { kMinSize = 256 }
 
enum  { kEmptyGenID = 1 }
 

Private Member Functions

void copy (const SkPathRef &ref, int additionalReserveVerbs, int additionalReservePoints)
 
void computeBounds () const
 
void setBounds (const SkRect &rect)
 
void incReserve (int additionalVerbs, int additionalPoints)
 Makes additional room but does not change the counts or change the genID.
 
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. More...
 
SkPointgrowForRepeatedVerb (intverb, int numVbs, SkScalar **weights)
 Increases the verb count by numVbs and point count by the required amount. More...
 
SkPointgrowForVerb (intverb, SkScalar weight)
 Increases the verb count 1, records the new verb, and creates room for the requisite number of additional points. More...
 
void makeSpace (size_t size)
 Ensures that the free space available in the path ref is >= size. More...
 
uint8_t * verbsMemWritable ()
 Private, non-const-ptr version of the public function verbsMemBegin().
 
size_t currSize () const
 Gets the total amount of space allocated for verbs, points, and reserve.
 
void setIsOval (bool isOval, bool isCCW, unsigned start)
 
void setIsRRect (bool isRRect, bool isCCW, unsigned start)
 
SkPointgetPoints ()
 
const SkPointgetPoints () const
 
void callGenIDChangeListeners ()
 

Static Private Member Functions

static bool ComputePtBounds (SkRect *bounds, const SkPathRef &ref)
 

Private Attributes

SkRect fBounds
 
SkPointfPoints
 
uint8_t * fVerbs
 
int fVerbCnt
 
int fPointCnt
 
size_t fFreeSpace
 
SkTDArray< SkScalar > fConicWeights
 
uint32_t fGenerationID
 
int32_t fEditorsAttached
 
SkTDArray< GenIDChangeListener * > fGenIDChangeListeners
 
uint8_t fBoundsIsDirty
 
SkBool8 fIsFinite
 
SkBool8 fIsOval
 
SkBool8 fIsRRect
 
SkBool8 fRRectOrOvalIsCCW
 
uint8_t fRRectOrOvalStartIdx
 
uint8_t fSegmentMask
 

Friends

class PathRefTest_Private
 
class ForceIsRRect_Private
 
SkPathRefsk_create_empty_pathref ()
 Called the first time someone calls CreateEmpty to actually create the singleton.
 

Detailed Description

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 copy-on-write if the SkPathRef is shared by multiple SkPaths. The caller passes the Editor's constructor a SkAutoTUnref, which may be updated to point to a new SkPathRef after the editor's constructor returns.

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).

Member Function Documentation

uint32_t SkPathRef::genID ( ) const

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.

const SkRect& SkPathRef::getBounds ( ) const
inline

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.

uint32_t SkPathRef::getSegmentMasks ( ) const
inline

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).

SkPoint* SkPathRef::growForRepeatedVerb ( intverb  ,
int  numVbs,
SkScalar **  weights 
)
private

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 verb. If 'verb' is kConic_Verb, 'weights' will return a pointer to the uninitialized conic weights.

SkPoint* SkPathRef::growForVerb ( intverb  ,
SkScalar  weight 
)
private

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.

bool SkPathRef::isOval ( SkRect rect,
bool *  isCCW,
unsigned *  start 
) const
inline

Returns true if the path is an oval.

Parameters
rectreturns the bounding rect of this oval. It's a circle if the height and width are the same.
isCCWis the oval CCW (or CW if false).
startindicates where the contour starts on the oval (see SkPath::addOval for intepretation of the index).
Returns
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.
void SkPathRef::makeSpace ( size_t  size)
inlineprivate

Ensures that the free space available in the path ref is >= size.

The verb and point counts are not changed.

void SkPathRef::resetToSize ( int  verbCount,
int  pointCount,
int  conicCount,
int  reserveVerbs = 0,
int  reservePoints = 0 
)
inlineprivate

Resets the path ref with verbCount verbs and pointCount points, all uninitialized.

Also allocates space for reserveVerb additional verbs and reservePoints additional points.

static void SkPathRef::Rewind ( SkAutoTUnref< SkPathRef > *  pathRef)
static

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.


The documentation for this class was generated from the following file: