Adding checksum to SkFlatData to accelerate SkPicture recording.
The checksum triggers an early exit in the mem compare use to search for duplicate flattened objects. Also, call to memcmp was replaced with 64-bit at a time comparison loop.

Review URL: http://codereview.appspot.com/6339046/
BUG=http://code.google.com/p/chromium/issues/detail?id=54079
TEST=Checksum and PictureRecord tests in bench.exe



git-svn-id: http://skia.googlecode.com/svn/trunk@4378 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPictureFlat.cpp b/src/core/SkPictureFlat.cpp
index 14d912d..ec04495 100644
--- a/src/core/SkPictureFlat.cpp
+++ b/src/core/SkPictureFlat.cpp
@@ -7,6 +7,7 @@
  */
 #include "SkPictureFlat.h"
 
+#include "SkChecksum.h"
 #include "SkColorFilter.h"
 #include "SkDrawLooper.h"
 #include "SkMaskFilter.h"
@@ -79,7 +80,13 @@
     flattenProc(buffer, obj);
     uint32_t size = buffer.size();
 
-    // allocate the enough memory to hold both SkFlatData and the serialized
+
+#if !SK_PREFER_32BIT_CHECKSUM
+    uint32_t unpaddedSize = size;
+    size = SkAlign8(size);
+#endif
+
+    // allocate enough memory to hold both SkFlatData and the serialized
     // contents
     SkFlatData* result = (SkFlatData*) heap->allocThrow(size + sizeof(SkFlatData));
     result->fIndex = index;
@@ -87,6 +94,18 @@
 
     // put the serialized contents into the data section of the new allocation
     buffer.flatten(result->data());
+#if SK_PREFER_32BIT_CHECKSUM
+    result->fChecksum =
+        SkComputeChecksum32(reinterpret_cast<uint32_t*>(result->data()), size);
+#else
+    if (size != unpaddedSize) {
+        // Flat data is padded: put zeros in the last 32 bits.
+        SkASSERT(size - 4 == unpaddedSize);
+        *((uint32_t*)((char*)result->data() + unpaddedSize)) = 0;
+    }
+    result->fChecksum =
+        SkComputeChecksum64(reinterpret_cast<uint64_t*>(result->data()), size);
+#endif
     return result;
 }
 
@@ -103,5 +122,5 @@
         facePlayback->setupBuffer(buffer);
     }
     unflattenProc(buffer, result);
-    SkASSERT(fAllocSize == (int32_t)buffer.offset());
+    SkASSERT(fAllocSize == SkAlign8((int32_t)buffer.offset()));
 }