It is useful to know how many rects comprise a region,
since in some situations we can optimize code based on
the complexity of the region. For instance, if we use
SkRegion for tracking invalidation we might opt to use
the region bounds as invalidation instead of iterating
over each rect.
R=reed@google.com, tomhudson@chromium.org, caryclark@google.com, robertphillips@google.com
Author: vmpstr@chromium.org
Review URL: https://chromiumcodereview.appspot.com/
19366008
git-svn-id: http://skia.googlecode.com/svn/trunk@10129
2bbb7eff-a529-9590-31e7-
b0007b416f81
*/
const SkIRect& getBounds() const { return fBounds; }
+ /**
+ * 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.
+ */
+ int computeRegionComplexity() const;
+
/**
* Returns true if the region is non-empty, and if so, appends the
* boundary(s) of the region to the specified path.
SkTSwap<RunHead*>(fRunHead, other.fRunHead);
}
+int SkRegion::computeRegionComplexity() const {
+ if (this->isEmpty()) {
+ return 0;
+ } else if (this->isRect()) {
+ return 1;
+ }
+ return fRunHead->getIntervalCount();
+}
+
bool SkRegion::setEmpty() {
this->freeRuns();
fBounds.set(0, 0, 0, 0);