change pixelref to not inherit from SkFlattenable

If I can "inline" MallocPixelRef unflatten, then I think we can delete this code. The only caller today should be unflattening in the legacy path for bitmaps.

R=robertphillips@google.com

Author: reed@google.com

Review URL: https://codereview.chromium.org/320873003
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 316878b..e525ea2 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -1292,6 +1292,7 @@
 };
 
 void SkBitmap::legacyUnflatten(SkReadBuffer& buffer) {
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
     this->reset();
 
     SkImageInfo info;
@@ -1317,7 +1318,7 @@
                 origin.fX = buffer.readInt();
                 origin.fY = buffer.readInt();
                 size_t offset = origin.fY * rowBytes + origin.fX * info.bytesPerPixel();
-                SkPixelRef* pr = buffer.readPixelRef();
+                SkPixelRef* pr = buffer.readFlattenable<SkPixelRef>();
                 if (!buffer.validate((NULL == pr) ||
                        (pr->getAllocatedSizeInBytes() >= (offset + this->getSafeSize())))) {
                     origin.setZero();
@@ -1332,6 +1333,9 @@
                 sk_throw();
         }
     }
+#else
+    sk_throw();
+#endif
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index d51fb7c..447083a 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -200,21 +200,7 @@
     return this->info().getSafeSize(fRB);
 }
 
-void SkMallocPixelRef::flatten(SkWriteBuffer& buffer) const {
-    this->INHERITED::flatten(buffer);
-
-    buffer.write32(SkToU32(fRB));
-
-    // TODO: replace this bulk write with a chunky one that can trim off any
-    // trailing bytes on each scanline (in case rowbytes > width*size)
-    size_t size = this->info().getSafeSize(fRB);
-    buffer.writeByteArray(fStorage, size);
-    buffer.writeBool(fCTable != NULL);
-    if (fCTable) {
-        fCTable->writeToBuffer(buffer);
-    }
-}
-
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
 SkMallocPixelRef::SkMallocPixelRef(SkReadBuffer& buffer)
     : INHERITED(buffer, NULL)
     , fReleaseProc(sk_free_releaseproc)
@@ -237,6 +223,7 @@
 
     this->setPreLocked(fStorage, fRB, fCTable);
 }
+#endif
 
 ///////////////////////////////////////////////////////////////////////////////
 
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index 829c3f1..3664dfa 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -108,6 +108,7 @@
     fPreLocked = false;
 }
 
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
 static SkImageInfo read_info(SkReadBuffer& buffer) {
     SkImageInfo info;
     info.unflatten(buffer);
@@ -130,6 +131,7 @@
     fUniqueGenerationID = false;  // Conservatively assuming the original still exists.
     fPreLocked = false;
 }
+#endif
 
 SkPixelRef::~SkPixelRef() {
     this->callGenIDChangeListeners();
@@ -159,23 +161,6 @@
 #endif
 }
 
-void SkPixelRef::flatten(SkWriteBuffer& buffer) const {
-    this->INHERITED::flatten(buffer);
-    fInfo.flatten(buffer);
-    buffer.writeBool(fIsImmutable);
-    // We write the gen ID into the picture for within-process recording. This
-    // is safe since the same genID will never refer to two different sets of
-    // pixels (barring overflow). However, each process has its own "namespace"
-    // of genIDs. So for cross-process recording we write a zero which will
-    // trigger assignment of a new genID in playback.
-    if (buffer.isCrossProcess()) {
-        buffer.writeUInt(0);
-    } else {
-        buffer.writeUInt(fGenerationID);
-        fUniqueGenerationID = false;  // Conservative, a copy is probably about to exist.
-    }
-}
-
 bool SkPixelRef::lockPixels(LockRec* rec) {
     SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
 
diff --git a/src/core/SkScaledImageCache.cpp b/src/core/SkScaledImageCache.cpp
index a030248..eda4871 100644
--- a/src/core/SkScaledImageCache.cpp
+++ b/src/core/SkScaledImageCache.cpp
@@ -183,7 +183,9 @@
     SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_t rowBytes);
     ~SkOneShotDiscardablePixelRef();
 
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
     SK_DECLARE_UNFLATTENABLE_OBJECT()
+#endif
 
 protected:
     virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;