2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2005 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkRegion_DEFINED
|
|
|
|
#define SkRegion_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRect.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SkPath;
|
|
|
|
class SkRgnBuilder;
|
|
|
|
|
|
|
|
/** \class SkRegion
|
2018-08-10 17:11:06 +00:00
|
|
|
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.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API SkRegion {
|
2008-12-17 15:59:43 +00:00
|
|
|
typedef int32_t RunType;
|
2018-07-28 14:14:27 +00:00
|
|
|
public:
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Constructs an empty SkRegion. SkRegion is set to empty bounds
|
|
|
|
at (0, 0) with zero width and height.
|
|
|
|
|
|
|
|
@return empty SkRegion
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_empty_constructor
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
SkRegion();
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param region SkRegion to copy by value
|
|
|
|
@return copy of SkRegion
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_copy_const_SkRegion
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
SkRegion(const SkRegion& region);
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Constructs a rectangular SkRegion matching the bounds of rect.
|
|
|
|
|
|
|
|
@param rect bounds of constructed SkRegion
|
|
|
|
@return rectangular SkRegion
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_copy_const_SkIRect
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-08-07 13:09:38 +00:00
|
|
|
explicit SkRegion(const SkIRect& rect);
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Releases ownership of any shared data and deletes data if SkRegion is sole owner.
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_destructor
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
~SkRegion();
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param region SkRegion to copy by value
|
|
|
|
@return SkRegion to copy by value
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_copy_operator
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
SkRegion& operator=(const SkRegion& region);
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Compares SkRegion and other; returns true if they enclose exactly
|
|
|
|
the same area.
|
|
|
|
|
|
|
|
@param other SkRegion to compare
|
|
|
|
@return true if SkRegion pair are equivalent
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_equal1_operator
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2012-01-25 21:53:53 +00:00
|
|
|
bool operator==(const SkRegion& other) const;
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Compares SkRegion and other; returns true if they do not enclose the same area.
|
|
|
|
|
|
|
|
@param other SkRegion to compare
|
|
|
|
@return true if SkRegion pair are not equivalent
|
|
|
|
*/
|
2012-01-25 21:53:53 +00:00
|
|
|
bool operator!=(const SkRegion& other) const {
|
|
|
|
return !(*this == other);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param src SkRegion to copy
|
|
|
|
@return copy of src
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
bool set(const SkRegion& src) {
|
|
|
|
*this = src;
|
|
|
|
return !this->isEmpty();
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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().
|
|
|
|
|
|
|
|
@param other operator=(const SkRegion& region) set
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_swap
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
void swap(SkRegion& other);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@return true if bounds has no width or height
|
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
bool isEmpty() const { return fRunHead == emptyRunHeadPtr(); }
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns true if SkRegion is one SkIRect with positive dimensions.
|
|
|
|
|
|
|
|
@return true if SkRegion contains one SkIRect
|
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
bool isRect() const { return fRunHead == kRectRunHeadPtr; }
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns true if SkRegion is described by more than one rectangle.
|
|
|
|
|
|
|
|
@return true if SkRegion contains more than one SkIRect
|
|
|
|
*/
|
2011-03-18 14:44:42 +00:00
|
|
|
bool isComplex() const { return !this->isEmpty() && !this->isRect(); }
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns minimum and maximum axes values of SkIRect array.
|
|
|
|
Returns (0, 0, 0, 0) if SkRegion is empty.
|
|
|
|
|
|
|
|
@return combined bounds of all SkIRect elements
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
const SkIRect& getBounds() const { return fBounds; }
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@return relative complexity
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_computeRegionComplexity
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2013-07-17 21:39:28 +00:00
|
|
|
int computeRegionComplexity() const;
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Appends outline of SkRegion to path.
|
|
|
|
Returns true if SkRegion is not empty; otherwise, returns false, and leaves path
|
|
|
|
unmodified.
|
|
|
|
|
|
|
|
@param path SkPath to append to
|
|
|
|
@return true if path changed
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_getBoundaryPath
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
bool getBoundaryPath(SkPath* path) const;
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Constructs an empty SkRegion. SkRegion is set to empty bounds
|
|
|
|
at (0, 0) with zero width and height. Always returns false.
|
|
|
|
|
|
|
|
@return false
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_setEmpty
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2011-03-18 14:44:42 +00:00
|
|
|
bool setEmpty();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Constructs a rectangular SkRegion matching the bounds of rect.
|
|
|
|
If rect is empty, constructs empty and returns false.
|
|
|
|
|
|
|
|
@param rect bounds of constructed SkRegion
|
|
|
|
@return true if rect is not empty
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_setRect
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
bool setRect(const SkIRect& rect);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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().
|
|
|
|
|
|
|
|
@param rects array of SkIRect
|
|
|
|
@param count array size
|
|
|
|
@return true if constructed SkRegion is not empty
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_setRects
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2010-07-13 18:35:14 +00:00
|
|
|
bool setRects(const SkIRect rects[], int count);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param region SkRegion to copy by value
|
|
|
|
@return SkRegion to copy by value
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_setRegion
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
bool setRegion(const SkRegion& region);
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param path SkPath providing outline
|
|
|
|
@param clip SkRegion containing path
|
|
|
|
@return true if constructed SkRegion is not empty
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_setPath
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
bool setPath(const SkPath& path, const SkRegion& clip);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns true if SkRegion intersects rect.
|
|
|
|
Returns false if either rect or SkRegion is empty, or do not intersect.
|
|
|
|
|
|
|
|
@param rect SkIRect to intersect
|
|
|
|
@return true if rect and SkRegion have area in common
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_intersects
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
bool intersects(const SkIRect& rect) const;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns true if SkRegion intersects other.
|
|
|
|
Returns false if either other or SkRegion is empty, or do not intersect.
|
|
|
|
|
|
|
|
@param other SkRegion to intersect
|
|
|
|
@return true if other and SkRegion have area in common
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_intersects_2
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
bool intersects(const SkRegion& other) const;
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns true if SkIPoint (x, y) is inside SkRegion.
|
|
|
|
Returns false if SkRegion is empty.
|
|
|
|
|
|
|
|
@param x test SkIPoint x-coordinate
|
|
|
|
@param y test SkIPoint y-coordinate
|
|
|
|
@return true if (x, y) is inside SkRegion
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_contains
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2011-03-18 14:44:42 +00:00
|
|
|
bool contains(int32_t x, int32_t y) const;
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns true if other is completely inside SkRegion.
|
|
|
|
Returns false if SkRegion or other is empty.
|
|
|
|
|
|
|
|
@param other SkIRect to contain
|
|
|
|
@return true if other is inside SkRegion
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_contains_2
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
bool contains(const SkIRect& other) const;
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns true if other is completely inside SkRegion.
|
|
|
|
Returns false if SkRegion or other is empty.
|
|
|
|
|
|
|
|
@param other SkRegion to contain
|
|
|
|
@return true if other is inside SkRegion
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_contains_3
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
bool contains(const SkRegion& other) const;
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns true if SkRegion is a single rectangle and contains r.
|
|
|
|
May return false even though SkRegion contains r.
|
|
|
|
|
|
|
|
@param r SkIRect to contain
|
|
|
|
@return true quickly if r points are equal or inside
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
bool quickContains(const SkIRect& r) const {
|
2019-08-24 23:39:13 +00:00
|
|
|
SkASSERT(this->isEmpty() == fBounds.isEmpty()); // valid region
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
return r.fLeft < r.fRight && r.fTop < r.fBottom &&
|
|
|
|
fRunHead == kRectRunHeadPtr && // this->isRect()
|
|
|
|
/* fBounds.contains(left, top, right, bottom); */
|
|
|
|
fBounds.fLeft <= r.fLeft && fBounds.fTop <= r.fTop &&
|
|
|
|
fBounds.fRight >= r.fRight && fBounds.fBottom >= r.fBottom;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param rect SkIRect to intersect
|
|
|
|
@return true if rect does not intersect
|
|
|
|
*/
|
2011-03-18 14:44:42 +00:00
|
|
|
bool quickReject(const SkIRect& rect) const {
|
2008-12-17 15:59:43 +00:00
|
|
|
return this->isEmpty() || rect.isEmpty() ||
|
|
|
|
!SkIRect::Intersects(fBounds, rect);
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param rgn SkRegion to intersect
|
|
|
|
@return true if rgn does not intersect
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
bool quickReject(const SkRegion& rgn) const {
|
|
|
|
return this->isEmpty() || rgn.isEmpty() ||
|
|
|
|
!SkIRect::Intersects(fBounds, rgn.fBounds);
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Offsets SkRegion by ivector (dx, dy). Has no effect if SkRegion is empty.
|
|
|
|
|
|
|
|
@param dx x-axis offset
|
|
|
|
@param dy y-axis offset
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void translate(int dx, int dy) { this->translate(dx, dy, this); }
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param dx x-axis offset
|
|
|
|
@param dy y-axis offset
|
|
|
|
@param dst translated result
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_translate_2
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void translate(int dx, int dy, SkRegion* dst) const;
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** \enum SkRegion::Op
|
|
|
|
The logical operations that can be performed when combining two SkRegion.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
enum Op {
|
2018-08-10 17:11:06 +00:00
|
|
|
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 = kReplace_Op, //!< last operator
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2014-06-09 14:59:06 +00:00
|
|
|
static const int kOpCnt = kLastOp + 1;
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Replaces SkRegion with the result of SkRegion op rect.
|
|
|
|
Returns true if replaced SkRegion is not empty.
|
|
|
|
|
|
|
|
@param rect SkIRect operand
|
|
|
|
@return false if result is empty
|
|
|
|
*/
|
2016-06-30 14:47:34 +00:00
|
|
|
bool op(const SkIRect& rect, Op op) {
|
|
|
|
if (this->isRect() && kIntersect_Op == op) {
|
|
|
|
if (!fBounds.intersect(rect)) {
|
|
|
|
return this->setEmpty();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->op(*this, rect, op);
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Replaces SkRegion with the result of SkRegion op rgn.
|
|
|
|
Returns true if replaced SkRegion is not empty.
|
|
|
|
|
|
|
|
@param rgn SkRegion operand
|
|
|
|
@return false if result is empty
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
bool op(const SkRegion& rgn, Op op) { return this->op(*this, rgn, op); }
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Replaces SkRegion with the result of rect op rgn.
|
|
|
|
Returns true if replaced SkRegion is not empty.
|
|
|
|
|
|
|
|
@param rect SkIRect operand
|
|
|
|
@param rgn SkRegion operand
|
|
|
|
@return false if result is empty
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_op_4
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-08-07 13:09:38 +00:00
|
|
|
bool op(const SkIRect& rect, const SkRegion& rgn, Op op);
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Replaces SkRegion with the result of rgn op rect.
|
|
|
|
Returns true if replaced SkRegion is not empty.
|
|
|
|
|
|
|
|
@param rgn SkRegion operand
|
|
|
|
@param rect SkIRect operand
|
|
|
|
@return false if result is empty
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_op_5
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-08-07 13:09:38 +00:00
|
|
|
bool op(const SkRegion& rgn, const SkIRect& rect, Op op);
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Replaces SkRegion with the result of rgna op rgnb.
|
|
|
|
Returns true if replaced SkRegion is not empty.
|
|
|
|
|
|
|
|
@param rgna SkRegion operand
|
|
|
|
@param rgnb SkRegion operand
|
|
|
|
@return false if result is empty
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_op_6
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
bool op(const SkRegion& rgna, const SkRegion& rgnb, Op op);
|
|
|
|
|
2018-11-15 20:54:59 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
2018-11-15 13:25:12 +00:00
|
|
|
/** Private. Android framework only.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
@return string representation of SkRegion
|
|
|
|
*/
|
2011-03-14 20:30:14 +00:00
|
|
|
char* toString();
|
|
|
|
#endif
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** \class SkRegion::Iterator
|
|
|
|
Returns sequence of rectangles, sorted along y-axis, then x-axis, that make
|
|
|
|
up SkRegion.
|
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API Iterator {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
/** Initializes SkRegion::Iterator with an empty SkRegion. done() on SkRegion::Iterator
|
|
|
|
returns true.
|
2018-08-10 17:11:06 +00:00
|
|
|
Call reset() to initialized SkRegion::Iterator at a later time.
|
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
@return empty SkRegion iterator
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2017-08-28 14:34:05 +00:00
|
|
|
Iterator() : fRgn(nullptr), fDone(true) {}
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Sets SkRegion::Iterator to return elements of SkIRect array in region.
|
|
|
|
|
|
|
|
@param region SkRegion to iterate
|
|
|
|
@return SkRegion iterator
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_Iterator_copy_const_SkRegion
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
Iterator(const SkRegion& region);
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** SkPoint SkRegion::Iterator to start of SkRegion.
|
|
|
|
Returns true if SkRegion was set; otherwise, returns false.
|
|
|
|
|
|
|
|
@return true if SkRegion was set
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_Iterator_rewind
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
bool rewind();
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Resets iterator, using the new SkRegion.
|
|
|
|
|
|
|
|
@param region SkRegion to iterate
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_Iterator_reset
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
void reset(const SkRegion& region);
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Returns true if SkRegion::Iterator is pointing to final SkIRect in SkRegion.
|
|
|
|
|
|
|
|
@return true if data parsing is complete
|
|
|
|
*/
|
2011-03-03 13:54:13 +00:00
|
|
|
bool done() const { return fDone; }
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Advances SkRegion::Iterator to next SkIRect in SkRegion if it is not done.
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_Iterator_next
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void next();
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Returns SkIRect element in SkRegion. Does not return predictable results if SkRegion
|
|
|
|
is empty.
|
|
|
|
|
|
|
|
@return part of SkRegion as SkIRect
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
const SkIRect& rect() const { return fRect; }
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Returns SkRegion if set; otherwise, returns nullptr.
|
|
|
|
|
|
|
|
@return iterated SkRegion
|
|
|
|
*/
|
2010-12-20 18:26:13 +00:00
|
|
|
const SkRegion* rgn() const { return fRgn; }
|
2011-03-18 14:44:42 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
const SkRegion* fRgn;
|
2018-07-28 14:14:27 +00:00
|
|
|
const SkRegion::RunType* fRuns;
|
2018-08-28 14:51:06 +00:00
|
|
|
SkIRect fRect = {0, 0, 0, 0};
|
2008-12-17 15:59:43 +00:00
|
|
|
bool fDone;
|
|
|
|
};
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** \class SkRegion::Cliperator
|
|
|
|
Returns the sequence of rectangles, sorted along y-axis, then x-axis, that make
|
|
|
|
up SkRegion intersected with the specified clip rectangle.
|
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API Cliperator {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Sets SkRegion::Cliperator to return elements of SkIRect array in SkRegion within clip.
|
|
|
|
|
|
|
|
@param region SkRegion to iterate
|
|
|
|
@param clip bounds of iteration
|
|
|
|
@return SkRegion iterator
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_Cliperator_const_SkRegion_const_SkIRect
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
Cliperator(const SkRegion& region, const SkIRect& clip);
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Returns true if SkRegion::Cliperator is pointing to final SkIRect in SkRegion.
|
|
|
|
|
|
|
|
@return true if data parsing is complete
|
|
|
|
*/
|
2011-03-18 14:44:42 +00:00
|
|
|
bool done() { return fDone; }
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Advances iterator to next SkIRect in SkRegion contained by clip.
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_Cliperator_next
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2011-03-18 14:44:42 +00:00
|
|
|
void next();
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
/** Returns SkIRect element in SkRegion, intersected with clip passed to
|
|
|
|
SkRegion::Cliperator constructor. Does not return predictable results if SkRegion
|
2018-08-10 17:11:06 +00:00
|
|
|
is empty.
|
|
|
|
|
|
|
|
@return part of SkRegion inside clip as SkIRect
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
const SkIRect& rect() const { return fRect; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Iterator fIter;
|
|
|
|
SkIRect fClip;
|
2018-08-28 14:51:06 +00:00
|
|
|
SkIRect fRect = {0, 0, 0, 0};
|
2008-12-17 15:59:43 +00:00
|
|
|
bool fDone;
|
|
|
|
};
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** \class SkRegion::Spanerator
|
|
|
|
Returns the line segment ends within SkRegion that intersect a horizontal line.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
class Spanerator {
|
|
|
|
public:
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Sets SkRegion::Spanerator to return line segments in SkRegion on scan line.
|
|
|
|
|
|
|
|
@param region SkRegion to iterate
|
|
|
|
@param y horizontal line to intersect
|
|
|
|
@param left bounds of iteration
|
|
|
|
@param right bounds of iteration
|
|
|
|
@return SkRegion iterator
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_Spanerator_const_SkRegion_int_int_int
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-07-28 14:14:27 +00:00
|
|
|
Spanerator(const SkRegion& region, int y, int left, int right);
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Advances iterator to next span intersecting SkRegion within line segment provided
|
|
|
|
in constructor. Returns true if interval was found.
|
|
|
|
|
|
|
|
@param left pointer to span start; may be nullptr
|
|
|
|
@param right pointer to span end; may be nullptr
|
|
|
|
@return true if interval was found
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_Spanerator_next
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2011-03-18 14:44:42 +00:00
|
|
|
bool next(int* left, int* right);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const SkRegion::RunType* fRuns;
|
|
|
|
int fLeft, fRight;
|
|
|
|
bool fDone;
|
|
|
|
};
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Writes SkRegion to buffer, and returns number of bytes written.
|
|
|
|
If buffer is nullptr, returns number number of bytes that would be written.
|
|
|
|
|
|
|
|
@param buffer storage for binary data
|
|
|
|
@return size of SkRegion
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_writeToMemory
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2013-11-05 15:46:56 +00:00
|
|
|
size_t writeToMemory(void* buffer) const;
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Constructs SkRegion from buffer of size length. Returns bytes read.
|
|
|
|
Returned value will be multiple of four or zero if length was too small.
|
|
|
|
|
|
|
|
@param buffer storage for binary data
|
|
|
|
@param length size of buffer
|
|
|
|
@return bytes read
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Region_readFromMemory
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2013-11-05 15:46:56 +00:00
|
|
|
size_t readFromMemory(const void* buffer, size_t length);
|
2011-03-23 13:51:55 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2018-04-26 12:32:37 +00:00
|
|
|
static constexpr int kOpCount = kReplace_Op + 1;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2018-04-26 12:32:37 +00:00
|
|
|
// T
|
|
|
|
// [B N L R S]
|
|
|
|
// S
|
|
|
|
static constexpr int kRectRegionRuns = 7;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
struct RunHead;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-07-28 14:14:27 +00:00
|
|
|
static RunHead* emptyRunHeadPtr() { return (SkRegion::RunHead*) -1; }
|
|
|
|
static constexpr RunHead* kRectRunHeadPtr = nullptr;
|
|
|
|
|
2012-05-01 14:43:22 +00:00
|
|
|
// allocate space for count runs
|
2012-05-02 18:07:33 +00:00
|
|
|
void allocateRuns(int count);
|
2012-05-01 14:43:22 +00:00
|
|
|
void allocateRuns(int count, int ySpanCount, int intervalCount);
|
|
|
|
void allocateRuns(const RunHead& src);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2018-07-28 14:14:27 +00:00
|
|
|
SkDEBUGCODE(void dump() const;)
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkIRect fBounds;
|
|
|
|
RunHead* fRunHead;
|
|
|
|
|
2012-05-02 18:07:33 +00:00
|
|
|
void freeRuns();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-02 18:07:33 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-05-01 14:43:22 +00:00
|
|
|
const RunType* getRuns(RunType tmpStorage[], int* intervals) const;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-02 18:07:33 +00:00
|
|
|
// This is called with runs[] that do not yet have their interval-count
|
|
|
|
// field set on each scanline. That is computed as part of this call
|
|
|
|
// (inside ComputeRunBounds).
|
|
|
|
bool setRuns(RunType runs[], int count);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
int count_runtype_values(int* itop, int* ibot) const;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-02-16 17:42:24 +00:00
|
|
|
bool isValid() const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
static void BuildRectRuns(const SkIRect& bounds,
|
|
|
|
RunType runs[kRectRegionRuns]);
|
2012-05-02 18:07:33 +00:00
|
|
|
|
|
|
|
// If the runs define a simple rect, return true and set bounds to that
|
|
|
|
// rect. If not, return false and ignore bounds.
|
|
|
|
static bool RunsAreARect(const SkRegion::RunType runs[], int count,
|
|
|
|
SkIRect* bounds);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-04-30 13:29:02 +00:00
|
|
|
/**
|
|
|
|
* If the last arg is null, just return if the result is non-empty,
|
|
|
|
* else store the result in the last arg.
|
|
|
|
*/
|
|
|
|
static bool Oper(const SkRegion&, const SkRegion&, SkRegion::Op, SkRegion*);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
friend struct RunHead;
|
|
|
|
friend class Iterator;
|
|
|
|
friend class Spanerator;
|
2018-02-27 20:44:36 +00:00
|
|
|
friend class SkRegionPriv;
|
2008-12-17 15:59:43 +00:00
|
|
|
friend class SkRgnBuilder;
|
|
|
|
friend class SkFlatRegion;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|