Prevent picture recording from over optimizing the culling of clips.

BUG=skia:1496
R=mtklein@google.com, reed@google.com, robertphillips@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk/src@10689 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkPictureRecord.cpp b/core/SkPictureRecord.cpp
index 9157363..2c2d334 100644
--- a/core/SkPictureRecord.cpp
+++ b/core/SkPictureRecord.cpp
@@ -24,6 +24,7 @@
 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, etc.
 static int const kUInt32Size = 4;
 
+static const uint32_t kSaveSize = 2 * kUInt32Size;
 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size;
 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect);
 
@@ -148,7 +149,7 @@
     fRestoreOffsetStack.push(-(int32_t)fWriter.size());
 
     // op + flags
-    uint32_t size = 2 * kUInt32Size;
+    uint32_t size = kSaveSize;
     uint32_t initialOffset = this->addDraw(SAVE, &size);
     addInt(flags);
 
@@ -479,6 +480,16 @@
         return false;
     }
     SkASSERT(SAVE == op);
+    SkASSERT(kSaveSize == opSize);
+
+    // get the save flag (last 4-bytes of the space allocated for the opSize)
+    SkCanvas::SaveFlags saveFlags = (SkCanvas::SaveFlags) *writer->peek32(offset+4);
+    if (SkCanvas::kMatrixClip_SaveFlag != saveFlags) {
+        // This function's optimization is only correct for kMatrixClip style saves.
+        // TODO: set checkMatrix & checkClip booleans here and then check for the
+        // offending operations in the following loop.
+        return false;
+    }
 
     // Walk forward until we get back to either a draw-verb (abort) or we hit
     // our restore (success).