skia2/include/core/SkFlattenable.h
Cary Clark 4dc5a45405 remove defines and add commas
Preparation for generating bookmaker files for all remaining
interfaces

Standardize enum and enum classes by including a comma after
the last entry.

Replace flatten-related #define in public interfaces
with their equivalent.

The motivation is to give documentation something to refer to.

An alternative would be to move part or all of this out of the
public interface; something I can work on in a follow-up CL.

R=reed@google.com,bsalomon@google.com

Bug: skia:6898
Change-Id: I4b865f6ec3d8f5d31e50448fef7d2714510302f0
Reviewed-on: https://skia-review.googlesource.com/129312
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Cary Clark <caryclark@skia.org>
2018-05-21 17:33:39 +00:00

105 lines
2.9 KiB
C++

/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkFlattenable_DEFINED
#define SkFlattenable_DEFINED
#include "SkRefCnt.h"
class SkData;
class SkReadBuffer;
class SkWriteBuffer;
struct SkSerialProcs;
struct SkDeserialProcs;
/** \class SkFlattenable
SkFlattenable is the base class for objects that need to be flattened
into a data stream for either transport or as part of the key to the
font cache.
*/
class SK_API SkFlattenable : public SkRefCnt {
public:
enum Type {
kSkColorFilter_Type,
kSkDrawable_Type,
kSkDrawLooper_Type,
kSkImageFilter_Type,
kSkMaskFilter_Type,
kSkPathEffect_Type,
kSkPixelRef_Type,
kSkUnused_Type4, // used to be SkRasterizer
kSkShaderBase_Type,
kSkUnused_Type, // used to be SkUnitMapper
kSkUnused_Type2,
kSkUnused_Type3, // used to be SkNormalSource
};
typedef sk_sp<SkFlattenable> (*Factory)(SkReadBuffer&);
SkFlattenable() {}
/** Implement this to return a factory function pointer that can be called
to recreate your class given a buffer (previously written to by your
override of flatten().
*/
virtual Factory getFactory() const = 0;
/**
* Returns the name of the object's class.
*
* Subclasses should override this function if they intend to provide
* support for flattening without using the global registry.
*
* If the flattenable is registered, there is no need to override.
*/
virtual const char* getTypeName() const { return FactoryToName(getFactory()); }
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);
/**
* Override this if your subclass needs to record data that it will need to recreate itself
* from its CreateProc (returned by getFactory()).
*
* DEPRECATED public : will move to protected ... use serialize() instead
*/
virtual void flatten(SkWriteBuffer&) const {}
virtual Type getFlattenableType() const = 0;
//
// public ways to serialize / deserialize
//
sk_sp<SkData> serialize(const SkSerialProcs* = nullptr) const;
size_t serialize(void* memory, size_t memory_size,
const SkSerialProcs* = nullptr) const;
static sk_sp<SkFlattenable> Deserialize(Type, const void* data, size_t length,
const SkDeserialProcs* procs = nullptr);
protected:
class PrivateInitializer {
public:
static void InitCore();
static void InitEffects();
};
private:
static void InitializeFlattenablesIfNeeded();
static void Finalize();
friend class SkGraphics;
typedef SkRefCnt INHERITED;
};
#endif