Add getRectCount to SkRegtion
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 17 Jul 2013 21:39:28 +0000 (21:39 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 17 Jul 2013 21:39:28 +0000 (21:39 +0000)
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

include/core/SkRegion.h
src/core/SkRegion.cpp

index ab8f220..a088d54 100644 (file)
@@ -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.
index 0955057..acc530a 100644 (file)
@@ -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);