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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkFlattenable_DEFINED
|
|
|
|
#define SkFlattenable_DEFINED
|
|
|
|
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
|
2017-12-06 21:09:20 +00:00
|
|
|
class SkData;
|
2014-01-30 18:58:24 +00:00
|
|
|
class SkReadBuffer;
|
|
|
|
class SkWriteBuffer;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-12-06 21:09:20 +00:00
|
|
|
struct SkSerialProcs;
|
|
|
|
struct SkDeserialProcs;
|
2015-08-24 19:33:19 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** \class SkFlattenable
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
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:
|
2016-04-04 21:57:19 +00:00
|
|
|
enum Type {
|
|
|
|
kSkColorFilter_Type,
|
2016-04-25 13:40:26 +00:00
|
|
|
kSkDrawable_Type,
|
2016-04-04 21:57:19 +00:00
|
|
|
kSkDrawLooper_Type,
|
|
|
|
kSkImageFilter_Type,
|
|
|
|
kSkMaskFilter_Type,
|
|
|
|
kSkPathEffect_Type,
|
|
|
|
kSkPixelRef_Type,
|
2018-01-20 00:09:32 +00:00
|
|
|
kSkUnused_Type4, // used to be SkRasterizer
|
2017-05-25 14:38:07 +00:00
|
|
|
kSkShaderBase_Type,
|
2016-04-04 21:57:19 +00:00
|
|
|
kSkUnused_Type, // used to be SkUnitMapper
|
2017-08-04 15:27:00 +00:00
|
|
|
kSkUnused_Type2,
|
2018-07-17 16:30:40 +00:00
|
|
|
kSkNormalSource_Type,
|
2016-04-04 21:57:19 +00:00
|
|
|
};
|
|
|
|
|
2016-04-03 16:11:13 +00:00
|
|
|
typedef sk_sp<SkFlattenable> (*Factory)(SkReadBuffer&);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkFlattenable() {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** 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().
|
|
|
|
*/
|
2013-10-21 12:26:10 +00:00
|
|
|
virtual Factory getFactory() const = 0;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2016-04-22 19:43:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the name of the object's class.
|
|
|
|
*/
|
2018-10-18 21:27:16 +00:00
|
|
|
virtual const char* getTypeName() const = 0;
|
2013-10-23 17:06:21 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
static Factory NameToFactory(const char name[]);
|
|
|
|
static const char* FactoryToName(Factory);
|
2013-10-23 17:06:21 +00:00
|
|
|
|
2018-10-20 11:54:41 +00:00
|
|
|
static void Register(const char name[], Factory);
|
2012-03-23 19:00:34 +00:00
|
|
|
|
2014-08-21 14:59:51 +00:00
|
|
|
/**
|
|
|
|
* Override this if your subclass needs to record data that it will need to recreate itself
|
|
|
|
* from its CreateProc (returned by getFactory()).
|
2017-12-06 21:09:20 +00:00
|
|
|
*
|
|
|
|
* DEPRECATED public : will move to protected ... use serialize() instead
|
2012-03-29 15:18:04 +00:00
|
|
|
*/
|
2014-08-21 14:59:51 +00:00
|
|
|
virtual void flatten(SkWriteBuffer&) const {}
|
2014-01-30 18:58:24 +00:00
|
|
|
|
2017-12-11 18:23:33 +00:00
|
|
|
virtual Type getFlattenableType() const = 0;
|
|
|
|
|
2017-12-06 21:09:20 +00:00
|
|
|
//
|
|
|
|
// public ways to serialize / deserialize
|
|
|
|
//
|
|
|
|
sk_sp<SkData> serialize(const SkSerialProcs* = nullptr) const;
|
2018-04-04 00:51:40 +00:00
|
|
|
size_t serialize(void* memory, size_t memory_size,
|
|
|
|
const SkSerialProcs* = nullptr) const;
|
2017-12-06 21:09:20 +00:00
|
|
|
static sk_sp<SkFlattenable> Deserialize(Type, const void* data, size_t length,
|
|
|
|
const SkDeserialProcs* procs = nullptr);
|
|
|
|
|
2016-01-13 16:47:54 +00:00
|
|
|
protected:
|
|
|
|
class PrivateInitializer {
|
|
|
|
public:
|
|
|
|
static void InitEffects();
|
2018-06-19 14:17:30 +00:00
|
|
|
static void InitImageFilters();
|
2016-01-13 16:47:54 +00:00
|
|
|
};
|
|
|
|
|
2011-12-15 14:16:43 +00:00
|
|
|
private:
|
2018-10-20 12:21:31 +00:00
|
|
|
static void RegisterFlattenablesIfNeeded();
|
2018-01-18 20:35:11 +00:00
|
|
|
static void Finalize();
|
2011-12-20 20:26:56 +00:00
|
|
|
|
|
|
|
friend class SkGraphics;
|
2012-06-21 20:25:03 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2018-11-30 20:33:19 +00:00
|
|
|
#define SK_REGISTER_FLATTENABLE(type) SkFlattenable::Register(#type, type::CreateProc)
|
2018-10-18 21:27:16 +00:00
|
|
|
|
|
|
|
#define SK_FLATTENABLE_HOOKS(type) \
|
|
|
|
static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&); \
|
|
|
|
friend class SkFlattenable::PrivateInitializer; \
|
|
|
|
Factory getFactory() const override { return type::CreateProc; } \
|
|
|
|
const char* getTypeName() const override { return #type; }
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|