SkCanvas::resetForNextPicture()

No diffs against head for DM --config 8888 gpu 2ndpic-8888 2ndpic-gpu.

  picture_overhead_draw	1.62us ->  1.6us	0.99x
picture_overhead_nodraw	 792ns ->  342ns	0.43x

tiles and serialization modes will also test this a bit.

BUG=chromium:470553

Committed: https://skia.googlesource.com/skia/+/f920e468ac66a36c9653d1b11181480295044c7d

Review URL: https://codereview.chromium.org/1067893002
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index ec21955..63a9241 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -135,6 +135,13 @@
         SkDELETE(fPaint);
     }
 
+    void reset(const SkIRect& bounds) {
+        SkASSERT(!fPaint);
+        SkASSERT(!fNext);
+        SkASSERT(fDevice);
+        fClip.setRect(bounds);
+    }
+
     void updateMC(const SkMatrix& totalMatrix, const SkRasterClip& totalClip,
                   const SkClipStack& clipStack, SkRasterClip* updateClip) {
         int x = fDevice->getOrigin().x();
@@ -224,6 +231,15 @@
         SkDELETE(fLayer);
         dec_rec();
     }
+
+    void reset(const SkIRect& bounds) {
+        SkASSERT(fLayer);
+        SkASSERT(fDeferredSaveCount == 0);
+
+        fMatrix.reset();
+        fRasterClip.setRect(bounds);
+        fLayer->reset(bounds);
+    }
 };
 
 class SkDrawIter : public SkDraw {
@@ -425,6 +441,18 @@
 
 ////////////////////////////////////////////////////////////////////////////
 
+void SkCanvas::resetForNextPicture(const SkIRect& bounds) {
+    this->restoreToCount(1);
+    fCachedLocalClipBounds.setEmpty();
+    fCachedLocalClipBoundsDirty = true;
+    fClipStack->reset();
+    fMCRec->reset(bounds);
+
+    // We're peering through a lot of structs here.  Only at this scope do we
+    // know that the device is an SkBitmapDevice (really an SkNoPixelsBitmapDevice).
+    static_cast<SkBitmapDevice*>(fMCRec->fLayer->fDevice)->setNewSize(bounds.size());
+}
+
 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
     fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag);
     fCachedLocalClipBounds.setEmpty();