begin to skiafy PDF headers : removing use of SkRefPtr

Review URL: https://codereview.appspot.com/6526050

git-svn-id: http://skia.googlecode.com/svn/trunk@5596 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-09-19 17:05:55 +00:00
Родитель 9ec51dd605
Коммит 2a006c1127
4 изменённых файлов: 20 добавлений и 22 удалений

Просмотреть файл

@ -139,13 +139,14 @@ public:
*/ */
SK_API const SkTDArray<SkPDFFont*>& getFontResources() const; SK_API const SkTDArray<SkPDFFont*>& getFontResources() const;
/** Returns the media box for this device. /** Returns a copy of the media box for this device. The caller is required
* to unref() this when it is finished.
*/ */
SK_API SkRefPtr<SkPDFArray> getMediaBox() const; SK_API SkPDFArray* copyMediaBox() const;
/** Get the annotations from this page. /** Get the annotations from this page, or NULL if there are none.
*/ */
SK_API SkRefPtr<SkPDFArray> getAnnotations() const; SK_API SkPDFArray* getAnnotations() const { return fAnnotations; }
/** Returns a SkStream with the page contents. The caller is responsible /** Returns a SkStream with the page contents. The caller is responsible
for a reference to the returned value. for a reference to the returned value.
@ -185,7 +186,7 @@ private:
SkMatrix fInitialTransform; SkMatrix fInitialTransform;
SkClipStack fExistingClipStack; SkClipStack fExistingClipStack;
SkRegion fExistingClipRegion; SkRegion fExistingClipRegion;
SkRefPtr<SkPDFArray> fAnnotations; SkPDFArray* fAnnotations;
SkRefPtr<SkPDFDict> fResourceDict; SkRefPtr<SkPDFDict> fResourceDict;
SkTDArray<SkPDFGraphicState*> fGraphicStateResources; SkTDArray<SkPDFGraphicState*> fGraphicStateResources;

Просмотреть файл

@ -546,6 +546,7 @@ SkPDFDevice::~SkPDFDevice() {
} }
void SkPDFDevice::init() { void SkPDFDevice::init() {
fAnnotations = NULL;
fResourceDict = NULL; fResourceDict = NULL;
fContentEntries.reset(); fContentEntries.reset();
fLastContentEntry = NULL; fLastContentEntry = NULL;
@ -562,6 +563,8 @@ void SkPDFDevice::cleanUp(bool clearFontUsage) {
fXObjectResources.unrefAll(); fXObjectResources.unrefAll();
fFontResources.unrefAll(); fFontResources.unrefAll();
fShaderResources.unrefAll(); fShaderResources.unrefAll();
SkSafeUnref(fAnnotations);
if (clearFontUsage) { if (clearFontUsage) {
fFontGlyphUsage->reset(); fFontGlyphUsage->reset();
} }
@ -1103,12 +1106,11 @@ const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
return fFontResources; return fFontResources;
} }
SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const { SkPDFArray* SkPDFDevice::copyMediaBox() const {
SkRefPtr<SkPDFInt> zero = new SkPDFInt(0); // should this be a singleton?
zero->unref(); // SkRefPtr and new both took a reference. SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0)));
SkRefPtr<SkPDFArray> mediaBox = new SkPDFArray(); SkPDFArray* mediaBox = SkNEW(SkPDFArray);
mediaBox->unref(); // SkRefPtr and new both took a reference.
mediaBox->reserve(4); mediaBox->reserve(4);
mediaBox->append(zero.get()); mediaBox->append(zero.get());
mediaBox->append(zero.get()); mediaBox->append(zero.get());
@ -1117,10 +1119,6 @@ SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const {
return mediaBox; return mediaBox;
} }
SkRefPtr<SkPDFArray> SkPDFDevice::getAnnotations() const {
return SkRefPtr<SkPDFArray>(fAnnotations);
}
SkStream* SkPDFDevice::content() const { SkStream* SkPDFDevice::content() const {
SkMemoryStream* result = new SkMemoryStream; SkMemoryStream* result = new SkMemoryStream;
result->setData(this->copyContentToData())->unref(); result->setData(this->copyContentToData())->unref();
@ -1196,9 +1194,8 @@ bool SkPDFDevice::handleAnnotations(const SkRect& r, const SkMatrix& matrix,
SkRect translatedRect; SkRect translatedRect;
transform.mapRect(&translatedRect, r); transform.mapRect(&translatedRect, r);
if (fAnnotations.get() == NULL) { if (NULL == fAnnotations) {
fAnnotations = new SkPDFArray; fAnnotations = SkNEW(SkPDFArray);
fAnnotations->unref(); // Both new and SkRefPtr took a reference.
} }
SkAutoTUnref<SkPDFDict> annotation(new SkPDFDict("Annot")); SkAutoTUnref<SkPDFDict> annotation(new SkPDFDict("Annot"));
annotation->insertName("Subtype", "Link"); annotation->insertName("Subtype", "Link");

Просмотреть файл

@ -28,7 +28,7 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
insertName("Type", "XObject"); insertName("Type", "XObject");
insertName("Subtype", "Form"); insertName("Subtype", "Form");
insert("BBox", device->getMediaBox().get()); SkSafeUnref(this->insert("BBox", device->copyMediaBox()));
insert("Resources", device->getResourceDict()); insert("Resources", device->getResourceDict());
// We invert the initial transform and apply that to the xobject so that // We invert the initial transform and apply that to the xobject so that

Просмотреть файл

@ -23,12 +23,12 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage,
SkTDArray<SkPDFObject*>* resourceObjects) { SkTDArray<SkPDFObject*>* resourceObjects) {
if (fContentStream.get() == NULL) { if (fContentStream.get() == NULL) {
insert("Resources", fDevice->getResourceDict()); insert("Resources", fDevice->getResourceDict());
insert("MediaBox", fDevice->getMediaBox().get()); SkSafeUnref(this->insert("MediaBox", fDevice->copyMediaBox()));
if (!SkToBool(catalog->getDocumentFlags() & if (!SkToBool(catalog->getDocumentFlags() &
SkPDFDocument::kNoLinks_Flags)) { SkPDFDocument::kNoLinks_Flags)) {
SkRefPtr<SkPDFArray> annots = fDevice->getAnnotations(); SkPDFArray* annots = fDevice->getAnnotations();
if (annots.get() && annots->size() > 0) { if (annots && annots->size() > 0) {
insert("Annots", annots.get()); insert("Annots", annots);
} }
} }