Skia
2D Graphics Library
SkRegion Class Reference

#include <SkRegion.h>

Classes

class  Cliperator
 
class  Iterator
 
class  Spanerator
 

Public Types

enum  Op {
  kDifference_Op, kIntersect_Op, kUnion_Op, kXOR_Op,
  kReverseDifference_Op, kReplace_Op, kLastOp = kReplace_Op
}
 

Public Member Functions

 SkRegion ()
 Constructs an empty SkRegion. More...
 
 SkRegion (const SkRegion &region)
 Constructs a copy of an existing region. More...
 
 SkRegion (const SkIRect &rect)
 Constructs a rectangular SkRegion matching the bounds of rect. More...
 
 ~SkRegion ()
 Releases ownership of any shared data and deletes data if SkRegion is sole owner. More...
 
SkRegionoperator= (const SkRegion &region)
 Constructs a copy of an existing region. More...
 
bool operator== (const SkRegion &other) const
 Compares SkRegion and other; returns true if they enclose exactly the same area. More...
 
bool operator!= (const SkRegion &other) const
 Compares SkRegion and other; returns true if they do not enclose the same area. More...
 
bool set (const SkRegion &src)
 Sets SkRegion to src, and returns true if src bounds is not empty. More...
 
void swap (SkRegion &other)
 Exchanges SkIRect array of SkRegion and other. More...
 
bool isEmpty () const
 Returns true if SkRegion is empty. More...
 
bool isRect () const
 Returns true if SkRegion is one SkIRect with positive dimensions. More...
 
bool isComplex () const
 Returns true if SkRegion is described by more than one rectangle. More...
 
const SkIRectgetBounds () const
 Returns minimum and maximum axes values of SkIRect array. More...
 
int computeRegionComplexity () const
 Returns a value that increases with the number of elements in SkRegion. More...
 
bool getBoundaryPath (SkPath *path) const
 Appends outline of SkRegion to path. More...
 
bool setEmpty ()
 Constructs an empty SkRegion. More...
 
bool setRect (const SkIRect &rect)
 Constructs a rectangular SkRegion matching the bounds of rect. More...
 
bool setRects (const SkIRect rects[], int count)
 Constructs SkRegion as the union of SkIRect in rects array. More...
 
bool setRegion (const SkRegion &region)
 Constructs a copy of an existing region. More...
 
bool setPath (const SkPath &path, const SkRegion &clip)
 Constructs SkRegion to match outline of path within clip. More...
 
bool intersects (const SkIRect &rect) const
 Returns true if SkRegion intersects rect. More...
 
bool intersects (const SkRegion &other) const
 Returns true if SkRegion intersects other. More...
 
bool contains (int32_t x, int32_t y) const
 Returns true if SkIPoint (x, y) is inside SkRegion. More...
 
bool contains (const SkIRect &other) const
 Returns true if other is completely inside SkRegion. More...
 
bool contains (const SkRegion &other) const
 Returns true if other is completely inside SkRegion. More...
 
bool quickContains (const SkIRect &r) const
 Returns true if SkRegion is a single rectangle and contains r. More...
 
bool quickReject (const SkIRect &rect) const
 Returns true if SkRegion does not intersect rect. More...
 
bool quickReject (const SkRegion &rgn) const
 Returns true if SkRegion does not intersect rgn. More...
 
void translate (int dx, int dy)
 Offsets SkRegion by ivector (dx, dy). More...
 
void translate (int dx, int dy, SkRegion *dst) const
 Offsets SkRegion by ivector (dx, dy), writing result to dst. More...
 
bool op (const SkIRect &rect, Op op)
 Replaces SkRegion with the result of SkRegion op rect. More...
 
bool op (const SkRegion &rgn, Op op)
 Replaces SkRegion with the result of SkRegion op rgn. More...
 
bool op (const SkIRect &rect, const SkRegion &rgn, Op op)
 Replaces SkRegion with the result of rect op rgn. More...
 
bool op (const SkRegion &rgn, const SkIRect &rect, Op op)
 Replaces SkRegion with the result of rgn op rect. More...
 
bool op (const SkRegion &rgna, const SkRegion &rgnb, Op op)
 Replaces SkRegion with the result of rgna op rgnb. More...
 
size_t writeToMemory (void *buffer) const
 Writes SkRegion to buffer, and returns number of bytes written. More...
 
size_t readFromMemory (const void *buffer, size_t length)
 Constructs SkRegion from buffer of size length. More...
 

Static Public Attributes

static const int kOpCnt = kLastOp + 1
 

Friends

struct RunHead
 
class Iterator
 
class Spanerator
 
class SkRegionPriv
 
class SkRgnBuilder
 
class SkFlatRegion
 

Detailed Description

SkRegion describes the set of pixels used to clip SkCanvas. SkRegion is compact, efficiently storing a single integer rectangle, or a run length encoded array of rectangles. SkRegion may reduce the current SkCanvas clip, or may be drawn as one or more integer rectangles. SkRegion iterator returns the scan lines or rectangles contained by it, optionally intersecting a bounding rectangle.

Member Enumeration Documentation

◆ Op

Enumerator
kDifference_Op 

target minus operand

kIntersect_Op 

target intersected with operand

kUnion_Op 

target unioned with operand

kXOR_Op 

target exclusive or with operand

kReverseDifference_Op 

operand minus target

kReplace_Op 

replace target with operand

kLastOp 

last operator

Constructor & Destructor Documentation

◆ SkRegion() [1/3]

SkRegion::SkRegion ( )

Constructs an empty SkRegion.

SkRegion is set to empty bounds at (0, 0) with zero width and height.

Returns
empty SkRegion

example: https://fiddle.skia.org/c/@Region_empty_constructor

◆ SkRegion() [2/3]

SkRegion::SkRegion ( const SkRegion region)

Constructs a copy of an existing region.

Copy constructor makes two regions identical by value. Internally, region and the returned result share pointer values. The underlying SkRect array is copied when modified.

Creating a SkRegion copy is very efficient and never allocates memory. SkRegion are always copied by value from the interface; the underlying shared pointers are not exposed.

Parameters
regionSkRegion to copy by value
Returns
copy of SkRegion

example: https://fiddle.skia.org/c/@Region_copy_const_SkRegion

◆ SkRegion() [3/3]

SkRegion::SkRegion ( const SkIRect rect)
explicit

Constructs a rectangular SkRegion matching the bounds of rect.

Parameters
rectbounds of constructed SkRegion
Returns
rectangular SkRegion

example: https://fiddle.skia.org/c/@Region_copy_const_SkIRect

◆ ~SkRegion()

SkRegion::~SkRegion ( )

Releases ownership of any shared data and deletes data if SkRegion is sole owner.

example: https://fiddle.skia.org/c/@Region_destructor

Member Function Documentation

◆ computeRegionComplexity()

int SkRegion::computeRegionComplexity ( ) const

Returns a value that increases with the number of elements in SkRegion.

Returns zero if SkRegion is empty. Returns one if SkRegion equals SkIRect; otherwise, returns value greater than one indicating that SkRegion is complex.

Call to compare SkRegion for relative complexity.

Returns
relative complexity

example: https://fiddle.skia.org/c/@Region_computeRegionComplexity

◆ contains() [1/3]

bool SkRegion::contains ( const SkIRect other) const

Returns true if other is completely inside SkRegion.

Returns false if SkRegion or other is empty.

Parameters
otherSkIRect to contain
Returns
true if other is inside SkRegion

example: https://fiddle.skia.org/c/@Region_contains_2

◆ contains() [2/3]

bool SkRegion::contains ( const SkRegion other) const

Returns true if other is completely inside SkRegion.

Returns false if SkRegion or other is empty.

Parameters
otherSkRegion to contain
Returns
true if other is inside SkRegion

example: https://fiddle.skia.org/c/@Region_contains_3

◆ contains() [3/3]

bool SkRegion::contains ( int32_t  x,
int32_t  y 
) const

Returns true if SkIPoint (x, y) is inside SkRegion.

Returns false if SkRegion is empty.

Parameters
xtest SkIPoint x-coordinate
ytest SkIPoint y-coordinate
Returns
true if (x, y) is inside SkRegion

example: https://fiddle.skia.org/c/@Region_contains

◆ getBoundaryPath()

bool SkRegion::getBoundaryPath ( SkPath path) const

Appends outline of SkRegion to path.

Returns true if SkRegion is not empty; otherwise, returns false, and leaves path unmodified.

Parameters
pathSkPath to append to
Returns
true if path changed

example: https://fiddle.skia.org/c/@Region_getBoundaryPath

◆ getBounds()

const SkIRect& SkRegion::getBounds ( ) const
inline

Returns minimum and maximum axes values of SkIRect array.

Returns (0, 0, 0, 0) if SkRegion is empty.

Returns
combined bounds of all SkIRect elements

◆ intersects() [1/2]

bool SkRegion::intersects ( const SkIRect rect) const

Returns true if SkRegion intersects rect.

Returns false if either rect or SkRegion is empty, or do not intersect.

Parameters
rectSkIRect to intersect
Returns
true if rect and SkRegion have area in common

example: https://fiddle.skia.org/c/@Region_intersects

◆ intersects() [2/2]

bool SkRegion::intersects ( const SkRegion other) const

Returns true if SkRegion intersects other.

Returns false if either other or SkRegion is empty, or do not intersect.

Parameters
otherSkRegion to intersect
Returns
true if other and SkRegion have area in common

example: https://fiddle.skia.org/c/@Region_intersects_2

◆ isComplex()

bool SkRegion::isComplex ( ) const
inline

Returns true if SkRegion is described by more than one rectangle.

Returns
true if SkRegion contains more than one SkIRect

◆ isEmpty()

bool SkRegion::isEmpty ( ) const
inline

Returns true if SkRegion is empty.

Empty SkRegion has bounds width or height less than or equal to zero. SkRegion() constructs empty SkRegion; setEmpty() and setRect() with dimensionless data make SkRegion empty.

Returns
true if bounds has no width or height

◆ isRect()

bool SkRegion::isRect ( ) const
inline

Returns true if SkRegion is one SkIRect with positive dimensions.

Returns
true if SkRegion contains one SkIRect

◆ op() [1/5]

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

Replaces SkRegion with the result of rect op rgn.

Returns true if replaced SkRegion is not empty.

Parameters
rectSkIRect operand
rgnSkRegion operand
Returns
false if result is empty

example: https://fiddle.skia.org/c/@Region_op_4

◆ op() [2/5]

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

Replaces SkRegion with the result of SkRegion op rect.

Returns true if replaced SkRegion is not empty.

Parameters
rectSkIRect operand
Returns
false if result is empty

◆ op() [3/5]

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

Replaces SkRegion with the result of rgn op rect.

Returns true if replaced SkRegion is not empty.

Parameters
rgnSkRegion operand
rectSkIRect operand
Returns
false if result is empty

example: https://fiddle.skia.org/c/@Region_op_5

◆ op() [4/5]

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

Replaces SkRegion with the result of SkRegion op rgn.

Returns true if replaced SkRegion is not empty.

Parameters
rgnSkRegion operand
Returns
false if result is empty

◆ op() [5/5]

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

Replaces SkRegion with the result of rgna op rgnb.

Returns true if replaced SkRegion is not empty.

Parameters
rgnaSkRegion operand
rgnbSkRegion operand
Returns
false if result is empty

example: https://fiddle.skia.org/c/@Region_op_6

◆ operator!=()

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

Compares SkRegion and other; returns true if they do not enclose the same area.

Parameters
otherSkRegion to compare
Returns
true if SkRegion pair are not equivalent

◆ operator=()

SkRegion& SkRegion::operator= ( const SkRegion region)

Constructs a copy of an existing region.

Makes two regions identical by value. Internally, region and the returned result share pointer values. The underlying SkRect array is copied when modified.

Creating a SkRegion copy is very efficient and never allocates memory. SkRegion are always copied by value from the interface; the underlying shared pointers are not exposed.

Parameters
regionSkRegion to copy by value
Returns
SkRegion to copy by value

example: https://fiddle.skia.org/c/@Region_copy_operator

◆ operator==()

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

Compares SkRegion and other; returns true if they enclose exactly the same area.

Parameters
otherSkRegion to compare
Returns
true if SkRegion pair are equivalent

example: https://fiddle.skia.org/c/@Region_equal1_operator

◆ quickContains()

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

Returns true if SkRegion is a single rectangle and contains r.

May return false even though SkRegion contains r.

Parameters
rSkIRect to contain
Returns
true quickly if r points are equal or inside

◆ quickReject() [1/2]

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

Returns true if SkRegion does not intersect rect.

Returns true if rect is empty or SkRegion is empty. May return false even though SkRegion does not intersect rect.

Parameters
rectSkIRect to intersect
Returns
true if rect does not intersect

◆ quickReject() [2/2]

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

Returns true if SkRegion does not intersect rgn.

Returns true if rgn is empty or SkRegion is empty. May return false even though SkRegion does not intersect rgn.

Parameters
rgnSkRegion to intersect
Returns
true if rgn does not intersect

◆ readFromMemory()

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

Constructs SkRegion from buffer of size length.

Returns bytes read. Returned value will be multiple of four or zero if length was too small.

Parameters
bufferstorage for binary data
lengthsize of buffer
Returns
bytes read

example: https://fiddle.skia.org/c/@Region_readFromMemory

◆ set()

bool SkRegion::set ( const SkRegion src)
inline

Sets SkRegion to src, and returns true if src bounds is not empty.

This makes SkRegion and src identical by value. Internally, SkRegion and src share pointer values. The underlying SkRect array is copied when modified.

Creating a SkRegion copy is very efficient and never allocates memory. SkRegion are always copied by value from the interface; the underlying shared pointers are not exposed.

Parameters
srcSkRegion to copy
Returns
copy of src

◆ setEmpty()

bool SkRegion::setEmpty ( )

Constructs an empty SkRegion.

SkRegion is set to empty bounds at (0, 0) with zero width and height. Always returns false.

Returns
false

example: https://fiddle.skia.org/c/@Region_setEmpty

◆ setPath()

bool SkRegion::setPath ( const SkPath path,
const SkRegion clip 
)

Constructs SkRegion to match outline of path within clip.

Returns false if constructed SkRegion is empty.

Constructed SkRegion draws the same pixels as path through clip when anti-aliasing is disabled.

Parameters
pathSkPath providing outline
clipSkRegion containing path
Returns
true if constructed SkRegion is not empty

example: https://fiddle.skia.org/c/@Region_setPath

◆ setRect()

bool SkRegion::setRect ( const SkIRect rect)

Constructs a rectangular SkRegion matching the bounds of rect.

If rect is empty, constructs empty and returns false.

Parameters
rectbounds of constructed SkRegion
Returns
true if rect is not empty

example: https://fiddle.skia.org/c/@Region_setRect

◆ setRects()

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

Constructs SkRegion as the union of SkIRect in rects array.

If count is zero, constructs empty SkRegion. Returns false if constructed SkRegion is empty.

May be faster than repeated calls to op().

Parameters
rectsarray of SkIRect
countarray size
Returns
true if constructed SkRegion is not empty

example: https://fiddle.skia.org/c/@Region_setRects

◆ setRegion()

bool SkRegion::setRegion ( const SkRegion region)

Constructs a copy of an existing region.

Makes two regions identical by value. Internally, region and the returned result share pointer values. The underlying SkRect array is copied when modified.

Creating a SkRegion copy is very efficient and never allocates memory. SkRegion are always copied by value from the interface; the underlying shared pointers are not exposed.

Parameters
regionSkRegion to copy by value
Returns
SkRegion to copy by value

example: https://fiddle.skia.org/c/@Region_setRegion

◆ swap()

void SkRegion::swap ( SkRegion other)

Exchanges SkIRect array of SkRegion and other.

swap() internally exchanges pointers, so it is lightweight and does not allocate memory.

swap() usage has largely been replaced by operator=(const SkRegion& region). SkPath do not copy their content on assignment until they are written to, making assignment as efficient as swap().

Parameters
otheroperator=(const SkRegion& region) set

example: https://fiddle.skia.org/c/@Region_swap

◆ translate() [1/2]

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

Offsets SkRegion by ivector (dx, dy).

Has no effect if SkRegion is empty.

Parameters
dxx-axis offset
dyy-axis offset

◆ translate() [2/2]

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

Offsets SkRegion by ivector (dx, dy), writing result to dst.

SkRegion may be passed as dst parameter, translating SkRegion in place. Has no effect if dst is nullptr. If SkRegion is empty, sets dst to empty.

Parameters
dxx-axis offset
dyy-axis offset
dsttranslated result

example: https://fiddle.skia.org/c/@Region_translate_2

◆ writeToMemory()

size_t SkRegion::writeToMemory ( void *  buffer) const

Writes SkRegion to buffer, and returns number of bytes written.

If buffer is nullptr, returns number number of bytes that would be written.

Parameters
bufferstorage for binary data
Returns
size of SkRegion

example: https://fiddle.skia.org/c/@Region_writeToMemory

Friends And Related Function Documentation

◆ Iterator

friend class Iterator
friend

◆ RunHead

friend struct RunHead
friend

◆ SkFlatRegion

friend class SkFlatRegion
friend

◆ SkRegionPriv

friend class SkRegionPriv
friend

◆ SkRgnBuilder

friend class SkRgnBuilder
friend

◆ Spanerator

friend class Spanerator
friend

Member Data Documentation

◆ kOpCnt

const int SkRegion::kOpCnt = kLastOp + 1
static

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