skia2/include/core/SkFlattenable.h
commit-bot@chromium.org 8b0e8ac5f5 Refactor read and write buffers.
Eliminates SkFlattenable{Read,Write}Buffer, promoting SkOrdered{Read,Write}Buffer
a step each in the hierarchy.

What used to be this:

SkFlattenableWriteBuffer -> SkOrderedWriteBuffer
SkFlattenableReadBuffer  -> SkOrderedReadBuffer
SkFlattenableReadBuffer  -> SkValidatingReadBuffer

is now

SkWriteBuffer
SkReadBuffer -> SkValidatingReadBuffer

Benefits:
  - code is simpler, names are less wordy
  - the generic SkFlattenableFooBuffer code in SkPaint was incorrect; removed
  - write buffers are completely devirtualized, important for record speed

This refactoring was mostly mechanical.  You aren't going to find anything
interesting in files with less than 10 lines changed.

BUG=skia:
R=reed@google.com, scroggo@google.com, djsollen@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/134163010

git-svn-id: http://skia.googlecode.com/svn/trunk@13245 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-30 18:58:24 +00:00

115 lines
3.2 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 SkReadBuffer;
class SkWriteBuffer;
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \
flattenable::GetFlattenableType());
#define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenables();
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
void flattenable::InitializeFlattenables() {
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
}
#define SK_DECLARE_UNFLATTENABLE_OBJECT() \
virtual Factory getFactory() const SK_OVERRIDE { return NULL; }
#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \
static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \
return SkNEW_ARGS(flattenable, (buffer)); \
}
/** 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
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,
kSkDrawLooper_Type,
kSkImageFilter_Type,
kSkMaskFilter_Type,
kSkPathEffect_Type,
kSkPixelRef_Type,
kSkRasterizer_Type,
kSkShader_Type,
kSkUnitMapper_Type,
kSkXfermode_Type,
};
SK_DECLARE_INST_COUNT(SkFlattenable)
typedef 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
*/
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);
class Registrar {
public:
Registrar(const char name[], Factory factory, Type type) {
SkFlattenable::Register(name, factory, type);
}
};
/** 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(SkWriteBuffer&) const;
protected:
SkFlattenable(SkReadBuffer&) {}
private:
static void InitializeFlattenablesIfNeeded();
friend class SkGraphics;
typedef SkRefCnt INHERITED;
};
#endif