diff options
author | 2015-09-09 09:09:53 -0700 | |
---|---|---|
committer | 2015-09-09 09:09:53 -0700 | |
commit | 6c59d80858f453a426df9b07fdf3a8cc01e0b906 (patch) | |
tree | 1fc4c3c03062744c4382a40e608bdb147bebad09 /src/pdf | |
parent | 336cda3fc0e01cd80212e0ac133d65b60824868e (diff) |
Port uses of SkLazyPtr to SkOncePtr.
This gives SkOncePtr a non-trivial destructor that uses std::default_delete
by default. This is overrideable, as seen in SkColorTable.
SK_DECLARE_STATIC_ONCE_PTR still just leaves its pointers hanging at EOP.
BUG=skia:
No public API changes.
TBR=reed@google.com
Committed: https://skia.googlesource.com/skia/+/a1254acdb344174e761f5061c820559dab64a74c
Review URL: https://codereview.chromium.org/1322933005
Diffstat (limited to 'src/pdf')
-rw-r--r-- | src/pdf/SkPDFGraphicState.cpp | 26 | ||||
-rw-r--r-- | src/pdf/SkPDFShader.cpp | 13 |
2 files changed, 11 insertions, 28 deletions
diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp index 162ddc8447..0ad1853f3e 100644 --- a/src/pdf/SkPDFGraphicState.cpp +++ b/src/pdf/SkPDFGraphicState.cpp @@ -6,7 +6,7 @@ */ #include "SkData.h" -#include "SkLazyPtr.h" +#include "SkOncePtr.h" #include "SkPDFCanon.h" #include "SkPDFFormXObject.h" #include "SkPDFGraphicState.h" @@ -126,8 +126,7 @@ SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint( return pdfGraphicState; } -namespace { -SkPDFObject* create_invert_function() { +static SkPDFObject* create_invert_function() { // Acrobat crashes if we use a type 0 function, kpdf crashes if we use // a type 2 function, so we use a type 4 function. SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); @@ -147,13 +146,7 @@ SkPDFObject* create_invert_function() { return invertFunction; } -template <typename T> void unref(T* ptr) { ptr->unref(); } -} // namespace - -SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject, - invertFunction, - create_invert_function, - unref<SkPDFObject>); +SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, invertFunction); // static SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, @@ -169,7 +162,7 @@ SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, } sMaskDict->insertObjRef("G", SkRef(sMask)); if (invert) { - sMaskDict->insertObjRef("TR", SkRef(invertFunction.get())); + sMaskDict->insertObjRef("TR", SkRef(invertFunction.get(create_invert_function))); } SkPDFDict* result = new SkPDFDict("ExtGState"); @@ -177,21 +170,16 @@ SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, return result; } -namespace { -SkPDFDict* create_no_smask_graphic_state() { +static SkPDFDict* create_no_smask_graphic_state() { SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState"); noSMaskGS->insertName("SMask", "None"); return noSMaskGS; } -} // namespace -SK_DECLARE_STATIC_LAZY_PTR(SkPDFDict, - noSMaskGraphicState, - create_no_smask_graphic_state, - unref<SkPDFDict>); +SK_DECLARE_STATIC_ONCE_PTR(SkPDFDict, noSMaskGraphicState); // static SkPDFDict* SkPDFGraphicState::GetNoSMaskGraphicState() { - return SkRef(noSMaskGraphicState.get()); + return SkRef(noSMaskGraphicState.get(create_no_smask_graphic_state)); } void SkPDFGraphicState::emitObject( diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index 645091dad2..fe6e47c1db 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -10,6 +10,7 @@ #include "SkPDFShader.h" #include "SkData.h" +#include "SkOncePtr.h" #include "SkPDFCanon.h" #include "SkPDFDevice.h" #include "SkPDFFormXObject.h" @@ -677,8 +678,7 @@ static bool split_perspective(const SkMatrix in, SkMatrix* affine, return true; } -namespace { -SkPDFObject* create_range_object() { +static SkPDFObject* create_range_object() { SkPDFArray* range = new SkPDFArray; range->reserve(6); range->appendInt(0); @@ -689,12 +689,7 @@ SkPDFObject* create_range_object() { range->appendInt(1); return range; } - -template <typename T> void unref(T* ptr) { ptr->unref();} -} // namespace - -SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject, rangeObject, - create_range_object, unref<SkPDFObject>); +SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, rangeObject); static SkPDFStream* make_ps_function(const SkString& psCode, SkPDFArray* domain) { @@ -703,7 +698,7 @@ static SkPDFStream* make_ps_function(const SkString& psCode, SkPDFStream* result = new SkPDFStream(funcData.get()); result->insertInt("FunctionType", 4); result->insertObject("Domain", SkRef(domain)); - result->insertObject("Range", SkRef(rangeObject.get())); + result->insertObject("Range", SkRef(rangeObject.get(create_range_object))); return result; } |