Fix for skp chunk sizes when clips are used outside of any save

https://codereview.appspot.com/7342047/



git-svn-id: http://skia.googlecode.com/svn/trunk@7748 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 45cc48d..5180e5e 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -352,8 +352,12 @@
 }
 
 bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
-    // id + rect + clip params + restore offset
-    uint32_t size = 1 * kUInt32Size + sizeof(rect) + 2 * kUInt32Size;
+    // id + rect + clip params
+    uint32_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size;
+    if (!fRestoreOffsetStack.isEmpty()) {
+        // + restore offset
+        size += kUInt32Size;
+    }
     uint32_t initialOffset = this->addDraw(CLIP_RECT, &size);
     addRect(rect);
     addInt(ClipParams_pack(op, doAA));
@@ -368,8 +372,12 @@
         return this->SkPictureRecord::clipRect(rrect.getBounds(), op, doAA);
     }
 
-    // op + rrect + clip params + restore offset
-    uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 2 * kUInt32Size;
+    // op + rrect + clip params
+    uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size;
+    if (!fRestoreOffsetStack.isEmpty()) {
+        // + restore offset
+        size += kUInt32Size;
+    }
     uint32_t initialOffset = this->addDraw(CLIP_RRECT, &size);
     addRRect(rrect);
     addInt(ClipParams_pack(op, doAA));
@@ -391,8 +399,12 @@
         return this->clipRect(r, op, doAA);
     }
 
-    // op + path index + clip params + restore offset
-    uint32_t size = 4 * kUInt32Size;
+    // op + path index + clip params
+    uint32_t size = 3 * kUInt32Size;
+    if (!fRestoreOffsetStack.isEmpty()) {
+        // + restore offset
+        size += kUInt32Size;
+    }
     uint32_t initialOffset = this->addDraw(CLIP_PATH, &size);
     addPath(path);
     addInt(ClipParams_pack(op, doAA));
@@ -408,8 +420,12 @@
 }
 
 bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) {
-    // op + region index + clip params + restore offset
-    uint32_t size = 4 * kUInt32Size;
+    // op + region index + clip params
+    uint32_t size = 3 * kUInt32Size;
+    if (!fRestoreOffsetStack.isEmpty()) {
+        // + restore offset
+        size += kUInt32Size;
+    }
     uint32_t initialOffset = this->addDraw(CLIP_REGION, &size); 
     addRegion(region);
     addInt(ClipParams_pack(op, false));