Update SkFlattenable buffers to be more modular.
authordjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 7 Aug 2012 15:54:32 +0000 (15:54 +0000)
committerdjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 7 Aug 2012 15:54:32 +0000 (15:54 +0000)
This CL is an effort to stage the conversion to named
parameters for all SkFlattenable commands. This particular
stage only does the following two things...

1. Move flattenable buffers from SkFlattenable.h into
   their own header.
2. Update and Add new read write methods for better clarity
   and convenience.

BUG=

Review URL: https://codereview.appspot.com/6448095

git-svn-id: http://skia.googlecode.com/svn/trunk@4980 2bbb7eff-a529-9590-31e7-b0007b416f81

75 files changed:
gyp/core.gyp
include/core/SkAnnotation.h
include/core/SkBitmap.h
include/core/SkColorFilter.h
include/core/SkDrawLooper.h
include/core/SkFlattenable.h
include/core/SkFlattenableBuffers.h [new file with mode: 0644]
include/core/SkImageFilter.h
include/core/SkOrderedReadBuffer.h
include/core/SkOrderedWriteBuffer.h
include/core/SkPaint.h
include/core/SkShape.h
include/effects/SkRectShape.h
include/effects/SkTestImageFilters.h
samplecode/ClockFaceView.cpp
samplecode/SampleAll.cpp
samplecode/SampleSlides.cpp
samplecode/SampleText.cpp
samplecode/SampleTextEffects.cpp
src/core/SkAnnotation.cpp
src/core/SkBitmap.cpp
src/core/SkBitmapProcShader.cpp
src/core/SkBlitter.cpp
src/core/SkColorFilter.cpp
src/core/SkColorTable.cpp
src/core/SkComposeShader.cpp
src/core/SkData.cpp
src/core/SkFlattenable.cpp
src/core/SkFlattenableBuffers.cpp [new file with mode: 0644]
src/core/SkGlyphCache.cpp
src/core/SkMallocPixelRef.cpp
src/core/SkOrderedReadBuffer.cpp
src/core/SkOrderedWriteBuffer.cpp
src/core/SkPaint.cpp
src/core/SkPathEffect.cpp
src/core/SkPathHeap.cpp
src/core/SkPictureFlat.cpp
src/core/SkPictureFlat.h
src/core/SkPicturePlayback.cpp
src/core/SkPixelRef.cpp
src/core/SkShader.cpp
src/core/SkXfermode.cpp
src/effects/Sk1DPathEffect.cpp
src/effects/Sk2DPathEffect.cpp
src/effects/SkAvoidXfermode.cpp
src/effects/SkBlurDrawLooper.cpp
src/effects/SkBlurImageFilter.cpp
src/effects/SkBlurMaskFilter.cpp
src/effects/SkColorFilters.cpp
src/effects/SkColorMatrix.cpp
src/effects/SkColorMatrixFilter.cpp
src/effects/SkCornerPathEffect.cpp
src/effects/SkDashPathEffect.cpp
src/effects/SkDiscretePathEffect.cpp
src/effects/SkEmbossMaskFilter.cpp
src/effects/SkGroupShape.cpp
src/effects/SkKernel33MaskFilter.cpp
src/effects/SkLayerDrawLooper.cpp
src/effects/SkLayerRasterizer.cpp
src/effects/SkLightingImageFilter.cpp
src/effects/SkMorphologyImageFilter.cpp
src/effects/SkPixelXorXfermode.cpp
src/effects/SkRectShape.cpp
src/effects/SkTableColorFilter.cpp
src/effects/SkTableMaskFilter.cpp
src/effects/SkTestImageFilters.cpp
src/effects/gradients/SkGradientShader.cpp
src/effects/gradients/SkGradientShaderPriv.h
src/images/SkFlipPixelRef.cpp
src/images/SkImageRef.cpp
src/pdf/SkPDFUtils.h
src/pipe/SkGPipeRead.cpp
src/ports/SkImageRef_ashmem.cpp
src/utils/SkUnitMappers.cpp
tests/ColorFilterTest.cpp

index 376512ba0e6a4abc46acb253891f885113170f52..6af2a57e4e23db0d42993e521ba896ca23d5e84b 100644 (file)
@@ -72,6 +72,7 @@
         '../src/core/SkFilterProc.cpp',
         '../src/core/SkFilterProc.h',
         '../src/core/SkFlattenable.cpp',
+        '../src/core/SkFlattenableBuffers.cpp',
         '../src/core/SkFloat.cpp',
         '../src/core/SkFloat.h',
         '../src/core/SkFloatBits.cpp',
index d401588c3c9533522b74d614d7735ea8f927f261..9cdb2d5ae9d0c065da86149bc8123df1ecb3f2d2 100644 (file)
@@ -12,6 +12,8 @@
 
 class SkData;
 class SkDataSet;
+class SkStream;
+class SkWStream;
 
 /**
  *  Experimental class for annotating draws. Do not use directly yet.
index 9ddd702a1f9eb33017c7d35f0aac5ca42d163dae..b4f86eaee7165d4e1c51ef1d79fc26c3bbd4edd7 100644 (file)
@@ -21,8 +21,6 @@ struct SkRect;
 class SkPaint;
 class SkPixelRef;
 class SkRegion;
-class SkFlattenableReadBuffer;
-class SkFlattenableWriteBuffer;
 
 // This is an opaque class, not interpreted by skia
 class SkGpuTexture;
index 76a0c9367f9b71af2aff042624e81ea85b61c5e1..4c5eee7c136231994bd5e9561a9f44714626ffd5 100644 (file)
@@ -14,6 +14,8 @@
 #include "SkFlattenable.h"
 #include "SkXfermode.h"
 
+class SkBitmap;
+
 class SK_API SkColorFilter : public SkFlattenable {
 public:
     SK_DECLARE_INST_COUNT(SkColorFilter)
index 0e99651fa04a12973be0f8b335bf9da7ad1153b9..f1fb5bdcb912279d69c8a9e4ea12a5db6a901858 100644 (file)
@@ -14,6 +14,7 @@
 
 class SkCanvas;
 class SkPaint;
+struct SkRect;
 
 /** \class SkDrawLooper
     Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are,
index bbd4a80edfccd9d5483d13193943a3383ce683cd..56bc96648fd9a568e5a23a1716cd52d9d12cd330 100644 (file)
 #define SkFlattenable_DEFINED
 
 #include "SkRefCnt.h"
-#include "SkReader32.h"
-#include "SkTDArray.h"
-#include "SkWriter32.h"
 
-class SkBitmap;
 class SkFlattenableReadBuffer;
 class SkFlattenableWriteBuffer;
-class SkPath;
-struct SkPoint;
-class SkString;
 
 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
 
@@ -55,7 +48,7 @@ class SkString;
     virtual Factory getFactory() SK_OVERRIDE { return NULL; }; \
 
 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
-    virtual Factory getFactory() SK_OVERRIDE { return CreateProc; }; \
+    virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } \
     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \
         return SkNEW_ARGS(flattenable, (buffer)); \
     }
@@ -110,116 +103,6 @@ private:
     typedef SkRefCnt INHERITED;
 };
 
-// helpers for matrix and region
-
-class SkMatrix;
-extern void SkReadMatrix(SkReader32*, SkMatrix*);
-extern void SkWriteMatrix(SkWriter32*, const SkMatrix&);
-
-class SkRegion;
-extern void SkReadRegion(SkReader32*, SkRegion*);
-extern void SkWriteRegion(SkWriter32*, const SkRegion&);
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-class SkTypeface;
-
-class SkFlattenableReadBuffer {
-public:
-    enum Flags {
-        kCrossProcess_Flag      = 1 << 0,
-        kScalarIsFloat_Flag     = 1 << 1,
-        kPtrIs64Bit_Flag        = 1 << 2,
-    };
-
-    SkFlattenableReadBuffer();
-    virtual ~SkFlattenableReadBuffer() {}
-
-    void setFlags(uint32_t flags) { fFlags = flags; }
-    uint32_t getFlags() const { return fFlags; }
-
-    bool isCrossProcess() const { return SkToBool(fFlags & kCrossProcess_Flag); }
-    bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); }
-    bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); }
-
-    virtual uint8_t readU8() = 0;
-    virtual uint16_t readU16() = 0;
-    virtual uint32_t readU32() = 0;
-    virtual void read(void* dst, size_t size) = 0;
-    virtual bool readBool() = 0;
-    virtual int32_t readInt() = 0;
-    virtual SkScalar readScalar() = 0;
-    virtual const void* skip(size_t size) = 0;
-
-    virtual int32_t readS32() { return readInt(); }
-    template <typename T> const T& skipT() {
-        SkASSERT(SkAlign4(sizeof(T)) == sizeof(T));
-        return *(const T*)this->skip(sizeof(T));
-    }
-
-    virtual void readMatrix(SkMatrix*) = 0;
-    virtual void readPath(SkPath*) = 0;
-    virtual void readPoint(SkPoint*) = 0;
-
-    // helper function for classes with const SkPoint members
-    SkPoint readPoint() {
-        SkPoint point;
-        this->readPoint(&point);
-        return point;
-    }
-
-    void setRefCntArray(SkRefCnt* array[], int count) {
-        fRCArray = array;
-        fRCCount = count;
-    }
-    
-    void setTypefaceArray(SkTypeface* array[], int count) {
-        fTFArray = array;
-        fTFCount = count;
-    }
-
-    /**
-     *  Call this with a pre-loaded array of Factories, in the same order as
-     *  were created/written by the writer. SkPicture uses this.
-     */
-    void setFactoryPlayback(SkFlattenable::Factory array[], int count) {
-        fFactoryTDArray = NULL;
-        fFactoryArray = array;
-        fFactoryCount = count;
-    }
-
-    /**
-     *  Call this with an initially empty array, so the reader can cache each
-     *  factory it sees by name. Used by the pipe code in combination with
-     *  setNamedFactoryRecorder.
-     */
-    void setFactoryArray(SkTDArray<SkFlattenable::Factory>* array) {
-        fFactoryTDArray = array;
-        fFactoryArray = NULL;
-        fFactoryCount = 0;
-    }
-    
-    virtual SkTypeface* readTypeface() = 0;
-    virtual SkRefCnt* readRefCnt() = 0;
-    virtual void* readFunctionPtr() = 0;
-    virtual SkFlattenable* readFlattenable() = 0;
-
-protected:
-    SkRefCnt** fRCArray;
-    int        fRCCount;
-    
-    SkTypeface** fTFArray;
-    int        fTFCount;
-    
-    SkTDArray<SkFlattenable::Factory>* fFactoryTDArray;
-    SkFlattenable::Factory* fFactoryArray;
-    int                     fFactoryCount;
-
-private:
-    uint32_t    fFlags;
-};
-
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "SkPtrRecorder.h"
@@ -268,89 +151,4 @@ private:
     SkTDArray<const char*> fNames;
 };
 
-class SkFlattenableWriteBuffer {
-public:
-    SkFlattenableWriteBuffer();
-    virtual ~SkFlattenableWriteBuffer();
-
-    // deprecated naming convention that will be removed after callers are updated
-    virtual bool writeBool(bool value) = 0;
-    virtual void writeInt(int32_t value) = 0;
-    virtual void write8(int32_t value) = 0;
-    virtual void write16(int32_t value) = 0;
-    virtual void write32(int32_t value) = 0;
-    virtual void writeScalar(SkScalar value) = 0;
-    virtual void writeMul4(const void* values, size_t size) = 0;
-
-    virtual void writePad(const void* src, size_t size) = 0;
-    virtual void writeString(const char* str, size_t len = (size_t)-1) = 0;
-    virtual uint32_t* reserve(size_t size) = 0;
-    virtual void flatten(void* dst) = 0;
-    virtual uint32_t size() = 0;
-    virtual void write(const void* values, size_t size) = 0;
-    virtual void writeRect(const SkRect& rect) = 0;
-    virtual size_t readFromStream(SkStream*, size_t length) = 0;
-
-    virtual void writeMatrix(const SkMatrix& matrix) = 0;
-    virtual void writePath(const SkPath& path) = 0;
-    virtual void writePoint(const SkPoint& point) = 0;
-
-    virtual bool writeToStream(SkWStream*) = 0;
-
-    virtual void writeFunctionPtr(void*)= 0;
-    virtual void writeFlattenable(SkFlattenable* flattenable)= 0;
-
-    void writeTypeface(SkTypeface*);
-    void writeRefCnt(SkRefCnt* obj);
-
-    SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
-    SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
-
-    SkRefCntSet* getRefCntRecorder() const { return fRCSet; }
-    SkRefCntSet* setRefCntRecorder(SkRefCntSet*);
-
-    SkFactorySet* getFactoryRecorder() const { return fFactorySet; }
-    SkFactorySet* setFactoryRecorder(SkFactorySet*);
-
-    SkNamedFactorySet* getNamedFactoryRecorder() const { return fNamedFactorySet; }
-    SkNamedFactorySet* setNamedFactoryRecorder(SkNamedFactorySet*);
-
-    enum Flags {
-        kCrossProcess_Flag               = 0x01,
-        /**
-         *  Instructs the writer to always serialize bitmap pixel data.
-         */
-        kForceFlattenBitmapPixels_Flag   = 0x04
-    };
-
-    uint32_t getFlags() const { return fFlags; }
-    void setFlags(uint32_t flags) { fFlags = flags; }
-
-    bool isCrossProcess() const {
-        return SkToBool(fFlags & kCrossProcess_Flag);
-    }
-
-    bool persistBitmapPixels() const {
-        return (fFlags & (kCrossProcess_Flag | kForceFlattenBitmapPixels_Flag)) != 0;
-    }
-
-    bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
-
-protected:
-
-    // A helper function so that each subclass does not have to be a friend of
-    // SkFlattenable.
-    void flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer) {
-        obj->flatten(buffer);
-    }
-
-    uint32_t           fFlags;
-    SkRefCntSet*       fTFSet;
-    SkRefCntSet*       fRCSet;
-    SkFactorySet*      fFactorySet;
-    SkNamedFactorySet* fNamedFactorySet;
-
-};
-
 #endif
-
diff --git a/include/core/SkFlattenableBuffers.h b/include/core/SkFlattenableBuffers.h
new file mode 100644 (file)
index 0000000..d87539e
--- /dev/null
@@ -0,0 +1,193 @@
+
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkFlattenableBuffers_DEFINED
+#define SkFlattenableBuffers_DEFINED
+
+#include "SkColor.h"
+#include "SkPaint.h"
+#include "SkPoint.h"
+
+class SkBitmap;
+class SkFlattenable;
+struct SkIRect;
+class SkMatrix;
+class SkOrderedReadBuffer;
+class SkOrderedWriteBuffer;
+class SkPath;
+class SkPixelRef;
+struct SkRect;
+class SkRefCnt;
+class SkRegion;
+class SkStream;
+class SkString;
+class SkTypeface;
+class SkWStream;
+
+class SkFlattenableReadBuffer {
+public:
+    SkFlattenableReadBuffer();
+    virtual ~SkFlattenableReadBuffer();
+
+    bool isOrderedBinaryBuffer() { return NULL != getOrderedBinaryBuffer(); }
+    virtual SkOrderedReadBuffer* getOrderedBinaryBuffer() { return NULL; }
+
+    enum Flags {
+        kCrossProcess_Flag      = 1 << 0,
+        kScalarIsFloat_Flag     = 1 << 1,
+        kPtrIs64Bit_Flag        = 1 << 2,
+    };
+
+    void setFlags(uint32_t flags) { fFlags = flags; }
+    uint32_t getFlags() const { return fFlags; }
+
+    bool isCrossProcess() const { return SkToBool(fFlags & kCrossProcess_Flag); }
+    bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); }
+    bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); }
+
+    // primitives
+    virtual bool readBool() = 0;
+    virtual SkColor readColor() = 0;
+    virtual SkFixed readFixed() = 0;
+    virtual int32_t readInt() = 0;
+    virtual SkScalar readScalar() = 0;
+    virtual uint32_t readUInt() = 0;
+    virtual int32_t read32() = 0;
+
+    // strings -- the caller is responsible for freeing the string contents
+    virtual char* readString() = 0;
+    virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) = 0;
+
+    // common data structures
+    virtual SkFlattenable* readFlattenable() = 0;
+    virtual void readPoint(SkPoint* point) = 0;
+    virtual void readMatrix(SkMatrix* matrix) = 0;
+    virtual void readIRect(SkIRect* rect) = 0;
+    virtual void readRect(SkRect* rect) = 0;
+    virtual void readRegion(SkRegion* region) = 0;
+    virtual void readPath(SkPath* path) = 0;
+
+    // binary data and arrays
+    virtual uint32_t readByteArray(void* value) = 0;
+    virtual uint32_t readColorArray(SkColor* colors) = 0;
+    virtual uint32_t readIntArray(int32_t* values) = 0;
+    virtual uint32_t readPointArray(SkPoint* points) = 0;
+    virtual uint32_t readScalarArray(SkScalar* values) = 0;
+
+    /** This helper peeks into the buffer and reports back the length of the next array in
+     *  the buffer but does not change the state of the buffer.
+     */
+    virtual uint32_t getArrayCount() = 0;
+
+    // helper functions
+    virtual void* readFunctionPtr();
+    virtual void readPaint(SkPaint* paint);
+    virtual SkRefCnt* readRefCntPtr();
+
+    virtual void readBitmap(SkBitmap* bitmap) = 0;
+    virtual SkTypeface* readTypeface() = 0;
+
+    // helper function for classes with const SkPoint members
+    SkPoint readPoint() {
+        SkPoint point;
+        this->readPoint(&point);
+        return point;
+    }
+
+    template <typename T> T* readFlattenableT() {
+        return static_cast<T*>(this->readFlattenable());
+    }
+
+private:
+    uint32_t fFlags;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class SkFlattenableWriteBuffer {
+public:
+    SkFlattenableWriteBuffer();
+    virtual ~SkFlattenableWriteBuffer();
+
+    virtual bool isOrderedBinaryBuffer() { return false; }
+    virtual SkOrderedWriteBuffer* getOrderedBinaryBuffer() { sk_throw(); return NULL; }
+
+    // primitives
+    virtual void writeByteArray(const void* data, size_t size) = 0;
+    virtual void writeBool(bool value) = 0;
+    virtual void writeFixed(SkFixed value) = 0;
+    virtual void writeScalar(SkScalar value) = 0;
+    virtual void writeScalarArray(const SkScalar* value, uint32_t count) = 0;
+    virtual void writeInt(int32_t value) = 0;
+    virtual void writeIntArray(const int32_t* value, uint32_t count) = 0;
+    virtual void writeUInt(uint32_t value) = 0;
+    virtual void write32(int32_t value) = 0; // printf in hex
+    virtual void writeString(const char* value) = 0;
+    virtual void writeEncodedString(const void* value, size_t byteLength,
+                                    SkPaint::TextEncoding encoding) = 0;
+
+    // common data structures
+    virtual void writeFlattenable(SkFlattenable* flattenable) = 0;
+    virtual void writeColor(const SkColor& color) = 0;
+    virtual void writeColorArray(const SkColor* color, uint32_t count) = 0;
+    virtual void writePoint(const SkPoint& point) = 0;
+    virtual void writePointArray(const SkPoint* points, uint32_t count) = 0;
+    virtual void writeMatrix(const SkMatrix& matrix) = 0;
+    virtual void writeIRect(const SkIRect& rect) = 0;
+    virtual void writeRect(const SkRect& rect) = 0;
+    virtual void writeRegion(const SkRegion& region) = 0;
+    virtual void writePath(const SkPath& path) = 0;
+    virtual size_t writeStream(SkStream* stream, size_t length) = 0;
+
+    // helper functions
+    virtual void writeFunctionPtr(void* ptr);
+    virtual void writePaint(const SkPaint& paint);
+    virtual void writeRefCntPtr(SkRefCnt* refCnt);
+
+    virtual void writeBitmap(const SkBitmap& bitmap) = 0;
+    virtual void writeTypeface(SkTypeface* typeface) = 0;
+
+    virtual bool writeToStream(SkWStream*) = 0;
+
+    enum Flags {
+        kCrossProcess_Flag               = 0x01,
+        /**
+         *  Instructs the writer to inline Factory names as there are seen the
+         *  first time (after that we store an index). The pipe code uses this.
+         */
+        kInlineFactoryNames_Flag         = 0x02,
+        /**
+         *  Instructs the writer to always serialize bitmap pixel data.
+         */
+        kForceFlattenBitmapPixels_Flag   = 0x04,
+    };
+
+    uint32_t getFlags() const { return fFlags; }
+    void setFlags(uint32_t flags) { fFlags = flags; }
+
+    bool isCrossProcess() const {
+        return SkToBool(fFlags & kCrossProcess_Flag);
+    }
+    bool inlineFactoryNames() const {
+        return SkToBool(fFlags & kInlineFactoryNames_Flag);
+    }
+
+    bool persistBitmapPixels() const {
+        return (fFlags & (kCrossProcess_Flag | kForceFlattenBitmapPixels_Flag)) != 0;
+    }
+
+    bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
+
+protected:
+    // A helper function so that each subclass does not have to be a friend of SkFlattenable
+    void flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer);
+
+    uint32_t fFlags;
+};
+
+#endif
index b16fb0f7a294e5552cbbf4e51238042ae9c4b1b0..1c0a05159fd0ab38b42e665aa70a51df24d6368f 100644 (file)
@@ -9,11 +9,15 @@
 #define SkImageFilter_DEFINED
 
 #include "SkFlattenable.h"
+#include "SkSize.h"
 
 class SkBitmap;
 class SkDevice;
 class SkMatrix;
+struct SkIPoint;
+struct SkIRect;
 struct SkPoint;
+struct SkRect;
 class GrCustomStage;
 class GrTexture;
 
index 12b74d1cdc9e295b38759cb664f25c8dd9fad12b..5651e7c1e7df6f5b99369d68fb06ce133390a017 100644 (file)
 
 #include "SkRefCnt.h"
 #include "SkBitmap.h"
-#include "SkFlattenable.h"
-#include "SkWriter32.h"
+#include "SkFlattenableBuffers.h"
+#include "SkReader32.h"
 #include "SkPath.h"
 
 class SkOrderedReadBuffer : public SkFlattenableReadBuffer {
 public:
     SkOrderedReadBuffer() : INHERITED() {}
     SkOrderedReadBuffer(const void* data, size_t size);
+    SkOrderedReadBuffer(SkStream* stream);
+    virtual ~SkOrderedReadBuffer();
+
+    virtual SkOrderedReadBuffer* getOrderedBinaryBuffer() SK_OVERRIDE { return this; }
+
+    SkReader32* getReader32() { return &fReader; }
 
-    void setMemory(const void* data, size_t size) { fReader.setMemory(data, size); }
     uint32_t size() { return fReader.size(); }
-    const void* base() { return fReader.base(); }
     uint32_t offset() { return fReader.offset(); }
     bool eof() { return fReader.eof(); }
-    void rewind() { fReader.rewind(); }
-    void setOffset(size_t offset) { fReader.setOffset(offset); }
+    const void* skip(size_t size) { return fReader.skip(size); }
 
-    SkReader32* getReader32() { return &fReader; }
+    // primitives
+    virtual bool readBool() SK_OVERRIDE;
+    virtual SkColor readColor() SK_OVERRIDE;
+    virtual SkFixed readFixed() SK_OVERRIDE;
+    virtual int32_t readInt() SK_OVERRIDE;
+    virtual SkScalar readScalar() SK_OVERRIDE;
+    virtual uint32_t readUInt() SK_OVERRIDE;
+    virtual int32_t read32() SK_OVERRIDE;
+
+    // strings -- the caller is responsible for freeing the string contents
+    virtual char* readString() SK_OVERRIDE;
+    virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) SK_OVERRIDE;
+
+    // common data structures
+    virtual SkFlattenable* readFlattenable() SK_OVERRIDE;
+    virtual void readPoint(SkPoint* point) SK_OVERRIDE;
+    virtual void readMatrix(SkMatrix* matrix) SK_OVERRIDE;
+    virtual void readIRect(SkIRect* rect) SK_OVERRIDE;
+    virtual void readRect(SkRect* rect) SK_OVERRIDE;
+    virtual void readRegion(SkRegion* region) SK_OVERRIDE;
+    virtual void readPath(SkPath* path) SK_OVERRIDE;
+
+    // binary data and arrays
+    virtual uint32_t readByteArray(void* value) SK_OVERRIDE;
+    virtual uint32_t readColorArray(SkColor* colors) SK_OVERRIDE;
+    virtual uint32_t readIntArray(int32_t* values) SK_OVERRIDE;
+    virtual uint32_t readPointArray(SkPoint* points) SK_OVERRIDE;
+    virtual uint32_t readScalarArray(SkScalar* values) SK_OVERRIDE;
+
+    // helpers to get info about arrays and binary data
+    virtual uint32_t getArrayCount() SK_OVERRIDE;
+
+    virtual SkRefCnt* readRefCntPtr() SK_OVERRIDE;
+
+    virtual void readBitmap(SkBitmap* bitmap) SK_OVERRIDE;
+    virtual SkTypeface* readTypeface() SK_OVERRIDE;
 
-    virtual uint8_t readU8() { return fReader.readU8(); }
-    virtual uint16_t readU16() { return fReader.readU16(); }
-    virtual uint32_t readU32() { return fReader.readU32(); }
-    virtual void read(void* dst, size_t size) { return fReader.read(dst, size); }
-    virtual bool readBool() { return fReader.readBool(); }
-    virtual int32_t readInt() { return fReader.readInt(); }
-    virtual SkScalar readScalar() { return fReader.readScalar(); }
-    virtual const void* skip(size_t size) { return fReader.skip(size); }
-
-    virtual void readMatrix(SkMatrix* m) { fReader.readMatrix(m); }
-    virtual void readPath(SkPath* p) { fReader.readPath(p); }
-
-    virtual void readPoint(SkPoint* p) {
-        p->fX = fReader.readScalar();
-        p->fY = fReader.readScalar();
+    void setRefCntArray(SkRefCnt* array[], int count) {
+        fRCArray = array;
+        fRCCount = count;
     }
 
-    virtual SkTypeface* readTypeface();
-    virtual SkRefCnt* readRefCnt();
-    virtual void* readFunctionPtr();
-    virtual SkFlattenable* readFlattenable();
+    void setTypefaceArray(SkTypeface* array[], int count) {
+        fTFArray = array;
+        fTFCount = count;
+    }
+
+    /**
+     *  Call this with a pre-loaded array of Factories, in the same order as
+     *  were created/written by the writer. SkPicture uses this.
+     */
+    void setFactoryPlayback(SkFlattenable::Factory array[], int count) {
+        fFactoryTDArray = NULL;
+        fFactoryArray = array;
+        fFactoryCount = count;
+    }
+
+    /**
+     *  Call this with an initially empty array, so the reader can cache each
+     *  factory it sees by name. Used by the pipe code in conjunction with
+     *  the writer's kInlineFactoryNames_Flag.
+     */
+    void setFactoryArray(SkTDArray<SkFlattenable::Factory>* array) {
+        fFactoryTDArray = array;
+        fFactoryArray = NULL;
+        fFactoryCount = 0;
+    }
 
 private:
     SkReader32 fReader;
+    void* fMemoryPtr;
+
+    SkRefCnt** fRCArray;
+    int        fRCCount;
+
+    SkTypeface** fTFArray;
+    int        fTFCount;
+
+    SkTDArray<SkFlattenable::Factory>* fFactoryTDArray;
+    SkFlattenable::Factory* fFactoryArray;
+    int                     fFactoryCount;
 
     typedef SkFlattenableReadBuffer INHERITED;
 };
 
 #endif // SkOrderedReadBuffer_DEFINED
-
index 64687197cf361357dc9128a5575c17b309c1bd41..8cd2d810f196c5f4f4e95f39c98a209e4f0fd6d9 100644 (file)
@@ -9,55 +9,81 @@
 #ifndef SkOrderedWriteBuffer_DEFINED
 #define SkOrderedWriteBuffer_DEFINED
 
+#include "SkFlattenableBuffers.h"
+
 #include "SkRefCnt.h"
 #include "SkBitmap.h"
-#include "SkFlattenable.h"
-#include "SkWriter32.h"
 #include "SkPath.h"
+#include "SkWriter32.h"
+
+class SkFlattenable;
 
 class SkOrderedWriteBuffer : public SkFlattenableWriteBuffer {
 public:
     SkOrderedWriteBuffer(size_t minSize);
     SkOrderedWriteBuffer(size_t minSize, void* initialStorage,
                          size_t storageSize);
-    virtual ~SkOrderedWriteBuffer() {}
+    virtual ~SkOrderedWriteBuffer();
+
+    virtual bool isOrderedBinaryBuffer() SK_OVERRIDE { return true; }
+    virtual SkOrderedWriteBuffer* getOrderedBinaryBuffer() SK_OVERRIDE { return this; }
 
     SkWriter32* getWriter32() { return &fWriter; }
 
-    // deprecated naming convention that will be removed after callers are updated
-    virtual bool writeBool(bool value) { return fWriter.writeBool(value); }
-    virtual void writeInt(int32_t value) { fWriter.writeInt(value); }
-    virtual void write8(int32_t value) { fWriter.write8(value); }
-    virtual void write16(int32_t value) { fWriter.write16(value); }
-    virtual void write32(int32_t value) { fWriter.write32(value); }
-    virtual void writeScalar(SkScalar value) { fWriter.writeScalar(value); }
-    virtual void writeMul4(const void* values, size_t size) { fWriter.writeMul4(values, size); }
-
-    virtual void writePad(const void* src, size_t size) { fWriter.writePad(src, size); }
-    virtual void writeString(const char* str, size_t len = (size_t)-1) { fWriter.writeString(str, len); }
-    virtual bool writeToStream(SkWStream* stream) { return fWriter.writeToStream(stream); }
-    virtual void write(const void* values, size_t size) { fWriter.write(values, size); }
-    virtual void writeRect(const SkRect& rect) { fWriter.writeRect(rect); }
-    virtual size_t readFromStream(SkStream* s, size_t length) { return fWriter.readFromStream(s, length); }
-
-    virtual void writeMatrix(const SkMatrix& matrix) { fWriter.writeMatrix(matrix); }
-    virtual void writePath(const SkPath& path) { fWriter.writePath(path); };
-    virtual void writePoint(const SkPoint& point) {
-        fWriter.writeScalar(point.fX);
-        fWriter.writeScalar(point.fY);
-    }
-
-    virtual uint32_t* reserve(size_t size) { return fWriter.reserve(size); }
-    virtual void flatten(void* dst) { fWriter.flatten(dst); }
-    virtual uint32_t size() { return fWriter.size(); }
-
-    virtual void writeFunctionPtr(void*);
-    virtual void writeFlattenable(SkFlattenable* flattenable);
+    void writeToMemory(void* dst) { fWriter.flatten(dst); }
+    uint32_t* reserve(size_t size) { return fWriter.reserve(size); }
+    uint32_t size() { return fWriter.size(); }
+
+    virtual void writeByteArray(const void* data, size_t size) SK_OVERRIDE;
+    virtual void writeBool(bool value) SK_OVERRIDE;
+    virtual void writeFixed(SkFixed value) SK_OVERRIDE;
+    virtual void writeScalar(SkScalar value) SK_OVERRIDE;
+    virtual void writeScalarArray(const SkScalar* value, uint32_t count) SK_OVERRIDE;
+    virtual void writeInt(int32_t value) SK_OVERRIDE;
+    virtual void writeIntArray(const int32_t* value, uint32_t count) SK_OVERRIDE;
+    virtual void writeUInt(uint32_t value) SK_OVERRIDE;
+    virtual void write32(int32_t value) SK_OVERRIDE;
+    virtual void writeString(const char* value) SK_OVERRIDE;
+    virtual void writeEncodedString(const void* value, size_t byteLength,
+                                    SkPaint::TextEncoding encoding) SK_OVERRIDE;
+
+    virtual void writeFlattenable(SkFlattenable* flattenable) SK_OVERRIDE;
+    virtual void writeColor(const SkColor& color) SK_OVERRIDE;
+    virtual void writeColorArray(const SkColor* color, uint32_t count) SK_OVERRIDE;
+    virtual void writePoint(const SkPoint& point) SK_OVERRIDE;
+    virtual void writePointArray(const SkPoint* point, uint32_t count) SK_OVERRIDE;
+    virtual void writeMatrix(const SkMatrix& matrix) SK_OVERRIDE;
+    virtual void writeIRect(const SkIRect& rect)SK_OVERRIDE;
+    virtual void writeRect(const SkRect& rect) SK_OVERRIDE;
+    virtual void writeRegion(const SkRegion& region) SK_OVERRIDE;
+    virtual void writePath(const SkPath& path) SK_OVERRIDE;
+    virtual size_t writeStream(SkStream* stream, size_t length) SK_OVERRIDE;
+
+    virtual void writeRefCntPtr(SkRefCnt* refCnt) SK_OVERRIDE;
+
+    virtual void writeBitmap(const SkBitmap& bitmap) SK_OVERRIDE;
+    virtual void writeTypeface(SkTypeface* typeface) SK_OVERRIDE;
+
+    virtual bool writeToStream(SkWStream*) SK_OVERRIDE;
+
+    SkFactorySet* setFactoryRecorder(SkFactorySet*);
+    SkNamedFactorySet* setNamedFactoryRecorder(SkNamedFactorySet*);
+
+    SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
+    SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
+
+    SkRefCntSet* getRefCntRecorder() const { return fRCSet; }
+    SkRefCntSet* setRefCntRecorder(SkRefCntSet*);
 
 private:
+    SkFactorySet* fFactorySet;
+    SkNamedFactorySet* fNamedFactorySet;
     SkWriter32 fWriter;
+
+    SkRefCntSet*    fRCSet;
+    SkRefCntSet*    fTFSet;
+
     typedef SkFlattenableWriteBuffer INHERITED;
 };
 
 #endif // SkOrderedWriteBuffer_DEFINED
-
index 4defe8b66821cdfbe2d6fe3ef8cea3030733820b..0e68f03fcf4ef305734723933163ecf04bf0654a 100644 (file)
@@ -29,6 +29,7 @@ class SkMaskFilter;
 class SkMatrix;
 class SkPath;
 class SkPathEffect;
+struct SkPoint;
 class SkRasterizer;
 class SkShader;
 class SkTypeface;
index 4f2bd98307288c6cff56f586e08b33f6639db110..1a149b1184b483032ebc37843b5922bc297a6cb3 100644 (file)
@@ -9,6 +9,7 @@
 #define SkShape_DEFINED
 
 #include "SkFlattenable.h"
+#include "SkScalar.h"
 
 class SkCanvas;
 class SkMatrix;
index a06adfc3ba5b36c016f987b84b60ce5dd1bfba6a..88a3646b14cd95ddfc95993294907baf6050ab4e 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "SkShape.h"
 #include "SkPaint.h"
+#include "SkRect.h"
 #include "SkSize.h"
 
 class SkPaintShape : public SkShape {
index a28ed8b98c744ca5260b8d218c01e75fbd060da1..bb873e9d37377c4469a455cc60e7dd4ecc337eec 100755 (executable)
@@ -4,6 +4,7 @@
 
 #include "SkImageFilter.h"
 #include "SkColorFilter.h"
+#include "SkPoint.h"
 
 class SkOffsetImageFilter : public SkImageFilter {
 public:
index 7d4da1051b75754dfb746fbda2305f55087086fd..a719608cad75910af42f4a45182de9ccf061378d 100644 (file)
@@ -8,6 +8,7 @@
 #include "SampleCode.h"
 #include "SkView.h"
 #include "SkCanvas.h"
+#include "SkFlattenableBuffers.h"
 #include "SkGradientShader.h"
 #include "SkPath.h"
 #include "SkRegion.h"
index 303059be42cd4dc5c6b5cdadca805ab5cd27d9bc..9644e79599611c3b2f71593a1750412681b48610 100644 (file)
@@ -18,6 +18,7 @@
 #include "SkDashPathEffect.h"
 #include "SkDiscretePathEffect.h"
 #include "SkEmbossMaskFilter.h"
+#include "SkFlattenableBuffers.h"
 #include "SkGradientShader.h"
 #include "SkImageDecoder.h"
 #include "SkLayerRasterizer.h"
index 1154c764d840d42fc14ad1d92e89c5404a216a7e..54a9cf95fcf916bf6b189099dd7e6b13137365fe 100644 (file)
@@ -9,6 +9,7 @@
 #include "SkView.h"
 #include "SkCanvas.h"
 #include "SkDevice.h"
+#include "SkFlattenableBuffers.h"
 #include "SkPaint.h"
 
 #define BG_COLOR    0xFFDDDDDD
index db4dbeaef2f4d74aa0d7f0aa580fc343be2835ed..7d192f4a285f163b950331b848792fafd64cc387 100644 (file)
@@ -9,6 +9,7 @@
 #include "SkView.h"
 #include "SkCanvas.h"
 #include "Sk64.h"
+#include "SkFlattenableBuffers.h"
 #include "SkGradientShader.h"
 #include "SkGraphics.h"
 #include "SkImageDecoder.h"
@@ -134,11 +135,11 @@ private:
     void init(SkScalar exponent);
     SkPowerMode(SkFlattenableReadBuffer& b) : INHERITED(b) {
         // read the exponent
-        this->init(SkFixedToScalar(b.readS32()));
+        this->init(SkFixedToScalar(b.readFixed()));
     }
     virtual void flatten(SkFlattenableWriteBuffer& b) const SK_OVERRIDE {
         this->INHERITED::flatten(b);
-        b.write32(SkScalarToFixed(fExp));
+        b.writeFixed(SkScalarToFixed(fExp));
     }
 
     typedef SkXfermode INHERITED;
index 215154894ecba652a8e27122578a6b2a74ed5a22..b2feae77a1f1ab0dabd7747ef0525514c47090f9 100644 (file)
@@ -8,6 +8,7 @@
 #include "SampleCode.h"
 #include "SkView.h"
 #include "SkCanvas.h"
+#include "SkFlattenableBuffers.h"
 #include "SkGradientShader.h"
 #include "SkPath.h"
 #include "SkRegion.h"
index 2dc684ede454ca1a210bb3c858f97008cb0cc863..62f865d15fbf728fc8882c5cdfc2eb1490623662 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "SkAnnotation.h"
 #include "SkDataSet.h"
+#include "SkFlattenableBuffers.h"
 #include "SkStream.h"
 
 SkAnnotation::SkAnnotation(SkDataSet* data, uint32_t flags) {
@@ -28,12 +29,12 @@ SkData* SkAnnotation::find(const char name[]) const {
 }
 
 SkAnnotation::SkAnnotation(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-    fFlags = buffer.readU32();
-    fDataSet = (SkDataSet*)buffer.readFlattenable();
+    fFlags = buffer.readUInt();
+    fDataSet = buffer.readFlattenableT<SkDataSet>();
 }
 
 void SkAnnotation::flatten(SkFlattenableWriteBuffer& buffer) const {
-    buffer.write32(fFlags);
+    buffer.writeUInt(fFlags);
     buffer.writeFlattenable(fDataSet);
 }
 
index f135d48fa47e8446bc7815dc9a24acc0cb5c15c4..70060f290186ada3af98aa899054b7a6c0acf4cb 100644 (file)
@@ -13,6 +13,8 @@
 #include "SkFlattenable.h"
 #include "SkMallocPixelRef.h"
 #include "SkMask.h"
+#include "SkOrderedReadBuffer.h"
+#include "SkOrderedWriteBuffer.h"
 #include "SkPixelRef.h"
 #include "SkThread.h"
 #include "SkUnPreMultiply.h"
@@ -1379,10 +1381,10 @@ enum {
     when to create a new texture.
 */
 void SkBitmap::flatten(SkFlattenableWriteBuffer& buffer) const {
-    buffer.write32(fWidth);
-    buffer.write32(fHeight);
-    buffer.write32(fRowBytes);
-    buffer.write8(fConfig);
+    buffer.writeInt(fWidth);
+    buffer.writeInt(fHeight);
+    buffer.writeInt(fRowBytes);
+    buffer.writeInt(fConfig);
     buffer.writeBool(this->isOpaque());
 
     /*  If we are called in this mode, then it is up to the caller to manage
@@ -1390,16 +1392,16 @@ void SkBitmap::flatten(SkFlattenableWriteBuffer& buffer) const {
     */
     if (!buffer.persistBitmapPixels()) {
         if (fPixelRef) {
-            buffer.write8(SERIALIZE_PIXELTYPE_REF_PTR);
-            buffer.write32(fPixelRefOffset);
-            buffer.writeRefCnt(fPixelRef);
+            buffer.writeInt(SERIALIZE_PIXELTYPE_REF_PTR);
+            buffer.writeUInt(fPixelRefOffset);
+            buffer.writeRefCntPtr(fPixelRef);
             return;
         } else {
             // we ignore the non-persist request, since we don't have a ref
             // ... or we could just write an empty bitmap...
             // (true) will write an empty bitmap, (false) will flatten the pix
             if (true) {
-                buffer.write8(SERIALIZE_PIXELTYPE_NONE);
+                buffer.writeInt(SERIALIZE_PIXELTYPE_NONE);
                 return;
             }
         }
@@ -1407,15 +1409,15 @@ void SkBitmap::flatten(SkFlattenableWriteBuffer& buffer) const {
 
     if (fPixelRef) {
         if (fPixelRef->getFactory()) {
-            buffer.write8(SERIALIZE_PIXELTYPE_REF_DATA);
-            buffer.write32(fPixelRefOffset);
+            buffer.writeInt(SERIALIZE_PIXELTYPE_REF_DATA);
+            buffer.writeUInt(fPixelRefOffset);
             buffer.writeFlattenable(fPixelRef);
             return;
         }
         // if we get here, we can't record the pixels
-        buffer.write8(SERIALIZE_PIXELTYPE_NONE);
+        buffer.writeInt(SERIALIZE_PIXELTYPE_NONE);
     } else {
-        buffer.write8(SERIALIZE_PIXELTYPE_NONE);
+        buffer.writeInt(SERIALIZE_PIXELTYPE_NONE);
     }
 }
 
@@ -1425,22 +1427,22 @@ void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) {
     int width = buffer.readInt();
     int height = buffer.readInt();
     int rowBytes = buffer.readInt();
-    int config = buffer.readU8();
+    int config = buffer.readInt();
 
     this->setConfig((Config)config, width, height, rowBytes);
     this->setIsOpaque(buffer.readBool());
 
-    int reftype = buffer.readU8();
+    int reftype = buffer.readInt();
     switch (reftype) {
         case SERIALIZE_PIXELTYPE_REF_PTR: {
-            size_t offset = buffer.readU32();
-            SkPixelRef* pr = (SkPixelRef*)buffer.readRefCnt();
+            size_t offset = buffer.readUInt();
+            SkPixelRef* pr = (SkPixelRef*)buffer.readRefCntPtr();
             this->setPixelRef(pr, offset);
             break;
         }
         case SERIALIZE_PIXELTYPE_REF_DATA: {
-            size_t offset = buffer.readU32();
-            SkPixelRef* pr = static_cast<SkPixelRef*>(buffer.readFlattenable());
+            size_t offset = buffer.readUInt();
+            SkPixelRef* pr = buffer.readFlattenableT<SkPixelRef>();
             SkSafeUnref(this->setPixelRef(pr, offset));
             break;
         }
index 9b88c687e8a3f0fb2924c1f378aa78c2fb460bdf..dc669ccf4cacab348f4f2cbe347a36a530a11da5 100644 (file)
@@ -7,6 +7,7 @@
  */
 #include "SkBitmapProcShader.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 #include "SkPixelRef.h"
 
 bool SkBitmapProcShader::CanDo(const SkBitmap& bm, TileMode tx, TileMode ty) {
@@ -33,9 +34,9 @@ SkBitmapProcShader::SkBitmapProcShader(const SkBitmap& src,
 
 SkBitmapProcShader::SkBitmapProcShader(SkFlattenableReadBuffer& buffer)
         : INHERITED(buffer) {
-    fRawBitmap.unflatten(buffer);
-    fState.fTileModeX = buffer.readU8();
-    fState.fTileModeY = buffer.readU8();
+    buffer.readBitmap(&fRawBitmap);
+    fState.fTileModeX = buffer.readUInt();
+    fState.fTileModeY = buffer.readUInt();
     fFlags = 0; // computed in setContext
 }
 
@@ -70,9 +71,9 @@ SkShader::BitmapType SkBitmapProcShader::asABitmap(SkBitmap* texture,
 void SkBitmapProcShader::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
 
-    fRawBitmap.flatten(buffer);
-    buffer.write8(fState.fTileModeX);
-    buffer.write8(fState.fTileModeY);
+    buffer.writeBitmap(fRawBitmap);
+    buffer.writeUInt(fState.fTileModeX);
+    buffer.writeUInt(fState.fTileModeY);
 }
 
 static bool only_scale_and_translate(const SkMatrix& matrix) {
index fda8d41adaa37aefc488a8a9c64dd0031f48bde0..02f7160ae123fb62bad91d961ea5b107d200d37f 100644 (file)
@@ -12,6 +12,7 @@
 #include "SkColor.h"
 #include "SkColorFilter.h"
 #include "SkFilterShader.h"
+#include "SkFlattenableBuffers.h"
 #include "SkMask.h"
 #include "SkMaskFilter.h"
 #include "SkTemplatesPriv.h"
@@ -662,15 +663,15 @@ public:
 
 protected:
     Sk3DShader(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-        fProxy = static_cast<SkShader*>(buffer.readFlattenable());
-        fPMColor = buffer.readU32();
+        fProxy = buffer.readFlattenableT<SkShader>();
+        fPMColor = buffer.readColor();
         fMask = NULL;
     }
 
     virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE {
         this->INHERITED::flatten(buffer);
         buffer.writeFlattenable(fProxy);
-        buffer.write32(fPMColor);
+        buffer.writeColor(fPMColor);
     }
 
 private:
index e781350023b232d42c8558de19004dc693ce229f..82a85f419e44fee0ad8d482d4c5ae079ba792baa 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "SkColorFilter.h"
 #include "SkFilterShader.h"
+#include "SkFlattenableBuffers.h"
 #include "SkShader.h"
 #include "SkUnPreMultiply.h"
 
@@ -48,8 +49,8 @@ SkFilterShader::SkFilterShader(SkShader* shader, SkColorFilter* filter) {
 
 SkFilterShader::SkFilterShader(SkFlattenableReadBuffer& buffer) :
         INHERITED(buffer) {
-    fShader = static_cast<SkShader*>(buffer.readFlattenable());
-    fFilter = static_cast<SkColorFilter*>(buffer.readFlattenable());
+    fShader = buffer.readFlattenableT<SkShader>();
+    fFilter = buffer.readFlattenableT<SkColorFilter>();
 }
 
 SkFilterShader::~SkFilterShader() {
index 3711de5836c6e18055c8e97db5b830befa036ee7..ce143f83ebc98aae3dba1763a6ec25350e953259 100644 (file)
@@ -8,6 +8,7 @@
 
 
 #include "SkColorTable.h"
+#include "SkFlattenableBuffers.h"
 #include "SkStream.h"
 #include "SkTemplates.h"
 
@@ -142,20 +143,17 @@ SkColorTable::SkColorTable(SkFlattenableReadBuffer& buffer) {
     SkDEBUGCODE(fColorLockCount = 0;)
     SkDEBUGCODE(f16BitCacheLockCount = 0;)
 
-    fCount = buffer.readU16();
-    SkASSERT((unsigned)fCount <= 256);
-
-    fFlags = buffer.readU8();
-
+    fFlags = buffer.readUInt();
+    fCount = buffer.getArrayCount();
     fColors = (SkPMColor*)sk_malloc_throw(fCount * sizeof(SkPMColor));
-    buffer.read(fColors, fCount * sizeof(SkPMColor));
+    const uint32_t countRead = buffer.readColorArray(fColors);
+    SkASSERT((unsigned)fCount <= 256);
+    SkASSERT(countRead == fCount);
 }
 
 void SkColorTable::flatten(SkFlattenableWriteBuffer& buffer) const {
-    int count = this->count();
-    buffer.write16(count);
-    buffer.write8(this->getFlags());
-    buffer.writeMul4(fColors, count * sizeof(SkPMColor));
+    buffer.writeUInt(fFlags);
+    buffer.writeColorArray(fColors, fCount);
 }
 
 SK_DEFINE_FLATTENABLE_REGISTRAR(SkColorTable)
index 90e4953422b684df35d3470c9e9d81d9dada4c76..af3f3a5f2084f98d54b881fb6c787dbe255ec5d5 100644 (file)
@@ -11,6 +11,7 @@
 #include "SkColorFilter.h"
 #include "SkColorPriv.h"
 #include "SkColorShader.h"
+#include "SkFlattenableBuffers.h"
 #include "SkXfermode.h"
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -25,15 +26,15 @@ SkComposeShader::SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode) {
 
 SkComposeShader::SkComposeShader(SkFlattenableReadBuffer& buffer) :
     INHERITED(buffer) {
-    fShaderA = static_cast<SkShader*>(buffer.readFlattenable());
+    fShaderA = buffer.readFlattenableT<SkShader>();
     if (NULL == fShaderA) {
         fShaderA = SkNEW_ARGS(SkColorShader, (0));
     }
-    fShaderB = static_cast<SkShader*>(buffer.readFlattenable());
+    fShaderB = buffer.readFlattenableT<SkShader>();
     if (NULL == fShaderB) {
         fShaderB = SkNEW_ARGS(SkColorShader, (0));
     }
-    fMode = static_cast<SkXfermode*>(buffer.readFlattenable());
+    fMode = buffer.readFlattenableT<SkXfermode>();
 }
 
 SkComposeShader::~SkComposeShader() {
index 261b5714362a69fed1befea2d0a42403148bfb67..5dbc206d8e3be232140609ffe5bd89605c2c18e0 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "SkData.h"
+#include "SkFlattenableBuffers.h"
 
 SK_DEFINE_INST_COUNT(SkData)
 
@@ -122,25 +123,22 @@ SkData* SkData::NewWithCString(const char cstr[]) {
 ///////////////////////////////////////////////////////////////////////////////
 
 void SkData::flatten(SkFlattenableWriteBuffer& buffer) const {
-    buffer.write32(fSize);
-    buffer.writePad(fPtr, fSize);
+    buffer.writeByteArray(fPtr, fSize);
 }
 
 SkData::SkData(SkFlattenableReadBuffer& buffer) {
-    fSize = buffer.readU32();
+    fSize = buffer.getArrayCount();
     fReleaseProcContext = NULL;
 
-    if (0 == fSize) {
+    if (fSize > 0) {
+        fPtr = sk_malloc_throw(fSize);
+        fReleaseProc = sk_free_releaseproc;
+    } else {
         fPtr = NULL;
         fReleaseProc = NULL;
-    } else {
-        // buffer.read expects a 4-byte aligned size
-        size_t size4 = SkAlign4(fSize);
-        void* data = sk_malloc_throw(size4);
-        buffer.read(data, size4);
-        fPtr = data;
-        fReleaseProc = sk_free_releaseproc;
     }
+
+    buffer.readByteArray(const_cast<void*>(fPtr));
 }
 
 SK_DEFINE_FLATTENABLE_REGISTRAR(SkData)
@@ -247,11 +245,9 @@ void SkDataSet::writeToStream(SkWStream* stream) const {
 }
 
 void SkDataSet::flatten(SkFlattenableWriteBuffer& buffer) const {
-    buffer.write32(fCount);
+    buffer.writeInt(fCount);
     if (fCount > 0) {
-        buffer.write32(fKeySize);
-        // our first key points to all the key storage
-        buffer.writePad(fPairs[0].fKey, fKeySize);
+        buffer.writeByteArray(fPairs[0].fKey, fKeySize);
         for (int i = 0; i < fCount; ++i) {
             buffer.writeFlattenable(fPairs[i].fValue);
         }
@@ -279,19 +275,18 @@ SkDataSet::SkDataSet(SkStream* stream) {
 }
 
 SkDataSet::SkDataSet(SkFlattenableReadBuffer& buffer) {
-    fCount = buffer.readU32();
+    fCount = buffer.readInt();
     if (fCount > 0) {
-        fKeySize = buffer.readU32();
-        // we align fKeySize, since buffer.read needs to read a mul4 amount
-        fPairs = allocatePairStorage(fCount, SkAlign4(fKeySize));
+        fKeySize = buffer.getArrayCount();
+        fPairs = allocatePairStorage(fCount, fKeySize);
         char* keyStorage = (char*)(fPairs + fCount);
         
-        buffer.read(keyStorage, SkAlign4(fKeySize));
+        buffer.readByteArray(keyStorage);
         
         for (int i = 0; i < fCount; ++i) {
             fPairs[i].fKey = keyStorage;
             keyStorage += strlen(keyStorage) + 1;
-            fPairs[i].fValue = (SkData*)buffer.readFlattenable();
+            fPairs[i].fValue = buffer.readFlattenableT<SkData>();
         }
     } else {
         fKeySize = 0;
index 60c04b14c76b2936235f41027e8e791ae3c3a26b..0523c68dbaab93679764fcf3d19f0a89aedbb665 100644 (file)
@@ -6,7 +6,6 @@
  * found in the LICENSE file.
  */
 #include "SkFlattenable.h"
-#include "SkTypeface.h"
 
 SK_DEFINE_INST_COUNT(SkFlattenable)
 
@@ -22,30 +21,6 @@ void SkFlattenable::flatten(SkFlattenableWriteBuffer&) const
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkFlattenableReadBuffer::SkFlattenableReadBuffer() {
-    fRCArray = NULL;
-    fRCCount = 0;
-
-    fTFArray = NULL;
-    fTFCount = 0;
-
-    fFactoryTDArray = NULL;
-    fFactoryArray = NULL;
-    fFactoryCount = 0;
-    
-    // Set default values. These should be explicitly set by our client
-    // via setFlags() if the buffer came from serialization.
-    fFlags = 0;
-#ifdef SK_SCALAR_IS_FLOAT
-    fFlags |= kScalarIsFloat_Flag;
-#endif
-    if (8 == sizeof(void*)) {
-        fFlags |= kPtrIs64Bit_Flag;
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
 SkNamedFactorySet::SkNamedFactorySet() : fNextAddedFactory(0) {}
 
 uint32_t SkNamedFactorySet::find(SkFlattenable::Factory factory) {
@@ -70,69 +45,6 @@ const char* SkNamedFactorySet::getNextAddedFactoryName() {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkFlattenableWriteBuffer::SkFlattenableWriteBuffer() {
-    fFlags = (Flags)0;
-    fRCSet = NULL;
-    fTFSet = NULL;
-    fFactorySet = NULL;
-    fNamedFactorySet = NULL;
-}
-
-SkFlattenableWriteBuffer::~SkFlattenableWriteBuffer() {
-    SkSafeUnref(fRCSet);
-    SkSafeUnref(fTFSet);
-    SkSafeUnref(fFactorySet);
-    SkSafeUnref(fNamedFactorySet);
-}
-
-SkRefCntSet* SkFlattenableWriteBuffer::setRefCntRecorder(SkRefCntSet* rec) {
-    SkRefCnt_SafeAssign(fRCSet, rec);
-    return rec;
-}
-
-SkRefCntSet* SkFlattenableWriteBuffer::setTypefaceRecorder(SkRefCntSet* rec) {
-    SkRefCnt_SafeAssign(fTFSet, rec);
-    return rec;
-}
-
-SkFactorySet* SkFlattenableWriteBuffer::setFactoryRecorder(SkFactorySet* rec) {
-    SkRefCnt_SafeAssign(fFactorySet, rec);
-    if (fNamedFactorySet != NULL) {
-        fNamedFactorySet->unref();
-        fNamedFactorySet = NULL;
-    }
-    return rec;
-}
-
-SkNamedFactorySet* SkFlattenableWriteBuffer::setNamedFactoryRecorder(
-        SkNamedFactorySet* rec) {
-    SkRefCnt_SafeAssign(fNamedFactorySet, rec);
-    if (fFactorySet != NULL) {
-        fFactorySet->unref();
-        fFactorySet = NULL;
-    }
-    return rec;
-}
-
-void SkFlattenableWriteBuffer::writeRefCnt(SkRefCnt* obj) {
-    SkASSERT(!isCrossProcess());
-    if (NULL == obj || NULL == fRCSet) {
-        this->write32(0);
-    } else {
-        this->write32(fRCSet->add(obj));
-    }
-}
-
-void SkFlattenableWriteBuffer::writeTypeface(SkTypeface* obj) {
-    if (NULL == obj || NULL == fTFSet) {
-        this->write32(0);
-    } else {
-        this->write32(fTFSet->add(obj));
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
 SkRefCntSet::~SkRefCntSet() {
     // call this now, while our decPtr() is sill in scope
     this->reset();
diff --git a/src/core/SkFlattenableBuffers.cpp b/src/core/SkFlattenableBuffers.cpp
new file mode 100644 (file)
index 0000000..e5a9545
--- /dev/null
@@ -0,0 +1,68 @@
+
+/*
+ * 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 "SkFlattenableBuffers.h"
+#include "SkPaint.h"
+#include "SkTypeface.h"
+
+SkFlattenableReadBuffer::SkFlattenableReadBuffer() {
+    // Set default values. These should be explicitly set by our client
+    // via setFlags() if the buffer came from serialization.
+    fFlags = 0;
+#ifdef SK_SCALAR_IS_FLOAT
+    fFlags |= kScalarIsFloat_Flag;
+#endif
+    if (8 == sizeof(void*)) {
+        fFlags |= kPtrIs64Bit_Flag;
+    }
+}
+
+SkFlattenableReadBuffer::~SkFlattenableReadBuffer() { }
+
+void* SkFlattenableReadBuffer::readFunctionPtr() {
+    void* proc;
+    SkASSERT(sizeof(void*) == this->getArrayCount());
+    this->readByteArray(&proc);
+    return proc;
+}
+
+void SkFlattenableReadBuffer::readPaint(SkPaint* paint) {
+    paint->unflatten(*this);
+}
+
+SkRefCnt* SkFlattenableReadBuffer::readRefCntPtr() {
+    void* ptrStorage[] = { NULL };
+    SkASSERT(sizeof(void*) == this->getArrayCount());
+    this->readByteArray(*ptrStorage);
+    return (SkRefCnt*)ptrStorage[0];
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+SkFlattenableWriteBuffer::SkFlattenableWriteBuffer() {
+    fFlags = (Flags)0;
+}
+
+SkFlattenableWriteBuffer::~SkFlattenableWriteBuffer() { }
+
+void SkFlattenableWriteBuffer::writeFunctionPtr(void* ptr) {
+    void* ptrStorage[] = { ptr };
+    this->writeByteArray(ptrStorage, sizeof(void*));
+}
+
+void SkFlattenableWriteBuffer::writePaint(const SkPaint& paint) {
+    paint.flatten(*this);
+}
+
+void SkFlattenableWriteBuffer::writeRefCntPtr(SkRefCnt* refCnt) {
+    void* ptrStorage[] = { (void*)refCnt };
+    this->writeByteArray(ptrStorage, sizeof(void*));
+}
+
+void SkFlattenableWriteBuffer::flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer) {
+    obj->flatten(buffer);
+}
index 9ca07b9069c45c2dc10cc2da8d2b2c901f419e19..e619419035cb23ee07a431f27bec700d1a027ac3 100644 (file)
@@ -10,6 +10,7 @@
 #include "SkGlyphCache.h"
 #include "SkGraphics.h"
 #include "SkPaint.h"
+#include "SkPath.h"
 #include "SkTemplates.h"
 #include "SkTLS.h"
 
index f0bc0578d6134b04e46d1b4f15f96191c066e5d7..758cbf2e02dcd24034a2e2d62b32773ff4582dda 100644 (file)
@@ -7,7 +7,7 @@
  */
 #include "SkMallocPixelRef.h"
 #include "SkBitmap.h"
-#include "SkFlattenable.h"
+#include "SkFlattenableBuffers.h"
 
 SkMallocPixelRef::SkMallocPixelRef(void* storage, size_t size,
                                    SkColorTable* ctable, bool ownPixels) {
@@ -43,23 +43,20 @@ void SkMallocPixelRef::onUnlockPixels() {
 void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
 
-    buffer.write32(fSize);
-    buffer.writePad(fStorage, fSize);
+    buffer.writeByteArray(fStorage, fSize);
+    buffer.writeBool(fCTable != NULL);
     if (fCTable) {
-        buffer.writeBool(true);
         buffer.writeFlattenable(fCTable);
-    } else {
-        buffer.writeBool(false);
     }
 }
 
 SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer)
         : INHERITED(buffer, NULL) {
-    fSize = buffer.readU32();
+    fSize = buffer.getArrayCount();
     fStorage = sk_malloc_throw(fSize);
-    buffer.read(fStorage, fSize);
+    buffer.readByteArray(fStorage);
     if (buffer.readBool()) {
-        fCTable = static_cast<SkColorTable*>(buffer.readFlattenable());
+        fCTable = buffer.readFlattenableT<SkColorTable>();
     } else {
         fCTable = NULL;
     }
index df949074fbc8e5c04b871b8902aab9d871e261b6..a502c5d99a4775d42a694fc6e4874ecac8d050f9 100644 (file)
 
 /*
- * Copyright 2011 Google Inc.
+ * 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 "SkOrderedReadBuffer.h"
+#include "SkStream.h"
 #include "SkTypeface.h"
 
 
 SkOrderedReadBuffer::SkOrderedReadBuffer(const void* data, size_t size) {
     fReader.setMemory(data, size);
+    fMemoryPtr = NULL;
+
+    fRCArray = NULL;
+    fRCCount = 0;
+
+    fTFArray = NULL;
+    fTFCount = 0;
+
+    fFactoryTDArray = NULL;
+    fFactoryArray = NULL;
+    fFactoryCount = 0;
+}
+
+SkOrderedReadBuffer::SkOrderedReadBuffer(SkStream* stream) {
+    const size_t length = stream->getLength();
+    fMemoryPtr = sk_malloc_throw(length);
+    stream->read(fMemoryPtr, length);
+    fReader.setMemory(fMemoryPtr, length);
+}
+
+SkOrderedReadBuffer::~SkOrderedReadBuffer() {
+    sk_free(fMemoryPtr);
+}
+
+bool SkOrderedReadBuffer::readBool() {
+    return fReader.readBool();
+}
+
+SkColor SkOrderedReadBuffer::readColor() {
+    return fReader.readInt();
+}
+
+SkFixed SkOrderedReadBuffer::readFixed() {
+    return fReader.readS32();
+}
+
+int32_t SkOrderedReadBuffer::readInt() {
+    return fReader.readInt();
+}
+
+SkScalar SkOrderedReadBuffer::readScalar() {
+    return fReader.readScalar();
+}
+
+uint32_t SkOrderedReadBuffer::readUInt() {
+    return fReader.readU32();
+}
+
+int32_t SkOrderedReadBuffer::read32() {
+    return fReader.readInt();
+}
+
+char* SkOrderedReadBuffer::readString() {
+    const char* string = fReader.readString();
+    const int32_t length = strlen(string);
+    char* value = (char*)sk_malloc_throw(length + 1);
+    strcpy(value, string);
+    return value;
+}
+
+void* SkOrderedReadBuffer::readEncodedString(size_t* length, SkPaint::TextEncoding encoding) {
+    int32_t encodingType = fReader.readInt();
+    SkASSERT(encodingType == encoding);
+    *length =  fReader.readInt();
+    void* data = sk_malloc_throw(*length);
+    memcpy(data, fReader.skip(SkAlign4(*length)), *length);
+    return data;
+}
+
+void SkOrderedReadBuffer::readPoint(SkPoint* point) {
+    point->fX = fReader.readScalar();
+    point->fY = fReader.readScalar();
+}
+
+void SkOrderedReadBuffer::readMatrix(SkMatrix* matrix) {
+    fReader.readMatrix(matrix);
+}
+
+void SkOrderedReadBuffer::readIRect(SkIRect* rect) {
+    memcpy(rect, fReader.skip(sizeof(SkIRect)), sizeof(SkIRect));
+}
+
+void SkOrderedReadBuffer::readRect(SkRect* rect) {
+    memcpy(rect, fReader.skip(sizeof(SkRect)), sizeof(SkRect));
+}
+
+void SkOrderedReadBuffer::readRegion(SkRegion* region) {
+    fReader.readRegion(region);
+}
+
+void SkOrderedReadBuffer::readPath(SkPath* path) {
+    fReader.readPath(path);
+}
+
+uint32_t SkOrderedReadBuffer::readByteArray(void* value) {
+    const uint32_t length = fReader.readU32();
+    memcpy(value, fReader.skip(SkAlign4(length)), length);
+    return length;
+}
+
+uint32_t SkOrderedReadBuffer::readColorArray(SkColor* colors) {
+    const uint32_t count = fReader.readU32();
+    const uint32_t byteLength = count * sizeof(SkColor);
+    memcpy(colors, fReader.skip(SkAlign4(byteLength)), byteLength);
+    return count;
+}
+
+uint32_t SkOrderedReadBuffer::readIntArray(int32_t* values) {
+    const uint32_t count = fReader.readU32();
+    const uint32_t byteLength = count * sizeof(int32_t);
+    memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength);
+    return count;
+}
+
+uint32_t SkOrderedReadBuffer::readPointArray(SkPoint* points) {
+    const uint32_t count = fReader.readU32();
+    const uint32_t byteLength = count * sizeof(SkPoint);
+    memcpy(points, fReader.skip(SkAlign4(byteLength)), byteLength);
+    return count;
+}
+
+uint32_t SkOrderedReadBuffer::readScalarArray(SkScalar* values) {
+    const uint32_t count = fReader.readU32();
+    const uint32_t byteLength = count * sizeof(SkScalar);
+    memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength);
+    return count;
+}
+
+uint32_t SkOrderedReadBuffer::getArrayCount() {
+    return *(uint32_t*)fReader.peek();
+}
+
+SkRefCnt* SkOrderedReadBuffer::readRefCntPtr() {
+    if (fRCArray) {
+        const uint32_t index = fReader.readU32();
+        SkASSERT(index <= (unsigned)fRCCount);
+        return fRCArray[index - 1];
+    } else {
+        return INHERITED::readRefCntPtr();
+    }
+}
+
+void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) {
+    bitmap->unflatten(*this);
 }
 
 SkTypeface* SkOrderedReadBuffer::readTypeface() {
+
     uint32_t index = fReader.readU32();
     if (0 == index || index > (unsigned)fTFCount) {
         if (index) {
@@ -27,16 +173,6 @@ SkTypeface* SkOrderedReadBuffer::readTypeface() {
     }
 }
 
-SkRefCnt* SkOrderedReadBuffer::readRefCnt() {
-    uint32_t index = fReader.readU32();
-    if (0 == index || index > (unsigned)fRCCount) {
-        return NULL;
-    } else {
-        SkASSERT(fRCArray);
-        return fRCArray[index - 1];
-    }
-}
-
 SkFlattenable* SkOrderedReadBuffer::readFlattenable() {
     SkFlattenable::Factory factory = NULL;
 
@@ -81,11 +217,3 @@ SkFlattenable* SkOrderedReadBuffer::readFlattenable() {
     }
     return obj;
 }
-
-void* SkOrderedReadBuffer::readFunctionPtr() {
-    SkASSERT(!this->isCrossProcess());
-
-    void* proc;
-    fReader.read(&proc, sizeof(proc));
-    return proc;
-}
index fdfb6e3b15a8cfd65c59b1a7f0f05e97769457e3..9dd70fb1cf68cc5d7276f34286a47760cab44af9 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * Copyright 2011 Google Inc.
+ * 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 "SkOrderedWriteBuffer.h"
 #include "SkTypeface.h"
 
-SkOrderedWriteBuffer::SkOrderedWriteBuffer(size_t minSize) 
-    : fWriter(minSize) {
+SkOrderedWriteBuffer::SkOrderedWriteBuffer(size_t minSize)
+    : INHERITED()
+    , fFactorySet(NULL)
+    , fNamedFactorySet(NULL)
+    , fWriter(minSize)
+    , fRCSet(NULL)
+    , fTFSet(NULL) {
 }
 
-SkOrderedWriteBuffer::SkOrderedWriteBuffer(size_t minSize, 
-                                           void* storage, 
-                                           size_t storageSize)
-    : fWriter(minSize, storage, storageSize) {
+SkOrderedWriteBuffer::SkOrderedWriteBuffer(size_t minSize, void* storage, size_t storageSize)
+    : INHERITED()
+    , fFactorySet(NULL)
+    , fNamedFactorySet(NULL)
+    , fWriter(minSize, storage, storageSize)
+    , fRCSet(NULL)
+    , fTFSet(NULL) {
+}
+
+SkOrderedWriteBuffer::~SkOrderedWriteBuffer() {
+    SkSafeUnref(fFactorySet);
+    SkSafeUnref(fNamedFactorySet);
+    SkSafeUnref(fRCSet);
+    SkSafeUnref(fTFSet);
+}
+
+void SkOrderedWriteBuffer::writeByteArray(const void* data, size_t size) {
+    fWriter.write32(size);
+    fWriter.writePad(data, size);
+}
+
+void SkOrderedWriteBuffer::writeBool(bool value) {
+    fWriter.writeBool(value);
+}
+
+void SkOrderedWriteBuffer::writeFixed(SkFixed value) {
+    fWriter.write32(value);
+}
+
+void SkOrderedWriteBuffer::writeScalar(SkScalar value) {
+    fWriter.writeScalar(value);
+}
+
+void SkOrderedWriteBuffer::writeScalarArray(const SkScalar* value, uint32_t count) {
+    fWriter.write32(count);
+    fWriter.write(value, count * sizeof(SkScalar));
+}
+
+void SkOrderedWriteBuffer::writeInt(int32_t value) {
+    fWriter.write32(value);
+}
+
+void SkOrderedWriteBuffer::writeIntArray(const int32_t* value, uint32_t count) {
+    fWriter.write32(count);
+    fWriter.write(value, count * sizeof(int32_t));
+}
+
+void SkOrderedWriteBuffer::writeUInt(uint32_t value) {
+    fWriter.write32(value);
+}
+
+void SkOrderedWriteBuffer::write32(int32_t value) {
+    fWriter.write32(value);
+}
+
+void SkOrderedWriteBuffer::writeString(const char* value) {
+    fWriter.writeString(value);
+}
+
+void SkOrderedWriteBuffer::writeEncodedString(const void* value, size_t byteLength,
+                                              SkPaint::TextEncoding encoding) {
+    fWriter.writeInt(encoding);
+    fWriter.writeInt(byteLength);
+    fWriter.write(value, byteLength);
+}
+
+
+void SkOrderedWriteBuffer::writeColor(const SkColor& color) {
+    fWriter.write32(color);
+}
+
+void SkOrderedWriteBuffer::writeColorArray(const SkColor* color, uint32_t count) {
+    fWriter.write32(count);
+    fWriter.write(color, count * sizeof(SkColor));
+}
+
+void SkOrderedWriteBuffer::writePoint(const SkPoint& point) {
+    fWriter.writeScalar(point.fX);
+    fWriter.writeScalar(point.fY);
+}
+
+void SkOrderedWriteBuffer::writePointArray(const SkPoint* point, uint32_t count) {
+    fWriter.write32(count);
+    fWriter.write(point, count * sizeof(SkPoint));
+}
+
+void SkOrderedWriteBuffer::writeMatrix(const SkMatrix& matrix) {
+    fWriter.writeMatrix(matrix);
+}
+
+void SkOrderedWriteBuffer::writeIRect(const SkIRect& rect) {
+    fWriter.write(&rect, sizeof(SkIRect));
+}
+
+void SkOrderedWriteBuffer::writeRect(const SkRect& rect) {
+    fWriter.writeRect(rect);
+}
+
+void SkOrderedWriteBuffer::writeRegion(const SkRegion& region) {
+    fWriter.writeRegion(region);
+}
+
+void SkOrderedWriteBuffer::writePath(const SkPath& path) {
+    fWriter.writePath(path);
+}
+
+size_t SkOrderedWriteBuffer::writeStream(SkStream* stream, size_t length) {
+    return fWriter.readFromStream(stream, length);
+}
+
+bool SkOrderedWriteBuffer::writeToStream(SkWStream* stream) {
+    return fWriter.writeToStream(stream);
+}
+
+void SkOrderedWriteBuffer::writeRefCntPtr(SkRefCnt* refCnt) {
+    SkASSERT(!isCrossProcess());
+    if (NULL == fRCSet) {
+        INHERITED::writeRefCntPtr(refCnt);
+    } else {
+        this->write32(fRCSet->add(refCnt));
+    }
+}
+
+void SkOrderedWriteBuffer::writeBitmap(const SkBitmap& bitmap) {
+    bitmap.flatten(*this);
+}
+
+void SkOrderedWriteBuffer::writeTypeface(SkTypeface* obj) {
+    if (NULL == obj || NULL == fTFSet) {
+        fWriter.write32(0);
+    } else {
+        fWriter.write32(fTFSet->add(obj));
+    }
+}
+
+SkFactorySet* SkOrderedWriteBuffer::setFactoryRecorder(SkFactorySet* rec) {
+    SkRefCnt_SafeAssign(fFactorySet, rec);
+    if (fNamedFactorySet != NULL) {
+        fNamedFactorySet->unref();
+        fNamedFactorySet = NULL;
+    }
+    return rec;
+}
+
+SkNamedFactorySet* SkOrderedWriteBuffer::setNamedFactoryRecorder(SkNamedFactorySet* rec) {
+    SkRefCnt_SafeAssign(fNamedFactorySet, rec);
+    if (fFactorySet != NULL) {
+        fFactorySet->unref();
+        fFactorySet = NULL;
+    }
+    return rec;
+}
+
+SkRefCntSet* SkOrderedWriteBuffer::setRefCntRecorder(SkRefCntSet* rec) {
+    SkRefCnt_SafeAssign(fRCSet, rec);
+    return rec;
+}
+
+SkRefCntSet* SkOrderedWriteBuffer::setTypefaceRecorder(SkRefCntSet* rec) {
+    SkRefCnt_SafeAssign(fTFSet, rec);
+    return rec;
 }
 
 void SkOrderedWriteBuffer::writeFlattenable(SkFlattenable* flattenable) {
@@ -69,18 +231,12 @@ void SkOrderedWriteBuffer::writeFlattenable(SkFlattenable* flattenable) {
     }
 
     // make room for the size of the flatttened object
-    (void)this->reserve(sizeof(uint32_t));
+    (void)fWriter.reserve(sizeof(uint32_t));
     // record the current size, so we can subtract after the object writes.
-    uint32_t offset = this->size();
+    uint32_t offset = fWriter.size();
     // now flatten the object
     flattenObject(flattenable, *this);
-    uint32_t objSize = this->size() - offset;
+    uint32_t objSize = fWriter.size() - offset;
     // record the obj's size
     *fWriter.peek32(offset - sizeof(uint32_t)) = objSize;
 }
-
-void SkOrderedWriteBuffer::writeFunctionPtr(void* proc) {
-    SkASSERT(!this->isCrossProcess());
-
-    *(void**)this->reserve(sizeof(void*)) = proc;
-}
index ae5d0b256150abc047ecffafeb01ea1f0f5909ca..2cfb67b0742607eb2e24208c2cb8222fb44a80f6 100644 (file)
@@ -26,6 +26,7 @@
 #include "SkAutoKern.h"
 #include "SkGlyphCache.h"
 #include "SkPaintDefaults.h"
+#include "SkOrderedReadBuffer.h"
 #include "SkOrderedWriteBuffer.h"
 
 // define this to get a printf for out-of-range parameter in setters
@@ -1392,8 +1393,8 @@ void SkPaint::getPosTextPath(const void* textData, size_t length,
 }
 
 static void add_flattenable(SkDescriptor* desc, uint32_t tag,
-                            SkFlattenableWriteBuffer* buffer) {
-    buffer->flatten(desc->addEntry(tag, buffer->size(), NULL));
+                            SkOrderedWriteBuffer* buffer) {
+    buffer->writeToMemory(desc->addEntry(tag, buffer->size(), NULL));
 }
 
 // SkFontHost can override this choice in FilterRec()
@@ -1932,24 +1933,43 @@ void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
         flatFlags |= kHasEffects_FlatFlag;
     }
 
-    SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
-    uint32_t* ptr = buffer.reserve(kPODPaintSize);
-
-    ptr = write_scalar(ptr, this->getTextSize());
-    ptr = write_scalar(ptr, this->getTextScaleX());
-    ptr = write_scalar(ptr, this->getTextSkewX());
-    ptr = write_scalar(ptr, this->getStrokeWidth());
-    ptr = write_scalar(ptr, this->getStrokeMiter());
-    *ptr++ = this->getColor();
-    // previously flags:16, textAlign:8, flatFlags:8
-    // now flags:16, hinting:4, textAlign:4, flatFlags:8
-    *ptr++ = (this->getFlags() << 16) |
-             // hinting added later. 0 in this nibble means use the default.
-             ((this->getHinting()+1) << 12) |
-             (this->getTextAlign() << 8) |
-             flatFlags;
-    *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(),
-                    this->getStyle(), this->getTextEncoding());
+
+    if (buffer.isOrderedBinaryBuffer()) {
+        SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
+        uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize);
+
+        ptr = write_scalar(ptr, this->getTextSize());
+        ptr = write_scalar(ptr, this->getTextScaleX());
+        ptr = write_scalar(ptr, this->getTextSkewX());
+        ptr = write_scalar(ptr, this->getStrokeWidth());
+        ptr = write_scalar(ptr, this->getStrokeMiter());
+        *ptr++ = this->getColor();
+        // previously flags:16, textAlign:8, flatFlags:8
+        // now flags:16, hinting:4, textAlign:4, flatFlags:8
+        *ptr++ = (this->getFlags() << 16) |
+                 // hinting added later. 0 in this nibble means use the default.
+                 ((this->getHinting()+1) << 12) |
+                 (this->getTextAlign() << 8) |
+                 flatFlags;
+        *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(),
+                        this->getStyle(), this->getTextEncoding());
+    } else {
+        buffer.writeScalar(fTextSize);
+        buffer.writeScalar(fTextScaleX);
+        buffer.writeScalar(fTextSkewX);
+        buffer.writeScalar(fWidth);
+        buffer.writeScalar(fMiterLimit);
+        buffer.writeColor(fColor);
+        buffer.writeUInt(fFlags);
+        buffer.writeUInt(fHinting);
+        buffer.writeUInt(fTextAlign);
+        buffer.writeUInt(flatFlags);
+
+        buffer.writeUInt(fCapType);
+        buffer.writeUInt(fJoinType);
+        buffer.writeUInt(fStyle);
+        buffer.writeUInt(fTextEncoding);
+    }
 
     // now we're done with ptr and the (pre)reserved space. If we need to write
     // additional fields, use the buffer directly
@@ -1970,38 +1990,57 @@ void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
 }
 
 void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) {
-    SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
-    const void* podData = buffer.skip(kPODPaintSize);
-    const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData);
-
     fPrivFlags = 0;
 
-    // the order we read must match the order we wrote in flatten()
-    this->setTextSize(read_scalar(pod));
-    this->setTextScaleX(read_scalar(pod));
-    this->setTextSkewX(read_scalar(pod));
-    this->setStrokeWidth(read_scalar(pod));
-    this->setStrokeMiter(read_scalar(pod));
-    this->setColor(*pod++);
-
-    // previously flags:16, textAlign:8, flatFlags:8
-    // now flags:16, hinting:4, textAlign:4, flatFlags:8
-    uint32_t tmp = *pod++;
-    this->setFlags(tmp >> 16);
-
-    // hinting added later. 0 in this nibble means use the default.
-    uint32_t hinting = (tmp >> 12) & 0xF;
-    this->setHinting(0 == hinting ? kNormal_Hinting : static_cast<Hinting>(hinting-1));
-
-    this->setTextAlign(static_cast<Align>((tmp >> 8) & 0xF));
-
-    uint8_t flatFlags = tmp & 0xFF;
-
-    tmp = *pod++;
-    this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF));
-    this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF));
-    this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF));
-    this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF));
+    uint8_t flatFlags = 0;
+    if (buffer.isOrderedBinaryBuffer()) {
+        SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
+        const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSize);
+        const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData);
+
+        // the order we read must match the order we wrote in flatten()
+        this->setTextSize(read_scalar(pod));
+        this->setTextScaleX(read_scalar(pod));
+        this->setTextSkewX(read_scalar(pod));
+        this->setStrokeWidth(read_scalar(pod));
+        this->setStrokeMiter(read_scalar(pod));
+        this->setColor(*pod++);
+
+        // previously flags:16, textAlign:8, flatFlags:8
+        // now flags:16, hinting:4, textAlign:4, flatFlags:8
+        uint32_t tmp = *pod++;
+        this->setFlags(tmp >> 16);
+
+        // hinting added later. 0 in this nibble means use the default.
+        uint32_t hinting = (tmp >> 12) & 0xF;
+        this->setHinting(0 == hinting ? kNormal_Hinting : static_cast<Hinting>(hinting-1));
+
+        this->setTextAlign(static_cast<Align>((tmp >> 8) & 0xF));
+
+        flatFlags = tmp & 0xFF;
+
+        tmp = *pod++;
+        this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF));
+        this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF));
+        this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF));
+        this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF));
+    } else {
+        this->setTextSize(buffer.readScalar());
+        this->setTextScaleX(buffer.readScalar());
+        this->setTextSkewX(buffer.readScalar());
+        this->setStrokeWidth(buffer.readScalar());
+        this->setStrokeMiter(buffer.readScalar());
+        this->setColor(buffer.readColor());
+        this->setFlags(buffer.readUInt());
+        this->setHinting(static_cast<SkPaint::Hinting>(buffer.readUInt()));
+        this->setTextAlign(static_cast<SkPaint::Align>(buffer.readUInt()));
+        flatFlags = buffer.readUInt();
+
+        this->setStrokeCap(static_cast<SkPaint::Cap>(buffer.readUInt()));
+        this->setStrokeJoin(static_cast<SkPaint::Join>(buffer.readUInt()));
+        this->setStyle(static_cast<SkPaint::Style>(buffer.readUInt()));
+        this->setTextEncoding(static_cast<SkPaint::TextEncoding>(buffer.readUInt()));
+    }
 
     if (flatFlags & kHasTypeface_FlatFlag) {
         this->setTypeface(buffer.readTypeface());
@@ -2010,15 +2049,15 @@ void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) {
     }
 
     if (flatFlags & kHasEffects_FlatFlag) {
-        SkSafeUnref(this->setPathEffect((SkPathEffect*) buffer.readFlattenable()));
-        SkSafeUnref(this->setShader((SkShader*) buffer.readFlattenable()));
-        SkSafeUnref(this->setXfermode((SkXfermode*) buffer.readFlattenable()));
-        SkSafeUnref(this->setMaskFilter((SkMaskFilter*) buffer.readFlattenable()));
-        SkSafeUnref(this->setColorFilter((SkColorFilter*) buffer.readFlattenable()));
-        SkSafeUnref(this->setRasterizer((SkRasterizer*) buffer.readFlattenable()));
-        SkSafeUnref(this->setLooper((SkDrawLooper*) buffer.readFlattenable()));
-        SkSafeUnref(this->setImageFilter((SkImageFilter*) buffer.readFlattenable()));
-        SkSafeUnref(this->setAnnotation((SkAnnotation*) buffer.readFlattenable()));
+        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->setAnnotation(buffer.readFlattenableT<SkAnnotation>()));
     } else {
         this->setPathEffect(NULL);
         this->setShader(NULL);
index 8708e7e8f994b76d805b93cfcb01d74ba4cf3f09..6abce74863618bf12b57d0679c5a4a8a872d69a0 100644 (file)
@@ -10,6 +10,7 @@
 #include "SkPathEffect.h"
 #include "SkPath.h"
 #include "SkBuffer.h"
+#include "SkFlattenableBuffers.h"
 #include "SkPaintDefaults.h"
 
 // must be < 0, since ==0 means hairline, and >0 means normal stroke
@@ -141,8 +142,8 @@ void SkPairPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const {
 }
 
 SkPairPathEffect::SkPairPathEffect(SkFlattenableReadBuffer& buffer) {
-    fPE0 = (SkPathEffect*)buffer.readFlattenable();
-    fPE1 = (SkPathEffect*)buffer.readFlattenable();
+    fPE0 = buffer.readFlattenableT<SkPathEffect>();
+    fPE1 = buffer.readFlattenableT<SkPathEffect>();
     // either of these may fail, so we have to check for nulls later on
 }
 
index 8713e7672f50157805cad426b41bf728687cc315..3add392ca1c1cdb4ce783876abb6873728c2fa57 100644 (file)
@@ -8,7 +8,7 @@
 #include "SkPathHeap.h"
 #include "SkPath.h"
 #include "SkStream.h"
-#include "SkFlattenable.h"
+#include "SkFlattenableBuffers.h"
 #include <new>
 
 SK_DEFINE_INST_COUNT(SkPathHeap)
@@ -20,7 +20,7 @@ SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
 
 SkPathHeap::SkPathHeap(SkFlattenableReadBuffer& buffer)
             : fHeap(kPathCount * sizeof(SkPath)) {
-    int count = buffer.readS32();
+    const int count = buffer.readInt();
 
     fPaths.setCount(count);
     SkPath** ptr = fPaths.begin();
@@ -53,7 +53,7 @@ int SkPathHeap::append(const SkPath& path) {
 void SkPathHeap::flatten(SkFlattenableWriteBuffer& buffer) const {
     int count = fPaths.count();
     
-    buffer.write32(count);
+    buffer.writeInt(count);
     SkPath** iter = fPaths.begin();
     SkPath** stop = fPaths.end();
     while (iter < stop) {
index fa65ca44ea47538286b69504fb56296b4d734512..a593e36c001ca6a8291d7ee19200c2384ead6c90 100644 (file)
@@ -126,7 +126,7 @@ SkFlatData* SkFlatData::Create(SkFlatController* controller, const void* obj,
     result->fFlatSize = size;
 
     // put the serialized contents into the data section of the new allocation
-    buffer.flatten(result->data());
+    buffer.writeToMemory(result->data());
     result->fChecksum = SkChecksum::Compute(result->data32(), size);
     result->setSentinelAsCandidate();
     return result;
index dbec5c92848c26853e2defc65af30672103916d0..c4605aa1e2fe5fa7b7af13614c5defe28fa967e5 100644 (file)
@@ -95,7 +95,7 @@ public:
     void setCount(int count);
     SkRefCnt* set(int index, SkRefCnt*);
 
-    virtual void setupBuffer(SkFlattenableReadBuffer& buffer) const {
+    virtual void setupBuffer(SkOrderedReadBuffer& buffer) const {
         buffer.setRefCntArray(fArray, fCount);
     }
     
@@ -106,7 +106,7 @@ protected:
 
 class SkTypefacePlayback : public SkRefCntPlayback {
 public:
-    virtual void setupBuffer(SkFlattenableReadBuffer& buffer) const {
+    virtual void setupBuffer(SkOrderedReadBuffer& buffer) const {
         buffer.setTypefaceArray((SkTypeface**)fArray, fCount);
     }
 };
@@ -123,7 +123,7 @@ public:
     
     SkFlattenable::Factory* base() const { return fArray; }
 
-    void setupBuffer(SkFlattenableReadBuffer& buffer) const {
+    void setupBuffer(SkOrderedReadBuffer& buffer) const {
         buffer.setFactoryPlayback(fArray, fCount);
     }
     
index c4c40c14c0e7870424a134127c1464cf1c928c30..f05aeaab9e920c0ada3bcadc3702e1d61d40730b 100644 (file)
@@ -206,10 +206,10 @@ void SkPicturePlayback::dumpSize() const {
 
 #include "SkStream.h"
 
-static void writeTagSize(SkFlattenableWriteBuffer& buffer, uint32_t tag,
+static void writeTagSize(SkOrderedWriteBuffer& buffer, uint32_t tag,
                          uint32_t size) {
-    buffer.write32(tag);
-    buffer.write32(size);
+    buffer.writeUInt(tag);
+    buffer.writeUInt(size);
 }
 
 static void writeTagSize(SkWStream* stream, uint32_t tag,
@@ -260,19 +260,22 @@ void SkPicturePlayback::flattenToBuffer(SkOrderedWriteBuffer& buffer) const {
     if ((n = SafeCount(fBitmaps)) > 0) {
         writeTagSize(buffer, PICT_BITMAP_BUFFER_TAG, n);
         for (i = 0; i < n; i++) {
-            (*fBitmaps)[i].flatten(buffer);
+            buffer.writeBitmap((*fBitmaps)[i]);
         }
     }
     
     if ((n = SafeCount(fMatrices)) > 0) {
         writeTagSize(buffer, PICT_MATRIX_BUFFER_TAG, n);
-        buffer.writeMul4(fMatrices->begin(), n * sizeof(SkMatrix));
+        for (i = 0; i < n; i++) {
+            buffer.writeMatrix((*fMatrices)[i]);
+        }
+
     }
     
     if ((n = SafeCount(fPaints)) > 0) {
         writeTagSize(buffer, PICT_PAINT_BUFFER_TAG, n);
         for (i = 0; i < n; i++) {
-            (*fPaints)[i].flatten(buffer);
+            buffer.writePaint((*fPaints)[i]);
         }
     }
     
@@ -284,7 +287,7 @@ void SkPicturePlayback::flattenToBuffer(SkOrderedWriteBuffer& buffer) const {
     if ((n = SafeCount(fRegions)) > 0) {
         writeTagSize(buffer, PICT_REGION_BUFFER_TAG, n);
         for (i = 0; i < n; i++) {
-            buffer.getWriter32()->writeRegion((*fRegions)[i]);
+            buffer.writeRegion((*fRegions)[i]);
         }
     }
 }
@@ -408,8 +411,8 @@ bool SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info,
             fTFPlayback.setupBuffer(buffer);
             
             while (!buffer.eof()) {
-                tag = buffer.readU32();
-                size = buffer.readU32();
+                tag = buffer.readUInt();
+                size = buffer.readUInt();
                 if (!this->parseBufferTag(buffer, tag, size)) {
                     return false;
                 }
@@ -426,17 +429,19 @@ bool SkPicturePlayback::parseBufferTag(SkOrderedReadBuffer& buffer,
         case PICT_BITMAP_BUFFER_TAG: {
             fBitmaps = SkTRefArray<SkBitmap>::Create(size);
             for (size_t i = 0; i < size; ++i) {
-                fBitmaps->writableAt(i).unflatten(buffer);
+                buffer.readBitmap(&fBitmaps->writableAt(i));
             }
         } break;
         case PICT_MATRIX_BUFFER_TAG:
             fMatrices = SkTRefArray<SkMatrix>::Create(size);
-            buffer.read(&fMatrices->writableAt(0), size * sizeof(SkMatrix));
+            for (size_t i = 0; i < size; ++i) {
+                buffer.readMatrix(&fMatrices->writableAt(i));
+            }
             break;
         case PICT_PAINT_BUFFER_TAG: {
             fPaints = SkTRefArray<SkPaint>::Create(size);
             for (size_t i = 0; i < size; ++i) {
-                fPaints->writableAt(i).unflatten(buffer);
+                buffer.readPaint(&fPaints->writableAt(i));
             }
         } break;
         case PICT_PATH_BUFFER_TAG:
@@ -447,7 +452,7 @@ bool SkPicturePlayback::parseBufferTag(SkOrderedReadBuffer& buffer,
         case PICT_REGION_BUFFER_TAG: {
             fRegions = SkTRefArray<SkRegion>::Create(size);
             for (size_t i = 0; i < size; ++i) {
-                buffer.getReader32()->readRegion(&fRegions->writableAt(i));
+                buffer.readRegion(&fRegions->writableAt(i));
             }
         } break;
     }
index a5ae6df1bdca77705f402530cec6d0021796a592..d02f5048955b76b0895721eebc67320cfaae3eaa 100644 (file)
@@ -6,7 +6,7 @@
  * found in the LICENSE file.
  */
 #include "SkPixelRef.h"
-#include "SkFlattenable.h"
+#include "SkFlattenableBuffers.h"
 #include "SkThread.h"
 
 SK_DEFINE_INST_COUNT(SkPixelRef)
@@ -74,7 +74,7 @@ SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
     fColorTable = NULL; // we do not track ownership of this
     fLockCount = 0;
     fIsImmutable = buffer.readBool();
-    fGenerationID = buffer.readU32();
+    fGenerationID = buffer.readUInt();
     fPreLocked = false;
 }
 
@@ -96,9 +96,9 @@ void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
     // 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.write32(0);
+        buffer.writeUInt(0);
     } else {
-        buffer.write32(fGenerationID);
+        buffer.writeUInt(fGenerationID);
     }
 }
 
index cf522b638cd7adefc063c9ee6b57ebb0f3be7cb6..92a5d3f92b3d840c27c1562b770d7e10f9ed23a5 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkScalar.h"
 #include "SkShader.h"
+#include "SkFlattenableBuffers.h"
 #include "SkPaint.h"
 #include "SkMallocPixelRef.h"
 
@@ -238,20 +239,20 @@ bool SkColorShader::isOpaque() const {
 SkColorShader::SkColorShader(SkFlattenableReadBuffer& b) : INHERITED(b) {
     fFlags = 0; // computed in setContext
 
-    fInheritColor = b.readU8();
+    fInheritColor = b.readBool();
     if (fInheritColor) {
         return;
     }
-    fColor = b.readU32();
+    fColor = b.readColor();
 }
 
 void SkColorShader::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
-    buffer.write8(fInheritColor);
+    buffer.writeBool(fInheritColor);
     if (fInheritColor) {
         return;
     }
-    buffer.write32(fColor);
+    buffer.writeColor(fColor);
 }
 
 uint32_t SkColorShader::getFlags() {
index 03f996a7eba1f2bcfdcf505eea2bd3e06c36cbca..74097be67b70ccbe743e26253078ecd6bcb420d3 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkXfermode.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 
 SK_DEFINE_INST_COUNT(SkXfermode)
 
@@ -734,7 +735,7 @@ public:
 
 protected:
     SkProcCoeffXfermode(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-        fMode = (SkXfermode::Mode)buffer.readU32();
+        fMode = (SkXfermode::Mode)buffer.read32();
 
         const ProcCoeff& rec = gProcCoeffs[fMode];
         // these may be valid, or may be CANNOT_USE_COEFF
index 10a9a8434bf9d8ba080461ec1f22e954351e0d11..a176cf87e660ade5202aa1de1e2d42b600780ed2 100644 (file)
@@ -8,6 +8,7 @@
 
 
 #include "Sk1DPathEffect.h"
+#include "SkFlattenableBuffers.h"
 #include "SkPathMeasure.h"
 
 bool Sk1DPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) {
@@ -149,7 +150,7 @@ SkPath1DPathEffect::SkPath1DPathEffect(SkFlattenableReadBuffer& buffer) {
     if (fAdvance > 0) {
         buffer.readPath(&fPath);
         fInitialOffset = buffer.readScalar();
-        fStyle = (Style) buffer.readU8();
+        fStyle = (Style) buffer.readUInt();
     } else {
         SkDEBUGF(("SkPath1DPathEffect can't use advance <= 0\n"));
         // Make Coverity happy.
@@ -168,7 +169,7 @@ void SkPath1DPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const {
     if (fAdvance > 0) {
         buffer.writePath(fPath);
         buffer.writeScalar(fInitialOffset);
-        buffer.write8(fStyle);
+        buffer.writeUInt(fStyle);
     }
 }
 
index e19cdeb117fb91153c53c5f14c8cdd999f2bba2b..1a09a92d6bc363d59919837daa8c864a5b755db5 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "Sk2DPathEffect.h"
 #include "SkBlitter.h"
+#include "SkFlattenableBuffers.h"
 #include "SkPath.h"
 #include "SkScan.h"
 
index b5375e602f2ecda6e3f180cc389ffe256e610a94..f828cca860f15400a7c6d60582d691088fe03f15 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkAvoidXfermode.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 
 SkAvoidXfermode::SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode)
 {
@@ -24,18 +25,18 @@ SkAvoidXfermode::SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode)
 SkAvoidXfermode::SkAvoidXfermode(SkFlattenableReadBuffer& buffer)
     : INHERITED(buffer)
 {
-    fOpColor = buffer.readU32();
-    fDistMul = buffer.readU32();
-    fMode = (Mode)buffer.readU8();
+    fOpColor = buffer.readColor();
+    fDistMul = buffer.readUInt();
+    fMode = (Mode)buffer.readUInt();
 }
 
 void SkAvoidXfermode::flatten(SkFlattenableWriteBuffer& buffer) const
 {
     this->INHERITED::flatten(buffer);
 
-    buffer.write32(fOpColor);
-    buffer.write32(fDistMul);
-    buffer.write8(fMode);
+    buffer.writeColor(fOpColor);
+    buffer.writeUInt(fDistMul);
+    buffer.writeUInt(fMode);
 }
 
 // returns 0..31
index 3b785731faafad19a142073b8146cd3b073f5784..9ec2aff97f4d1930eaee745e14a15937330b6e02 100644 (file)
@@ -8,6 +8,7 @@
 #include "SkBlurDrawLooper.h"
 #include "SkBlurMaskFilter.h"
 #include "SkCanvas.h"
+#include "SkFlattenableBuffers.h"
 #include "SkPaint.h"
 #include "SkMaskFilter.h"
 #include "SkColorFilter.h"
@@ -50,10 +51,10 @@ SkBlurDrawLooper::SkBlurDrawLooper(SkFlattenableReadBuffer& buffer)
 
     fDx = buffer.readScalar();
     fDy = buffer.readScalar();
-    fBlurColor = buffer.readU32();
-    fBlur = static_cast<SkMaskFilter*>(buffer.readFlattenable());
-    fColorFilter = static_cast<SkColorFilter*>(buffer.readFlattenable());
-    fBlurFlags = buffer.readU32() & kAll_BlurFlag;
+    fBlurColor = buffer.readColor();
+    fBlur = buffer.readFlattenableT<SkMaskFilter>();
+    fColorFilter = buffer.readFlattenableT<SkColorFilter>();
+    fBlurFlags = buffer.readUInt() & kAll_BlurFlag;
 }
 
 SkBlurDrawLooper::~SkBlurDrawLooper() {
@@ -65,10 +66,10 @@ void SkBlurDrawLooper::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
     buffer.writeScalar(fDx);
     buffer.writeScalar(fDy);
-    buffer.write32(fBlurColor);
+    buffer.writeColor(fBlurColor);
     buffer.writeFlattenable(fBlur);
     buffer.writeFlattenable(fColorFilter);
-    buffer.write32(fBlurFlags);
+    buffer.writeUInt(fBlurFlags);
 }
 
 void SkBlurDrawLooper::init(SkCanvas* canvas) {
index f3e96e076f1c608d3028d42d01011c9d606205d2..b01795ba59cb820125d3c3322b782ecd0e351236 100644 (file)
@@ -8,6 +8,7 @@
 #include "SkBitmap.h"
 #include "SkBlurImageFilter.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
 #endif
index 306770bb65329f8ed75cd9511aea866ee8137ffc..64247321f82b874f35484a1d0eb1f4687b48175a 100644 (file)
@@ -10,6 +10,7 @@
 #include "SkBlurMaskFilter.h"
 #include "SkBlurMask.h"
 #include "SkBuffer.h"
+#include "SkFlattenableBuffers.h"
 #include "SkMaskFilter.h"
 
 class SkBlurMaskFilterImpl : public SkMaskFilter {
@@ -104,8 +105,8 @@ void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src, SkRect* dst) {
 SkBlurMaskFilterImpl::SkBlurMaskFilterImpl(SkFlattenableReadBuffer& buffer)
         : SkMaskFilter(buffer) {
     fRadius = buffer.readScalar();
-    fBlurStyle = (SkBlurMaskFilter::BlurStyle)buffer.readS32();
-    fBlurFlags = buffer.readU32() & SkBlurMaskFilter::kAll_BlurFlag;
+    fBlurStyle = (SkBlurMaskFilter::BlurStyle)buffer.readInt();
+    fBlurFlags = buffer.readUInt() & SkBlurMaskFilter::kAll_BlurFlag;
     SkASSERT(fRadius >= 0);
     SkASSERT((unsigned)fBlurStyle < SkBlurMaskFilter::kBlurStyleCount);
 }
@@ -113,8 +114,8 @@ SkBlurMaskFilterImpl::SkBlurMaskFilterImpl(SkFlattenableReadBuffer& buffer)
 void SkBlurMaskFilterImpl::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
     buffer.writeScalar(fRadius);
-    buffer.write32(fBlurStyle);
-    buffer.write32(fBlurFlags);
+    buffer.writeInt(fBlurStyle);
+    buffer.writeUInt(fBlurFlags);
 }
 
 static const SkMaskFilter::BlurType gBlurStyle2BlurType[] = {
index 78ef0f738a7d5d9d0e288acdfe265619dc81d8fc..2862f8bfb8237b32936561d3343080bdb7064ec7 100644 (file)
@@ -10,6 +10,7 @@
 #include "SkBlitRow.h"
 #include "SkColorFilter.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 #include "SkUtils.h"
 
 #define ILLEGAL_XFERMODE_MODE   ((SkXfermode::Mode)-1)
@@ -79,13 +80,13 @@ public:
 protected:
     virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE {
         this->INHERITED::flatten(buffer);
-        buffer.write32(fColor);
-        buffer.write32(fMode);
+        buffer.writeColor(fColor);
+        buffer.writeUInt(fMode);
     }
 
     SkModeColorFilter(SkFlattenableReadBuffer& buffer) {
-        fColor = buffer.readU32();
-        fMode = (SkXfermode::Mode)buffer.readU32();
+        fColor = buffer.readColor();
+        fMode = (SkXfermode::Mode)buffer.readUInt();
         this->updateCache();
     }
 
@@ -265,13 +266,13 @@ public:
 protected:
     virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE {
         this->INHERITED::flatten(buffer);
-        buffer.write32(fMul);
-        buffer.write32(fAdd);
+        buffer.writeColor(fMul);
+        buffer.writeColor(fAdd);
     }
 
     SkLightingColorFilter(SkFlattenableReadBuffer& buffer) {
-        fMul = buffer.readU32();
-        fAdd = buffer.readU32();
+        fMul = buffer.readColor();
+        fAdd = buffer.readColor();
     }
 
     SkColor fMul, fAdd;
index cb77de1449cab14aeb1a682e7f1ba55ed8f60b20..5f6cfd4777cc2a393acc7f0c37d9c3b85e45ae91 100644 (file)
@@ -6,6 +6,7 @@
  * found in the LICENSE file.
  */
 #include "SkColorMatrix.h"
+#include "SkFlattenableBuffers.h"
 
 #define kRScale     0
 #define kGScale     6
index 534bc01e5f32a288c84d5f9ef7e5a25fd63a8ee2..64283ab05854ab31bc81d72e7f7c5cb3b2416364 100644 (file)
@@ -8,6 +8,7 @@
 #include "SkColorMatrixFilter.h"
 #include "SkColorMatrix.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 #include "SkUnPreMultiply.h"
 
 static int32_t rowmul4(const int32_t array[], unsigned r, unsigned g,
@@ -299,14 +300,14 @@ void SkColorMatrixFilter::filterSpan16(const uint16_t src[], int count,
 
 void SkColorMatrixFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
-    // TODO: buffer.writeScalars(array, N)?
-    buffer.write(fMatrix.fMat, sizeof(fMatrix.fMat));
+    SkASSERT(sizeof(fMatrix.fMat)/sizeof(SkScalar) == 20);
+    buffer.writeScalarArray(fMatrix.fMat, 20);
 }
 
 SkColorMatrixFilter::SkColorMatrixFilter(SkFlattenableReadBuffer& buffer)
         : INHERITED(buffer) {
-    // TODO: buffer.readScalars(array, N)?
-    buffer.read(fMatrix.fMat, sizeof(fMatrix.fMat));
+    SkASSERT(buffer.getArrayCount() == 20);
+    buffer.readScalarArray(fMatrix.fMat);
     this->initState(fMatrix.fMat);
 }
 
index 749384d579a79a865228fbcaa5bedf08c5c28e52..449122f1c85ba62fe01e205666226aa1029df4aa 100644 (file)
@@ -11,6 +11,7 @@
 #include "SkPath.h"
 #include "SkPoint.h"
 #include "SkBuffer.h"
+#include "SkFlattenableBuffers.h"
 
 SkCornerPathEffect::SkCornerPathEffect(SkScalar radius) : fRadius(radius)
 {
index c1bb7058181df372ddb803273c18db5634cfb127..537601fa87ce1b006ee4c627b80cce75ed69f5a0 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkDashPathEffect.h"
 #include "SkBuffer.h"
+#include "SkFlattenableBuffers.h"
 #include "SkPathMeasure.h"
 
 static inline int is_even(int x) {
@@ -235,27 +236,26 @@ void SkDashPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const {
     SkASSERT(fInitialDashLength >= 0);
 
     this->INHERITED::flatten(buffer);
-    buffer.write32(fCount);
-    buffer.write32(fInitialDashIndex);
+    buffer.writeInt(fInitialDashIndex);
     buffer.writeScalar(fInitialDashLength);
     buffer.writeScalar(fIntervalLength);
-    buffer.write32(fScaleToFit);
-    buffer.writeMul4(fIntervals, fCount * sizeof(fIntervals[0]));
+    buffer.writeBool(fScaleToFit);
+    buffer.writeScalarArray(fIntervals, fCount);
 }
 
 SkFlattenable* SkDashPathEffect::CreateProc(SkFlattenableReadBuffer& buffer) {
     return SkNEW_ARGS(SkDashPathEffect, (buffer));
 }
 
-SkDashPathEffect::SkDashPathEffect(SkFlattenableReadBuffer& buffer) {
-    fCount = buffer.readS32();
-    fInitialDashIndex = buffer.readS32();
+SkDashPathEffect::SkDashPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
+    fInitialDashIndex = buffer.readInt();
     fInitialDashLength = buffer.readScalar();
     fIntervalLength = buffer.readScalar();
-    fScaleToFit = (buffer.readS32() != 0);
+    fScaleToFit = buffer.readBool();
     
+    fCount = buffer.getArrayCount();
     fIntervals = (SkScalar*)sk_malloc_throw(sizeof(SkScalar) * fCount);
-    buffer.read(fIntervals, fCount * sizeof(fIntervals[0]));
+    buffer.readScalarArray(fIntervals);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index 0536e5646d3fc407e3837064eb085727f5a3a385..77a6ec6b4472e120123aecf7d7f3ba87d2a37027 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkDiscretePathEffect.h"
 #include "SkBuffer.h"
+#include "SkFlattenableBuffers.h"
 #include "SkPathMeasure.h"
 #include "SkRandom.h"
 
index 9ecba340c72a8cf136edd35cb1cf32e5c241a6b8..ebc3addd19d0be1dd19bbbe962c240a5cc522b8d 100644 (file)
@@ -12,6 +12,7 @@
 #include "SkBlurMask.h"
 #include "SkEmbossMask.h"
 #include "SkBuffer.h"
+#include "SkFlattenableBuffers.h"
 
 static inline int pin2byte(int n) {
     if (n < 0) {
@@ -117,7 +118,8 @@ bool SkEmbossMaskFilter::filterMask(SkMask* dst, const SkMask& src,
 
 SkEmbossMaskFilter::SkEmbossMaskFilter(SkFlattenableReadBuffer& buffer)
         : SkMaskFilter(buffer) {
-    buffer.read(&fLight, sizeof(fLight));
+    SkASSERT(buffer.getArrayCount() == sizeof(Light));
+    buffer.readByteArray(&fLight);
     SkASSERT(fLight.fPad == 0); // for the font-cache lookup to be clean
     fBlurRadius = buffer.readScalar();
 }
@@ -127,7 +129,7 @@ void SkEmbossMaskFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
 
     Light tmpLight = fLight;
     tmpLight.fPad = 0;    // for the font-cache lookup to be clean
-    buffer.writeMul4(&tmpLight, sizeof(tmpLight));
+    buffer.writeByteArray(&tmpLight, sizeof(tmpLight));
     buffer.writeScalar(fBlurRadius);
 }
 
index 0468d5b087f228f08498b9fffebc5ec4c4d1150a..224d2a2eca9efd3b211c1e68344c38448f16f459 100644 (file)
@@ -6,6 +6,7 @@
  * found in the LICENSE file.
  */
 #include "SkGroupShape.h"
+#include "SkFlattenableBuffers.h"
 
 SkGroupShape::SkGroupShape() {}
 
@@ -86,8 +87,7 @@ void SkGroupShape::onDraw(SkCanvas* canvas) {
 void SkGroupShape::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
 
-    int count = fList.count();
-    buffer.write32(count);
+    buffer.writeInt(fList.count());
     const Rec* rec = fList.begin();
     const Rec* stop = fList.end();
     while (rec < stop) {
@@ -101,9 +101,9 @@ void SkGroupShape::flatten(SkFlattenableWriteBuffer& buffer) const {
 }
 
 SkGroupShape::SkGroupShape(SkFlattenableReadBuffer& buffer) : INHERITED(buffer){
-    int count = buffer.readS32();
+    int count = buffer.readInt();
     for (int i = 0; i < count; i++) {
-        SkShape* shape = reinterpret_cast<SkShape*>(buffer.readFlattenable());
+        SkShape* shape = buffer.readFlattenableT<SkShape>();
         SkMatrixRef* mr = NULL;
         bool hasMatrix = buffer.readBool();
         if (hasMatrix) {
index 10aabc4e773833d9dad17df0ae76519d53576f80..9426dd9037efa2d95ebaa6ec981107a8ef684fe7 100644 (file)
@@ -7,6 +7,7 @@
  */
 #include "SkKernel33MaskFilter.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 
 SkMask::Format SkKernel33ProcMaskFilter::getFormat() {
     return SkMask::kA8_Format;
@@ -75,12 +76,12 @@ bool SkKernel33ProcMaskFilter::filterMask(SkMask* dst, const SkMask& src,
 
 void SkKernel33ProcMaskFilter::flatten(SkFlattenableWriteBuffer& wb) const {
     this->INHERITED::flatten(wb);
-    wb.write32(fPercent256);
+    wb.writeInt(fPercent256);
 }
 
 SkKernel33ProcMaskFilter::SkKernel33ProcMaskFilter(SkFlattenableReadBuffer& rb)
         : SkMaskFilter(rb) {
-    fPercent256 = rb.readS32();
+    fPercent256 = rb.readInt();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -106,13 +107,14 @@ uint8_t SkKernel33MaskFilter::computeValue(uint8_t* const* srcRows) {
 
 void SkKernel33MaskFilter::flatten(SkFlattenableWriteBuffer& wb) const {
     this->INHERITED::flatten(wb);
-    wb.writeMul4(fKernel, 9 * sizeof(int));
-    wb.write32(fShift);
+    wb.writeIntArray(&fKernel[0][0], 9);
+    wb.writeInt(fShift);
 }
 
 SkKernel33MaskFilter::SkKernel33MaskFilter(SkFlattenableReadBuffer& rb)
         : SkKernel33ProcMaskFilter(rb) {
-    rb.read(fKernel, 9 * sizeof(int));
-    fShift = rb.readS32();
+    const uint32_t count = rb.readIntArray(&fKernel[0][0]);
+    SkASSERT(9 == count);
+    fShift = rb.readInt();
 }
 
index c8da568a411a295d01eeee1c581cfaa66838324d..a32cf9ba316b4c4c89b79ea875c91d8df72c5223 100644 (file)
@@ -7,6 +7,7 @@
  */
 #include "SkCanvas.h"
 #include "SkColor.h"
+#include "SkFlattenableBuffers.h"
 #include "SkLayerDrawLooper.h"
 #include "SkPaint.h"
 #include "SkUnPreMultiply.h"
@@ -204,10 +205,9 @@ void SkLayerDrawLooper::flatten(SkFlattenableWriteBuffer& buffer) const {
         buffer.writeInt(rec->fInfo.fFlagsMask);
         buffer.writeInt(rec->fInfo.fPaintBits);
         buffer.writeInt(rec->fInfo.fColorMode);
-        buffer.writeScalar(rec->fInfo.fOffset.fX);
-        buffer.writeScalar(rec->fInfo.fOffset.fY);
+        buffer.writePoint(rec->fInfo.fOffset);
         buffer.writeBool(rec->fInfo.fPostTranslate);
-        rec->fPaint.flatten(buffer);
+        buffer.writePaint(rec->fPaint);
         rec = rec->fNext;
     }
 }
@@ -224,10 +224,9 @@ SkLayerDrawLooper::SkLayerDrawLooper(SkFlattenableReadBuffer& buffer)
         info.fFlagsMask = buffer.readInt();
         info.fPaintBits = buffer.readInt();
         info.fColorMode = (SkXfermode::Mode)buffer.readInt();
-        info.fOffset.fX = buffer.readScalar();
-        info.fOffset.fY = buffer.readScalar();
+        buffer.readPoint(&info.fOffset);
         info.fPostTranslate = buffer.readBool();
-        this->addLayer(info)->unflatten(buffer);
+        buffer.readPaint(this->addLayer(info));
     }
     SkASSERT(count == fCount);
 
index dbcbefd030face6127d35a9bb0bd7cee7712b96d..8aaa9fb700e16115141b6085406168d9fcb578c3 100644 (file)
@@ -10,6 +10,7 @@
 #include "SkLayerRasterizer.h"
 #include "SkBuffer.h"
 #include "SkDraw.h"
+#include "SkFlattenableBuffers.h"
 #include "SkMask.h"
 #include "SkMaskFilter.h"
 #include "SkPaint.h"
@@ -143,78 +144,30 @@ bool SkLayerRasterizer::onRasterize(const SkPath& path, const SkMatrix& matrix,
     return true;
 }
 
-/////////// Routines for flattening /////////////////
-
-static void paint_read(SkPaint* paint, SkFlattenableReadBuffer& buffer) {
-    paint->setAntiAlias(buffer.readBool());
-    paint->setStyle((SkPaint::Style)buffer.readU8());
-    paint->setAlpha(buffer.readU8());
-
-    if (paint->getStyle() != SkPaint::kFill_Style) {
-        paint->setStrokeWidth(buffer.readScalar());
-        paint->setStrokeMiter(buffer.readScalar());
-        paint->setStrokeCap((SkPaint::Cap)buffer.readU8());
-        paint->setStrokeJoin((SkPaint::Join)buffer.readU8());
-    }
-
-    SkSafeUnref(paint->setMaskFilter((SkMaskFilter*)buffer.readFlattenable()));
-    SkSafeUnref(paint->setPathEffect((SkPathEffect*)buffer.readFlattenable()));
-    SkSafeUnref(paint->setRasterizer((SkRasterizer*)buffer.readFlattenable()));
-    SkSafeUnref(paint->setXfermode((SkXfermode*)buffer.readFlattenable()));
-}
-
-static void paint_write(const SkPaint& paint, SkFlattenableWriteBuffer& buffer) {
-    buffer.writeBool(paint.isAntiAlias());
-    buffer.write8(paint.getStyle());
-    buffer.write8(paint.getAlpha());
-
-    if (paint.getStyle() != SkPaint::kFill_Style) {
-        buffer.writeScalar(paint.getStrokeWidth());
-        buffer.writeScalar(paint.getStrokeMiter());
-        buffer.write8(paint.getStrokeCap());
-        buffer.write8(paint.getStrokeJoin());
-    }
-
-    buffer.writeFlattenable(paint.getMaskFilter());
-    buffer.writeFlattenable(paint.getPathEffect());
-    buffer.writeFlattenable(paint.getRasterizer());
-    buffer.writeFlattenable(paint.getXfermode());
-}
-
 SkLayerRasterizer::SkLayerRasterizer(SkFlattenableReadBuffer& buffer)
     : SkRasterizer(buffer), fLayers(sizeof(SkLayerRasterizer_Rec)) {
-    int count = buffer.readS32();
+    int count = buffer.readInt();
 
     for (int i = 0; i < count; i++) {
         SkLayerRasterizer_Rec* rec = (SkLayerRasterizer_Rec*)fLayers.push_back();
 
-#if 0
-        SkNEW_PLACEMENT_ARGS(&rec->fPaint, SkPaint, (buffer));
-#else
         SkNEW_PLACEMENT(&rec->fPaint, SkPaint);
-        paint_read(&rec->fPaint, buffer);
-#endif
-        rec->fOffset.fX = buffer.readScalar();
-        rec->fOffset.fY = buffer.readScalar();
+        buffer.readPaint(&rec->fPaint);
+        buffer.readPoint(&rec->fOffset);
     }
 }
 
 void SkLayerRasterizer::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
 
-    buffer.write32(fLayers.count());
+    buffer.writeInt(fLayers.count());
 
     SkDeque::F2BIter                iter(fLayers);
     const SkLayerRasterizer_Rec*    rec;
 
     while ((rec = (const SkLayerRasterizer_Rec*)iter.next()) != NULL) {
-#if 0
-        rec->fPaint.flatten(buffer);
-#else
-        paint_write(rec->fPaint, buffer);
-#endif
-        buffer.writeScalar(rec->fOffset.fX);
-        buffer.writeScalar(rec->fOffset.fY);
+        buffer.writePaint(rec->fPaint);
+        buffer.writePoint(rec->fOffset);
     }
 }
 
index b6532aa292d4a2ef32e536ee0e1a85c9b3a76031..c590c262e8e63e9117b02e3f05d79878cbf206d6 100644 (file)
@@ -8,6 +8,9 @@
 #include "SkLightingImageFilter.h"
 #include "SkBitmap.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
+#include "SkOrderedReadBuffer.h"
+#include "SkOrderedWriteBuffer.h"
 #include "SkTypes.h"
 
 #if SK_SUPPORT_GPU
@@ -754,7 +757,7 @@ SkLightingImageFilter::~SkLightingImageFilter() {
 SkLightingImageFilter::SkLightingImageFilter(SkFlattenableReadBuffer& buffer)
   : INHERITED(buffer)
 {
-    fLight = (SkLight*)buffer.readFlattenable();
+    fLight = buffer.readFlattenableT<SkLight>();
     fSurfaceScale = buffer.readScalar();
 }
 
index b0fc289eb847c59b935f907b790788823d7014f8..c1e2d26fd51d816131b6cd3aac1402133c55a7e2 100644 (file)
@@ -8,6 +8,8 @@
 #include "SkMorphologyImageFilter.h"
 #include "SkBitmap.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
+#include "SkRect.h"
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
 #include "GrTexture.h"
index 7b58ed76a8c6128dedae995920d15c36ca808797..236aec549eaaa855894ba24405ea5a58dffcbfee 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkPixelXorXfermode.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 
 // we always return an opaque color, 'cause I don't know what to do with
 // the alpha-component and still return a valid premultiplied color.
@@ -20,12 +21,12 @@ SkPMColor SkPixelXorXfermode::xferColor(SkPMColor src, SkPMColor dst) {
 
 void SkPixelXorXfermode::flatten(SkFlattenableWriteBuffer& wb) const {
     this->INHERITED::flatten(wb);
-    wb.write32(fOpColor);
+    wb.writeColor(fOpColor);
 }
 
 SkPixelXorXfermode::SkPixelXorXfermode(SkFlattenableReadBuffer& rb)
         : INHERITED(rb) {
-    fOpColor = rb.readU32();
+    fOpColor = rb.readColor();
 }
 
 SK_DEFINE_FLATTENABLE_REGISTRAR(SkPixelXorXfermode)
index 68d1e1f7ffe4ca5b193764fff99137af49460d11..06631061c2e9632914efa35ba4148e7890d49fe7 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkRectShape.h"
 #include "SkCanvas.h"
+#include "SkFlattenableBuffers.h"
 
 SkPaintShape::SkPaintShape() {
     fPaint.setAntiAlias(true);
@@ -64,24 +65,25 @@ void SkRectShape::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
 
     buffer.writeRect(fBounds);
-    *(SkSize*)buffer.reserve(sizeof(SkSize)) = fRadii;
+    buffer.writeScalar(fRadii.fWidth);
+    buffer.writeScalar(fRadii.fHeight);
 }
 
-SkRectShape::SkRectShape(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {    
-    buffer.read(&fBounds, sizeof(fBounds));
-    buffer.read(&fRadii, sizeof(fRadii));
+SkRectShape::SkRectShape(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
+    buffer.readRect(&fBounds);
+    fRadii.fWidth = buffer.readScalar();
+    fRadii.fHeight = buffer.readScalar();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
 void SkPaintShape::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
-    
-    fPaint.flatten(buffer);
+    buffer.writePaint(fPaint);
 }
 
 SkPaintShape::SkPaintShape(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-    fPaint.unflatten(buffer);
+    buffer.readPaint(&fPaint);
 }
 
 SK_DEFINE_FLATTENABLE_REGISTRAR(SkRectShape)
index 769a40d27f5ade8165a1deb4a78b0520c107db9e..f316c5296dfd9031ae773228791504345fc11f90 100644 (file)
@@ -1,6 +1,8 @@
+
 #include "SkBitmap.h"
-#include "SkColorPriv.h"
 #include "SkTableColorFilter.h"
+#include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 #include "SkUnPreMultiply.h"
 
 class SkTable_ColorFilter : public SkColorFilter {
@@ -161,8 +163,7 @@ void SkTable_ColorFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
 //    SkDebugf("raw %d packed %d\n", count * 256, size);
     
     buffer.writeInt(fFlags);
-    buffer.writeInt(size);
-    buffer.write(storage, size);
+    buffer.writeByteArray(storage, size);
 }
 
 SkTable_ColorFilter::SkTable_ColorFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
@@ -171,8 +172,10 @@ SkTable_ColorFilter::SkTable_ColorFilter(SkFlattenableReadBuffer& buffer) : INHE
     uint8_t storage[5*256];
 
     fFlags = buffer.readInt();
-    size_t size = buffer.readInt();
-    buffer.read(storage, size);
+
+    size_t size = buffer.getArrayCount();
+    SkASSERT(size <= sizeof(storage));
+    buffer.readByteArray(storage);
 
     size_t raw = SkPackBits::Unpack8(storage, size, fStorage);
 
index 43da55eab158e91a859bdabbcfb1aa78a2f24cd4..495affb1880c5ff492ed2814b3d8ffaa171cc3f5 100644 (file)
@@ -8,6 +8,7 @@
 
 
 #include "SkTableMaskFilter.h"
+#include "SkFlattenableBuffers.h"
 
 SkTableMaskFilter::SkTableMaskFilter() {
     for (int i = 0; i < 256; i++) {
@@ -73,12 +74,13 @@ SkMask::Format SkTableMaskFilter::getFormat() {
 
 void SkTableMaskFilter::flatten(SkFlattenableWriteBuffer& wb) const {
     this->INHERITED::flatten(wb);
-    wb.writePad(fTable, 256);
+    wb.writeByteArray(fTable, 256);
 }
 
 SkTableMaskFilter::SkTableMaskFilter(SkFlattenableReadBuffer& rb)
         : INHERITED(rb) {
-    rb.read(fTable, 256);
+    SkASSERT(256 == rb.getArrayCount());
+    rb.readByteArray(fTable);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index 2633b0959d427b88b64058f8e61f97914441608c..70e39efbf5837b6e734b4f34a1a3e5e9deb171df 100755 (executable)
@@ -1,6 +1,8 @@
+
 #include "SkTestImageFilters.h"
 #include "SkCanvas.h"
 #include "SkDevice.h"
+#include "SkFlattenableBuffers.h"
 
 // Simple helper canvas that "takes ownership" of the provided device, so that
 // when this canvas goes out of scope, so will its device. Could be replaced
@@ -41,13 +43,11 @@ bool SkOffsetImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm
 
 void SkOffsetImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
-    buffer.writeScalar(fOffset.x());
-    buffer.writeScalar(fOffset.y());
+    buffer.writePoint(fOffset);
 }
 
 SkOffsetImageFilter::SkOffsetImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-    fOffset.fX = buffer.readScalar();
-    fOffset.fY = buffer.readScalar();
+    buffer.readPoint(&fOffset);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -99,8 +99,8 @@ void SkComposeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
 }
 
 SkComposeImageFilter::SkComposeImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-    fOuter = (SkImageFilter*)buffer.readFlattenable();
-    fInner = (SkImageFilter*)buffer.readFlattenable();
+    fOuter = buffer.readFlattenableT<SkImageFilter>();
+    fInner = buffer.readFlattenableT<SkImageFilter>();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -253,29 +253,30 @@ void SkMergeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
         // negative count signals we have modes
         storedCount = -storedCount;
     }
-    buffer.write32(storedCount);
+    buffer.writeInt(storedCount);
 
     if (fCount) {
         for (int i = 0; i < fCount; ++i) {
             buffer.writeFlattenable(fFilters[i]);
         }
         if (fModes) {
-            buffer.write(fModes, fCount * sizeof(fModes[0]));
+            buffer.writeByteArray(fModes, fCount * sizeof(fModes[0]));
         }
     }
 }
 
 SkMergeImageFilter::SkMergeImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-    int storedCount = buffer.readS32();
+    int storedCount = buffer.readInt();
     this->initAlloc(SkAbs32(storedCount), storedCount < 0);
 
     for (int i = 0; i < fCount; ++i) {
-        fFilters[i] = (SkImageFilter*)buffer.readFlattenable();
+        fFilters[i] = buffer.readFlattenableT<SkImageFilter>();
     }
 
     if (fModes) {
         SkASSERT(storedCount < 0);
-        buffer.read(fModes, fCount * sizeof(fModes[0]));
+        SkASSERT(buffer.getArrayCount() == fCount * sizeof(fModes[0]));
+        buffer.readByteArray(fModes);
     } else {
         SkASSERT(storedCount >= 0);
     }
@@ -321,7 +322,7 @@ void SkColorFilterImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
 }
 
 SkColorFilterImageFilter::SkColorFilterImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
-    fColorFilter = (SkColorFilter*)buffer.readFlattenable();
+    fColorFilter = buffer.readFlattenableT<SkColorFilter>();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index f61f8d53b01225592980b05f6b88dbb005f9f95b..a07b38878d4afd321cc2cc5da82fcca864a3a91e 100644 (file)
@@ -134,30 +134,30 @@ SkGradientShaderBase::SkGradientShaderBase(SkFlattenableReadBuffer& buffer) :
     INHERITED(buffer) {
     fCacheAlpha = 256;
 
-    fMapper = static_cast<SkUnitMapper*>(buffer.readFlattenable());
+    fMapper = buffer.readFlattenableT<SkUnitMapper>();
 
     fCache16 = fCache16Storage = NULL;
     fCache32 = NULL;
     fCache32PixelRef = NULL;
 
-    int colorCount = fColorCount = buffer.readU32();
+    int colorCount = fColorCount = buffer.getArrayCount();
     if (colorCount > kColorStorageCount) {
         size_t size = sizeof(SkColor) + sizeof(SkPMColor) + sizeof(Rec);
         fOrigColors = (SkColor*)sk_malloc_throw(size * colorCount);
     } else {
         fOrigColors = fStorage;
     }
-    buffer.read(fOrigColors, colorCount * sizeof(SkColor));
+    buffer.readColorArray(fOrigColors);
 
-    fTileMode = (TileMode)buffer.readU8();
+    fTileMode = (TileMode)buffer.readUInt();
     fTileProc = gTileProcs[fTileMode];
     fRecs = (Rec*)(fOrigColors + colorCount);
     if (colorCount > 2) {
         Rec* recs = fRecs;
         recs[0].fPos = 0;
         for (int i = 1; i < colorCount; i++) {
-            recs[i].fPos = buffer.readS32();
-            recs[i].fScale = buffer.readU32();
+            recs[i].fPos = buffer.readInt();
+            recs[i].fScale = buffer.readUInt();
         }
     }
     buffer.readMatrix(&fPtsToUnit);
@@ -187,14 +187,13 @@ void SkGradientShaderBase::initCommon() {
 void SkGradientShaderBase::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
     buffer.writeFlattenable(fMapper);
-    buffer.write32(fColorCount);
-    buffer.writeMul4(fOrigColors, fColorCount * sizeof(SkColor));
-    buffer.write8(fTileMode);
+    buffer.writeColorArray(fOrigColors, fColorCount);
+    buffer.writeUInt(fTileMode);
     if (fColorCount > 2) {
         Rec* recs = fRecs;
         for (int i = 1; i < fColorCount; i++) {
-            buffer.write32(recs[i].fPos);
-            buffer.write32(recs[i].fScale);
+            buffer.writeInt(recs[i].fPos);
+            buffer.writeUInt(recs[i].fScale);
         }
     }
     buffer.writeMatrix(fPtsToUnit);
index 807bf324ada694b01a82cc900fc2292e2de7fa42..8152d5fb71ee8eae07a6b690c5aeedcca228e84f 100644 (file)
@@ -12,6 +12,7 @@
 #include "SkGradientShader.h"
 #include "SkClampRange.h"
 #include "SkColorPriv.h"
+#include "SkFlattenableBuffers.h"
 #include "SkMallocPixelRef.h"
 #include "SkUnitMapper.h"
 #include "SkUtils.h"
index 6ab5bbc68fe80076e498930c197aa426bbdb98c1..4e42d6c909237c636898ef2e7a27d05ea686d4ae 100644 (file)
@@ -6,7 +6,7 @@
  * found in the LICENSE file.
  */
 #include "SkFlipPixelRef.h"
-#include "SkFlattenable.h"
+#include "SkFlattenableBuffers.h"
 #include "SkRegion.h"
 
 SkFlipPixelRef::SkFlipPixelRef(SkBitmap::Config config, int width, int height)
@@ -62,19 +62,17 @@ void SkFlipPixelRef::swapPages() {
 
 void SkFlipPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
-    
-    buffer.write32(fSize);
     // only need to write page0
-    buffer.writePad(fPage0, fSize);
+    buffer.writeByteArray(fPage0, fSize);
 }
 
 SkFlipPixelRef::SkFlipPixelRef(SkFlattenableReadBuffer& buffer)
         : INHERITED(buffer, NULL) {
-    fSize = buffer.readU32();
+    fSize = buffer.getArrayCount();
     fStorage = sk_malloc_throw(fSize << 1);
     fPage0 = fStorage;
     fPage1 = (char*)fStorage + fSize;
-    buffer.read(fPage0, fSize);
+    buffer.readByteArray(fPage0);
 }
 
 SK_DEFINE_FLATTENABLE_REGISTRAR(SkFlipPixelRef)
index 1d6b270d6ced0630938ea70a6fdcffc56ee9a1ac..39a1de930204f8d17fc212fc60537e80eca28790 100644 (file)
@@ -7,7 +7,7 @@
  */
 #include "SkImageRef.h"
 #include "SkBitmap.h"
-#include "SkFlattenable.h"
+#include "SkFlattenableBuffers.h"
 #include "SkImageDecoder.h"
 #include "SkStream.h"
 #include "SkTemplates.h"
@@ -177,13 +177,13 @@ size_t SkImageRef::ramUsed() const {
 
 SkImageRef::SkImageRef(SkFlattenableReadBuffer& buffer)
         : INHERITED(buffer, &gImageRefMutex), fErrorInDecoding(false) {
-    fConfig = (SkBitmap::Config)buffer.readU8();
-    fSampleSize = buffer.readU8();
+    fConfig = (SkBitmap::Config)buffer.readUInt();
+    fSampleSize = buffer.readInt();
     fDoDither = buffer.readBool();
 
-    size_t length = buffer.readU32();
+    size_t length = buffer.getArrayCount();
     fStream = SkNEW_ARGS(SkMemoryStream, (length));
-    buffer.read((void*)fStream->getMemoryBase(), length);
+    buffer.readByteArray((void*)fStream->getMemoryBase());
 
     fPrev = fNext = NULL;
     fFactory = NULL;
@@ -192,12 +192,10 @@ SkImageRef::SkImageRef(SkFlattenableReadBuffer& buffer)
 void SkImageRef::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
 
-    buffer.write8(fConfig);
-    buffer.write8(fSampleSize);
+    buffer.writeUInt(fConfig);
+    buffer.writeInt(fSampleSize);
     buffer.writeBool(fDoDither);
-    size_t length = fStream->getLength();
-    buffer.write32(length);
     fStream->rewind();
-    buffer.readFromStream(fStream, length);
+    buffer.writeStream(fStream, fStream->getLength());
 }
 
index 1bce61455496a054d955bbb17208ba58bbe34e0d..1bdbf785cc7ec70d9b6b47d1e376807db9009514 100644 (file)
@@ -17,6 +17,7 @@ class SkMatrix;
 class SkPath;
 class SkPDFArray;
 struct SkRect;
+class SkWStream;
 
 #if 0
 #define PRINT_NOT_IMPL(str) fprintf(stderr, str)
index a8cba27b4cf657d066ec568bac9e6510ad746c28..725a57b5ee8fc63ce8cfd2429c5e87f186988ab7 100644 (file)
@@ -78,7 +78,7 @@ public:
         return fFlags;
     }
 
-    void setReader(SkFlattenableReadBuffer* reader) {
+    void setReader(SkOrderedReadBuffer* reader) {
         fReader = reader;
         this->updateReader();
     }
@@ -129,7 +129,7 @@ public:
     }
 
     void addTypeface() {
-        size_t size = fReader->readU32();
+        size_t size = fReader->read32();
         const void* data = fReader->skip(SkAlign4(size));
         SkMemoryStream stream(data, size, false);
         *fTypefaces.append() = SkTypeface::Deserialize(&stream);
@@ -152,7 +152,7 @@ private:
             fReader->setFactoryArray(NULL);
         }
     }
-    SkFlattenableReadBuffer*  fReader;
+    SkOrderedReadBuffer*      fReader;
     SkPaint                   fPaint;
     SkTDArray<SkFlattenable*> fFlatArray;
     SkTDArray<SkTypeface*>    fTypefaces;
@@ -677,7 +677,7 @@ SkGPipeReader::Status SkGPipeReader::playback(const void* data, size_t length,
 
     fState->setReader(&reader);
     while (!reader.eof()) {
-        uint32_t op32 = reader.readU32();
+        uint32_t op32 = reader.readUInt();
         unsigned op = DrawOp_unpackOp(op32);
         // SkDEBUGCODE(DrawOps drawOp = (DrawOps)op;)
         
index 6ea5c95e78523f6e126d4b52b075da6ec5165289..81f24dd6300d9ace6a979a2d79bdabe29bbc2dd1 100644 (file)
@@ -214,14 +214,7 @@ void SkImageRef_ashmem::onUnlockPixels() {
 
 void SkImageRef_ashmem::flatten(SkFlattenableWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
-    const char* uri = getURI();
-    if (uri) {
-        size_t len = strlen(uri);
-        buffer.write32(len);
-        buffer.writePad(uri, len);
-    } else {
-        buffer.write32(0);
-    }
+    buffer.writeString(getURI());
 }
 
 SkImageRef_ashmem::SkImageRef_ashmem(SkFlattenableReadBuffer& buffer)
@@ -231,17 +224,12 @@ SkImageRef_ashmem::SkImageRef_ashmem(SkFlattenableReadBuffer& buffer)
     fRec.fSize = 0;
     fRec.fPinned = false;
     fCT = NULL;
-    size_t length = buffer.readU32();
-    if (length) {
-        char* buf = (char*) malloc(length);
-        buffer.read(buf, length);
-        setURI(buf, length);
+    const char* uri = buffer.readString();
+    if (uri) {
+        setURI(uri);
+        sk_free(uri);
     }
     this->useDefaultMutex();   // we don't need/want the shared imageref mutex
 }
 
-SkPixelRef* SkImageRef_ashmem::Create(SkFlattenableReadBuffer& buffer) {
-    return SkNEW_ARGS(SkImageRef_ashmem, (buffer));
-}
-
 SK_DEFINE_FLATTENABLE_REGISTRAR(SkImageRef_ashmem)
index b2ab02bb0e5cf6b93e5f400e361cb360f07f05d7..735a4340abd19c6b12f0736aab1100df4e3ce7bb 100644 (file)
@@ -6,6 +6,7 @@
  * found in the LICENSE file.
  */
 #include "SkUnitMappers.h"
+#include "SkFlattenableBuffers.h"
 
 SK_DEFINE_INST_COUNT(SkUnitMapper)
 
@@ -31,14 +32,14 @@ uint16_t SkDiscreteMapper::mapUnit16(uint16_t input) {
 
 SkDiscreteMapper::SkDiscreteMapper(SkFlattenableReadBuffer& rb)
         : SkUnitMapper(rb) {
-    fSegments = rb.readU32();
-    fScale = rb.readU32();
+    fSegments = rb.readInt();
+    fScale = rb.read32();
 }
 
 void SkDiscreteMapper::flatten(SkFlattenableWriteBuffer& wb) const {
     this->INHERITED::flatten(wb);
 
-    wb.write32(fSegments);
+    wb.writeInt(fSegments);
     wb.write32(fScale);
 }
 
index 6bfd9f26a2fb5cfea4aeb6c9a8c8c9ea34909454..7cfb467c2b578097c4dbe1c1e91f778388d7da90 100644 (file)
@@ -20,7 +20,7 @@ static SkFlattenable* reincarnate_flattenable(SkFlattenable* obj) {
     size_t size = wb.size();
     SkAutoSMalloc<1024> storage(size);
     // make a copy into storage
-    wb.flatten(storage.get());
+    wb.writeToMemory(storage.get());
 
     SkOrderedReadBuffer rb(storage.get(), size);
     return rb.readFlattenable();