Start stripping out complicated parts of SkPicture{Record,Data}.

First step: no more paint flattening or deduplication.

BUG=skia:

Review URL: https://codereview.chromium.org/723593002
diff --git a/gyp/tests.gypi b/gyp/tests.gypi
index b21d61e..b6a8faa 100644
--- a/gyp/tests.gypi
+++ b/gyp/tests.gypi
@@ -90,7 +90,6 @@
     '../tests/ErrorTest.cpp',
     '../tests/FillPathTest.cpp',
     '../tests/FitsInTest.cpp',
-    '../tests/FlatDataTest.cpp',
     '../tests/FlateTest.cpp',
     '../tests/FloatingPointTextureTest.cpp',
     '../tests/FontHostStreamTest.cpp',
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp
index 896c2e6..0ccb776 100644
--- a/src/core/SkPictureData.cpp
+++ b/src/core/SkPictureData.cpp
@@ -48,11 +48,8 @@
 
     fContentInfo.set(record.fContentInfo);
 
-    // copy over the refcnt dictionary to our reader
-    record.fFlattenableHeap.setupPlaybacks();
-
     fBitmaps = record.fBitmapHeap->extractBitmaps();
-    fPaints = record.fPaints.unflattenToArray();
+    fPaints = SkTRefArray<SkPaint>::Create(record.fPaints.begin(), record.fPaints.count());
 
     fBitmapHeap.reset(SkSafeRef(record.fBitmapHeap));
     fPathHeap.reset(SkSafeRef(record.pathHeap()));
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index bd2ad29..40f6a0a 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -570,47 +570,4 @@
     SkTDynamicHash<SkFlatData, SkFlatData, SkFlatData::HashTraits> fHash;
 };
 
-struct SkPaintFlatteningTraits {
-    static void Flatten(SkWriteBuffer& buffer, const SkPaint& paint) { paint.flatten(buffer); }
-    static void Unflatten(SkReadBuffer& buffer, SkPaint* paint) { paint->unflatten(buffer); }
-};
-
-typedef SkFlatDictionary<SkPaint, SkPaintFlatteningTraits> SkPaintDictionary;
-
-class SkChunkFlatController : public SkFlatController {
-public:
-    SkChunkFlatController(size_t minSize)
-    : fHeap(minSize)
-    , fTypefaceSet(SkNEW(SkRefCntSet))
-    , fLastAllocated(NULL) {
-        this->setTypefaceSet(fTypefaceSet);
-        this->setTypefacePlayback(&fTypefacePlayback);
-    }
-
-    virtual void* allocThrow(size_t bytes) SK_OVERRIDE {
-        fLastAllocated = fHeap.allocThrow(bytes);
-        return fLastAllocated;
-    }
-
-    virtual void unalloc(void* ptr) SK_OVERRIDE {
-        // fHeap can only free a pointer if it was the last one allocated.  Otherwise, we'll just
-        // have to wait until fHeap is destroyed.
-        if (ptr == fLastAllocated) (void)fHeap.unalloc(ptr);
-    }
-
-    void setupPlaybacks() const {
-        fTypefacePlayback.reset(fTypefaceSet.get());
-    }
-
-    void setBitmapStorage(SkBitmapHeap* heap) {
-        this->setBitmapHeap(heap);
-    }
-
-private:
-    SkChunkAlloc               fHeap;
-    SkAutoTUnref<SkRefCntSet>  fTypefaceSet;
-    void*                      fLastAllocated;
-    mutable SkTypefacePlayback fTypefacePlayback;
-};
-
 #endif
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 40ecc6a..00c51ac 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -31,12 +31,9 @@
 
 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
     : INHERITED(dimensions.width(), dimensions.height())
-    , fFlattenableHeap(HEAP_BLOCK_SIZE)
-    , fPaints(&fFlattenableHeap)
     , fRecordFlags(flags) {
 
     fBitmapHeap = SkNEW(SkBitmapHeap);
-    fFlattenableHeap.setBitmapStorage(fBitmapHeap);
 
     fFirstSavedLayerIndex = kNoSavedLayerIndex;
     fInitialSaveCount = kNoInitialSave;
@@ -44,7 +41,6 @@
 
 SkPictureRecord::~SkPictureRecord() {
     SkSafeUnref(fBitmapHeap);
-    fFlattenableHeap.setBitmapStorage(NULL);
     fPictureRefs.unrefAll();
     fTextBlobRefs.unrefAll();
 }
@@ -926,9 +922,8 @@
     fContentInfo.onAddPaintPtr(paint);
 
     if (paint) {
-        const SkFlatData* flat = fPaints.findAndReturnFlat(*paint);
-        SkASSERT(flat && flat->index() != 0);
-        this->addInt(flat->index());
+        fPaints.push_back(*paint);
+        this->addInt(fPaints.count());
     } else {
         this->addInt(0);
     }
diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h
index 032c5f6..bac5586 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -13,7 +13,6 @@
 #include "SkPathHeap.h"
 #include "SkPicture.h"
 #include "SkPictureData.h"
-#include "SkPictureFlat.h"
 #include "SkTemplates.h"
 #include "SkWriter32.h"
 
@@ -244,9 +243,7 @@
     SkPictureContentInfo fContentInfo;
     SkAutoTUnref<SkPathHeap> fPathHeap;
 
-    SkChunkFlatController fFlattenableHeap;
-
-    SkPaintDictionary fPaints;
+    SkTArray<SkPaint> fPaints;
 
     SkWriter32 fWriter;
 
diff --git a/tests/BitmapHeapTest.cpp b/tests/BitmapHeapTest.cpp
index dc9905e..d65ebb6 100644
--- a/tests/BitmapHeapTest.cpp
+++ b/tests/BitmapHeapTest.cpp
@@ -15,6 +15,13 @@
 #include "SkShader.h"
 #include "Test.h"
 
+struct SimpleFlatController : public SkFlatController {
+    SimpleFlatController() : SkFlatController() {}
+    virtual void* allocThrow(size_t bytes) { return sk_malloc_throw(bytes); }
+    virtual void unalloc(void* ptr) { sk_free(ptr); }
+    void setBitmapStorage(SkBitmapHeap* h) { this->setBitmapHeap(h); }
+};
+
 struct SkShaderTraits {
     static void Flatten(SkWriteBuffer& buffer, const SkShader& shader) {
         buffer.writeFlattenable(&shader);
@@ -23,7 +30,6 @@
 typedef SkFlatDictionary<SkShader, SkShaderTraits> FlatDictionary;
 
 class SkBitmapHeapTester {
-
 public:
     static int32_t GetRefCount(const SkBitmapHeapEntry* entry) {
         return entry->fRefCount;
@@ -44,7 +50,7 @@
 
     // Flatten, storing it in the bitmap heap.
     SkBitmapHeap heap(1, 1);
-    SkChunkFlatController controller(1024);
+    SimpleFlatController controller;
     controller.setBitmapStorage(&heap);
     FlatDictionary dictionary(&controller);
 
diff --git a/tests/FlatDataTest.cpp b/tests/FlatDataTest.cpp
deleted file mode 100644
index 2be92b6..0000000
--- a/tests/FlatDataTest.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkBitmap.h"
-#include "SkCanvas.h"
-#include "SkColor.h"
-#include "SkColorFilter.h"
-#include "SkGradientShader.h"
-#include "SkPaint.h"
-#include "SkPictureFlat.h"
-#include "SkShader.h"
-#include "SkXfermode.h"
-#include "Test.h"
-
-struct SkFlattenableTraits {
-    static void Flatten(SkWriteBuffer& buffer, const SkFlattenable& flattenable) {
-        buffer.writeFlattenable(&flattenable);
-    }
-};
-
-class Controller : public SkChunkFlatController {
-public:
-    Controller() : INHERITED(1024) {
-        this->INHERITED::setNamedFactorySet(SkNEW(SkNamedFactorySet))->unref();
-    }
-private:
-    typedef SkChunkFlatController INHERITED;
-};
-
-/**
- * Verify that two SkFlatData objects that created from the same object are
- * identical when using an SkNamedFactorySet.
- * @param reporter Object to report failures.
- * @param obj Flattenable object to be flattened.
- * @param flattenProc Function that flattens objects with the same type as obj.
- */
-template <typename Traits, typename T>
-static void testCreate(skiatest::Reporter* reporter, const T& obj) {
-    Controller controller;
-    // No need to delete data because that will be taken care of by the controller.
-    SkFlatData* data1 = SkFlatData::Create<Traits>(&controller, obj, 0);
-    SkFlatData* data2 = SkFlatData::Create<Traits>(&controller, obj, 1);
-    REPORTER_ASSERT(reporter, *data1 == *data2);
-}
-
-DEF_TEST(FlatData, reporter) {
-    // Test flattening SkShader
-    SkPoint points[2];
-    points[0].set(0, 0);
-    points[1].set(SkIntToScalar(20), SkIntToScalar(20));
-    SkColor colors[2];
-    colors[0] = SK_ColorRED;
-    colors[1] = SK_ColorBLUE;
-
-    SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, colors, NULL, 2,
-                                                                 SkShader::kRepeat_TileMode));
-    testCreate<SkFlattenableTraits>(reporter, *shader);
-
-    // Test SkColorFilter
-    SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateLightingFilter(SK_ColorBLUE, SK_ColorRED));
-    testCreate<SkFlattenableTraits>(reporter, *cf);
-
-    // Test SkXfermode
-    SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mode));
-    testCreate<SkFlattenableTraits>(reporter, *xfer);
-}