fix empty region iter rect

Region iterators return bounds but do not initialize
the result if Iterator has no region or region is
empty.

Add general tests for empty region iterators.

R=reed@google.com,halcanary@google.com

Docs-Preview: https://skia.org/?cl=149980
Bug: skia:8186
Change-Id: If4367d4c0eef7fc9c7bfd7d1436143e155b78309
Reviewed-on: https://skia-review.googlesource.com/149980
Commit-Queue: Cary Clark <caryclark@skia.org>
Reviewed-by: Hal Canary <halcanary@google.com>
diff --git a/include/core/SkRegion.h b/include/core/SkRegion.h
index 80d7952..6f8bf34 100644
--- a/include/core/SkRegion.h
+++ b/include/core/SkRegion.h
@@ -520,7 +520,7 @@
     private:
         const SkRegion* fRgn;
         const SkRegion::RunType*  fRuns;
-        SkIRect         fRect;
+        SkIRect         fRect = {0, 0, 0, 0};
         bool            fDone;
     };
 
@@ -560,7 +560,7 @@
     private:
         Iterator    fIter;
         SkIRect     fClip;
-        SkIRect     fRect;
+        SkIRect     fRect = {0, 0, 0, 0};
         bool        fDone;
     };
 
diff --git a/tests/RegionTest.cpp b/tests/RegionTest.cpp
index d3d93d5..821c36c 100644
--- a/tests/RegionTest.cpp
+++ b/tests/RegionTest.cpp
@@ -474,3 +474,44 @@
     REPORTER_ASSERT(reporter, !region.setRect({0, 0, 0x7FFFFFFF, 0x7FFFFFFE}));
     REPORTER_ASSERT(reporter, !region.setRect({0, 0, 0x7FFFFFFF, 0x7FFFFFFF}));
 }
+
+DEF_TEST(region_empty_iter, reporter) {
+    SkRegion::Iterator emptyIter;
+    REPORTER_ASSERT(reporter, !emptyIter.rewind());
+    REPORTER_ASSERT(reporter, emptyIter.done());
+    auto eRect = emptyIter.rect();
+    REPORTER_ASSERT(reporter, eRect.isEmpty());
+    REPORTER_ASSERT(reporter, SkIRect::MakeEmpty() == eRect);
+    REPORTER_ASSERT(reporter, !emptyIter.rgn());
+
+    SkRegion region;
+    SkRegion::Iterator resetIter;
+    resetIter.reset(region);
+    REPORTER_ASSERT(reporter, resetIter.rewind());
+    REPORTER_ASSERT(reporter, resetIter.done());
+    auto rRect = resetIter.rect();
+    REPORTER_ASSERT(reporter, rRect.isEmpty());
+    REPORTER_ASSERT(reporter, SkIRect::MakeEmpty() == rRect);
+    REPORTER_ASSERT(reporter, resetIter.rgn());
+    REPORTER_ASSERT(reporter, resetIter.rgn()->isEmpty());
+
+    SkRegion::Iterator iter(region);
+    REPORTER_ASSERT(reporter, iter.done());
+    auto iRect = iter.rect();
+    REPORTER_ASSERT(reporter, iRect.isEmpty());
+    REPORTER_ASSERT(reporter, SkIRect::MakeEmpty() == iRect);
+    REPORTER_ASSERT(reporter, iter.rgn());
+    REPORTER_ASSERT(reporter, iter.rgn()->isEmpty());
+
+    SkRegion::Cliperator clipIter(region, {0, 0, 100, 100});
+    REPORTER_ASSERT(reporter, clipIter.done());
+    auto cRect = clipIter.rect();
+    REPORTER_ASSERT(reporter, cRect.isEmpty());
+    REPORTER_ASSERT(reporter, SkIRect::MakeEmpty() == cRect);
+
+    SkRegion::Spanerator spanIter(region, 0, 0, 100);
+    int left = 0, right = 0;
+    REPORTER_ASSERT(reporter, !spanIter.next(&left, &right));
+    REPORTER_ASSERT(reporter, !left);
+    REPORTER_ASSERT(reporter, !right);
+}