Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 Flattenables | |
| 2 ============ | |
| 3 | |
| 4 Many objects in Skia, such as SkShaders and other effects on SkPaint, need to be | |
| 5 flattened into a data stream for either transport or as part of the key to the | |
| 6 font cache. Classes for these objects should derive from SkFlattenable or one of | |
| 7 its subclasses. If you create a new flattenable class, you need to make sure you | |
| 8 do a few things so that it will work on all platforms: | |
| 9 | |
| 10 1: Override the method flatten (the default scope is protected): | |
| 11 | |
| 12 ~~~~ | |
|
jcgregorio
2015/01/21 17:55:39
Add prettify before all the code sections in all t
| |
| 13 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE { | |
| 14 this->INHERITED::flatten(buffer); | |
| 15 // Write any private data that needs to be stored to recreate this object | |
| 16 } | |
| 17 ~~~~ | |
| 18 | |
| 19 2: Override the (protected) constructor that creates an object from an | |
| 20 SkFlattenableReadBuffer: | |
| 21 | |
| 22 ~~~~ | |
| 23 SkNewClass(SkFlattenableReadBuffer& buffer) | |
| 24 : INHERITED(buffer) { | |
| 25 // Read the data from the buffer in the same order as it was written to the | |
| 26 // SkFlattenableWriteBuffer and construct the new object | |
| 27 } | |
| 28 ~~~~ | |
| 29 | |
| 30 3: Declare a set of deserialization procs for your object in the class declarati on: | |
| 31 We have a macro for this: | |
| 32 | |
| 33 ~~~~ | |
| 34 public: | |
| 35 | |
| 36 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkNewClass) | |
| 37 ~~~~ | |
| 38 | |
| 39 4: If your class is declared in a .cpp file or in a private header file, create a | |
| 40 function to register its group: | |
| 41 This occurs in cases where the classes are hidden behind a factory, like many ef fects | |
| 42 and shaders are. Then in the parent class header file (such as SkGradientShader ) you | |
| 43 need to add: | |
| 44 | |
| 45 ~~~~ | |
| 46 public: | |
| 47 | |
| 48 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | |
| 49 | |
| 50 | |
| 51 Then in the cpp file you define all the members of the group together: | |
| 52 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGroupClass) | |
| 53 | |
| 54 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkMemberClass1) | |
| 55 | |
| 56 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkMemberClass2) | |
| 57 | |
| 58 // etc | |
| 59 | |
| 60 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | |
| 61 ~~~~ | |
| 62 | |
| 63 | |
| 64 5: Register your flattenable with the global registrar: | |
| 65 You need to add one line to SkFlattenable::InitalizeFlattenables(). To register the | |
| 66 flattenable in a Skia build, that function is defined in SkGlobalInitialization_ default.cpp. | |
| 67 For Chromium, it is in SkGlobalInitialization_chromium.cpp. | |
| 68 For a single flattenable add | |
| 69 | |
| 70 ~~~~ | |
| 71 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkNewClass) | |
| 72 ~~~~ | |
| 73 | |
| 74 For a group, add | |
| 75 | |
| 76 ~~~~ | |
| 77 SkGroupClass::InitializeFlattenables(); | |
| 78 ~~~~ | |
| 79 | |
| OLD | NEW |