Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkRegion Class Reference

The SkRegion class encapsulates the geometric region used to specify clipping areas for drawing. More...

#include <SkRegion.h>

Classes

class  Cliperator
 Returns the sequence of rectangles, sorted in Y and X, that make up this region intersected with the specified clip rectangle. More...
 
class  Iterator
 Returns the sequence of rectangles, sorted in Y and X, that make up this region. More...
 
class  Spanerator
 Returns the sequence of runs that make up this region for the specified Y scanline, clipped to the specified left and right X values. More...
 

Public Types

enum  { kRunTypeSentinel = 0x7FFFFFFF }
 
enum  Op {
  kDifference_Op, kIntersect_Op, kUnion_Op, kXOR_Op,
  kReverseDifference_Op, kReplace_Op, kLastOp = kReplace_Op
}
 The logical operations that can be performed when combining two regions. More...
 
typedef int32_t RunType
 

Public Member Functions

 SkRegion (const SkRegion &)
 
 SkRegion (const SkIRect &)
 
SkRegionoperator= (const SkRegion &)
 
bool operator== (const SkRegion &other) const
 Return true if the two regions are equal. More...
 
bool operator!= (const SkRegion &other) const
 Return true if the two regions are not equal.
 
bool set (const SkRegion &src)
 Replace this region with the specified region, and return true if the resulting region is non-empty.
 
void swap (SkRegion &)
 Swap the contents of this and the specified region. More...
 
bool isEmpty () const
 Return true if this region is empty.
 
bool isRect () const
 Return true if this region is a single, non-empty rectangle.
 
bool isComplex () const
 Return true if this region consists of more than 1 rectangular area.
 
const SkIRectgetBounds () const
 Return the bounds of this region. More...
 
int computeRegionComplexity () const
 Returns a value that grows approximately linearly with the number of intervals comprised in the region. More...
 
bool getBoundaryPath (SkPath *path) const
 Returns true if the region is non-empty, and if so, appends the boundary(s) of the region to the specified path. More...
 
bool setEmpty ()
 Set the region to be empty, and return false, since the resulting region is empty.
 
bool setRect (const SkIRect &)
 If rect is non-empty, set this region to that rectangle and return true, otherwise set this region to empty and return false.
 
bool setRect (int32_t left, int32_t top, int32_t right, int32_t bottom)
 If left < right and top < bottom, set this region to that rectangle and return true, otherwise set this region to empty and return false.
 
bool setRects (const SkIRect rects[], int count)
 Set this region to the union of an array of rects. More...
 
bool setRegion (const SkRegion &)
 Set this region to the specified region, and return true if it is non-empty.
 
bool setPath (const SkPath &, const SkRegion &clip)
 Set this region to the area described by the path, clipped. More...
 
bool intersects (const SkIRect &) const
 Returns true if the specified rectangle has a non-empty intersection with this region.
 
bool intersects (const SkRegion &) const
 Returns true if the specified region has a non-empty intersection with this region.
 
bool contains (int32_t x, int32_t y) const
 Return true if the specified x,y coordinate is inside the region.
 
bool contains (const SkIRect &) const
 Return true if the specified rectangle is completely inside the region. More...
 
bool contains (const SkRegion &) const
 Return true if the specified region is completely inside the region. More...
 
bool quickContains (const SkIRect &r) const
 Return true if this region is a single rectangle (not complex) and the specified rectangle is contained by this region. More...
 
bool quickContains (int32_t left, int32_t top, int32_t right, int32_t bottom) const
 Return true if this region is a single rectangle (not complex) and the specified rectangle is contained by this region. More...
 
bool quickReject (const SkIRect &rect) const
 Return true if this region is empty, or if the specified rectangle does not intersect the region. More...
 
bool quickReject (const SkRegion &rgn) const
 Return true if this region, or rgn, is empty, or if their bounds do not intersect. More...
 
void translate (int dx, int dy)
 Translate the region by the specified (dx, dy) amount. More...
 
void translate (int dx, int dy, SkRegion *dst) const
 Translate the region by the specified (dx, dy) amount, writing the resulting region into dst. More...
 
bool op (const SkIRect &rect, Op op)
 Set this region to the result of applying the Op to this region and the specified rectangle: this = (this op rect). More...
 
bool op (int left, int top, int right, int bottom, Op op)
 Set this region to the result of applying the Op to this region and the specified rectangle: this = (this op rect). More...
 
bool op (const SkRegion &rgn, Op op)
 Set this region to the result of applying the Op to this region and the specified region: this = (this op rgn). More...
 
bool op (const SkIRect &rect, const SkRegion &rgn, Op)
 Set this region to the result of applying the Op to the specified rectangle and region: this = (rect op rgn). More...
 
bool op (const SkRegion &rgn, const SkIRect &rect, Op)
 Set this region to the result of applying the Op to the specified region and rectangle: this = (rgn op rect). More...
 
bool op (const SkRegion &rgna, const SkRegion &rgnb, Op op)
 Set this region to the result of applying the Op to the specified regions: this = (rgna op rgnb). More...
 
size_t writeToMemory (void *buffer) const
 Write the region to the buffer, and return the number of bytes written. More...
 
size_t readFromMemory (const void *buffer, size_t length)
 Initializes the region from the buffer. More...
 
void dump () const
 
void validate () const
 
bool debugSetRuns (const RunType runs[], int count)
 

Static Public Member Functions

static const SkRegionGetEmptyRegion ()
 Returns a reference to a global empty region. More...
 
static void UnitTest ()
 

Static Public Attributes

static const int kOpCnt = kLastOp + 1
 

Private Types

enum  { kOpCount = kReplace_Op + 1 }
 
enum  { kRectRegionRuns = 7 }
 

Private Member Functions

void allocateRuns (int count)
 
void allocateRuns (int count, int ySpanCount, int intervalCount)
 
void allocateRuns (const RunHead &src)
 
void freeRuns ()
 
const RunType * getRuns (RunType tmpStorage[], int *intervals) const
 Return the runs from this region, consing up fake runs if the region is empty or a rect. More...
 
bool setRuns (RunType runs[], int count)
 
int count_runtype_values (int *itop, int *ibot) const
 
bool isValid () const
 

Static Private Member Functions

static void BuildRectRuns (const SkIRect &bounds, RunType runs[kRectRegionRuns])
 
static bool RunsAreARect (const SkRegion::RunType runs[], int count, SkIRect *bounds)
 
static bool Oper (const SkRegion &, const SkRegion &, SkRegion::Op, SkRegion *)
 If the last arg is null, just return if the result is non-empty, else store the result in the last arg.
 

Private Attributes

SkIRect fBounds
 
RunHead * fRunHead
 

Friends

class android::Region
 
struct RunHead
 
class Iterator
 
class Spanerator
 
class SkRgnBuilder
 
class SkFlatRegion
 

Detailed Description

The SkRegion class encapsulates the geometric region used to specify clipping areas for drawing.

Member Enumeration Documentation

The logical operations that can be performed when combining two regions.

Enumerator
kDifference_Op 

subtract the op region from the first region

kIntersect_Op 

intersect the two regions

kUnion_Op 

union (inclusive-or) the two regions

kXOR_Op 

exclusive-or the two regions

kReverseDifference_Op 

subtract the first region from the op region

kReplace_Op 

replace the dst region with the op region

Member Function Documentation

int SkRegion::computeRegionComplexity ( ) const

Returns a value that grows approximately linearly with the number of intervals comprised in the region.

Empty region will return 0, Rect will return 1, Complex will return a value > 1.

Use this to compare two regions, where the larger count likely indicates a more complex region.

bool SkRegion::contains ( const SkIRect ) const

Return true if the specified rectangle is completely inside the region.

This works for simple (rectangular) and complex regions, and always returns the correct result. Note: if either this region or the rectangle is empty, contains() returns false.

bool SkRegion::contains ( const SkRegion ) const

Return true if the specified region is completely inside the region.

This works for simple (rectangular) and complex regions, and always returns the correct result. Note: if either region is empty, contains() returns false.

bool SkRegion::getBoundaryPath ( SkPath path) const

Returns true if the region is non-empty, and if so, appends the boundary(s) of the region to the specified path.

If the region is empty, returns false, and path is left unmodified.

const SkIRect& SkRegion::getBounds ( ) const
inline

Return the bounds of this region.

If the region is empty, returns an empty rectangle.

static const SkRegion& SkRegion::GetEmptyRegion ( )
static

Returns a reference to a global empty region.

Just a convenience for callers that need a const empty region.

const RunType* SkRegion::getRuns ( RunType  tmpStorage[],
int *  intervals 
) const
private

Return the runs from this region, consing up fake runs if the region is empty or a rect.

In those 2 cases, we use tmpStorage to hold the run data.

bool SkRegion::op ( const SkIRect rect,
Op  op 
)
inline

Set this region to the result of applying the Op to this region and the specified rectangle: this = (this op rect).

Return true if the resulting region is non-empty.

bool SkRegion::op ( int  left,
int  top,
int  right,
int  bottom,
Op  op 
)
inline

Set this region to the result of applying the Op to this region and the specified rectangle: this = (this op rect).

Return true if the resulting region is non-empty.

bool SkRegion::op ( const SkRegion rgn,
Op  op 
)
inline

Set this region to the result of applying the Op to this region and the specified region: this = (this op rgn).

Return true if the resulting region is non-empty.

bool SkRegion::op ( const SkIRect rect,
const SkRegion rgn,
Op   
)

Set this region to the result of applying the Op to the specified rectangle and region: this = (rect op rgn).

Return true if the resulting region is non-empty.

bool SkRegion::op ( const SkRegion rgn,
const SkIRect rect,
Op   
)

Set this region to the result of applying the Op to the specified region and rectangle: this = (rgn op rect).

Return true if the resulting region is non-empty.

bool SkRegion::op ( const SkRegion rgna,
const SkRegion rgnb,
Op  op 
)

Set this region to the result of applying the Op to the specified regions: this = (rgna op rgnb).

Return true if the resulting region is non-empty.

bool SkRegion::operator== ( const SkRegion other) const

Return true if the two regions are equal.

i.e. The enclose exactly the same area.

bool SkRegion::quickContains ( const SkIRect r) const
inline

Return true if this region is a single rectangle (not complex) and the specified rectangle is contained by this region.

Returning false is not a guarantee that the rectangle is not contained by this region, but return true is a guarantee that the rectangle is contained by this region.

bool SkRegion::quickContains ( int32_t  left,
int32_t  top,
int32_t  right,
int32_t  bottom 
) const
inline

Return true if this region is a single rectangle (not complex) and the specified rectangle is contained by this region.

Returning false is not a guarantee that the rectangle is not contained by this region, but return true is a guarantee that the rectangle is contained by this region.

bool SkRegion::quickReject ( const SkIRect rect) const
inline

Return true if this region is empty, or if the specified rectangle does not intersect the region.

Returning false is not a guarantee that they intersect, but returning true is a guarantee that they do not.

bool SkRegion::quickReject ( const SkRegion rgn) const
inline

Return true if this region, or rgn, is empty, or if their bounds do not intersect.

Returning false is not a guarantee that they intersect, but returning true is a guarantee that they do not.

size_t SkRegion::readFromMemory ( const void *  buffer,
size_t  length 
)

Initializes the region from the buffer.

Parameters
bufferMemory to read from
lengthAmount of memory available in the buffer
Returns
number of bytes read (must be a multiple of 4) or 0 if there was not enough memory available
bool SkRegion::setPath ( const SkPath ,
const SkRegion clip 
)

Set this region to the area described by the path, clipped.

Return true if the resulting region is non-empty. This produces a region that is identical to the pixels that would be drawn by the path (with no antialiasing) with the specified clip.

bool SkRegion::setRects ( const SkIRect  rects[],
int  count 
)

Set this region to the union of an array of rects.

This is generally faster than calling region.op(rect, kUnion_Op) in a loop. If count is 0, then this region is set to the empty region.

Returns
true if the resulting region is non-empty
void SkRegion::swap ( SkRegion )

Swap the contents of this and the specified region.

This operation is gauarenteed to never fail.

void SkRegion::translate ( int  dx,
int  dy 
)
inline

Translate the region by the specified (dx, dy) amount.

void SkRegion::translate ( int  dx,
int  dy,
SkRegion dst 
) const

Translate the region by the specified (dx, dy) amount, writing the resulting region into dst.

Note: it is legal to pass this region as the dst parameter, effectively translating the region in place. If dst is null, nothing happens.

size_t SkRegion::writeToMemory ( void *  buffer) const

Write the region to the buffer, and return the number of bytes written.

If buffer is NULL, it still returns the number of bytes.


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