/* * Copyright 2005 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/
/** \class SkRegion 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.
*/ class SK_API SkRegion { typedef int32_t RunType; public:
/** Constructs an empty SkRegion. SkRegion is set to empty bounds at (0, 0) with zero width and height.
/** 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
/** 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
/** 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
*/ booloperator!=(const SkRegion& other) const { return !(*this == other);
}
/** 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.
/** 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
/** 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
*/ bool isEmpty() const { return fRunHead == emptyRunHeadPtr(); }
/** Returns true if SkRegion is one SkIRect with positive dimensions.
@return true if SkRegion contains one SkIRect
*/ bool isRect() const { return fRunHead == kRectRunHeadPtr; }
/** Returns true if SkRegion is described by more than one rectangle.
@return true if SkRegion contains more than one SkIRect
*/ bool isComplex() const { return !this->isEmpty() && !this->isRect(); }
/** 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
*/ const SkIRect& getBounds() const { return fBounds; }
/** 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.
/** 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
/** 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
/** 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
*/ bool quickContains(const SkIRect& r) const {
SkASSERT(this->isEmpty() == fBounds.isEmpty()); // valid region
/** 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
*/ bool quickReject(const SkIRect& rect) const { return this->isEmpty() || rect.isEmpty() ||
!SkIRect::Intersects(fBounds, rect);
}
/** 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
*/ bool quickReject(const SkRegion& rgn) const { return this->isEmpty() || rgn.isEmpty() ||
!SkIRect::Intersects(fBounds, rgn.fBounds);
}
/** Offsets SkRegion by ivector (dx, dy). Has no effect if SkRegion is empty.
@param dx x-axis offset @param dy y-axis offset
*/ void translate(int dx, int dy) { this->translate(dx, dy, this); }
/** 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
/** \enum SkRegion::Op The logical operations that can be performed when combining two SkRegion.
*/ enum Op {
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
};
staticconstint kOpCnt = kLastOp + 1;
/** 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
*/ bool op(const SkIRect& rect, Op op) { if (this->isRect() && kIntersect_Op == op) { if (!fBounds.intersect(rect)) { return this->setEmpty();
} returntrue;
} return this->op(*this, rect, op);
}
/** 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
*/ bool op(const SkRegion& rgn, Op op) { return this->op(*this, rgn, op); }
/** 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
@return string representation of SkRegion
*/ char* toString(); #endif
/** \class SkRegion::Iterator Returns sequence of rectangles, sorted along y-axis, then x-axis, that make up SkRegion.
*/ class SK_API Iterator { public:
/** Initializes SkRegion::Iterator with an empty SkRegion. done() on SkRegion::Iterator returns true. Call reset() to initialized SkRegion::Iterator at a later time.
/** \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.
*/ class SK_API Cliperator { public:
/** 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
/** Returns SkIRect element in SkRegion, intersected with clip passed to SkRegion::Cliperator constructor. Does not return predictable results if SkRegion is empty.
@return part of SkRegion inside clip as SkIRect
*/ const SkIRect& rect() const { return fRect; }
/** \class SkRegion::Spanerator Returns the line segment ends within SkRegion that intersect a horizontal line.
*/ class Spanerator { public:
/** 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
// allocate space for count runs void allocateRuns(int count); void allocateRuns(int count, int ySpanCount, int intervalCount); void allocateRuns(const RunHead& src);
/** * 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.
*/ const RunType* getRuns(RunType tmpStorage[], int* intervals) const;
// 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);
int count_runtype_values(int* itop, int* ibot) const;
// If the runs define a simple rect, return true and set bounds to that // rect. If not, return false and ignore bounds. staticbool RunsAreARect(const SkRegion::RunType runs[], int count,
SkIRect* bounds);
/** * If the last arg is null, just return if the result is non-empty, * else store the result in the last arg.
*/ staticbool Oper(const SkRegion&, const SkRegion&, SkRegion::Op, SkRegion*);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.