Chromium Code Reviews| Index: src/pdf/SkPDFTypes.h |
| =================================================================== |
| --- src/pdf/SkPDFTypes.h (revision 7963) |
| +++ src/pdf/SkPDFTypes.h (working copy) |
| @@ -29,6 +29,8 @@ |
| public: |
| SK_DECLARE_INST_COUNT(SkPDFObject) |
| + virtual ~SkPDFObject() { }; |
| + |
| /** Return the size (number of bytes) of this object in the final output |
| * file. Compound objects or objects that are computationally intensive |
| * to output should override this method. |
| @@ -79,6 +81,26 @@ |
| static void GetResourcesHelper(SkTDArray<SkPDFObject*>* resources, |
| SkTDArray<SkPDFObject*>* result); |
| + /** Destroys safely an array of SkPDFObject's. |
|
Tom Hudson
2013/03/07 13:54:37
nit: no apostrophe
edisonn
2013/03/07 16:51:30
Done.
|
| + * The stack won't be used much, and stack overflow will be avoided. |
| + * @param list: The list of objects to be destroyed. |
|
Tom Hudson
2013/03/07 13:54:37
nit: redundant @param
edisonn
2013/03/07 16:51:30
removed
|
| + */ |
| + static void safeUnref(SkTDArray<SkPDFObject*>* list) { |
| + while (list->count() > 0) { |
| + SkPDFObject* obj = NULL; |
| + list->pop(&obj); |
| + if (obj) { |
| + // Releases all refs to be owned by list, unref will call destructor! |
| + if (obj->fRefCnt == 1) { |
| + obj->trasferPDFObjecsOwnership(list); |
| + } |
| + // If unref calls destructor, it won't call recursively |
| + // other ~SkPDFObjects(). |
| + obj->unref(); |
| + } |
| + } |
| + } |
| + |
| protected: |
| /** Subclasses must implement this method to print the object to the |
| * PDF file. |
| @@ -89,6 +111,14 @@ |
| virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, |
| bool indirect) = 0; |
| + /** Dumps all the SkPDFObject members in the list. When the destructor is |
| + * called, the stack won't be used much. |
| + * This method will destroy the state of the object. Should be called only |
| + * during destructor calls. |
| + * @param list: The list that will own the SkPDFObject members. |
|
Tom Hudson
2013/03/07 13:54:37
This @param declaration doesn't actually explain w
edisonn
2013/03/07 16:51:30
Done.
|
| + */ |
| + virtual void trasferPDFObjecsOwnership(SkTDArray<SkPDFObject*>* list) {} |
| + |
| typedef SkRefCnt INHERITED; |
| }; |
| @@ -111,6 +141,13 @@ |
| bool indirect); |
| virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
| +protected: |
| + virtual void trasferPDFObjecsOwnership(SkTDArray<SkPDFObject*>* list) { |
| + list->push(fObj.detach()); |
| + |
| + INHERITED::trasferPDFObjecsOwnership(list); |
| + } |
| + |
| private: |
| SkAutoTUnref<SkPDFObject> fObj; |
| @@ -406,6 +443,18 @@ |
| */ |
| void clear(); |
| + virtual void trasferPDFObjecsOwnership(SkTDArray<SkPDFObject*>* list) { |
| + for (int i = 0; i < fValue.count(); i++) { |
| + list->push(fValue[i].key); |
| + fValue[i].key = NULL; |
| + list->push(fValue[i].value); |
| + fValue[i].value = NULL; |
| + } |
| + fValue.reset(); |
| + |
| + INHERITED::trasferPDFObjecsOwnership(list); |
| + } |
| + |
| private: |
| struct Rec { |
| SkPDFName* key; |