Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(901)

Unified Diff: src/pdf/SkPDFTypes.h

Issue 1790023003: SkPDF: add drop() virtual to release resources early. (Closed) Base URL: https://skia.googlesource.com/skia.git@skpdf-global
Patch Set: Record move fns Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/pdf/SkPDFTypes.h
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h
index f93b030465736216a796eeb51cc8f4f3a7626067..0a7c1bd06c5252609cc4d774707eea98cfdd4025 100644
--- a/src/pdf/SkPDFTypes.h
+++ b/src/pdf/SkPDFTypes.h
@@ -51,6 +51,13 @@ public:
virtual void addResources(SkPDFObjNumMap* catalog,
const SkPDFSubstituteMap& substitutes) const {}
+ /**
+ * Release all resources associated with this SkPDFObject. It is
+ * an error to call emitObject() or addResources() after calling
+ * dump().
+ */
+ virtual void dump() {}
mtklein 2016/03/18 14:03:26 We usually use dump() to mean, print this to stdou
tomhudson 2016/03/18 14:11:54 Yes! I was concerned but didn't have a better idea
hal.canary 2016/03/18 21:18:07 done. I like drop better.
hal.canary 2016/03/18 21:18:07 Done.
+
private:
typedef SkRefCnt INHERITED;
};
@@ -178,8 +185,6 @@ private:
*/
class SkPDFArray final : public SkPDFObject {
public:
- static const int kMaxLen = 8191;
-
/** Create a PDF array. Maximum length is 8191.
*/
SkPDFArray();
@@ -191,6 +196,7 @@ public:
const SkPDFSubstituteMap& substitutes) const override;
void addResources(SkPDFObjNumMap*,
const SkPDFSubstituteMap&) const override;
+ void dump() override;
/** The size of the array.
*/
@@ -215,9 +221,9 @@ public:
void appendObjRef(sk_sp<SkPDFObject>);
private:
- SkTDArray<SkPDFUnion> fValues;
+ SkTArray<SkPDFUnion> fValues;
void append(SkPDFUnion&& value);
- typedef SkPDFObject INHERITED;
+ SkDEBUGCODE(bool fDumped;)
};
/** \class SkPDFDict
@@ -226,14 +232,10 @@ private:
*/
class SkPDFDict : public SkPDFObject {
public:
- /** Create a PDF dictionary. Maximum number of entries is 4095.
- */
- SkPDFDict();
-
- /** Create a PDF dictionary with a Type entry.
- * @param type The value of the Type entry.
+ /** Create a PDF dictionary.
+ * @param type The value of the Type entry, nullptr for no type.
*/
- explicit SkPDFDict(const char type[]);
+ explicit SkPDFDict(const char type[] = nullptr);
virtual ~SkPDFDict();
@@ -243,6 +245,7 @@ public:
const SkPDFSubstituteMap& substitutes) const override;
void addResources(SkPDFObjNumMap*,
const SkPDFSubstituteMap&) const override;
+ void dump() override;
/** The size of the dictionary.
*/
@@ -270,10 +273,6 @@ public:
void insertString(const char key[], const char value[]);
void insertString(const char key[], const SkString& value);
- /** Remove all entries from the dictionary.
- */
- void clear();
-
/** Emit the dictionary, without the "<<" and ">>".
*/
void emitAll(SkWStream* stream,
@@ -284,13 +283,14 @@ private:
struct Record {
SkPDFUnion fKey;
SkPDFUnion fValue;
+ Record(SkPDFUnion&&, SkPDFUnion&&);
+ Record(Record&&);
+ Record& operator=(Record&&);
+ Record(const Record&) = delete;
+ Record& operator=(const Record&) = delete;
};
- SkTDArray<Record> fRecords;
- static const int kMaxLen = 4095;
-
- void set(SkPDFUnion&& name, SkPDFUnion&& value);
-
- typedef SkPDFObject INHERITED;
+ SkTArray<Record> fRecords;
+ SkDEBUGCODE(bool fDumped;)
};
/** \class SkPDFSharedStream
@@ -303,18 +303,20 @@ private:
class SkPDFSharedStream final : public SkPDFObject {
public:
// Takes ownership of asset.
- SkPDFSharedStream(SkStreamAsset* data)
- : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); }
+ SkPDFSharedStream(SkStreamAsset* data);
+ ~SkPDFSharedStream();
SkPDFDict* dict() { return fDict.get(); }
void emitObject(SkWStream*,
const SkPDFObjNumMap&,
const SkPDFSubstituteMap&) const override;
void addResources(SkPDFObjNumMap*,
const SkPDFSubstituteMap&) const override;
+ void dump() override;
private:
SkAutoTDelete<SkStreamAsset> fAsset;
sk_sp<SkPDFDict> fDict;
+ SkDEBUGCODE(bool fDumped;)
typedef SkPDFObject INHERITED;
};
@@ -344,10 +346,10 @@ public:
*/
int32_t getObjectNumber(SkPDFObject* obj) const;
- const SkTDArray<SkPDFObject*>& objects() const { return fObjects; }
+ const SkTArray<sk_sp<SkPDFObject>>& objects() const { return fObjects; }
private:
- SkTDArray<SkPDFObject*> fObjects;
+ SkTArray<sk_sp<SkPDFObject>> fObjects;
SkTHashMap<SkPDFObject*, int32_t> fObjectNumbers;
};

Powered by Google App Engine
This is Rietveld 408576698