[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
This commit is contained in:
parent
3dd42b3c87
commit
79ac4fd6eb
@ -66,9 +66,8 @@ public:
|
||||
SkPDFObject* insert(const char key[], SkPDFObject* value);
|
||||
|
||||
private:
|
||||
SkString fContent;
|
||||
SkRefPtr<SkPDFDevice> fDevice;
|
||||
SkRefPtr<SkPDFStream> fStream;
|
||||
SkTDArray<SkPDFObject*> fResources;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user