De-virtualize SkCanvas save/restore.

This moves the state management logic into non-virtual SkCanvas methods,
and turns the virtuals into protected notifiers.

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

Author: fmalita@chromium.org

Review URL: https://codereview.chromium.org/194713008

git-svn-id: http://skia.googlecode.com/svn/trunk@13776 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 08b69b8..a85ea8d 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -146,7 +146,7 @@
     return gPaintOffsets[op] * sizeof(uint32_t) + overflow;
 }
 
-int SkPictureRecord::save(SaveFlags flags) {
+void SkPictureRecord::willSave(SaveFlags flags) {
 
 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
     fMCMgr.save(flags);
@@ -156,7 +156,8 @@
     fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
     this->recordSave(flags);
 #endif
-    return this->INHERITED::save(flags);
+
+    this->INHERITED::willSave(flags);
 }
 
 void SkPictureRecord::recordSave(SaveFlags flags) {
@@ -168,12 +169,11 @@
     this->validate(initialOffset, size);
 }
 
-int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint,
-                               SaveFlags flags) {
+SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds,
+                                                           const SkPaint* paint, SaveFlags flags) {
 
-    int count;
 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
-    count = fMCMgr.saveLayer(bounds, paint, flags);
+    fMCMgr.saveLayer(bounds, paint, flags);
 #else
     // record the offset to us, making it non-positive to distinguish a save
     // from a clip entry.
@@ -184,15 +184,13 @@
     }
 #endif
 
-    /*  Don't actually call INHERITED::saveLayer, because that will try to allocate
-        an offscreen device (potentially very big) which we don't actually need
+    this->INHERITED::willSaveLayer(bounds, paint, flags);
+    /*  No need for a (potentially very big) layer which we don't actually need
         at this time (and may not be able to afford since during record our
         clip starts out the size of the picture, which is often much larger
         than the size of the actual device we'll use during playback).
      */
-    count = this->INHERITED::save(flags);
-    this->clipRectBounds(bounds, flags, NULL);
-    return count;
+    return kNoLayer_SaveLayerStrategy;
 }
 
 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint,
@@ -605,7 +603,7 @@
     }
 }
 
-void SkPictureRecord::restore() {
+void SkPictureRecord::willRestore() {
     // FIXME: SkDeferredCanvas needs to be refactored to respect
     // save/restore balancing so that the following test can be
     // turned on permanently.
@@ -653,7 +651,7 @@
     fRestoreOffsetStack.pop();
 #endif
 
-    return this->INHERITED::restore();
+    this->INHERITED::willRestore();
 }
 
 void SkPictureRecord::recordRestore(bool fillInSkips) {