aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-30 18:58:24 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-30 18:58:24 +0000
commit8b0e8ac5f582de80356019406e2975079bf0829d (patch)
tree9f43589895207dfcf422d41318b371c9540f1ada /include/core
parent5fbccb35eb9e7e8cfa3c6b02026206db77990324 (diff)
Refactor read and write buffers.
Eliminates SkFlattenable{Read,Write}Buffer, promoting SkOrdered{Read,Write}Buffer a step each in the hierarchy. What used to be this: SkFlattenableWriteBuffer -> SkOrderedWriteBuffer SkFlattenableReadBuffer -> SkOrderedReadBuffer SkFlattenableReadBuffer -> SkValidatingReadBuffer is now SkWriteBuffer SkReadBuffer -> SkValidatingReadBuffer Benefits: - code is simpler, names are less wordy - the generic SkFlattenableFooBuffer code in SkPaint was incorrect; removed - write buffers are completely devirtualized, important for record speed This refactoring was mostly mechanical. You aren't going to find anything interesting in files with less than 10 lines changed. BUG=skia: R=reed@google.com, scroggo@google.com, djsollen@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/134163010 git-svn-id: http://skia.googlecode.com/svn/trunk@13245 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkAnnotation.h8
-rw-r--r--include/core/SkBitmap.h4
-rw-r--r--include/core/SkColorFilter.h2
-rw-r--r--include/core/SkColorShader.h4
-rw-r--r--include/core/SkColorTable.h4
-rw-r--r--include/core/SkComposeShader.h4
-rw-r--r--include/core/SkDrawLooper.h2
-rw-r--r--include/core/SkEmptyShader.h2
-rw-r--r--include/core/SkFlattenable.h16
-rw-r--r--include/core/SkFlattenableBuffers.h260
-rw-r--r--include/core/SkImageFilter.h8
-rw-r--r--include/core/SkImageInfo.h8
-rw-r--r--include/core/SkMallocPixelRef.h4
-rw-r--r--include/core/SkMaskFilter.h2
-rw-r--r--include/core/SkPaint.h8
-rw-r--r--include/core/SkPaintOptionsAndroid.h8
-rw-r--r--include/core/SkPathEffect.h10
-rw-r--r--include/core/SkPicture.h4
-rw-r--r--include/core/SkPixelRef.h4
-rw-r--r--include/core/SkRasterizer.h2
-rw-r--r--include/core/SkReadBuffer.h205
-rw-r--r--include/core/SkShader.h4
-rw-r--r--include/core/SkUnitMapper.h2
-rw-r--r--include/core/SkWriteBuffer.h121
-rw-r--r--include/core/SkXfermode.h6
25 files changed, 389 insertions, 313 deletions
diff --git a/include/core/SkAnnotation.h b/include/core/SkAnnotation.h
index 4d17b79004..872bb941a5 100644
--- a/include/core/SkAnnotation.h
+++ b/include/core/SkAnnotation.h
@@ -12,8 +12,8 @@
#include "SkString.h"
class SkData;
-class SkFlattenableReadBuffer;
-class SkFlattenableWriteBuffer;
+class SkReadBuffer;
+class SkWriteBuffer;
class SkStream;
class SkWStream;
struct SkPoint;
@@ -32,8 +32,8 @@ public:
*/
SkData* find(const char key[]) const;
- SkAnnotation(SkFlattenableReadBuffer&);
- void writeToBuffer(SkFlattenableWriteBuffer&) const;
+ SkAnnotation(SkReadBuffer&);
+ void writeToBuffer(SkWriteBuffer&) const;
private:
SkString fKey;
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 2cdac27bad..4951cf19cf 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -658,8 +658,8 @@ public:
buffers as they can optimize the recording process and avoid recording
duplicate bitmaps and pixelRefs.
*/
- void flatten(SkFlattenableWriteBuffer&) const;
- void unflatten(SkFlattenableReadBuffer&);
+ void flatten(SkWriteBuffer&) const;
+ void unflatten(SkReadBuffer&);
SkDEBUGCODE(void validate() const;)
diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h
index 106e5bb86f..a5ffca818d 100644
--- a/include/core/SkColorFilter.h
+++ b/include/core/SkColorFilter.h
@@ -135,7 +135,7 @@ public:
protected:
SkColorFilter() {}
- SkColorFilter(SkFlattenableReadBuffer& rb) : INHERITED(rb) {}
+ SkColorFilter(SkReadBuffer& rb) : INHERITED(rb) {}
private:
typedef SkFlattenable INHERITED;
diff --git a/include/core/SkColorShader.h b/include/core/SkColorShader.h
index c3790682e4..5b8a86dfc1 100644
--- a/include/core/SkColorShader.h
+++ b/include/core/SkColorShader.h
@@ -52,8 +52,8 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader)
protected:
- SkColorShader(SkFlattenableReadBuffer&);
- virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+ SkColorShader(SkReadBuffer&);
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
private:
diff --git a/include/core/SkColorTable.h b/include/core/SkColorTable.h
index 52300fc427..e4c8c86c13 100644
--- a/include/core/SkColorTable.h
+++ b/include/core/SkColorTable.h
@@ -75,8 +75,8 @@ public:
SkDEBUGCODE(f16BitCacheLockCount -= 1);
}
- explicit SkColorTable(SkFlattenableReadBuffer&);
- void writeToBuffer(SkFlattenableWriteBuffer&) const;
+ explicit SkColorTable(SkReadBuffer&);
+ void writeToBuffer(SkWriteBuffer&) const;
private:
SkPMColor* fColors;
diff --git a/include/core/SkComposeShader.h b/include/core/SkComposeShader.h
index 524161b785..1fefd1369a 100644
--- a/include/core/SkComposeShader.h
+++ b/include/core/SkComposeShader.h
@@ -43,8 +43,8 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader)
protected:
- SkComposeShader(SkFlattenableReadBuffer& );
- virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+ SkComposeShader(SkReadBuffer& );
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
private:
diff --git a/include/core/SkDrawLooper.h b/include/core/SkDrawLooper.h
index d6028ff94c..4609c1dcf9 100644
--- a/include/core/SkDrawLooper.h
+++ b/include/core/SkDrawLooper.h
@@ -68,7 +68,7 @@ public:
protected:
SkDrawLooper() {}
- SkDrawLooper(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
+ SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {}
private:
typedef SkFlattenable INHERITED;
diff --git a/include/core/SkEmptyShader.h b/include/core/SkEmptyShader.h
index 08c131db1b..3f7dae41a9 100644
--- a/include/core/SkEmptyShader.h
+++ b/include/core/SkEmptyShader.h
@@ -34,7 +34,7 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmptyShader)
protected:
- SkEmptyShader(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
+ SkEmptyShader(SkReadBuffer& buffer) : INHERITED(buffer) {}
private:
typedef SkShader INHERITED;
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index 5a6e2ae889..ee7a433710 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -12,8 +12,8 @@
#include "SkRefCnt.h"
-class SkFlattenableReadBuffer;
-class SkFlattenableWriteBuffer;
+class SkReadBuffer;
+class SkWriteBuffer;
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \
@@ -32,7 +32,7 @@ class SkFlattenableWriteBuffer;
#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \
+ static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \
return SkNEW_ARGS(flattenable, (buffer)); \
}
@@ -67,7 +67,7 @@ public:
SK_DECLARE_INST_COUNT(SkFlattenable)
- typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&);
+ typedef SkFlattenable* (*Factory)(SkReadBuffer&);
SkFlattenable() {}
@@ -94,19 +94,19 @@ public:
}
};
-protected:
- SkFlattenable(SkFlattenableReadBuffer&) {}
/** Override this to write data specific to your subclass into the buffer,
being sure to call your super-class' version first. This data will later
be passed to your Factory function, returned by getFactory().
*/
- virtual void flatten(SkFlattenableWriteBuffer&) const;
+ virtual void flatten(SkWriteBuffer&) const;
+
+protected:
+ SkFlattenable(SkReadBuffer&) {}
private:
static void InitializeFlattenablesIfNeeded();
friend class SkGraphics;
- friend class SkFlattenableWriteBuffer;
typedef SkRefCnt INHERITED;
};
diff --git a/include/core/SkFlattenableBuffers.h b/include/core/SkFlattenableBuffers.h
index aa61f21a7b..3e5d5b94ee 100644
--- a/include/core/SkFlattenableBuffers.h
+++ b/include/core/SkFlattenableBuffers.h
@@ -1,260 +1,10 @@
-
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
+// Temporary shim to keep a couple dependencies working in Chromium.
#ifndef SkFlattenableBuffers_DEFINED
#define SkFlattenableBuffers_DEFINED
-#include "SkColor.h"
-#include "SkData.h"
-#include "SkPaint.h"
-#include "SkPoint.h"
-
-class SkBitmap;
-class SkDrawLooper;
-class SkFlattenable;
-struct SkIRect;
-class SkMatrix;
-class SkOrderedReadBuffer;
-class SkOrderedWriteBuffer;
-class SkPath;
-class SkPixelRef;
-struct SkRect;
-class SkRegion;
-class SkStream;
-class SkString;
-class SkTypeface;
-class SkUnitMapper;
-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,
- /** The kValidation_Flag is used to force stream validations (by making
- * sure that no operation reads past the end of the stream, for example)
- * and error handling if any reading operation yields an invalid value.
- */
- kValidation_Flag = 1 << 3,
- };
-
- void setFlags(uint32_t flags) { fFlags = flags; }
- uint32_t getFlags() const { return fFlags; }
-
- bool isCrossProcess() const { return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag)); }
- bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); }
- bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); }
- bool isValidating() const { return SkToBool(fFlags & kValidation_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 void readString(SkString* string) = 0;
- virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) = 0;
-
- /**
- @param type This parameter is only used when using SkValidatingReadBuffer. It will verify
- that the object about to be deserialized is of the given type or early return
- NULL otherwise. The type provided here is the type of the base class of the
- object to deserialize.
- */
- virtual SkFlattenable* readFlattenable(SkFlattenable::Type type) = 0;
-
- SkColorFilter* readColorFilter();
- SkDrawLooper* readDrawLooper();
- SkImageFilter* readImageFilter();
- SkMaskFilter* readMaskFilter();
- SkPathEffect* readPathEffect();
- SkPixelRef* readPixelRef();
- SkRasterizer* readRasterizer();
- SkShader* readShader();
- SkUnitMapper* readUnitMapper();
- SkXfermode* readXfermode();
-
- // common data structures
- 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
-
- /**
- * In the following read.*Array(...) functions, the size parameter specifies the allocation
- * size in number of elements (or in bytes, for void*) of the pointer parameter. If the
- * pointer parameter's size does not match the size to be read, the pointer parameter's memory
- * will then stay uninitialized, the cursor will be moved to the end of the stream and, in the
- * case where isValidating() is true, an error flag will be set internally (see
- * SkValidatingReadBuffer).
- * If the sizes match, then "size" amount of memory will be read.
- *
- * @param size amount of memory expected to be read
- * @return true if the size parameter matches the size to be read, false otherwise
- */
- virtual bool readByteArray(void* value, size_t size) = 0;
- virtual bool readColorArray(SkColor* colors, size_t size) = 0;
- virtual bool readIntArray(int32_t* values, size_t size) = 0;
- virtual bool readPointArray(SkPoint* points, size_t size) = 0;
- virtual bool readScalarArray(SkScalar* values, size_t size) = 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 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;
- }
-
- SkData* readByteArrayAsData() {
- size_t len = this->getArrayCount();
- void* buffer = NULL;
- if (this->validateAvailable(len)) {
- buffer = sk_malloc_throw(len);
- (void)this->readByteArray(buffer, len);
- } else {
- len = 0;
- }
- return SkData::NewFromMalloc(buffer, len);
- }
-
- /** This function validates that the isValid input parameter is true
- * If isValidating() is false, then true is always returned
- * If isValidating() is true, then true is returned until validate() is called with isValid
- * set to false. When isValid is false, an error flag will be set internally and, from that
- * point on, validate() will return false. The error flag cannot be unset.
- *
- * @param isValid result of a test that is expected to be true
- */
- virtual bool validate(bool isValid);
-
- /** This function returns true by default
- * If isValidating() is true, it will return false if the internal error flag is set.
- * Otherwise, it will return true.
- */
- virtual bool isValid() const { return true; }
-
- /** This function returns true by default
- * If isValidating() is true, it will return whether there's
- * at least "size" memory left to read in the stream.
- *
- * @param size amount of memory that should still be available
- */
- virtual bool validateAvailable(size_t size) { return true; }
-
-private:
- template <typename T> T* readFlattenableT();
- 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(const 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 writeBitmap(const SkBitmap& bitmap) = 0;
- virtual void writeTypeface(SkTypeface* typeface) = 0;
-
- virtual bool writeToStream(SkWStream*) = 0;
-
- enum Flags {
- kCrossProcess_Flag = 0x01,
- /** The kValidation_Flag is used here to make sure the write operation
- * is symmetric with the read operation using the equivalent flag
- * SkFlattenableReadBuffer::kValidation_Flag.
- */
- kValidation_Flag = 0x02,
- };
-
- uint32_t getFlags() const { return fFlags; }
- void setFlags(uint32_t flags) { fFlags = flags; }
-
- bool isCrossProcess() const {
- return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag));
- }
-
- bool isValidating() const {
- return SkToBool(fFlags & kValidation_Flag);
- }
-
- bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
-
- void writeDataAsByteArray(SkData* data) {
- this->writeByteArray(data->data(), data->size());
- }
-
-protected:
- // A helper function so that each subclass does not have to be a friend of SkFlattenable
- void flattenObject(const SkFlattenable* obj, SkFlattenableWriteBuffer& buffer);
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
- uint32_t fFlags;
-};
+typedef SkReadBuffer SkFlattenableReadBuffer;
-#endif
+#endif//SkFlattenableBuffers_DEFINED
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index 25d3bac802..37993c0ea3 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -160,15 +160,15 @@ protected:
virtual ~SkImageFilter();
/**
- * Constructs a new SkImageFilter read from an SkFlattenableReadBuffer object.
+ * Constructs a new SkImageFilter read from an SkReadBuffer object.
*
* @param inputCount The exact number of inputs expected for this SkImageFilter object.
* -1 can be used if the filter accepts any number of inputs.
- * @param rb SkFlattenableReadBuffer object from which the SkImageFilter is read.
+ * @param rb SkReadBuffer object from which the SkImageFilter is read.
*/
- explicit SkImageFilter(int inputCount, SkFlattenableReadBuffer& rb);
+ explicit SkImageFilter(int inputCount, SkReadBuffer& rb);
- virtual void flatten(SkFlattenableWriteBuffer& wb) const SK_OVERRIDE;
+ virtual void flatten(SkWriteBuffer& wb) const SK_OVERRIDE;
/**
* This is the virtual which should be overridden by the derived class
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index d389d5e00a..722ff27437 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -11,8 +11,8 @@
#include "SkTypes.h"
#include "SkSize.h"
-class SkFlattenableWriteBuffer;
-class SkFlattenableReadBuffer;
+class SkWriteBuffer;
+class SkReadBuffer;
/**
* Describes how to interpret the alpha compoent of a pixel.
@@ -178,8 +178,8 @@ struct SkImageInfo {
return 0 != memcmp(this, &other, sizeof(other));
}
- void unflatten(SkFlattenableReadBuffer&);
- void flatten(SkFlattenableWriteBuffer&) const;
+ void unflatten(SkReadBuffer&);
+ void flatten(SkWriteBuffer&) const;
size_t getSafeSize(size_t rowBytes) const {
if (0 == fHeight) {
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index 4607fa2843..f6a57b3dea 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -91,12 +91,12 @@ protected:
// The ownPixels version of this constructor is deprecated.
SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
bool ownPixels);
- SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
+ SkMallocPixelRef(SkReadBuffer& buffer);
virtual ~SkMallocPixelRef();
virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
virtual void onUnlockPixels() SK_OVERRIDE;
- virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE;
private:
diff --git a/include/core/SkMaskFilter.h b/include/core/SkMaskFilter.h
index 20dc379721..b47e034e3c 100644
--- a/include/core/SkMaskFilter.h
+++ b/include/core/SkMaskFilter.h
@@ -137,7 +137,7 @@ public:
protected:
// empty for now, but lets get our subclass to remember to init us for the future
- SkMaskFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
+ SkMaskFilter(SkReadBuffer& buffer) : INHERITED(buffer) {}
enum FilterReturn {
kFalse_FilterReturn,
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 00ec29e42e..abb859950c 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -24,8 +24,8 @@ class SkAutoGlyphCache;
class SkColorFilter;
class SkDescriptor;
struct SkDeviceProperties;
-class SkFlattenableReadBuffer;
-class SkFlattenableWriteBuffer;
+class SkReadBuffer;
+class SkWriteBuffer;
struct SkGlyph;
struct SkRect;
class SkGlyphCache;
@@ -72,8 +72,8 @@ public:
return !(a == b);
}
- void flatten(SkFlattenableWriteBuffer&) const;
- void unflatten(SkFlattenableReadBuffer&);
+ void flatten(SkWriteBuffer&) const;
+ void unflatten(SkReadBuffer&);
/** Restores the paint to its initial settings.
*/
diff --git a/include/core/SkPaintOptionsAndroid.h b/include/core/SkPaintOptionsAndroid.h
index f49345f12b..ab84ec050e 100644
--- a/include/core/SkPaintOptionsAndroid.h
+++ b/include/core/SkPaintOptionsAndroid.h
@@ -13,8 +13,8 @@
#include "SkTypes.h"
#include "SkString.h"
-class SkFlattenableReadBuffer;
-class SkFlattenableWriteBuffer;
+class SkReadBuffer;
+class SkWriteBuffer;
/** \class SkLanguage
@@ -80,8 +80,8 @@ public:
fUseFontFallbacks != b.fUseFontFallbacks;
}
- void flatten(SkFlattenableWriteBuffer&) const;
- void unflatten(SkFlattenableReadBuffer&);
+ void flatten(SkWriteBuffer&) const;
+ void unflatten(SkReadBuffer&);
/** Return the paint's language value used for drawing text.
@return the paint's language value used for drawing text.
diff --git a/include/core/SkPathEffect.h b/include/core/SkPathEffect.h
index ed6d93b765..3f38f3a101 100644
--- a/include/core/SkPathEffect.h
+++ b/include/core/SkPathEffect.h
@@ -109,7 +109,7 @@ public:
SK_DEFINE_FLATTENABLE_TYPE(SkPathEffect)
protected:
- SkPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
+ SkPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {}
private:
// illegal
@@ -131,8 +131,8 @@ public:
virtual ~SkPairPathEffect();
protected:
- SkPairPathEffect(SkFlattenableReadBuffer&);
- virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+ SkPairPathEffect(SkReadBuffer&);
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
// these are visible to our subclasses
SkPathEffect* fPE0, *fPE1;
@@ -162,7 +162,7 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
protected:
- SkComposePathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
+ SkComposePathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {}
private:
// illegal
@@ -193,7 +193,7 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)
protected:
- SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
+ SkSumPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {}
private:
// illegal
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index d63b66befa..82d6835dbd 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -169,8 +169,8 @@ public:
/**
* Function to encode an SkBitmap to an SkData. A function with this
- * signature can be passed to serialize() and SkOrderedWriteBuffer.
- * Returning NULL will tell the SkOrderedWriteBuffer to use
+ * signature can be passed to serialize() and SkWriteBuffer.
+ * Returning NULL will tell the SkWriteBuffer to use
* SkBitmap::flatten() to store the bitmap.
*
* @param pixelRefOffset DEPRECATED -- caller assumes it will return 0.
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index 5a9a5a05f7..439a4ca54e 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -328,8 +328,8 @@ protected:
SkBaseMutex* mutex() const { return fMutex; }
// serialization
- SkPixelRef(SkFlattenableReadBuffer&, SkBaseMutex*);
- virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+ SkPixelRef(SkReadBuffer&, SkBaseMutex*);
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
// only call from constructor. Flags this to always be locked, removing
// the need to grab the mutex and call onLockPixels/onUnlockPixels.
diff --git a/include/core/SkRasterizer.h b/include/core/SkRasterizer.h
index 6e6224ef35..d916b231b7 100644
--- a/include/core/SkRasterizer.h
+++ b/include/core/SkRasterizer.h
@@ -33,7 +33,7 @@ public:
SK_DEFINE_FLATTENABLE_TYPE(SkRasterizer)
protected:
- SkRasterizer(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
+ SkRasterizer(SkReadBuffer& buffer) : INHERITED(buffer) {}
virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,
const SkIRect* clipBounds,
diff --git a/include/core/SkReadBuffer.h b/include/core/SkReadBuffer.h
new file mode 100644
index 0000000000..75cc64b2be
--- /dev/null
+++ b/include/core/SkReadBuffer.h
@@ -0,0 +1,205 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkReadBuffer_DEFINED
+#define SkReadBuffer_DEFINED
+
+#include "SkBitmapHeap.h"
+#include "SkColorFilter.h"
+#include "SkData.h"
+#include "SkDrawLooper.h"
+#include "SkImageFilter.h"
+#include "SkMaskFilter.h"
+#include "SkPath.h"
+#include "SkPathEffect.h"
+#include "SkPicture.h"
+#include "SkPixelRef.h"
+#include "SkRasterizer.h"
+#include "SkReadBuffer.h"
+#include "SkReader32.h"
+#include "SkRefCnt.h"
+#include "SkShader.h"
+#include "SkUnitMapper.h"
+#include "SkWriteBuffer.h"
+#include "SkXfermode.h"
+
+class SkBitmap;
+
+#if defined(SK_DEBUG) && defined(SK_BUILD_FOR_MAC)
+ #define DEBUG_NON_DETERMINISTIC_ASSERT
+#endif
+
+class SkReadBuffer {
+public:
+ SkReadBuffer();
+ SkReadBuffer(const void* data, size_t size);
+ SkReadBuffer(SkStream* stream);
+ virtual ~SkReadBuffer();
+
+ enum Flags {
+ kCrossProcess_Flag = 1 << 0,
+ kScalarIsFloat_Flag = 1 << 1,
+ kPtrIs64Bit_Flag = 1 << 2,
+ kValidation_Flag = 1 << 3,
+ };
+
+ void setFlags(uint32_t flags) { fFlags = flags; }
+ uint32_t getFlags() const { return fFlags; }
+
+ bool isCrossProcess() const {
+ return this->isValidating() || SkToBool(fFlags & kCrossProcess_Flag);
+ }
+ bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); }
+ bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); }
+ bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }
+
+ SkReader32* getReader32() { return &fReader; }
+
+ uint32_t size() { return fReader.size(); }
+ uint32_t offset() { return fReader.offset(); }
+ bool eof() { return fReader.eof(); }
+ const void* skip(size_t size) { return fReader.skip(size); }
+
+ // primitives
+ virtual bool readBool();
+ virtual SkColor readColor();
+ virtual SkFixed readFixed();
+ virtual int32_t readInt();
+ virtual SkScalar readScalar();
+ virtual uint32_t readUInt();
+ virtual int32_t read32();
+
+ void* readFunctionPtr() {
+ void* ptr;
+ this->readByteArray(&ptr, sizeof(ptr));
+ return ptr;
+ }
+
+ // strings -- the caller is responsible for freeing the string contents
+ virtual void readString(SkString* string);
+ virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding);
+
+ // common data structures
+ virtual void readPoint(SkPoint* point);
+ SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; }
+ virtual void readMatrix(SkMatrix* matrix);
+ virtual void readIRect(SkIRect* rect);
+ virtual void readRect(SkRect* rect);
+ virtual void readRegion(SkRegion* region);
+ virtual void readPath(SkPath* path);
+ void readPaint(SkPaint* paint) { paint->unflatten(*this); }
+
+ virtual SkFlattenable* readFlattenable(SkFlattenable::Type);
+ template <typename T> T* readFlattenable() {
+ return (T*) this->readFlattenable(T::GetFlattenableType());
+ }
+ SkColorFilter* readColorFilter() { return this->readFlattenable<SkColorFilter>(); }
+ SkDrawLooper* readDrawLooper() { return this->readFlattenable<SkDrawLooper>(); }
+ SkImageFilter* readImageFilter() { return this->readFlattenable<SkImageFilter>(); }
+ SkMaskFilter* readMaskFilter() { return this->readFlattenable<SkMaskFilter>(); }
+ SkPathEffect* readPathEffect() { return this->readFlattenable<SkPathEffect>(); }
+ SkPixelRef* readPixelRef() { return this->readFlattenable<SkPixelRef>(); }
+ SkRasterizer* readRasterizer() { return this->readFlattenable<SkRasterizer>(); }
+ SkShader* readShader() { return this->readFlattenable<SkShader>(); }
+ SkUnitMapper* readUnitMapper() { return this->readFlattenable<SkUnitMapper>(); }
+ SkXfermode* readXfermode() { return this->readFlattenable<SkXfermode>(); }
+
+
+ // binary data and arrays
+ virtual bool readByteArray(void* value, size_t size);
+ virtual bool readColorArray(SkColor* colors, size_t size);
+ virtual bool readIntArray(int32_t* values, size_t size);
+ virtual bool readPointArray(SkPoint* points, size_t size);
+ virtual bool readScalarArray(SkScalar* values, size_t size);
+
+ SkData* readByteArrayAsData() {
+ size_t len = this->getArrayCount();
+ if (!this->validateAvailable(len)) {
+ return SkData::NewEmpty();
+ }
+ void* buffer = sk_malloc_throw(len);
+ this->readByteArray(buffer, len);
+ return SkData::NewFromMalloc(buffer, len);
+ }
+
+ // helpers to get info about arrays and binary data
+ virtual uint32_t getArrayCount();
+
+ virtual void readBitmap(SkBitmap* bitmap);
+ virtual SkTypeface* readTypeface();
+
+ void setBitmapStorage(SkBitmapHeapReader* bitmapStorage) {
+ SkRefCnt_SafeAssign(fBitmapStorage, bitmapStorage);
+ }
+
+ 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
+ * SkWriteBuffer::setNamedFactoryRecorder.
+ */
+ void setFactoryArray(SkTDArray<SkFlattenable::Factory>* array) {
+ fFactoryTDArray = array;
+ fFactoryArray = NULL;
+ fFactoryCount = 0;
+ }
+
+ /**
+ * Provide a function to decode an SkBitmap from encoded data. Only used if the writer
+ * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap with the
+ * appropriate size will be used.
+ */
+ void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) {
+ fBitmapDecoder = bitmapDecoder;
+ }
+
+ // Default impelementations don't check anything.
+ virtual bool validate(bool isValid) { return true; }
+ virtual bool isValid() const { return true; }
+ virtual bool validateAvailable(size_t size) { return true; }
+
+private:
+ bool readArray(void* value, size_t size, size_t elementSize);
+
+ uint32_t fFlags;
+
+ SkReader32 fReader;
+ void* fMemoryPtr;
+
+ SkBitmapHeapReader* fBitmapStorage;
+ SkTypeface** fTFArray;
+ int fTFCount;
+
+ SkTDArray<SkFlattenable::Factory>* fFactoryTDArray;
+ SkFlattenable::Factory* fFactoryArray;
+ int fFactoryCount;
+
+ SkPicture::InstallPixelRefProc fBitmapDecoder;
+
+#ifdef DEBUG_NON_DETERMINISTIC_ASSERT
+ // Debugging counter to keep track of how many bitmaps we
+ // have decoded.
+ int fDecodedBitmapIndex;
+#endif // DEBUG_NON_DETERMINISTIC_ASSERT
+};
+
+#endif // SkReadBuffer_DEFINED
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index cdb7a2fdbf..108c6b0829 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -363,8 +363,8 @@ protected:
const SkMatrix& getTotalInverse() const { return fTotalInverse; }
MatrixClass getInverseClass() const { return (MatrixClass)fTotalInverseClass; }
- SkShader(SkFlattenableReadBuffer& );
- virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+ SkShader(SkReadBuffer& );
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
private:
SkMatrix fLocalMatrix;
SkMatrix fTotalInverse;
diff --git a/include/core/SkUnitMapper.h b/include/core/SkUnitMapper.h
index 57a8b8332e..46f6eddd70 100644
--- a/include/core/SkUnitMapper.h
+++ b/include/core/SkUnitMapper.h
@@ -28,7 +28,7 @@ public:
SK_DEFINE_FLATTENABLE_TYPE(SkUnitMapper)
protected:
- SkUnitMapper(SkFlattenableReadBuffer& rb) : SkFlattenable(rb) {}
+ SkUnitMapper(SkReadBuffer& rb) : SkFlattenable(rb) {}
private:
typedef SkFlattenable INHERITED;
diff --git a/include/core/SkWriteBuffer.h b/include/core/SkWriteBuffer.h
new file mode 100644
index 0000000000..ab56f9d48d
--- /dev/null
+++ b/include/core/SkWriteBuffer.h
@@ -0,0 +1,121 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkWriteBuffer_DEFINED
+#define SkWriteBuffer_DEFINED
+
+#include "SkBitmapHeap.h"
+#include "SkData.h"
+#include "SkPath.h"
+#include "SkPicture.h"
+#include "SkRefCnt.h"
+#include "SkWriter32.h"
+
+class SkBitmap;
+class SkFactorySet;
+class SkFlattenable;
+class SkNamedFactorySet;
+class SkRefCntSet;
+
+class SkWriteBuffer {
+public:
+ SkWriteBuffer();
+ SkWriteBuffer(void* initialStorage, size_t storageSize);
+ ~SkWriteBuffer();
+
+ enum Flags {
+ kCrossProcess_Flag = 1 << 0,
+ kValidation_Flag = 1 << 1,
+ };
+ void setFlags(uint32_t flags) { fFlags = flags; }
+ uint32_t getFlags() const { return fFlags; }
+
+ bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }
+ bool isCrossProcess() const {
+ return this->isValidating() || SkToBool(fFlags & kCrossProcess_Flag);
+ }
+
+ SkWriter32* getWriter32() { return &fWriter; }
+ void reset(void* storage = NULL, size_t storageSize = 0) {
+ fWriter.reset(storage, storageSize);
+ }
+
+ uint32_t* reserve(size_t size) { return fWriter.reserve(size); }
+
+ size_t bytesWritten() const { return fWriter.bytesWritten(); }
+
+ void writeByteArray(const void* data, size_t size);
+ void writeDataAsByteArray(SkData* data) { this->writeByteArray(data->data(), data->size()); }
+ void writeBool(bool value);
+ void writeFixed(SkFixed value);
+ void writeScalar(SkScalar value);
+ void writeScalarArray(const SkScalar* value, uint32_t count);
+ void writeInt(int32_t value);
+ void writeIntArray(const int32_t* value, uint32_t count);
+ void writeUInt(uint32_t value);
+ void write32(int32_t value);
+ void writeString(const char* value);
+ void writeEncodedString(const void* value, size_t byteLength, SkPaint::TextEncoding encoding);
+ void writeFunctionPtr(void* ptr) { this->writeByteArray(&ptr, sizeof(ptr)); }
+
+ void writeFlattenable(const SkFlattenable* flattenable);
+ void writeColor(const SkColor& color);
+ void writeColorArray(const SkColor* color, uint32_t count);
+ void writePoint(const SkPoint& point);
+ void writePointArray(const SkPoint* point, uint32_t count);
+ void writeMatrix(const SkMatrix& matrix);
+ void writeIRect(const SkIRect& rect);
+ void writeRect(const SkRect& rect);
+ void writeRegion(const SkRegion& region);
+ void writePath(const SkPath& path);
+ size_t writeStream(SkStream* stream, size_t length);
+ void writeBitmap(const SkBitmap& bitmap);
+ void writeTypeface(SkTypeface* typeface);
+ void writePaint(const SkPaint& paint) { paint.flatten(*this); }
+
+ bool writeToStream(SkWStream*);
+ void writeToMemory(void* dst) { fWriter.flatten(dst); }
+
+ SkFactorySet* setFactoryRecorder(SkFactorySet*);
+ SkNamedFactorySet* setNamedFactoryRecorder(SkNamedFactorySet*);
+
+ SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
+ SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
+
+ /**
+ * Set an SkBitmapHeap to store bitmaps rather than flattening.
+ *
+ * Incompatible with an EncodeBitmap function. If an EncodeBitmap function is set, setting an
+ * SkBitmapHeap will set the function to NULL in release mode and crash in debug.
+ */
+ void setBitmapHeap(SkBitmapHeap*);
+
+ /**
+ * Provide a function to encode an SkBitmap to an SkData. writeBitmap will attempt to use
+ * bitmapEncoder to store the SkBitmap. If the reader does not provide a function to decode, it
+ * will not be able to restore SkBitmaps, but will still be able to read the rest of the stream.
+ * bitmapEncoder will never be called with a NULL pixelRefOffset.
+ *
+ * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will be set to NULL in
+ * release and crash in debug.
+ */
+ void setBitmapEncoder(SkPicture::EncodeBitmap bitmapEncoder);
+
+private:
+ uint32_t fFlags;
+ SkFactorySet* fFactorySet;
+ SkNamedFactorySet* fNamedFactorySet;
+ SkWriter32 fWriter;
+
+ SkBitmapHeap* fBitmapHeap;
+ SkRefCntSet* fTFSet;
+
+ SkPicture::EncodeBitmap fBitmapEncoder;
+};
+
+#endif // SkWriteBuffer_DEFINED
diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h
index 3ef2241c7d..31b8081f85 100644
--- a/include/core/SkXfermode.h
+++ b/include/core/SkXfermode.h
@@ -218,7 +218,7 @@ public:
SK_DEFINE_FLATTENABLE_TYPE(SkXfermode)
protected:
- SkXfermode(SkFlattenableReadBuffer& rb) : SkFlattenable(rb) {}
+ SkXfermode(SkReadBuffer& rb) : SkFlattenable(rb) {}
/** The default implementation of xfer32/xfer16/xferA8 in turn call this
method, 1 color at a time (upscaled to a SkPMColor). The default
@@ -264,8 +264,8 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkProcXfermode)
protected:
- SkProcXfermode(SkFlattenableReadBuffer&);
- virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+ SkProcXfermode(SkReadBuffer&);
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
// allow subclasses to update this after we unflatten
void setProc(SkXfermodeProc proc) {