force readbuffer clients to use specialized readFoo for flattenables
BUG= R=mtklein@google.com Review URL: https://codereview.chromium.org/26702002 git-svn-id: http://skia.googlecode.com/svn/trunk@11803 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
d36522d12d
commit
353482251e
@ -15,6 +15,7 @@
|
||||
#include "SkPoint.h"
|
||||
|
||||
class SkBitmap;
|
||||
class SkDrawLooper;
|
||||
class SkFlattenable;
|
||||
struct SkIRect;
|
||||
class SkMatrix;
|
||||
@ -28,8 +29,22 @@ class SkRegion;
|
||||
class SkStream;
|
||||
class SkString;
|
||||
class SkTypeface;
|
||||
class SkUnitMapper;
|
||||
class SkWStream;
|
||||
|
||||
enum SkEffectType {
|
||||
kColorFilter_SkEffectType,
|
||||
kDrawLooper_SkEffectType,
|
||||
kImageFilter_SkEffectType,
|
||||
kMaskFilter_SkEffectType,
|
||||
kPathEffect_SkEffectType,
|
||||
kPixelRef_SkEffectType,
|
||||
kRasterizer_SkEffectType,
|
||||
kShader_SkEffectType,
|
||||
kUnitMapper_SkEffectType,
|
||||
kXfermode_SkEffectType,
|
||||
};
|
||||
|
||||
class SkFlattenableReadBuffer {
|
||||
public:
|
||||
SkFlattenableReadBuffer();
|
||||
@ -64,8 +79,40 @@ public:
|
||||
virtual void readString(SkString* string) = 0;
|
||||
virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) = 0;
|
||||
|
||||
virtual SkFlattenable* readFlattenable(SkEffectType) = 0;
|
||||
|
||||
SkColorFilter* readColorFilter() {
|
||||
return (SkColorFilter*)this->readFlattenable(kColorFilter_SkEffectType);
|
||||
}
|
||||
SkDrawLooper* readDrawLooper() {
|
||||
return (SkDrawLooper*)this->readFlattenable(kDrawLooper_SkEffectType);
|
||||
}
|
||||
SkImageFilter* readImageFilter() {
|
||||
return (SkImageFilter*)this->readFlattenable(kImageFilter_SkEffectType);
|
||||
}
|
||||
SkMaskFilter* readMaskFilter() {
|
||||
return (SkMaskFilter*)this->readFlattenable(kMaskFilter_SkEffectType);
|
||||
}
|
||||
SkPathEffect* readPathEffect() {
|
||||
return (SkPathEffect*)this->readFlattenable(kPathEffect_SkEffectType);
|
||||
}
|
||||
SkPixelRef* readPixelRef() {
|
||||
return (SkPixelRef*)this->readFlattenable(kPixelRef_SkEffectType);
|
||||
}
|
||||
SkRasterizer* readRasterizer() {
|
||||
return (SkRasterizer*)this->readFlattenable(kRasterizer_SkEffectType);
|
||||
}
|
||||
SkShader* readShader() {
|
||||
return (SkShader*)this->readFlattenable(kShader_SkEffectType);
|
||||
}
|
||||
SkUnitMapper* readUnitMapper() {
|
||||
return (SkUnitMapper*)this->readFlattenable(kUnitMapper_SkEffectType);
|
||||
}
|
||||
SkXfermode* readXfermode() {
|
||||
return (SkXfermode*)this->readFlattenable(kXfermode_SkEffectType);
|
||||
}
|
||||
|
||||
// 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;
|
||||
@ -106,10 +153,6 @@ public:
|
||||
return SkData::NewFromMalloc(buffer, len);
|
||||
}
|
||||
|
||||
template <typename T> T* readFlattenableT() {
|
||||
return static_cast<T*>(this->readFlattenable());
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t fFlags;
|
||||
};
|
||||
|
@ -1610,7 +1610,7 @@ void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) {
|
||||
switch (reftype) {
|
||||
case SERIALIZE_PIXELTYPE_REF_DATA: {
|
||||
size_t offset = buffer.readUInt();
|
||||
SkPixelRef* pr = buffer.readFlattenableT<SkPixelRef>();
|
||||
SkPixelRef* pr = buffer.readPixelRef();
|
||||
SkSafeUnref(this->setPixelRef(pr, offset));
|
||||
break;
|
||||
}
|
||||
|
@ -683,7 +683,7 @@ public:
|
||||
|
||||
protected:
|
||||
Sk3DShader(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
|
||||
fProxy = buffer.readFlattenableT<SkShader>();
|
||||
fProxy = buffer.readShader();
|
||||
fPMColor = buffer.readColor();
|
||||
fMask = NULL;
|
||||
}
|
||||
|
@ -27,15 +27,15 @@ SkComposeShader::SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode) {
|
||||
|
||||
SkComposeShader::SkComposeShader(SkFlattenableReadBuffer& buffer) :
|
||||
INHERITED(buffer) {
|
||||
fShaderA = buffer.readFlattenableT<SkShader>();
|
||||
fShaderA = buffer.readShader();
|
||||
if (NULL == fShaderA) {
|
||||
fShaderA = SkNEW_ARGS(SkColorShader, (0));
|
||||
}
|
||||
fShaderB = buffer.readFlattenableT<SkShader>();
|
||||
fShaderB = buffer.readShader();
|
||||
if (NULL == fShaderB) {
|
||||
fShaderB = SkNEW_ARGS(SkColorShader, (0));
|
||||
}
|
||||
fMode = buffer.readFlattenableT<SkXfermode>();
|
||||
fMode = buffer.readXfermode();
|
||||
}
|
||||
|
||||
SkComposeShader::~SkComposeShader() {
|
||||
|
@ -22,8 +22,8 @@ SkFilterShader::SkFilterShader(SkShader* shader, SkColorFilter* filter) {
|
||||
|
||||
SkFilterShader::SkFilterShader(SkFlattenableReadBuffer& buffer)
|
||||
: INHERITED(buffer) {
|
||||
fShader = buffer.readFlattenableT<SkShader>();
|
||||
fFilter = buffer.readFlattenableT<SkColorFilter>();
|
||||
fShader = buffer.readShader();
|
||||
fFilter = buffer.readColorFilter();
|
||||
}
|
||||
|
||||
SkFilterShader::~SkFilterShader() {
|
||||
|
@ -54,3 +54,4 @@ void SkFlattenableWriteBuffer::writePaint(const SkPaint& paint) {
|
||||
void SkFlattenableWriteBuffer::flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer) {
|
||||
obj->flatten(buffer);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "SkData.h"
|
||||
#include "SkFlattenable.h"
|
||||
#include "SkImageFilter.h"
|
||||
#include "SkOrderedReadBuffer.h"
|
||||
#include "SkOrderedWriteBuffer.h"
|
||||
|
||||
@ -22,7 +23,9 @@ SkData* SkSerializeFlattenable(SkFlattenable* flattenable) {
|
||||
return SkData::NewFromMalloc(data, size);
|
||||
}
|
||||
|
||||
// TODO: this guy should be renamed to ImageFilter, or take SkEffectType as
|
||||
// a parameter.
|
||||
SkFlattenable* SkDeserializeFlattenable(const void* data, size_t size) {
|
||||
SkOrderedReadBuffer buffer(data, size);
|
||||
return buffer.readFlattenable();
|
||||
return buffer.readImageFilter();
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ SkImageFilter::SkImageFilter(SkFlattenableReadBuffer& buffer)
|
||||
: fInputCount(buffer.readInt()), fInputs(new SkImageFilter*[fInputCount]) {
|
||||
for (int i = 0; i < fInputCount; i++) {
|
||||
if (buffer.readBool()) {
|
||||
fInputs[i] = static_cast<SkImageFilter*>(buffer.readFlattenable());
|
||||
fInputs[i] = buffer.readImageFilter();
|
||||
} else {
|
||||
fInputs[i] = NULL;
|
||||
}
|
||||
|
@ -268,7 +268,11 @@ SkTypeface* SkOrderedReadBuffer::readTypeface() {
|
||||
}
|
||||
}
|
||||
|
||||
SkFlattenable* SkOrderedReadBuffer::readFlattenable() {
|
||||
SkFlattenable* SkOrderedReadBuffer::readFlattenable(SkEffectType et) {
|
||||
//
|
||||
// TODO: confirm that et matches the factory we decide to use
|
||||
//
|
||||
|
||||
SkFlattenable::Factory factory = NULL;
|
||||
|
||||
if (fFactoryCount > 0) {
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) SK_OVERRIDE;
|
||||
|
||||
// common data structures
|
||||
virtual SkFlattenable* readFlattenable() SK_OVERRIDE;
|
||||
virtual SkFlattenable* readFlattenable(SkEffectType) SK_OVERRIDE;
|
||||
virtual void readPoint(SkPoint* point) SK_OVERRIDE;
|
||||
virtual void readMatrix(SkMatrix* matrix) SK_OVERRIDE;
|
||||
virtual void readIRect(SkIRect* rect) SK_OVERRIDE;
|
||||
|
@ -2178,14 +2178,14 @@ void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) {
|
||||
}
|
||||
|
||||
if (flatFlags & kHasEffects_FlatFlag) {
|
||||
SkSafeUnref(this->setPathEffect(buffer.readFlattenableT<SkPathEffect>()));
|
||||
SkSafeUnref(this->setShader(buffer.readFlattenableT<SkShader>()));
|
||||
SkSafeUnref(this->setXfermode(buffer.readFlattenableT<SkXfermode>()));
|
||||
SkSafeUnref(this->setMaskFilter(buffer.readFlattenableT<SkMaskFilter>()));
|
||||
SkSafeUnref(this->setColorFilter(buffer.readFlattenableT<SkColorFilter>()));
|
||||
SkSafeUnref(this->setRasterizer(buffer.readFlattenableT<SkRasterizer>()));
|
||||
SkSafeUnref(this->setLooper(buffer.readFlattenableT<SkDrawLooper>()));
|
||||
SkSafeUnref(this->setImageFilter(buffer.readFlattenableT<SkImageFilter>()));
|
||||
SkSafeUnref(this->setPathEffect(buffer.readPathEffect()));
|
||||
SkSafeUnref(this->setShader(buffer.readShader()));
|
||||
SkSafeUnref(this->setXfermode(buffer.readXfermode()));
|
||||
SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter()));
|
||||
SkSafeUnref(this->setColorFilter(buffer.readColorFilter()));
|
||||
SkSafeUnref(this->setRasterizer(buffer.readRasterizer()));
|
||||
SkSafeUnref(this->setLooper(buffer.readDrawLooper()));
|
||||
SkSafeUnref(this->setImageFilter(buffer.readImageFilter()));
|
||||
|
||||
if (buffer.readBool()) {
|
||||
this->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref();
|
||||
|
@ -48,8 +48,8 @@ void SkPairPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const {
|
||||
}
|
||||
|
||||
SkPairPathEffect::SkPairPathEffect(SkFlattenableReadBuffer& buffer) {
|
||||
fPE0 = buffer.readFlattenableT<SkPathEffect>();
|
||||
fPE1 = buffer.readFlattenableT<SkPathEffect>();
|
||||
fPE0 = buffer.readPathEffect();
|
||||
fPE1 = buffer.readPathEffect();
|
||||
// either of these may fail, so we have to check for nulls later on
|
||||
}
|
||||
|
||||
|
@ -66,14 +66,15 @@ void SkGlyph::zeroMetrics() {
|
||||
#define DUMP_RECx
|
||||
#endif
|
||||
|
||||
static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag) {
|
||||
static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag,
|
||||
SkEffectType et) {
|
||||
SkFlattenable* obj = NULL;
|
||||
uint32_t len;
|
||||
const void* data = desc->findEntry(tag, &len);
|
||||
|
||||
if (data) {
|
||||
SkOrderedReadBuffer buffer(data, len);
|
||||
obj = buffer.readFlattenable();
|
||||
obj = buffer.readFlattenable(et);
|
||||
SkASSERT(buffer.offset() == buffer.size());
|
||||
}
|
||||
return obj;
|
||||
@ -84,9 +85,9 @@ SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
|
||||
|
||||
, fBaseGlyphCount(0)
|
||||
, fTypeface(SkRef(typeface))
|
||||
, fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag)))
|
||||
, fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_SkDescriptorTag)))
|
||||
, fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_SkDescriptorTag)))
|
||||
, fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag, kPathEffect_SkEffectType)))
|
||||
, fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_SkDescriptorTag, kMaskFilter_SkEffectType)))
|
||||
, fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_SkDescriptorTag, kRasterizer_SkEffectType)))
|
||||
|
||||
// Initialize based on our settings. Subclasses can also force this.
|
||||
, fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != NULL || fRasterizer != NULL)
|
||||
|
@ -69,8 +69,8 @@ SkBlurDrawLooper::SkBlurDrawLooper(SkFlattenableReadBuffer& buffer)
|
||||
fDx = buffer.readScalar();
|
||||
fDy = buffer.readScalar();
|
||||
fBlurColor = buffer.readColor();
|
||||
fBlur = buffer.readFlattenableT<SkMaskFilter>();
|
||||
fColorFilter = buffer.readFlattenableT<SkColorFilter>();
|
||||
fBlur = buffer.readMaskFilter();
|
||||
fColorFilter = buffer.readColorFilter();
|
||||
fBlurFlags = buffer.readUInt() & kAll_BlurFlag;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf,
|
||||
}
|
||||
|
||||
SkColorFilterImageFilter::SkColorFilterImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
|
||||
fColorFilter = buffer.readFlattenableT<SkColorFilter>();
|
||||
fColorFilter = buffer.readColorFilter();
|
||||
}
|
||||
|
||||
void SkColorFilterImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
|
||||
|
@ -45,7 +45,7 @@ SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, const CropRect* cr
|
||||
|
||||
SkRectShaderImageFilter::SkRectShaderImageFilter(SkFlattenableReadBuffer& buffer)
|
||||
: INHERITED(buffer) {
|
||||
fShader = buffer.readFlattenableT<SkShader>();
|
||||
fShader = buffer.readShader();
|
||||
}
|
||||
|
||||
void SkRectShaderImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
|
||||
|
@ -34,7 +34,7 @@ SkXfermodeImageFilter::~SkXfermodeImageFilter() {
|
||||
|
||||
SkXfermodeImageFilter::SkXfermodeImageFilter(SkFlattenableReadBuffer& buffer)
|
||||
: INHERITED(buffer) {
|
||||
fMode = buffer.readFlattenableT<SkXfermode>();
|
||||
fMode = buffer.readXfermode();
|
||||
}
|
||||
|
||||
void SkXfermodeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
|
||||
|
@ -146,7 +146,7 @@ static uint32_t unpack_flags(uint32_t packed) {
|
||||
SkGradientShaderBase::SkGradientShaderBase(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
|
||||
fCacheAlpha = 256;
|
||||
|
||||
fMapper = buffer.readFlattenableT<SkUnitMapper>();
|
||||
fMapper = buffer.readUnitMapper();
|
||||
|
||||
fCache16 = fCache16Storage = NULL;
|
||||
fCache32 = NULL;
|
||||
|
@ -19,11 +19,11 @@
|
||||
enum PaintFlats {
|
||||
kColorFilter_PaintFlat,
|
||||
kDrawLooper_PaintFlat,
|
||||
kImageFilter_PaintFlat,
|
||||
kMaskFilter_PaintFlat,
|
||||
kPathEffect_PaintFlat,
|
||||
kRasterizer_PaintFlat,
|
||||
kShader_PaintFlat,
|
||||
kImageFilter_PaintFlat,
|
||||
kXfermode_PaintFlat,
|
||||
|
||||
kLast_PaintFlat = kXfermode_PaintFlat
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "SkAnnotation.h"
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkDrawLooper.h"
|
||||
#include "SkImageFilter.h"
|
||||
#include "SkMaskFilter.h"
|
||||
#include "SkOrderedReadBuffer.h"
|
||||
#include "SkPathEffect.h"
|
||||
@ -27,6 +28,22 @@
|
||||
#include "SkTypeface.h"
|
||||
#include "SkXfermode.h"
|
||||
|
||||
static SkEffectType paintflat_to_effecttype(PaintFlats pf) {
|
||||
static const uint8_t gEffectTypesInPaintFlatsOrder[] = {
|
||||
kColorFilter_SkEffectType,
|
||||
kDrawLooper_SkEffectType,
|
||||
kImageFilter_SkEffectType,
|
||||
kMaskFilter_SkEffectType,
|
||||
kPathEffect_SkEffectType,
|
||||
kRasterizer_SkEffectType,
|
||||
kShader_SkEffectType,
|
||||
kXfermode_SkEffectType,
|
||||
};
|
||||
|
||||
SkASSERT((size_t)pf < SK_ARRAY_COUNT(gEffectTypesInPaintFlatsOrder));
|
||||
return (SkEffectType)gEffectTypesInPaintFlatsOrder[pf];
|
||||
}
|
||||
|
||||
static void set_paintflat(SkPaint* paint, SkFlattenable* obj, unsigned paintFlat) {
|
||||
SkASSERT(paintFlat < kCount_PaintFlats);
|
||||
switch (paintFlat) {
|
||||
@ -105,7 +122,7 @@ public:
|
||||
|
||||
void defFlattenable(PaintFlats pf, int index) {
|
||||
index--;
|
||||
SkFlattenable* obj = fReader->readFlattenable();
|
||||
SkFlattenable* obj = fReader->readFlattenable(paintflat_to_effecttype(pf));
|
||||
if (fFlatArray.count() == index) {
|
||||
*fFlatArray.append() = obj;
|
||||
} else {
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "SkOrderedReadBuffer.h"
|
||||
#include "SkOrderedWriteBuffer.h"
|
||||
|
||||
static SkFlattenable* reincarnate_flattenable(SkFlattenable* obj) {
|
||||
static SkColorFilter* reincarnate_colorfilter(SkFlattenable* obj) {
|
||||
SkOrderedWriteBuffer wb(1024);
|
||||
wb.writeFlattenable(obj);
|
||||
|
||||
@ -25,11 +25,7 @@ static SkFlattenable* reincarnate_flattenable(SkFlattenable* obj) {
|
||||
wb.writeToMemory(storage.get());
|
||||
|
||||
SkOrderedReadBuffer rb(storage.get(), size);
|
||||
return rb.readFlattenable();
|
||||
}
|
||||
|
||||
template <typename T> T* reincarnate(T* obj) {
|
||||
return (T*)reincarnate_flattenable(obj);
|
||||
return rb.readColorFilter();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -82,7 +78,7 @@ static void test_asColorMode(skiatest::Reporter* reporter) {
|
||||
REPORTER_ASSERT(reporter, m == expectedMode);
|
||||
|
||||
{
|
||||
SkColorFilter* cf2 = reincarnate(cf);
|
||||
SkColorFilter* cf2 = reincarnate_colorfilter(cf);
|
||||
SkAutoUnref aur2(cf2);
|
||||
REPORTER_ASSERT(reporter, cf2);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user