aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-08 19:22:40 +0000
committerGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-08 19:22:40 +0000
commit79ac4fd6eb52512094ab762d2ec785390000cdd2 (patch)
treefbc478ec16803c9802c9fe5fedc3c4a72629930b /src
parent3dd42b3c87299ad17b4df93fe251f6f9362495dc (diff)
[PDF] Change SkPDFFormXObject to not hold a reference to device.
This prevents two copies of the content stream from sticking around. It also fixes an invalid memory reference because SkCanvas::internalRestore deletes the device (maybe it should just unref) after drawing it onto the main device. Review URL: http://codereview.appspot.com/4080056 git-svn-id: http://skia.googlecode.com/svn/trunk@773 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/pdf/SkPDFFormXObject.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp
index 7485e638bf..346bce6e85 100644
--- a/src/pdf/SkPDFFormXObject.cpp
+++ b/src/pdf/SkPDFFormXObject.cpp
@@ -22,11 +22,15 @@
#include "SkStream.h"
#include "SkTypes.h"
-SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device)
- : fContent(device->content(false)),
- fDevice(device) {
- SkMemoryStream* stream_data = new SkMemoryStream(fContent.c_str(),
- fContent.size());
+SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
+ // We don't want to keep around device because we'd have two copies
+ // of content, so reference or copy everything we need (content and
+ // resources).
+ device->getResources(&fResources);
+
+ SkString content = device->content(false);
+ SkMemoryStream* stream_data = new SkMemoryStream(content.c_str(),
+ content.size());
SkAutoUnref stream_data_unref(stream_data);
fStream = new SkPDFStream(stream_data);
fStream->unref(); // SkRefPtr and new both took a reference.
@@ -37,7 +41,9 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device)
insert("Resources", device->getResourceDict().get());
}
-SkPDFFormXObject::~SkPDFFormXObject() {}
+SkPDFFormXObject::~SkPDFFormXObject() {
+ fResources.unrefAll();
+}
void SkPDFFormXObject::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
bool indirect) {
@@ -55,7 +61,11 @@ size_t SkPDFFormXObject::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
}
void SkPDFFormXObject::getResources(SkTDArray<SkPDFObject*>* resourceList) {
- fDevice->getResources(resourceList);
+ resourceList->setReserve(resourceList->count() + fResources.count());
+ for (int i = 0; i < fResources.count(); i++) {
+ resourceList->push(fResources[i]);
+ fResources[i]->ref();
+ }
}
SkPDFObject* SkPDFFormXObject::insert(SkPDFName* key, SkPDFObject* value) {