Revert of Delete SkFlattenable::Type (patchset #2 id:20001 of https://codereview.chromium.org/1834303003/ )

Reason for revert:
Used by Chrome.

c:\b\build\slave\workdir\build\src\cc\playback\compositing_display_item.cc(53): error C2039: 'GetFlattenableType': is not a member of 'SkColorFilter'
c:\b\build\slave\workdir\build\src\third_party\skia\include\core\skshader.h(19): note: see declaration of 'SkColorFilter'
c:\b\build\slave\workdir\build\src\cc\playback\compositing_display_item.cc(53): error C3861: 'GetFlattenableType': identifier not found

Original issue's description:
> Delete SkFlattenable::Type
>
> BUG=skia:
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1834303003
>
> Committed: https://skia.googlesource.com/skia/+/99d9231f6a4cb6b85b8637e9d8ae32f8bd7c466f

TBR=reed@google.com,msarett@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Review URL: https://codereview.chromium.org/1853383002
This commit is contained in:
mtklein 2016-04-04 14:57:19 -07:00 committed by Commit bot
parent 99d9231f6a
commit 3b37545bc5
24 changed files with 95 additions and 24 deletions

View File

@ -23,7 +23,8 @@ public:
public:
Registrar() {
SkFlattenable::Register("FailImageFilter",
FailImageFilter::CreateProc);
FailImageFilter::CreateProc,
FailImageFilter::GetFlattenableType());
}
};
static sk_sp<SkImageFilter> Make() {
@ -65,7 +66,8 @@ public:
public:
Registrar() {
SkFlattenable::Register("IdentityImageFilter",
IdentityImageFilter::CreateProc);
IdentityImageFilter::CreateProc,
IdentityImageFilter::GetFlattenableType());
}
};
static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilter> input) {

View File

@ -32,7 +32,8 @@ public:
public:
Registrar() {
SkFlattenable::Register("SimpleOffsetFilter",
SimpleOffsetFilter::CreateProc);
SimpleOffsetFilter::CreateProc,
SimpleOffsetFilter::GetFlattenableType());
}
};
static sk_sp<SkImageFilter> Make(SkScalar dx, SkScalar dy, sk_sp<SkImageFilter> input) {

View File

@ -162,6 +162,7 @@ public:
SK_TO_STRING_PUREVIRT()
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
SK_DEFINE_FLATTENABLE_TYPE(SkColorFilter)
protected:
SkColorFilter() {}

View File

@ -107,6 +107,7 @@ public:
virtual bool asABlurShadow(BlurShadowRec*) const;
SK_TO_STRING_PUREVIRT()
SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper)
protected:
SkDrawLooper() {}

View File

@ -43,7 +43,8 @@ class SkPrivateEffectInitializer;
}
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
SkFlattenable::Register(#flattenable, flattenable::CreateProc);
SkFlattenable::Register(#flattenable, flattenable::CreateProc, \
flattenable::GetFlattenableType());
#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
private: \
@ -52,6 +53,14 @@ class SkPrivateEffectInitializer;
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
@ -60,6 +69,19 @@ class SkPrivateEffectInitializer;
*/
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() {}
@ -76,8 +98,9 @@ public:
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);
static void Register(const char name[], Factory, Type);
/**
* Override this if your subclass needs to record data that it will need to recreate itself

View File

@ -13,6 +13,7 @@
class SkData;
SK_API SkData* SkValidatingSerializeFlattenable(SkFlattenable*);
SK_API SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size);
SK_API SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size,
SkFlattenable::Type type);
#endif

View File

@ -292,6 +292,7 @@ public:
#endif
SK_TO_STRING_PUREVIRT()
SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
protected:
class Common {

View File

@ -171,6 +171,7 @@ public:
virtual bool asABlur(BlurRec*) const;
SK_TO_STRING_PUREVIRT()
SK_DEFINE_FLATTENABLE_TYPE(SkMaskFilter)
protected:
SkMaskFilter() {}

View File

@ -129,6 +129,7 @@ public:
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.

View File

@ -26,6 +26,8 @@ public:
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,

View File

@ -456,6 +456,7 @@ public:
virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const;
SK_TO_STRING_VIRT()
SK_DEFINE_FLATTENABLE_TYPE(SkShader)
protected:
void flatten(SkWriteBuffer&) const override;

View File

@ -234,6 +234,7 @@ public:
SK_TO_STRING_PUREVIRT()
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
SK_DEFINE_FLATTENABLE_TYPE(SkXfermode)
enum D32Flags {
kSrcIsOpaque_D32Flag = 1 << 0,

View File

@ -799,7 +799,8 @@ static SkImageFilter* make_serialized_image_filter() {
}
}
#endif // SK_ADD_RANDOM_BIT_FLIPS
SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(ptr, len);
SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(ptr, len,
SkImageFilter::GetFlattenableType());
return static_cast<SkImageFilter*>(flattenable);
}

View File

@ -53,18 +53,20 @@ void SkRefCntSet::decPtr(void* ptr) {
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) {
void SkFlattenable::Register(const char name[], Factory factory, SkFlattenable::Type type) {
SkASSERT(name);
SkASSERT(factory);
SkASSERT(gCount < MAX_ENTRY_COUNT);
gEntries[gCount].fName = name;
gEntries[gCount].fFactory = factory;
gEntries[gCount].fType = type;
gCount += 1;
}
@ -92,6 +94,22 @@ SkFlattenable::Factory SkFlattenable::NameToFactory(const char name[]) {
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

View File

@ -20,7 +20,8 @@ SkData* SkValidatingSerializeFlattenable(SkFlattenable* flattenable) {
return data.release();
}
SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size) {
SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size,
SkFlattenable::Type type) {
SkValidatingReadBuffer buffer(data, size);
return buffer.readFlattenable();
return buffer.readFlattenable(type);
}

View File

@ -329,7 +329,11 @@ SkTypeface* SkReadBuffer::readTypeface() {
}
}
SkFlattenable* SkReadBuffer::readFlattenable() {
SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
//
// TODO: confirm that ft matches the factory we decide to use
//
SkFlattenable::Factory factory = nullptr;
if (fFactoryCount > 0) {

View File

@ -126,9 +126,9 @@ public:
virtual void readPath(SkPath* path);
void readPaint(SkPaint* paint) { paint->unflatten(*this); }
virtual SkFlattenable* readFlattenable();
virtual SkFlattenable* readFlattenable(SkFlattenable::Type);
template <typename T> sk_sp<T> readFlattenable() {
return sk_sp<T>((T*)this->readFlattenable());
return sk_sp<T>((T*)this->readFlattenable(T::GetFlattenableType()));
}
sk_sp<SkColorFilter> readColorFilter() { return this->readFlattenable<SkColorFilter>(); }
sk_sp<SkDrawLooper> readDrawLooper() { return this->readFlattenable<SkDrawLooper>(); }

View File

@ -62,14 +62,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,
SkFlattenable::Type ft) {
SkFlattenable* obj = nullptr;
uint32_t len;
const void* data = desc->findEntry(tag, &len);
if (data) {
SkReadBuffer buffer(data, len);
obj = buffer.readFlattenable();
obj = buffer.readFlattenable(ft);
SkASSERT(buffer.offset() == buffer.size());
}
return obj;
@ -79,9 +80,12 @@ SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
: fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, nullptr)))
, 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,
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)))
// Initialize based on our settings. Subclasses can also force this.
, fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != nullptr || fRasterizer != nullptr)

View File

@ -222,14 +222,20 @@ bool SkValidatingReadBuffer::validateAvailable(size_t size) {
return this->validate((size <= SK_MaxU32) && fReader.isAvailable(static_cast<uint32_t>(size)));
}
SkFlattenable* SkValidatingReadBuffer::readFlattenable() {
SkFlattenable* SkValidatingReadBuffer::readFlattenable(SkFlattenable::Type type) {
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

View File

@ -39,7 +39,7 @@ public:
void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) override;
// common data structures
SkFlattenable* readFlattenable() override;
SkFlattenable* readFlattenable(SkFlattenable::Type type) override;
void skipFlattenable() override;
void readPoint(SkPoint* point) override;
void readMatrix(SkMatrix* matrix) override;

View File

@ -14,6 +14,7 @@
// 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)
};

View File

@ -1089,7 +1089,7 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
// cross-process. Do this by "laundering" it through SkValidatingReadBuffer.
SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(imageFilter.get()));
SkAutoTUnref<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
data->data(), data->size()));
data->data(), data->size(), SkImageFilter::GetFlattenableType()));
SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get());
redPaintWithFilter.setImageFilter(unflattenedFilter);
@ -1536,7 +1536,7 @@ DEF_TEST(ImageFilterImageSourceSerialization, reporter) {
sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
sk_sp<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
data->data(), data->size()));
data->data(), data->size(), SkImageFilter::GetFlattenableType()));
SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get());
REPORTER_ASSERT(reporter, unflattenedFilter);

View File

@ -42,7 +42,7 @@ template<typename T> struct SerializationUtils {
writer.writeFlattenable(flattenable);
}
static void Read(SkValidatingReadBuffer& reader, T** flattenable) {
*flattenable = (T*)reader.readFlattenable();
*flattenable = (T*)reader.readFlattenable(T::GetFlattenableType());
}
};

View File

@ -31,7 +31,7 @@ static void run_test_case(const SkString& testdata, const SkBitmap& bitmap,
// 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());
testdata.c_str(), testdata.size(), SkImageFilter::GetFlattenableType());
// Adding some info, but the test passed if we got here without any trouble
if (flattenable != nullptr) {