diff options
author | vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-24 23:22:30 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-24 23:22:30 +0000 |
commit | c2a9b7fe5640af8f0c371561f1ac71b045d6d8ec (patch) | |
tree | 8db889cce0421f3c36c92bb6539654062cd254dc | |
parent | f60a001d1a0052fe21956d8d222d9ba1b5a05981 (diff) |
[PDF] Remove one copy of each content stream.
Review URL: http://codereview.appspot.com/4231044
git-svn-id: http://skia.googlecode.com/svn/trunk@856 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/pdf/SkPDFDevice.h | 5 | ||||
-rw-r--r-- | include/pdf/SkPDFPage.h | 1 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 14 | ||||
-rw-r--r-- | src/pdf/SkPDFFormXObject.cpp | 8 | ||||
-rw-r--r-- | src/pdf/SkPDFPage.cpp | 8 |
5 files changed, 19 insertions, 17 deletions
diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h index f9247a7122..3e1edb7d97 100644 --- a/include/pdf/SkPDFDevice.h +++ b/include/pdf/SkPDFDevice.h @@ -132,9 +132,10 @@ public: */ SkRefPtr<SkPDFArray> getMediaBox() const; - /** Returns a string with the page contents. + /** Returns a SkStream with the page contents. The caller is responsible + for a reference to the returned value. */ - SkString content() const; + SkStream* content() const; private: int fWidth; diff --git a/include/pdf/SkPDFPage.h b/include/pdf/SkPDFPage.h index 0831cb504e..b12be16fa2 100644 --- a/include/pdf/SkPDFPage.h +++ b/include/pdf/SkPDFPage.h @@ -90,7 +90,6 @@ private: // Multiple pages may reference the content. SkRefPtr<SkPDFDevice> fDevice; - SkString fContent; // Once the content is finalized, put it into a stream for output. SkRefPtr<SkPDFStream> fContentStream; }; diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 1c6477f9ba..cf6a68e3d9 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -558,10 +558,16 @@ SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const { return mediaBox; } -SkString SkPDFDevice::content() const { - SkString result = fContent; - for (int i = 0; i < fGraphicStackIndex; i++) - result.append("Q\n"); +SkStream* SkPDFDevice::content() const { + size_t offset = fContent.size(); + char* data = (char*)sk_malloc_throw(offset + fGraphicStackIndex * 2); + memcpy(data, fContent.c_str(), offset); + for (int i = 0; i < fGraphicStackIndex; i++) { + data[offset++] = 'Q'; + data[offset++] = '\n'; + } + SkMemoryStream* result = new SkMemoryStream; + result->setMemoryOwned(data, offset); return result; } diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp index 40bfad74e3..70f166c1a9 100644 --- a/src/pdf/SkPDFFormXObject.cpp +++ b/src/pdf/SkPDFFormXObject.cpp @@ -28,11 +28,9 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { // resources). device->getResources(&fResources); - SkString content = device->content(); - SkMemoryStream* stream_data = new SkMemoryStream(content.c_str(), - content.size()); - SkAutoUnref stream_data_unref(stream_data); - fStream = new SkPDFStream(stream_data); + SkRefPtr<SkStream> content = device->content(); + content->unref(); // SkRefPtr and content() both took a reference. + fStream = new SkPDFStream(content.get()); fStream->unref(); // SkRefPtr and new both took a reference. insert("Type", new SkPDFName("XObject"))->unref(); diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp index 2bec90744e..54f8dba8e3 100644 --- a/src/pdf/SkPDFPage.cpp +++ b/src/pdf/SkPDFPage.cpp @@ -32,11 +32,9 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage, insert("Resources", fDevice->getResourceDict().get()); insert("MediaBox", fDevice->getMediaBox().get()); - fContent = fDevice->content(); - SkRefPtr<SkMemoryStream> contentStream = new SkMemoryStream( - fContent.c_str(), fContent.size()); - contentStream->unref(); // SkRefPtr and new both took a reference. - fContentStream = new SkPDFStream(contentStream.get()); + SkRefPtr<SkStream> content = fDevice->content(); + content->unref(); // SkRefPtr and content() both took a reference. + fContentStream = new SkPDFStream(content.get()); fContentStream->unref(); // SkRefPtr and new both took a reference. insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref(); } |