Index: include/core/SkFlattenable.h |
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h |
index 0b21abcc764c7aed2bd67f9a83c5162df3e222a9..80928e44f84d7d7cc50cda0fa7fd2616c29212ee 100644 |
--- a/include/core/SkFlattenable.h |
+++ b/include/core/SkFlattenable.h |
@@ -27,14 +27,52 @@ class SkFlattenableWriteBuffer; |
} |
#define SK_DECLARE_UNFLATTENABLE_OBJECT() \ |
- virtual Factory getFactory() SK_OVERRIDE { return NULL; }; \ |
+ virtual Factory getFactory() SK_OVERRIDE { return NULL; }; |
+ |
+#define SK_DEFINE_FLATTENABLE_TYPE_FCNT(flattenable) \ |
mtklein
2013/09/24 22:52:18
OK, I give up. What's FCNT stand for / short for?
sugoi1
2013/09/25 21:15:27
Sorry, typo, I meant FNCT, as in function. The nam
|
+ static bool IsA(SkFlattenable::Type type) { \ |
+ return (flattenable::GetType() == type) || INHERITED::IsA(type); \ |
+ } \ |
+ virtual SkFlattenable::Type getFlattenableType() SK_OVERRIDE { \ |
+ return flattenable::GetType(); \ |
+ } |
-#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ |
+#define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ |
mtklein
2013/09/24 22:52:18
Normally I love macros which cleverly do things li
sugoi1
2013/09/25 21:15:27
I not against this, but I sort of like the fact th
|
+ static SkFlattenable::Type GetType() { \ |
+ return SkFlattenable::k##flattenable; \ |
+ } \ |
+ SK_DEFINE_FLATTENABLE_TYPE_FCNT(flattenable) |
+ |
+/** Only for SkFlattenable derived objects that have implementations hidden in a cpp file |
+ */ |
+#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_UTILS() \ |
mtklein
2013/09/24 22:52:18
May SK_DECLARE_FLATTENABLE_DESERIALIZATION and SK_
sugoi1
2013/09/25 21:15:27
I didn't invent the PUBLIC name, it was there befo
|
+ static SkFlattenable::Factory GetFactory(SkFlattenable::Type); \ |
+ static SkFlattenable::TypeCheck GetTypeCheck(SkFlattenable::Type); |
+ |
+#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION(flattenable) \ |
virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } \ |
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \ |
return SkNEW_ARGS(flattenable, (buffer)); \ |
} |
+/** For SkFlattenable derived objects defined within the skia library |
+ */ |
+#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ |
mtklein
2013/09/24 22:52:18
I think we'll be better off in the long term if we
sugoi1
2013/09/25 21:15:27
All right, I'll try to combine them into fewer mac
|
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION(flattenable) \ |
+ SK_DEFINE_FLATTENABLE_TYPE(flattenable) |
+ |
+/** For SkFlattenable derived objects defined outside of the skia (sample code, gms, etc). |
+ Since these external object won't go through the ipc serialization, they are not given |
+ a "Type" in the SkFlattenable::Type enum and there is no need to modify SkFlattenable.h |
+ to add these derived classes. Note that the type is set to SkFlattenable::kNone here. |
+ */ |
+#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS_EXTERN(flattenable) \ |
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION(flattenable) \ |
+ static SkFlattenable::Type GetType() { \ |
+ return SkFlattenable::kNone; \ |
+ } \ |
+ SK_DEFINE_FLATTENABLE_TYPE_FCNT(flattenable) |
+ |
/** \class SkFlattenable |
SkFlattenable is the base class for objects that need to be flattened |
@@ -43,9 +81,111 @@ class SkFlattenableWriteBuffer; |
*/ |
class SK_API SkFlattenable : public SkRefCnt { |
public: |
+ enum Type { |
mtklein
2013/09/24 22:52:18
Do you have any opinion on whether we want to limi
mtklein
2013/09/24 22:52:18
It'll help to add some comments here about how thi
sugoi1
2013/09/25 21:15:27
I don't see any reason to exclude types from it. T
sugoi1
2013/09/25 21:15:27
I added the comment about not reordering and a not
|
+ kNone, |
mtklein
2013/09/24 22:52:18
Oh I so hate to ask you to do this, but you're goi
sugoi1
2013/09/25 21:15:27
No problem, that's easy enough.
|
+ kSkFlattenable, |
+ kBATShader, |
+ kSk2DPathEffect, |
+ kSk3DShader, |
+ kSkAnnotation, |
+ kSkArithmeticMode_scalar, |
+ kSkAvoidXfermode, |
+ kSkBicubicImageFilter, |
+ kSkBitmapProcShader, |
+ kSkBitmapSource, |
+ kSkBlurDrawLooper, |
+ kSkBlurImageFilter, |
+ kSkBlurMaskFilterImpl, |
+ kSkClearXfermode, |
+ kSkColorFilter, |
+ kSkColorFilterImageFilter, |
+ kSkColorMatrixFilter, |
+ kSkColorShader, |
+ kSkColorTable, |
+ kSkComposeImageFilter, |
+ kSkComposePathEffect, |
+ kSkComposeShader, |
+ kSkCornerPathEffect, |
+ kSkCosineMapper, |
+ kSkData, |
+ kSkDataPixelRef, |
+ kSkDataSet, |
+ kSkDataTable, |
+ kSkDiffuseLightingImageFilter, |
+ kSkDilateImageFilter, |
+ kSkDiscreteMapper, |
+ kSkDiscretePathEffect, |
+ kSkDisplacementMapEffect, |
+ kSkDistantLight, |
+ kSkDownSampleImageFilter, |
+ kSkDrawLooper, |
+ kSkDropShadowImageFilter, |
+ kSkDstInXfermode, |
+ kSkDstOutXfermode, |
+ kSkEmbossMaskFilter, |
+ kSkEmptyShader, |
+ kSkErodeImageFilter, |
+ kSkFilterShader, |
+ kSkImageFilter, |
+ kSkImageRef_GlobalPool, |
+ kSkKernel33MaskFilter, |
+ kSkLayerDrawLooper, |
+ kSkLayerRasterizer, |
+ kSkLerpXfermode, |
+ kSkLight, |
+ kSkLightingColorFilter, |
+ kSkLightingColorFilter_JustAdd, |
+ kSkLightingColorFilter_JustMul, |
+ kSkLightingColorFilter_NoPin, |
+ kSkLightingColorFilter_SingleMul, |
+ kSkLinearGradient, |
+ kSkLine2DPathEffect, |
+ kSkLumaMaskXfermode, |
+ kSkLumaMaskXfermodeSrcOver, |
+ kSkMagnifierImageFilter, |
+ kSkMallocPixelRef, |
+ kSkMaskFilter, |
+ kSkMatrixConvolutionImageFilter, |
+ kSkMergeImageFilter, |
+ kSkModeColorFilter, |
+ kSkOffsetImageFilter, |
+ kSkPathEffect, |
+ kSkPath1DPathEffect, |
+ kSkPath2DPathEffect, |
+ kSkPerlinNoiseShader, |
+ kSkPixelRef, |
+ kSkPixelXorXfermode, |
+ kSkPointLight, |
+ kSkProcCoeffXfermode, |
+ kSkProcXfermode, |
+ kSkRadialGradient, |
+ kSkRasterizer, |
+ kSkRectShaderImageFilter, |
+ kSkShader, |
+ kSkSpecularLightingImageFilter, |
+ kSkSpotLight, |
+ kSkSrcXfermode, |
+ kSkStippleMaskFilter, |
+ kSkSumPathEffect, |
+ kSkSweepGradient, |
+ kSkTable_ColorFilter, |
+ kSkTableMaskFilter, |
+ kSkTransparentShader, |
+ kSkTriColorShader, |
+ kSkTwoPointConicalGradient, |
+ kSkTwoPointRadialGradient, |
+ kSkUnitMapper, |
+ kSkXfermode, |
+ kSkXfermodeImageFilter, |
+ kSrc_SkModeColorFilter, |
+ kSrcOver_SkModeColorFilter, |
+ kTypeCount |
+ }; |
mtklein
2013/09/24 22:52:18
Can you add a comment betwe kSrcOver_SkModeColorFi
sugoi1
2013/09/25 21:15:27
Done.
|
+ |
SK_DECLARE_INST_COUNT(SkFlattenable) |
typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&); |
+ typedef bool (*TypeCheck)(SkFlattenable::Type); |
SkFlattenable() {} |
@@ -59,6 +199,32 @@ public: |
static const char* FactoryToName(Factory); |
static void Register(const char name[], Factory); |
+ /** Returns the class id |
mtklein
2013/09/24 22:52:18
Let's flesh out this (and related comments):
/**
sugoi1
2013/09/25 21:15:27
Done.
|
+ */ |
+ static SkFlattenable::Type GetType() { |
+ return SkFlattenable::kSkFlattenable; |
+ } |
+ |
+ /** Returns the class id of an object |
+ */ |
+ virtual SkFlattenable::Type getFlattenableType() = 0; |
+ |
+ /** Returns whether the current object is of the given type |
+ */ |
+ static bool IsA(SkFlattenable::Type type) { |
+ return (GetType() == type); |
+ } |
+ |
+ /** Returns the factory function required to create the given type |
+ */ |
+ static Factory TypeToFactory(Type type); |
+ |
+ /** Checks if typeA is a typeB |
+ * For example, if typeA is kSkImageFilter and typeB is kSkFlattenable, this would return true |
+ * Inversely, if typeA is kSkFlattenable and typeB is kSkImageFilter, this would return false |
+ */ |
+ static bool TypeIsA(SkFlattenable::Type typeA, SkFlattenable::Type typeB); |
mtklein
2013/09/24 22:52:18
Does this need to be public?
sugoi1
2013/09/25 21:15:27
It needs to be accessible inside SkValidatingReadB
|
+ |
class Registrar { |
public: |
Registrar(const char name[], Factory factory) { |