force readbuffer clients to use specialized readFoo for flattenables

BUG=
R=mtklein@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk/src@11803 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkBitmap.cpp b/core/SkBitmap.cpp
index 434c817..63a760c 100644
--- a/core/SkBitmap.cpp
+++ b/core/SkBitmap.cpp
@@ -1610,7 +1610,7 @@
     switch (reftype) {
         case SERIALIZE_PIXELTYPE_REF_DATA: {
             size_t offset = buffer.readUInt();
-            SkPixelRef* pr = buffer.readFlattenableT<SkPixelRef>();
+            SkPixelRef* pr = buffer.readPixelRef();
             SkSafeUnref(this->setPixelRef(pr, offset));
             break;
         }
diff --git a/core/SkBlitter.cpp b/core/SkBlitter.cpp
index 162fdbc..6ba82bf 100644
--- a/core/SkBlitter.cpp
+++ b/core/SkBlitter.cpp
@@ -683,7 +683,7 @@
 
 protected:
     Sk3DShader(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-        fProxy = buffer.readFlattenableT<SkShader>();
+        fProxy = buffer.readShader();
         fPMColor = buffer.readColor();
         fMask = NULL;
     }
diff --git a/core/SkComposeShader.cpp b/core/SkComposeShader.cpp
index de0ffdb..206608a 100644
--- a/core/SkComposeShader.cpp
+++ b/core/SkComposeShader.cpp
@@ -27,15 +27,15 @@
 
 SkComposeShader::SkComposeShader(SkFlattenableReadBuffer& buffer) :
     INHERITED(buffer) {
-    fShaderA = buffer.readFlattenableT<SkShader>();
+    fShaderA = buffer.readShader();
     if (NULL == fShaderA) {
         fShaderA = SkNEW_ARGS(SkColorShader, (0));
     }
-    fShaderB = buffer.readFlattenableT<SkShader>();
+    fShaderB = buffer.readShader();
     if (NULL == fShaderB) {
         fShaderB = SkNEW_ARGS(SkColorShader, (0));
     }
-    fMode = buffer.readFlattenableT<SkXfermode>();
+    fMode = buffer.readXfermode();
 }
 
 SkComposeShader::~SkComposeShader() {
diff --git a/core/SkFilterShader.cpp b/core/SkFilterShader.cpp
index 4fcb936..1e590cb 100644
--- a/core/SkFilterShader.cpp
+++ b/core/SkFilterShader.cpp
@@ -22,8 +22,8 @@
 
 SkFilterShader::SkFilterShader(SkFlattenableReadBuffer& buffer)
     : INHERITED(buffer) {
-    fShader = buffer.readFlattenableT<SkShader>();
-    fFilter = buffer.readFlattenableT<SkColorFilter>();
+    fShader = buffer.readShader();
+    fFilter = buffer.readColorFilter();
 }
 
 SkFilterShader::~SkFilterShader() {
diff --git a/core/SkFlattenableBuffers.cpp b/core/SkFlattenableBuffers.cpp
index 50a47d5..28cc76d 100644
--- a/core/SkFlattenableBuffers.cpp
+++ b/core/SkFlattenableBuffers.cpp
@@ -54,3 +54,4 @@
 void SkFlattenableWriteBuffer::flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer) {
     obj->flatten(buffer);
 }
+
diff --git a/core/SkFlattenableSerialization.cpp b/core/SkFlattenableSerialization.cpp
index b74c82f..cda3182 100644
--- a/core/SkFlattenableSerialization.cpp
+++ b/core/SkFlattenableSerialization.cpp
@@ -9,6 +9,7 @@
 
 #include "SkData.h"
 #include "SkFlattenable.h"
+#include "SkImageFilter.h"
 #include "SkOrderedReadBuffer.h"
 #include "SkOrderedWriteBuffer.h"
 
@@ -22,7 +23,9 @@
     return SkData::NewFromMalloc(data, size);
 }
 
+// TODO: this guy should be renamed to ImageFilter, or take SkEffectType as
+// a parameter.
 SkFlattenable* SkDeserializeFlattenable(const void* data, size_t size) {
     SkOrderedReadBuffer buffer(data, size);
-    return buffer.readFlattenable();
+    return buffer.readImageFilter();
 }
diff --git a/core/SkImageFilter.cpp b/core/SkImageFilter.cpp
index 3b7de25..c8c0c4d 100644
--- a/core/SkImageFilter.cpp
+++ b/core/SkImageFilter.cpp
@@ -68,7 +68,7 @@
     : fInputCount(buffer.readInt()), fInputs(new SkImageFilter*[fInputCount]) {
     for (int i = 0; i < fInputCount; i++) {
         if (buffer.readBool()) {
-            fInputs[i] = static_cast<SkImageFilter*>(buffer.readFlattenable());
+            fInputs[i] = buffer.readImageFilter();
         } else {
             fInputs[i] = NULL;
         }
diff --git a/core/SkOrderedReadBuffer.cpp b/core/SkOrderedReadBuffer.cpp
index 9d99194..aff6e20 100644
--- a/core/SkOrderedReadBuffer.cpp
+++ b/core/SkOrderedReadBuffer.cpp
@@ -268,7 +268,11 @@
     }
 }
 
-SkFlattenable* SkOrderedReadBuffer::readFlattenable() {
+SkFlattenable* SkOrderedReadBuffer::readFlattenable(SkEffectType et) {
+    //
+    // TODO: confirm that et matches the factory we decide to use
+    //
+
     SkFlattenable::Factory factory = NULL;
 
     if (fFactoryCount > 0) {
diff --git a/core/SkOrderedReadBuffer.h b/core/SkOrderedReadBuffer.h
index 556fce8..b29f310 100644
--- a/core/SkOrderedReadBuffer.h
+++ b/core/SkOrderedReadBuffer.h
@@ -52,7 +52,7 @@
     virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) SK_OVERRIDE;
 
     // common data structures
-    virtual SkFlattenable* readFlattenable() SK_OVERRIDE;
+    virtual SkFlattenable* readFlattenable(SkEffectType) SK_OVERRIDE;
     virtual void readPoint(SkPoint* point) SK_OVERRIDE;
     virtual void readMatrix(SkMatrix* matrix) SK_OVERRIDE;
     virtual void readIRect(SkIRect* rect) SK_OVERRIDE;
diff --git a/core/SkPaint.cpp b/core/SkPaint.cpp
index cfef8b1..44eef44 100644
--- a/core/SkPaint.cpp
+++ b/core/SkPaint.cpp
@@ -2178,14 +2178,14 @@
     }
 
     if (flatFlags & kHasEffects_FlatFlag) {
-        SkSafeUnref(this->setPathEffect(buffer.readFlattenableT<SkPathEffect>()));
-        SkSafeUnref(this->setShader(buffer.readFlattenableT<SkShader>()));
-        SkSafeUnref(this->setXfermode(buffer.readFlattenableT<SkXfermode>()));
-        SkSafeUnref(this->setMaskFilter(buffer.readFlattenableT<SkMaskFilter>()));
-        SkSafeUnref(this->setColorFilter(buffer.readFlattenableT<SkColorFilter>()));
-        SkSafeUnref(this->setRasterizer(buffer.readFlattenableT<SkRasterizer>()));
-        SkSafeUnref(this->setLooper(buffer.readFlattenableT<SkDrawLooper>()));
-        SkSafeUnref(this->setImageFilter(buffer.readFlattenableT<SkImageFilter>()));
+        SkSafeUnref(this->setPathEffect(buffer.readPathEffect()));
+        SkSafeUnref(this->setShader(buffer.readShader()));
+        SkSafeUnref(this->setXfermode(buffer.readXfermode()));
+        SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter()));
+        SkSafeUnref(this->setColorFilter(buffer.readColorFilter()));
+        SkSafeUnref(this->setRasterizer(buffer.readRasterizer()));
+        SkSafeUnref(this->setLooper(buffer.readDrawLooper()));
+        SkSafeUnref(this->setImageFilter(buffer.readImageFilter()));
 
         if (buffer.readBool()) {
             this->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref();
diff --git a/core/SkPathEffect.cpp b/core/SkPathEffect.cpp
index 8306d7a..e7f6822 100644
--- a/core/SkPathEffect.cpp
+++ b/core/SkPathEffect.cpp
@@ -48,8 +48,8 @@
 }
 
 SkPairPathEffect::SkPairPathEffect(SkFlattenableReadBuffer& buffer) {
-    fPE0 = buffer.readFlattenableT<SkPathEffect>();
-    fPE1 = buffer.readFlattenableT<SkPathEffect>();
+    fPE0 = buffer.readPathEffect();
+    fPE1 = buffer.readPathEffect();
     // either of these may fail, so we have to check for nulls later on
 }
 
diff --git a/core/SkScalerContext.cpp b/core/SkScalerContext.cpp
index ee9d919..83cf8f8 100644
--- a/core/SkScalerContext.cpp
+++ b/core/SkScalerContext.cpp
@@ -66,14 +66,15 @@
     #define DUMP_RECx
 #endif
 
-static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag) {
+static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag,
+                                       SkEffectType et) {
     SkFlattenable*  obj = NULL;
     uint32_t        len;
     const void*     data = desc->findEntry(tag, &len);
 
     if (data) {
         SkOrderedReadBuffer   buffer(data, len);
-        obj = buffer.readFlattenable();
+        obj = buffer.readFlattenable(et);
         SkASSERT(buffer.offset() == buffer.size());
     }
     return obj;
@@ -84,9 +85,9 @@
 
     , fBaseGlyphCount(0)
     , fTypeface(SkRef(typeface))
-    , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag)))
-    , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_SkDescriptorTag)))
-    , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_SkDescriptorTag)))
+    , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag, kPathEffect_SkEffectType)))
+    , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_SkDescriptorTag, kMaskFilter_SkEffectType)))
+    , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_SkDescriptorTag, kRasterizer_SkEffectType)))
 
       // Initialize based on our settings. Subclasses can also force this.
     , fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != NULL || fRasterizer != NULL)
diff --git a/effects/SkBlurDrawLooper.cpp b/effects/SkBlurDrawLooper.cpp
index e8407f9..51e6ec9 100644
--- a/effects/SkBlurDrawLooper.cpp
+++ b/effects/SkBlurDrawLooper.cpp
@@ -69,8 +69,8 @@
     fDx = buffer.readScalar();
     fDy = buffer.readScalar();
     fBlurColor = buffer.readColor();
-    fBlur = buffer.readFlattenableT<SkMaskFilter>();
-    fColorFilter = buffer.readFlattenableT<SkColorFilter>();
+    fBlur = buffer.readMaskFilter();
+    fColorFilter = buffer.readColorFilter();
     fBlurFlags = buffer.readUInt() & kAll_BlurFlag;
 }
 
diff --git a/effects/SkColorFilterImageFilter.cpp b/effects/SkColorFilterImageFilter.cpp
index a756a47..fdcc7ff 100755
--- a/effects/SkColorFilterImageFilter.cpp
+++ b/effects/SkColorFilterImageFilter.cpp
@@ -83,7 +83,7 @@
 }
 
 SkColorFilterImageFilter::SkColorFilterImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-    fColorFilter = buffer.readFlattenableT<SkColorFilter>();
+    fColorFilter = buffer.readColorFilter();
 }
 
 void SkColorFilterImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
diff --git a/effects/SkRectShaderImageFilter.cpp b/effects/SkRectShaderImageFilter.cpp
index a240907..e99899e 100644
--- a/effects/SkRectShaderImageFilter.cpp
+++ b/effects/SkRectShaderImageFilter.cpp
@@ -45,7 +45,7 @@
 
 SkRectShaderImageFilter::SkRectShaderImageFilter(SkFlattenableReadBuffer& buffer)
   : INHERITED(buffer) {
-    fShader = buffer.readFlattenableT<SkShader>();
+    fShader = buffer.readShader();
 }
 
 void SkRectShaderImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
diff --git a/effects/SkXfermodeImageFilter.cpp b/effects/SkXfermodeImageFilter.cpp
index 5175fd4..4d30f00 100644
--- a/effects/SkXfermodeImageFilter.cpp
+++ b/effects/SkXfermodeImageFilter.cpp
@@ -34,7 +34,7 @@
 
 SkXfermodeImageFilter::SkXfermodeImageFilter(SkFlattenableReadBuffer& buffer)
   : INHERITED(buffer) {
-    fMode = buffer.readFlattenableT<SkXfermode>();
+    fMode = buffer.readXfermode();
 }
 
 void SkXfermodeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
diff --git a/effects/gradients/SkGradientShader.cpp b/effects/gradients/SkGradientShader.cpp
index 9360ba9..fb8bbac 100644
--- a/effects/gradients/SkGradientShader.cpp
+++ b/effects/gradients/SkGradientShader.cpp
@@ -146,7 +146,7 @@
 SkGradientShaderBase::SkGradientShaderBase(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
     fCacheAlpha = 256;
 
-    fMapper = buffer.readFlattenableT<SkUnitMapper>();
+    fMapper = buffer.readUnitMapper();
 
     fCache16 = fCache16Storage = NULL;
     fCache32 = NULL;
diff --git a/pipe/SkGPipePriv.h b/pipe/SkGPipePriv.h
index 2954ebf..9272496 100644
--- a/pipe/SkGPipePriv.h
+++ b/pipe/SkGPipePriv.h
@@ -19,11 +19,11 @@
 enum PaintFlats {
     kColorFilter_PaintFlat,
     kDrawLooper_PaintFlat,
+    kImageFilter_PaintFlat,
     kMaskFilter_PaintFlat,
     kPathEffect_PaintFlat,
     kRasterizer_PaintFlat,
     kShader_PaintFlat,
-    kImageFilter_PaintFlat,
     kXfermode_PaintFlat,
 
     kLast_PaintFlat = kXfermode_PaintFlat
diff --git a/pipe/SkGPipeRead.cpp b/pipe/SkGPipeRead.cpp
index ac0aadd..e76ec12 100644
--- a/pipe/SkGPipeRead.cpp
+++ b/pipe/SkGPipeRead.cpp
@@ -18,6 +18,7 @@
 #include "SkAnnotation.h"
 #include "SkColorFilter.h"
 #include "SkDrawLooper.h"
+#include "SkImageFilter.h"
 #include "SkMaskFilter.h"
 #include "SkOrderedReadBuffer.h"
 #include "SkPathEffect.h"
@@ -27,6 +28,22 @@
 #include "SkTypeface.h"
 #include "SkXfermode.h"
 
+static SkEffectType paintflat_to_effecttype(PaintFlats pf) {
+    static const uint8_t gEffectTypesInPaintFlatsOrder[] = {
+        kColorFilter_SkEffectType,
+        kDrawLooper_SkEffectType,
+        kImageFilter_SkEffectType,
+        kMaskFilter_SkEffectType,
+        kPathEffect_SkEffectType,
+        kRasterizer_SkEffectType,
+        kShader_SkEffectType,
+        kXfermode_SkEffectType,
+    };
+    
+    SkASSERT((size_t)pf < SK_ARRAY_COUNT(gEffectTypesInPaintFlatsOrder));
+    return (SkEffectType)gEffectTypesInPaintFlatsOrder[pf];
+}
+
 static void set_paintflat(SkPaint* paint, SkFlattenable* obj, unsigned paintFlat) {
     SkASSERT(paintFlat < kCount_PaintFlats);
     switch (paintFlat) {
@@ -105,7 +122,7 @@
 
     void defFlattenable(PaintFlats pf, int index) {
         index--;
-        SkFlattenable* obj = fReader->readFlattenable();
+        SkFlattenable* obj = fReader->readFlattenable(paintflat_to_effecttype(pf));
         if (fFlatArray.count() == index) {
             *fFlatArray.append() = obj;
         } else {