gfx/skia/trunk/include/core/SkFlattenable.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkFlattenable.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2006 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkFlattenable_DEFINED
    1.14 +#define SkFlattenable_DEFINED
    1.15 +
    1.16 +#include "SkRefCnt.h"
    1.17 +
    1.18 +class SkReadBuffer;
    1.19 +class SkWriteBuffer;
    1.20 +
    1.21 +#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
    1.22 +        SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \
    1.23 +                                 flattenable::GetFlattenableType());
    1.24 +
    1.25 +#define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenables();
    1.26 +
    1.27 +#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
    1.28 +    void flattenable::InitializeFlattenables() {
    1.29 +
    1.30 +#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
    1.31 +    }
    1.32 +
    1.33 +#define SK_DECLARE_UNFLATTENABLE_OBJECT() \
    1.34 +    virtual Factory getFactory() const SK_OVERRIDE { return NULL; }
    1.35 +
    1.36 +#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
    1.37 +    virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \
    1.38 +    static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \
    1.39 +        return SkNEW_ARGS(flattenable, (buffer)); \
    1.40 +    }
    1.41 +
    1.42 +/** For SkFlattenable derived objects with a valid type
    1.43 +    This macro should only be used in base class objects in core
    1.44 +  */
    1.45 +#define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \
    1.46 +    static Type GetFlattenableType() { \
    1.47 +        return k##flattenable##_Type; \
    1.48 +    }
    1.49 +
    1.50 +/** \class SkFlattenable
    1.51 +
    1.52 + SkFlattenable is the base class for objects that need to be flattened
    1.53 + into a data stream for either transport or as part of the key to the
    1.54 + font cache.
    1.55 + */
    1.56 +class SK_API SkFlattenable : public SkRefCnt {
    1.57 +public:
    1.58 +    enum Type {
    1.59 +        kSkColorFilter_Type,
    1.60 +        kSkDrawLooper_Type,
    1.61 +        kSkImageFilter_Type,
    1.62 +        kSkMaskFilter_Type,
    1.63 +        kSkPathEffect_Type,
    1.64 +        kSkPixelRef_Type,
    1.65 +        kSkRasterizer_Type,
    1.66 +        kSkShader_Type,
    1.67 +        kSkUnitMapper_Type,
    1.68 +        kSkXfermode_Type,
    1.69 +    };
    1.70 +
    1.71 +    SK_DECLARE_INST_COUNT(SkFlattenable)
    1.72 +
    1.73 +    typedef SkFlattenable* (*Factory)(SkReadBuffer&);
    1.74 +
    1.75 +    SkFlattenable() {}
    1.76 +
    1.77 +    /** Implement this to return a factory function pointer that can be called
    1.78 +     to recreate your class given a buffer (previously written to by your
    1.79 +     override of flatten().
    1.80 +     */
    1.81 +    virtual Factory getFactory() const = 0;
    1.82 +
    1.83 +    /** Returns the name of the object's class
    1.84 +      */
    1.85 +    const char* getTypeName() const { return FactoryToName(getFactory()); }
    1.86 +
    1.87 +    static Factory NameToFactory(const char name[]);
    1.88 +    static const char* FactoryToName(Factory);
    1.89 +    static bool NameToType(const char name[], Type* type);
    1.90 +
    1.91 +    static void Register(const char name[], Factory, Type);
    1.92 +
    1.93 +    class Registrar {
    1.94 +    public:
    1.95 +        Registrar(const char name[], Factory factory, Type type) {
    1.96 +            SkFlattenable::Register(name, factory, type);
    1.97 +        }
    1.98 +    };
    1.99 +
   1.100 +    /** Override this to write data specific to your subclass into the buffer,
   1.101 +     being sure to call your super-class' version first. This data will later
   1.102 +     be passed to your Factory function, returned by getFactory().
   1.103 +     */
   1.104 +    virtual void flatten(SkWriteBuffer&) const;
   1.105 +
   1.106 +protected:
   1.107 +    SkFlattenable(SkReadBuffer&) {}
   1.108 +
   1.109 +private:
   1.110 +    static void InitializeFlattenablesIfNeeded();
   1.111 +
   1.112 +    friend class SkGraphics;
   1.113 +
   1.114 +    typedef SkRefCnt INHERITED;
   1.115 +};
   1.116 +
   1.117 +#endif

mercurial