diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-17 21:39:28 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-17 21:39:28 +0000 |
commit | 5dd567c2a55c16c8bc2668902cdfce1734dfae8f (patch) | |
tree | b97bb6c3a6fce526e0a69eb82053e64c9b8b4668 | |
parent | a308883003e36cbff4d1c4c2d2e7fceb3eea95b1 (diff) |
Add getRectCount to SkRegtion
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
-rw-r--r-- | include/core/SkRegion.h | 10 | ||||
-rw-r--r-- | src/core/SkRegion.cpp | 9 |
2 files changed, 19 insertions, 0 deletions
diff --git a/include/core/SkRegion.h b/include/core/SkRegion.h index ab8f220a35..a088d54620 100644 --- a/include/core/SkRegion.h +++ b/include/core/SkRegion.h @@ -86,6 +86,16 @@ public: 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. * If the region is empty, returns false, and path is left unmodified. diff --git a/src/core/SkRegion.cpp b/src/core/SkRegion.cpp index 09550571e6..acc530a94d 100644 --- a/src/core/SkRegion.cpp +++ b/src/core/SkRegion.cpp @@ -124,6 +124,15 @@ void SkRegion::swap(SkRegion& other) { 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); |