public:
Registrar() {
SkFlattenable::Register("FailImageFilter",
- FailImageFilter::CreateProc,
- FailImageFilter::GetFlattenableType());
+ FailImageFilter::CreateProc);
}
};
static sk_sp<SkImageFilter> Make() {
public:
Registrar() {
SkFlattenable::Register("IdentityImageFilter",
- IdentityImageFilter::CreateProc,
- IdentityImageFilter::GetFlattenableType());
+ IdentityImageFilter::CreateProc);
}
};
static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilter> input) {
public:
Registrar() {
SkFlattenable::Register("SimpleOffsetFilter",
- SimpleOffsetFilter::CreateProc,
- SimpleOffsetFilter::GetFlattenableType());
+ SimpleOffsetFilter::CreateProc);
}
};
static sk_sp<SkImageFilter> Make(SkScalar dx, SkScalar dy, sk_sp<SkImageFilter> input) {
SK_TO_STRING_PUREVIRT()
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
- SK_DEFINE_FLATTENABLE_TYPE(SkColorFilter)
protected:
SkColorFilter() {}
virtual bool asABlurShadow(BlurShadowRec*) const;
SK_TO_STRING_PUREVIRT()
- SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper)
protected:
SkDrawLooper() {}
}
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
- SkFlattenable::Register(#flattenable, flattenable::CreateProc, \
- flattenable::GetFlattenableType());
+ SkFlattenable::Register(#flattenable, flattenable::CreateProc);
#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
private: \
public: \
Factory getFactory() const override { return CreateProc; }
-/** For SkFlattenable derived objects with a valid type
- This macro should only be used in base class objects in core
- */
-#define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \
- static Type GetFlattenableType() { \
- return k##flattenable##_Type; \
- }
-
/** \class SkFlattenable
SkFlattenable is the base class for objects that need to be flattened
*/
class SK_API SkFlattenable : public SkRefCnt {
public:
- enum Type {
- kSkColorFilter_Type,
- kSkDrawLooper_Type,
- kSkImageFilter_Type,
- kSkMaskFilter_Type,
- kSkPathEffect_Type,
- kSkPixelRef_Type,
- kSkRasterizer_Type,
- kSkShader_Type,
- kSkUnused_Type, // used to be SkUnitMapper
- kSkXfermode_Type,
- };
-
typedef sk_sp<SkFlattenable> (*Factory)(SkReadBuffer&);
SkFlattenable() {}
static Factory NameToFactory(const char name[]);
static const char* FactoryToName(Factory);
- static bool NameToType(const char name[], Type* type);
- static void Register(const char name[], Factory, Type);
+ static void Register(const char name[], Factory);
/**
* Override this if your subclass needs to record data that it will need to recreate itself
class SkData;
SK_API SkData* SkValidatingSerializeFlattenable(SkFlattenable*);
-SK_API SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size,
- SkFlattenable::Type type);
+SK_API SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size);
#endif
#endif
SK_TO_STRING_PUREVIRT()
- SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
protected:
class Common {
virtual bool asABlur(BlurRec*) const;
SK_TO_STRING_PUREVIRT()
- SK_DEFINE_FLATTENABLE_TYPE(SkMaskFilter)
protected:
SkMaskFilter() {}
virtual DashType asADash(DashInfo* info) const;
SK_TO_STRING_PUREVIRT()
- SK_DEFINE_FLATTENABLE_TYPE(SkPathEffect)
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
/// Override for subclasses as appropriate.
const SkIRect* clipBounds, SkMaskFilter* filter,
SkMask* mask, SkMask::CreateMode mode) const;
- SK_DEFINE_FLATTENABLE_TYPE(SkRasterizer)
-
protected:
SkRasterizer() {}
virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,
virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const;
SK_TO_STRING_VIRT()
- SK_DEFINE_FLATTENABLE_TYPE(SkShader)
protected:
void flatten(SkWriteBuffer&) const override;
SK_TO_STRING_PUREVIRT()
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
- SK_DEFINE_FLATTENABLE_TYPE(SkXfermode)
enum D32Flags {
kSrcIsOpaque_D32Flag = 1 << 0,
}
}
#endif // SK_ADD_RANDOM_BIT_FLIPS
- SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(ptr, len,
- SkImageFilter::GetFlattenableType());
+ SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(ptr, len);
return static_cast<SkImageFilter*>(flattenable);
}
struct Entry {
const char* fName;
SkFlattenable::Factory fFactory;
- SkFlattenable::Type fType;
};
static int gCount = 0;
static Entry gEntries[MAX_ENTRY_COUNT];
-void SkFlattenable::Register(const char name[], Factory factory, SkFlattenable::Type type) {
+void SkFlattenable::Register(const char name[], Factory factory) {
SkASSERT(name);
SkASSERT(factory);
SkASSERT(gCount < MAX_ENTRY_COUNT);
gEntries[gCount].fName = name;
gEntries[gCount].fFactory = factory;
- gEntries[gCount].fType = type;
gCount += 1;
}
return nullptr;
}
-bool SkFlattenable::NameToType(const char name[], SkFlattenable::Type* type) {
- SkASSERT(type);
- InitializeFlattenablesIfNeeded();
-#ifdef SK_DEBUG
- report_no_entries(__FUNCTION__);
-#endif
- const Entry* entries = gEntries;
- for (int i = gCount - 1; i >= 0; --i) {
- if (strcmp(entries[i].fName, name) == 0) {
- *type = entries[i].fType;
- return true;
- }
- }
- return false;
-}
-
const char* SkFlattenable::FactoryToName(Factory fact) {
InitializeFlattenablesIfNeeded();
#ifdef SK_DEBUG
return data.release();
}
-SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size,
- SkFlattenable::Type type) {
+SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size) {
SkValidatingReadBuffer buffer(data, size);
- return buffer.readFlattenable(type);
+ return buffer.readFlattenable();
}
}
}
-SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
- //
- // TODO: confirm that ft matches the factory we decide to use
- //
-
+SkFlattenable* SkReadBuffer::readFlattenable() {
SkFlattenable::Factory factory = nullptr;
if (fFactoryCount > 0) {
virtual void readPath(SkPath* path);
void readPaint(SkPaint* paint) { paint->unflatten(*this); }
- virtual SkFlattenable* readFlattenable(SkFlattenable::Type);
+ virtual SkFlattenable* readFlattenable();
template <typename T> sk_sp<T> readFlattenable() {
- return sk_sp<T>((T*)this->readFlattenable(T::GetFlattenableType()));
+ return sk_sp<T>((T*)this->readFlattenable());
}
sk_sp<SkColorFilter> readColorFilter() { return this->readFlattenable<SkColorFilter>(); }
sk_sp<SkDrawLooper> readDrawLooper() { return this->readFlattenable<SkDrawLooper>(); }
#define DUMP_RECx
#endif
-static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag,
- SkFlattenable::Type ft) {
+static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag) {
SkFlattenable* obj = nullptr;
uint32_t len;
const void* data = desc->findEntry(tag, &len);
if (data) {
SkReadBuffer buffer(data, len);
- obj = buffer.readFlattenable(ft);
+ obj = buffer.readFlattenable();
SkASSERT(buffer.offset() == buffer.size());
}
return obj;
: fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, nullptr)))
, fTypeface(SkRef(typeface))
- , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag,
- SkFlattenable::kSkPathEffect_Type)))
- , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_SkDescriptorTag,
- SkFlattenable::kSkMaskFilter_Type)))
- , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_SkDescriptorTag,
- SkFlattenable::kSkRasterizer_Type)))
+ , 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)))
// Initialize based on our settings. Subclasses can also force this.
, fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != nullptr || fRasterizer != nullptr)
return this->validate((size <= SK_MaxU32) && fReader.isAvailable(static_cast<uint32_t>(size)));
}
-SkFlattenable* SkValidatingReadBuffer::readFlattenable(SkFlattenable::Type type) {
+SkFlattenable* SkValidatingReadBuffer::readFlattenable() {
SkString name;
this->readString(&name);
if (fError) {
return nullptr;
}
- // Is this the type we wanted ?
const char* cname = name.c_str();
- SkFlattenable::Type baseType;
- if (!SkFlattenable::NameToType(cname, &baseType) || (baseType != type)) {
- return nullptr;
- }
-
SkFlattenable::Factory factory = SkFlattenable::NameToFactory(cname);
if (nullptr == factory) {
return nullptr; // writer failed to give us the flattenable
void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) override;
// common data structures
- SkFlattenable* readFlattenable(SkFlattenable::Type type) override;
+ SkFlattenable* readFlattenable() override;
void skipFlattenable() override;
void readPoint(SkPoint* point) override;
void readMatrix(SkMatrix* matrix) override;
// Should be removed when SKP versions which may contain SkBitmapSource records are phased out.
class SkBitmapSourceDeserializer : public SkFlattenable {
public:
- SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapSource)
};
// cross-process. Do this by "laundering" it through SkValidatingReadBuffer.
SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(imageFilter.get()));
SkAutoTUnref<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
- data->data(), data->size(), SkImageFilter::GetFlattenableType()));
+ data->data(), data->size()));
SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get());
redPaintWithFilter.setImageFilter(unflattenedFilter);
sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
sk_sp<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
- data->data(), data->size(), SkImageFilter::GetFlattenableType()));
+ data->data(), data->size()));
SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get());
REPORTER_ASSERT(reporter, unflattenedFilter);
writer.writeFlattenable(flattenable);
}
static void Read(SkValidatingReadBuffer& reader, T** flattenable) {
- *flattenable = (T*)reader.readFlattenable(T::GetFlattenableType());
+ *flattenable = (T*)reader.readFlattenable();
}
};
// This call shouldn't crash or cause ASAN to flag any memory issues
// If nothing bad happens within this call, everything is fine
SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
- testdata.c_str(), testdata.size(), SkImageFilter::GetFlattenableType());
+ testdata.c_str(), testdata.size());
// Adding some info, but the test passed if we got here without any trouble
if (flattenable != nullptr) {