2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkFlattenable_DEFINED
|
|
|
|
#define SkFlattenable_DEFINED
|
|
|
|
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
|
|
|
|
class SkFlattenableReadBuffer;
|
|
|
|
class SkFlattenableWriteBuffer;
|
|
|
|
|
2011-12-15 14:16:43 +00:00
|
|
|
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
|
|
|
|
#define SK_DEFINE_FLATTENABLE_REGISTRAR(flattenable) \
|
|
|
|
static SkFlattenable::Registrar g##flattenable##Reg(#flattenable, \
|
2012-03-23 19:00:34 +00:00
|
|
|
flattenable::CreateProc);
|
2011-12-15 14:16:43 +00:00
|
|
|
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
|
|
|
|
static SkFlattenable::Registrar g##flattenable##Reg(#flattenable, \
|
2012-03-23 19:00:34 +00:00
|
|
|
flattenable::CreateProc);
|
|
|
|
|
|
|
|
#define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
|
|
|
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable)
|
2011-12-15 14:16:43 +00:00
|
|
|
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2012-03-23 19:00:34 +00:00
|
|
|
#define SK_DEFINE_FLATTENABLE_REGISTRAR(flattenable)
|
|
|
|
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
|
|
|
|
SkFlattenable::Registrar(#flattenable, flattenable::CreateProc);
|
2011-12-15 14:16:43 +00:00
|
|
|
|
2012-03-23 19:00:34 +00:00
|
|
|
#define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenables();
|
2011-12-15 14:16:43 +00:00
|
|
|
|
|
|
|
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
|
2012-03-23 19:00:34 +00:00
|
|
|
void flattenable::InitializeFlattenables() {
|
|
|
|
|
2011-12-15 14:16:43 +00:00
|
|
|
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-03-26 17:57:35 +00:00
|
|
|
#define SK_DECLARE_UNFLATTENABLE_OBJECT() \
|
|
|
|
virtual Factory getFactory() SK_OVERRIDE { return NULL; }; \
|
|
|
|
|
|
|
|
#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
|
2012-08-07 15:54:32 +00:00
|
|
|
virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } \
|
2012-03-26 17:57:35 +00:00
|
|
|
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \
|
|
|
|
return SkNEW_ARGS(flattenable, (buffer)); \
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** \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.
|
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API SkFlattenable : public SkRefCnt {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2012-06-21 20:25:03 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkFlattenable)
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&);
|
|
|
|
|
|
|
|
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() = 0;
|
|
|
|
|
|
|
|
static Factory NameToFactory(const char name[]);
|
|
|
|
static const char* FactoryToName(Factory);
|
|
|
|
static void Register(const char name[], Factory);
|
2012-03-23 19:00:34 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
class Registrar {
|
|
|
|
public:
|
|
|
|
Registrar(const char name[], Factory factory) {
|
|
|
|
SkFlattenable::Register(name, factory);
|
|
|
|
}
|
|
|
|
};
|
2012-03-23 19:00:34 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
|
|
|
SkFlattenable(SkFlattenableReadBuffer&) {}
|
2012-03-29 15:18:04 +00:00
|
|
|
/** 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;
|
2011-12-15 14:16:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
static void InitializeFlattenables();
|
|
|
|
#endif
|
2011-12-20 20:26:56 +00:00
|
|
|
|
|
|
|
friend class SkGraphics;
|
2012-03-29 15:18:04 +00:00
|
|
|
friend class SkFlattenableWriteBuffer;
|
2012-06-21 20:25:03 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|