diff options
author | halcanary <halcanary@google.com> | 2016-03-08 13:03:55 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-08 13:03:55 -0800 |
commit | 51d04d3c17954f9f8629e7d8a9fe870a7b19962f (patch) | |
tree | 0238b33291f8166aacc332d0c0d5df0c0b3e5dcf /src/pdf/SkPDFTypes.h | |
parent | 647cc8474828202c98d540f799742e3074a2aace (diff) |
Revert of SkPDF: Add sk_sp setters; .release() becomes std::move() (patchset #2 id:20001 of https://codereview.chromium.org/1775043002/ )
Reason for revert:
https://build.chromium.org/p/client.skia/builders/Linux%20Builder/builds/6405/steps/compile/logs/stdio
Original issue's description:
> 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
TBR=bungeman@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.chromium.org/1775143002
Diffstat (limited to 'src/pdf/SkPDFTypes.h')
-rw-r--r-- | src/pdf/SkPDFTypes.h | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h index f93b030465..a6a3e12ee6 100644 --- a/src/pdf/SkPDFTypes.h +++ b/src/pdf/SkPDFTypes.h @@ -39,6 +39,7 @@ 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; @@ -64,6 +65,8 @@ 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); @@ -82,7 +85,7 @@ public: static SkPDFUnion Scalar(SkScalar); - /** These two functions do NOT take ownership of char*, and do NOT + /** These two functions do NOT take ownership of ptr, and do NOT copy the string. Suitable for passing in static const strings. For example: SkPDFUnion n = SkPDFUnion::Name("Length"); @@ -105,8 +108,17 @@ public: /** SkPDFUnion::String will encode the passed string. */ static SkPDFUnion String(const SkString&); - static SkPDFUnion Object(sk_sp<SkPDFObject>); - static SkPDFUnion ObjRef(sk_sp<SkPDFObject>); + /** 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*); /** These two non-virtual methods mirror SkPDFObject's corresponding virtuals. */ @@ -162,7 +174,7 @@ public: const SkPDFObjNumMap& objNumMap, const SkPDFSubstituteMap& substitutes) final; void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; - SkPDFAtom(SkPDFUnion&& v) : fValue(std::move(v) {} + SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {} private: const SkPDFUnion fValue; @@ -211,8 +223,9 @@ public: void appendName(const SkString&); void appendString(const char[]); void appendString(const SkString&); - void appendObject(sk_sp<SkPDFObject>); - void appendObjRef(sk_sp<SkPDFObject>); + /** appendObject and appendObjRef take ownership of the passed object */ + void appendObject(SkPDFObject*); + void appendObjRef(SkPDFObject*); private: SkTDArray<SkPDFUnion> fValues; @@ -248,14 +261,15 @@ public: */ int size() const; - /** Add the value to the dictionary with the given key. + /** Add the value to the dictionary with the given key. Takes + * ownership of the object. * @param key The text of the key for this dictionary entry. * @param value The value for this dictionary entry. */ - 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>); + 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); /** Add the value to the dictionary with the given key. * @param key The text of the key for this dictionary entry. @@ -303,8 +317,7 @@ 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&, |