Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkFlattenable_DEFINED | 10 #ifndef SkFlattenable_DEFINED |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ | 23 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ |
| 24 void flattenable::InitializeFlattenables() { | 24 void flattenable::InitializeFlattenables() { |
| 25 | 25 |
| 26 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ | 26 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ |
| 27 } | 27 } |
| 28 | 28 |
| 29 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ | 29 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ |
| 30 virtual Factory getFactory() SK_OVERRIDE { return NULL; } | 30 virtual Factory getFactory() SK_OVERRIDE { return NULL; } |
| 31 | 31 |
| 32 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ | 32 /** For SkFlattenable derived objects that can be serialized without type checki ng |
| 33 */ | |
| 34 #define SK_DEFINE_FLATTENABLE_SERIALIZABLE(flattenable) \ | |
| 33 virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } \ | 35 virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } \ |
| 34 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \ | 36 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \ |
| 35 return SkNEW_ARGS(flattenable, (buffer)); \ | 37 return SkNEW_ARGS(flattenable, (buffer)); \ |
| 36 } | 38 } |
| 37 | 39 |
| 40 /** For SkFlattenable derived objects that need type checking | |
| 41 */ | |
| 42 #define SK_DEFINE_FLATTENABLE_TYPE_CHECKING(flattenable) \ | |
| 43 static bool IsA(SkFlattenable::Type type) { \ | |
| 44 return (flattenable::GetType() == type) || INHERITED::IsA(type); \ | |
| 45 } \ | |
| 46 virtual SkFlattenable::Type getFlattenableType() SK_OVERRIDE { \ | |
| 47 return flattenable::GetType(); \ | |
| 48 } | |
| 49 | |
| 50 /** For SkFlattenable derived objects with a valid type | |
| 51 This macros would typically be used by virtual classes, which need a type, b ut can't | |
| 52 be constructed or serialized directly without going through a derived class | |
| 53 */ | |
| 54 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ | |
| 55 static SkFlattenable::Type GetType() { \ | |
| 56 return SkFlattenable::k##flattenable##_Type; \ | |
| 57 } \ | |
| 58 SK_DEFINE_FLATTENABLE_TYPE_CHECKING(flattenable) | |
| 59 | |
| 60 /** For SkFlattenable derived objects defined outside of skia (sample code, gms, etc). | |
| 61 Since these external object won't go through the secure deserialization, the y are not given | |
| 62 a "Type" in the SkFlattenable::Type enum and there is no need to modify SkFl attenable.h | |
| 63 to add these derived classes. Note that the type is set to SkFlattenable::kN one_Type here. | |
| 64 */ | |
| 65 #define SK_DEFINE_FLATTENABLE_EXTERN(flattenable) \ | |
| 66 SK_DEFINE_FLATTENABLE_SERIALIZABLE(flattenable) \ | |
| 67 static SkFlattenable::Type GetType() { \ | |
| 68 return SkFlattenable::kNone_Type; \ | |
| 69 } \ | |
| 70 SK_DEFINE_FLATTENABLE_TYPE_CHECKING(flattenable) | |
| 71 | |
| 72 /** For SkFlattenable derived objects defined within the skia library | |
| 73 */ | |
| 74 #define SK_DEFINE_FLATTENABLE_SERIALIZABLE_TYPE(flattenable) \ | |
| 75 SK_DEFINE_FLATTENABLE_SERIALIZABLE(flattenable) \ | |
| 76 SK_DEFINE_FLATTENABLE_TYPE(flattenable) | |
| 77 | |
| 78 /** Deprecated, remove once noone is using it anymore | |
| 79 */ | |
| 80 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ | |
| 81 SK_DEFINE_FLATTENABLE_SERIALIZABLE_TYPE(flattenable) | |
| 82 | |
| 83 /** Only for SkFlattenable derived objects that have implementations hidden in a cpp file | |
| 84 This isn't used directly outside of SkFlattenable.h | |
| 85 */ | |
| 86 #define SK_DECLARE_FLATTENABLE_BASE() \ | |
| 87 static SkFlattenable::Factory GetFactory(SkFlattenable::Type); \ | |
| 88 static SkFlattenable::TypeCheck GetTypeCheck(SkFlattenable::Type); | |
| 89 | |
| 90 /** This is for an instantiatable SkFlattenable derived class | |
| 91 with derived classes available in header files | |
| 92 */ | |
| 93 #define SK_DECLARE_FLATTENABLE_GROUP_TYPE(flattenable) \ | |
| 94 SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ | |
| 95 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | |
| 96 | |
| 97 /** This is for an instantiatable SkFlattenable derived class | |
| 98 with derived classes local to a cpp file | |
| 99 */ | |
| 100 #define SK_DECLARE_FLATTENABLE_BASE_SERIALIZABLE_TYPE(flattenable) \ | |
| 101 SK_DECLARE_FLATTENABLE_BASE() \ | |
| 102 SK_DEFINE_FLATTENABLE_SERIALIZABLE(flattenable) \ | |
| 103 SK_DEFINE_FLATTENABLE_TYPE(flattenable) | |
| 104 | |
| 105 /** This is for an uninstantiatable/virtual SkFlattenable derived class | |
| 106 with derived classes local to a cpp file | |
| 107 */ | |
| 108 #define SK_DECLARE_FLATTENABLE_GROUP_BASE_TYPE(flattenable) \ | |
| 109 SK_DECLARE_FLATTENABLE_BASE() \ | |
| 110 SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ | |
| 111 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | |
| 112 | |
| 113 /** This is for a non SkFlattenable class (used as a namespace, essentially) | |
| 114 with SkFlattenable derived classes local to a cpp file | |
| 115 */ | |
| 116 #define SK_DECLARE_FLATTENABLE_GROUP_BASE() \ | |
| 117 SK_DECLARE_FLATTENABLE_BASE() \ | |
| 118 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | |
| 119 | |
| 38 /** \class SkFlattenable | 120 /** \class SkFlattenable |
| 39 | 121 |
| 40 SkFlattenable is the base class for objects that need to be flattened | 122 SkFlattenable is the base class for objects that need to be flattened |
| 41 into a data stream for either transport or as part of the key to the | 123 into a data stream for either transport or as part of the key to the |
| 42 font cache. | 124 font cache. |
| 43 */ | 125 */ |
| 44 class SK_API SkFlattenable : public SkRefCnt { | 126 class SK_API SkFlattenable : public SkRefCnt { |
| 45 public: | 127 public: |
| 128 | |
| 129 /** This is an APPEND ONLY ENUM. Reordering this will break all previously | |
| 130 serialized streams / files using the validating read / write buffer. | |
| 131 | |
| 132 All the types listed here must provide the necessary functionality to | |
| 133 perform type checking and must be stable across binary versions. | |
| 134 */ | |
| 135 enum Type { | |
|
reed1
2013/10/03 08:41:09
*if* we have to have an enumeration of known subcl
| |
| 136 kNone_Type, | |
| 137 kSkFlattenable_Type, | |
| 138 kBATShader_Type, | |
| 139 kCompositeImageFilter_Type, | |
| 140 kFloodImageFilter_Type, | |
| 141 kOffsetImageFilter_Type, | |
| 142 kSk2DPathEffect_Type, | |
| 143 kSk3DShader_Type, | |
| 144 kSkAnnotation_Type, | |
| 145 kSkArithmeticMode_scalar_Type, | |
| 146 kSkAvoidXfermode_Type, | |
| 147 kSkBicubicImageFilter_Type, | |
| 148 kSkBitmapProcShader_Type, | |
| 149 kSkBitmapSource_Type, | |
| 150 kSkBlurDrawLooper_Type, | |
| 151 kSkBlurImageFilter_Type, | |
| 152 kSkBlurMaskFilterImpl_Type, | |
| 153 kSkClearXfermode_Type, | |
| 154 kSkColorFilter_Type, | |
| 155 kSkColorFilterImageFilter_Type, | |
| 156 kSkColorMatrixFilter_Type, | |
| 157 kSkColorShader_Type, | |
| 158 kSkColorTable_Type, | |
| 159 kSkComposeImageFilter_Type, | |
| 160 kSkComposePathEffect_Type, | |
| 161 kSkComposeShader_Type, | |
| 162 kSkCornerPathEffect_Type, | |
| 163 kSkCosineMapper_Type, | |
| 164 kSkData_Type, | |
| 165 kSkDataPixelRef_Type, | |
| 166 kSkDataSet_Type, | |
| 167 kSkDataTable_Type, | |
| 168 kSkDiffuseLightingImageFilter_Type, | |
| 169 kSkDilateImageFilter_Type, | |
| 170 kSkDiscreteMapper_Type, | |
| 171 kSkDiscretePathEffect_Type, | |
| 172 kSkDisplacementMapEffect_Type, | |
| 173 kSkDistantLight_Type, | |
| 174 kSkDownSampleImageFilter_Type, | |
| 175 kSkDrawLooper_Type, | |
| 176 kSkDropShadowImageFilter_Type, | |
| 177 kSkDstInXfermode_Type, | |
| 178 kSkDstOutXfermode_Type, | |
| 179 kSkEmbossMaskFilter_Type, | |
| 180 kSkEmptyShader_Type, | |
| 181 kSkErodeImageFilter_Type, | |
| 182 kSkFilterShader_Type, | |
| 183 kSkImageFilter_Type, | |
| 184 kSkImageRef_GlobalPool_Type, | |
| 185 kSkKernel33MaskFilter_Type, | |
| 186 kSkLayerDrawLooper_Type, | |
| 187 kSkLayerRasterizer_Type, | |
| 188 kSkLerpXfermode_Type, | |
| 189 kSkLight_Type, | |
| 190 kSkLightingColorFilter_Type, | |
| 191 kSkLightingColorFilter_JustAdd_Type, | |
| 192 kSkLightingColorFilter_JustMul_Type, | |
| 193 kSkLightingColorFilter_NoPin_Type, | |
| 194 kSkLightingColorFilter_SingleMul_Type, | |
| 195 kSkLightingImageFilter_Type, | |
| 196 kSkLinearGradient_Type, | |
| 197 kSkLine2DPathEffect_Type, | |
| 198 kSkLumaMaskXfermode_Type, | |
| 199 kSkLumaMaskXfermodeSrcOver_Type, | |
| 200 kSkMagnifierImageFilter_Type, | |
| 201 kSkMallocPixelRef_Type, | |
| 202 kSkMaskFilter_Type, | |
| 203 kSkMatrixConvolutionImageFilter_Type, | |
| 204 kSkMergeImageFilter_Type, | |
| 205 kSkModeColorFilter_Type, | |
| 206 kSkOffsetImageFilter_Type, | |
| 207 kSkPathEffect_Type, | |
| 208 kSkPath1DPathEffect_Type, | |
| 209 kSkPath2DPathEffect_Type, | |
| 210 kSkPerlinNoiseShader_Type, | |
| 211 kSkPixelRef_Type, | |
| 212 kSkPixelXorXfermode_Type, | |
| 213 kSkPointLight_Type, | |
| 214 kSkProcCoeffXfermode_Type, | |
| 215 kSkProcXfermode_Type, | |
| 216 kSkRadialGradient_Type, | |
| 217 kSkRasterizer_Type, | |
| 218 kSkRectShaderImageFilter_Type, | |
| 219 kSkShader_Type, | |
| 220 kSkSpecularLightingImageFilter_Type, | |
| 221 kSkSpotLight_Type, | |
| 222 kSkSrcXfermode_Type, | |
| 223 kSkStippleMaskFilter_Type, | |
| 224 kSkSumPathEffect_Type, | |
| 225 kSkSweepGradient_Type, | |
| 226 kSkTable_ColorFilter_Type, | |
| 227 kSkTableMaskFilter_Type, | |
| 228 kSkTileImageFilter_Type, | |
| 229 kSkTransparentShader_Type, | |
| 230 kSkTriColorShader_Type, | |
| 231 kSkTwoPointConicalGradient_Type, | |
| 232 kSkTwoPointRadialGradient_Type, | |
| 233 kSkUnitMapper_Type, | |
| 234 kSkXfermode_Type, | |
| 235 kSkXfermodeImageFilter_Type, | |
| 236 kSrc_SkModeColorFilter_Type, | |
| 237 kSrcOver_SkModeColorFilter_Type, | |
| 238 kTileImageFilter_Type, | |
| 239 // New values go here. This is an APPEND ONLY ENUM. Do not insert values alphabetically. | |
| 240 kTypeCount | |
| 241 }; | |
| 242 | |
| 46 SK_DECLARE_INST_COUNT(SkFlattenable) | 243 SK_DECLARE_INST_COUNT(SkFlattenable) |
| 47 | 244 |
| 48 typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&); | 245 typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&); |
| 246 typedef bool (*TypeCheck)(SkFlattenable::Type); | |
| 49 | 247 |
| 50 SkFlattenable() {} | 248 SkFlattenable() {} |
| 51 | 249 |
| 52 /** Implement this to return a factory function pointer that can be called | 250 /** Implement this to return a factory function pointer that can be called |
| 53 to recreate your class given a buffer (previously written to by your | 251 to recreate your class given a buffer (previously written to by your |
| 54 override of flatten(). | 252 override of flatten(). |
| 55 */ | 253 */ |
| 56 virtual Factory getFactory() = 0; | 254 virtual Factory getFactory() = 0; |
| 57 | 255 |
| 58 static Factory NameToFactory(const char name[]); | 256 static Factory NameToFactory(const char name[]); |
| 59 static const char* FactoryToName(Factory); | 257 static const char* FactoryToName(Factory); |
| 60 static void Register(const char name[], Factory); | 258 static void Register(const char name[], Factory); |
| 61 | 259 |
| 260 /** Returns the class id | |
| 261 GetType methods on classes descending from SkFlattenable should return t he | |
| 262 SkFlattenable::Type associated with that class, or SkFlattenable::kNoneT ype if | |
| 263 they're not part of the subset of SkFlattenables that can be used with | |
| 264 SkFlattenable::TypeToFactory(). Typycally, SK_DEFINE_FLATTENABLE_TYPE() will | |
| 265 define GetType(), getFlattenableType() and IsA() in the derived class. | |
| 266 * Note that SK_DEFINE_FLATTENABLE_TYPE() is included in other macros tha t include | |
| 267 the "_TYPE" suffix, so most classes will have these declared by defaul t. | |
| 268 External classes can use SK_DEFINE_FLATTENABLE_EXTERN(), which will do the same, | |
| 269 but set the class type to SkFlattenable::kNone_Type. | |
| 270 */ | |
| 271 static SkFlattenable::Type GetType() { | |
| 272 return SkFlattenable::kSkFlattenable_Type; | |
| 273 } | |
| 274 | |
| 275 /** Returns the class id of an object | |
| 276 */ | |
| 277 virtual SkFlattenable::Type getFlattenableType() = 0; | |
| 278 | |
| 279 /** Returns whether the current object is of the given type | |
| 280 */ | |
| 281 static bool IsA(SkFlattenable::Type type) { | |
| 282 return (GetType() == type); | |
| 283 } | |
| 284 | |
| 285 /** Returns the factory function required to create the given type | |
| 286 */ | |
| 287 static Factory TypeToFactory(Type type); | |
| 288 | |
| 289 /** Checks if typeA is a typeB | |
| 290 * For example, if typeA is kSkImageFilter and typeB is kSkFlattenable, thi s would return true | |
| 291 * Inversely, if typeA is kSkFlattenable and typeB is kSkImageFilter, this would return false | |
| 292 */ | |
| 293 static bool TypeIsA(SkFlattenable::Type typeA, SkFlattenable::Type typeB); | |
| 294 | |
| 62 class Registrar { | 295 class Registrar { |
| 63 public: | 296 public: |
| 64 Registrar(const char name[], Factory factory) { | 297 Registrar(const char name[], Factory factory) { |
| 65 SkFlattenable::Register(name, factory); | 298 SkFlattenable::Register(name, factory); |
| 66 } | 299 } |
| 67 }; | 300 }; |
| 68 | 301 |
| 69 protected: | 302 protected: |
| 70 SkFlattenable(SkFlattenableReadBuffer&) {} | 303 SkFlattenable(SkFlattenableReadBuffer&) {} |
| 71 /** Override this to write data specific to your subclass into the buffer, | 304 /** Override this to write data specific to your subclass into the buffer, |
| 72 being sure to call your super-class' version first. This data will later | 305 being sure to call your super-class' version first. This data will later |
| 73 be passed to your Factory function, returned by getFactory(). | 306 be passed to your Factory function, returned by getFactory(). |
| 74 */ | 307 */ |
| 75 virtual void flatten(SkFlattenableWriteBuffer&) const; | 308 virtual void flatten(SkFlattenableWriteBuffer&) const; |
| 76 | 309 |
| 77 private: | 310 private: |
| 78 static void InitializeFlattenables(); | 311 static void InitializeFlattenables(); |
| 79 | 312 |
| 80 friend class SkGraphics; | 313 friend class SkGraphics; |
| 81 friend class SkFlattenableWriteBuffer; | 314 friend class SkFlattenableWriteBuffer; |
| 82 | 315 |
| 83 typedef SkRefCnt INHERITED; | 316 typedef SkRefCnt INHERITED; |
| 84 }; | 317 }; |
| 85 | 318 |
| 86 #endif | 319 #endif |
| OLD | NEW |