limit mask drawing to clip bounds

Change-Id: Iab74531614654f241e12d1cd1af14725888580c8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/207143
Reviewed-by: Mike Reed <reed@google.com>
Auto-Submit: Lee Salzman <lsalzman@mozilla.com>
Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index b30f654..90bdf47 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -965,6 +965,11 @@
 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, const SkPaint& paint) const {
     SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType);
 
+    // nothing to draw
+    if (fRC->isEmpty()) {
+        return;
+    }
+
     if (SkTreatAsSprite(*fMatrix, bitmap.dimensions(), paint)) {
         int ix = SkScalarRoundToInt(fMatrix->getTranslateX());
         int iy = SkScalarRoundToInt(fMatrix->getTranslateY());
@@ -991,10 +996,11 @@
         r.round(&mask.fBounds);
 
         // set the mask's bounds to the transformed bitmap-bounds,
-        // clipped to the actual device
+        // clipped to the actual device and further limited by the clip bounds
         {
-            SkIRect    devBounds;
-            devBounds.set(0, 0, fDst.width(), fDst.height());
+            SkASSERT(fDst.bounds().contains(fRC->getBounds()));
+            SkIRect devBounds = fDst.bounds();
+            devBounds.intersect(fRC->getBounds().makeOutset(1, 1));
             // need intersect(l, t, r, b) on irect
             if (!mask.fBounds.intersect(devBounds)) {
                 return;