Initial error handling code
I made it as simple as possible. The impact seems minimal and it should do what's necessary to make this code secure.
BUG=
Committed: http://code.google.com/p/skia/source/detail?r=11247
R=reed@google.com, scroggo@google.com, djsollen@google.com, sugoi@google.com, bsalomon@google.com, mtklein@google.com, senorblanco@google.com, senorblanco@chromium.org
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/23021015
git-svn-id: http://skia.googlecode.com/svn/trunk@11922 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index 6cc76db..5a6e2ae 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -16,7 +16,8 @@
class SkFlattenableWriteBuffer;
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
- SkFlattenable::Registrar(#flattenable, flattenable::CreateProc);
+ SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \
+ flattenable::GetFlattenableType());
#define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenables();
@@ -35,6 +36,14 @@
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
@@ -43,6 +52,19 @@
*/
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)(SkFlattenableReadBuffer&);
@@ -55,14 +77,20 @@
*/
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 void Register(const char name[], 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) {
- SkFlattenable::Register(name, factory);
+ Registrar(const char name[], Factory factory, Type type) {
+ SkFlattenable::Register(name, factory, type);
}
};
@@ -75,7 +103,7 @@
virtual void flatten(SkFlattenableWriteBuffer&) const;
private:
- static void InitializeFlattenables();
+ static void InitializeFlattenablesIfNeeded();
friend class SkGraphics;
friend class SkFlattenableWriteBuffer;