Fixed oversized SkRegion bound problem for complexclip_aa GM

http://codereview.appspot.com/6447076/



git-svn-id: http://skia.googlecode.com/svn/trunk@4906 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkAAClip.cpp b/src/core/SkAAClip.cpp
index 8936297..e0fcf7a 100644
--- a/src/core/SkAAClip.cpp
+++ b/src/core/SkAAClip.cpp
@@ -221,6 +221,8 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
+// Count the number of zeros on the left and right edges of the passed in
+// RLE row. If 'row' is all zeros return 'width' in both variables.
 static void count_left_right_zeros(const uint8_t* row, int width,
                                    int* leftZ, int* riteZ) {
     int zeros = 0;
@@ -237,6 +239,12 @@
     } while (width > 0);
     *leftZ = zeros;
 
+    if (0 == width) {
+        // this line is completely empty return 'width' in both variables
+        *riteZ = *leftZ;
+        return;
+    }
+
     zeros = 0;
     while (width > 0) {
         int n = row[0];
@@ -265,7 +273,7 @@
     const uint8_t data2[] = {  7, 0,     5, 0, 2, 0, 3, 0xFF };
     const uint8_t data3[] = {  0, 5,     5, 0xFF, 2, 0, 3, 0 };
     const uint8_t data4[] = {  2, 3,     2, 0, 5, 0xFF, 3, 0 };
-    const uint8_t data5[] = { 10, 0,     10, 0 };
+    const uint8_t data5[] = { 10, 10,    10, 0 };
     const uint8_t data6[] = {  2, 2,     2, 0, 2, 0xFF, 2, 0, 2, 0xFF, 2, 0 };
 
     const uint8_t* array[] = {
@@ -398,11 +406,15 @@
     YOffset* stop = yoff + head->fRowCount;
     uint8_t* base = head->data();
 
+    // After this loop, 'leftZeros' & 'rightZeros' will contain the minimum
+    // number of zeros on the left and right of the clip. This information
+    // can be used to shrink the bounding box.
     int leftZeros = width;
     int riteZeros = width;
     while (yoff < stop) {
         int L, R;
         count_left_right_zeros(base + yoff->fOffset, width, &L, &R);
+        SkASSERT(L + R < width || (L == width && R == width));
         if (L < leftZeros) {
             leftZeros = L;
         }
@@ -417,7 +429,8 @@
     }
 
     SkASSERT(leftZeros || riteZeros);
-    if (width == (leftZeros + riteZeros)) {
+    if (width == leftZeros) {
+        SkASSERT(width == riteZeros);
         return this->setEmpty();
     }