Set write buffer flags only in SkWriteBuffer and SkFlatController constructors.

This is a baby step toward refactored (and faster in-process) typeface and flattenable factory encoding and decoding.  The sooner SkWriteBuffer knows its flags, the better.

Next steps will be to rearrange Sk{Read,Write}Buffer members into disjoint strategies to handle typefaces and flattenable factories: one for in-process, one for cross-process, one when validating.

BUG=skia:
R=reed@google.com, scroggo@google.com

Author: mtklein@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13253 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkFlattenableSerialization.cpp b/src/core/SkFlattenableSerialization.cpp
index 13fbe6e..f34e641 100644
--- a/src/core/SkFlattenableSerialization.cpp
+++ b/src/core/SkFlattenableSerialization.cpp
@@ -12,8 +12,7 @@
 #include "SkWriteBuffer.h"
 
 SkData* SkValidatingSerializeFlattenable(SkFlattenable* flattenable) {
-    SkWriteBuffer writer;
-    writer.setFlags(SkWriteBuffer::kValidation_Flag);
+    SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag);
     writer.writeFlattenable(flattenable);
     uint32_t size = writer.bytesWritten();
     void* data = sk_malloc_throw(size);
diff --git a/src/core/SkPictureFlat.cpp b/src/core/SkPictureFlat.cpp
index e3a6f13..7b2e67f 100644
--- a/src/core/SkPictureFlat.cpp
+++ b/src/core/SkPictureFlat.cpp
@@ -60,12 +60,12 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkFlatController::SkFlatController()
+SkFlatController::SkFlatController(uint32_t writeBufferFlags)
 : fBitmapHeap(NULL)
 , fTypefaceSet(NULL)
 , fTypefacePlayback(NULL)
 , fFactorySet(NULL)
-, fWriteBufferFlags(0) {}
+, fWriteBufferFlags(writeBufferFlags) {}
 
 SkFlatController::~SkFlatController() {
     SkSafeUnref(fBitmapHeap);
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index 431fa96..7973e65 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -168,7 +168,7 @@
 public:
     SK_DECLARE_INST_COUNT(SkFlatController)
 
-    SkFlatController();
+    SkFlatController(uint32_t writeBufferFlags = 0);
     virtual ~SkFlatController();
     /**
      * Return a new block of memory for the SkFlatDictionary to use.
@@ -242,17 +242,12 @@
      */
     SkNamedFactorySet* setNamedFactorySet(SkNamedFactorySet*);
 
-    /**
-     * Set the flags to be used during flattening.
-     */
-    void setWriteBufferFlags(uint32_t flags) { fWriteBufferFlags = flags; }
-
 private:
     SkBitmapHeap*       fBitmapHeap;
     SkRefCntSet*        fTypefaceSet;
     SkTypefacePlayback* fTypefacePlayback;
     SkNamedFactorySet*  fFactorySet;
-    uint32_t            fWriteBufferFlags;
+    const uint32_t      fWriteBufferFlags;
 
     typedef SkRefCnt INHERITED;
 };
@@ -264,12 +259,11 @@
     static SkFlatData* Create(SkFlatController* controller, const T& obj, int index) {
         // A buffer of 256 bytes should fit most paints, regions, and matrices.
         uint32_t storage[64];
-        SkWriteBuffer buffer(storage, sizeof(storage));
+        SkWriteBuffer buffer(storage, sizeof(storage), controller->getWriteBufferFlags());
 
         buffer.setBitmapHeap(controller->getBitmapHeap());
         buffer.setTypefaceRecorder(controller->getTypefaceSet());
         buffer.setNamedFactoryRecorder(controller->getNamedFactorySet());
-        buffer.setFlags(controller->getWriteBufferFlags());
 
         Traits::flatten(buffer, obj);
         size_t size = buffer.bytesWritten();
@@ -367,6 +361,7 @@
 public:
     explicit SkFlatDictionary(SkFlatController* controller)
     : fController(SkRef(controller))
+    , fScratch(controller->getWriteBufferFlags())
     , fReady(false) {
         this->reset();
     }
@@ -496,7 +491,6 @@
         fScratch.setBitmapHeap(fController->getBitmapHeap());
         fScratch.setTypefaceRecorder(fController->getTypefaceSet());
         fScratch.setNamedFactoryRecorder(fController->getNamedFactorySet());
-        fScratch.setFlags(fController->getWriteBufferFlags());
         fReady = true;
     }
 
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index 02d8828..e71a17f 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -411,8 +411,7 @@
         SkRefCntSet  typefaceSet;
         SkFactorySet factSet;
 
-        SkWriteBuffer buffer;
-        buffer.setFlags(SkWriteBuffer::kCrossProcess_Flag);
+        SkWriteBuffer buffer(SkWriteBuffer::kCrossProcess_Flag);
         buffer.setTypefaceRecorder(&typefaceSet);
         buffer.setFactoryRecorder(&factSet);
         buffer.setBitmapEncoder(encoder);
diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp
index cbbb4c9..a295a8c 100644
--- a/src/core/SkWriteBuffer.cpp
+++ b/src/core/SkWriteBuffer.cpp
@@ -14,8 +14,8 @@
 #include "SkStream.h"
 #include "SkTypeface.h"
 
-SkWriteBuffer::SkWriteBuffer()
-    : fFlags(0)
+SkWriteBuffer::SkWriteBuffer(uint32_t flags)
+    : fFlags(flags)
     , fFactorySet(NULL)
     , fNamedFactorySet(NULL)
     , fBitmapHeap(NULL)
@@ -23,8 +23,8 @@
     , fBitmapEncoder(NULL) {
 }
 
-SkWriteBuffer::SkWriteBuffer(void* storage, size_t storageSize)
-    : fFlags(0)
+SkWriteBuffer::SkWriteBuffer(void* storage, size_t storageSize, uint32_t flags)
+    : fFlags(flags)
     , fFactorySet(NULL)
     , fNamedFactorySet(NULL)
     , fWriter(storage, storageSize)