aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-02-24 12:56:16 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-24 12:56:16 -0800
commit334fcbc167237f02058cb508cb5f51b718141461 (patch)
treec5bd0fc294357e9f9c471d466c42489e0df1f6a8 /src/pdf
parentf73e589c0d3d54371466dcaa0642925824df24d7 (diff)
SkPDF: replace SkPDFDevice::copyContentToData
Motivation: remove copyToData(). Later we will stop caching the data alltogether. BUG=skia: Review URL: https://codereview.chromium.org/958433003
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/SkPDFDevice.cpp23
-rw-r--r--src/pdf/SkPDFDevice.h11
-rw-r--r--src/pdf/SkPDFFormXObject.cpp4
-rw-r--r--src/pdf/SkPDFPage.cpp2
-rw-r--r--src/pdf/SkPDFShader.cpp2
5 files changed, 17 insertions, 25 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index b6acf34bec..99f3ce1188 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -1301,10 +1301,10 @@ SkPDFArray* SkPDFDevice::copyMediaBox() const {
return mediaBox;
}
-SkStream* SkPDFDevice::content() const {
- SkMemoryStream* result = new SkMemoryStream;
- result->setData(this->copyContentToData())->unref();
- return result;
+SkStreamAsset* SkPDFDevice::content() const {
+ SkDynamicMemoryWStream buffer;
+ this->writeContent(&buffer);
+ return buffer.detachAsStream();
}
void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry,
@@ -1327,10 +1327,9 @@ void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry,
gsState.drainStack();
}
-SkData* SkPDFDevice::copyContentToData() const {
- SkDynamicMemoryWStream data;
+void SkPDFDevice::writeContent(SkWStream* out) const {
if (fInitialTransform.getType() != SkMatrix::kIdentity_Mask) {
- SkPDFUtils::AppendTransform(fInitialTransform, &data);
+ SkPDFUtils::AppendTransform(fInitialTransform, out);
}
// TODO(aayushkumar): Apply clip along the margins. Currently, webkit
@@ -1338,7 +1337,7 @@ SkData* SkPDFDevice::copyContentToData() const {
// that currently acts as our clip.
// Also, think about adding a transform here (or assume that the values
// sent across account for that)
- SkPDFDevice::copyContentEntriesToData(fMarginContentEntries.get(), &data);
+ SkPDFDevice::copyContentEntriesToData(fMarginContentEntries.get(), out);
// If the content area is the entire page, then we don't need to clip
// the content area (PDF area clips to the page size). Otherwise,
@@ -1347,14 +1346,10 @@ SkData* SkPDFDevice::copyContentToData() const {
if (fPageSize != fContentSize) {
SkRect r = SkRect::MakeWH(SkIntToScalar(this->width()),
SkIntToScalar(this->height()));
- emit_clip(NULL, &r, &data);
+ emit_clip(NULL, &r, out);
}
- SkPDFDevice::copyContentEntriesToData(fContentEntries.get(), &data);
-
- // potentially we could cache this SkData, and only rebuild it if we
- // see that our state has changed.
- return data.copyToData();
+ SkPDFDevice::copyContentEntriesToData(fContentEntries.get(), out);
}
#ifdef SK_PDF_USE_PATHOPS
diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h
index fc4f208f48..679c24b8bf 100644
--- a/src/pdf/SkPDFDevice.h
+++ b/src/pdf/SkPDFDevice.h
@@ -162,15 +162,12 @@ public:
SK_API SkPDFArray* getAnnotations() const { return fAnnotations; }
/** Returns a SkStream with the page contents. The caller is responsible
- for a reference to the returned value.
- DEPRECATED: use copyContentToData()
+ for a deleting the returned value.
*/
- SK_API SkStream* content() const;
+ SK_API SkStreamAsset* content() const;
- /** Returns a SkStream with the page contents. The caller is responsible
- * for calling data->unref() when it is finished.
- */
- SK_API SkData* copyContentToData() const;
+ /** Writes the page contents to the stream. */
+ SK_API void writeContent(SkWStream*) const;
SK_API const SkMatrix& initialTransform() const {
return fInitialTransform;
diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp
index 48d182eb40..19570f3d6d 100644
--- a/src/pdf/SkPDFFormXObject.cpp
+++ b/src/pdf/SkPDFFormXObject.cpp
@@ -23,8 +23,8 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
// resources).
SkPDFResourceDict* resourceDict = device->getResourceDict();
- SkAutoTDelete<SkStream> content(device->content());
- setData(content.get());
+ SkAutoTDelete<SkStreamAsset> content(device->content());
+ this->setData(content.get());
SkAutoTUnref<SkPDFArray> bboxArray(device->copyMediaBox());
init(NULL, resourceDict, bboxArray);
diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp
index b792f5e365..da0179a283 100644
--- a/src/pdf/SkPDFPage.cpp
+++ b/src/pdf/SkPDFPage.cpp
@@ -32,7 +32,7 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage,
insert("Annots", annots);
}
- SkAutoTUnref<SkData> content(fDevice->copyContentToData());
+ SkAutoTDelete<SkStreamAsset> content(fDevice->content());
fContentStream.reset(new SkPDFStream(content.get()));
insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref();
}
diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp
index d7605b3362..d7a5044591 100644
--- a/src/pdf/SkPDFShader.cpp
+++ b/src/pdf/SkPDFShader.cpp
@@ -1110,7 +1110,7 @@ SkPDFImageShader* SkPDFImageShader::Create(
}
// Put the canvas into the pattern stream (fContent).
- SkAutoTDelete<SkStream> content(patternDevice->content());
+ SkAutoTDelete<SkStreamAsset> content(patternDevice->content());
SkPDFImageShader* imageShader =
SkNEW_ARGS(SkPDFImageShader, (canon, autoState->detach()));