diff options
author | halcanary <halcanary@google.com> | 2016-03-08 15:10:16 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-08 15:10:16 -0800 |
commit | 8103a34300c5de2e85793a96c4738a33fc6eb46d (patch) | |
tree | 705b9e5d51cfe1286245cac434516d3d7355aded /src/pdf/SkPDFTypes.h | |
parent | c48fc9b1fdd0ba255a3ef1a9b3bcba9ee918b1f7 (diff) |
SkPDF: Add sk_sp setters; .release() becomes std::move()
Note to reviewers: Start with changes to SkPDFTypes.h
Many places that had a bare pointer owning a reference are refactored to
use a sk_sp.
There remain several places where a non-owning pointer `T*` should be
replaced with `const sk_sp<T>&` to eliminate the common pattern
`sk_sp<T>(SkRef(x))`.
Committed: https://skia.googlesource.com/skia/+/9904c9212074279380e21f96575078734dbbd308
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1775043002
Review URL: https://codereview.chromium.org/1775043002
Diffstat (limited to 'src/pdf/SkPDFTypes.h')
-rw-r--r-- | src/pdf/SkPDFTypes.h | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h index a6a3e12ee6..f93b030465 100644 --- a/src/pdf/SkPDFTypes.h +++ b/src/pdf/SkPDFTypes.h @@ -39,7 +39,6 @@ public: * @param catalog The object catalog to use. * @param stream The writable output stream to send the output to. */ - // TODO(halcanary): make this method const virtual void emitObject(SkWStream* stream, const SkPDFObjNumMap& objNumMap, const SkPDFSubstituteMap& substitutes) const = 0; @@ -65,8 +64,6 @@ private: */ class SkPDFUnion { public: - // u.move() is analogous to std::move(u). It returns an rvalue. - SkPDFUnion move() { return static_cast<SkPDFUnion&&>(*this); } // Move contstructor and assignemnt operator destroy the argument // and steal their references (if needed). SkPDFUnion(SkPDFUnion&& other); @@ -85,7 +82,7 @@ public: static SkPDFUnion Scalar(SkScalar); - /** These two functions do NOT take ownership of ptr, and do NOT + /** These two functions do NOT take ownership of char*, and do NOT copy the string. Suitable for passing in static const strings. For example: SkPDFUnion n = SkPDFUnion::Name("Length"); @@ -108,17 +105,8 @@ public: /** SkPDFUnion::String will encode the passed string. */ static SkPDFUnion String(const SkString&); - /** This function DOES take ownership of the object. E.g. - auto dict = sk_make_sp<SkPDFDict>(); - dict->insert(.....); - SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */ - static SkPDFUnion Object(SkPDFObject*); - - /** This function DOES take ownership of the object. E.g. - sk_sp<SkPDFBitmap> image( - SkPDFBitmap::Create(fCanon, bitmap)); - SkPDFUnion u = SkPDFUnion::ObjRef(image.detach()) */ - static SkPDFUnion ObjRef(SkPDFObject*); + static SkPDFUnion Object(sk_sp<SkPDFObject>); + static SkPDFUnion ObjRef(sk_sp<SkPDFObject>); /** These two non-virtual methods mirror SkPDFObject's corresponding virtuals. */ @@ -174,7 +162,7 @@ public: const SkPDFObjNumMap& objNumMap, const SkPDFSubstituteMap& substitutes) final; void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; - SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {} + SkPDFAtom(SkPDFUnion&& v) : fValue(std::move(v) {} private: const SkPDFUnion fValue; @@ -223,9 +211,8 @@ public: void appendName(const SkString&); void appendString(const char[]); void appendString(const SkString&); - /** appendObject and appendObjRef take ownership of the passed object */ - void appendObject(SkPDFObject*); - void appendObjRef(SkPDFObject*); + void appendObject(sk_sp<SkPDFObject>); + void appendObjRef(sk_sp<SkPDFObject>); private: SkTDArray<SkPDFUnion> fValues; @@ -261,15 +248,14 @@ public: */ int size() const; - /** Add the value to the dictionary with the given key. Takes - * ownership of the object. + /** Add the value to the dictionary with the given key. * @param key The text of the key for this dictionary entry. * @param value The value for this dictionary entry. */ - void insertObject(const char key[], SkPDFObject* value); - void insertObject(const SkString& key, SkPDFObject* value); - void insertObjRef(const char key[], SkPDFObject* value); - void insertObjRef(const SkString& key, SkPDFObject* value); + void insertObject(const char key[], sk_sp<SkPDFObject>); + void insertObject(const SkString& key, sk_sp<SkPDFObject>); + void insertObjRef(const char key[], sk_sp<SkPDFObject>); + void insertObjRef(const SkString& key, sk_sp<SkPDFObject>); /** Add the value to the dictionary with the given key. * @param key The text of the key for this dictionary entry. @@ -317,7 +303,8 @@ private: class SkPDFSharedStream final : public SkPDFObject { public: // Takes ownership of asset. - SkPDFSharedStream(SkStreamAsset* data) : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); } + SkPDFSharedStream(SkStreamAsset* data) + : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); } SkPDFDict* dict() { return fDict.get(); } void emitObject(SkWStream*, const SkPDFObjNumMap&, |