Make GrSWMaskHelper take a matrix for each draw

Change-Id: I52659857174848696f360d64552a9690db24ed50
Reviewed-on: https://skia-review.googlesource.com/40883
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index af0d1bd..5d0c375 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -33,25 +33,35 @@
 /**
  * Draw a single rect element of the clip stack into the accumulation bitmap
  */
-void GrSWMaskHelper::drawRect(const SkRect& rect, SkRegion::Op op, GrAA aa, uint8_t alpha) {
+void GrSWMaskHelper::drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA aa,
+                              uint8_t alpha) {
     SkPaint paint;
-
     paint.setBlendMode(op_to_mode(op));
     paint.setAntiAlias(GrAA::kYes == aa);
     paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha));
 
+    SkMatrix translatedMatrix = matrix;
+    translatedMatrix.postTranslate(fTranslate.fX, fTranslate.fY);
+    fDraw.fMatrix = &translatedMatrix;
+
     fDraw.drawRect(rect, paint);
+    SkDEBUGCODE(fDraw.fMatrix = (SkMatrix*)0xbbbbbbbb);
 }
 
 /**
  * Draw a single path element of the clip stack into the accumulation bitmap
  */
-void GrSWMaskHelper::drawShape(const GrShape& shape, SkRegion::Op op, GrAA aa, uint8_t alpha) {
+void GrSWMaskHelper::drawShape(const GrShape& shape, const SkMatrix& matrix, SkRegion::Op op,
+                               GrAA aa, uint8_t alpha) {
     SkPaint paint;
     paint.setPathEffect(shape.style().refPathEffect());
     shape.style().strokeRec().applyToPaint(&paint);
     paint.setAntiAlias(GrAA::kYes == aa);
 
+    SkMatrix translatedMatrix = matrix;
+    translatedMatrix.postTranslate(fTranslate.fX, fTranslate.fY);
+    fDraw.fMatrix = &translatedMatrix;
+
     SkPath path;
     shape.asPath(&path);
     if (SkRegion::kReplace_Op == op && 0xFF == alpha) {
@@ -62,17 +72,12 @@
         paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha));
         fDraw.drawPath(path, paint);
     }
-}
+    SkDEBUGCODE(fDraw.fMatrix = (SkMatrix*)0xbbbbbbbb);
+};
 
-bool GrSWMaskHelper::init(const SkIRect& resultBounds, const SkMatrix* matrix) {
-    if (matrix) {
-        fMatrix = *matrix;
-    } else {
-        fMatrix.setIdentity();
-    }
-
-    // Now translate so the bound's UL corner is at the origin
-    fMatrix.postTranslate(-SkIntToScalar(resultBounds.fLeft), -SkIntToScalar(resultBounds.fTop));
+bool GrSWMaskHelper::init(const SkIRect& resultBounds) {
+    // We will need to translate draws so the bound's UL corner is at the origin
+    fTranslate = {-SkIntToScalar(resultBounds.fLeft), -SkIntToScalar(resultBounds.fTop)};
     SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), resultBounds.height());
 
     const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(bounds.width(), bounds.height());
@@ -85,7 +90,8 @@
     fDraw.fDst      = *fPixels;
     fRasterClip.setRect(bounds);
     fDraw.fRC       = &fRasterClip;
-    fDraw.fMatrix   = &fMatrix;
+    // Each draw must specify the matrix.
+    SkDEBUGCODE(fDraw.fMatrix = (SkMatrix*)0xbbbbbbbb);
     return true;
 }